From 67cef013f391203c1916311590238a2cb27cfae4 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 14 Jan 2014 06:09:12 -0800 Subject: [PATCH] Search page completed. Bootstrap3 template functional. e-expandit can now accept multiple target IDs using the data-target attribute. --- e107_core/templates/search_template.php | 16 +- e107_handlers/e_parse_class.php | 6 +- e107_handlers/form_handler.php | 11 +- e107_plugins/news/e_search.php | 117 ++++++++ e107_themes/bootstrap3/theme.php | 4 +- e107_web/js/core/all.jquery.js | 79 +++++- search.php | 362 +++++++++++++++++------- 7 files changed, 478 insertions(+), 117 deletions(-) create mode 100644 e107_plugins/news/e_search.php diff --git a/e107_core/templates/search_template.php b/e107_core/templates/search_template.php index 9f98489f5..1b48e5678 100644 --- a/e107_core/templates/search_template.php +++ b/e107_core/templates/search_template.php @@ -138,24 +138,28 @@ $SEARCH_TEMPLATE['form']['start'] = '
-
{SEARCH_MAIN_SEARCHFIELD}{SEARCH_MAIN_SUBMIT} {ENHANCED_ICON} +
{SEARCH_MAIN}
- +
+ {SEARCH_ENHANCED} +
'; $SEARCH_TEMPLATE['form']['advanced'] = '
-
+
+ {SEARCH_ADV_B} +
'; $SEARCH_TEMPLATE['form']['enhanced'] = ' -
+
{ENHANCED_FIELD} @@ -163,7 +167,7 @@ $SEARCH_TEMPLATE['form']['enhanced'] = '
'; - +/* $SEARCH_TEMPLATE['form']['type'] = '
@@ -171,7 +175,7 @@ $SEARCH_TEMPLATE['form']['type'] = ' {SEARCH_TYPE_SEL}
'; - +*/ $SEARCH_TEMPLATE['form']['category'] = '
diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 4a6632f2f..fef6e5051 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2673,8 +2673,12 @@ class e_parser // Bootstrap 3 Glyph names. $bs3 = e107::getMedia()->getGlyphs('bs3',''); + if(substr($text,0,5) != 'icon-' && substr($text,0,3) != 'fa-') + { + $text = 'icon-'.$text.'.glyph'; + } - if(substr($text,-6) == '.glyph' || strpos($text,".")==false) // Bootstrap or Font-Awesome. +// if(substr($text,-6) == '.glyph' || strpos($text,".")==false) // Bootstrap or Font-Awesome. { list($cls,$tmp) = explode('.glyph',$text); list($type, $tmp2) = explode("-",$text,2); diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index f3c2c21f7..bad6ff8e9 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -1104,13 +1104,13 @@ class e_form $labelFound = vartrue($options['label']); unset($options['label']); // label attribute not valid in html5 - + $options = $this->format_options('radio', $name, $options); $options['checked'] = $checked; //comes as separate argument just for convenience // $options['class'] = 'inline'; $text = ""; - + // return print_a($options,true); if($labelFound) // Bootstrap compatible markup @@ -1119,6 +1119,9 @@ class e_form } + + + $text .= "get_attributes($options, $name, $value)." />"; if(vartrue($options['help'])) @@ -1150,8 +1153,8 @@ class e_form if(vartrue($options['class']) == 'e-expandit' || vartrue($options['expandit'])) // See admin->prefs 'Single Login' for an example. { - $options_on = array('class' => 'e-expandit-on'); - $options_off = array('class' => 'e-expandit-off'); + $options_on = array_merge($options, array('class' => 'e-expandit-on')); + $options_off = array_merge($options, array('class' => 'e-expandit-off')); } $options_on['label'] = $label_enabled ? defset($label_enabled,$label_enabled) : LAN_ENABLED; diff --git a/e107_plugins/news/e_search.php b/e107_plugins/news/e_search.php new file mode 100644 index 000000000..5acd79eeb --- /dev/null +++ b/e107_plugins/news/e_search.php @@ -0,0 +1,117 @@ + 'all', 'title' => LAN_SEARCH_51); + + if ($sql ->select("news_category", "category_id, category_name")) + { + while($row = $sql->fetch()) + { + $catList[] = array('id' => $row['category_id'], 'title' => $row['category_name']); + // $advanced_caption['title'][$row['category_id']] = 'News -> '.$row['category_name']; + } + } + + + $matchList = array( + array('id' => 0, 'title' => LAN_SEARCH_53), + array('id' => 1, 'title' => LAN_SEARCH_54) + ); + + + $search = array( + 'name' => "News", + 'table' => 'news AS n LEFT JOIN #news_category AS c ON n.news_category = c.category_id', + + 'advanced' => array( + 'cat' => array('type' => 'dropdown', 'text' => LAN_SEARCH_55, 'list'=>$catList), + 'date'=> array('type' => 'date', 'text' => LAN_SEARCH_50), + 'match'=> array('type' => 'dropdown', 'text' => LAN_SEARCH_52, 'list'=>$matchList) + ), + + 'return_fields' => array('n.news_id', 'n.news_title', 'n.news_sef', 'n.news_body', 'n.news_extended', 'n.news_allow_comments', 'n.news_datestamp', 'n.news_category', 'c.category_name'), + 'search_fields' => array('n.news_title' => '1.2', 'n.news_body' => '0.6', 'n.news_extended' => '0.6', 'n.news_summary' => '1.2'), // fields and their weights. + + 'order' => array('news_datestamp' => DESC), + 'refpage' => 'news.php' + ); + + + return $search; + } + + + + /* Compile Database data for output */ + function compile($row) + { + $tp = e107::getParser(); + + $res = array(); + + $res['link'] = e107::getUrl()->create('news/view/item', $row);//$row['news_allow_comments'] ? "news.php?item.".$row['news_id'] : "comment.php?comment.news.".$row['news_id']; + $res['pre_title'] = $row['category_name']." | "; + $res['title'] = $row['news_title']; + $res['summary'] = $row['news_body'].' '.$row['news_extended']; + $res['detail'] = LAN_SEARCH_3.$tp->toDate($row['news_datestamp'], "long"); + $res['image'] = $row['news_thumbnail']; + + return $res; + + } + + + + /** + * Optional - Advanced Where + * @param $parm - data returned from $parm (ie. advanced fields included. in this case 'date' and 'author' ) + */ + function where($parm='') + { + $tp = e107::getParser(); + + $time = time(); + + $qry = "(news_start < ".$time.") AND (news_end=0 OR news_end > ".$time.") AND news_class IN (".USERCLASS_LIST.") AND"; + + if (isset($parm['cat']) && $parm['cat'] != 'all') { + $qry .= " c.category_id='".intval($parm['cat'])."' AND"; + } + + if (isset($parm['time']) && is_numeric($parm['time'])) { + $qry .= " n.news_datestamp ".($parm['on'] == 'new' ? '>=' : '<=')." '".(time() - $parm['time'])."' AND"; + } + + return $qry; + } + + +} + +//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'); + +?> \ No newline at end of file diff --git a/e107_themes/bootstrap3/theme.php b/e107_themes/bootstrap3/theme.php index 6a7b7b313..05e5df448 100644 --- a/e107_themes/bootstrap3/theme.php +++ b/e107_themes/bootstrap3/theme.php @@ -72,9 +72,9 @@ function tablestyle($caption, $text, $mode='') } echo '

