1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-16 20:28:28 +01:00
php-e107/search.php

1307 lines
35 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
* e107 website system
*
2013-03-18 14:20:49 +01:00
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
2006-12-02 04:36:16 +00:00
require_once('class2.php');
e107::coreLan('search');
e107_require(e_HANDLER.'search_class.php');
2006-12-02 04:36:16 +00:00
2014-01-06 18:41:35 -08:00
if (!check_class($pref['search_restrict']))
{
2006-12-02 04:36:16 +00:00
require_once(HEADERF);
2013-03-18 14:20:49 +01:00
$ns->tablerender(LAN_SEARCH_20, "<div style='text-align: center'>".LAN_SEARCH_21."</div>");
2006-12-02 04:36:16 +00:00
require_once(FOOTERF);
exit;
}
if (isset($_GET['t']) && is_numeric($_GET['t']))
{
switch ($_GET['t'])
{
case '0' :
$_GET['t'] = 'news';
break;
case 1 :
$_GET['t'] = 'comments';
break;
case 2 :
$_GET['t'] = 'users';
break;
case 3 :
$_GET['t'] = 'downloads';
break;
case 4 :
$_GET['t'] = 'pages';
break;
}
}
2006-12-02 04:36:16 +00:00
2014-01-06 18:41:35 -08:00
class search extends e_shortcode
{
2014-01-06 18:41:35 -08:00
private $search_prefs = array();
private $auto_order = 1000;
private $enhanced = false;
private $query = null;
private $result_flag = 0;
private $message = '';
function __construct()
{
$this->search_prefs = e107::getConfig('search')->getPref();
if (!e_QUERY)
{
$this->enhanced = true;
}
}
// Shortcodes -----------------------
function sc_search_main_searchfield($parm='')
{
$tp = e107::getParser();
$value = isset($_GET['q']) ? $tp->post_toForm($_GET['q']) : "";
return "<input class='tbox m_search' type='text' id='q' name='q' size='35' value='".$value."' maxlength='50' />";
}
function sc_search_main_submit($parm='')
{
return "<input class='btn btn-primary button' type='submit' name='s' value='".LAN_180."' />
<input type='hidden' name='r' value='0' />";
}
function sc_enhanced_icon($parm='')
{
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')\"/>";
}
2014-01-06 18:41:35 -08:00
function sc_search_main_checkall($parm='')
{
if($this->search_prefs['selector'] == 1)
{
return "<input class='btn button' type='button' name='CheckAll' value='".LAN_SEARCH_1."' onclick='checkAll(this);' />";
}
}
2014-01-06 18:41:35 -08:00
function sc_search_main_uncheckall($parm='')
{
if($this->search_prefs['selector'] == 1)
{
return "<input class='btn button' type='button' name='UnCheckAll' value='".LAN_SEARCH_2."' onclick='uncheckAll(this); uncheckG();' />";
}
}
2014-01-06 18:41:35 -08:00
function sc_search_type_sel($parm='')
{
return "<input type='radio' name='adv' value='0' ".(varsettrue($_GET['adv']) ? "" : "checked='checked'")." /> ".LAN_SEARCH_29."&nbsp;
<input type='radio' name='adv' value='1' ".(varsettrue($_GET['adv']) ? "checked='checked'" : "" )." /> ".LAN_SEARCH_30;
}
2014-01-06 18:41:35 -08:00
function sc_search_dropdown($parm = '')
{
return $this->selectElement('dropdown');
}
2014-01-06 18:41:35 -08:00
function sc_search_main_checkboxes($parm = '')
{
2014-01-06 18:41:35 -08:00
return $this->selectElement('checkboxes');
}
function sc_search_message($parm = '')
{
return $this->message;
}
private function selectElement($parm)
{
// standard search config
if ($this->search_prefs['selector'] == 2)
{
2014-01-06 18:41:35 -08:00
$dropdown = "<select name='t' id='t' class='tbox' onchange=\"ab()\">";
if ($this->search_prefs['multisearch'])
{
$dropdown .= "<option value='all'>".LAN_SEARCH_22."</option>";
}
}
else
{
2014-01-06 18:41:35 -08:00
$checkboxes = '';
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
foreach($this->search_info as $key => $value)
{
2014-01-06 18:41:35 -08:00
if ($this->search_prefs['selector'] == 2)
{
$sel = (isset($this->searchtype[$key]) && $this->searchtype[$key]) ? " selected='selected'" : "";
}
else
{
$sel = (isset($this->searchtype[$key]) && $this->searchtype[$key]) ? " checked='checked'" : "";
}
2014-01-06 18:41:35 -08:00
$google_js = check_class($this->search_prefs['google']) ? "onclick=\"uncheckG();\" " : "";
2014-01-06 18:41:35 -08:00
if ($this->search_prefs['selector'] == 2)
{
$dropdown .= "<option value='".$key."' ".$sel.">".$value['qtype']."</option>";
}
else if ($this->search_prefs['selector'] == 1)
{
$checkboxes .= $PRE_CHECKBOXES."<input ".$google_js." type='checkbox' name='t[".$key."]' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
}
else
{
2014-01-06 18:41:35 -08:00
$checkboxes .= $PRE_CHECKBOXES."<input type='radio' name='t' value='".$key."' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
}
2014-01-06 18:41:35 -08:00
}
2014-01-06 18:41:35 -08:00
if (check_class($this->search_prefs['google']))
{
if ($this->search_prefs['selector'] == 2)
{
$dropdown .= "<option value='".$google_id."'>Google</option>"; //FIXME googleid
}
else if
($this->search_prefs['selector'] == 1) //FIXME PRE_CHECKBOXES and POST_CHECKBOXES
{
$checkboxes .= $PRE_CHECKBOXES."<input id='google' type='checkbox' name='t[".$google_id."]' onclick='uncheckAll(this)' />Google".$POST_CHECKBOXES;
}
else
{
$checkboxes .= $PRE_CHECKBOXES."<input id='google' type='radio' name='t' value='".$google_id."' />Google".$POST_CHECKBOXES;
}
}
2014-01-06 18:41:35 -08:00
if ($this->search_prefs['selector'] == 2)
{
$dropdown .= "</select>";
}
if($parm == 'dropdown')
{
return $dropdown;
}
else
{
return $checkboxes;
}
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
// -------------
function searchPrefs()
{
return $this->search_prefs;
}
2006-12-02 04:36:16 +00:00
2014-01-06 18:41:35 -08:00
function search_info($id, $type, $plug_require=null, $info='')
{
$tp = e107::getParser();
if (check_class($this->search_prefs[$type.'_handlers'][$id]['class']))
{
if ($plug_require)
{
require_once($plug_require);
$ret = $search_info[0];
}
else
{
$ret = $info;
}
if($obj = e107::getAddon($id,'e_search'))
{
$ret = $obj->config();
$ret['qtype'] = $ret['name'];
if(!isset($ret['id']))
{
$ret['id'] = $ret['name'];
}
}
$ret['chars'] = $this->search_prefs[$type.'_handlers'][$id]['chars'];
$ret['results'] = $this->search_prefs[$type.'_handlers'][$id]['results'];
$ret['pre_title'] = $this->search_prefs[$type.'_handlers'][$id]['pre_title'];
$ret['pre_title_alt'] = $tp -> toHtml($this->search_prefs[$type.'_handlers'][$id]['pre_title_alt']);
$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;
$this->auto_order++;
return $ret;
}
else
{
return false;
}
}
2014-01-06 18:41:35 -08:00
2006-12-02 04:36:16 +00:00
2014-01-06 18:41:35 -08:00
// Get Core and Plugin search configurations
function searchConfig()
{
//core search routines
$search_info = array();
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'))) {
// $search_id++;
} else {
unset($search_info['news']);
}
if(e107::getConfig('core')->get('comments_disabled')!=1) // Only when comments are enabled.
{
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'))) {
// $search_id++;
} else {
unset($search_info['comments']);
}
}
if(e107::getConfig('core')->get('user_reg')==1) // Only when user-registration is enabled.
{
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'))) {
// $search_id++;
} else {
unset($search_info['users']);
}
}
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'))) {
// $search_id++;
} else {
unset($search_info['pages']);
}
$e_searchList = e107::getConfig('core')->get('e_search_list');
//plugin search routines // plugin folder is used as the search key. ie. $_GET['t'] = 'chatbox';
foreach ($this->search_prefs['plug_handlers'] as $plug_dir => $active)
{
if(isset($search_info[$plug_dir]))
{
continue;
}
if (in_array($plug_dir,$e_searchList) && is_readable(e_PLUGIN.$plug_dir."/e_search.php"))
{
if ($search_info[$plug_dir] = $this->search_info($plug_dir, 'plug', e_PLUGIN.$plug_dir."/e_search.php"))
{
// $search_id++;
}
else
{
unset($search_info[$plug_dir]);
}
}
}
// order search routines
$search_info = $this->array_sort($search_info, 'order', SORT_ASC);
$this->search_info = $search_info;
return $search_info;
}
2006-12-02 04:36:16 +00:00
2006-12-02 04:36:16 +00:00
2014-01-06 18:41:35 -08:00
// determine areas being searched
public function searchType()
{
$searchtype = array();
if (!$this->search_prefs['user_select'] && $_GET['r'] < 1)
{
foreach($this->search_info as $key => $value)
{
$searchtype[$key] = true;
}
}
else
{
if (isset($_GET['t']))
{
if (is_array($_GET['t']))
{
$searchtype = $_GET['t'];
}
else
{
$searchtype[$_GET['t']] = true;
}
}
else
{
if (isset($_GET['ref']))
{
foreach($this->search_info as $key => $value)
{
if ($value['id'] == $_GET['ref'])
{
$searchtype[$key] = true;
$_GET['t'] = $key;
}
}
}
else if (e_QUERY)
{
if (isset($_SERVER['HTTP_REFERER']))
{
if (!$refpage = substr($_SERVER['HTTP_REFERER'], (strrpos($_SERVER['HTTP_REFERER'], "/")+1)))
{
$refpage = "index.php";
}
}
else
{
$refpage = "";
}
foreach($this->search_info as $key=>$value)
{
if ($value['refpage'])
{
if (strpos($refpage, $value['refpage']) !== FALSE)
{
$searchtype[$key] = true;
$_GET['t'] = $key;
}
}
}
}
if (!isset($this->searchtype) && isset($this->query))
{
if ($this->search_prefs['multisearch'])
{
$searchtype['all'] = true;
}
else
{
$searchtype[0] = true;
}
}
}
}
$this->searchtype = $searchtype;
return $searchtype;
}
2014-01-06 18:41:35 -08:00
function array_sort($array, $column, $order = SORT_DESC)
{
2014-01-06 18:41:35 -08:00
$i = 0;
foreach($array as $info) {
$sortarr[] = $info[$column];
$i++;
}
array_multisort($sortarr, $order, $array, $order);
return($array);
}
2014-01-06 18:41:35 -08:00
function renderResults()
{
2014-01-06 18:41:35 -08:00
global $query, $search_prefs, $pre_title, $search_chars, $search_res, $result_flag;
$ns = e107::getRender();
$sch = new e_search;
2014-01-09 09:54:10 -08:00
$tp = e107::getParser();
2014-01-06 18:41:35 -08:00
$query = $this->query;
$_GET['q'] = rawurlencode($_GET['q']);
$_GET['t'] = preg_replace('/[^\w\-]/i', '', $_GET['t']);
$search_prefs = $this->search_prefs;
$result_flag = $this->result_flag;
foreach ($this->search_info as $key => $a)
{
2014-01-06 18:41:35 -08:00
if (isset($this->searchtype[$key]) || isset($this->searchtype['all']))
{
unset($text);
//if (file_exists($this->search_info[$key]['sfile']))
{
$pre_title = ($this->search_info[$key]['pre_title'] == 2) ? $this->search_info[$key]['pre_title_alt'] : $this->search_info[$key]['pre_title'];
$search_chars = $this->search_info[$key]['chars'];
$search_res = $this->search_info[$key]['results'];
if(vartrue($this->search_info[$key]['sfile']) && file_exists($this->search_info[$key]['sfile'])) // Legacy
{
$text .= '<div class="search-block">';
require_once($this->search_info[$key]['sfile']);
$text .= '</div>';
}
else// New v2 standard. @see chatbox_menu/e_search.php
{
$className = $key."_search";
$obj = new $className;
$where = (method_exists($obj,'where')) ? $obj->where($_GET) : "";
$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']);
$text .= '<div class="search-block">';
$text .= $ps['text'];
$text .= '</div>';
$results = $ps['results'];
}
$parms = $results.",".$search_res.",".$_GET['r'].",".e_REQUEST_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]";
$core_parms = array('r' => '', 'q' => '', 't' => '', 's' => '');
foreach ($_GET as $pparm_key => $pparm_value)
{
$temp = preg_replace('/[^\w_]/i','',$pparm_key);
$temp1 = preg_replace('/[^\w_ +]/i','',$pparm_value); // Filter 'non-word' charcters in search term
if (($temp == $pparm_key) && !isset($core_parms[$pparm_key]))
{
$parms .= "&".$pparm_key."=".$temp1;
}
}
if ($results > $search_res)
{
$nextprev = ($results > $search_res) ? $tp -> parseTemplate("{NEXTPREV={$parms}}") : "";
$text .= "<div class='nextprev search form-inline'>".$nextprev."</div>";
}
if ($results > 0)
{
$res_from = $_GET['r'] + 1;
$res_to = ($_GET['r'] + $search_res) > $results ? $results : ($_GET['r'] + $search_res);
$res_display = $res_from." - ".$res_to." ".LAN_SEARCH_12." ".$results;
}
else
{
$res_display = "";
}
$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');
}
}
}
2014-01-06 18:41:35 -08:00
}
function magic_search($data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = $this->magic_search($value);
} else {
$data[$key] = stripslashes($value);
}
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
return $data;
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
function searchQuery()
{
global $perform_search;
if (isset($_GET['q']) || isset($_GET['in']) || isset($_GET['ex']) || isset($_GET['ep']) || isset($_GET['beg']))
{
if (MAGIC_QUOTES_GPC == true)
{
$_GET = $this->magic_search($_GET);
}
$full_query = $_GET['q'];
if ($_GET['in'])
{
$en_in = explode(' ', $_GET['in']);
foreach ($en_in as $en_in_key)
{
$full_query .= " +".$en_in_key;
}
$this->enhanced = true;
}
if ($_GET['ex'])
{
$en_ex = explode(' ', $_GET['ex']);
foreach ($en_ex as $en_ex_key)
{
$full_query .= " -".$en_ex_key;
}
$this->enhanced = true;
}
if ($_GET['ep'])
{
$full_query .= " \"".$_GET['ep']."\"";
$this->enhanced = true;
}
if ($_GET['be'])
{
$en_be = explode(' ', $_GET['be']);
foreach ($en_be as $en_be_key)
{
$full_query .= " ".$en_be_key."*";
}
$this->enhanced = true;
}
if (isset($_GET['r']) && !is_numeric($_GET['r']))
{
$perform_search = false;
$this->message = LAN_SEARCH_201;
$this->result_flag = 0;
}
else if (strlen($full_query) == 0)
{
$perform_search = false;
$this->message = LAN_SEARCH_201;
}
elseif (strlen($full_query) < ($char_count = ($search_prefs['mysql_sort'] ? 4 : 3)))
{
$perform_search = false;
$this->message = str_replace('--CHARS--', $char_count, LAN_417);
}
elseif ($search_prefs['time_restrict'])
{
$time = time() - $search_prefs['time_secs'];
$query_check = $tp -> toDB($full_query);
$ip = e107::getIPHandler()->getIP(FALSE);
if ($sql->select("tmp", "tmp_ip, tmp_time, tmp_info", "tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'"))
{
$row = $sql->fetch();
if (($row['tmp_time'] > $time) && ($row['tmp_info'] != 'type_search '.$query_check))
{
$perform_search = false;
$this->message = LAN_SEARCH_17.$search_prefs['time_secs'].LAN_SEARCH_18;
}
else
{
$sql->update("tmp", "tmp_time='".time()."', tmp_info='type_search ".$query_check."' WHERE tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'");
}
}
else
{
$sql->insert("tmp", "'".$ip."', '".time()."', 'type_search ".$query_check."'");
}
}
if ($perform_search)
{
$this->result_flag = $_GET['r'];
}
$query = trim($full_query);
$this->query = $query;
return $query;
}
}
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
$srchObj = new search;
$search_info = $srchObj->searchConfig();
$search_prefs = $srchObj->searchPrefs();
2006-12-02 04:36:16 +00:00
// validate search query
$perform_search = true;
// simple parse object
$SEARCH_VARS = new e_vars();
2014-01-06 18:41:35 -08:00
/*
2006-12-02 04:36:16 +00:00
function magic_search($data) {
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = magic_search($value);
} else {
$data[$key] = stripslashes($value);
}
}
return $data;
}
if (!e_QUERY) {
$enhanced = true;
}
2014-01-06 18:41:35 -08:00
*/
/*
2006-12-02 04:36:16 +00:00
if (isset($_GET['q']) || isset($_GET['in']) || isset($_GET['ex']) || isset($_GET['ep']) || isset($_GET['beg'])) {
if (MAGIC_QUOTES_GPC == true) {
$_GET = magic_search($_GET);
}
$full_query = $_GET['q'];
if ($_GET['in']) {
$en_in = explode(' ', $_GET['in']);
foreach ($en_in as $en_in_key) {
$full_query .= " +".$en_in_key;
}
$enhanced = true;
}
if ($_GET['ex']) {
$en_ex = explode(' ', $_GET['ex']);
foreach ($en_ex as $en_ex_key) {
$full_query .= " -".$en_ex_key;
}
$enhanced = true;
}
if ($_GET['ep']) {
$full_query .= " \"".$_GET['ep']."\"";
$enhanced = true;
}
if ($_GET['be']) {
$en_be = explode(' ', $_GET['be']);
foreach ($en_be as $en_be_key) {
$full_query .= " ".$en_be_key."*";
}
$enhanced = true;
}
if (isset($_GET['r']) && !is_numeric($_GET['r'])) {
$perform_search = false;
$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_201;
2006-12-02 04:36:16 +00:00
$result_flag = 0;
} else if (strlen($full_query) == 0) {
$perform_search = false;
$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_201;
}
elseif (strlen($full_query) < ($char_count = ($search_prefs['mysql_sort'] ? 4 : 3)))
{
2006-12-02 04:36:16 +00:00
$perform_search = false;
$SEARCH_VARS->SEARCH_MESSAGE = str_replace('--CHARS--', $char_count, LAN_417);
}
elseif ($search_prefs['time_restrict']) {
2006-12-02 04:36:16 +00:00
$time = time() - $search_prefs['time_secs'];
$query_check = $tp -> toDB($full_query);
$ip = e107::getIPHandler()->getIP(FALSE);
2006-12-02 04:36:16 +00:00
if ($sql -> db_Select("tmp", "tmp_ip, tmp_time, tmp_info", "tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'")) {
$row = $sql -> db_Fetch();
if (($row['tmp_time'] > $time) && ($row['tmp_info'] != 'type_search '.$query_check)) {
$perform_search = false;
$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_17.$search_prefs['time_secs'].LAN_SEARCH_18;
2006-12-02 04:36:16 +00:00
} else {
$sql -> db_Update("tmp", "tmp_time='".time()."', tmp_info='type_search ".$query_check."' WHERE tmp_info LIKE 'type_search%' AND tmp_ip='".$ip."'");
}
} else {
$sql -> db_Insert("tmp", "'".$ip."', '".time()."', 'type_search ".$query_check."'");
}
}
if ($perform_search) {
$result_flag = $_GET['r'];
}
$query = trim($full_query);
2014-01-06 18:41:35 -08:00
}*/
$query = $srchObj->searchQuery();
2006-12-02 04:36:16 +00:00
// forward user if searching in google
$search_count = count($search_info);
$google_id = $search_count + 1;
2014-01-06 18:41:35 -08:00
if ($perform_search)
{
if ($search_prefs['selector'] == 1)
{ // Care needed - with alpha strings on search of single area $_GET['t'][$google_id] returns a character on page > 1
if (isset($_GET['t'][$google_id]) && ($_GET['t']==$google_id) && $_GET['t'][$google_id])
{
// echo "We think google should be used using checkboxes<br />";
2006-12-02 04:36:16 +00:00
header("location:http://www.google.com/search?q=".stripslashes(str_replace(" ", "+", $query)));
exit;
}
}
else
{
if (isset($_GET['t']) && $_GET['t'] == $google_id)
{
2006-12-02 04:36:16 +00:00
header("location:http://www.google.com/search?q=".stripslashes(str_replace(" ", "+", $query)));
exit;
}
}
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
$searchtype = $srchObj->searchType();
2006-12-02 04:36:16 +00:00
// determine areas being searched
2014-01-06 18:41:35 -08:00
/*
2006-12-02 04:36:16 +00:00
if (!$search_prefs['user_select'] && $_GET['r'] < 1) {
foreach($search_info as $key => $value) {
$searchtype[$key] = true;
}
} else {
if (isset($_GET['t'])) {
if (is_array($_GET['t'])) {
$searchtype = $_GET['t'];
} else {
$searchtype[$_GET['t']] = true;
}
} else {
if (isset($_GET['ref'])) {
foreach($search_info as $key => $value) {
if ($value['id'] == $_GET['ref']) {
$searchtype[$key] = true;
$_GET['t'] = $key;
}
}
} else if (e_QUERY) {
if (isset($_SERVER['HTTP_REFERER'])) {
if (!$refpage = substr($_SERVER['HTTP_REFERER'], (strrpos($_SERVER['HTTP_REFERER'], "/")+1))) {
$refpage = "index.php";
}
} else {
$refpage = "";
}
foreach($search_info as $key => $value) {
if ($value['refpage']) {
if (strpos($refpage, $value['refpage']) !== FALSE) {
$searchtype[$key] = true;
$_GET['t'] = $key;
}
}
}
}
if (!isset($searchtype) && isset($query)) {
if ($search_prefs['multisearch']) {
$searchtype['all'] = true;
} else {
$searchtype[0] = true;
}
}
}
}
2014-01-06 18:41:35 -08:00
*/
2006-12-02 04:36:16 +00:00
2014-01-06 18:41:35 -08:00
//$value = isset($_GET['q']) ? $tp -> post_toForm($_GET['q']) : "";
//$SEARCH_VARS->SEARCH_MAIN_SEARCHFIELD = "<input class='tbox m_search' type='text' id='q' name='q' size='35' value='".$value."' maxlength='50' />";
2014-01-06 18:41:35 -08:00
/*
if ($search_prefs['selector'] == 1)
{
$SEARCH_VARS->SEARCH_MAIN_CHECKALL = "<input class='btn button' type='button' name='CheckAll' value='".LAN_SEARCH_1."' onclick='checkAll(this);' />";
$SEARCH_VARS->SEARCH_MAIN_UNCHECKALL = "<input class='btn button' type='button' name='UnCheckAll' value='".LAN_SEARCH_2."' onclick='uncheckAll(this); uncheckG();' />";
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
*/
//$SEARCH_VARS->SEARCH_MAIN_SUBMIT = "<input type='hidden' name='r' value='0' /><input class='btn button' type='submit' name='s' value='".LAN_180."' />";
2006-12-02 04:36:16 +00:00
//$SEARCH_VARS->ENHANCED_ICON = "<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')\"/>";
2006-12-02 04:36:16 +00:00
$enhanced_types['in'] = LAN_SEARCH_24.':';
$enhanced_types['ex'] = LAN_SEARCH_25.':';
$enhanced_types['ep'] = LAN_SEARCH_26.':';
$enhanced_types['be'] = LAN_SEARCH_27.':';
$SEARCH_VARS->ENHANCED_DISPLAY = $enhanced ? "" : "style='display: none'";
2006-12-02 04:36:16 +00:00
// advanced search config
if (!varsettrue($_GET['adv']) || $_GET['t'] == 'all')
{
foreach ($_GET as $gk => $gv)
{
if ($gk != 't' && $gk != 'q' && $gk != 'r' && $gk != 'in' && $gk != 'ex' && $gk != 'ep' && $gk != 'be' && $gk != 'adv')
{
unset($_GET[$gk]);
2006-12-02 04:36:16 +00:00
}
}
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
//$SEARCH_VARS->SEARCH_TYPE_SEL = "<input type='radio' name='adv' value='0' ".(varsettrue($_GET['adv']) ? "" : "checked='checked'")." /> ".LAN_SEARCH_29."&nbsp;
//<input type='radio' name='adv' value='1' ".(varsettrue($_GET['adv']) ? "checked='checked'" : "" )." /> ".LAN_SEARCH_30;
2006-12-02 04:36:16 +00:00
$js_adv = '';
foreach ($search_info as $key => $value)
{
if (!isset($search_info[$key]['advanced']))
{
$js_adv .= " && abid != '".$key."'";
}
2006-12-02 04:36:16 +00:00
}
if (isset($_GET['t']) && isset($search_info[$_GET['t']]['advanced']))
{
$SEARCH_VARS->SEARCH_TYPE_DISPLAY = "";
}
else
{
$SEARCH_VARS->SEARCH_TYPE_DISPLAY = "style='display: none'";
2006-12-02 04:36:16 +00:00
}
if (check_class($search_prefs['google'])) {
$js_adv .= " && abid != '".$google_id."'";
2006-12-02 04:36:16 +00:00
}
if ($perform_search)
{
$con = new convert;
$sch = new e_search;
// omitted words message
$stop_count = count($sch -> stop_keys);
2014-01-06 18:41:35 -08:00
if ($stop_count)
{
if ($stop_count > 1)
{
$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_32.": ";
}
else
{
$SEARCH_VARS->SEARCH_MESSAGE = LAN_SEARCH_33.": ";
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
$i = 1;
foreach ($sch -> stop_keys as $stop_key)
{
$SEARCH_VARS->SEARCH_MESSAGE .= $stop_key;
if ($i != $stop_count)
{
$SEARCH_VARS->SEARCH_MESSAGE .= ', ';
}
$i++;
}
}
2006-12-02 04:36:16 +00:00
}
require_once(HEADERF);
// render search config
/*
if(deftrue('BOOTSTRAP'))
{
$tmp = e107::getCoreTemplate('search','form');
$SEARCH_TOP_TABLE = $tmp['start'];
$SEARCH_BOT_TABLE = $tmp['end'];
$SEARCH_CATS = $tmp['category'];
$SEARCH_TYPE = $tmp['type'];
$SEARCH_ADV = $tmp['advanced'];
$SEARCH_ENHANCED = $tmp['enhanced'];
$SEARCH_ADV_COMBO = $tmp['advanced-combo'];
unset($tmp);
}
*/
2014-01-06 18:41:35 -08:00
2006-12-02 04:36:16 +00:00
if (!isset($SEARCH_TOP_TABLE))
{
2013-03-20 23:50:30 -07:00
if (file_exists(THEME."search_template.php"))
{
2006-12-02 04:36:16 +00:00
require(THEME."search_template.php");
2013-03-20 23:50:30 -07:00
}
else
{
require(e_CORE."templates/search_template.php");
2006-12-02 04:36:16 +00:00
}
}
2014-01-06 18:41:35 -08:00
//$SEARCH_TOP_TABLE = $tp->parseTemplate($SEARCH_TOP_TABLE,true,$srchObj);
//$SEARCH_TYPE = $tp->parseTemplate($SEARCH_TYPE,true, $srchObj);
2014-01-06 18:41:35 -08:00
/*
// standard search config
if ($search_prefs['selector'] == 2)
{
$SEARCH_VARS->SEARCH_DROPDOWN = "<select name='t' id='t' class='tbox' onchange=\"ab()\">";
if ($search_prefs['multisearch']) {
$SEARCH_VARS->SEARCH_DROPDOWN .= "<option value='all'>".LAN_SEARCH_22."</option>";
}
}
else
{
$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES = '';
}
foreach($search_info as $key => $value)
{
if ($search_prefs['selector'] == 2) {
$sel = (isset($searchtype[$key]) && $searchtype[$key]) ? " selected='selected'" : "";
} else {
$sel = (isset($searchtype[$key]) && $searchtype[$key]) ? " checked='checked'" : "";
}
$google_js = check_class($search_prefs['google']) ? "onclick=\"uncheckG();\" " : "";
if ($search_prefs['selector'] == 2) {
$SEARCH_VARS->SEARCH_DROPDOWN .= "<option value='".$key."' ".$sel.">".$value['qtype']."</option>";
} else if ($search_prefs['selector'] == 1) {
$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input ".$google_js." type='checkbox' name='t[".$key."]' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
} else {
$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input type='radio' name='t' value='".$key."' ".$sel." />".$value['qtype'].$POST_CHECKBOXES;
}
}
if (check_class($search_prefs['google']))
{
if ($search_prefs['selector'] == 2) {
$SEARCH_VARS->SEARCH_DROPDOWN .= "<option value='".$google_id."'>Google</option>";
} else if ($search_prefs['selector'] == 1) {
$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input id='google' type='checkbox' name='t[".$google_id."]' onclick='uncheckAll(this)' />Google".$POST_CHECKBOXES;
} else {
$SEARCH_VARS->SEARCH_MAIN_CHECKBOXES .= $PRE_CHECKBOXES."<input id='google' type='radio' name='t' value='".$google_id."' />Google".$POST_CHECKBOXES;
}
}
if ($search_prefs['selector'] == 2)
{
$SEARCH_VARS->SEARCH_DROPDOWN .= "</select>";
}
// end of standard search config
2014-01-06 18:41:35 -08:00
*/
//$text = preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TOP_TABLE);
$tp = e107::getParser();
2014-01-06 18:41:35 -08:00
// $text = $tp->simpleParse($SEARCH_TOP_TABLE, $SEARCH_VARS);
2014-01-06 18:41:35 -08:00
$text = $tp->parseTemplate($SEARCH_TOP_TABLE,true,$srchObj);
foreach ($enhanced_types as $en_id => $ENHANCED_TEXT)
{
$SEARCH_VARS->ENHANCED_TEXT = $ENHANCED_TEXT;
$SEARCH_VARS->ENHANCED_DISPLAY_ID = "en_".$en_id;
$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' />";
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_ENHANCED);
$text .= $tp->simpleParse($SEARCH_ENHANCED, $SEARCH_VARS);
2006-12-02 04:36:16 +00:00
}
$SEARCH_VARS->ENHANCED_TEXT = $SEARCH_VARS->ENHANCED_DISPLAY_ID = $SEARCH_VARS->ENHANCED_FIELD = null;
2014-01-06 18:41:35 -08:00
if ($search_prefs['user_select'])
{
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_CATS);
2014-01-06 18:41:35 -08:00
// $text .= $tp->simpleParse($SEARCH_CATS, $SEARCH_VARS);
$text .= $tp->parseTemplate($SEARCH_CATS,true, $srchObj);
2006-12-02 04:36:16 +00:00
}
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TYPE);
2014-01-06 18:41:35 -08:00
// $text .= $tp->simpleParse($SEARCH_TYPE, $SEARCH_VARS);
$text .= $tp->parseTemplate($SEARCH_TYPE,true, $srchObj);
2006-12-02 04:36:16 +00:00
if ($_GET['adv'])
{
if (isset($search_info[$_GET['t']]['advanced']))
{
if(is_array($search_info[$_GET['t']]['advanced']))
{
$advanced = ($search_info[$_GET['t']]['advanced']);
}
elseif(isset($search_info[$_GET['t']]['advanced']))
{
require_once($search_info[$_GET['t']]['advanced']);
}
foreach ($advanced as $adv_key => $adv_value)
{
if ($adv_value['type'] == 'single')
{
$SEARCH_VARS->SEARCH_ADV_TEXT = $adv_value['text'];
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_ADV_COMBO);
$text .= $tp->simpleParse($SEARCH_ADV_COMBO, $SEARCH_VARS);
}
else
{
if ($adv_value['type'] == 'dropdown')
{
$SEARCH_VARS->SEARCH_ADV_A = $adv_value['text'];
$SEARCH_VARS->SEARCH_ADV_B = "<select name='".$adv_key."' class='tbox'>";
2006-12-02 04:36:16 +00:00
foreach ($adv_value['list'] as $list_item) {
$SEARCH_VARS->SEARCH_ADV_B .= "<option value='".$list_item['id']."' ".($_GET[$adv_key] == $list_item['id'] ? "selected='selected'" : "").">".$list_item['title']."</option>";
2006-12-02 04:36:16 +00:00
}
$SEARCH_VARS->SEARCH_ADV_B .= "</select>";
}
else if ($adv_value['type'] == 'date')
{
$SEARCH_VARS->SEARCH_ADV_A = $adv_value['text'];
$SEARCH_VARS->SEARCH_ADV_B = "<select id='on' name='on' class='tbox'>
2006-12-02 04:36:16 +00:00
<option value='new' ".($_GET['on'] == 'new' ? "selected='selected'" : "").">".LAN_SEARCH_34."</option>
<option value='old' ".($_GET['on'] == 'old' ? "selected='selected'" : "").">".LAN_SEARCH_35."</option>
</select>&nbsp;<select id='time' name='time' class='tbox'>";
$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);
foreach ($time as $time_title => $time_secs)
{
$SEARCH_VARS->SEARCH_ADV_B .= "<option value='".$time_secs."' ".($_GET['time'] == $time_secs ? "selected='selected'" : "").">".$time_title."</option>";
2006-12-02 04:36:16 +00:00
}
$SEARCH_VARS->SEARCH_ADV_B .= "</select>";
}
else if ($adv_value['type'] == 'author')
{
2006-12-02 04:36:16 +00:00
require_once(e_HANDLER.'user_select_class.php');
$us = new user_select;
$SEARCH_VARS->SEARCH_ADV_A = $adv_value['text'];
$SEARCH_VARS->SEARCH_ADV_B = $us -> select_form('popup', $adv_key, $_GET[$adv_key]);
}
else if ($adv_value['type'] == 'dual')
{
$SEARCH_VARS->SEARCH_ADV_A = $adv_value['adv_a'];
$SEARCH_VARS->SEARCH_ADV_B = $adv_value['adv_b'];
2006-12-02 04:36:16 +00:00
}
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_ADV);
$text .= $tp->simpleParse($SEARCH_ADV, $SEARCH_VARS);
2006-12-02 04:36:16 +00:00
}
}
}
2014-01-06 18:41:35 -08:00
else
{
2006-12-02 04:36:16 +00:00
$_GET['adv'] = 0;
}
}
//$
$text .= $SEARCH_MESSAGE ? preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TABLE_MSG) : "";
$text .= $SEARCH_VARS->SEARCH_MESSAGE ? $tp->simpleParse($SEARCH_TABLE_MSG, $SEARCH_VARS) : "";
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_BOT_TABLE);
$text .= $tp->simpleParse($SEARCH_BOT_TABLE, $SEARCH_VARS);
2006-12-02 04:36:16 +00:00
e107::getRender()->tablerender(PAGE_NAME." ".SITENAME, $text, 'search_head');
2006-12-02 04:36:16 +00:00
// parse search
$SEARCH_VARS = new e_vars();
2008-10-14 20:59:38 +00:00
if ($perform_search)
{
2014-01-06 18:41:35 -08:00
$srchObj->renderResults();
/*
2008-10-14 20:59:38 +00:00
$_GET['q'] = rawurlencode($_GET['q']);
2014-01-06 18:41:35 -08:00
$_GET['t'] = preg_replace('/[^\w\-]/i', '', $_GET['t']);
foreach ($search_info as $key => $a)
2012-01-22 14:33:31 +00:00
{
2014-01-06 18:41:35 -08:00
if (isset($searchtype[$key]) || isset($searchtype['all']))
2012-01-22 14:33:31 +00:00
{
2014-01-06 18:41:35 -08:00
unset($text);
//if (file_exists($search_info[$key]['sfile']))
{
2014-01-06 18:41:35 -08:00
$pre_title = ($search_info[$key]['pre_title'] == 2) ? $search_info[$key]['pre_title_alt'] : $search_info[$key]['pre_title'];
$search_chars = $search_info[$key]['chars'];
$search_res = $search_info[$key]['results'];
2014-01-06 18:41:35 -08:00
e107::getAddon();
2014-01-06 18:41:35 -08:00
if(vartrue($search_info[$key]['sfile']) && file_exists($search_info[$key]['sfile'])) // Legacy
{
$text .= '<div class="search-block">';
@require_once($search_info[$key]['sfile']);
$text .= '</div>';
}
else// New v2 standard. @see chatbox_menu/e_search.php
{
$className = $key."_search";
$obj = new $className;
$where = (method_exists($obj,'where')) ? $obj->where($_GET) : "";
$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']);
$text .= '<div class="search-block">';
$text .= $ps['text'];
$text .= '</div>';
$results = $ps['results'];
}
2014-01-06 18:41:35 -08:00
$parms = $results.",".$search_res.",".$_GET['r'].",".e_REQUEST_SELF."?q=".$_GET['q']."&t=".$key."&r=[FROM]";
$core_parms = array('r' => '', 'q' => '', 't' => '', 's' => '');
foreach ($_GET as $pparm_key => $pparm_value)
2012-01-22 14:33:31 +00:00
{
2014-01-06 18:41:35 -08:00
$temp = preg_replace('/[^\w_]/i','',$pparm_key);
$temp1 = preg_replace('/[^\w_ +]/i','',$pparm_value); // Filter 'non-word' charcters in search term
if (($temp == $pparm_key) && !isset($core_parms[$pparm_key]))
{
$parms .= "&".$pparm_key."=".$temp1;
}
2006-12-02 04:36:16 +00:00
}
2014-01-06 18:41:35 -08:00
if ($results > $search_res)
{
$nextprev = ($results > $search_res) ? $tp -> parseTemplate("{NEXTPREV={$parms}}") : "";
$text .= "<div class='nextprev search form-inline'>".$nextprev."</div>";
}
if ($results > 0)
{
$res_from = $_GET['r'] + 1;
$res_to = ($_GET['r'] + $search_res) > $results ? $results : ($_GET['r'] + $search_res);
$res_display = $res_from." - ".$res_to." ".LAN_SEARCH_12." ".$results;
}
else
{
$res_display = "";
}
$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');
2006-12-02 04:36:16 +00:00
}
}
2014-01-06 18:41:35 -08:00
}*/
2006-12-02 04:36:16 +00:00
}
2006-12-02 04:36:16 +00:00
// old 6xx search parser for reverse compatability
function parsesearch($text, $match)
{
$tp = e107::getParser();
2006-12-02 04:36:16 +00:00
$text = strip_tags($text);
$temp = $tp->ustristr($text, $match);
$pos = $tp->ustrlen($text) - $tp->ustrlen($temp);
$matchedText = $tp->usubstr($text,$pos,$tp->ustrlen($match));
2006-12-02 04:36:16 +00:00
if ($pos < 70) {
$text = "...".$tp->usubstr($text, 0, 100)."...";
2006-12-02 04:36:16 +00:00
} else {
$text = "...".$tp->usubstr($text, ($pos-50), $pos+30)."...";
2006-12-02 04:36:16 +00:00
}
$text = preg_replace("/".$match."/i", "<span class='searchhighlight'>".$matchedText."</span>", $text);
return($text);
}
function headerjs() {
global $search_count, $google_id, $search_prefs, $js_adv, $search_info;
if ($search_prefs['selector'] == 1) {
$types = array_keys($search_info);
$types = implode("', '", $types);
$script = "<script type='text/javascript'>
<!--
var i;
var stypes = new Array('".$types."');
function checkAll(allbox) {
for (var i in stypes)
document.getElementById('searchform')[\"t[\" + stypes[i] + \"]\"].checked = true ;
uncheckG();
}
function uncheckAll(allbox) {
for (var i in stypes)
document.getElementById('searchform')[\"t[\" + stypes[i] + \"]\"].checked = false ;
}\n";
if (check_class($search_prefs['google'])) {
$script .= "
function uncheckG() {
document.getElementById('searchform')[\"t[".$google_id."]\"].checked = false ;
}\n";
}
$script .= "// -->
</script>";
}
$script .= "<script type='text/javascript'>
<!--
function ab() {
abid = document.getElementById('t').value;
if (abid != 'all'".$js_adv.") {
document.getElementById('advanced_type').style.display = '';
} else {
document.getElementById('advanced_type').style.display = 'none';
}
}
//-->
</script>";
return $script;
}
require_once(FOOTERF);
?>