function checkOpenOffice() { $diagnose = SearchHelper::checkOpenOfficeAvailablity(); if (!is_null($diagnose)) { $this->addIssue('Open Office Server', $diagnose); } }
/** * Method to display a view. * * @param boolean If true, the view output will be cached * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. * @since 1.5 */ public function display($cachable = false, $urlparams = false) { require_once JPATH_COMPONENT . '/helpers/search.php'; // Load the submenu. SearchHelper::addSubmenu(JRequest::getCmd('view', 'searches')); parent::display(); }
public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * Method to display a view. * * @param boolean $cachable If true, the view output will be cached * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return SearchController This object to support chaining. * * @since 1.5 */ public function display($cachable = false, $urlparams = false) { JLoader::register('SearchHelper', JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php'); // Load the submenu. SearchHelper::addSubmenu($this->input->get('view', 'searches')); return parent::display(); }
/** * Check that open office is running * * @return boolean */ private function checkOO() { $available = SearchHelper::checkOpenOfficeAvailablity(); if (is_null($available)) { return true; } return false; }
/** * Setup the Toolbar. */ protected function _setToolbar() { $canDo = SearchHelper::getActions(); JToolBarHelper::title(JText::_('Search_Manager_Searches'), 'search.png'); JToolBarHelper::custom('searches.reset', 'refresh.png', 'refresh_f2.png', 'Reset', false); JToolBarHelper::divider(); if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_search'); } JToolBarHelper::divider(); JToolBarHelper::help('screen.stats.searches'); }
function render() { $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/search2/search_portlet"); $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1); $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if (!$iFolderId && !$iDocumentId) { return null; } $savedSearches = SearchHelper::getSavedSearches($_SESSION['userID']); $aTemplateData = array('context' => $this, 'folder_id' => $iFolderId, 'document_id' => $iDocumentId, 'savedSearches' => $savedSearches); return $oTemplate->render($aTemplateData); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { $canDo = SearchHelper::getActions(); JToolBarHelper::title(JText::_('COM_SEARCH_MANAGER_SEARCHES'), 'search.png'); if ($canDo->get('core.edit.state')) { JToolBarHelper::custom('searches.reset', 'refresh.png', 'refresh_f2.png', 'JSEARCH_RESET', false); } JToolBarHelper::divider(); if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_search'); } JToolBarHelper::divider(); JToolBarHelper::help('JHELP_COMPONENTS_SEARCH'); }
/** * 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; }
function getPollInfo($tIds) { $sql = 'SELECT * FROM ' . DB::table('forum_polloption') . ' WHERE tid IN (' . implode(',', $tIds) . ')'; $result = array(); $query = DB::query($sql); while ($row = DB::fetch($query)) { $result[$row['tid']][$row['polloptionid']] = SearchHelper::convertPoll($row); } return $result; }
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); }
/** * Search Quick2cart (Products). * The SQL must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav. * * @param string $text Target search string. * @param string $phrase Matching option (possible values: exact|any|all). Default is "any". * @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest". * @param mixed $areas An array if the search it to be restricted to areas or null to search all areas. * * @return array Search results. * * @since 1.6 */ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $tag = JFactory::getLanguage()->getTag(); require_once JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php'; $searchText = $text; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $sContent = $this->params->get('search_products', 1); $limit = $this->params->def('search_limit', 50); $nullDate = $db->getNullDate(); $date = JFactory::getDate(); $now = $date->toSql(); $text = trim($text); if ($text == '') { return array(); } switch ($phrase) { case 'exact': $text = $db->quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.name LIKE ' . $text; $wheres2[] = 'a.description LIKE ' . $text; $wheres2[] = 'a.metakey LIKE ' . $text; $wheres2[] = 'a.metadesc LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.name LIKE ' . $word; $wheres2[] = 'a.description LIKE ' . $word; $wheres2[] = 'a.metakey LIKE ' . $word; $wheres2[] = 'a.metadesc LIKE ' . $word; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.cdate ASC'; break; /*case 'popular': $order = 'a.hits DESC'; break;*/ /*case 'popular': $order = 'a.hits DESC'; break;*/ case 'alpha': $order = 'a.name ASC'; break; case 'category': $order = 'c.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.cdate DESC'; break; } $rows = array(); $query = $db->getQuery(true); // Search products. if ($sContent && $limit > 0) { $query->clear(); $query->select('a.item_id, a.name AS title, a.metadesc, a.metakey, a.cdate AS created')->select('a.description AS text')->select('c.title AS section')->from('#__kart_items AS a')->join('INNER', '#__categories AS c ON c.id=a.category')->where('(' . $where . ') AND a.state=1 AND c.published = 1')->group('a.item_id, a.name, a.metadesc, a.metakey, a.cdate, a.description, c.title, c.id')->order($order); $db->setQuery($query, 0, $limit); $list = $db->loadObjectList(); $limit -= count($list); if (isset($list)) { $comquick2cartHelper = new comquick2cartHelper(); $itemid = $comquick2cartHelper->getItemId('index.php?option=com_quick2cart&view=productpage&layout=default'); foreach ($list as $key => $item) { $link = 'index.php?option=com_quick2cart&view=productpage&layout=default&item_id=' . $item->item_id . '&Itemid=' . $itemid; $list[$key]->href = JRoute::_($link, false); } } $rows[] = $list; } $results = array(); if (count($rows)) { foreach ($rows as $row) { $new_row = array(); foreach ($row as $article) { $article->browsernav = ''; if (SearchHelper::checkNoHTML($article, $searchText, array('text', 'title', 'metadesc', 'metakey'))) { $new_row[] = $article; } } $results = array_merge($results, (array) $new_row); } } return $results; }
/** * Teams 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(if used) * @param mixed An array if the search it to be restricted to areas, null if search all */ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $tag = JFactory::getLanguage()->getTag(); require_once JPATH_SITE . '/components/com_knvbapi/helpers/route.php'; require_once JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php'; $search_text = $text; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $sTeam = 1; $sTeamArchived = 0; $limit = 50; $sTeam = $this->params->get('search_teams', 1); $sTeamArchived = $this->params->get('search_archived_teams', 0); $limit = $this->params->def('search_limit', 50); if ($this->params->get('itemid') != '') { $item_id_str = '&Itemid=' . (string) $this->params->get('itemid'); $keep_item_id = true; } else { $item_id_str = ''; $keep_item_id = false; } $null_date = $db->getNullDate(); $date = JFactory::getDate(); $now = $date->toSQL(); $text = JString::trim($text); if ($text == '') { return array(); } switch ($phrase) { case 'exact': $text = $db->quote('%' . $db->escape($text, true) . '%', false); $wheres_2 = array(); $wheres_2[] = $db->quoteName('a.name') . ' LIKE ' . $text; $wheres_2[] = $db->quoteName('a.description') . ' LIKE ' . $text; $wheres_2[] = $db->quoteName('a.metakey') . ' LIKE ' . $text; $wheres_2[] = $db->quoteName('a.metadesc') . ' LIKE ' . $text; $where = '(' . implode(') OR (', $wheres_2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->quote('%' . $db->escape($word, true) . '%', false); $wheres_2 = array(); $wheres_2[] = 'LOWER(' . $db->quoteName('a.name') . ') LIKE LOWER(' . $word . ')'; $wheres_2[] = 'LOWER(' . $db->quoteName('a.description') . ') LIKE LOWER(' . $word . ')'; $wheres_2[] = 'LOWER(' . $db->quoteName('a.metakey') . ') LIKE LOWER(' . $word . ')'; $wheres_2[] = 'LOWER(' . $db->quoteName('a.metadesc') . ') LIKE LOWER(' . $word . ')'; $wheres[] = implode(' OR ', $wheres_2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } $order = ''; switch ($ordering) { case 'oldest': $order = $db->quoteName('a.created') . ' ASC'; break; case 'popular': $order = $db->quoteName('a.hits') . ' DESC'; break; case 'alpha': $order = $db->quoteName('a.name') . ' ASC'; break; case 'newest': $order = $db->quoteName('a.created') . ' DESC'; break; default: $order = $db->quoteName('a.ordering') . ' DESC'; break; } $rows = array(); $query = $db->getQuery(true); $search_section = JText::_('PLG_SEARCH_TEAMS_TEAMS'); // search teams if ($sTeam and $limit > 0) { $query->clear(); //sqlsrv changes $slug_select = ' CASE WHEN '; $slug_select .= $query->charLength('a.alias', '!=', '0'); $slug_select .= ' THEN '; $a_id = $query->castAsChar('a.id'); $slug_select .= $query->concatenate(array($a_id, 'a.alias'), ':'); $slug_select .= ' ELSE '; $slug_select .= $a_id . ' END as slug, '; $query->select($db->quoteName('a.name') . ' AS title, ' . $db->quoteName('a.metadesc') . ', ' . $db->quoteName('a.metakey') . ', ' . $db->quoteName('a.created') . ' AS created, ' . $db->quoteName('a.description') . ' AS text, ' . $db->quoteName('a.language') . ' AS language, ' . $db->quote($search_section) . ' AS section, ' . $slug_select . '"2" AS browsernav'); $query->from($db->quoteName('#__knvbapi_teams') . ' AS a'); $query->where('(' . $where . ')' . 'AND ' . $db->quoteName('a.state') . ' = 1 ' . 'AND ' . $db->quoteName('a.access') . ' IN (' . $groups . ') ' . 'AND (' . $db->quoteName('a.publish_up') . ' = ' . $db->quote($null_date) . ' OR ' . $db->quoteName('a.publish_up') . ' <= ' . $db->quote($now) . ') ' . 'AND (' . $db->quoteName('a.publish_down') . ' = ' . $db->quote($null_date) . ' OR ' . $db->quoteName('a.publish_down') . ' >= ' . $db->quote($now) . ') '); // Filter by language if ($app->isSite() and JLanguageMultilang::isEnabled()) { $query->where($db->quoteName('a.language') . ' IN (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); $query->where($db->quoteName('c.language') . ' IN (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $query->group($db->quoteName('a.id') . ', ' . $db->quoteName('a.name')); $query->order($order); $db->setQuery($query, 0, $limit); $list = $db->loadObjectList(); $limit -= count($list); if (isset($list)) { foreach ($list as $key => $item) { $list[$key]->href = JRoute::_(KnvbapiHelperRoute::getTeamRoute($item->slug, $item->language, $this->layout, $keep_item_id)); //Add the selected item id to the link if there is one $list[$key]->href .= $item_id_str; } } $rows[] = $list; } // search archived teams if ($sTeamArchived and $limit > 0) { $query->clear(); //sqlsrv changes $slug_select = ' CASE WHEN '; $slug_select .= $query->charLength('a.alias', '!=', '0'); $slug_select .= ' THEN '; $a_id = $query->castAsChar('a.id'); $slug_select .= $query->concatenate(array($a_id, 'a.alias'), ':'); $slug_select .= ' ELSE '; $slug_select .= $a_id . ' END AS slug, '; $query->select($db->quoteName('a.name') . ' AS title, ' . $db->quoteName('a.metadesc') . ', ' . $db->quoteName('a.metakey') . ', ' . $db->quoteName('a.created') . ' AS created, ' . $db->quoteName('a.description') . ' AS text, ' . $db->quoteName('a.language') . ' AS language, ' . $db->quote($search_section) . ' AS section, ' . $slug_select . '"2" AS browsernav'); $query->from($db->quoteName('#__knvbapi_teams') . ' AS a'); $query->where('(' . $where . ') ' . 'AND ' . $db->quoteName('a.state') . ' = 2 ' . 'AND ' . $db->quoteName('a.access') . ' IN (' . $groups . ') ' . 'AND (' . $db->quoteName('a.publish_up') . ' = ' . $db->quote($null_date) . ' OR ' . $db->quoteName('a.publish_up') . ' <= ' . $db->quote($now) . ') ' . 'AND (' . $db->quoteName('a.publish_down') . ' = ' . $db->quote($null_date) . ' OR ' . $db->quoteName('a.publish_down') . ' >= ' . $db->quote($now) . ') '); // Filter by language if ($app->isSite() and JLanguageMultilang::isEnabled()) { $query->where($db->quoteName('a.language') . ' IN (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); $query->where($db->quoteName('c.language') . ' IN (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $query->order($order); $db->setQuery($query, 0, $limit); $list3 = $db->loadObjectList(); // find an itemid for archived to use if there isn't another one $item = $app->getMenu()->getItems('link', 'index.php?option=com_knvbapi&view=teamarchive', true); $item_id = isset($item) ? '&Itemid=' . $item->id : $item_id_str; if (isset($list3)) { foreach ($list3 as $key => $item) { $date = JFactory::getDate($item->created); $created_month = $date->format("n"); $created_year = $date->format("Y"); $list3[$key]->href = JRoute::_('index.php?option=com_knvbapi&view=teamarchive' . '&year=' . $created_year . '&month=' . $created_month . $item_id); } } $rows[] = $list3; } $results = array(); if (count($rows)) { foreach ($rows as $row) { $new_row = array(); foreach ($row as $team) { if (SearchHelper::checkNoHTML($team, $search_text, array('title', 'description', 'metadesc', 'metakey'))) { $new_row[] = $team; } } $results = array_merge($results, (array) $new_row); } } return $results; }
/** * 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; }
/** * Search content (articles). * The SQL must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav. * * @param string $text Target search string. * @param string $phrase Matching option (possible values: exact|any|all). Default is "any". * @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest". * @param mixed $areas An array if the search it to be restricted to areas or null to search all areas. * * @return array Search results. * * @since 1.6 */ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $tag = JFactory::getLanguage()->getTag(); require_once JPATH_SITE . '/components/com_content/helpers/route.php'; require_once JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php'; $searchText = $text; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $sContent = $this->params->get('search_content', 1); $sArchived = $this->params->get('search_archived', 1); $limit = $this->params->def('search_limit', 50); $nullDate = $db->getNullDate(); $date = JFactory::getDate(); $now = $date->toSql(); $text = trim($text); if ($text == '') { return array(); } switch ($phrase) { case 'exact': $text = $db->quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.title LIKE ' . $text; $wheres2[] = 'a.introtext LIKE ' . $text; $wheres2[] = 'a.fulltext LIKE ' . $text; $wheres2[] = 'a.metakey LIKE ' . $text; $wheres2[] = 'a.metadesc LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(a.title) LIKE LOWER(' . $word . ')'; $wheres2[] = 'LOWER(a.introtext) LIKE LOWER(' . $word . ')'; $wheres2[] = 'LOWER(a.fulltext) LIKE LOWER(' . $word . ')'; $wheres2[] = 'LOWER(a.metakey) LIKE LOWER(' . $word . ')'; $wheres2[] = 'LOWER(a.metadesc) LIKE LOWER(' . $word . ')'; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.created ASC'; break; case 'popular': $order = 'a.hits DESC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'category': $order = 'c.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.created DESC'; break; } $rows = array(); $query = $db->getQuery(true); // Search articles. if ($sContent && $limit > 0) { $query->clear(); // SQLSRV changes. $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias', '!=', '0'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id . ' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias', '!=', '0'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; $query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created, a.language, a.catid')->select($query->concatenate(array('a.introtext', 'a.fulltext')) . ' AS text')->select('c.title AS section, ' . $case_when . ',' . $case_when1 . ', ' . '\'2\' AS browsernav')->from('#__content AS a')->join('INNER', '#__categories AS c ON c.id=a.catid')->where('(' . $where . ') AND a.state=1 AND c.published = 1 AND a.access IN (' . $groups . ') ' . 'AND c.access IN (' . $groups . ') ' . 'AND (a.publish_up = ' . $db->quote($nullDate) . ' OR a.publish_up <= ' . $db->quote($now) . ') ' . 'AND (a.publish_down = ' . $db->quote($nullDate) . ' OR a.publish_down >= ' . $db->quote($now) . ')')->group('a.id, a.title, a.metadesc, a.metakey, a.created, a.introtext, a.fulltext, c.title, a.alias, c.alias, c.id')->order($order); // Filter by language. if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')')->where('c.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $db->setQuery($query, 0, $limit); $list = $db->loadObjectList(); $limit -= count($list); if (isset($list)) { foreach ($list as $key => $item) { $list[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language); } } $rows[] = $list; } // Search archived content. if ($sArchived && $limit > 0) { $query->clear(); // SQLSRV changes. $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias', '!=', '0'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id . ' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias', '!=', '0'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; $query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created, ' . $query->concatenate(array("a.introtext", "a.fulltext")) . ' AS text,' . $case_when . ',' . $case_when1 . ', ' . 'c.title AS section, \'2\' AS browsernav'); // .'CONCAT_WS("/", c.title) AS section, \'2\' AS browsernav' ); $query->from('#__content AS a')->join('INNER', '#__categories AS c ON c.id=a.catid AND c.access IN (' . $groups . ')')->where('(' . $where . ') AND a.state = 2 AND c.published = 1 AND a.access IN (' . $groups . ') AND c.access IN (' . $groups . ') ' . 'AND (a.publish_up = ' . $db->quote($nullDate) . ' OR a.publish_up <= ' . $db->quote($now) . ') ' . 'AND (a.publish_down = ' . $db->quote($nullDate) . ' OR a.publish_down >= ' . $db->quote($now) . ')')->order($order); // Filter by language. if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')')->where('c.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $db->setQuery($query, 0, $limit); $list3 = $db->loadObjectList(); // Find an itemid for archived to use if there isn't another one. $item = $app->getMenu()->getItems('link', 'index.php?option=com_content&view=archive', true); $itemid = isset($item->id) ? '&Itemid=' . $item->id : ''; if (isset($list3)) { foreach ($list3 as $key => $item) { $date = JFactory::getDate($item->created); $created_month = $date->format("n"); $created_year = $date->format("Y"); $list3[$key]->href = JRoute::_('index.php?option=com_content&view=archive&year=' . $created_year . '&month=' . $created_month . $itemid); } } $rows[] = $list3; } $results = array(); if (count($rows)) { foreach ($rows as $row) { $new_row = array(); foreach ($row as $article) { if (SearchHelper::checkNoHTML($article, $searchText, array('text', 'title', 'metadesc', 'metakey'))) { $new_row[] = $article; } } $results = array_merge($results, (array) $new_row); } } return $results; }
public function diagnose() { if (!$this->useOO) { return true; } if (false === $this->python) { return _kt('Cannot locate python'); } if (false === $this->documentConverter) { return _kt('Cannot locate DocumentConverter.py'); } return SearchHelper::checkOpenOfficeAvailablity(); }
foreach ($_extgroupids as $v) { if ($v) { $my_extgroupids[] = $v; } } $my_extgroupids_str = implode(',', $my_extgroupids); $params = array('sId' => $_G['setting']['my_siteid'], 'ts' => time(), 'cuId' => $_G['uid'], 'cuName' => $_G['username'], 'gId' => $_G['groupid'], 'agId' => $_G['adminid'], 'egIds' => $my_extgroupids_str, 'fmSign' => substr($my_forums['sign'], -4)); $groupIds = explode(',', $_G['groupid']); if ($_G['adminid']) { $groupIds[] = $_G['adminid']; } if ($my_extgroupids) { $groupIds = array_merge($groupIds, $my_extgroupids); } $groupIds = array_unique($groupIds); $userGroups = SearchHelper::getUserGroupPermissions($groupIds); foreach ($groupIds as $k => $v) { $value = substr($userGroups[$v]['sign'], -4); if ($value) { $params['ugSign' . $v] = $value; } } $params['sign'] = md5(implode('|', $params) . '|' . $_G['setting']['my_sitekey']); $extra = array('q', 'fId', 'author', 'scope', 'source', 'module', 'isAdv'); foreach ($extra as $v) { if ($_GET[$v]) { $params[$v] = $_GET[$v]; } } $params['charset'] = $_G['charset']; if ($_G['setting']['my_search_domain']) {
function onSearchGetForums($fIds = array()) { return SearchHelper::getForums($fIds); }
/** * Register the extractor types. * * @param boolean $clear. Optional. Defaults to false. */ public function registerTypes($clear = false) { if ($clear) { $this->clearExtractors(); } $dir = opendir(SearchHelper::correctPath($this->extractorPath)); while (($file = readdir($dir)) !== false) { if (substr($file, -17) == 'Extractor.inc.php') { require_once $this->extractorPath . '/' . $file; $class = substr($file, 0, -8); if (!class_exists($class)) { // if the class does not exist, we can't do anything. continue; } $extractor = new $class(); if ($extractor instanceof DocumentExtractor) { $extractor->registerMimeTypes(); } } } closedir($dir); }
function setcloudappstatus_search($appName, $status) { global $_G; $searchData = unserialize($_G['setting']['my_search_data']); if (!is_array($searchData)) { $searchData = array(); } $searchData['isnew'] = 0; $searchData = addslashes(serialize(dstripslashes($searchData))); $available = 0; if ($status == 'normal') { $available = 1; } $res = DB::insert('common_setting', array('skey' => 'my_search_data', 'svalue' => $searchData), false, true); if ($available) { require_once DISCUZ_ROOT . './api/manyou/Manyou.php'; SearchHelper::allowSearchForum(); } updatecloudpluginavailable('cloudsearch', $available); return true; }
function getReplyAndView($tids) { if (!$tids) { return array(); } $res = array(); $threads = SearchHelper::getThreads($tids); foreach ($threads as $thread) { $res[$thread['tId']] = array('tid' => $thread['tId'], 'replies' => $thread['replyNum'], 'views' => $thread['viewNum']); } return $res; }
/** * Load all fields into the registry * */ public function registerFields() { $this->fields = array(); $dir = opendir(SearchHelper::correctPath($this->path)); while (($file = readdir($dir)) !== false) { if (substr($file, -13) == 'Field.inc.php') { require_once $this->path . '/' . $file; $class = substr($file, 0, -8); if (!class_exists($class)) { continue; } $field = new $class(); if (is_null($field) || !$field instanceof FieldExpr) { continue; } $this->registerField($field); } } closedir($dir); $this->registerMetdataFields(); }
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); }
$sGiveOutput = isset($argv[1]) && $argv[1] == 'output' ? true : false; // Check indexed document count // If the number of indexed documents is greater than the set amount, restart open office // this clears open office's memory usage $resetPoint = 50; // todo: put in config $count = Indexer::getIndexedDocumentCount(); $restartOO = false; if ($count > $resetPoint) { $restartOO = true; // reset the count Indexer::updateIndexedDocumentCount(0); $default->log->debug('Check Open Office Task: Restarting open office.'); } // First we check the host:port to see if open office is running $sCheckOO = SearchHelper::checkOpenOfficeAvailablity(); if (empty($sCheckOO) && !$restartOO) { // If the check returns empty then it is available on that port so we exit if ($sGiveOutput) { echo 1; } exit; } // Open office appears not to be running or requires a restart if (OS_WINDOWS) { $OOService = 'ktopenoffice'; $default->log->debug('Check Open Office Task: ' . get_current_user()); if ($restartOO) { // If Open office needs to be restarted - stop it here $result_stop = win32_stop_service($OOService); // Wait for the service to stop fully before trying to restart it
/** * Prepares results from search for display * * @param string The source string * @param int Number of chars to trim * @param string The searchword to select around * @return string */ function prepareSearchContent($text, $length = 200, $searchword) { // strips tags won't remove the actual jscript $text = preg_replace("'<script[^>]*>.*?</script>'si", "", $text); $text = preg_replace('/{.+?}/', '', $text); //$text = preg_replace( '/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2', $text ); // replace line breaking tags with whitespace $text = preg_replace("'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", ' ', $text); return SearchHelper::_smartSubstr(strip_tags($text), $length, $searchword); }
/** * @version $Id: default.php 20899 2011-03-07 20:56:09Z ian $ * @package Joomla.Administrator * @subpackage com_search * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access. defined('_JEXEC') or die; // Include the component HTML helpers. JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); JHtml::_('behavior.tooltip'); JHTML::_('script', 'system/multiselect.js', false, true); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); $canDo = SearchHelper::getActions(); ?> <form action="<?php echo JRoute::_('index.php?option=com_search&view=searches'); ?> " method="post" name="adminForm" id="adminForm"> <fieldset id="filter-bar"> <div class="filter-search fltlft"> <label class="filter-search-lbl" for="filter_search"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?> </label> <input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?> " title="<?php
/** * Search content (articles). * The SQL must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav. * * @param string $text Target search string. * @param string $phrase Matching option (possible values: exact|any|all). Default is "any". * @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest". * @param mixed $areas An array if the search it to be restricted to areas or null to search all areas. * * @return array Search results. * * @since 1.6 */ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $menu = $app->getMenu(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $tag = JFactory::getLanguage()->getTag(); require_once JPATH_SITE . '/components/com_content/helpers/route.php'; require_once JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php'; $searchText = $text; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $limit = $this->params->def('search_limit', 50); $nullDate = $db->getNullDate(); $date = JFactory::getDate(); $now = $date->toSql(); $text = trim($text); if ($text == '') { return array(); } switch ($phrase) { case 'exact': $text = $db->quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.title LIKE ' . $text; $wheres2[] = 'a.text LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(a.title) LIKE LOWER(' . $word . ')'; $wheres2[] = 'LOWER(a.text) LIKE LOWER(' . $word . ')'; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.created_time ASC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'newest': default: $order = 'a.created_time DESC'; break; } $rows = array(); $query = $db->getQuery(true); // Search articles. if ($limit > 0) { $query->clear(); // SQLSRV changes. $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias', '!=', '0'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id . ' END as slug'; $query->select('a.id, a.title AS title, a.text AS text, a.og_description AS metadesc, a.og_title AS metakey, a.created_time AS created, a.language')->select($case_when . ',' . '\'2\' AS browsernav')->from('#__sppagebuilder AS a')->where('(' . $where . ') AND a.published = 1 AND a.access IN (' . $groups . ') ')->group('a.id, a.title, a.og_description, a.og_title, a.created_time, a.text, a.alias')->order($order); // Filter by language. if ($app->isSite() && JLanguageMultilang::isEnabled()) { $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $db->setQuery($query, 0, $limit); try { $list = $db->loadObjectList(); } catch (RuntimeException $e) { echo $e->getMessage(); $list = array(); JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error'); } $limit -= count($list); if (isset($list)) { foreach ($list as $key => $item) { // Generate nice links! Respecting menu items! $link = 'index.php?option=com_sppagebuilder&view=page&id=' . $item->id; $menuitem = $menu->getItems('link', $link, true); if (isset($menuitem) && isset($menuitem->id)) { $link .= '&Itemid=' . $menuitem->id; } $list[$key]->href = JRoute::_($link); } } $rows[] = $list; } $results = array(); /* * Postprocess result */ if (count($rows)) { foreach ($rows as $row) { $new_row = array(); foreach ($row as $article) { // Fetch content as array $textobj = json_decode($article->text); // Flatten deep array // this is some cool stuff from stackoverflow, thanks VolkerK http://stackoverflow.com/users/4833/volkerk $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($textobj)); $text = ''; foreach ($iterator as $key => $value) { if ($key == 'title' || $key == "text") { $text .= $value . ' '; } } $article->text = $text; if (SearchHelper::checkNoHtml($article, $searchText, array('text', 'title', 'metadesc', 'metakey'))) { $new_row[] = $article; } } $results = array_merge($results, (array) $new_row); } } return $results; }
public function actionLoadAjax() { $keyword = trim(yii::app()->request->getParam('q', '')); $search_type = $type = trim(yii::app()->request->getParam('type', 'song')); $page = intval(yii::app()->request->getParam('page', 1)); $is_search = Yii::app()->request->getParam('is_search', 1); $paging = array('page' => $page, 'recordsPerPage' => !$search_type ? Yii::app()->params['numberPerPage'] : Yii::app()->params['pageSize']); switch ($search_type) { case 'song': $response = SearchHelper::getInstance()->search($keyword, 'song', $paging['recordsPerPage'], $page - 1); $results = $this->copyAndCast($response->docs, array('name' => 'name', 'artist_name' => 'artist_name')); if ($response->numFound > 0) { $countSong = $response->numFound; $pages = new CPagination($countSong); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $topItems = array(); $topItemPages = new CPagination(0); $results = $this->getStatistic($results, $type); } else { $pages = new CPagination(0); $pageSize = Yii::app()->params['numberPerPage']; $topItemPages = new CPagination($pageSize); $topItemPages->setPageSize($pageSize); $currentPage = $topItemPages->getCurrentPage(); $topItems = null; // WapSongModel::model()->getTopSongsWeek($currentPage * $pageSize, $pageSize);;//WapSongModel::getListHot(1,$pageSize,'filter_sync_status'); } $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages); break; case 'clip': $response = SearchHelper::getInstance()->search($keyword, 'video', $paging['recordsPerPage'], $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); if ($response->numFound > 0) { $countClip = $response->numFound; $pages = new CPagination($countClip); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $topItems = array(); $topItemPages = new CPagination(0); $results = $this->getStatistic($results, $type); } else { $pages = new CPagination(0); $pageSize = Yii::app()->params['numberPerPage']; $topItemPages = new CPagination($pageSize); $currentPage = $topItemPages->getCurrentPage(); $topItemPages->setPageSize($pageSize); $topItems = null; //WapVideoModel::model()->getTopVideosWeek($currentPage * $pageSize, $pageSize);//WapVideoModel::getListHot(1,$pageSize,'filter_sync_status'); } $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages); break; case 'album': $response = SearchHelper::getInstance()->search($keyword, 'album', $paging['recordsPerPage'], $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); if ($response->numFound > 0) { $countAlbum = $response->numFound; $pages = new CPagination($countAlbum); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $topItems = array(); $topItemPages = new CPagination(0); $results = $this->getStatistic($results, $type); } else { $pages = new CPagination(0); $pageSize = Yii::app()->params['numberPerPage']; $topItemPages = new CPagination($pageSize); $topItemPages->setPageSize($pageSize); $currentPage = $topItemPages->getCurrentPage(); $topItems = null; //WapAlbumModel::model()->getTopAlbumsWeek($currentPage * $pageSize, $pageSize);//WapAlbumModel::getListHot(1,$pageSize); } $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages); break; case 'artist': $response = SearchHelper::getInstance()->search($keyword, 'artist', $paging['recordsPerPage'], $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); if ($response->numFound > 0) { $countArtist = $response->numFound; $pages = new CPagination($countArtist); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $topItems = array(); $topItemPages = new CPagination(0); $results = $this->getStatistic($results, $type, 'song_count'); } else { $pages = new CPagination(0); $pageSize = Yii::app()->params['numberPerPage']; $topItemPages = new CPagination($pageSize); $currentPage = $topItemPages->getCurrentPage(); $topItemPages->setPageSize($pageSize); $topItems = null; //WapArtistModel::model()->getTopArtists($currentPage * $pageSize, $pageSize); } $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages); break; case 'videoplaylist': $response = SearchHelper::getInstance()->search($keyword, 'videoplaylist', $paging['recordsPerPage'], $page - 1); $results = $this->copyAndCast($response->docs, array('artist' => 'artist_name')); if ($response->numFound > 0) { $countArtist = $response->numFound; $pages = new CPagination($countArtist); $pageSize = Yii::app()->params['pageSize']; $pages->params = array('q' => $keyword, 'type' => $type); $pages->setPageSize($pageSize); $topItems = array(); $topItemPages = new CPagination(0); $results = $this->getStatistic($results, $type); } else { $pages = new CPagination(0); $pageSize = Yii::app()->params['numberPerPage']; $topItemPages = new CPagination($pageSize); $currentPage = $topItemPages->getCurrentPage(); $topItemPages->setPageSize($pageSize); $topItems = null; //WapArtistModel::model()->getTopArtists($currentPage * $pageSize, $pageSize); } $total_results[$type] = array('numFound' => $response->numFound, 'results' => $results, 'topItems' => $topItems, 'pages' => $pages, 'topItemPages' => $topItemPages); break; } $this->layout = false; $this->render("_ajaxList", compact('total_results', 'search_type')); }
function render() { global $default; $oConfig = KTConfig::getSingleton(); if (empty($this->contents)) { $this->contents = ""; } if (is_string($this->contents) && trim($this->contents) === "") { $this->addError(_kt("This page did not produce any content")); $this->contents = ""; } if (!is_string($this->contents)) { $this->contents = $this->contents->render(); } // if we have no portlets, make the ui a tad nicer. if (empty($this->portlets)) { $this->show_portlets = false; } if (empty($this->title)) { if (!empty($this->breadcrumbDetails)) { $this->title = $this->breadcrumbDetails; } else { if (!empty($this->breadcrumbs)) { $this->title = array_slice($this->breadcrumbs, -1); $this->title = $this->title[0]['label']; } else { if (!empty($this->breadcrumbSection)) { $this->title = $this->breadcrumbSection['label']; } else { $this->title = $this->componentLabel; } } } } $this->userMenu = array(); $sBaseUrl = KTUtil::kt_url(); if (!(PEAR::isError($this->user) || is_null($this->user) || $this->user->isAnonymous())) { if ($oConfig->get("user_prefs/restrictPreferences", false) && !Permission::userIsSystemAdministrator($this->user->getId())) { $this->userMenu['logout'] = array('label' => _kt('Logout'), 'url' => $sBaseUrl . '/presentation/logout.php'); } else { if ($default->enableESignatures) { $sUrl = KTPluginUtil::getPluginPath('electronic.signatures.plugin', true); $heading = _kt('You are attempting to modify Preferences'); $this->userMenu['preferences']['url'] = '#'; $this->userMenu['preferences']['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading}', 'dms.administration.accessing_preferences', 'system', '{$sBaseUrl}/preferences.php', 'redirect');"; } else { $this->userMenu['preferences']['url'] = $sBaseUrl . '/preferences.php'; } // $this->userMenu['preferences'] = array('label' => _kt('Preferences'), 'url' => $sBaseUrl.'/preferences.php'); $this->userMenu['preferences']['label'] = _kt('Preferences'); $this->userMenu['aboutkt'] = array('label' => _kt('About'), 'url' => $sBaseUrl . '/about.php'); $this->userMenu['logout'] = array('label' => _kt('Logout'), 'url' => $sBaseUrl . '/presentation/logout.php'); } } else { $this->userMenu['login'] = array('label' => _kt('Login'), 'url' => $sBaseUrl . '/login.php'); } // FIXME we need a more complete solution to navigation restriction if (!is_null($this->menu['administration']) && !is_null($this->user)) { if (!Permission::userIsSystemAdministrator($this->user->getId())) { unset($this->menu['administration']); } } $sContentType = 'Content-type: ' . $this->contentType; if (!empty($this->charset)) { $sContentType .= '; charset=' . $this->charset; } header($sContentType); $savedSearches = SearchHelper::getSavedSearches($_SESSION['userID']); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate($this->template); $aTemplateData = array("page" => $this, "systemversion" => $default->systemVersion, "versionname" => $default->versionName, 'smallVersion' => substr($default->versionName, -17), 'savedSearches' => $savedSearches); if ($oConfig->get("ui/automaticRefresh", false)) { $aTemplateData['refreshTimeout'] = (int) $oConfig->get("session/sessionTimeout") + 3; } // unlike the rest of KT, we use echo here. echo $oTemplate->render($aTemplateData); }