'.$caption.'

-

+ '.$text.' -

'; + '; return; diff --git a/e107_web/js/core/all.jquery.js b/e107_web/js/core/all.jquery.js index e50889dc1..e2dfdc25b 100644 --- a/e107_web/js/core/all.jquery.js +++ b/e107_web/js/core/all.jquery.js @@ -67,11 +67,19 @@ $(document).ready(function() var href = ($(this).is("a")) ? $(this).attr("href") : ''; - if(href == '' && $(this).attr("data-target")) + if((href === "#" || href == "") && $(this).attr("data-target")) { - href = '#' + $(this).attr("data-target"); + select = $(this).attr("data-target").split(','); // support multiple targets (comma separated) + + $(select).each( function() { + + $('#'+ this).toggle("slow"); + }); + + return false; } + if(href === "#" || href == "") { @@ -79,19 +87,33 @@ $(document).ready(function() $(idt).toggle("slow"); return true; } - + //var id = $(this).attr("href"); $(href).toggle("slow"); + return false; }); + + + + + // On $(".e-expandit-on").click(function () { if($(this).is("input") && $(this).attr("type")=='radio') { - idt = $(this).parent().nextAll("div.e-expandit-container"); + if($(this).attr("data-target")) + { + idt = '#' + $(this).attr("data-target"); + } + else + { + idt = $(this).parent().nextAll("div.e-expandit-container"); + } + $(idt).show("slow"); return true; } @@ -122,7 +144,15 @@ $(document).ready(function() if($(this).is("input") && $(this).attr("type")=='radio') { - idt = $(this).parent().nextAll("div.e-expandit-container"); + if($(this).attr("data-target")) + { + idt = '#' + $(this).attr("data-target"); + } + else + { + idt = $(this).parent().nextAll("div.e-expandit-container"); + } + $(idt).hide("slow"); return true; } @@ -617,7 +647,7 @@ $(document).ready(function() - $(".e-ajax").click(function(){ + $("a.e-ajax").click(function(){ var id = $(this).attr("href"); @@ -663,7 +693,42 @@ $(document).ready(function() }); - + + + + $("select.e-ajax").on('change', function(){ + + var form = $(this).closest("form").attr('id'); + + var target = $(this).attr("data-target"); // support for input buttons etc. + var loading = $(this).attr('data-loading'); // image to show loading. + var handler = $(this).attr('data-src'); + + var data = $('#'+form).serialize(); + + if(loading != null) + { + $("#"+target).html(""); + } + + $.ajax({ + type: 'post', + url: handler, + data: data, + success: function(data) + { + // console.log(data); + $("#"+target).html(data).hide().show("slow");; + } + }); + + + + return false; + + }); + + diff --git a/search.php b/search.php index 6b28eface..a35bad803 100644 --- a/search.php +++ b/search.php @@ -43,39 +43,133 @@ if (isset($_GET['t']) && is_numeric($_GET['t'])) } - class search extends e_shortcode { private $search_prefs = array(); + private $search_info = array(); private $auto_order = 1000; private $enhanced = false; private $query = null; private $result_flag = 0; private $message = ''; + public $template = array(); + private $enhancedTypes = array( + 'in' => LAN_SEARCH_24, + 'ex' => LAN_SEARCH_25, + 'ep' => LAN_SEARCH_26, + 'be' => LAN_SEARCH_27 + ); function __construct() { - $this->search_prefs = e107::getConfig('search')->getPref(); + $this->search_prefs = e107::getConfig('search')->getPref(); + $this->search_info = $this->searchConfig(); - if (!e_QUERY) + + if(deftrue('BOOTSTRAP')) { - $this->enhanced = true; + $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']; + + $this->template = $tmp; + + + + unset($tmp); + } + else + { + if (file_exists(THEME."search_template.php")) + { + require(THEME."search_template.php"); + } + else + { + require(e_CORE."templates/search_template.php"); + } + + $SEARCH_TOP_TABLE .= "{SEARCH_ENHANCED}"; + + $tmp = array(); + + $tmp['start'] = $SEARCH_TOP_TABLE ; + $tmp['end'] = $SEARCH_BOT_TABLE ; + $tmp['category'] = $SEARCH_CATS; + $tmp['type'] = $SEARCH_TYPE; + $tmp['advanced'] = $SEARCH_ADV; + $tmp['enhanced'] = $SEARCH_ENHANCED; + $tmp['advanced-combo'] = $SEARCH_ADV_COMBO; + + $this->template = $tmp; + } + + + + + + if(e_AJAX_REQUEST) + { + if(vartrue($_POST['t'])) + { + echo $this->sc_search_advanced_block($_POST['t']); + } + + exit; } } + function getPrefs() + { + return $this->search_prefs; + } + function getConfig() + { + return $this->search_info; + } // Shortcodes ----------------------- + function sc_search_main($parm = '') + { + $tp = e107::getParser(); + $value = isset($_GET['q']) ? $tp->post_toForm($_GET['q']) : ""; + + $text = "
+ +
+ + + "; + + $text .= ''; + + $text .= " +
+ +
+ "; + + return $text; + + } function sc_search_main_searchfield($parm='') { $tp = e107::getParser(); $value = isset($_GET['q']) ? $tp->post_toForm($_GET['q']) : ""; - return ""; + return ""; } function sc_search_main_submit($parm='') @@ -107,6 +201,10 @@ class search extends e_shortcode function sc_search_type_sel($parm='') { + 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')); + + + return " ".LAN_SEARCH_29."  ".LAN_SEARCH_30; } @@ -131,7 +229,7 @@ class search extends e_shortcode // standard search config if ($this->search_prefs['selector'] == 2) { - $dropdown = ""; if ($this->search_prefs['multisearch']) { @@ -204,8 +302,142 @@ class search extends e_shortcode } + function sc_search_enhanced() + { + + $tp = e107::getParser(); + + $text = ''; + $var = array(); + + foreach ($this->enhancedTypes as $en_id => $ENHANCED_TEXT) + { + $var['ENHANCED_TEXT'] = $ENHANCED_TEXT; + $var['ENHANCED_DISPLAY_ID'] = "en_".$en_id; + $var['ENHANCED_FIELD'] = ""; + + $text .= $tp->simpleParse($this->template['enhanced'], $var); + } + + return $text; + } + function sc_enhanced_display() + { + return ($this->enhanced !== true) ? "style='display: none'" : "" ; + } + + function sc_search_advanced_block($parm='') + { + $tp = e107::getParser(); + $sql = e107::getDb(); + $sql2 = e107::getDb('search'); + + + if(!$parm) + { + // return; + } + + + if (isset($this->search_info[$parm]['advanced'])) + { + + if(is_array($this->search_info[$parm]['advanced'])) + { + $advanced = ($this->search_info[$parm]['advanced']); + } + elseif(isset($this->search_info[$parm]['advanced'])) + { + require($this->search_info[$parm]['advanced']); + + } + + $vars = array(); + + + + foreach ($advanced as $adv_key => $adv_value) + { + if ($adv_value['type'] == 'single') + { + $vars['SEARCH_ADV_TEXT'] = $adv_value['text']; + $text .= $tp->simpleParse($this->template['advanced-combo'], $vars); + } + else + { + if ($adv_value['type'] == 'dropdown') + { + $vars['SEARCH_ADV_A'] = $adv_value['text']; + $vars['SEARCH_ADV_B'] = ""; + } + else if ($adv_value['type'] == 'date') + { + $vars['SEARCH_ADV_A'] = $adv_value['text']; + $vars['SEARCH_ADV_B'] = " + +
+   + + +
"; + } + else if ($adv_value['type'] == 'author') + { + // require_once(e_HANDLER.'user_select_class.php'); + + // $us = new user_select; + $vars['SEARCH_ADV_A'] = $adv_value['text']; + $vars['SEARCH_ADV_B'] = e107::getForm()->userpicker($adv_key."_name",$adv_key,$_GET[$adv_key]); // $us -> select_form('popup', $adv_key, $_GET[$adv_key]); + + + + } + else if ($adv_value['type'] == 'dual') + { + $vars['SEARCH_ADV_A'] = $adv_value['adv_a']; + $vars['SEARCH_ADV_B'] = $adv_value['adv_b']; + } + + $text .= $tp->simpleParse($this->template['advanced'], $vars); + } + } + + + } + else + { + $_GET['adv'] = 0; + } + + + return $text; + } + + + + + + // ------------- @@ -285,12 +517,13 @@ class search extends e_shortcode $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'))) { @@ -350,7 +583,7 @@ class search extends e_shortcode $this->search_info = $search_info; // print_a($this->search_prefs); - print_a($this->search_info); + // print_a($this->search_info); return $search_info; } @@ -500,6 +733,10 @@ class search extends e_shortcode $className = $key."_search"; + if(!class_exists($className)) + { + continue; + } $obj = new $className; $where = (method_exists($obj,'where')) ? $obj->where($_GET) : ""; @@ -684,8 +921,8 @@ class search extends e_shortcode $srchObj = new search; -$search_info = $srchObj->searchConfig(); -$search_prefs = $srchObj->searchPrefs(); +$search_info = $srchObj->getConfig(); +$search_prefs = $srchObj->getPrefs(); // validate search query $perform_search = true; @@ -964,7 +1201,7 @@ if ($perform_search) require_once(HEADERF); // render search config -/* + if(deftrue('BOOTSTRAP')) { $tmp = e107::getCoreTemplate('search','form'); @@ -976,13 +1213,12 @@ if(deftrue('BOOTSTRAP')) $SEARCH_ENHANCED = $tmp['enhanced']; $SEARCH_ADV_COMBO = $tmp['advanced-combo']; - + $srchObj->template = $tmp; unset($tmp); } -*/ @@ -996,8 +1232,15 @@ if (!isset($SEARCH_TOP_TABLE)) { require(e_CORE."templates/search_template.php"); } + + $SEARCH_TOP_TABLE .= "{SEARCH_ENHANCED}"; } + + + + + //$SEARCH_TOP_TABLE = $tp->parseTemplate($SEARCH_TOP_TABLE,true,$srchObj); //$SEARCH_TYPE = $tp->parseTemplate($SEARCH_TYPE,true, $srchObj); @@ -1062,7 +1305,7 @@ $tp = e107::getParser(); $text = $tp->parseTemplate($SEARCH_TOP_TABLE,true,$srchObj); - +/* foreach ($enhanced_types as $en_id => $ENHANCED_TEXT) { $SEARCH_VARS->ENHANCED_TEXT = $ENHANCED_TEXT; @@ -1072,6 +1315,8 @@ foreach ($enhanced_types as $en_id => $ENHANCED_TEXT) $text .= $tp->simpleParse($SEARCH_ENHANCED, $SEARCH_VARS); } $SEARCH_VARS->ENHANCED_TEXT = $SEARCH_VARS->ENHANCED_DISPLAY_ID = $SEARCH_VARS->ENHANCED_FIELD = null; +*/ + if ($search_prefs['user_select']) { @@ -1084,77 +1329,11 @@ if ($search_prefs['user_select']) // $text .= $tp->simpleParse($SEARCH_TYPE, $SEARCH_VARS); $text .= $tp->parseTemplate($SEARCH_TYPE,true, $srchObj); -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 = ""; - } - else if ($adv_value['type'] == 'date') - { - $SEARCH_VARS->SEARCH_ADV_A = $adv_value['text']; - $SEARCH_VARS->SEARCH_ADV_B = " "; - } - 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') - { - $SEARCH_VARS->SEARCH_ADV_A = $adv_value['adv_a']; - $SEARCH_VARS->SEARCH_ADV_B = $adv_value['adv_b']; - } - //$text .= preg_replace("/\{(.*?)\}/e", '$\1', $SEARCH_ADV); - $text .= $tp->simpleParse($SEARCH_ADV, $SEARCH_VARS); - } - } - } - else - { - $_GET['adv'] = 0; - } -} + + $text .= "
"; + $text .= $tp->parseTemplate("{SEARCH_ADVANCED_BLOCK=".vartrue($_GET['t'])."}",true, $srchObj); + $text .= "
"; + //$ @@ -1308,18 +1487,7 @@ function headerjs() { } - $script .= ""; + return $script; }