1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +02:00

Search upgrades - new e_search.php standard added.

This commit is contained in:
Cameron 2014-01-05 11:25:30 -08:00
parent a790848bdb
commit 42c3588e29
8 changed files with 507 additions and 93 deletions

View File

@ -9,7 +9,8 @@ if (!defined('SEARCH_SHORTCODE_REF')) {
*/
if (!isset($SEARCH_SHORTCODE)) {
if(!isset($SEARCH_SHORTCODE))
{
$SEARCH_SHORTCODE = "<input class='tbox search' type='text' name='q' size='20' value='' maxlength='50' />
<input class='btn button search' type='submit' name='s' value=\"".LAN_180."\" />";
@ -23,8 +24,9 @@ if (!isset($SEARCH_SHORTCODE)) {
if (!isset($SEARCH_TOP_TABLE)) {
$SEARCH_TOP_TABLE = "<div style='text-align: center'>
if(!isset($SEARCH_TOP_TABLE))
{
$SEARCH_TOP_TABLE = "<div>
<form id='searchform' method='get' action='".e_SELF."'>
<table style='".USER_WIDTH."' class='table fborder'><tr>
<td class='forumheader3' style='width: 40%'>".LAN_199."</td>
@ -34,7 +36,10 @@ if (!isset($SEARCH_TOP_TABLE)) {
</tr>";
}
if (!isset($SEARCH_ENHANCED)) {
if(!isset($SEARCH_ENHANCED))
{
$SEARCH_ENHANCED = "<tr id='{ENHANCED_DISPLAY_ID}' {ENHANCED_DISPLAY}>
<td class='forumheader3' style='width: 40%; white-space: nowrap'>{ENHANCED_TEXT}</td>
<td class='forumheader3' style='width: 60%; white-space: nowrap'>
@ -43,7 +48,10 @@ if (!isset($SEARCH_ENHANCED)) {
</tr>";
}
if (!isset($SEARCH_CATS)) {
if(!isset($SEARCH_CATS))
{
$SEARCH_CATS = "<tr>
<td style='width:30%' class='forumheader3'>".LAN_SEARCH_19."<br />
{SEARCH_MAIN_CHECKALL} {SEARCH_MAIN_UNCHECKALL}
@ -55,7 +63,9 @@ if (!isset($SEARCH_CATS)) {
</tr>";
}
if (!isset($SEARCH_TYPE)) {
if(!isset($SEARCH_TYPE))
{
$SEARCH_TYPE = "<tr id='advanced_type' {SEARCH_TYPE_DISPLAY}>
<td style='width:30%' class='forumheader3'>".LAN_SEARCH_75.":</td>
<td style='width:70%' class='forumheader3'>
@ -65,7 +75,9 @@ if (!isset($SEARCH_TYPE)) {
</tr>";
}
if (!isset($SEARCH_ADV)) {
if(!isset($SEARCH_ADV))
{
$SEARCH_ADV = "<tr>
<td class='forumheader3'>
{SEARCH_ADV_A}
@ -76,7 +88,9 @@ if (!isset($SEARCH_ADV)) {
</tr>";
}
if (!isset($SEARCH_ADV_COMBO)) {
if(!isset($SEARCH_ADV_COMBO))
{
$SEARCH_ADV_COMBO = "<tr>
<td class='forumheader3' colspan='2'>
{SEARCH_ADV_TEXT}
@ -84,7 +98,9 @@ if (!isset($SEARCH_ADV_COMBO)) {
</tr>";
}
if (!isset($SEARCH_TABLE_MSG)) {
if(!isset($SEARCH_TABLE_MSG))
{
$SEARCH_TABLE_MSG = "<tr>
<td class='forumheader3' style='text-align: center' colspan='2'>
{SEARCH_MESSAGE}
@ -92,7 +108,9 @@ if (!isset($SEARCH_TABLE_MSG)) {
</tr>";
}
if (!isset($SEARCH_BOT_TABLE)) {
if(!isset($SEARCH_BOT_TABLE))
{
$SEARCH_BOT_TABLE = "<tr style='display: none !important; display: visible'>
<td style='display: none' colspan='2'></td>
</tr></table>
@ -100,12 +118,86 @@ if (!isset($SEARCH_BOT_TABLE)) {
</div>";
}
if (!isset($PRE_CHECKBOXES)) {
if(!isset($PRE_CHECKBOXES))
{
$PRE_CHECKBOXES = "<span style='white-space: nowrap; padding-bottom: 7px; padding-top: 7px'>"; /* string thats printed before each category checkbox */
}
if (!isset($POST_CHECKBOXES)) {
if(!isset($POST_CHECKBOXES))
{
$POST_CHECKBOXES = "</span>"; /* string thats printed after each category checkbox */
}
// Bootstrap v2.
$SEARCH_TEMPLATE['form']['start'] = '
<form class="form-horizontal" role="form" id="searchform" method="get" action="'.e_SELF.'">
<div class="form-group">
<label for="inputEmail3" class="col-sm-3 control-label">'.LAN_199.'</label>
<div class="col-sm-9">{SEARCH_MAIN_SEARCHFIELD}{SEARCH_MAIN_SUBMIT}&nbsp;{ENHANCED_ICON}
</div>
</div>
';
$SEARCH_TEMPLATE['form']['advanced'] = '
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">{SEARCH_ADV_A}</label>
<div class="col-sm-9">
{SEARCH_ADV_B}
</div>
</div>';
$SEARCH_TEMPLATE['form']['enhanced'] = '
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">{ENHANCED_TEXT}</label>
<div class="col-sm-9">
{ENHANCED_FIELD}
</div>
</div>';
$SEARCH_TEMPLATE['form']['type'] = '
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">'.LAN_SEARCH_75.'</label>
<div class="col-sm-9">
{SEARCH_TYPE_SEL}
</div>
</div>';
$SEARCH_TEMPLATE['form']['category'] = '
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">'.LAN_SEARCH_19.'</label>
<div class="col-sm-9">
{SEARCH_MAIN_CHECKBOXES}{SEARCH_DROPDOWN}&nbsp;{SEARCH_ADVANCED}
</div>
</div>';
$SEARCH_TEMPLATE['form']['end'] = "
</form>
";
$SEARCH_TEMPLATE['form']['advanced-combo'] = '<div>{SEARCH_ADV_TEXT}</div>';
/*
"<tr>
<td style='width:30%' class='forumheader3'>".LAN_SEARCH_19."<br />
{SEARCH_MAIN_CHECKALL} {SEARCH_MAIN_UNCHECKALL}
</td>
<td style='width:70%' class='forumheader3'>
{SEARCH_MAIN_CHECKBOXES}{SEARCH_DROPDOWN}&nbsp;{SEARCH_ADVANCED}
<br />
</td>
</tr>";
*/
?>

View File

@ -1750,8 +1750,7 @@ class e107
}
/**
* Retrieves config() from addons such as e_url.php, e_cron.php, e_sitelink.php
* FIXME ASAP extremely bad standard e.g. e_sitelink.php -> plugin_sitelinks. Should be e_sitelinks.php -> plugin_sitelinks or e_sitelink.php -> plugin_sitelink
* Retrieves config() from a specific plugin for addons such as e_url.php, e_cron.php, e_sitelink.php
* FIXME override from e.g. core/override/addons/
*
* @param string $pluginName e.g. faq, page
@ -1787,7 +1786,7 @@ class e107
}
/**
* Retrieves config() from addons such as e_url.php, e_cron.php, e_sitelink.php
* Retrieves config() from all plugins for addons such as e_url.php, e_cron.php, e_sitelink.php
* @param string $addonName eg. e_cron, e_url
* @param string $className [optional] (if different from addonName)
* @return none
@ -1804,6 +1803,7 @@ class e107
}
$elist = self::getPref($filename.'_list');
if($elist)
{
foreach(array_keys($elist) as $key)

View File

@ -2721,8 +2721,7 @@ class e_parser
*/
public function toIcon($icon='',$legacyPath ='')
{
if(!vartrue($icon))
{
return;

View File

@ -27,11 +27,11 @@ if (isset($_GET['time']) && is_numeric($_GET['time'])) {
}
if (isset($_GET['author']) && $_GET['author'] != '') {
$advanced_where .= " c.comment_author LIKE '%".$tp -> toDB($_GET['author'])."%' AND";
$advanced_where .= " c.comment_author_name LIKE '%".$tp -> toDB($_GET['author'])."%' AND";
}
//basic
$return_fields = 'c.comment_item_id, c.comment_author, c.comment_datestamp, c.comment_comment, c.comment_type';
$return_fields = 'c.comment_item_id, c.comment_author_id, comment_author_name, c.comment_datestamp, c.comment_comment, c.comment_type';
foreach ($search_prefs['comments_handlers'] as $h_key => $value) {
if (check_class($value['class'])) {
@ -46,7 +46,7 @@ foreach ($search_prefs['comments_handlers'] as $h_key => $value) {
}
}
$search_fields = array('c.comment_comment', 'c.comment_author');
$search_fields = array('c.comment_comment', 'c.comment_author_name');
$weights = array('1.2', '0.6');
$no_results = LAN_198;
$where = "comment_type IN (".implode(',', $in).") AND".$advanced_where;

View File

@ -16,7 +16,10 @@
if (!defined('e107_INIT')) { exit; }
class e_search {
class e_search
{
var $query;
var $text;
@ -26,7 +29,7 @@ class e_search {
var $stopwords_php = "|a|about|an|and|are|as|at|be|by|com|edu|for|from|how|i|in|is|it|of|on|or|that|the|this|to|was|what|when|where|who|will|with|the|www|";
var $stopwords_mysql = "|a|a's|able|about|above|according|accordingly|across|actually|after|afterwards|again|against|ain't|all|allow|allows|almost|alone|along|already|also|although|always|am|among|amongst|an|and|another|any|anybody|anyhow|anyone|anything|anyway|anyways|anywhere|apart|appear|appreciate|appropriate|are|aren't|around|as|aside|ask|asking|associated|at|available|away|awfully|be|became|because|become|becomes|becoming|been|before|beforehand|behind|being|believe|below|beside|besides|best|better|between|beyond|both|brief|but|by|c'mon|c's|came|can|can't|cannot|cant|cause|causes|certain|certainly|changes|clearly|co|com|come|comes|concerning|consequently|consider|considering|contain|containing|contains|corresponding|could|couldn't|course|currently|definitely|described|despite|did|didn't|different|do|does|doesn't|doing|don't|done|down|downwards|during|each|edu|eg|eight|either|else|elsewhere|enough|entirely|especially|et|etc|even|ever|every|everybody|everyone|everything|everywhere|ex|exactly|example|except|far|few|fifth|first|five|followed|following|follows|for|former|formerly|forth|four|from|further|furthermore|get|gets|getting|given|gives|go|goes|going|gone|got|gotten|greetings|had|hadn't|happens|hardly|has|hasn't|have|haven't|having|he|he's|hello|help|hence|her|here|here's|hereafter|hereby|herein|hereupon|hers|herself|hi|him|himself|his|hither|hopefully|how|howbeit|however|i|i'd|i'll|i'm|i've|ie|if|ignored|immediate|in|inasmuch|inc|indeed|indicate|indicated|indicates|inner|insofar|instead|into|inward|is|isn't|it|it'd|it'll|it's|its|itself|just|keep|keeps|kept|know|knows|known|last|lately|later|latter|latterly|least|less|lest|let|let's|like|liked|likely|little|look|looking|looks|ltd|mainly|many|may|maybe|me|mean|meanwhile|merely|might|more|moreover|most|mostly|much|must|my|myself|name|namely|nd|near|nearly|necessary|need|needs|neither|never|nevertheless|new|next|nine|no|nobody|non|none|noone|nor|normally|not|nothing|novel|now|nowhere|obviously|of|off|often|oh|ok|okay|old|on|once|one|ones|only|onto|or|other|others|otherwise|ought|our|ours|ourselves|out|outside|over|overall|own|particular|particularly|per|perhaps|php|placed|please|plus|possible|presumably|probably|provides|que|quite|qv|rather|rd|re|really|reasonably|regarding|regardless|regards|relatively|respectively|right|said|same|saw|say|saying|says|second|secondly|see|seeing|seem|seemed|seeming|seems|seen|self|selves|sensible|sent|serious|seriously|seven|several|shall|she|should|shouldn't|since|six|so|some|somebody|somehow|someone|something|sometime|sometimes|somewhat|somewhere|soon|sorry|specified|specify|specifying|still|sub|such|sup|sure|t's|take|taken|tell|tends|th|than|thank|thanks|thanx|that|that's|thats|the|their|theirs|them|themselves|then|thence|there|there's|thereafter|thereby|therefore|therein|theres|thereupon|these|they|they'd|they'll|they're|they've|think|third|this|thorough|thoroughly|those|though|three|through|throughout|thru|thus|to|together|too|took|toward|towards|tried|tries|truly|try|trying|twice|two|un|under|unfortunately|unless|unlikely|until|unto|up|upon|us|use|used|useful|uses|using|usually|value|various|very|via|viz|vs|want|wants|was|wasn't|way|we|we'd|we'll|we're|we've|welcome|well|went|were|weren't|what|what's|whatever|when|whence|whenever|where|where's|whereafter|whereas|whereby|wherein|whereupon|wherever|whether|which|while|whither|who|who's|whoever|whole|whom|whose|why|will|willing|wish|with|within|without|won't|wonder|would|would|wouldn't|yes|yet|you|you'd|you'll|you're|you've|your|yours|yourself|yourselves|zero|";
function e_search()
function __construct()
{
$tp = e107::getParser();
$this->query = $query;
@ -73,32 +76,68 @@ class e_search {
}
}
function parsesearch($table, $return_fields, $search_fields, $weights, $handler, $no_results, $where, $order) {
global $sql, $query, $tp, $search_prefs, $pre_title, $search_chars, $search_res, $result_flag;
function parsesearch($table, $return_fields, $search_fields, $weights, $handler, $no_results, $where, $order)
{
global $query, $search_prefs, $pre_title, $search_chars, $search_res, $result_flag;
$sql = e107::getDb('search');
$tp = e107::getParser();
if($handler == 'self')
{
$handler = array($this,'compile');
}
if(is_array($return_fields))
{
$return_fields = implode(",",$return_fields);
}
$this -> query = $tp -> toDB($query);
if (!$search_prefs['mysql_sort']) {
if (!$search_prefs['mysql_sort'])
{
$field_operator = 'AND ';
foreach ($this -> keywords['match'] as $k_key => $key) {
foreach ($this -> keywords['match'] as $k_key => $key)
{
$boolean_regex = '';
if ($this -> keywords['boolean'][$k_key] == '+') {
if ($this -> keywords['boolean'][$k_key] == '+')
{
$key_operator = 'OR ';
$break = TRUE;
$no_exact = TRUE;
} else if ($this -> keywords['boolean'][$k_key] == '-') {
foreach ($this -> keywords as $unset_key => $unset_value) {
} else if ($this -> keywords['boolean'][$k_key] == '-')
{
foreach ($this -> keywords as $unset_key => $unset_value)
{
unset($this -> keywords[$unset_key][$k_key]);
}
$key_operator = 'AND ';
$boolean_regex = 'NOT';
$no_exact = TRUE;
} else if (!isset($break)) {
}
else if (!isset($break))
{
$key_operator = 'OR ';
if (isset($switch)) {
if (isset($switch))
{
$field_operator = 'OR ';
}
$switch = TRUE;
} else {
}
else
{
break;
}
$match_query .= isset($uninitial_field) ? " ".$field_operator." (" : "(";
@ -139,7 +178,9 @@ class e_search {
$exact_query[] = $query;
$this -> keywords['split'] = array_merge($exact_query, $this -> keywords['split']);
}
} else {
}
else
{
$this -> query = str_replace('&quot;', '"', $this -> query);
$field_query = implode(',', $search_fields);
foreach ($search_fields as $field_key => $field) {
@ -154,22 +195,31 @@ class e_search {
$sql_query = "SELECT SQL_CALC_FOUND_ROWS ".$return_fields.", (".$match_query.") AS relevance FROM #".$table." WHERE ".$where." ( MATCH(".$field_query.") AGAINST ('".$this -> query."' IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY relevance DESC ".$sql_order.$limit.";";
}
if ($ps['results'] = $sql -> db_Select_gen($sql_query)) {
if (!$search_prefs['mysql_sort']) {
if ($ps['results'] = $sql->gen($sql_query))
{
if (!$search_prefs['mysql_sort'])
{
$x = 0;
foreach ($search_fields as $field_key => $field) {
$crop_fields[] = preg_replace('/(.*?)\./', '', $field);
}
while ($row = $sql -> db_Fetch()) {
while ($row = $sql -> db_Fetch())
{
$weight = 0;
foreach ($crop_fields as $field_key => $field) {
foreach ($crop_fields as $field_key => $field)
{
$this -> text = $row[$field];
foreach ($this -> keywords['match'] as $k_key => $this -> query) {
if (stristr($this -> text, $this -> query) !== FALSE) {
if ($this -> keywords['exact'][$k_key] || $this -> keywords['boolean'][$k_key]) {
foreach ($this -> keywords['match'] as $k_key => $this -> query)
{
if (stristr($this -> text, $this -> query) !== FALSE)
{
if ($this -> keywords['exact'][$k_key] || $this -> keywords['boolean'][$k_key])
{
$weight += (($weights[$field_key] * 2) * ($keycount));
$endweight = TRUE;
} else if (!$endweight) {
}
else if (!$endweight)
{
$weight += $weights[$field_key];
}
}
@ -177,7 +227,8 @@ class e_search {
$endweight = FALSE;
}
foreach ($row as $r_key => $r_value) {
foreach ($row as $r_key => $r_value)
{
$qrow[$x][$r_key] = $r_value;
$qrow[$x]['relevance'] = $weight;
$qrow[$x]['search_id'] = $x;
@ -185,7 +236,8 @@ class e_search {
$x++;
}
foreach($qrow as $info) {
foreach($qrow as $info)
{
$sortarr[] = $info['relevance'];
}
array_multisort($sortarr, SORT_DESC, $qrow, SORT_DESC);
@ -197,15 +249,19 @@ class e_search {
} else {
$x = 0;
while ($row = $sql -> db_Fetch()) {
while ($row = $sql -> db_Fetch())
{
$display_row[] = $row;
$x++;
}
}
foreach ($display_row as $row) {
foreach ($display_row as $row)
{
$res = call_user_func($handler, $row);
if (!$res['omit_result']) {
if (!$res['omit_result'])
{
$matches = array($res['title'], $res['summary']);
$endcrop = FALSE;
$output = '';
@ -263,7 +319,9 @@ class e_search {
for ($i = 0; $i < $result_number; $i++) {
$ps['text'] .= $ps_limit[$i];
}
} else {
}
else
{
$ps['text'] = $no_results;
}
if ($search_prefs['mysql_sort'])
@ -273,7 +331,10 @@ class e_search {
return $ps;
}
function parsesearch_crop() {
function parsesearch_crop()
{
global $search_chars;
$tp = e107::getParser();
if (strlen($this -> text) > $search_chars) {
@ -288,8 +349,11 @@ class e_search {
$this -> pos = $tp->ustrlen($this -> text) - $tp->ustrlen($match_start);
}
}
function stopword($key) {
function stopword($key)
{
global $search_prefs;
$tp = e107::getParser();
if ($search_prefs['mysql_sort'] && ($key{0} == '+')) {
@ -316,4 +380,7 @@ class e_search {
return FALSE;
}
}
}

View File

@ -1,11 +1,97 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2014 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Chatbox e_search addon
*/
if (!defined('e107_INIT')) { exit; }
if (file_exists(e_PLUGIN."chatbox_menu/languages/".e_LANGUAGE."/lan_chatbox_search.php")) {
include_once(e_PLUGIN."chatbox_menu/languages/".e_LANGUAGE."/lan_chatbox_search.php");
} else {
include_once(e_PLUGIN."chatbox_menu/languages/English/lan_chatbox_search.php");
// v2 e_search addon.
// Removes the need for search_parser.php, search_advanced.php and in most cases search language files.
class chatbox_menu_search extends e_search // include plugin-folder in the name.
{
function config()
{
$search = array(
'name' => LAN_PLUGIN_CHATBOX_MENU_NAME,
'table' => 'chatbox',
'advanced' => array(
'date' => array('type' => 'date', 'text' => LAN_SEARCH_50),
'author'=> array('type' => 'author', 'text' => LAN_SEARCH_61)
),
'return_fields' => array('cb_id', 'cb_nick', 'cb_message', 'cb_datestamp'),
'search_fields' => array('cb_nick', 'cb_message'),
'weights' => array('1', '1'),
'order' => array('cb_datestamp' => DESC),
'refpage' => 'chat.php'
);
return $search;
}
/* Compile Database data for output */
function compile($row)
{
$tp = e107::getParser();
preg_match("/([0-9]+)\.(.*)/", $row['cb_nick'], $user);
$res = array();
$res['link'] = e_PLUGIN."chatbox_menu/chat.php?".$row['cb_id'].".fs";
$res['pre_title'] = LAN_SEARCH_7;
$res['title'] = $user[2];
$res['summary'] = $row['cb_message'];
$res['detail'] = $tp->toDate($row['cb_datestamp'], "long");
return $res;
}
/**
* Optional - Advanced Where
* @param $parm - data returned from $_GET (ie. advanced fields included. in this case 'date' and 'author' )
*/
function where($parm='')
{
$tp = e107::getParser();
$qry = "";
if (vartrue($parm['time']) && is_numeric($parm['time']))
{
$qry .= " cb_datestamp ".($parm['on'] == 'new' ? '>=' : '<=')." '".(time() - $parm['time'])."' AND";
}
if (vartrue($parm['author']))
{
$qry .= " cb_nick LIKE '%".$tp -> toDB($parm['author'])."%' AND";
}
return $qry;
}
}
$search_info[] = array('sfile' => e_PLUGIN.'chatbox_menu/search/search_parser.php', 'qtype' => CB_SCH_LAN_1, 'refpage' => 'chat.php', 'advanced' => e_PLUGIN.'chatbox_menu/search/search_advanced.php');
//Old v1.
// $search_info[] = array('sfile' => e_PLUGIN.'chatbox_menu/search/search_parser.php', 'qtype' => CB_SCH_LAN_1, 'refpage' => 'chat.php', 'advanced' => e_PLUGIN.'chatbox_menu/search/search_advanced.php');
?>

View File

@ -40,6 +40,8 @@ $ps = $sch -> parsesearch('chatbox', $return_fields, $search_fields, $weights, '
$text .= $ps['text'];
$results = $ps['results'];
echo "result = ".$ps['results'];
function search_chatbox($row) {
global $con, $cb_count;
preg_match("/([0-9]+)\.(.*)/", $row['cb_nick'], $user);

View File

@ -10,6 +10,7 @@
require_once('class2.php');
e107::coreLan('search');
e107_require(e_HANDLER.'search_class.php');
if (!check_class($pref['search_restrict'])) {
require_once(HEADERF);
@ -18,7 +19,7 @@ if (!check_class($pref['search_restrict'])) {
exit;
}
if (isset($_GET['t']))
if (isset($_GET['t']) && is_numeric($_GET['t']))
{
switch ($_GET['t'])
{
@ -40,33 +41,91 @@ if (isset($_GET['t']))
}
}
class search_shortcodes extends e_shortcode
{
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')\"/>";
}
}
$search_prefs = $sysprefs -> getArray('search_prefs');
// load search routines
$search_info = array();
$auto_order = 1000;
function search_info($id, $type, $plug_require, $info='')
{
global $tp, $search_prefs, $auto_order;
if (check_class($search_prefs[$type.'_handlers'][$id]['class'])) {
if ($plug_require) {
$tp = e107::getParser();
global $search_prefs, $auto_order;
if (check_class($search_prefs[$type.'_handlers'][$id]['class']))
{
if ($plug_require)
{
require_once($plug_require);
$ret = $search_info[0];
} else {
}
else
{
$ret = $info;
}
$ret['chars'] = $search_prefs[$type.'_handlers'][$id]['chars'];
$ret['results'] = $search_prefs[$type.'_handlers'][$id]['results'];
$ret['pre_title'] = $search_prefs[$type.'_handlers'][$id]['pre_title'];
$ret['pre_title_alt'] = $tp -> toHtml($search_prefs[$type.'_handlers'][$id]['pre_title_alt']);
$ret['order'] = (isset($search_prefs[$type.'_handlers'][$id]['order']) && $search_prefs[$type.'_handlers'][$id]['order']) ? $search_prefs[$type.'_handlers'][$id]['order'] : $auto_order;
if($obj = e107::getAddon($id,'e_search'))
{
$ret = $obj->config();
$ret['qtype'] = $ret['name'];
if(!isset($ret['id']))
{
$ret['id'] = $ret['name'];
}
}
$ret['chars'] = $search_prefs[$type.'_handlers'][$id]['chars'];
$ret['results'] = $search_prefs[$type.'_handlers'][$id]['results'];
$ret['pre_title'] = $search_prefs[$type.'_handlers'][$id]['pre_title'];
$ret['pre_title_alt'] = $tp -> toHtml($search_prefs[$type.'_handlers'][$id]['pre_title_alt']);
$ret['order'] = (isset($search_prefs[$type.'_handlers'][$id]['order']) && $search_prefs[$type.'_handlers'][$id]['order']) ? $search_prefs[$type.'_handlers'][$id]['order'] : $auto_order;
$auto_order++;
return $ret;
} else {
}
else
{
return false;
}
}
//core search routines
if ($search_info['news'] = 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'))) {
@ -103,8 +162,20 @@ if ($search_info['pages'] = search_info('pages', 'core', false, array('sfile' =>
$e_searchList = e107::getConfig('core')->get('e_search_list');
//
// print_a($search_info);
//plugin search routines // plugin folder is used as the search key. ie. $_GET['t'] = 'chatbox';
foreach ($search_prefs['plug_handlers'] as $plug_dir => $active) {
foreach ($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"))
{
@ -117,8 +188,11 @@ foreach ($search_prefs['plug_handlers'] as $plug_dir => $active) {
unset($search_info[$plug_dir]);
}
}
}
// print_a($search_info);
// order search routines
function array_sort($array, $column, $order = SORT_DESC) {
@ -294,17 +368,19 @@ if (!$search_prefs['user_select'] && $_GET['r'] < 1) {
}
$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' />";
//$SEARCH_VARS->SEARCH_MAIN_SEARCHFIELD = "<input class='tbox m_search' type='text' id='q' name='q' size='35' value='".$value."' maxlength='50' />";
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();' />";
}
$SEARCH_VARS->SEARCH_MAIN_SUBMIT = "<input type='hidden' name='r' value='0' /><input class='btn button' type='submit' name='s' value='".LAN_180."' />";
//$SEARCH_VARS->SEARCH_MAIN_SUBMIT = "<input type='hidden' name='r' value='0' /><input class='btn button' type='submit' name='s' value='".LAN_180."' />";
$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')\"/>";
//$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')\"/>";
$enhanced_types['in'] = LAN_SEARCH_24.':';
$enhanced_types['ex'] = LAN_SEARCH_25.':';
@ -354,7 +430,7 @@ if (check_class($search_prefs['google'])) {
if ($perform_search)
{
$con = new convert;
e107_require(e_HANDLER.'search_class.php');
$sch = new e_search;
// omitted words message
@ -385,8 +461,30 @@ if ($perform_search)
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'];
if (!isset($SEARCH_TOP_TABLE)) {
unset($tmp);
}
*/
$search_shortcodes = new search_shortcodes;
if (!isset($SEARCH_TOP_TABLE))
{
if (file_exists(THEME."search_template.php"))
{
require(THEME."search_template.php");
@ -397,7 +495,10 @@ if (!isset($SEARCH_TOP_TABLE)) {
}
}
$SEARCH_TOP_TABLE = $tp->parseTemplate($SEARCH_TOP_TABLE,true,$search_shortcodes);
// standard search config
if ($search_prefs['selector'] == 2)
@ -449,6 +550,11 @@ if ($search_prefs['selector'] == 2)
//$text = preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TOP_TABLE);
$tp = e107::getParser();
$text = $tp->simpleParse($SEARCH_TOP_TABLE, $SEARCH_VARS);
foreach ($enhanced_types as $en_id => $ENHANCED_TEXT)
{
@ -468,39 +574,64 @@ if ($search_prefs['user_select']) {
//$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TYPE);
$text .= $tp->simpleParse($SEARCH_TYPE, $SEARCH_VARS);
if ($_GET['adv']) {
if (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') {
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') {
}
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'>";
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>";
}
$SEARCH_VARS->SEARCH_ADV_B .= "</select>";
} else if ($adv_value['type'] == 'date') {
}
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'>
<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) {
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>";
}
$SEARCH_VARS->SEARCH_ADV_B .= "</select>";
} else if ($adv_value['type'] == 'author') {
}
else if ($adv_value['type'] == 'author')
{
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') {
}
else if ($adv_value['type'] == 'dual')
{
$SEARCH_VARS->SEARCH_ADV_A = $adv_value['adv_a'];
$SEARCH_VARS->SEARCH_ADV_B = $adv_value['adv_b'];
}
@ -508,20 +639,26 @@ if ($_GET['adv']) {
$text .= $tp->simpleParse($SEARCH_ADV, $SEARCH_VARS);
}
}
} else {
}
else {
$_GET['adv'] = 0;
}
}
//$text .= $SEARCH_MESSAGE ? preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_TABLE_MSG) : "";
//$
$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);
e107::getRender()->tablerender(PAGE_NAME." ".SITENAME, $text, 'search_head');
// parse search
$SEARCH_VARS = new e_vars();
if ($perform_search)
{
$_GET['q'] = rawurlencode($_GET['q']);
@ -531,15 +668,42 @@ if ($perform_search)
if (isset($searchtype[$key]) || isset($searchtype['all']))
{
unset($text);
if (file_exists($search_info[$key]['sfile']))
//if (file_exists($search_info[$key]['sfile']))
{
$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'];
$text .= '<div class="search-block">';
@require_once($search_info[$key]['sfile']);
$text .= '</div>';
$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'];
e107::getAddon();
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'];
}
$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)
{
@ -571,6 +735,10 @@ if ($perform_search)
}
}
// old 6xx search parser for reverse compatability
function parsesearch($text, $match)
{