/** * Creates a list of maps. * * @return array An array containing the maps that can be selected. * * @since 2.5 */ public static function mapslist() { $lang = JFactory::getLanguage(); // Load the finder types. $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('title AS text, id AS value'); $query->from($db->quoteName('#__finder_taxonomy')); $query->where($db->quoteName('parent_id') . ' = 1'); $query->order('ordering, title ASC'); $db->setQuery($query); try { $rows = $db->loadObjectList(); } catch (RuntimeException $e) { return; } // Compile the options. $options = array(); $options[] = JHtml::_('select.option', '1', JText::_('COM_FINDER_MAPS_BRANCHES')); foreach ($rows as $row) { $key = $lang->hasKey(FinderHelperLanguage::branchPlural($row->text)) ? FinderHelperLanguage::branchPlural($row->text) : $row->text; $string = JText::sprintf('COM_FINDER_ITEM_X_ONLY', JText::_($key)); $options[] = JHtml::_('select.option', $row->value, $string); } return $options; }
/** * Method to display the view. * * @param string $tpl A template file to load. [optional] * * @return mixed A string if successful, otherwise a JError object. * * @since 2.5 */ public function display($tpl = null) { // Load plug-in language files. FinderHelperLanguage::loadPluginLanguage(); $this->items = $this->get('Items'); $this->total = $this->get('Total'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->pluginState = $this->get('pluginState'); $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); FinderHelper::addSubmenu('index'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } if (!$this->pluginState['plg_content_finder']->enabled) { JFactory::getApplication()->enqueueMessage(JText::_('COM_FINDER_INDEX_PLUGIN_CONTENT_NOT_ENABLED'), 'warning'); } elseif ($this->get('TotalIndexed') === 0) { JFactory::getApplication()->enqueueMessage(JText::_('COM_FINDER_INDEX_NO_DATA') . ' ' . JText::_('COM_FINDER_INDEX_TIP'), 'notice'); } JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); // Configure the toolbar. $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
/** * Method to get the field options. * * @return array The field option objects. * * @since 3.6.0 */ public function getOptions() { $lang = JFactory::getLanguage(); $options = array(); $db = JFactory::getDbo(); $query = $db->getQuery(true)->select($db->quoteName('id', 'value'))->select($db->quoteName('title', 'text'))->from($db->quoteName('#__finder_types')); // Get the options. $db->setQuery($query); try { $contentTypes = $db->loadObjectList(); } catch (RuntimeException $e) { JError::raiseWarning(500, $db->getMessage()); } // Translate. foreach ($contentTypes as $contentType) { $key = FinderHelperLanguage::branchSingular($contentType->text); $contentType->translatedText = $lang->hasKey($key) ? JText::_($key) : $contentType->text; } // Order by title. $contentTypes = ArrayHelper::sortObjects($contentTypes, 'translatedText', 1, true, true); // Convert the values to options. foreach ($contentTypes as $contentType) { $options[] = JHtml::_('select.option', $contentType->value, $contentType->translatedText); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Creates a list of maps. * * @return array An array containing the maps that can be selected. * * @since 2.5 */ public static function mapslist() { $lang = JFactory::getLanguage(); // Load the finder types. $db = JFactory::getDbo(); $query = $db->getQuery(true)->select($db->quoteName('title', 'text'))->select($db->quoteName('id', 'value'))->from($db->quoteName('#__finder_taxonomy'))->where($db->quoteName('parent_id') . ' = 1'); $db->setQuery($query); try { $branches = $db->loadObjectList(); } catch (RuntimeException $e) { JError::raiseWarning(500, $db->getMessage()); } // Translate. foreach ($branches as $branch) { $key = FinderHelperLanguage::branchPlural($branch->text); $branch->translatedText = $lang->hasKey($key) ? JText::_($key) : $branch->text; } // Order by title. $branches = ArrayHelper::sortObjects($branches, 'translatedText', 1, true, true); // Compile the options. $options = array(); $options[] = JHtml::_('select.option', '', JText::_('COM_FINDER_MAPS_SELECT_BRANCH')); // Convert the values to options. foreach ($branches as $branch) { $options[] = JHtml::_('select.option', $branch->value, $branch->translatedText); } return $options; }
/** * Method to get the explained (human-readable) search query. * * @param FinderIndexerQuery $query A FinderIndexerQuery object to explain. * * @return mixed String if there is data to explain, null otherwise. * * @since 2.5 */ public static function explained(FinderIndexerQuery $query) { $parts = array(); // Process the required tokens. foreach ($query->included as $token) { if ($token->required && (!isset($token->derived) || $token->derived == false)) { $parts[] = '<span class="query-required">' . JText::sprintf('COM_FINDER_QUERY_TOKEN_REQUIRED', $token->term) . '</span>'; } } // Process the optional tokens. foreach ($query->included as $token) { if (!$token->required && (!isset($token->derived) || $token->derived == false)) { $parts[] = '<span class="query-optional">' . JText::sprintf('COM_FINDER_QUERY_TOKEN_OPTIONAL', $token->term) . '</span>'; } } // Process the excluded tokens. foreach ($query->excluded as $token) { if (!isset($token->derived) || $token->derived == false) { $parts[] = '<span class="query-excluded">' . JText::sprintf('COM_FINDER_QUERY_TOKEN_EXCLUDED', $token->term) . '</span>'; } } // Process the start date. if ($query->date1) { $date = JFactory::getDate($query->date1)->format(JText::_('DATE_FORMAT_LC')); $parts[] = '<span class="query-start-date">' . JText::sprintf('COM_FINDER_QUERY_START_DATE', $query->when1, $date) . '</span>'; } // Process the end date. if ($query->date2) { $date = JFactory::getDate($query->date2)->format(JText::_('DATE_FORMAT_LC')); $parts[] = '<span class="query-end-date">' . JText::sprintf('COM_FINDER_QUERY_END_DATE', $query->when2, $date) . '</span>'; } // Process the taxonomy filters. if (!empty($query->filters)) { // Get the filters in the request. $t = JFactory::getApplication()->input->request->get('t', array(), 'array'); // Process the taxonomy branches. foreach ($query->filters as $branch => $nodes) { // Process the taxonomy nodes. $lang = JFactory::getLanguage(); foreach ($nodes as $title => $id) { // Translate the title for Types $key = FinderHelperLanguage::branchPlural($title); if ($lang->hasKey($key)) { $title = JText::_($key); } // Don't include the node if it is not in the request. if (!in_array($id, $t)) { continue; } // Add the node to the explanation. $bv = JString::strtolower($branch); $nv = JString::strtolower($title); $parts[] = '<span class="query-taxonomy">' . JText::sprintf('COM_FINDER_QUERY_TAXONOMY_NODE', $title, JText::_(FinderHelperLanguage::branchSingular($branch))) . '</span>'; } } } // Build the interpreted query. return count($parts) ? JText::sprintf('COM_FINDER_QUERY_TOKEN_INTERPRETED', implode(JText::_('COM_FINDER_QUERY_TOKEN_GLUE'), $parts)) : null; }
/** * Method to display a view. * * @param boolean $cachable If true, the view output will be cached. [optional] * @param array $urlparams An array of safe url parameters and their variable types, * for valid values see {@link JFilterInput::clean()}. [optional] * * @return JControllerLegacy This object is to support chaining. * * @since 2.5 */ public function display($cachable = false, $urlparams = array()) { $input = JFactory::getApplication()->input; $cachable = true; // Load plug-in language files. FinderHelperLanguage::loadPluginLanguage(); // Set the default view name and format from the Request. $viewName = $input->get('view', 'search', 'word'); $input->set('view', $viewName); // Don't cache view for search queries if ($input->get('q', null, 'string') || $input->get('f', null, 'int') || $input->get('t', null, 'array')) { $cachable = false; } $safeurlparams = array('f' => 'INT', 'lang' => 'CMD'); return parent::display($cachable, $safeurlparams); }
/** * Method to get the list of content map options grouped by first level. * * @return array The field option objects as a nested array in groups. * * @since 3.6.0 */ protected function getGroups() { $groups = array(); // Get the database object and a new query object. $db = JFactory::getDbo(); // Levels subquery. $levelQuery = $db->getQuery(true); $levelQuery->select('title AS branch_title, 1 as level')->select($db->quoteName('id'))->from($db->quoteName('#__finder_taxonomy'))->where($db->quoteName('parent_id') . ' = 1'); $levelQuery2 = $db->getQuery(true); $levelQuery2->select('b.title AS branch_title, 2 as level')->select($db->quoteName('a.id'))->from($db->quoteName('#__finder_taxonomy', 'a'))->join('LEFT', $db->quoteName('#__finder_taxonomy', 'b') . ' ON ' . $db->qn('a.parent_id') . ' = ' . $db->qn('b.id'))->where($db->quoteName('a.parent_id') . ' NOT IN (0, 1)'); $levelQuery->union($levelQuery2); // Main query. $query = $db->getQuery(true)->select($db->quoteName('a.title', 'text'))->select($db->quoteName('a.id', 'value'))->select($db->quoteName('d.level'))->from($db->quoteName('#__finder_taxonomy', 'a'))->join('LEFT', '(' . $levelQuery . ') AS d ON ' . $db->qn('d.id') . ' = ' . $db->qn('a.id'))->where($db->quoteName('a.parent_id') . ' <> 0')->order('d.branch_title ASC, d.level ASC, a.title ASC'); $db->setQuery($query); try { $contentMap = $db->loadObjectList(); } catch (RuntimeException $e) { return; } // Build the grouped list array. if ($contentMap) { $lang = JFactory::getLanguage(); foreach ($contentMap as $branch) { if ((int) $branch->level === 1) { $name = $branch->text; } else { $levelPrefix = str_repeat('- ', max(0, $branch->level - 1)); if (trim($name, '**') == 'Language') { $text = FinderHelperLanguage::branchLanguageTitle($branch->text); } else { $key = FinderHelperLanguage::branchSingular($branch->text); $text = $lang->hasKey($key) ? JText::_($key) : $branch->text; } // Initialize the group if necessary. if (!isset($groups[$name])) { $groups[$name] = array(); } $groups[$name][] = JHtml::_('select.option', $branch->value, $levelPrefix . $text); } } } // Merge any additional groups in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }
/** * Method to display the view. * * @param string $tpl A template file to load. [optional] * * @return mixed A string if successful, otherwise a JError object. * * @since 2.5 */ public function display($tpl = null) { // Load plug-in language files. FinderHelperLanguage::loadPluginLanguage(); // Load the view data. $this->items = $this->get('Items'); $this->total = $this->get('Total'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // Prepare the view. $this->addToolbar(); JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); parent::display($tpl); }
/** * Method to display the view. * * @param string $tpl A template file to load. [optional] * * @return mixed A string if successful, otherwise a JError object. * * @since 2.5 */ public function display($tpl = null) { // Load plug-in language files. FinderHelperLanguage::loadPluginLanguage(); $this->items = $this->get('Items'); $this->total = $this->get('Total'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->pluginState = $this->get('pluginState'); $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); FinderHelper::addSubmenu('index'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); // Configure the toolbar. $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
// Include the helper. require_once __DIR__ . '/helper.php'; if (!defined('FINDER_PATH_INDEXER')) { define('FINDER_PATH_INDEXER', JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer'); } JLoader::register('FinderIndexerQuery', FINDER_PATH_INDEXER . '/query.php'); // Check for OpenSearch if ($params->get('opensearch', 1)) { /* This code intentionally commented $doc = JFactory::getDocument(); $app = JFactory::getApplication(); $ostitle = $params->get('opensearch_title', JText::_('MOD_FINDER_SEARCHBUTTON_TEXT') . ' ' . $app->getCfg('sitename')); $doc->addHeadLink( JURI::getInstance()->toString(array('scheme', 'host', 'port')) . JRoute::_('&option=com_finder&format=opensearch'), 'search', 'rel', array('title' => $ostitle, 'type' => 'application/opensearchdescription+xml') ); */ } // Initialize module parameters. $params->def('field_size', 20); // Get the route. $route = FinderHelperRoute::getSearchRoute($params->get('searchfilter', null)); // Load component language file. FinderHelperLanguage::loadComponentLanguage(); // Load plug-in language files. FinderHelperLanguage::loadPluginLanguage(); // Get Smart Search query object. $query = modFinderHelper::getQuery($params); require JModuleHelper::getLayoutPath('mod_finder', $params->get('layout', 'default'));
?> <?php foreach ($this->items as $i => $item) { ?> <tr class="row<?php echo $i % 2; ?> "> <th class="center"> <?php echo JHtml::_('grid.id', $i, $item->id); ?> </th> <td> <?php $key = FinderHelperLanguage::branchSingular($item->title); $title = $lang->hasKey($key) ? JText::_($key) : $item->title; ?> <?php if ($this->state->get('filter.branch') == 1 && $item->num_children) { ?> <a href="#" onclick="document.id('filter_branch').value='<?php echo (int) $item->id; ?> ';document.adminForm.submit();" title="<?php echo JText::_('COM_FINDER_MAPS_BRANCH_LINK'); ?> "> <?php echo $this->escape($title); ?>
/** * Method to process the query input string and extract required, optional, * and excluded tokens; taxonomy filters; and date filters. * * @param string $input The query input string. * @param string $lang The query input language. * @param string $mode The query matching mode. * * @return boolean True on success. * * @since 2.5 * @throws Exception on database error. */ protected function processString($input, $lang, $mode) { // Clean up the input string. $input = html_entity_decode($input, ENT_QUOTES, 'UTF-8'); $input = JString::strtolower($input); $input = preg_replace('#\\s+#mi', ' ', $input); $input = JString::trim($input); $debug = JFactory::getConfig()->get('debug_lang'); /* * First, we need to handle string based modifiers. String based * modifiers could potentially include things like "category:blah" or * "before:2009-10-21" or "type:article", etc. */ $patterns = array('before' => JText::_('COM_FINDER_FILTER_WHEN_BEFORE'), 'after' => JText::_('COM_FINDER_FILTER_WHEN_AFTER')); // Add the taxonomy branch titles to the possible patterns. foreach (FinderIndexerTaxonomy::getBranchTitles() as $branch) { // Add the pattern. $patterns[$branch] = JString::strtolower(JText::_(FinderHelperLanguage::branchSingular($branch))); } // Container for search terms and phrases. $terms = array(); $phrases = array(); // Cleared filter branches. $cleared = array(); /* * Compile the suffix pattern. This is used to match the values of the * filter input string. Single words can be input directly, multi-word * values have to be wrapped in double quotes. */ $quotes = html_entity_decode('‘’'', ENT_QUOTES, 'UTF-8'); $suffix = '(([\\w\\d' . $quotes . '-]+)|\\"([\\w\\d\\s' . $quotes . '-]+)\\")'; /* * Iterate through the possible filter patterns and search for matches. * We need to match the key, colon, and a value pattern for the match * to be valid. */ foreach ($patterns as $modifier => $pattern) { $matches = array(); if ($debug) { $pattern = substr($pattern, 2, -2); } // Check if the filter pattern is in the input string. if (preg_match('#' . $pattern . '\\s*:\\s*' . $suffix . '#mi', $input, $matches)) { // Get the value given to the modifier. $value = isset($matches[3]) ? $matches[3] : $matches[1]; // Now we have to handle the filter string. switch ($modifier) { // Handle a before and after date filters. case 'before': case 'after': // Get the time offset. $offset = JFactory::getApplication()->get('offset'); // Array of allowed when values. $whens = array('before', 'after', 'exact'); // The value of 'today' is a special case that we need to handle. if ($value === JString::strtolower(JText::_('COM_FINDER_QUERY_FILTER_TODAY'))) { $today = JFactory::getDate('now', $offset); $value = $today->format('%Y-%m-%d'); } // Try to parse the date string. $date = JFactory::getDate($value, $offset); // Check if the date was parsed successfully. if ($date->toUnix() !== null) { // Set the date filter. $this->date1 = $date->toSQL(); $this->when1 = in_array($modifier, $whens) ? $modifier : 'before'; } break; // Handle a taxonomy branch filter. // Handle a taxonomy branch filter. default: // Try to find the node id. $return = FinderIndexerTaxonomy::getNodeByTitle($modifier, $value); // Check if the node id was found. if ($return) { // Check if the branch has been cleared. if (!in_array($modifier, $cleared)) { // Clear the branch. $this->filters[$modifier] = array(); // Add the branch to the cleared list. $cleared[] = $modifier; } // Add the filter to the list. $this->filters[$modifier][$return->title] = (int) $return->id; } break; } // Clean up the input string again. $input = str_replace($matches[0], '', $input); $input = preg_replace('#\\s+#mi', ' ', $input); $input = JString::trim($input); } } /* * Extract the tokens enclosed in double quotes so that we can handle * them as phrases. */ if (JString::strpos($input, '"') !== false) { $matches = array(); // Extract the tokens enclosed in double quotes. if (preg_match_all('#\\"([^"]+)\\"#mi', $input, $matches)) { /* * One or more phrases were found so we need to iterate through * them, tokenize them as phrases, and remove them from the raw * input string before we move on to the next processing step. */ foreach ($matches[1] as $key => $match) { // Find the complete phrase in the input string. $pos = JString::strpos($input, $matches[0][$key]); $len = JString::strlen($matches[0][$key]); // Add any terms that are before this phrase to the stack. if (JString::trim(JString::substr($input, 0, $pos))) { $terms = array_merge($terms, explode(' ', JString::trim(JString::substr($input, 0, $pos)))); } // Strip out everything up to and including the phrase. $input = JString::substr($input, $pos + $len); // Clean up the input string again. $input = preg_replace('#\\s+#mi', ' ', $input); $input = JString::trim($input); // Get the number of words in the phrase. $parts = explode(' ', $match); // Check if the phrase is longer than three words. if (count($parts) > 3) { /* * If the phrase is longer than three words, we need to * break it down into smaller chunks of phrases that * are less than or equal to three words. We overlap * the chunks so that we can ensure that a match is * found for the complete phrase and not just portions * of it. */ for ($i = 0, $c = count($parts); $i < $c; $i += 2) { // Set up the chunk. $chunk = array(); // The chunk has to be assembled based on how many // pieces are available to use. switch ($c - $i) { /* * If only one word is left, we can break from * the switch and loop because the last word * was already used at the end of the last * chunk. */ case 1: break 2; // If there words are left, we use them both as // the last chunk of the phrase and we're done. // If there words are left, we use them both as // the last chunk of the phrase and we're done. case 2: $chunk[] = $parts[$i]; $chunk[] = $parts[$i + 1]; break; // If there are three or more words left, we // build a three word chunk and continue on. // If there are three or more words left, we // build a three word chunk and continue on. default: $chunk[] = $parts[$i]; $chunk[] = $parts[$i + 1]; $chunk[] = $parts[$i + 2]; break; } // If the chunk is not empty, add it as a phrase. if (count($chunk)) { $phrases[] = implode(' ', $chunk); $terms[] = implode(' ', $chunk); } } } else { // The phrase is <= 3 words so we can use it as is. $phrases[] = $match; $terms[] = $match; } } } } // Add the remaining terms if present. if (!empty($input)) { $terms = array_merge($terms, explode(' ', $input)); } // An array of our boolean operators. $operator => $translation $operators = array('AND' => JString::strtolower(JText::_('COM_FINDER_QUERY_OPERATOR_AND')), 'OR' => JString::strtolower(JText::_('COM_FINDER_QUERY_OPERATOR_OR')), 'NOT' => JString::strtolower(JText::_('COM_FINDER_QUERY_OPERATOR_NOT'))); // If language debugging is enabled you need to ignore the debug strings in matching. if (JDEBUG) { $debugStrings = array('**', '??'); $operators = str_replace($debugStrings, '', $operators); } /* * Iterate through the terms and perform any sorting that needs to be * done based on boolean search operators. Terms that are before an * and/or/not modifier have to be handled in relation to their operator. */ for ($i = 0, $c = count($terms); $i < $c; $i++) { // Check if the term is followed by an operator that we understand. if (isset($terms[$i + 1]) && in_array($terms[$i + 1], $operators)) { // Get the operator mode. $op = array_search($terms[$i + 1], $operators); // Handle the AND operator. if ($op === 'AND' && isset($terms[$i + 2])) { // Tokenize the current term. $token = FinderIndexerHelper::tokenize($terms[$i], $lang, true); $token = $this->getTokenData($token); // Set the required flag. $token->required = true; // Add the current token to the stack. $this->included[] = $token; $this->highlight = array_merge($this->highlight, array_keys($token->matches)); // Skip the next token (the mode operator). $this->operators[] = $terms[$i + 1]; // Tokenize the term after the next term (current plus two). $other = FinderIndexerHelper::tokenize($terms[$i + 2], $lang, true); $other = $this->getTokenData($other); // Set the required flag. $other->required = true; // Add the token after the next token to the stack. $this->included[] = $other; $this->highlight = array_merge($this->highlight, array_keys($other->matches)); // Remove the processed phrases if possible. if (($pk = array_search($terms[$i], $phrases)) !== false) { unset($phrases[$pk]); } if (($pk = array_search($terms[$i + 2], $phrases)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. unset($terms[$i]); unset($terms[$i + 1]); unset($terms[$i + 2]); // Adjust the loop. $i += 2; continue; } elseif ($op === 'OR' && isset($terms[$i + 2])) { // Tokenize the current term. $token = FinderIndexerHelper::tokenize($terms[$i], $lang, true); $token = $this->getTokenData($token); // Set the required flag. $token->required = false; // Add the current token to the stack. if (count($token->matches)) { $this->included[] = $token; $this->highlight = array_merge($this->highlight, array_keys($token->matches)); } else { $this->ignored[] = $token; } // Skip the next token (the mode operator). $this->operators[] = $terms[$i + 1]; // Tokenize the term after the next term (current plus two). $other = FinderIndexerHelper::tokenize($terms[$i + 2], $lang, true); $other = $this->getTokenData($other); // Set the required flag. $other->required = false; // Add the token after the next token to the stack. if (count($other->matches)) { $this->included[] = $other; $this->highlight = array_merge($this->highlight, array_keys($other->matches)); } else { $this->ignored[] = $other; } // Remove the processed phrases if possible. if (($pk = array_search($terms[$i], $phrases)) !== false) { unset($phrases[$pk]); } if (($pk = array_search($terms[$i + 2], $phrases)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. unset($terms[$i]); unset($terms[$i + 1]); unset($terms[$i + 2]); // Adjust the loop. $i += 2; continue; } } elseif (isset($terms[$i + 1]) && array_search($terms[$i], $operators) === 'OR') { // Skip the next token (the mode operator). $this->operators[] = $terms[$i]; // Tokenize the next term (current plus one). $other = FinderIndexerHelper::tokenize($terms[$i + 1], $lang, true); $other = $this->getTokenData($other); // Set the required flag. $other->required = false; // Add the token after the next token to the stack. if (count($other->matches)) { $this->included[] = $other; $this->highlight = array_merge($this->highlight, array_keys($other->matches)); } else { $this->ignored[] = $other; } // Remove the processed phrase if possible. if (($pk = array_search($terms[$i + 1], $phrases)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. unset($terms[$i]); unset($terms[$i + 1]); // Adjust the loop. $i += 1; continue; } elseif (isset($terms[$i + 1]) && array_search($terms[$i], $operators) === 'NOT') { // Skip the next token (the mode operator). $this->operators[] = $terms[$i]; // Tokenize the next term (current plus one). $other = FinderIndexerHelper::tokenize($terms[$i + 1], $lang, true); $other = $this->getTokenData($other); // Set the required flag. $other->required = false; // Add the next token to the stack. if (count($other->matches)) { $this->excluded[] = $other; } else { $this->ignored[] = $other; } // Remove the processed phrase if possible. if (($pk = array_search($terms[$i + 1], $phrases)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. unset($terms[$i]); unset($terms[$i + 1]); // Adjust the loop. $i += 1; continue; } } /* * Iterate through any search phrases and tokenize them. We handle * phrases as autonomous units and do not break them down into two and * three word combinations. */ for ($i = 0, $c = count($phrases); $i < $c; $i++) { // Tokenize the phrase. $token = FinderIndexerHelper::tokenize($phrases[$i], $lang, true); $token = $this->getTokenData($token); // Set the required flag. $token->required = true; // Add the current token to the stack. $this->included[] = $token; $this->highlight = array_merge($this->highlight, array_keys($token->matches)); // Remove the processed term if possible. if (($pk = array_search($phrases[$i], $terms)) !== false) { unset($terms[$pk]); } // Remove the processed phrase. unset($phrases[$i]); } /* * Handle any remaining tokens using the standard processing mechanism. */ if (!empty($terms)) { // Tokenize the terms. $terms = implode(' ', $terms); $tokens = FinderIndexerHelper::tokenize($terms, $lang, false); // Make sure we are working with an array. $tokens = is_array($tokens) ? $tokens : array($tokens); // Get the token data and required state for all the tokens. foreach ($tokens as $token) { // Get the token data. $token = $this->getTokenData($token); // Set the required flag for the token. $token->required = $mode === 'AND' ? $token->phrase ? false : true : false; // Add the token to the appropriate stack. if (count($token->matches) || $token->required) { $this->included[] = $token; $this->highlight = array_merge($this->highlight, array_keys($token->matches)); } else { $this->ignored[] = $token; } } } return true; }
/** * Method to generate filters using select box dropdown controls. * * @param FinderIndexerQuery $idxQuery A FinderIndexerQuery object. * @param array $options An array of options. * * @return mixed A rendered HTML widget on success, null otherwise. * * @since 2.5 */ public static function select($idxQuery, $options) { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $filter = null; // Get the configuration options. $classSuffix = $options->get('class_suffix', null); $showDates = $options->get('show_date_filters', false); // Try to load the results from cache. $cache = JFactory::getCache('com_finder', ''); $cacheId = 'filter_select_' . serialize(array($idxQuery->filter, $options, $groups, JFactory::getLanguage()->getTag())); // Check the cached results. if (!($branches = $cache->get($cacheId))) { $db = JFactory::getDbo(); $query = $db->getQuery(true); // Load the predefined filter if specified. if (!empty($idxQuery->filter)) { $query->select('f.data, ' . $db->quoteName('f.params'))->from($db->quoteName('#__finder_filters') . ' AS f')->where('f.filter_id = ' . (int) $idxQuery->filter); // Load the filter data. $db->setQuery($query); try { $filter = $db->loadObject(); } catch (RuntimeException $e) { return null; } // Initialize the filter parameters. if ($filter) { $registry = new Registry(); $registry->loadString($filter->params); $filter->params = $registry; } } // Build the query to get the branch data and the number of child nodes. $query->clear()->select('t.*, count(c.id) AS children')->from($db->quoteName('#__finder_taxonomy') . ' AS t')->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id')->where('t.parent_id = 1')->where('t.state = 1')->where('t.access IN (' . $groups . ')')->where('c.state = 1')->where('c.access IN (' . $groups . ')')->group($db->quoteName('t.id'))->order('t.ordering, t.title'); // Limit the branch children to a predefined filter. if (!empty($filter->data)) { $query->where('c.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($query); try { $branches = $db->loadObjectList('id'); } catch (RuntimeException $e) { return null; } // Check that we have at least one branch. if (count($branches) === 0) { return null; } // Iterate through the branches and build the branch groups. foreach ($branches as $bk => $bv) { // If the multi-lang plugin is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } // Build the query to get the child nodes for this branch. $query->clear()->select('t.*')->from($db->quoteName('#__finder_taxonomy') . ' AS t')->where('t.parent_id = ' . (int) $bk)->where('t.state = 1')->where('t.access IN (' . $groups . ')')->order('t.ordering, t.title'); // Self-join to get the parent title. $query->select('e.title AS parent_title')->join('LEFT', $db->quoteName('#__finder_taxonomy', 'e') . ' ON ' . $db->quoteName('e.id') . ' = ' . $db->quoteName('t.parent_id')); // Limit the nodes to a predefined filter. if (!empty($filter->data)) { $query->where('t.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($query); try { $branches[$bk]->nodes = $db->loadObjectList('id'); } catch (RuntimeException $e) { return null; } // Translate branch nodes if possible. $language = JFactory::getLanguage(); foreach ($branches[$bk]->nodes as $node_id => $node) { if (trim($node->parent_title, '**') == 'Language') { $title = FinderHelperLanguage::branchLanguageTitle($node->title); } else { $key = FinderHelperLanguage::branchPlural($node->title); $title = $language->hasKey($key) ? JText::_($key) : $node->title; } $branches[$bk]->nodes[$node_id]->title = $title; } // Add the Search All option to the branch. array_unshift($branches[$bk]->nodes, array('id' => null, 'title' => JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL'))); } // Store the data in cache. $cache->store($branches, $cacheId); } $html = ''; // Add the dates if enabled. if ($showDates) { $html .= JHtml::_('filter.dates', $idxQuery, $options); } $html .= '<div class="filter-branch' . $classSuffix . ' control-group">'; // Iterate through all branches and build code. foreach ($branches as $bk => $bv) { // If the multi-lang plugin is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } $active = null; // Check if the branch is in the filter. if (array_key_exists($bv->title, $idxQuery->filters)) { // Get the request filters. $temp = JFactory::getApplication()->input->request->get('t', array(), 'array'); // Search for active nodes in the branch and get the active node. $active = array_intersect($temp, $idxQuery->filters[$bv->title]); $active = count($active) === 1 ? array_shift($active) : null; } // Build a node. $html .= '<div class="controls finder-selects">'; $html .= '<label for="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '" class="control-label">'; $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title))); $html .= '</label>'; $html .= '<br />'; $html .= JHtml::_('select.genericlist', $branches[$bk]->nodes, 't[]', 'class="inputbox advancedSelect"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title)); $html .= '</div>'; } $html .= '</div>'; return $html; }
/** * Method to generate filters using select box drop down controls. * * @param FinderIndexerQuery $query A FinderIndexerQuery object. * @param array $options An array of options. * * @return mixed A rendered HTML widget on success, null otherwise. * * @since 2.5 */ public static function select($query, $options) { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $filter = null; // Get the configuration options. $classSuffix = $options->get('class_suffix', null); $loadMedia = $options->get('load_media', true); $showDates = $options->get('show_date_filters', false); // Try to load the results from cache. $cache = JFactory::getCache('com_finder', ''); $cacheId = 'filter_select_' . serialize(array($query->filter, $options, $groups, JFactory::getLanguage()->getTag())); // Check the cached results. if (!($branches = $cache->get($cacheId))) { $db = JFactory::getDBO(); $sql = $db->getQuery(true); // Load the predefined filter if specified. if (!empty($query->filter)) { $sql->select($db->quoteName('f') . '.' . $db->quoteName('data') . ', ' . $db->quoteName('f') . '.' . $db->quoteName('params')); $sql->from($db->quoteName('#__finder_filters') . ' AS f'); $sql->where($db->quoteName('f') . '.' . $db->quoteName('filter_id') . ' = ' . (int) $query->filter); // Load the filter data. $db->setQuery($sql); $filter = $db->loadObject(); // Check for an error. if ($db->getErrorNum()) { return null; } // Initialize the filter parameters. if ($filter) { $registry = new JRegistry(); $registry->loadString($filter->params); $filter->params = $registry; } } // Build the query to get the branch data and the number of child nodes. $sql->clear(); $sql->select('t.*, count(c.id) AS children'); $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t'); $sql->join('INNER', $db->quoteName('#__finder_taxonomy') . ' AS c ON c.parent_id = t.id'); $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = 1'); $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1'); $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')'); $sql->where($db->quoteName('c') . '.' . $db->quoteName('state') . ' = 1'); $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')'); $sql->group($db->quoteName('t') . '.' . $db->quoteName('id')); $sql->order('t.ordering, t.title'); // Limit the branch children to a predefined filter. if (!empty($filter->data)) { $sql->where('c.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($sql); $branches = $db->loadObjectList('id'); // Check for an error. if ($db->getErrorNum()) { return null; } // Check that we have at least one branch. if (count($branches) === 0) { return null; } // Iterate through the branches and build the branch groups. foreach ($branches as $bk => $bv) { // If the multi-lang plug-in is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } // Build the query to get the child nodes for this branch. $sql->clear(); $sql->select('t.*'); $sql->from($db->quoteName('#__finder_taxonomy') . ' AS t'); $sql->where($db->quoteName('t') . '.' . $db->quoteName('parent_id') . ' = ' . (int) $bk); $sql->where($db->quoteName('t') . '.' . $db->quoteName('state') . ' = 1'); $sql->where($db->quoteName('t') . '.' . $db->quoteName('access') . ' IN (' . $groups . ')'); $sql->order('t.ordering, t.title'); // Limit the nodes to a predefined filter. if (!empty($filter->data)) { $sql->where('t.id IN(' . $filter->data . ')'); } // Load the branches. $db->setQuery($sql); $branches[$bk]->nodes = $db->loadObjectList('id'); // Check for an error. if ($db->getErrorNum()) { return null; } // Translate branch nodes if possible. $language = JFactory::getLanguage(); foreach ($branches[$bk]->nodes as $node_id => $node) { $key = FinderHelperLanguage::branchPlural($node->title); if ($language->hasKey($key)) { $branches[$bk]->nodes[$node_id]->title = JText::_($key); } } // Add the Search All option to the branch. array_unshift($branches[$bk]->nodes, array('id' => null, 'title' => JText::_('COM_FINDER_FILTER_SELECT_ALL_LABEL'))); } // Store the data in cache. $cache->store($branches, $cacheId); } $html = ''; // Add the dates if enabled. if ($showDates) { $html .= JHtml::_('filter.dates', $query, $options); } $html .= '<ul id="finder-filter-select-list">'; // Iterate through all branches and build code. foreach ($branches as $bk => $bv) { // If the multi-lang plug-in is enabled then drop the language branch. if ($bv->title == 'Language' && JLanguageMultilang::isEnabled()) { continue; } $active = null; // Check if the branch is in the filter. if (array_key_exists($bv->title, $query->filters)) { // Get the request filters. $temp = JFactory::getApplication()->input->request->get('t', array(), 'array'); // Search for active nodes in the branch and get the active node. $active = array_intersect($temp, $query->filters[$bv->title]); $active = count($active) === 1 ? array_shift($active) : null; } $html .= '<li class="filter-branch' . $classSuffix . '">'; $html .= '<label for="tax-' . JFilterOutput::stringUrlSafe($bv->title) . '">'; $html .= JText::sprintf('COM_FINDER_FILTER_BRANCH_LABEL', JText::_(FinderHelperLanguage::branchSingular($bv->title))); $html .= '</label>'; $html .= JHtml::_('select.genericlist', $branches[$bk]->nodes, 't[]', 'class="inputbox"', 'id', 'title', $active, 'tax-' . JFilterOutput::stringUrlSafe($bv->title)); $html .= '</li>'; } // Close the widget. $html .= '</ul>'; // Load the CSS/JS resources. if ($loadMedia) { JHtml::stylesheet('com_finder/sliderfilter.css', false, true, false); } return $html; }
public static function Selectbox($selectid) { $mainframe =& JFactory::getApplication(); $author = JRequest::getVar('t'); $db =& JFactory::getDBO(); if (Count($selectid) == 0) { $query = "SELECT * FROM #__finder_taxonomy WHERE parent_id=1 AND state=1 ORDER BY ID DESC "; $db->setQuery($query); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { echo $db->stderr(); return false; } echo "<div class=\"btsmartsearch\">"; echo "<div class=\"btsmartspace\">"; foreach ($rows as $row) { echo "<select name=\"t[]\" class=\"inputboxsmart\">"; echo '<option class="option-results" value="">' . JText::_('MOD_BT_SMART_SEARCHBY') . JText::_(FinderHelperLanguage::branchSingular($row->title)) . '</option>'; $string = "SELECT * FROM #__finder_taxonomy WHERE parent_id='{$row->id}' AND state=1 ORDER BY ID DESC "; $db->setQuery($string); $items = $db->loadObjectList(); foreach ($items as $pro) { $selected = ''; if ($author) { foreach ($author as $au) { if ($au == $pro->id) { $selected = ' selected="selected"'; break; } else { $selected = ''; } } } echo '<option class="option-results" value="' . $pro->id . '"' . $selected . '>' . $pro->title . '</option>'; } echo "</select>"; } echo "</div>"; echo "</div>"; } else { echo "<div class=\"btsmartsearch\">"; echo "<div class=\"btsmartspace\">"; foreach ($selectid as $key => $value) { echo "<select name=\"t[]\" class=\"inputboxsmart\">"; echo '<option class="option-results" value="">' . JText::_('MOD_BT_SMART_SEARCHBY') . JText::_(FinderHelperLanguage::branchSingular($key)) . '</option>'; foreach ($value as $title => $id) { $selected = ''; if ($author) { foreach ($author as $au) { if ($au == $id) { $selected = ' selected="selected"'; break; } else { $selected = ''; } } } echo '<option class="option-results" value="' . $id . '"' . $selected . '>' . $title . '</option>'; } echo "</select>"; } echo "</div>"; echo "</div>"; } }
<small>(<?php echo $item->num_children; ?> )</small> <?php } elseif ($item->num_nodes > 0) { ?> <small>(<?php echo $item->num_nodes; ?> )</small> <?php } ?> <?php if ($this->escape(trim($title, '**')) == 'Language' && FinderHelperLanguage::isMultiLanguage()) { ?> <strong><?php echo JText::_('COM_FINDER_MAPS_MULTILANG'); ?> </strong> <?php } ?> </td> <td class="center nowrap"> <?php echo JHtml::_('jgrid.published', $item->state, $i, 'maps.', $canChange, 'cb'); ?> </td> </tr>