<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2012

 See text/EN/licence.txt for full licencing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license		http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright	ocProducts Ltd
 * @package		core
 */

/**
 * Module page class.
 */
class Module_admin
{
	var $keywords;
	var $and_query=true;

	/**
	 * Standard modular info function.
	 *
	 * @return ?array	Map of module info (NULL: module is disabled).
	 */
	function info()
	{
		$info=array();
		$info['author']='Chris Graham';
		$info['organisation']='ocProducts';
		$info['hacked_by']=NULL;
		$info['hack_version']=NULL;
		$info['version']=2;
		$info['locked']=false;
		return $info;
	}

	/**
	 * Standard modular entry-point finder function.
	 *
	 * @return ?array	A map of entry points (type-code=>language-code) (NULL: disabled).
	 */
	function get_entry_points()
	{
		return array('misc'=>'ADMIN_ZONE','structure'=>'STRUCTURE','usage'=>'USAGE','style'=>'STYLE','setup'=>'SETUP','tools'=>'TOOLS','security'=>'SECURITY_GROUP_SETUP');
	}

	/**
	 * Standard modular run function.
	 *
	 * @return tempcode	The result of execution.
	 */
	function run()
	{
		require_code('templates_donext');
		require_code('menus');

		require_all_lang();

		$type=get_param('type','misc');

		if (((!has_specific_permission(get_member(),'avoid_simplified_adminzone_look')) || ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()))) && (num_staff_icons()<MIN_STAFF_ICONS_BEFORE_COLLAPSE))
		{
			if ($type=='misc') return do_next_manager_admin_simplified();
		}

		// Warning about whether the Setup Wizard still needs running
		if ((get_param_integer('cancel_sw_warn',0)==1) || (!addon_installed('setupwizard')))
		{
			set_value('setup_wizard_completed','1');
		} else
		{
			$_done_sw_once=get_value('setup_wizard_completed');
			$done_sw_once=!is_null($_done_sw_once);
			if ((!$done_sw_once) && (get_param('page','')!='admin_setupwizard') && (has_actual_page_access(get_member(),'admin_setupwizard')))
			{
				$setup_wizard_url=build_url(array('page'=>'admin_setupwizard'),get_module_zone('admin_setupwizard'));
				$cancel_sw_url=get_self_url(false,false,array('cancel_sw_warn'=>1));
				attach_message(do_lang_tempcode('SETUP_WIZARD_NOT_RUN',escape_html($setup_wizard_url->evaluate()),escape_html($cancel_sw_url->evaluate())),'notice');
			}
		}

		switch ($type)
		{
			case 'misc':
				return do_next_manager_hooked('ADMIN_ZONE','DOC_ADMIN_ZONE','');
			case 'structure':
				return do_next_manager_hooked('STRUCTURE','DOC_STRUCTURE','structure');
			case 'usage':
				return do_next_manager_hooked('USAGE','DOC_USAGE','usage');
			case 'style':
				return do_next_manager_hooked('STYLE','DOC_STYLE','style');
			case 'setup':
				return do_next_manager_hooked('SETUP','DOC_SETUP','setup');
			case 'tools':
				return do_next_manager_hooked('TOOLS','DOC_TOOLS','tools');
			case 'security':
				return do_next_manager_hooked('SECURITY','DOC_SECURITY','security');

			case 'search':
				return $this->search();
		}

		return new ocp_tempcode();
	}

	/**
	 * Get synonyms for ocPortal terminology.
	 *
	 * @return array		Synonyms (each element is an array of synonyms).
	 */
	function _synonyms()
	{
		return array(
			array('multi-moderation','multimoderation'),
			array('invitation','invite'),
			array('banner','advert','advertising','advertise'),
			array('news','blogs','press release'),
			array('check-in','workflow','validation','valid','approval','approved','live','accept','posted','online','active','activate','activation'),
			array('theme','skin','style'),
			array('uninstall','disable','remove'),
			array('pruning','prune','lurkers'),
			array('colour','color','css','font','background'),
			array('sef','seo','google','search engine','search-engine-friendly','search-engine-optimisation'),
			array('ban','suspend','suspension','probation','warn','punish','punitive'),
			array('staff','moderator','admin', 'administrator','operator'),
			array('open','closed','live','activate','activation',/*'enable',*/'turn'),
			array('iotd','potd','image of the day'),
			array('import','convert','migrate','upload'),
			array('export','download'),
			array('email','e-mail'),
			array('center','centre'),
			array('license','licence'),
			array('atom','rss','feed'),
			array('login','logon','log-in','log-on'),
			array('gallery','album'),
			array('audit','log','usage'),
			array('download','file','document'),
			array('page','article','comcode'),
			array('entry','item','content','resource','submission'),
			array('category','node','section','repository'),
			array('catalogue','database','classified','catalog'),
			array('speed','slow','fast','optimisation','performance','efficiency'),
			array('panel','sidebar','frame'),
			array('usergroup','group','promote','rank'),
			array('member','user'),
			array('profile','account','memberaccount'),
			array('permission','privilege','authorisation','authorization','right'),
			array('option','setting','value'),
			array('configure','setup','install'),
			array('emoticon','smiley','face'),
			array('forum','board','bbs'),
			array('thread','topic'),
			array('karma','point'),
			array('subscribe','track','notification','alert','monitor','watch'),
			array('bbcode','wikicode','comcode','shortcode'),
			array('html','xhtml'),
			array('addon','add-on','mod','hack','extension','plugin'),
			array('cedi','wiki','seedy'),
			array('name','title'),
			array('analytics','statistics','hits'),
			array('newsletter','mass-mail','mass-mailing','bulletin','mail-merge'),
			array('description','caption','summary'),
			array('choose','set'),
			array('add','submit','create','make'),
			array('edit','modify','manage','change','control','moderate','update'),
			array('delete','erase','remove','discard'),
			array('restore','revert','undo'),
			array('news','story','stories','article'),
			array('language','unicode','utf','utf8','utf-8','character','charset','24','clock','timezone','time-zone','time','date','translate'),
			array('ldap','active directory'),
			array('contact','feedback','ticket','message','issue'),
			array('documentation','help','guide'),
			array('sef','short','friendly'),
			array('survey','quiz','competition','test'),
			array('swf','flash'),
			array('subscribe','subscription'),
			array('attach','embed'),
			array('smf','simple machines forum'),
			array('ipb','invision'),
			array('join','register','signup','sign-up'),
			array('logout','log-out','sign-out','sign-off'),
			array('login','log-in','sign-in','sign-on'),
			array('shopping','ecommerce','payment','purchase'),
			array('module','addon','system'),
			array('cache','decache','cleanup'),
			array('ssl','https'),
			array('seed','theme wizard'),
			array('block','widget'), // Joomla uses 'module', but we don't want to synonym this as it means something else in ocPortal
		);
	}

	/**
	 * Strip junk words from the keywords representing a search.
	 *
	 * @param  array		Input words.
	 * @return array		Replaced, with junk words removed.
	 */
	function _strip_junk_words($words)
	{
		$bad=array('the','of','to','and','a','in','is','it','you','that','he','was','for','on','are',
			'with','as','I','his','they','be','at','this','or','had','by','but','what','some','we','can',
			'out','other','were','all','there','when','your','how','an','which','do','so','these','has','go',
			'come','did','no','my','where','me','our','thing','site','website');
		$_words=array();
		foreach ($words as $i=>$b)
		{
			if (!in_array($b,$bad))
			{
				if ((($b!='chat') || (!array_key_exists($i+1,$words)) || (($words[$i+1]!='room') && ($words[$i+1]!='rooms'))) && (($b!='user') || (!array_key_exists($i+1,$words)) || (($words[$i+1]!='group') && ($words[$i+1]!='groups'))))
					$_words[]=$b;
				else // Special case of compound terms that are actually single words in ocPortal; fix the word, and also stop ridiculous amounts of spurious result
					$words[$i+1]=$b.$words[$i+1];
			}
		}
		return $_words;
	}

	/**
	 * See if a string matches one of the keywords.
	 *
	 * @param  string		Search string.
	 * @return boolean	Whether there is a match.
	 */
	function _keyword_match($t)
	{
		static $regexp='';
		if (($regexp=='') || ($this->and_query))
		{
			foreach ($this->keywords as $keyword_group)
			{
				if ($this->and_query)
				{
					$regexp='';
				}
				foreach ($keyword_group as $keyword)
				{
					if ($regexp!='') $regexp.='|';
					$regexp_for_keyword='((^|\.|\#|\s|\/|\-|>|\)|\(|\})'.str_replace('#','\#',preg_quote($keyword)).')';
					$regexp.=$regexp_for_keyword;
				}
				if ($this->and_query)
				{
					if (preg_match('#'.$regexp.'#i',$t)==0) return false;
				}
			}
		}
		if ($this->and_query)
		{
			return true;
		}
		return (preg_match('#'.$regexp.'#i',$t)!=0);
	}

	/**
	 * See if our current section is going to be searched.
	 *
	 * @param  array		List of sections to search (empty: search all sections).
	 * @param  string		Current section.
	 * @return boolean	Whether there is a match.
	 */
	function _section_match($section_limitations,$results_type)
	{
		if ($section_limitations==array()) return true;

		foreach ($section_limitations as $l)
		{
			if (strpos(strtolower($results_type),strtolower($l))!==false) return true;
		}

		return false;
	}

	/**
	 * Actualiser to perform Admin Zone search.
	 *
	 * @return tempcode	Interface.
	 */
	function search()
	{
		require_all_lang();
		require_code('zones2');
		disable_php_memory_limit();

		if (function_exists('set_time_limit')) @set_time_limit(100);

		$n=mixed();

		$default_theme=$GLOBALS['FORUM_DRIVER']->get_theme('');

		// Mess around to find our search keywords (takes synonyms into account, and generally tidies up)
		$raw_search_string=get_param('search_content',false,true);

		// Work out our keywords
		$keyword_string=$raw_search_string;
		$_keywords=array();
		$current_word='';
		$in_quotes=false;
		for ($xi=0;$xi<strlen($keyword_string);$xi++)
		{
			if (($in_quotes) || (trim($keyword_string[$xi])!=''))
			{
				if ($keyword_string[$xi]=='"')
				{
					$in_quotes=!$in_quotes;
				} else
				{
					$current_word.=$keyword_string[$xi];
				}
			} else
			{
				if ($current_word!='') $_keywords[]=$current_word;
				$current_word='';
			}
		}
		if ($current_word!='') $_keywords[]=$current_word;
		$_keywords=$this->_strip_junk_words($_keywords);
		if (count($_keywords)==0)
		{
			return do_template('INDEX_SCREEN_FANCIER_SCREEN',array('TITLE'=>get_screen_title('ADMIN_ZONE_SEARCH_RESULTS'),'EMPTY'=>true,'ARRAY'=>true,'CONTENT'=>'','PRE'=>'','POST'=>''));
		}
		$keywords=array();
		$synonym_rows=$this->_synonyms(); // Only in English by default. To do for another language, override this file using inheritance
		$section_limitations=array();
		foreach ($_keywords as $xi=>$keyword)
		{
			$_keywords=array();
			$keyword=trim($keyword);
			if ($keyword=='') continue;

			if (substr($keyword,0,1)=='@')
			{
				$section_limitations[]=substr($keyword,1);
				continue;
			}

			foreach ($synonym_rows as $synonyms)
			{
				if ((in_array(strtolower($keyword),$synonyms)) || ((array_key_exists($xi+1,$_keywords)) && (in_array(strtolower($_keywords[$xi].' '.$_keywords[$xi+1]),$synonyms))))
				{
					$_keywords=array_merge($_keywords,$synonyms);
				}
			}

			$_keywords[]=$keyword;
			$keywords[]=$_keywords;
		}

		// Stemming, if available (needs Stemmer class like http://www.chuggnutt.com/stemmer-source.php which we can't redistribute due to it being GPL not LGPL)
		if ((file_exists(get_file_base().'/sources_custom/stemmer_'.user_lang().'.php')) && (!in_safe_mode()))
		{
			require_code('stemmer_'.user_lang());
			$stemmer=object_factory('Stemmer_'.user_lang());
			foreach ($keywords as $i=>$keyword_group)
			{
				$_keyword_group=$keyword_group;
				foreach ($keyword_group as $keyword)
				{
					// Special stemmer exceptions
					if ($keyword=='news') continue;
					if ($keyword=='defaultness') continue;

					$_keyword_group[]=$stemmer->stem($keyword);
				}
				$keywords[$i]=array_unique($_keyword_group);
			}
		} else
		{
			foreach ($keywords as $i=>$keyword_group)
			{
				$_keyword_group=$keyword_group;
				foreach ($keyword_group as $keyword) // Lame pluralisation fudge, if we don't have stemming
				{
					if ((strlen($keyword)>3) && (substr($keyword,-1)=='s'))
						$_keyword_group[]=substr($keyword,0,strlen($keyword)-1);
					else
						$_keyword_group[]=$keyword.'s';
				}
				$keywords[$i]=array_unique($_keyword_group);
			}
		}

		$this->keywords=$keywords;

		$content=array();

		// Admin/CMS menu icons
		$current_results_type=do_lang('ADMIN_MODULES');
		if ($this->_section_match($section_limitations,$current_results_type))
		{
			$content[$current_results_type]=new ocp_tempcode();
			$hooks=find_all_hooks('systems','do_next_menus');
			foreach (array_keys($hooks) as $hook)
			{
				require_code('hooks/systems/do_next_menus/'.filter_naughty_harsh($hook));
				$object=object_factory('Hook_do_next_menus_'.filter_naughty_harsh($hook),true);
				if (is_null($object)) continue;
				$info=$object->run(true);
				foreach ($info as $i)
				{
					if (is_null($i)) continue;

					$n=$i[3];
					if (($this->_keyword_match(is_object($n)?$n->evaluate():$n)) && (has_actual_page_access(get_member(),$i[2][0],$i[2][2])))
					{
						$_url=build_url(array('page'=>$i[2][0])+$i[2][1],$i[2][2]);
						$breadcrumbs=new ocp_tempcode();
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>$i[0]),'adminzone'),do_lang(strtoupper($i[0]))));
						$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'ec53a1d45fe6a80308bf509b896d2763','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));
					}
				}
			}
		}

		// Module entry points
		$current_results_type=do_lang('SCREENS');
		if ($this->_section_match($section_limitations,$current_results_type))
		{
			$content[$current_results_type]=new ocp_tempcode();
			foreach (find_all_zones(false,true) as $zone=>$zone_details)
			{
				$modules=find_all_modules($zone);
				foreach (array_keys($modules) as $page)
				{
					$_entrypoints=extract_module_functions_page($zone,$page,array('get_entry_points'));
					if (!is_null($_entrypoints[0]))
					{
						if ((is_array($_entrypoints[0])) || (strpos($_entrypoints[0],'::')===false))
						{
							$entry_points=is_array($_entrypoints[0])?call_user_func_array($_entrypoints[0][0],$_entrypoints[0][1]):eval($_entrypoints[0]);
						} else
						{
							$path=zone_black_magic_filterer(filter_naughty($zone).(($zone=='')?'':'/').'pages/modules_custom/'.filter_naughty($page).'.php',true);
							if (!file_exists(get_file_base().'/'.$path)) $path=zone_black_magic_filterer(filter_naughty($zone).'/pages/modules/'.filter_naughty($page).'.php',true);
							if ((!defined('HIPHOP_PHP')) && ((ini_get('memory_limit')!='-1') && (ini_get('memory_limit')!='0') || (get_option('has_low_memory_limit')==='1')) && (strpos(file_get_contents(get_file_base().'/'.$path),' extends standard_aed_module')!==false)) // Hackerish code when we have a memory limit. It's unfortunate, we'd rather execute in full
							{
								$new_code=str_replace(',parent::get_entry_points()','',str_replace('parent::get_entry_points(),','',$_entrypoints[0]));
								if (strpos($new_code,'parent::')!==false) continue;
								$entry_points=eval($new_code);
							} else
							{
								require_code($path);
								if (class_exists('Mx_'.filter_naughty_harsh($page)))
								{
									$object=object_factory('Mx_'.filter_naughty_harsh($page));
								} else
								{
									$object=object_factory('Module_'.filter_naughty_harsh($page));
								}
								$entry_points=$object->get_entry_points();
							}
						}
						if ($page=='admin_themes')
						{
							$entry_points['!themes']='EDIT_CSS';
							$entry_points['!!themes']='EDIT_TEMPLATES';
							$entry_points['!!!themes']='MANAGE_THEME_IMAGES';
						}
						if (is_null($entry_points)) $entry_points=array();
						foreach ($entry_points as $type=>$lang)
						{
							$type=str_replace('!','',$type); // The ! was a hackerish thing just to multiply-up possibilities for the single entry-point
							$n=do_lang_tempcode($lang);
							if (($this->_keyword_match($n->evaluate())) && (has_actual_page_access(get_member(),$page,$zone)))
							{
								$breadcrumbs=new ocp_tempcode();
								$breadcrumbs->attach(hyperlink(build_url(array('page'=>''),$zone),$zone_details[1]));
								if (($zone=='cms') || ($zone=='adminzone'))
								{
									if (($page!='admin') && ($page!='cms'))
									{
										$hooks=find_all_hooks('systems','do_next_menus');
										foreach (array_keys($hooks) as $hook)
										{
											require_code('hooks/systems/do_next_menus/'.filter_naughty_harsh($hook));
											$object=object_factory('Hook_do_next_menus_'.filter_naughty_harsh($hook),true);
											if (is_null($object)) continue;
											$info=$object->run();
											foreach ($info as $i)
											{
												if (is_null($i)) continue;

												if (($page==$i[2][0]) && (((!array_key_exists('type',$i[2][1])) && ($type=='misc')) || ((array_key_exists('type',$i[2][1])) && ($type==$i[2][1]['type']))) && ($zone==$i[2][2]))
												{
													if ($i[0]=='cms')
													{
														$_url=build_url(array('page'=>'cms','type'=>$i[0]),'cms');
													} else
													{
														$_url=build_url(array('page'=>'admin','type'=>$i[0]),'adminzone');
													}

													require_lang('menus');
													require_lang('security');

													$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
													$breadcrumbs->attach(hyperlink($_url,do_lang_tempcode(strtoupper($i[0]))));
													if ($type!='misc')
													{
														$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
														$breadcrumbs->attach(hyperlink(build_url(array('page'=>$page,'type'=>'misc'),$zone),$i[3]));
													}
													break 2;
												}
											}
										}
									} else
									{
										$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
										$breadcrumbs->attach(hyperlink(build_url(array('page'=>$page),$zone),$page));
									}
								}
								$_url=build_url(array('page'=>$page,'type'=>$type),$zone);
								$sup=$breadcrumbs->is_empty()?NULL:do_lang_tempcode('LOCATED_IN',$breadcrumbs);
								$site_tree_editor_url=build_url(array('page'=>'admin_sitetree','type'=>'site_tree','id'=>$zone.':'.$page),'adminzone');
								$permission_tree_editor_url=build_url(array('page'=>'admin_permissions','id'=>$zone.':'.$page),'adminzone');
								$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'f656efd513099deac516d3273f9adfc4','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>do_lang_tempcode('FIND_IN_SITE_TREE_EDITOR',escape_html($site_tree_editor_url->evaluate()),escape_html($permission_tree_editor_url->evaluate())),'SUP'=>$sup)));
							}
						}
					}
				}
			}
		}

		$current_results_type=do_lang('IMPORT');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_import')))
		{
			// Importers
			$content[$current_results_type]=new ocp_tempcode();
			$hooks=find_all_hooks('modules','admin_import');
			foreach (array_keys($hooks) as $hook)
			{
				if ($this->_keyword_match($hook))
				{
					require_code('hooks/modules/admin_import/'.filter_naughty_harsh($hook));
					$_hook=object_factory('Hook_'.filter_naughty_harsh($hook));
					$info=$_hook->info();
					$name=$info['product'];
					$_url=build_url(array('page'=>'admin_import','type'=>'session','importer'=>$hook),get_module_zone('admin_import'));
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'e0f1221d5cb9d7f34bd884d6d3e480dc','NAME'=>$name,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>'')));
				}
			}
		}

		$current_results_type=do_lang('CONFIGURATION');
		if ((($this->_section_match($section_limitations,$current_results_type)) || ($this->_section_match($section_limitations,do_lang('OPTION_CATEGORIES'))) || ($this->_section_match($section_limitations,do_lang('OPTION_GROUPS')))) && (has_actual_page_access(get_member(),'admin_config')))
		{
			// Config options- names, descriptions, groups, categories
			$content[$current_results_type]=new ocp_tempcode();
			$map=array();
			if (!is_null($GLOBALS['CURRENT_SHARE_USER'])) $map['shared_hosting_restricted']=0;
			$all_options=$GLOBALS['SITE_DB']->query_select('config',array('the_name','human_name','the_page','section','explanation','eval'),$map);
			$all_options[]=array('the_name'=>'timezone','human_name'=>'TIME_ZONE','config_value'=>'','the_type'=>'special','eval'=>'','the_page'=>'SITE','section'=>'GENERAL','explanation'=>'','shared_hosting_restricted'=>0);
			$config_categories=array();
			$conf_found_count=0;
			foreach ($all_options as $p)
			{
				if (defined('HIPHOP_PHP'))
				{
					require_code('hooks/systems/config_default/'.$p['the_name']);
					$hook=object_factory('Hook_config_default_'.$p['the_name']);
					$null_test=$hook->get_default();
				} else
				{
					$null_test=eval($p['eval']);
				}

				if (!is_null($null_test))
				{
					$n=do_lang_tempcode($p['human_name']);
					switch ($p['the_name'])
					{
						case 'timezone':
							$t=do_lang('DESCRIPTION_TIMEZONE_SITE');
							break;

						default:
							$t=do_lang($p['explanation'],NULL,NULL,NULL,NULL,false);
							break;
					}
					if (is_null($n)) continue;
					$config_value=array_key_exists('config_value',$p)?$p['config_value']:get_option($p['the_name']);
					if ($config_value===false) continue;
					if ((($this->_keyword_match($p['the_name'])) || ($this->_keyword_match($n->evaluate())) || ($this->_keyword_match($t)) || ($this->_keyword_match($config_value))))
					{
						if (!is_null($null_test))
						{
							$_url=build_url(array('page'=>'admin_config','type'=>'category','id'=>$p['the_page']),'adminzone');
							$url=$_url->evaluate();
							$url.='#group_'.$p['section'];
							if (is_null($t)) $t='';
							$breadcrumbs=new ocp_tempcode();
							$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'setup'),'adminzone'),do_lang_tempcode('SETUP')));
							$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
							$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_config','type'=>'misc'),'adminzone'),do_lang_tempcode('CONFIGURATION')));
							$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
							$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_config','type'=>'category','id'=>$p['the_page']),'adminzone'),do_lang('CONFIG_CATEGORY_'.$p['the_page'])));
							$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
							$breadcrumbs->attach(hyperlink($url,do_lang($p['section'])));
							$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
							$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'f7271912ccbe0358fe263ed61f7ed427','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>protect_from_escaping($t),'SUP'=>$sup)));

							if ($conf_found_count>100)
							{
								$content[$current_results_type]=do_template('INDEX_SCREEN_FANCIER_ENTRY',array('NAME'=>do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'),'URL'=>'','TITLE'=>'','DESCRIPTION'=>'','SUP'=>''));
								break;
							}

							$conf_found_count++;

							if (!array_key_exists($p['the_page'],$config_categories)) $config_categories[$p['the_page']]=array();
							$config_categories[$p['the_page']][$p['section']]=1;
						}
					}
				}
			}
			$current_results_type=do_lang('OPTION_CATEGORIES');
			$content[$current_results_type]=new ocp_tempcode();
			$current_results_type_2=do_lang('OPTION_GROUPS');
			$content[$current_results_type_2]=new ocp_tempcode();
			foreach ($config_categories as $p=>$groups)
			{
				$_n=do_lang('CONFIG_CATEGORY_'.$p,NULL,NULL,NULL,NULL,false);
				if (is_null($_n)) continue;
				$n=do_lang_tempcode('CONFIG_CATEGORY_'.$p);
				if ($this->_keyword_match($n->evaluate()))
				{
					$_url=build_url(array('page'=>'admin_config','type'=>'category','id'=>$p),'adminzone');
					$description=do_lang_tempcode('CONFIG_CATEGORY_DESCRIPTION__'.$p);
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'setup'),'adminzone'),do_lang_tempcode('SETUP')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_config','type'=>'misc'),'adminzone'),do_lang_tempcode('CONFIGURATION')));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'eec6e7cc57e660bdcbf123db8419e24e','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>$description,'SUP'=>$sup)));
				}
				foreach (array_keys($groups) as $group)
				{
					$n2=do_lang($group,NULL,NULL,NULL,NULL,false);
					if (is_null($n2)) continue;

					if ($this->_keyword_match($n2))
					{
						$upload_max_filesize=(ini_get('upload_max_filesize')=='0')?do_lang('NA'):clean_file_size(php_return_bytes(ini_get('upload_max_filesize')));
						$post_max_size=(ini_get('post_max_size')=='0')?do_lang('NA'):clean_file_size(php_return_bytes(ini_get('post_max_size')));
						$_group_description=do_lang('CONFIG_GROUP_DESCRIP_'.$group,escape_html($post_max_size),escape_html($upload_max_filesize),NULL,NULL,false);
						if (is_null($_group_description))
						{
							$group_description=new ocp_tempcode();
						} else
						{
							$group_description=do_lang_tempcode('CONFIG_GROUP_DESCRIP_'.$group,escape_html($post_max_size),escape_html($upload_max_filesize),false);
						}
						$_url=build_url(array('page'=>'admin_config','type'=>'category','id'=>$p),'adminzone');
						$url=$_url->evaluate();
						$url.='#group_'.$group;
						$breadcrumbs=new ocp_tempcode();
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'setup'),'adminzone'),do_lang_tempcode('SETUP')));
						$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_config','type'=>'misc'),'adminzone'),do_lang_tempcode('CONFIGURATION')));
						$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_config','type'=>'category','id'=>$p),'adminzone'),do_lang('CONFIG_CATEGORY_'.$p)));
						$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
						$content[$current_results_type_2]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'e95b87d01c839e41ee1ea484feeb5cd7','NAME'=>$n2,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>$group_description,'SUP'=>$sup)));
					}
				}
			}
		}

		$current_results_type=do_lang('USERGROUPS');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_ocf_groups')) && (get_forum_type()=='ocf'))
		{
			// Usergroups
			$content[$current_results_type]=new ocp_tempcode();
			$map=array('g_is_private_club'=>0);
			$all_groups=$GLOBALS['FORUM_DB']->query_select('f_groups',array('id','g_name'),$map);
			foreach ($all_groups as $p)
			{
				$n=get_translated_text($p['g_name']);
				if ($this->_keyword_match($n))
				{
					$_url=build_url(array('page'=>'admin_ocf_groups','type'=>'_ed','id'=>$p['id']),'adminzone');
					$url=$_url->evaluate();
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'security'),'adminzone'),do_lang_tempcode('SECURITY')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_ocf_groups','type'=>'misc'),'adminzone'),do_lang_tempcode('USERGROUPS')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_ocf_groups','type'=>'ed'),'adminzone'),do_lang_tempcode('EDIT_GROUP')));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'785e7208a7b10dfd095197754cedf505','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));
				}
			}
		}

		$current_results_type=do_lang('THEMES');
		if (($this->_section_match($section_limitations,$current_results_type)) && has_actual_page_access(get_member(),'admin_themes'))
		{
			// Themes
			$content[$current_results_type]=new ocp_tempcode();
			$map=array();
			foreach (array(do_lang('SUPPORTS_WIDE'),do_lang('MOBILE_PAGES')) as $n)
			{
				if ($this->_keyword_match($n))
				{
					$_url=build_url(array('page'=>'admin_themes','type'=>'edit_theme','theme'=>$GLOBALS['FORUM_DRIVER']->get_theme('')),'adminzone');
					$url=$_url->evaluate();
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'style'),'adminzone'),do_lang_tempcode('STYLE')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'misc'),'adminzone'),do_lang_tempcode('THEMES')));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'00bb6ce930058afc298ce206b703322b','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));

					break;
				}
			}
		}

		$current_results_type=do_lang('ZONES');
		if (($this->_section_match($section_limitations,$current_results_type)) && has_actual_page_access(get_member(),'admin_zones'))
		{
			// Zones
			$content[$current_results_type]=new ocp_tempcode();
			$map=array();
			$all_groups=$GLOBALS['SITE_DB']->query_select('zones',array('zone_name','zone_title','zone_header_text'),$map,'ORDER BY zone_title',50/*reasonable limit; zone_title is sequential for default zones*/);
			foreach ($all_groups as $p)
			{
				$n=$p['zone_name'];
				$t=get_translated_text($p['zone_title']);
				$ht=get_translated_text($p['zone_header_text']);
				if (($this->_keyword_match($n)) || ($this->_keyword_match($t)) || ($this->_keyword_match($ht)))
				{
					$_url=build_url(array('page'=>'admin_zones','type'=>'_edit','id'=>$p['zone_name']),'adminzone');
					$url=$_url->evaluate();
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'setup'),'adminzone'),do_lang_tempcode('STRUCTURE')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_zones','type'=>'misc'),'adminzone'),do_lang_tempcode('ZONES')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_zones','type'=>'edit'),'adminzone'),do_lang_tempcode('EDIT_ZONE')));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'d9e5c8d9ba1aedb920ac7c719d4ace69','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>escape_html($t),'SUP'=>$sup)));
				}
			}
		}

		// Blocks
		$current_results_type=do_lang('_BLOCKS');
		if ($this->_section_match($section_limitations,$current_results_type))
		{
			$content[$current_results_type]=new ocp_tempcode();
			$map=array();
			require_code('zones2');
			$all_blocks=find_all_blocks();
			foreach (array_keys($all_blocks) as $p)
			{
				$t=do_lang('BLOCK_'.$p.'_DESCRIPTION');
				if (($this->_keyword_match($p)) || ($this->_keyword_match($t)))
				{
					$url='';
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'1368be933d0ccbcd65939f29dd6d7003','NAME'=>$p,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>escape_html($t))));
				}
			}
		}

		$current_results_type=do_lang('PRIVILEGES');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_permissions')))
		{
			// Privileges- sections/names/descriptions
			$content[$current_results_type]=new ocp_tempcode();
			$all_permissions=$GLOBALS['SITE_DB']->query_select('sp_list',array('the_name','p_section'));
			$pt_sections=array();
			foreach ($all_permissions as $p)
			{
				$n=do_lang('PT_'.$p['the_name'],NULL,NULL,NULL,NULL,false);
				if (is_null($n)) continue;
				if (($this->_keyword_match($n)) || ($this->_keyword_match($p['the_name'])))
				{
					$_url=build_url(array('page'=>'admin_permissions','type'=>'specific','id'=>$p['p_section']),'adminzone');
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'security'),'adminzone'),do_lang_tempcode('SECURITY')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_permissions','type'=>'specific'),'adminzone'),do_lang_tempcode('PRIVILEGES')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink($_url,do_lang($p['p_section'])));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'52a412bd158c7dd16f3f9d0e84ae1b0b','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));
				}
				$pt_sections[$p['p_section']]=1;
			}
			$current_results_type=do_lang('PRIVILEGE_SECTIONS');
			$content[$current_results_type]=new ocp_tempcode();
			foreach (array_keys($pt_sections) as $p)
			{
				$n=do_lang($p,NULL,NULL,NULL,NULL,false);
				if (is_null($n)) continue;
				if (($this->_keyword_match($n)) || ($this->_keyword_match($p)))
				{
					$_url=build_url(array('page'=>'admin_permissions','type'=>'specific','id'=>$p),'adminzone');
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'security'),'adminzone'),do_lang_tempcode('SECURITY')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_permissions','type'=>'specific'),'adminzone'),do_lang_tempcode('PRIVILEGES')));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'43bfb229943e0bb1d2c2e4512e0e5ec9','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));
				}
			}
		}

		$current_results_type=do_lang('USERGROUP_SETTINGS');
		if (($this->_section_match($section_limitations,$current_results_type)) && (get_forum_type()=='ocf') && (has_actual_page_access(get_member(),'admin_ocf_groups','adminzone')))
		{
			// Usergroup settings
			$content[$current_results_type]=new ocp_tempcode();
			$applicable_langstrings=array(
				array('ENQUIRE_ON_NEW_IPS','DESCRIPTION_ENQUIRE_ON_NEW_IPS'),
				array('FLOOD_CONTROL_ACCESS_SECS','DESCRIPTION_FLOOD_CONTROL_ACCESS_SECS'),
				array('FLOOD_CONTROL_SUBMIT_SECS','DESCRIPTION_FLOOD_CONTROL_SUBMIT_SECS'),
				array('MAX_ATTACHMENTS_PER_POST','DESCRIPTION_MAX_ATTACHMENTS_PER_POST'),
				array('MAX_DAILY_UPLOAD_MB','DESCRIPTION_MAX_DAILY_UPLOAD_MB'),
				array('MAX_AVATAR_WIDTH','DESCRIPTION_MAX_AVATAR_WIDTH'),
				array('MAX_AVATAR_HEIGHT','DESCRIPTION_MAX_AVATAR_HEIGHT'),
				array('MAX_POST_LENGTH_COMCODE','DESCRIPTION_MAX_POST_LENGTH_COMCODE'),
				array('MAX_SIG_LENGTH_COMCODE','DESCRIPTION_MAX_SIG_LENGTH_COMCODE'),
			);
			if (addon_installed('points'))
			{
				$applicable_langstrings=array_merge($applicable_langstrings,array(
					array('GIFT_POINTS_BASE','DESCRIPTION_GIFT_POINTS_BASE'),
					array('GIFT_POINTS_PER_DAY','DESCRIPTION_GIFT_POINTS_PER_DAY'),
				));
			}
			foreach ($applicable_langstrings as $_langstring)
			{
				$array=is_array($_langstring)?$_langstring:array($_langstring);
				foreach ($array as $langstring)
				{
					$n=do_lang($langstring);
					if ($this->_keyword_match($n))
					{
						$n=do_lang_tempcode($array[0]);
						$_url=build_url(array('page'=>'admin_ocf_groups','type'=>'ed'),'adminzone');
						$descrip=array_key_exists(1,$array)?do_lang_tempcode($array[1]):new ocp_tempcode();
						$breadcrumbs=new ocp_tempcode();
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'security'),'adminzone'),do_lang_tempcode('SECURITY')));
						$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_ocf_groups','type'=>'misc'),'adminzone'),do_lang_tempcode('USERGROUPS')));
						$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'d0baedf2ee9cf0bdd00e604bd4c7f3b4','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>$descrip,'SUP'=>$sup)));
						continue 2;
					}
				}
			}
		}

		$current_results_type=do_lang('MEMBER_SETTINGS');
		if (($this->_section_match($section_limitations,$current_results_type)) && (get_forum_type()=='ocf') && (has_actual_page_access(get_member(),'members')))
		{
			// Member settings
			$content[$current_results_type]=new ocp_tempcode();
			$applicable_langstrings=array(
				array('WIDE','DESCRIPTION_WIDE'),
				array('REVEAL_AGE','DESCRIPTION_REVEAL_AGE'),
				array('PREVIEW_POSTS','DESCRIPTION_PREVIEW_POSTS'),
				array('AUTO_NOTIFICATION_CONTRIB_CONTENT','DESCRIPTION_AUTO_NOTIFICATION_CONTRIB_CONTENT'),
				array('PT_RULES_TEXT','PT_RULES_TEXT_DESCRIPTION'),
			);
			foreach ($applicable_langstrings as $_langstring)
			{
				$array=is_array($_langstring)?$_langstring:array($_langstring);
				foreach ($array as $langstring)
				{
					$n=do_lang($langstring);
					if ($this->_keyword_match($n))
					{
						$n=do_lang_tempcode($array[0]);
						$descrip=array_key_exists(1,$array)?do_lang_tempcode($array[1]):new ocp_tempcode();
						$_url=build_url(array('page'=>'members','type'=>'view'),get_module_zone('members'),NULL,false,false,false,'tab__edit');
						$url=$_url->evaluate();
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'4b2b7dd9c8c81f15583428fc2692bca5','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>$descrip)));
						continue 2;
					}
				}
			}
		}

		// Zone options
		$current_results_type=do_lang('ZONE_OPTIONS');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_zones','adminzone')))
		{
			$content[$current_results_type]=new ocp_tempcode();
			$applicable_langstrings=array(
				array('DEFAULT_PAGE','DESCRIPTION_DEFAULT_PAGE'),
				array('HEADER_TEXT','DESCRIPTION_HEADER_TEXT'),
				array('WIDE','DESCRIPTION_WIDE'),
				array('REQUIRE_SESSION','DESCRIPTION_REQUIRE_SESSION'),
				array('DISPLAYED_IN_MENU','DESCRIPTION_DISPLAYED_IN_MENU'),
				array('THEME',(get_forum_type()=='ocf')?'_DESCRIPTION_THEME_OCF':'_DESCRIPTION_THEME'),
			);
			foreach ($applicable_langstrings as $_langstring)
			{
				$array=is_array($_langstring)?$_langstring:array($_langstring);
				foreach ($array as $langstring)
				{
					$n=do_lang($langstring);
					if ($this->_keyword_match($n))
					{
						$n=do_lang_tempcode($array[0]);
						$_url=build_url(array('page'=>'admin_zones','type'=>'edit'),'adminzone');
						$descrip=array_key_exists(1,$array)?do_lang_tempcode($array[1]):new ocp_tempcode();
						$breadcrumbs=new ocp_tempcode();
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'structure'),'adminzone'),do_lang_tempcode('STRUCTURE')));
						$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_zones','type'=>'misc'),'adminzone'),do_lang_tempcode('ZONES')));
						$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'9c2cadfe9be9776c91c4d99050e0c187','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>$descrip,'SUP'=>$sup)));
						continue 2;
					}
				}
			}
		}

		// Install options
		$current_results_type=do_lang('BASE_CONFIGURATION');
		if (($this->_section_match($section_limitations,$current_results_type)) && ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())))
		{
			$content[$current_results_type]=new ocp_tempcode();
			if (file_exists(get_file_base().'/config_editor.php'))
			{
				$file_contents=file_get_contents(get_file_base().'/config_editor.php');
				$matches=array();
				$num_matches=preg_match_all('#case \'([^\']+)\':\n\s*\$notes=\'([^\']+)\';#',$file_contents,$matches);
				for ($i=0;$i<$num_matches;$i++)
				{
					$n=stripslashes($matches[2][$i]);
					if ($this->_keyword_match($n))
					{
						$url=get_base_url().'/config_editor.php';
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('NAME'=>stripslashes($matches[1][$i]),'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>$n)));
					}
				}
			}
		}

		// Language string names and contents
		$current_results_type=do_lang('MODULE_TRANS_NAME_admin_lang');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_lang','adminzone')))
		{
			$content[$current_results_type]=new ocp_tempcode();

			if (user_lang()!=fallback_lang())
				$content[$current_results_type]->attach(paragraph(do_lang_tempcode('SEARCH_LAUNCHPAD',escape_html(urlencode($raw_search_string)),escape_html(urlencode(user_lang())))));

			global $LANGUAGE;
			$lang_file_contents=array();
			$lang_found=array();
			foreach ($LANGUAGE[user_lang()] as $n=>$n_value) // Search all lang strings (we loaded all earlier with require_all_lang)
			{
				if (($this->_keyword_match($n)) || ($this->_keyword_match($n_value)))
				{
					$lang_found[$n]=$n_value;
					if (count($lang_found)>100)
					{
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('NAME'=>do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'),'URL'=>'','TITLE'=>'','DESCRIPTION'=>'','SUP'=>'')));
						$lang_found=array();
						break;
					}
				}
			}
			foreach ($lang_found as $n=>$n_value)
			{
				// Try and find what lang file it came from
				$lang_file='global';
				foreach (array('lang','lang_custom') as $lang_dir)
				{
					$dh=@opendir(get_file_base().'/'.$lang_dir.'/'.fallback_lang().'/');
					if ($dh!==false)
					{
						while (($file=readdir($dh))!==false)
						{
							if (substr(strtolower($file),-4)=='.ini')
							{
								if (!array_key_exists($file,$lang_file_contents))
									$lang_file_contents[$file]=file_get_contents(get_file_base().'/'.$lang_dir.'/'.fallback_lang().'/'.$file);
								if ((preg_match('#^'.str_replace('#','\#',preg_quote($n)).'=#m',$lang_file_contents[$file])!=0) || ((file_exists(get_custom_file_base().'/lang_custom/'.user_lang().'/'.$file)) && (preg_match('#^'.str_replace('#','\#',preg_quote($n)).'=#m',file_get_contents(get_custom_file_base().'/lang_custom/'.user_lang().'/'.$file))!=0)))
								{
									$lang_file=basename($file,'.ini');
									break;
								}
							}
						}
					}
				}

				$_url=build_url(array('page'=>'admin_lang','type'=>'misc','lang'=>user_lang(),'lang_file'=>$lang_file),'adminzone');
				$url=$_url->evaluate();
				$url.='#jmp_'.$n;
				$breadcrumbs=new ocp_tempcode();
				$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'style'),'adminzone'),do_lang_tempcode('STYLE')));
				$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
				$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_lang','type'=>'misc'),'adminzone'),do_lang_tempcode('TRANSLATE_CONTENT')));
				$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
				$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_lang','type'=>'misc','lang'=>user_lang(),'lang_file'=>$lang_file),'adminzone'),$lang_file));
				$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
				$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'cafa14d50ce6ecc1db1486017b364ce5','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>escape_html($n_value),'SUP'=>$sup)));
			}
			$lang_file_contents=array();
		}

		// Theme images
		$current_results_type=do_lang('MANAGE_THEME_IMAGES');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_themes','adminzone')))
		{
			$content[$current_results_type]=new ocp_tempcode();
			$images=$GLOBALS['SITE_DB']->query_select('theme_images',array('id','theme','lang'));
			foreach ($images as $image)
			{
				$n=$image['id'];
				if ($this->_keyword_match($n))
				{
					$_url=build_url(array('page'=>'admin_themes','type'=>'edit_image','theme'=>$image['theme'],'lang'=>$image['lang'],'id'=>$n),'adminzone');
					$breadcrumbs=new ocp_tempcode();
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'style'),'adminzone'),do_lang_tempcode('STYLE')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'misc'),'adminzone'),do_lang_tempcode('THEMES')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'edit_css','theme'=>$image['theme']),'adminzone'),do_lang_tempcode('EDIT_THEME_IMAGE')));
					$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
					$breadcrumbs->attach(escape_html($image['theme']));
					$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
					$lang=$image['lang'];
					$lang_map=better_parse_ini_file(file_exists(get_file_base().'/lang_custom/langs.ini')?(get_file_base().'/lang_custom/langs.ini'):(get_file_base().'/lang/langs.ini'));
					$lang=array_key_exists($lang,$lang_map)?$lang_map[$lang]:$lang;
					$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'68b418db6d3f7676cf1682a68f76f88a','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>$lang,'SUP'=>$sup)));
				}
			}
		}

		// Template names
		$current_results_type=do_lang('TEMPLATES');
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_themes','adminzone')))
		{
			$content[$current_results_type]=new ocp_tempcode();
			$tpl_found=array();
			foreach (array('templates_custom','templates') as $template_dir)
			{
				$dh=opendir(get_file_base().'/themes/default/'.$template_dir.'/');
				while (($file=readdir($dh))!==false)
				{
					if ((substr(strtolower($file),-4)=='.tpl') && (!array_key_exists($file,$tpl_found)))
					{
						$n=$file;
						if (($this->_keyword_match(basename($n,'.tpl'))) || ($this->_keyword_match($n)) || (($template_dir=='templates_custom') && ($this->_keyword_match(file_get_contents(get_file_base().'/themes/default/'.$template_dir.'/'.$n)))))
						{
							$_url=build_url(array('page'=>'admin_themes','type'=>'_edit_templates','theme'=>$default_theme,'f0file'=>$file),'adminzone');
							$breadcrumbs=new ocp_tempcode();
							$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'style'),'adminzone'),do_lang_tempcode('STYLE')));
							$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
							$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'misc'),'adminzone'),do_lang_tempcode('THEMES')));
							$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
							$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'edit_templates','theme'=>$default_theme),'adminzone'),do_lang_tempcode('EDIT_TEMPLATES')));
							$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
							$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'5cd222ad77fe4bfdf05b4856a5f7b8ac','NAME'=>$n,'URL'=>$_url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));
							$tpl_found[$file]=1;
						}
					}
				}
			}
		}

		// CSS file contents
		$current_results_type='CSS';
		if (($this->_section_match($section_limitations,$current_results_type)) && (has_actual_page_access(get_member(),'admin_themes','adminzone')))
		{
			$content[$current_results_type]=new ocp_tempcode();
			$dh=opendir(get_file_base().'/themes/default/css/');
			while (($file=readdir($dh))!==false)
			{
				if (substr(strtolower($file),-4)=='.css')
				{
					$n=$file;
					if ($this->_keyword_match(file_get_contents(get_file_base().'/themes/default/css/'.$n)))
					{
						$_url=build_url(array('page'=>'admin_themes','type'=>'edit_css','theme'=>$default_theme,'file'=>$file),'adminzone');
						$url=$_url->evaluate();
						if (isset($keywords[0]))
							$url.='#'.$keywords[0][0];
						$breadcrumbs=new ocp_tempcode();
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin','type'=>'style'),'adminzone'),do_lang_tempcode('STYLE')));
						$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'misc'),'adminzone'),do_lang_tempcode('THEMES')));
						$breadcrumbs->attach(do_template('BREADCRUMB_SEPARATOR'));
						$breadcrumbs->attach(hyperlink(build_url(array('page'=>'admin_themes','type'=>'choose_css','theme'=>$default_theme),'adminzone'),do_lang_tempcode('EDIT_CSS')));
						$sup=do_lang_tempcode('LOCATED_IN',$breadcrumbs);
						$content[$current_results_type]->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY',array('_GUID'=>'3ac82fa3d03b3367a03116f57993769b','NAME'=>$n,'URL'=>$url,'TITLE'=>'','DESCRIPTION'=>'','SUP'=>$sup)));
					}
				}
			}
		}

		//ksort($content);		Don't sort, we have an implicit good order in this code file

		// And show results...
		if (addon_installed('search'))
		{
			$_search_url=build_url(array('page'=>'search','type'=>'results','content'=>$raw_search_string,'days'=>'-1','search_comcode_pages'=>1,'all_defaults'=>1),get_module_zone('search'));
			$search_url=$_search_url->evaluate();
			$software_search_url=brand_base_url().'/site/index.php?page=search&type=results&search_under=docs&search_comcode_pages=1&days=-1&content='.urlencode($raw_search_string);
			$software_search_url_2=brand_base_url().'/site/index.php?page=search&type=results&search_ocf_posts=1&days=-1&content='.urlencode($raw_search_string);
			$pre=do_lang_tempcode('ADMINZONE_SEARCH_RESULTS',escape_html($raw_search_string),escape_html($search_url),array(escape_html($software_search_url),escape_html($software_search_url_2)));
		} else $pre=new ocp_tempcode();
		$found_some=false;
		foreach ($content as $c)
		{
			if (!$c->is_empty())
			{
				$found_some=true;
				break;
			}
		}
		$post=((strpos($raw_search_string,'"')!==false) || (!$found_some))?new ocp_tempcode():do_lang_tempcode('ADMINZONE_SEARCH_TIP',escape_html(preg_replace('#\s@\w+#','',$raw_search_string)));

		if ((!$found_some) && ($this->and_query)) // Oh well, try as an OR query then
		{
			$this->and_query=false;
			return $this->search();
		}

		return do_template('INDEX_SCREEN_FANCIER_SCREEN',array('TITLE'=>get_screen_title('ADMIN_ZONE_SEARCH_RESULTS'),'EMPTY'=>$found_some?NULL:true,'ARRAY'=>true,'CONTENT'=>$found_some?$content:array(),'PRE'=>$pre,'POST'=>$post));
	}

}


