PageRenderTime 177ms CodeModel.GetById 80ms app.highlight 65ms RepoModel.GetById 15ms app.codeStats 1ms

/search.php

https://github.com/CasperGemini/e107
PHP | 1497 lines | 866 code | 294 blank | 337 comment | 197 complexity | b30cd91e0a0a2f0da6ec1a2a3c4c00d7 MD5 | raw file
   1<?php
   2/*
   3 * e107 website system
   4 *
   5 * Copyright (C) 2008-2013 e107 Inc (e107.org)
   6 * Released under the terms and conditions of the
   7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
   8 *
   9 */
  10
  11require_once('class2.php');
  12e107::coreLan('search');
  13e107_require(e_HANDLER.'search_class.php');
  14
  15if (!check_class($pref['search_restrict'])) 
  16{
  17	require_once(HEADERF);
  18	$ns->tablerender(LAN_SEARCH_20, "<div style='text-align: center'>".LAN_SEARCH_21."</div>");
  19	require_once(FOOTERF);
  20	exit;
  21}
  22
  23if (isset($_GET['t']) && is_numeric($_GET['t']))
  24{
  25  switch ($_GET['t'])
  26  {
  27	case '0' : 
  28	  $_GET['t'] = 'news';
  29	  break;
  30	case 1 :
  31	  $_GET['t'] = 'comments';
  32	  break;
  33	case  2 :
  34	  $_GET['t'] = 'users';
  35	  break;
  36	case 3 :
  37	  $_GET['t'] = 'downloads';
  38	  break;
  39	case 4 :
  40	  $_GET['t'] = 'pages';
  41	  break;
  42  }
  43}
  44
  45
  46class search extends e_shortcode
  47{
  48	
  49	private $search_prefs = array();
  50	private $search_info = array();
  51	private $auto_order = 1000;
  52	private $enhanced = false;
  53	private $query = null;
  54	private $result_flag = 0;
  55	private $message = '';
  56	public 	$template = array();
  57	private $enhancedTypes = array(
  58								'in' => LAN_SEARCH_24,
  59								'ex' => LAN_SEARCH_25,
  60								'ep' => LAN_SEARCH_26,
  61								'be' => LAN_SEARCH_27
  62							);
  63	
  64	function __construct()
  65	{
  66		$this->search_prefs = e107::getConfig('search')->getPref();		
  67		$this->search_info 	= $this->searchConfig();
  68		
  69		
  70		if(deftrue('BOOTSTRAP'))
  71		{
  72			$tmp 				= e107::getCoreTemplate('search','form');
  73			$SEARCH_TOP_TABLE 	= $tmp['start'];
  74			$SEARCH_BOT_TABLE 	= $tmp['end'];
  75			$SEARCH_CATS		= $tmp['category'];
  76			$SEARCH_TYPE		= $tmp['type'];
  77			$SEARCH_ADV			= $tmp['advanced'];
  78			$SEARCH_ENHANCED	= $tmp['enhanced'];
  79			$SEARCH_ADV_COMBO	= $tmp['advanced-combo'];
  80			
  81			$this->template = $tmp;
  82		
  83			
  84			
  85			unset($tmp);
  86		}
  87		else
  88		{
  89			if (file_exists(THEME."search_template.php")) 
  90			{
  91				require(THEME."search_template.php");
  92			} 
  93			else 
  94			{
  95				require(e_CORE."templates/search_template.php");
  96			}
  97			
  98			$SEARCH_TOP_TABLE .= "{SEARCH_ENHANCED}";
  99			
 100			$tmp = array();
 101			
 102			$tmp['start']  			= $SEARCH_TOP_TABLE ;
 103			$tmp['end'] 			= $SEARCH_BOT_TABLE ;
 104			$tmp['category'] 		= $SEARCH_CATS;
 105			$tmp['type'] 			= $SEARCH_TYPE;
 106			$tmp['advanced'] 		= $SEARCH_ADV;
 107			$tmp['enhanced'] 		= $SEARCH_ENHANCED;
 108			$tmp['advanced-combo'] 	= $SEARCH_ADV_COMBO;
 109			
 110			$this->template = $tmp;
 111		}
 112
 113	
 114
 115
 116
 117		if(e_AJAX_REQUEST)
 118		{
 119			if(vartrue($_POST['t']))
 120			{
 121				echo $this->sc_search_advanced_block($_POST['t']);
 122			}
 123			
 124			exit;
 125		}
 126
 127	}
 128
 129	function getPrefs()
 130	{
 131		return $this->search_prefs;	
 132	}
 133
 134
 135	function getConfig()
 136	{
 137		return $this->search_info;	
 138	}
 139	
 140	// Shortcodes  -----------------------
 141	
 142	function sc_search_main($parm = '')
 143	{
 144		$tp = e107::getParser();
 145		$value = isset($_GET['q']) ? $tp->post_toForm($_GET['q']) : "";
 146		
 147		$text = "<div class='input-group'>
 148		<input class='tbox form-control m_search' type='text' id='q' name='q' size='35' value='".$value."' maxlength='50' />
 149		<div class='input-group-btn'>
 150		<button class='btn btn-primary' type='submit' name='s' value='1' >".$tp->toGlyph('search',false)."</button>
 151		<button class='btn btn-primary dropdown-toggle' tabindex='-1' data-toggle='dropdown' type='button'><span class='caret'></span></button>
 152		";
 153		
 154		$text .= '<ul class="dropdown-menu pull-right">
 155          <li><a class="e-expandit" href="#" data-target="search-advanced,search-enhanced"><small>'.LAN_SEARCH_202.'</small></a></li>
 156        </ul>';
 157		
 158		$text .= "
 159		</div>
 160		
 161		</div>
 162		<input type='hidden' name='r' value='0' />";
 163		
 164		return $text;		
 165		
 166	}
 167
 168	function sc_search_main_searchfield($parm='')
 169	{
 170		$tp = e107::getParser();
 171		$value = isset($_GET['q']) ? $tp->post_toForm($_GET['q']) : "";
 172		return "<input class='tbox form-control m_search' type='text' id='q' name='q' size='35' value='".$value."' maxlength='50' />";	
 173	}	
 174	
 175	function sc_search_main_submit($parm='')
 176	{
 177		return "<input class='btn btn-primary button' type='submit' name='s' value='".LAN_180."' />
 178		<input type='hidden' name='r' value='0' />";
 179	}
 180	
 181	function sc_enhanced_icon($parm='')
 182	{
 183		return  "<img src='".e_IMAGE_ABS."generic/search_basic.png' style='width: 16px; height: 16px; vertical-align: top' alt='".LAN_SEARCH_23."' title='".LAN_SEARCH_23."' onclick=\"expandit('en_in'); expandit('en_ex'); expandit('en_ep'); expandit('en_be')\"/>";
 184	}
 185	
 186	function sc_search_main_checkall($parm='')
 187	{
 188		 if($this->search_prefs['selector'] == 1) 
 189		 {
 190		 	return "<input class='btn btn-default button' type='button' name='CheckAll' value='".LAN_SEARCH_1."' onclick='checkAll(this);' />";	
 191		 }
 192	}
 193
 194	function sc_search_main_uncheckall($parm='')
 195	{
 196		 if($this->search_prefs['selector'] == 1) 
 197		 {
 198		 	return "<input class='btn btn-default button' type='button' name='UnCheckAll' value='".LAN_SEARCH_2."' onclick='uncheckAll(this); uncheckG();' />";
 199		 }	
 200	}
 201	
 202	function sc_search_type_sel($parm='')
 203	{
 204		return e107::getForm()->radio_switch('adv', vartrue($_GET['adv']), LAN_SEARCH_30, LAN_SEARCH_29, array('class'=>'e-expandit','reverse'=>1, 'data-target'=>'search-advanced'));
 205		
 206		
 207		
 208		return "<input type='radio' name='adv' value='0' ".(varsettrue($_GET['adv']) ? "" : "checked='checked'")." /> ".LAN_SEARCH_29."&nbsp;
 209		<input type='radio' name='adv' value='1' ".(varsettrue($_GET['adv']) ? "checked='checked'" : "" )." /> ".LAN_SEARCH_30;	
 210	}
 211	
 212	function sc_search_dropdown($parm = '')
 213	{
 214		return $this->selectElement('dropdown');
 215	}
 216	
 217	function sc_search_main_checkboxes($parm = '')
 218	{
 219		return $this->selectElement('checkboxes');
 220	}
 221	
 222	function sc_search_message($parm = '')
 223	{
 224		return $this->message;	
 225	}
 226
 227	private function selectElement($parm)
 228	{
 229		// standard search config
 230		if ($this->search_prefs['selector'] == 2) 
 231		{
 232			$dropdown = "<select name='t' id='t' class='tbox form-control e-ajax' data-src='".e_SELF."' data-target='search-advanced' >";
 233			
 234			if ($this->search_prefs['multisearch']) 
 235			{
 236				$dropdown .= "<option value='all'>".LAN_SEARCH_22."</option>";
 237			}
 238		} 
 239		else 
 240		{
 241		  $checkboxes = '';
 242		}
 243		
 244		foreach($this->search_info as $key => $value) 
 245		{
 246			if ($this->search_prefs['selector'] == 2) 
 247			{
 248				$sel = (isset($this->searchtype[$key]) && $this->searchtype[$key]) ? " selected='selected'" : "";
 249			} 
 250			else 
 251			{
 252				$sel = (isset($this->searchtype[$key]) && $this->searchtype[$key]) ? " checked='checked'" : "";
 253			}
 254			
 255			$google_js = check_class($this->search_prefs['google']) ? "onclick=\"uncheckG();\" " : "";
 256			
 257			if ($this->search_prefs['selector'] == 2) 
 258			{
 259				$dropdown .= "<option value='".$key."' ".$sel.">".$value['qtype']."</option>";
 260			} 
 261			else if ($this->search_prefs['selector'] == 1) 
 262			{
 263				$checkboxes .= $PRE_CHECKBOXES."<input ".$google_js." type='checkbox' name='t[".$key."]' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
 264			} 
 265			else 
 266			{
 267				$checkboxes .= $PRE_CHECKBOXES."<input type='radio' name='t' value='".$key."' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
 268			}
 269		}
 270		
 271		if (check_class($this->search_prefs['google'])) 
 272		{
 273			if ($this->search_prefs['selector'] == 2) 
 274			{
 275				$dropdown .= "<option value='".$google_id."'>Google</option>"; //FIXME googleid
 276			} 
 277			else if 
 278			($this->search_prefs['selector'] == 1)  //FIXME PRE_CHECKBOXES and POST_CHECKBOXES
 279			{
 280				$checkboxes .= $PRE_CHECKBOXES."<input id='google' type='checkbox' name='t[".$google_id."]' onclick='uncheckAll(this)' />Google".$POST_CHECKBOXES;
 281			} 
 282			else 
 283			{
 284				$checkboxes .= $PRE_CHECKBOXES."<input id='google' type='radio' name='t' value='".$google_id."' />Google".$POST_CHECKBOXES;
 285			}
 286		}
 287		
 288		if ($this->search_prefs['selector'] == 2) 
 289		{
 290			$dropdown .= "</select>";
 291		}
 292		
 293		if($parm == 'dropdown')
 294		{
 295			return $dropdown;	
 296		}
 297		else 
 298		{
 299			return $checkboxes;
 300		}
 301	
 302		
 303	}
 304
 305	function sc_search_enhanced()
 306	{
 307		
 308		$tp = e107::getParser();
 309		
 310		$text = '';
 311		$var = array();
 312		
 313		foreach ($this->enhancedTypes as $en_id => $ENHANCED_TEXT) 
 314		{
 315			$var['ENHANCED_TEXT'] 		= $ENHANCED_TEXT;
 316			$var['ENHANCED_DISPLAY_ID'] = "en_".$en_id;
 317			$var['ENHANCED_FIELD'] 		= "<input class='tbox form-control' type='text' id='".$en_id."' name='".$en_id."' size='35' value='".$tp->post_toForm($_GET[$en_id])."' maxlength='50' />";
 318		
 319			$text .= $tp->simpleParse($this->template['enhanced'], $var);
 320		}
 321		
 322		return $text;
 323	}
 324
 325
 326	function sc_enhanced_display()
 327	{
 328		return ($this->enhanced !== true) ?  "style='display: none'" : "" ;
 329	}
 330		
 331	function sc_search_advanced_block($parm='')
 332	{
 333		$tp = e107::getParser();
 334		$sql = e107::getDb();
 335		$sql2 = e107::getDb('search');
 336		
 337			
 338		if(!$parm)
 339		{
 340		//	return;	
 341		}	
 342			
 343		
 344		if (isset($this->search_info[$parm]['advanced'])) 
 345		{
 346			
 347			if(is_array($this->search_info[$parm]['advanced']))
 348			{
 349				$advanced  = ($this->search_info[$parm]['advanced']);
 350			}
 351			elseif(isset($this->search_info[$parm]['advanced']))
 352			{
 353				require($this->search_info[$parm]['advanced']); 
 354				
 355			}
 356			
 357			$vars = array();
 358			
 359			
 360			
 361			foreach ($advanced as $adv_key => $adv_value) 
 362			{
 363				if ($adv_value['type'] == 'single') 
 364				{
 365					$vars['SEARCH_ADV_TEXT'] = $adv_value['text'];
 366					$text .= $tp->simpleParse($this->template['advanced-combo'], $vars);
 367				} 
 368				else 
 369				{
 370					if ($adv_value['type'] == 'dropdown') 
 371					{
 372						$vars['SEARCH_ADV_A'] = $adv_value['text'];
 373						$vars['SEARCH_ADV_B'] = "<select name='".$adv_key."' class='tbox form-control'>";
 374						
 375						foreach ($adv_value['list'] as $list_item) 
 376						{
 377							$vars['SEARCH_ADV_B'] .= "<option value='".$list_item['id']."' ".($_GET[$adv_key] == $list_item['id'] ? "selected='selected'" : "").">".$list_item['title']."</option>";
 378						}
 379						$vars['SEARCH_ADV_B'] .= "</select>";
 380					} 
 381					else if ($adv_value['type'] == 'date') 
 382					{
 383						$vars['SEARCH_ADV_A'] = $adv_value['text'];
 384						$vars['SEARCH_ADV_B'] = "
 385						
 386						<div class='form-inline'>
 387						<select id='on' name='on' class='tbox form-control '>
 388						<option value='new' ".($_GET['on'] == 'new' ? "selected='selected'" : "").">".LAN_SEARCH_34."</option>
 389						<option value='old' ".($_GET['on'] == 'old' ? "selected='selected'" : "").">".LAN_SEARCH_35."</option>
 390						</select>&nbsp;
 391					
 392						<select id='time' name='time' class='tbox form-control '>";
 393						
 394						$time = array(LAN_SEARCH_36 => 'any', LAN_SEARCH_37 => 86400, LAN_SEARCH_38 => 172800, LAN_SEARCH_39 => 259200, LAN_SEARCH_40 => 604800, LAN_SEARCH_41 => 1209600, LAN_SEARCH_42 => 1814400, LAN_SEARCH_43 => 2628000, LAN_SEARCH_44 => 5256000, LAN_SEARCH_45 => 7884000, LAN_SEARCH_46 => 15768000, LAN_SEARCH_47 => 31536000, LAN_SEARCH_48 => 63072000, LAN_SEARCH_49 => 94608000);
 395						
 396						foreach ($time as $time_title => $time_secs) 
 397						{
 398							$vars['SEARCH_ADV_B'] .= "<option value='".$time_secs."' ".($_GET['time'] == $time_secs ? "selected='selected'" : "").">".$time_title."</option>";
 399						}
 400						
 401						$vars['SEARCH_ADV_B'] .= "</select>
 402						</div>";
 403					} 
 404					else if ($adv_value['type'] == 'author') 
 405					{
 406					//	require_once(e_HANDLER.'user_select_class.php');
 407						
 408					//	$us = new user_select;
 409						$vars['SEARCH_ADV_A'] = $adv_value['text'];
 410						$vars['SEARCH_ADV_B'] = e107::getForm()->userpicker($adv_key."_name",$adv_key,$_GET[$adv_key]); // $us -> select_form('popup', $adv_key, $_GET[$adv_key]);
 411						
 412						
 413						
 414					} 
 415					else if ($adv_value['type'] == 'dual') 
 416					{
 417						$vars['SEARCH_ADV_A'] = $adv_value['adv_a'];
 418						$vars['SEARCH_ADV_B'] = $adv_value['adv_b'];
 419					}
 420			
 421					$text .= $tp->simpleParse($this->template['advanced'], $vars);
 422				}
 423			}
 424	
 425			
 426		} 
 427		else 
 428		{
 429			$_GET['adv'] = 0;
 430		}
 431		
 432		
 433		return $text;
 434	}
 435				
 436				
 437			
 438			
 439		
 440
 441	// -------------
 442	
 443	
 444	
 445	function searchPrefs()
 446	{
 447		return $this->search_prefs;	
 448	}
 449
 450
 451	
 452	function search_info($id, $type, $plug_require=null, $info='') 
 453	{
 454		$tp = e107::getParser();
 455		
 456		if (check_class($this->search_prefs[$type.'_handlers'][$id]['class'])) 
 457		{
 458	//		echo "<br />type = ".$this->search_prefs[$type.'_handlers'][$id]['class'];
 459			
 460	//		print_a($this->search_prefs);
 461			
 462			if ($plug_require) 
 463			{
 464				require_once($plug_require);
 465				$ret = $search_info[0];
 466			} 
 467			else 
 468			{
 469				$ret = $info;
 470			}
 471			
 472			if($obj = e107::getAddon($id,'e_search'))
 473			{
 474				if(!$ret = $obj->config())
 475				{
 476					return false;
 477				}	
 478				
 479				$ret['qtype'] = $ret['name'];
 480				
 481				if(!isset($ret['id']))
 482				{
 483					$ret['id'] = $ret['name'];	
 484				}
 485				
 486				$ret['weights'] = array_values($ret['search_fields']);
 487				$ret['search_fields'] = array_keys($ret['search_fields']);
 488	
 489			}	
 490			
 491			
 492			$ret['chars'] 			= $this->search_prefs[$type.'_handlers'][$id]['chars'];
 493			$ret['results'] 		= $this->search_prefs[$type.'_handlers'][$id]['results'];
 494			$ret['pre_title'] 		= $this->search_prefs[$type.'_handlers'][$id]['pre_title'];
 495			$ret['pre_title_alt'] 	= $tp -> toHtml($this->search_prefs[$type.'_handlers'][$id]['pre_title_alt']);
 496			$ret['order'] 			= (isset($this->search_prefs[$type.'_handlers'][$id]['order']) && $this->search_prefs[$type.'_handlers'][$id]['order']) ? $this->search_prefs[$type.'_handlers'][$id]['order'] : $this->auto_order;
 497			
 498			$this->auto_order++;
 499			
 500			return $ret;
 501		} 
 502		else 
 503		{
 504			return false;
 505		}
 506	}
 507	
 508
 509
 510	
 511	// Get Core and Plugin search configurations
 512	function searchConfig()
 513	{
 514		
 515		
 516		//core search routines
 517		
 518		$search_info = array();
 519		
 520		/*
 521		if ($search_info['news'] = $this->search_info('news', 'core', false, array('sfile' => e_HANDLER.'search/search_news.php', 'qtype' => LAN_SEARCH_98, 'refpage' => 'news.php', 'advanced' => e_HANDLER.'search/advanced_news.php', 'id' => 'news'))) {
 522		   //	$search_id++;
 523		} else {
 524			unset($search_info['news']);
 525		}
 526		*/
 527		if(e107::getConfig('core')->get('comments_disabled')!=1)  // Only when comments are enabled.
 528		{
 529			if ($search_info['comments'] = $this->search_info('comments', 'core', false, array('sfile' => e_HANDLER.'search/search_comment.php', 'qtype' => LAN_SEARCH_99, 'refpage' => 'comment.php', 'advanced' => e_HANDLER.'search/advanced_comment.php', 'id' => 'comment'))) {
 530			   //	$search_id++;
 531			} else {
 532				unset($search_info['comments']);
 533			}
 534		}
 535		
 536		
 537		if(e107::getConfig('core')->get('user_reg')==1) // Only when user-registration is enabled.
 538		{
 539			if ($search_info['users'] = $this->search_info('users', 'core', false, array('sfile' => e_HANDLER.'search/search_user.php', 'qtype' => LAN_140, 'refpage' => 'user.php', 'advanced' => e_HANDLER.'search/advanced_user.php', 'id' => 'user'))) {
 540				//	$search_id++;
 541			} else {
 542				unset($search_info['users']);
 543			}
 544		}
 545		
 546		
 547		if ($search_info['pages'] = $this->search_info('pages', 'core', false, array('sfile' => e_HANDLER.'search/search_pages.php', 'qtype' => LAN_418, 'refpage' => 'page.php', 'advanced' => e_HANDLER.'search/advanced_pages.php', 'id' => 'pages'))) {
 548		   //	$search_id++;
 549		} else {
 550			unset($search_info['pages']);
 551		}
 552		
 553		 $e_searchList = e107::getConfig('core')->get('e_search_list');
 554		
 555		
 556		//plugin search routines    // plugin folder is used as the search key. ie. $_GET['t'] = 'chatbox';
 557		foreach ($this->search_prefs['plug_handlers'] as $plug_dir => $active) 
 558		{
 559			if(isset($search_info[$plug_dir]))
 560			{
 561				continue;
 562			}
 563			
 564			if (in_array($plug_dir,$e_searchList) && is_readable(e_PLUGIN.$plug_dir."/e_search.php"))
 565			{
 566				if ($search_info[$plug_dir] = $this->search_info($plug_dir, 'plug', e_PLUGIN.$plug_dir."/e_search.php"))
 567				{
 568				  //	$search_id++;
 569				}
 570				else
 571				{
 572					unset($search_info[$plug_dir]);
 573				}
 574			}
 575			
 576			
 577		}
 578		
 579		// order search routines
 580		
 581		 $search_info = $this->array_sort($search_info, 'order', SORT_ASC);	
 582		 
 583		 $this->search_info = $search_info;
 584		 
 585		// print_a($this->search_prefs);
 586		// print_a($this->search_info);
 587		 
 588		 return $search_info;
 589	}	
 590
 591
 592
 593
 594	// determine areas being searched
 595	public function searchType()
 596	{
 597		$searchtype = array();	
 598			
 599		if (!$this->search_prefs['user_select'] && $_GET['r'] < 1) 
 600		{
 601			foreach($this->search_info as $key => $value) 
 602			{
 603				$searchtype[$key] = true;
 604			}
 605		}
 606		 else 
 607		 {
 608			if (isset($_GET['t'])) 
 609			{
 610				if (is_array($_GET['t'])) 
 611				{
 612					$searchtype = $_GET['t'];
 613				} 
 614				else 
 615				{
 616					$searchtype[$_GET['t']] = true;
 617				}
 618			} 
 619			else 
 620			{
 621				if (isset($_GET['ref'])) 
 622				{
 623					foreach($this->search_info as $key => $value) 
 624					{
 625						if ($value['id'] == $_GET['ref']) 
 626						{
 627							$searchtype[$key] = true;
 628							$_GET['t'] = $key;
 629						}
 630					}
 631				} 
 632				else if (e_QUERY) 
 633				{
 634					if (isset($_SERVER['HTTP_REFERER'])) 
 635					{
 636						if (!$refpage = substr($_SERVER['HTTP_REFERER'], (strrpos($_SERVER['HTTP_REFERER'], "/")+1))) 
 637						{
 638							$refpage = "index.php";
 639						}
 640					} 
 641					else 
 642					{
 643						$refpage = "";
 644					}
 645		
 646					foreach($this->search_info as $key=>$value) 
 647					{
 648						if ($value['refpage']) 
 649						{
 650							if (strpos($refpage, $value['refpage']) !== FALSE) 
 651							{
 652								$searchtype[$key] = true;
 653								$_GET['t'] = $key;
 654							}
 655						}
 656					}
 657				}
 658		
 659				if (!isset($this->searchtype) && isset($this->query)) 
 660				{
 661					if ($this->search_prefs['multisearch']) 
 662					{
 663						$searchtype['all'] = true;
 664					} 
 665					else 
 666					{
 667						$searchtype[0] = true;
 668					}
 669				}
 670			}
 671		}	
 672		
 673		$this->searchtype = $searchtype;
 674		
 675		return $searchtype;
 676	}
 677
 678
 679
 680
 681
 682	function array_sort($array, $column, $order = SORT_DESC) 
 683	{
 684		$i = 0;
 685		foreach($array as $info) {
 686			$sortarr[] = $info[$column];
 687			$i++;
 688		}
 689	 	array_multisort($sortarr, $order, $array, $order);
 690		return($array);
 691	}	
 692	
 693	
 694	
 695	
 696	function renderResults()
 697	{
 698		global $query, $search_prefs, $pre_title, $search_chars, $search_res, $result_flag;
 699		
 700		$ns = e107::getRender();
 701		$sch = new e_search;
 702		$tp = e107::getParser();
 703		 
 704		
 705		$query = $this->query;
 706		
 707		$_GET['q'] = rawurlencode($_GET['q']);
 708		$_GET['t'] = preg_replace('/[^\w\-]/i', '', $_GET['t']);
 709		
 710		$search_prefs	= $this->search_prefs;
 711		$result_flag	= $this->result_flag;
 712		
 713		foreach ($this->search_info as $key => $a) 
 714		{
 715			if (isset($this->searchtype[$key]) || isset($this->searchtype['all'])) 
 716			{
 717				
 718				unset($text);
 719				//if (file_exists($this->search_info[$key]['sfile'])) 
 720				{
 721					$pre_title 		= ($this->search_info[$key]['pre_title'] == 2) ? $this->search_info[$key]['pre_title_alt'] : $this->search_info[$key]['pre_title'];
 722					$search_chars 	= $this->search_info[$key]['chars'];
 723					$search_res 	= $this->search_info[$key]['results'];
 724			
 725					if(vartrue($this->search_info[$key]['sfile']) && file_exists($this->search_info[$key]['sfile'])) // Legacy
 726					{
 727						$text .= '<div class="search-block">';
 728						require_once($this->search_info[$key]['sfile']);
 729						$text .= '</div>';
 730					}
 731					else// New v2 standard. @see chatbox_menu/e_search.php
 732					{
 733						
 734						$className = $key."_search";
 735						
 736						if(!class_exists($className))
 737						{
 738							continue;
 739						}
 740						$obj = new $className;
 741	
 742						$where = (method_exists($obj,'where')) ? $obj->where($_GET) : "";
 743						
 744						$ps = $obj->parsesearch($this->search_info[$key]['table'], $this->search_info[$key]['return_fields'], $this->search_info[$key]['search_fields'], $this->search_info[$key]['weights'], 'self', varset($this->search_info[$key]['no_results'],LAN_198), $where , $this->search_info[$key]['order']);
 745						
 746						$text .= '<div class="search-block">';
 747						$text .= $ps['text'];
 748						$text .= '</div>';
 749						$results = $ps['results'];	
 750						
 751					}
 752					
 753					
 754				//	$parms = $results.",".$search_res.",".$_GET['r'].",".e_REQUEST_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]";
 755					
 756					$nextprev = array(
 757								'total'			=> $results,
 758								'amount'		=> intval($search_res),
 759								'current'		=> intval($_GET['r']),
 760								'url'			=> urldecode(e_REQUEST_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]"),
 761							//	'caption'		=> false,
 762								'tmpl_prefix'	=>'default'
 763					);
 764					
 765					$npParms = http_build_query($nextprev,false,'&');
 766					
 767					$core_parms = array('r' => '', 'q' => '', 't' => '', 's' => '');
 768					foreach ($_GET as $pparm_key => $pparm_value) 
 769					{
 770						$temp = preg_replace('/[^\w_]/i','',$pparm_key);
 771						$temp1 = preg_replace('/[^\w_ +]/i','',$pparm_value);		// Filter 'non-word' charcters in search term
 772						if (($temp == $pparm_key) && !isset($core_parms[$pparm_key])) 
 773						{
 774							$parms .= "&".$pparm_key."=".$temp1;
 775						}
 776					}
 777					if ($results > $search_res) 
 778					{
 779						$nextprev = ($results > $search_res) ? $tp -> parseTemplate("{NEXTPREV={$npParms}}") : "";
 780						$text .= "<div class='nextprev search form-inline'>".$nextprev."</div>";
 781					}
 782					if ($results > 0) 
 783					{
 784						$res_from = $_GET['r'] + 1;
 785						$res_to = ($_GET['r'] + $search_res) > $results ? $results : ($_GET['r'] + $search_res);
 786						$res_display = $res_from." - ".$res_to." ".LAN_SEARCH_12." ".$results;
 787					} 
 788					else 
 789					{
 790						$res_display = "";
 791					}
 792					
 793					$ns->tablerender(LAN_SEARCH_11." ".$res_display." ".LAN_SEARCH_13." ".(isset($_GET[$advanced_caption['id']]) ? $advanced_caption['title'][$_GET[$advanced_caption['id']]] : $this->search_info[$key]['qtype']), $text, 'search_result');
 794				}
 795			}
 796		}
 797
 798	}
 799		
 800		
 801		
 802	function magic_search($data) 
 803	{
 804		foreach ($data as $key => $value) {
 805			if (is_array($value)) {
 806				$data[$key] = $this->magic_search($value);
 807			} else {
 808				$data[$key] = stripslashes($value);
 809			}
 810		}
 811		return $data;
 812	}
 813	
 814		
 815	function searchQuery()
 816	{
 817		global $perform_search;
 818		
 819		if (isset($_GET['q']) || isset($_GET['in']) || isset($_GET['ex']) || isset($_GET['ep']) || isset($_GET['beg'])) 
 820		{
 821			if (MAGIC_QUOTES_GPC == true) 
 822			{
 823				$_GET = $this->magic_search($_GET);
 824			}
 825			
 826			$full_query = $_GET['q'];
 827			
 828			if ($_GET['in']) 
 829			{
 830				$en_in = explode(' ', $_GET['in']);
 831				foreach ($en_in as $en_in_key) 
 832				{
 833					$full_query .= " +".$en_in_key;
 834				}
 835				$this->enhanced = true;
 836			}
 837			if ($_GET['ex']) 
 838			{
 839				$en_ex = explode(' ', $_GET['ex']);
 840				foreach ($en_ex as $en_ex_key) 
 841				{
 842					$full_query .= " -".$en_ex_key;
 843				}
 844				$this->enhanced = true;
 845			}
 846			if ($_GET['ep']) 
 847			{
 848				$full_query .= " \"".$_GET['ep']."\"";
 849				$this->enhanced = true;
 850			}
 851			if ($_GET['be']) 
 852			{
 853				$en_be = explode(' ', $_GET['be']);
 854				foreach ($en_be as $en_be_key) 
 855				{
 856					$full_query .= " ".$en_be_key."*";
 857				}
 858				$this->enhanced = true;
 859			}
 860		
 861			if (isset($_GET['r']) && !is_numeric($_GET['r'])) 
 862			{
 863				$perform_search = false;
 864				$this->message = LAN_SEARCH_201;
 865				$this->result_flag = 0;
 866			} 
 867			else if (strlen($full_query) == 0) 
 868			{
 869				$perform_search = false;
 870				$this->message = LAN_SEARCH_201;
 871			} 
 872			elseif (strlen($full_query) < ($char_count = ($this->search_prefs['mysql_sort'] ? 4 : 3))) 
 873			{
 874				$perform_search = false;
 875				$this->message = str_replace('--CHARS--', $char_count, LAN_417);
 876			} 
 877			elseif ($this->search_prefs['time_restrict']) 
 878			{
 879				$time = time() - $this->search_prefs['time_secs'];
 880				$query_check = $tp -> toDB($full_query);
 881				$ip = e107::getIPHandler()->getIP(FALSE);
 882				
 883				if ($sql->select("tmp", "tmp_ip, tmp_time, tmp_info", "tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'")) 
 884				{
 885					$row = $sql->fetch();
 886					if (($row['tmp_time'] > $time) && ($row['tmp_info'] != 'type_search '.$query_check)) 
 887					{
 888						$perform_search = false;
 889						$this->message = LAN_SEARCH_17.$search_prefs['time_secs'].LAN_SEARCH_18;
 890					} 
 891					else 
 892					{
 893						$sql->update("tmp", "tmp_time='".time()."', tmp_info='type_search ".$query_check."' WHERE tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'");
 894					}
 895				} 
 896				else 
 897				{
 898					$sql->insert("tmp", "'".$ip."', '".time()."', 'type_search ".$query_check."'");
 899				}
 900			}
 901			
 902			if ($perform_search) 
 903			{
 904				$this->result_flag = intval($_GET['r']);
 905			}
 906
 907			$query = trim($full_query);
 908			
 909			$this->query = $query;
 910			
 911			return $query;
 912		}	
 913		
 914		
 915		
 916	}	
 917	
 918	
 919	
 920}
 921
 922
 923$srchObj 		= new search;
 924$search_info 	= $srchObj->getConfig();
 925$search_prefs	= $srchObj->getPrefs();
 926
 927// validate search query
 928$perform_search = true;
 929
 930// simple parse object
 931$SEARCH_VARS = new e_vars();
 932
 933/*
 934function magic_search($data) {
 935	foreach ($data as $key => $value) {
 936		if (is_array($value)) {
 937			$data[$key] = magic_search($value);
 938		} else {
 939			$data[$key] = stripslashes($value);
 940		}
 941	}
 942	return $data;
 943}
 944
 945if (!e_QUERY) {
 946	$enhanced = true;
 947}
 948*/
 949
 950/*
 951
 952if (isset($_GET['q']) || isset($_GET['in']) || isset($_GET['ex']) || isset($_GET['ep']) || isset($_GET['beg'])) {
 953	if (MAGIC_QUOTES_GPC == true) {
 954		$_GET = magic_search($_GET);
 955	}
 956	$full_query = $_GET['q'];
 957	if ($_GET['in']) {
 958		$en_in = explode(' ', $_GET['in']);
 959		foreach ($en_in as $en_in_key) {
 960			$full_query .= " +".$en_in_key;
 961		}
 962		$enhanced = true;
 963	}
 964	if ($_GET['ex']) {
 965		$en_ex = explode(' ', $_GET['ex']);
 966		foreach ($en_ex as $en_ex_key) {
 967			$full_query .= " -".$en_ex_key;
 968		}
 969		$enhanced = true;
 970	}
 971	if ($_GET['ep']) {
 972		$full_query .= " \"".$_GET['ep']."\"";
 973		$enhanced = true;
 974	}
 975	if ($_GET['be']) {
 976		$en_be = explode(' ', $_GET['be']);
 977		foreach ($en_be as $en_be_key) {
 978			$full_query .= " ".$en_be_key."*";
 979		}
 980		$enhanced = true;
 981	}
 982
 983	if (isset($_GET['r']) && !is_numeric($_GET['r'])) {
 984		$perform_search = false;
 985		$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_201;
 986		$result_flag = 0;
 987	} else if (strlen($full_query) == 0) {
 988		$perform_search = false;
 989		$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_201;
 990	} 
 991	elseif (strlen($full_query) < ($char_count = ($search_prefs['mysql_sort'] ? 4 : 3))) 
 992	{
 993		$perform_search = false;
 994		$SEARCH_VARS->SEARCH_MESSAGE = str_replace('--CHARS--', $char_count, LAN_417);
 995	} 
 996	elseif ($search_prefs['time_restrict']) {
 997		$time = time() - $search_prefs['time_secs'];
 998		$query_check = $tp -> toDB($full_query);
 999		$ip = e107::getIPHandler()->getIP(FALSE);
1000		if ($sql -> db_Select("tmp", "tmp_ip, tmp_time, tmp_info", "tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'")) {
1001			$row = $sql -> db_Fetch();
1002			if (($row['tmp_time'] > $time) && ($row['tmp_info'] != 'type_search '.$query_check)) {
1003				$perform_search = false;
1004				$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_17.$search_prefs['time_secs'].LAN_SEARCH_18;
1005			} else {
1006				$sql -> db_Update("tmp", "tmp_time='".time()."', tmp_info='type_search ".$query_check."' WHERE tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'");
1007			}
1008		} else {
1009			$sql -> db_Insert("tmp", "'".$ip."', '".time()."', 'type_search ".$query_check."'");
1010		}
1011	}
1012	if ($perform_search) {
1013		$result_flag = $_GET['r'];
1014	}
1015	$query = trim($full_query);
1016}*/
1017
1018
1019$query =  $srchObj->searchQuery();
1020
1021
1022// forward user if searching in google
1023$search_count = count($search_info);
1024$google_id = $search_count + 1;
1025
1026
1027
1028
1029if ($perform_search)
1030{
1031  if ($search_prefs['selector'] == 1) 
1032  {  // Care needed - with alpha strings on search of single area $_GET['t'][$google_id] returns a character on page > 1
1033	if (isset($_GET['t'][$google_id]) && ($_GET['t']==$google_id) && $_GET['t'][$google_id]) 
1034	{
1035//	echo "We think google should be used using checkboxes<br />";
1036		header("location:http://www.google.com/search?q=".stripslashes(str_replace(" ", "+", $query)));
1037		exit;
1038	}
1039  } 
1040  else 
1041  { 
1042	if (isset($_GET['t']) && $_GET['t'] == $google_id) 
1043	{
1044		header("location:http://www.google.com/search?q=".stripslashes(str_replace(" ", "+", $query)));
1045		exit;
1046	}
1047  }
1048}
1049
1050$searchtype = $srchObj->searchType();
1051
1052
1053
1054
1055// determine areas being searched
1056/*
1057if (!$search_prefs['user_select'] && $_GET['r'] < 1) {
1058	foreach($search_info as $key => $value) {
1059		$searchtype[$key] = true;
1060	}
1061} else {
1062	if (isset($_GET['t'])) {
1063		if (is_array($_GET['t'])) {
1064			$searchtype = $_GET['t'];
1065		} else {
1066			$searchtype[$_GET['t']] = true;
1067		}
1068	} else {
1069		if (isset($_GET['ref'])) {
1070			foreach($search_info as $key => $value) {
1071				if ($value['id'] == $_GET['ref']) {
1072					$searchtype[$key] = true;
1073					$_GET['t'] = $key;
1074				}
1075			}
1076		} else if (e_QUERY) {
1077			if (isset($_SERVER['HTTP_REFERER'])) {
1078				if (!$refpage = substr($_SERVER['HTTP_REFERER'], (strrpos($_SERVER['HTTP_REFERER'], "/")+1))) {
1079					$refpage = "index.php";
1080				}
1081			} else {
1082				$refpage = "";
1083			}
1084
1085			foreach($search_info as $key => $value) {
1086				if ($value['refpage']) {
1087					if (strpos($refpage, $value['refpage']) !== FALSE) {
1088						$searchtype[$key] = true;
1089						$_GET['t'] = $key;
1090					}
1091				}
1092			}
1093		}
1094
1095		if (!isset($searchtype) && isset($query)) {
1096			if ($search_prefs['multisearch']) {
1097				$searchtype['all'] = true;
1098			} else {
1099				$searchtype[0] = true;
1100			}
1101		}
1102	}
1103}
1104*/
1105
1106
1107//$value = isset($_GET['q']) ? $tp -> post_toForm($_GET['q']) : "";
1108//$SEARCH_VARS->SEARCH_MAIN_SEARCHFIELD = "<input class='tbox m_search' type='text' id='q' name='q' size='35' value='".$value."' maxlength='50' />";
1109
1110
1111/*
1112if ($search_prefs['selector'] == 1) 
1113{
1114  $SEARCH_VARS->SEARCH_MAIN_CHECKALL = "<input  type='button' name='CheckAll' value='".LAN_SEARCH_1."' onclick='checkAll(this);' />";
1115  $SEARCH_VARS->SEARCH_MAIN_UNCHECKALL = "<input  type='button' name='UnCheckAll' value='".LAN_SEARCH_2."' onclick='uncheckAll(this); uncheckG();' />";
1116}
1117*/
1118//$SEARCH_VARS->SEARCH_MAIN_SUBMIT = "<input type='hidden' name='r' value='0' /><input type='submit' name='s' value='".LAN_180."' />";
1119
1120//$SEARCH_VARS->ENHANCED_ICON = "<img src='".e_IMAGE_ABS."generic/search_basic.png' style='width: 16px; height: 16px; vertical-align: top'
1121//alt='".LAN_SEARCH_23."' title='".LAN_SEARCH_23."' onclick=\"expandit('en_in'); expandit('en_ex'); expandit('en_ep'); expandit('en_be')\"/>";
1122
1123$enhanced_types['in'] = LAN_SEARCH_24.':';
1124$enhanced_types['ex'] = LAN_SEARCH_25.':';
1125$enhanced_types['ep'] = LAN_SEARCH_26.':';
1126$enhanced_types['be'] = LAN_SEARCH_27.':';
1127
1128$SEARCH_VARS->ENHANCED_DISPLAY = $enhanced ? "" : "style='display: none'";
1129
1130// advanced search config
1131if (!varsettrue($_GET['adv']) || $_GET['t'] == 'all') 
1132{
1133  foreach ($_GET as $gk => $gv) 
1134  {
1135	if ($gk != 't' && $gk != 'q' && $gk != 'r' && $gk != 'in' && $gk != 'ex' && $gk != 'ep' && $gk != 'be' && $gk != 'adv') 
1136	{
1137	  unset($_GET[$gk]);
1138	}
1139  }
1140}
1141
1142//$SEARCH_VARS->SEARCH_TYPE_SEL = "<input type='radio' name='adv' value='0' ".(varsettrue($_GET['adv']) ? "" : "checked='checked'")." /> ".LAN_SEARCH_29."&nbsp;
1143//<input type='radio' name='adv' value='1' ".(varsettrue($_GET['adv']) ? "checked='checked'" : "" )." /> ".LAN_SEARCH_30;
1144
1145$js_adv = '';
1146foreach ($search_info as $key => $value) 
1147{
1148  if (!isset($search_info[$key]['advanced'])) 
1149  {
1150	$js_adv .= " && abid != '".$key."'";
1151  }
1152}
1153
1154if (isset($_GET['t']) && isset($search_info[$_GET['t']]['advanced'])) 
1155{
1156  $SEARCH_VARS->SEARCH_TYPE_DISPLAY = "";
1157} 
1158else 
1159{
1160  $SEARCH_VARS->SEARCH_TYPE_DISPLAY = "style='display: none'";
1161}
1162
1163if (check_class($search_prefs['google'])) {
1164	$js_adv .= " && abid != '".$google_id."'";
1165}
1166
1167
1168if ($perform_search) 
1169{
1170  $con = new convert;
1171 
1172  $sch = new e_search;
1173
1174  // omitted words message
1175  $stop_count = count($sch -> stop_keys);
1176  
1177  if ($stop_count) 
1178  {
1179	if ($stop_count > 1) 
1180	{
1181	  $SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_32.": ";
1182	} 
1183	else 
1184	{
1185	  $SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_33.": ";
1186	}
1187	
1188	$i = 1;
1189	foreach ($sch -> stop_keys as $stop_key) 
1190	{
1191	  $SEARCH_VARS->SEARCH_MESSAGE .= $stop_key;
1192	  if ($i != $stop_count) 
1193	  {
1194		$SEARCH_VARS->SEARCH_MESSAGE .= ', ';
1195	  }
1196	  $i++;
1197	}
1198  }
1199}
1200
1201require_once(HEADERF);
1202
1203// render search config
1204
1205if(deftrue('BOOTSTRAP'))
1206{
1207	$tmp 				= e107::getCoreTemplate('search','form');
1208	$SEARCH_TOP_TABLE 	= $tmp['start'];
1209	$SEARCH_BOT_TABLE 	= $tmp['end'];
1210	$SEARCH_CATS		= $tmp['category'];
1211	$SEARCH_TYPE		= $tmp['type'];
1212	$SEARCH_ADV			= $tmp['advanced'];
1213	$SEARCH_ENHANCED	= $tmp['enhanced'];
1214	$SEARCH_ADV_COMBO	= $tmp['advanced-combo'];
1215	
1216	$srchObj->template = $tmp;
1217
1218	
1219	
1220	unset($tmp);
1221}
1222
1223
1224
1225if (!isset($SEARCH_TOP_TABLE)) 
1226{
1227	if (file_exists(THEME."search_template.php")) 
1228	{
1229		require(THEME."search_template.php");
1230	} 
1231	else 
1232	{
1233		require(e_CORE."templates/search_template.php");
1234	}
1235	
1236	$SEARCH_TOP_TABLE .= "{SEARCH_ENHANCED}";
1237}
1238
1239
1240
1241
1242
1243
1244//$SEARCH_TOP_TABLE =  $tp->parseTemplate($SEARCH_TOP_TABLE,true,$srchObj);
1245//$SEARCH_TYPE =  $tp->parseTemplate($SEARCH_TYPE,true, $srchObj);
1246			
1247		
1248	
1249/*
1250
1251// standard search config
1252if ($search_prefs['selector'] == 2) 
1253{
1254	$SEARCH_VARS->SEARCH_DROPDOWN = "<select name='t' id='t' class='tbox' onchange=\"ab()\">";
1255	if ($search_prefs['multisearch']) {
1256		$SEARCH_VARS->SEARCH_DROPDOWN .= "<option value='all'>".LAN_SEARCH_22."</option>";
1257	}
1258} 
1259else 
1260{
1261  $SEARCH_VARS->SEARCH_MAIN_CHECKBOXES = '';
1262}
1263
1264foreach($search_info as $key => $value) 
1265{
1266	if ($search_prefs['selector'] == 2) {
1267		$sel = (isset($searchtype[$key]) && $searchtype[$key]) ? " selected='selected'" : "";
1268	} else {
1269		$sel = (isset($searchtype[$key]) && $searchtype[$key]) ? " checked='checked'" : "";
1270	}
1271	$google_js = check_class($search_prefs['google']) ? "onclick=\"uncheckG();\" " : "";
1272	if ($search_prefs['selector'] == 2) {
1273		$SEARCH_VARS->SEARCH_DROPDOWN .= "<option value='".$key."' ".$sel.">".$value['qtype']."</option>";
1274	} else if ($search_prefs['selector'] == 1) {
1275		$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input ".$google_js." type='checkbox' name='t[".$key."]' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
1276	} else {
1277		$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input type='radio' name='t' value='".$key."' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
1278	}
1279}
1280
1281if (check_class($search_prefs['google'])) 
1282{
1283	if ($search_prefs['selector'] == 2) {
1284		$SEARCH_VARS->SEARCH_DROPDOWN .= "<option value='".$google_id."'>Google</option>";
1285	} else if ($search_prefs['selector'] == 1) {
1286		$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input id='google' type='checkbox' name='t[".$google_id."]' onclick='uncheckAll(this)' />Google".$POST_CHECKBOXES;
1287	} else {
1288		$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input id='google' type='radio' name='t' value='".$google_id."' />Google".$POST_CHECKBOXES;
1289	}
1290}
1291
1292if ($search_prefs['selector'] == 2) 
1293{
1294	$SEARCH_VARS->SEARCH_DROPDOWN .= "</select>";
1295}
1296// end of standard search config
1297
1298*/
1299
1300//$text = preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TOP_TABLE);
1301$tp = e107::getParser();
1302
1303
1304// $text = $tp->simpleParse($SEARCH_TOP_TABLE, $SEARCH_VARS);
1305
1306$text =  $tp->parseTemplate($SEARCH_TOP_TABLE,true,$srchObj);
1307
1308/*
1309foreach ($enhanced_types as $en_id => $ENHANCED_TEXT) 
1310{
1311	$SEARCH_VARS->ENHANCED_TEXT = $ENHANCED_TEXT;
1312	$SEARCH_VARS->ENHANCED_DISPLAY_ID = "en_".$en_id;
1313	$SEARCH_VARS->ENHANCED_FIELD = "<input class='tbox' type='text' id='".$en_id."' name='".$en_id."' size='35' value='".$tp->post_toForm($_GET[$en_id])."' maxlength='50' />";
1314	//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_ENHANCED);
1315	$text .= $tp->simpleParse($SEARCH_ENHANCED, $SEARCH_VARS);
1316}
1317$SEARCH_VARS->ENHANCED_TEXT = $SEARCH_VARS->ENHANCED_DISPLAY_ID = $SEARCH_VARS->ENHANCED_FIELD = null;
1318*/
1319
1320
1321if ($search_prefs['user_select']) 
1322{
1323	//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_CATS);
1324//	$text .= $tp->simpleParse($SEARCH_CATS, $SEARCH_VARS);
1325	$text .= $tp->parseTemplate($SEARCH_CATS,true, $srchObj);
1326}
1327
1328//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TYPE);
1329// $text .= $tp->simpleParse($SEARCH_TYPE, $SEARCH_VARS);
1330$text .= $tp->parseTemplate($SEARCH_TYPE,true, $srchObj);
1331
1332
1333	$text .= "<div class='e-hideme' id='search-advanced' >";
1334	$text .= $tp->parseTemplate("{SEARCH_ADVANCED_BLOCK=".vartrue($_GET['t'])."}",true, $srchObj);
1335	$text .= "</div>";
1336
1337
1338//$
1339
1340$text .= $SEARCH_MESSAGE ? preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TABLE_MSG) : "";
1341$text .= $SEARCH_VARS->SEARCH_MESSAGE ? $tp->simpleParse($SEARCH_TABLE_MSG, $SEARCH_VARS) : "";
1342//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_BOT_TABLE);
1343$text .= $tp->simpleParse($SEARCH_BOT_TABLE, $SEARCH_VARS);
1344
1345
1346
1347e107::getRender()->tablerender(PAGE_NAME." ".SITENAME, $text, 'search_head');
1348
1349// parse search
1350$SEARCH_VARS = new e_vars();
1351
1352if ($perform_search) 
1353{
1354	
1355	$srchObj->renderResults();
1356	
1357	
1358	/*
1359	$_GET['q'] = rawurlencode($_GET['q']);
1360		$_GET['t'] = preg_replace('/[^\w\-]/i', '', $_GET['t']);
1361		foreach ($search_info as $key => $a) 
1362		{
1363			if (isset($searchtype[$key]) || isset($searchtype['all'])) 
1364			{
1365				unset($text);
1366				//if (file_exists($search_info[$key]['sfile'])) 
1367				{
1368					$pre_title 		= ($search_info[$key]['pre_title'] == 2) ? $search_info[$key]['pre_title_alt'] : $search_info[$key]['pre_title'];
1369					$search_chars 	= $search_info[$key]['chars'];
1370					$search_res 	= $search_info[$key]['results'];
1371					
1372					
1373					e107::getAddon();
1374					
1375					if(vartrue($search_info[$key]['sfile']) && file_exists($search_info[$key]['sfile'])) // Legacy
1376					{
1377						$text .= '<div class="search-block">';
1378						@require_once($search_info[$key]['sfile']);
1379						$text .= '</div>';
1380					}
1381					else// New v2 standard. @see chatbox_menu/e_search.php
1382					{
1383						
1384						$className = $key."_search";
1385						
1386						$obj = new $className;
1387	
1388						$where = (method_exists($obj,'where')) ? $obj->where($_GET) : "";
1389						
1390						$ps = $obj->parsesearch($search_info[$key]['table'], $search_info[$key]['return_fields'], $search_info[$key]['search_fields'], $search_info[$key]['weights'], 'self', varset($search_info[$key]['no_results'],LAN_198), $where , $search_info[$key]['order']);
1391						
1392						$text .= '<div class="search-block">';
1393						$text .= $ps['text'];
1394						$text .= '</div>';
1395						$results = $ps['results'];	
1396						
1397					}
1398					
1399					
1400					$parms = $results.",".$search_res.",".$_GET['r'].",".e_REQUEST_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]";
1401					
1402					$core_parms = array('r' => '', 'q' => '', 't' => '', 's' => '');
1403					foreach ($_GET as $pparm_key => $pparm_value) 
1404					{
1405						$temp = preg_replace('/[^\w_]/i','',$pparm_key);
1406						$temp1 = preg_replace('/[^\w_ +]/i','',$pparm_value);		// Filter 'non-word' charcters in search term
1407						if (($temp == $pparm_key) && !isset($core_parms[$pparm_key])) 
1408						{
1409							$parms .= "&".$pparm_key."=".$temp1;
1410						}
1411					}
1412					if ($results > $search_res) 
1413					{
1414						$nextprev = ($results > $search_res) ? $tp -> parseTemplate("{NEXTPREV={$parms}}") : "";
1415						$text .= "<div class='nextprev search form-inline'>".$nextprev."</div>";
1416					}
1417					if ($results > 0) 
1418					{
1419						$res_from = $_GET['r'] + 1;
1420						$res_to = ($_GET['r'] + $search_res) > $results ? $results : ($_GET['r'] + $search_res);
1421						$res_display = $res_from." - ".$res_to." ".LAN_SEARCH_12." ".$results;
1422					} 
1423					else 
1424					{
1425						$res_display = "";
1426					}
1427					$ns->tablerender(LAN_SEARCH_11." ".$res_display." ".LAN_SEARCH_13." ".(isset($_GET[$advanced_caption['id']]) ? $advanced_caption['title'][$_GET[$advanced_caption['id']]] : $search_info[$key]['qtype']), $text, 'search_result');
1428				}
1429			}
1430		}*/
1431	
1432}
1433
1434
1435
1436
1437
1438// old 6xx search parser for reverse compatability
1439function parsesearch($text, $match) 
1440{
1441	$tp = e107::getParser();
1442	$text = strip_tags($text);
1443	$temp = $tp->ustristr($text, $match);
1444	$pos = $tp->ustrlen($text) - $tp->ustrlen($temp);
1445	$matchedText = $tp->usubstr($text,$pos,$tp->ustrlen($match));
1446	if ($pos < 70) {
1447		$text = "...".$tp->usubstr($text, 0, 100)."...";
1448	} else {
1449		$text = "...".$tp->usubstr($text, ($pos-50), $pos+30)."...";
1450	}
1451	$text = preg_replace("/".$match."/i", "<span class='searchhighlight'>".$matchedText."</span>", $text);
1452	return($text);
1453}
1454
1455function headerjs() {
1456	global $search_count, $google_id, $search_prefs, $js_adv, $search_info;
1457	if ($search_prefs['selector'] == 1) {
1458		
1459		$types = array_keys($search_info);
1460		$types = implode("', '", $types);
1461		
1462		$script = "<script type='text/javascript'>
1463		<!--
1464		var i;
1465		var stypes = new Array('".$types."');
1466		
1467		function checkAll(allbox) {
1468			for (var i in stypes)
1469			document.getElementById('searchform')[\"t[\" + stypes[i] + \"]\"].checked = true ;
1470			uncheckG();
1471		}
1472
1473		function uncheckAll(allbox) {
1474			for (var i in stypes)
1475			document.getElementById('searchform')[\"t[\" + stypes[i] + \"]\"].checked = false ;
1476		}\n";
1477
1478		if (check_class($search_prefs['google'])) {
1479		$script .= "
1480		function uncheckG() {
1481			document.getElementById('searchform')[\"t[".$google_id."]\"].checked = false ;
1482		}\n";
1483		}
1484
1485		$script .= "// -->
1486		</script>";
1487
1488	}
1489
1490
1491
1492	return $script;
1493}
1494
1495require_once(FOOTERF);
1496
1497?>