/** * Remote Search method * * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @return array Search Results * @since 1.5 */ function searchSite($searchword, $phrase = '', $order = '') { global $mainframe; // Initialize variables $db =& JFactory::getDBO(); // Prepare arguments $searchword = $db->getEscaped(trim($searchword)); $phrase = ''; $ordering = ''; // Load search plugins and fire the onSearch event JPluginHelper::importPlugin('search'); $results = $mainframe->triggerEvent('onSearch', array($searchword, $phrase, $ordering)); // Iterate through results building the return array require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php'; foreach ($results as $i => $rows) { foreach ($rows as $j => $row) { $results[$i][$j]->href = preg_match('#^(http|https)://#i', $row->href) ? $row->href : JURI::root() . '/' . $row->href; $results[$i][$j]->text = SearchHelper::prepareSearchContent($row->text, 200, $searchword); } } return $results; }
function onRestCall() { $searchword = JRequest::getVar('keyword'); $match = JRequest::getVar('match'); // Get the results $results = $this->doSearch(); // Process them like Joomla does for ($i = 0; $i < count($results); $i++) { $row =& $results[$i]->text; if ($match == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchwords = preg_split("/\\s+/u", $searchword); $needle = $searchwords[0]; } $row = SearchHelper::prepareSearchContent($row, 200, $needle); $searchwords = array_unique($searchwords); /* $searchRegex = '#('; $x = 0; foreach ($searchwords as $k => $hlword) { $searchRegex .= ($x == 0 ? '' : '|'); $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; */ $result =& $results[$i]; if ($result->created) { $created = $result->created; } else { $created = ''; } $result->created = $created; $result->count = $i + 1; } return $results; }
public function display($tpl = null) { require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/search.php'; $app = JFactory::getApplication(); $pathway = $app->getPathway(); $uri = JURI::getInstance(); $error = null; $rows = null; $results = null; $total = 0; // Get some data from the model $areas = $this->get('areas'); $state = $this->get('state'); $searchword = $state->get('keyword'); $params = $app->getParams(); $menus = $app->getMenu(); $menu = $menus->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JRegistry(); $menu_params->loadString($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', JText::_('COM_SEARCH_SEARCH')); } } else { $params->set('page_title', JText::_('COM_SEARCH_SEARCH')); } $title = $params->get('page_title'); if ($app->getCfg('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename')); } $this->document->setTitle($title); if ($params->get('menu-meta_description')) { $this->document->setDescription($params->get('menu-meta_description')); } if ($params->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $params->get('menu-meta_keywords')); } if ($params->get('robots')) { $this->document->setMetadata('robots', $params->get('robots')); } // built select lists $orders = array(); $orders[] = JHtml::_('select.option', 'newest', JText::_('COM_SEARCH_NEWEST_FIRST')); $orders[] = JHtml::_('select.option', 'oldest', JText::_('COM_SEARCH_OLDEST_FIRST')); $orders[] = JHtml::_('select.option', 'popular', JText::_('COM_SEARCH_MOST_POPULAR')); $orders[] = JHtml::_('select.option', 'alpha', JText::_('COM_SEARCH_ALPHABETICAL')); $orders[] = JHtml::_('select.option', 'category', JText::_('JCATEGORY')); $lists = array(); $lists['ordering'] = JHtml::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text', $state->get('ordering')); $searchphrases = array(); $searchphrases[] = JHtml::_('select.option', 'all', JText::_('COM_SEARCH_ALL_WORDS')); $searchphrases[] = JHtml::_('select.option', 'any', JText::_('COM_SEARCH_ANY_WORDS')); $searchphrases[] = JHtml::_('select.option', 'exact', JText::_('COM_SEARCH_EXACT_PHRASE')); $lists['searchphrase'] = JHtml::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', $state->get('match')); // log the search JSearchHelper::logSearch($searchword, 'com_search'); //limit searchword $lang = JFactory::getLanguage(); $upper_limit = $lang->getUpperLimitSearchWord(); $lower_limit = $lang->getLowerLimitSearchWord(); if (SearchHelper::limitSearchWord($searchword)) { $error = JText::sprintf('COM_SEARCH_ERROR_SEARCH_MESSAGE', $lower_limit, $upper_limit); } // Sanitise searchword if (SearchHelper::santiseSearchWord($searchword, $state->get('match'))) { $error = JText::_('COM_SEARCH_ERROR_IGNOREKEYWORD'); } if (!$searchword && !empty($this->input) && count($this->input->post)) { // $error = JText::_('COM_SEARCH_ERROR_ENTERKEYWORD'); } // Put the filtered results back into the model // for next release, the checks should be done in the model perhaps... $state->set('keyword', $searchword); if ($error == null) { $results = $this->get('data'); $total = $this->get('total'); $pagination = $this->get('pagination'); require_once JPATH_SITE . '/components/com_content/helpers/route.php'; for ($i = 0, $count = count($results); $i < $count; $i++) { $row =& $results[$i]->text; if ($state->get('match') == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchworda = preg_replace('#\\xE3\\x80\\x80#s', ' ', $searchword); $searchwords = preg_split("/\\s+/u", $searchworda); $needle = $searchwords[0]; } $row = SearchHelper::prepareSearchContent($row, $needle); $searchwords = array_unique($searchwords); $searchRegex = '#('; $x = 0; foreach ($searchwords as $k => $hlword) { $searchRegex .= $x == 0 ? '' : '|'; $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; $row = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $row); $result =& $results[$i]; if ($result->created) { $created = JHtml::_('date', $result->created, JText::_('DATE_FORMAT_LC3')); } else { $created = ''; } $result->text = JHtml::_('content.prepare', $result->text, '', 'com_search.search'); $result->created = $created; $result->count = $i + 1; } } // Check for layout override $active = JFactory::getApplication()->getMenu()->getActive(); if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->pagination =& $pagination; $this->results =& $results; $this->lists =& $lists; $this->params =& $params; $this->ordering = $state->get('ordering'); $this->searchword = $searchword; $this->origkeyword = $state->get('origkeyword'); $this->searchphrase = $state->get('match'); $this->searchareas = $areas; $this->total = $total; $this->error = $error; $this->action = $uri; parent::display($tpl); }
/** * Process search * @param type $query Search query * @return array Rerach Results * * This method uses portions of SearchController::search from components/com_search/controller.php * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. */ public function doSearch($query) { $wf = WFEditorPlugin::getInstance(); $filter = JFilterInput::getInstance(); if (!class_exists('JSite')) { // Load JSite class JLoader::register('JSite', JPATH_SITE . '/includes/application.php'); } $app = JApplication::getInstance('site'); $router = $app->getRouter('site'); // get SearchHelper require_once JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php'; // get router mode $sef = (int) $wf->getParam('search.link.sef_url', 0); // set router off so a raw url is returned by the Search plugin if ($router) { $router->setMode(0); } // slashes cause errors, <> get stripped anyway later on. # causes problems. $searchword = trim(str_replace(array('#', '>', '<', '\\'), '', $filter->clean($query))); $ordering = JRequest::getWord('ordering', null, 'post'); $searchphrase = JRequest::getWord('searchphrase', 'all', 'post'); $areas = JRequest::getVar('areas', null, 'post', 'array'); // if searchword enclosed in double quotes, strip quotes and do exact match if (substr($searchword, 0, 1) == '"' && substr($searchword, -1) == '"') { $searchword = substr($searchword, 1, -1); $searchphrase = 'exact'; } // clean areas if (!empty($areas)) { foreach ($areas as $area) { $areas[] = $filter->clean($area, 'cmd'); } } $event = WF_JOOMLA15 ? 'onSearch' : 'onContentSearch'; // trigger search on loaded plugins $searches = $app->triggerEvent($event, array($searchword, $searchphrase, $ordering, $areas)); $results = array(); $rows = array(); foreach ($searches as $search) { $rows = array_merge((array) $rows, (array) $search); } for ($i = 0, $count = count($rows); $i < $count; $i++) { $row =& $rows[$i]; $result = new StdClass(); if ($searchphrase == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchworda = preg_replace('#\\xE3\\x80\\x80#s', ' ', $searchword); $searchwords = preg_split("/\\s+/u", $searchworda); $needle = $searchwords[0]; } // get anchors $anchors = self::getAnchors($row->text); if (!empty($anchors)) { $row->anchors = $anchors; } if (method_exists('SearchHelper', 'getActions')) { $row->text = SearchHelper::prepareSearchContent($row->text, $needle); } else { $row->text = SearchHelper::prepareSearchContent($row->text, 200, $needle); } $searchwords = array_unique($searchwords); $searchRegex = '#('; $x = 0; foreach ($searchwords as $k => $hlword) { $searchRegex .= $x == 0 ? '' : '|'; $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; $row->text = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $row->text); // remove base url if (strpos($row->href, JURI::base(true)) !== false) { $row->href = substr_replace($row->href, '', 0, strlen(JURI::base(true)) + 1); } // convert to SEF if ($router && $sef) { $router->setMode(1); $url = str_replace('&', '&', $row->href); $uri = $router->build($url); $url = $uri->toString(); $row->href = str_replace('/administrator/', '/', $url); } $result->title = $row->title; $result->text = $row->text; $result->link = $row->href; $results[] = $result; } return $results; }
function display($tpl = null) { global $mainframe; require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'search.php'; // Initialize some variables $pathway =& $mainframe->getPathway(); $uri =& JFactory::getURI(); $error = ''; $rows = null; $total = 0; // Get some data from the model $areas =& $this->get('areas'); $state =& $this->get('state'); $searchword = $state->get('keyword'); $params =& $mainframe->getParams(); $menus =& JSite::getMenu(); $menu = $menus->getActive(); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JParameter($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', JText::_('Search')); } } else { $params->set('page_title', JText::_('Search')); } $document =& JFactory::getDocument(); $document->setTitle($params->get('page_title')); // Get the parameters of the active menu item $params =& $mainframe->getParams(); // built select lists $orders = array(); $orders[] = JHTML::_('select.option', 'newest', JText::_('Newest first')); $orders[] = JHTML::_('select.option', 'oldest', JText::_('Oldest first')); $orders[] = JHTML::_('select.option', 'popular', JText::_('Most popular')); $orders[] = JHTML::_('select.option', 'alpha', JText::_('Alphabetical')); $orders[] = JHTML::_('select.option', 'category', JText::_('Section/Category')); $lists = array(); $lists['ordering'] = JHTML::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text', $state->get('ordering')); $searchphrases = array(); $searchphrases[] = JHTML::_('select.option', 'all', JText::_('All words')); $searchphrases[] = JHTML::_('select.option', 'any', JText::_('Any words')); $searchphrases[] = JHTML::_('select.option', 'exact', JText::_('Exact phrase')); $lists['searchphrase'] = JHTML::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', $state->get('match')); // log the search SearchHelper::logSearch($searchword); //limit searchword if (SearchHelper::limitSearchWord($searchword)) { $error = JText::_('SEARCH_MESSAGE'); } //sanatise searchword if (SearchHelper::santiseSearchWord($searchword, $state->get('match'))) { $error = JText::_('IGNOREKEYWORD'); } if (!$searchword && count(JRequest::get('post'))) { //$error = JText::_( 'Enter a search keyword' ); } // put the filtered results back into the model // for next release, the checks should be done in the model perhaps... $state->set('keyword', $searchword); if (!$error) { $results =& $this->get('data'); $total =& $this->get('total'); $pagination =& $this->get('pagination'); require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php'; for ($i = 0; $i < count($results); $i++) { $row =& $results[$i]->text; if ($state->get('match') == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchwords = preg_split("/\\s+/u", $searchword); $needle = $searchwords[0]; } $row = SearchHelper::prepareSearchContent($row, 200, $needle); $searchwords = array_unique($searchwords); $searchRegex = '#('; $x = 0; foreach ($searchwords as $k => $hlword) { $searchRegex .= $x == 0 ? '' : '|'; $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; $row = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $row); $result =& $results[$i]; if ($result->created) { $created = JHTML::Date($result->created); } else { $created = ''; } $result->created = $created; $result->count = $i + 1; } } $this->result = JText::sprintf('TOTALRESULTSFOUND', $total); $this->assignRef('pagination', $pagination); $this->assignRef('results', $results); $this->assignRef('lists', $lists); $this->assignRef('params', $params); $this->assign('ordering', $state->get('ordering')); $this->assign('searchword', $searchword); $this->assign('searchphrase', $state->get('match')); $this->assign('searchareas', $areas); $this->assign('total', $total); $this->assign('error', $error); $this->assign('action', $uri->toString()); parent::display($tpl); }
/** * Function to show the intro of the article * @param object $row Content Item row * @param string $searchword searched word to be highlighted * @param object $params Component parameters * @return HTML HTML string with Article title rendered */ function showIntro($row, $searchword, $params) { $text_length = $params->get('text_length'); $show_section = $params->get('show_section'); ?> <div class="cp_text"> <?php if ($searchword == "") { echo prepareContent($row->introtext . ' ' . $row->fulltext, $text_length); } else { /* using same helper as mod_cpsearch */ $helper_path = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php'; require_once $helper_path; $text = SearchHelper::prepareSearchContent($row->introtext . ' ' . $row->fulltext, $text_length, $searchword); $text = preg_replace('/(' . $searchword . ')/i', '<span class="highlight">\\0</span>', $text); echo $text; } ?> </div> <?php }
/** * Execute and display a template script. * * @param string $tpl The name of the template file to parse; automatically searches through the template paths. * * @return mixed A string if successful, otherwise an Error object. */ public function display($tpl = null) { JLoader::register('SearchHelper', JPATH_COMPONENT_ADMINISTRATOR . '/helpers/search.php'); $app = JFactory::getApplication(); $uri = JUri::getInstance(); $error = null; $rows = null; $results = null; $total = 0; // Get some data from the model $areas = $this->get('areas'); $state = $this->get('state'); $searchword = $state->get('keyword'); $params = $app->getParams(); $menus = $app->getMenu(); $menu = $menus->getActive(); // Because the application sets a default page title, we need to get it right from the menu item itself if (is_object($menu)) { $menu_params = new Registry($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', JText::_('COM_SEARCH_SEARCH')); } } else { $params->set('page_title', JText::_('COM_SEARCH_SEARCH')); } $title = $params->get('page_title'); if ($app->get('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title); } elseif ($app->get('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename')); } $this->document->setTitle($title); if ($params->get('menu-meta_description')) { $this->document->setDescription($params->get('menu-meta_description')); } if ($params->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $params->get('menu-meta_keywords')); } if ($params->get('robots')) { $this->document->setMetadata('robots', $params->get('robots')); } // Built select lists $orders = array(); $orders[] = JHtml::_('select.option', 'newest', JText::_('COM_SEARCH_NEWEST_FIRST')); $orders[] = JHtml::_('select.option', 'oldest', JText::_('COM_SEARCH_OLDEST_FIRST')); $orders[] = JHtml::_('select.option', 'popular', JText::_('COM_SEARCH_MOST_POPULAR')); $orders[] = JHtml::_('select.option', 'alpha', JText::_('COM_SEARCH_ALPHABETICAL')); $orders[] = JHtml::_('select.option', 'category', JText::_('JCATEGORY')); $lists = array(); $lists['ordering'] = JHtml::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text', $state->get('ordering')); $searchphrases = array(); $searchphrases[] = JHtml::_('select.option', 'all', JText::_('COM_SEARCH_ALL_WORDS')); $searchphrases[] = JHtml::_('select.option', 'any', JText::_('COM_SEARCH_ANY_WORDS')); $searchphrases[] = JHtml::_('select.option', 'exact', JText::_('COM_SEARCH_EXACT_PHRASE')); $lists['searchphrase'] = JHtml::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', $state->get('match')); // Log the search JSearchHelper::logSearch($searchword, 'com_search'); // Limit searchword $lang = JFactory::getLanguage(); $upper_limit = $lang->getUpperLimitSearchWord(); $lower_limit = $lang->getLowerLimitSearchWord(); if (SearchHelper::limitSearchWord($searchword)) { $error = JText::sprintf('COM_SEARCH_ERROR_SEARCH_MESSAGE', $lower_limit, $upper_limit); } // Sanitise searchword if (SearchHelper::santiseSearchWord($searchword, $state->get('match'))) { $error = JText::_('COM_SEARCH_ERROR_IGNOREKEYWORD'); } if (!$searchword && !empty($this->input) && count($this->input->post)) { // $error = JText::_('COM_SEARCH_ERROR_ENTERKEYWORD'); } // Put the filtered results back into the model // for next release, the checks should be done in the model perhaps... $state->set('keyword', $searchword); if ($error == null) { $results = $this->get('data'); $total = $this->get('total'); $pagination = $this->get('pagination'); JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php'); for ($i = 0, $count = count($results); $i < $count; $i++) { $row =& $results[$i]->text; if ($state->get('match') == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchworda = preg_replace('#\\xE3\\x80\\x80#s', ' ', $searchword); $searchwords = preg_split("/\\s+/u", $searchworda); $needle = $searchwords[0]; } $row = SearchHelper::prepareSearchContent($row, $needle); $searchwords = array_values(array_unique($searchwords)); $srow = strtolower(SearchHelper::remove_accents($row)); $hl1 = '<span class="highlight">'; $hl2 = '</span>'; $posCollector = array(); $mbString = extension_loaded('mbstring'); if ($mbString) { // E.g. german umlauts like ä are converted to ae and so // $pos calculated with $srow doesn't match for $row $correctPos = mb_strlen($srow) > mb_strlen($row); $highlighterLen = mb_strlen($hl1 . $hl2); } else { // E.g. german umlauts like ä are converted to ae and so // $pos calculated with $srow desn't match for $row $correctPos = StringHelper::strlen($srow) > StringHelper::strlen($row); $highlighterLen = StringHelper::strlen($hl1 . $hl2); } foreach ($searchwords as $hlword) { if ($mbString) { if (($pos = mb_strpos($srow, strtolower(SearchHelper::remove_accents($hlword)))) !== false) { // Iconv transliterates '€' to 'EUR' // TODO: add other expanding translations? $eur_compensation = $pos > 0 ? substr_count($row, "€", 0, $pos) * 2 : 0; $pos -= $eur_compensation; if ($correctPos) { // Calculate necessary corrections from 0 to current $pos $ChkRow = mb_substr($row, 0, $pos); $sChkRowLen = mb_strlen(strtolower(SearchHelper::remove_accents($ChkRow))); $ChkRowLen = mb_strlen($ChkRow); // Correct $pos $pos -= $sChkRowLen - $ChkRowLen; } // Collect pos and searchword $posCollector[$pos] = $hlword; } } else { if (($pos = StringHelper::strpos($srow, strtolower(SearchHelper::remove_accents($hlword)))) !== false) { // Iconv transliterates '€' to 'EUR' // TODO: add other expanding translations? $eur_compensation = $pos > 0 ? substr_count($row, "€", 0, $pos) * 2 : 0; $pos -= $eur_compensation; if ($correctPos) { // Calculate necessary corrections from 0 to current $pos $ChkRow = StringHelper::substr($row, 0, $pos); $sChkRowLen = StringHelper::strlen(strtolower(SearchHelper::remove_accents($ChkRow))); $ChkRowLen = StringHelper::strlen($ChkRow); // Correct $pos $pos -= $sChkRowLen - $ChkRowLen; } // Collect pos and searchword $posCollector[$pos] = $hlword; } } } if (count($posCollector)) { // Sort by pos. Easier to handle overlapping highlighter-spans ksort($posCollector); $cnt = 0; $lastHighlighterEnd = -1; foreach ($posCollector as $pos => $hlword) { $pos += $cnt * $highlighterLen; /* Avoid overlapping/corrupted highlighter-spans * TODO $chkOverlap could be used to highlight remaining part * of searchword outside last highlighter-span. * At the moment no additional highlighter is set.*/ $chkOverlap = $pos - $lastHighlighterEnd; if ($chkOverlap >= 0) { // Set highlighter around searchword if ($mbString) { $hlwordLen = mb_strlen($hlword); $row = mb_substr($row, 0, $pos) . $hl1 . mb_substr($row, $pos, $hlwordLen) . $hl2 . mb_substr($row, $pos + $hlwordLen); } else { $hlwordLen = StringHelper::strlen($hlword); $row = StringHelper::substr($row, 0, $pos) . $hl1 . StringHelper::substr($row, $pos, StringHelper::strlen($hlword)) . $hl2 . StringHelper::substr($row, $pos + StringHelper::strlen($hlword)); } $cnt++; $lastHighlighterEnd = $pos + $hlwordLen + $highlighterLen; } } } $result =& $results[$i]; if ($result->created) { $created = JHtml::_('date', $result->created, JText::_('DATE_FORMAT_LC3')); } else { $created = ''; } $result->text = JHtml::_('content.prepare', $result->text, '', 'com_search.search'); $result->created = $created; $result->count = $i + 1; } } // Check for layout override $active = JFactory::getApplication()->getMenu()->getActive(); if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } // Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->pagination =& $pagination; $this->results =& $results; $this->lists =& $lists; $this->params =& $params; $this->ordering = $state->get('ordering'); $this->searchword = $searchword; $this->origkeyword = $state->get('origkeyword'); $this->searchphrase = $state->get('match'); $this->searchareas = $areas; $this->total = $total; $this->error = $error; $this->action = $uri; parent::display($tpl); }
function parseItems_params($items, $type = null) { global $javconfig; //print_r($items);exit; $db = JFactory::getDBO(); $helper = new JAVoiceHelpers(); $Itemid = JRequest::getInt('Itemid'); if ($type) { $types[0] = $type; } else { $types = $this->getVoiceTypes(); } $array_votes = array(); if ($types) { foreach ($types as $type) { $params_type = class_exists('JRegistry') ? new JRegistry($type->vote_option) : new JParameter($type->vote_option); $array_votes[$type->id]['value'] = $params_type->get('votes_value') ? str_replace("###", ',', $params_type->get('votes_value')) : ''; $array_votes[$type->id]['text'] = $params_type->get('votes_text') ? $db->Quote(str_replace("###", ',', $params_type->get('votes_text'))) : ''; $array_votes[$type->id]['description'] = $params_type->get('votes_description') ? $db->Quote(str_replace("###", ',', htmlspecialchars($params_type->get('votes_description')))) : ''; } } $currentUser = JFactory::getUser(); require_once JPATH_SITE . DS . 'components' . DS . 'com_javoice' . DS . 'models' . DS . 'forums.php'; $model_forums = new JAVoiceModelforums(); $searchword = JRequest::getString('key'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php'; if ($items) { $model_status = JAVBModel::getInstance('voicetypesstatus', 'javoiceModel'); foreach ($items as $k => $item) { if (!$item->status_publishded) { $items[$k]->voice_type_status_id = 0; } $items[$k]->content = $helper->showItem($items[$k]->content, 0); //if user use anonymous in this item if (!($javconfig['systems']->get('use_anonymous', 0) && $item->use_anonymous)) { if (isset($item->user_id) && $item->user_id > 0) { $user = JFactory::getUser($item->user_id); if ($javconfig['plugin']->get('displayname', 'username') == "name") { $creat_by = $user->name; } else { if ($javconfig['plugin']->get('displayname', 'username') == "username") { $creat_by = $user->username; } else { $creat_by = JText::_("ANONYMOUS"); } } } elseif (isset($item->guest_name) && $item->guest_name != '') { if ($javconfig['plugin']->get('displayname', 'username') == "anonymous") { $creat_by = JText::_("ANONYMOUS"); } else { $creat_by = $item->guest_name; } } else { $creat_by = JText::_('ANONYMOUS'); } } else { $creat_by = JText::_('ANONYMOUS'); } $link = JRoute::_('index.php?option=com_javoice&view=items&layout=item&cid=' . $item->id . '&type=' . $item->voice_types_id . '&forums=' . $item->forums_id . '&Itemid=' . $Itemid); $items[$k]->create_date_store = $item->create_date; $items[$k]->create_date = $helper->generatTimeStamp($item->create_date); $items[$k]->update_date = $helper->generatTimeStamp($item->update_date); $items[$k]->create_by = $creat_by; $items[$k]->link = $link; $items[$k]->list_vote_value = ''; $items[$k]->list_vote_text = '\'\''; $items[$k]->list_vote_description = '\'\''; $items[$k]->has_down = 0; $check = true; /* Check status has closed */ if ($item->voice_type_status_id && $item->status_allow_voting == 0) { $items[$k]->list_vote_msg = $db->Quote(JText::_('VOTING_IS_CLOSED')); $check = false; } elseif ($item->voice_type_status_id && $item->status_allow_voting == -1) { $parent_status = $model_status->getItem($item->status_parent_id); if ($parent_status->allow_voting == 0) { $items[$k]->list_vote_msg = $db->Quote(JText::_('VOTING_IS_CLOSED')); $check = false; } else { $item->status_allow_voting = $parent_status->allow_voting; } } if ($check) { $user_can_post = $user_can_view = 0; $forum = $model_forums->getItem(array($item->forums_id)); $forum->gids_post = str_replace("\n\n", "\n", $forum->gids_post); $forum->gids_vote = str_replace("\n\n", "\n", $forum->gids_post); $lits_user_can_posts = explode("\n", $forum->gids_post); $lits_user_can_views = explode("\n", $forum->gids_view); $levels = $currentUser->getAuthorisedViewLevels(); $levels[] = 0; foreach ($levels as $gkey => $gVal) { if (in_array($gVal, $lits_user_can_posts)) { $user_can_post = 1; } if (in_array($gVal, $lits_user_can_views)) { $user_can_view = 1; } } if (!$user_can_view) { unset($items[$k]); } else { if ($user_can_post && isset($array_votes[$item->voice_types_id]['value'])) { $items[$k]->list_vote_value = $array_votes[$item->voice_types_id]['value']; $items[$k]->list_vote_text = $array_votes[$item->voice_types_id]['text']; $items[$k]->list_vote_description = $array_votes[$item->voice_types_id]['description']; $items[$k]->list_vote_msg = '\'\''; $values = explode(',', $array_votes[$item->voice_types_id]['value']); foreach ($values as $value) { if (intval($value) < 0) { $items[$k]->has_down = 1; break; } } } else { if ($currentUser->id) { $items[$k]->list_vote_msg = '<span class=error>' . JText::_('YOU_DO_NOT_HAVE_PERMISSION_TO_VOTE') . '<span>'; } else { $items[$k]->list_vote_msg = JText::_('LOGINREGISTER_TO_VOTE'); } $items[$k]->list_vote_msg = $db->Quote($items[$k]->list_vote_msg); } } } if ($searchword && isset($items[$k])) { $searchwords = preg_split("/\\s+/u", $searchword); $needle = $searchwords[0]; $maxchars = $javconfig['systems']->get('maxchars', 100); if ($maxchars == -1) { $maxchars = strlen($item->content); } SearchHelper::prepareSearchContent($item->content, $maxchars, $needle); $searchwords = array_unique($searchwords); $searchRegex = '#('; $x = 0; foreach ($searchwords as $hlword) { $searchRegex .= $x == 0 ? '' : '|'; $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; $items[$k]->content = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $item->content); $items[$k]->title = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $item->title); } } } return $items; }
?> ) </span> </dd> <?php } ?> <dd class="result-text"> <?php if (isset($this->highlight['introtext'])) { echo ElasticSearchHelper::truncateHighLight($this->highlight['introtext'], 200); } else { if (isset($this->highlight['fulltext'])) { echo ElasticSearchHelper::truncateHighLight($this->highlight['fulltext'], 500); } else { $text = SearchHelper::prepareSearchContent($this->data['introtext'], ""); echo JHtmlString::truncate($text, 500, true, false); } } ?> </dd> <?php if (isset($this->data['created_at'])) { ?> <dd class="result-created"> <?php $date = new DateTime($this->data['created_at']); echo JText::sprintf('JGLOBAL_CREATED_DATE_ON', $date->format('Y-m-d H:i:s')); ?> </dd> <?php
<?php if ($categories) { ?> <dd class="result-category"> <span class="small"> (<?php echo $this->escape($categories[0]); ?> ) </span> </dd> <?php } ?> <dd class="result-text"> <?php if (isset($this->highlight['description'])) { echo ElasticSearchHelper::truncateHighLight($this->highlight['description'], 200); } else { if (isset($this->highlight['description'])) { echo ElasticSearchHelper::truncateHighLight($this->highlight['description'], 500); } else { $text = SearchHelper::prepareSearchContent($this->data['description'], ""); echo JHtmlString::truncate($text, 500, true, false); } } ?> </dd> </div>