PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/search.php

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