diff --git a/administrator/components/com_finder/helpers/indexer/adapter.php b/administrator/components/com_finder/helpers/indexer/adapter.php index 6ef6b2e422958..990b645f507d7 100644 --- a/administrator/components/com_finder/helpers/indexer/adapter.php +++ b/administrator/components/com_finder/helpers/indexer/adapter.php @@ -160,7 +160,7 @@ public function __construct(&$subject, $config) /** * Method to get the adapter state and push it into the indexer. * - * @return boolean True on success. + * @return void * * @since 2.5 * @throws Exception on error. @@ -312,7 +312,7 @@ abstract protected function index(FinderIndexerResult $item); * * @param integer $id The ID of the item to reindex. * - * @return boolean True on success. + * @return void * * @since 2.5 * @throws Exception on database error. @@ -902,12 +902,9 @@ protected function pluginDisable($pks) protected function translateState($item, $category = null) { // If category is present, factor in its states as well - if ($category !== null) + if ($category !== null && $category == 0) { - if ($category == 0) - { - $item = 0; - } + $item = 0; } // Translate the state diff --git a/administrator/components/com_finder/helpers/indexer/driver/mysql.php b/administrator/components/com_finder/helpers/indexer/driver/mysql.php index c91c1295e24a9..69892a20f815f 100644 --- a/administrator/components/com_finder/helpers/indexer/driver/mysql.php +++ b/administrator/components/com_finder/helpers/indexer/driver/mysql.php @@ -216,8 +216,7 @@ public function index($item, $format = 'html') if ($group === static::PATH_CONTEXT) { $ip = JFile::stripExt($ip); - $ip = str_replace('/', ' ', $ip); - $ip = str_replace('-', ' ', $ip); + $ip = str_replace(array('/', '-'), ' ', $ip); } // Tokenize a string of content and add it to the database. diff --git a/administrator/components/com_finder/helpers/indexer/driver/postgresql.php b/administrator/components/com_finder/helpers/indexer/driver/postgresql.php index cc3a32055eba9..9c3ea1a60c12d 100644 --- a/administrator/components/com_finder/helpers/indexer/driver/postgresql.php +++ b/administrator/components/com_finder/helpers/indexer/driver/postgresql.php @@ -58,7 +58,7 @@ public function index($item, $format = 'html') $isNew = empty($link->link_id) ? true : false; // Check the signatures. If they match, the item is up to date. - if (!$isNew && $curSig == $oldSig) + if (!$isNew && $curSig === $oldSig) { return $linkId; } @@ -208,8 +208,7 @@ public function index($item, $format = 'html') if ($group === static::PATH_CONTEXT) { $ip = JFile::stripExt($ip); - $ip = str_replace('/', ' ', $ip); - $ip = str_replace('-', ' ', $ip); + $ip = str_replace(array('/', '-'), ' ', $ip); } // Tokenize a string of content and add it to the database. @@ -328,7 +327,7 @@ public function index($item, $format = 'html') ' WHERE ta.term_id = 0' ); - if ($db->loadRow() == null) + if ($db->loadRow() === null) { $db->setQuery( 'INSERT INTO ' . $db->quoteName('#__finder_terms') . diff --git a/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php b/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php index dd975dc1e9470..922b6792dd594 100644 --- a/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php +++ b/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php @@ -66,7 +66,7 @@ public function index($item, $format = 'html') $isNew = empty($link->link_id) ? true : false; // Check the signatures. If they match, the item is up to date. - if (!$isNew && $curSig == $oldSig) + if (!$isNew && $curSig === $oldSig) { return $linkId; } @@ -216,8 +216,7 @@ public function index($item, $format = 'html') if ($group === static::PATH_CONTEXT) { $ip = JFile::stripExt($ip); - $ip = str_replace('/', ' ', $ip); - $ip = str_replace('-', ' ', $ip); + $ip = str_replace(array('/', '-'), ' ', $ip); } // Tokenize a string of content and add it to the database. diff --git a/administrator/components/com_finder/helpers/indexer/helper.php b/administrator/components/com_finder/helpers/indexer/helper.php index 3a8d3768b096c..5367f736459c9 100644 --- a/administrator/components/com_finder/helpers/indexer/helper.php +++ b/administrator/components/com_finder/helpers/indexer/helper.php @@ -64,7 +64,7 @@ public static function parse($input, $format = 'html') * @param string $lang The language of the input. * @param boolean $phrase Flag to indicate whether input could be a phrase. [optional] * - * @return array An array of FinderIndexerToken objects. + * @return array|FinderIndexerToken An array of FinderIndexerToken objects or a single FinderIndexerToken object. * * @since 2.5 */ @@ -124,14 +124,14 @@ public static function tokenize($input, $lang, $phrase = false) for ($i = 0, $n = count($terms); $i < $n; $i++) { $charMatches = array(); - $charCount = preg_match_all('#[\p{Han}]#mui', $terms[$i], $charMatches); + $charCount = preg_match_all('#[\p{Han}]#mui', $terms[$i], $charMatches); // Split apart any groups of Chinese characters. for ($j = 0; $j < $charCount; $j++) { $tSplit = StringHelper::str_ireplace($charMatches[0][$j], '', $terms[$i], false); - if (!empty($tSplit)) + if ((bool) $tSplit) { $terms[$i] = $tSplit; } @@ -177,7 +177,12 @@ public static function tokenize($input, $lang, $phrase = false) if ($i2 < $n && isset($tokens[$i2])) { // Tokenize the two word phrase. - $token = new FinderIndexerToken(array($tokens[$i]->term, $tokens[$i2]->term), $lang, $lang === 'zh' ? '' : ' '); + $token = new FinderIndexerToken( + array( + $tokens[$i]->term, + $tokens[$i2]->term + ), $lang, $lang === 'zh' ? '' : ' ' + ); $token->derived = true; // Add the token to the stack. @@ -188,7 +193,13 @@ public static function tokenize($input, $lang, $phrase = false) if ($i3 < $n && isset($tokens[$i3])) { // Tokenize the three word phrase. - $token = new FinderIndexerToken(array($tokens[$i]->term, $tokens[$i2]->term, $tokens[$i3]->term), $lang, $lang === 'zh' ? '' : ' '); + $token = new FinderIndexerToken( + array( + $tokens[$i]->term, + $tokens[$i2]->term, + $tokens[$i3]->term + ), $lang, $lang === 'zh' ? '' : ' ' + ); $token->derived = true; // Add the token to the stack. @@ -265,7 +276,7 @@ public static function addContentType($title, $mime = null) { static $types; - $db = JFactory::getDbo(); + $db = JFactory::getDbo(); $query = $db->getQuery(true); // Check if the types are loaded. @@ -432,7 +443,7 @@ public static function getContentPath($url) } // Build the relative route. - $uri = $router->build($url); + $uri = $router->build($url); $route = $uri->toString(array('path', 'query', 'fragment')); $route = str_replace(JUri::base(true) . '/', '', $route); @@ -450,7 +461,7 @@ public static function getContentPath($url) * @since 2.5 * @throws Exception on database error. */ - public static function getContentExtras(FinderIndexerResult &$item) + public static function getContentExtras(FinderIndexerResult $item) { // Get the event dispatcher. $dispatcher = JEventDispatcher::getInstance(); @@ -504,7 +515,7 @@ public static function prepareContent($text, $params = null, FinderIndexerResult } // Create a mock content object. - $content = JTable::getInstance('Content'); + $content = JTable::getInstance('Content'); $content->text = $text; if ($item) diff --git a/administrator/components/com_finder/helpers/indexer/indexer.php b/administrator/components/com_finder/helpers/indexer/indexer.php index 34af6698cf5a6..777ec513abc8f 100644 --- a/administrator/components/com_finder/helpers/indexer/indexer.php +++ b/administrator/components/com_finder/helpers/indexer/indexer.php @@ -177,7 +177,7 @@ public static function getInstance() public static function getState() { // First, try to load from the internal state. - if (!empty(static::$state)) + if ((bool) static::$state) { return static::$state; } @@ -443,8 +443,7 @@ protected function tokenizeToDb($input, $context, $lang, $format) // Parse, tokenise and add tokens to the database. $count = $this->tokenizeToDbShort($string, $context, $lang, $format, $count); - unset($string); - unset($tokens); + unset($string, $tokens); } return $count; @@ -513,20 +512,12 @@ protected function addTokensToDb($tokens, $context = '') $query = clone $this->addTokensToDbQueryTemplate; - // Check if a single FinderIndexerToken object was given and make it to be an array of FinderIndexerToken objects - $tokens = is_array($tokens) ? $tokens : array($tokens); - // Count the number of token values. $values = 0; - // Break into chunks of no more than 1000 items - $chunks = array_chunk($tokens, 1000); - - foreach ($chunks as $tokens) + // Iterate through the tokens to create SQL value sets. + if (!is_a($tokens, 'FinderIndexerToken')) { - $query->clear('values'); - - // Iterate through the tokens to create SQL value sets. foreach ($tokens as $token) { $query->values( @@ -534,15 +525,27 @@ protected function addTokensToDb($tokens, $context = '') . $db->quote($token->stem) . ', ' . (int) $token->common . ', ' . (int) $token->phrase . ', ' - . (float) $token->weight . ', ' + . $db->escape((float) $token->weight) . ', ' . (int) $context . ', ' . $db->quote($token->language) ); ++$values; } - - $db->setQuery($query)->execute(); } + else + { + $query->values( + $db->quote($tokens->term) . ', ' + . $db->quote($tokens->stem) . ', ' + . (int) $tokens->common . ', ' + . (int) $tokens->phrase . ', ' + . $db->escape((float) $tokens->weight) . ', ' + . (int) $context . ', ' + . $db->quote($tokens->language) + ); + ++$values; + } + $db->setQuery($query)->execute(); return $values; } diff --git a/administrator/components/com_finder/helpers/indexer/parser/html.php b/administrator/components/com_finder/helpers/indexer/parser/html.php index 4bf1e79b8dfce..8fcd0ac103fc3 100644 --- a/administrator/components/com_finder/helpers/indexer/parser/html.php +++ b/administrator/components/com_finder/helpers/indexer/parser/html.php @@ -98,6 +98,8 @@ protected function process($input) * @param string $endTag String representing the end tag. * * @return string with blocks removed. + * + * @since 3.4 */ private function removeBlocks($input, $startTag, $endTag) { diff --git a/administrator/components/com_finder/helpers/indexer/parser/rtf.php b/administrator/components/com_finder/helpers/indexer/parser/rtf.php index fbb2563d2c4db..d6b5acb9faddb 100644 --- a/administrator/components/com_finder/helpers/indexer/parser/rtf.php +++ b/administrator/components/com_finder/helpers/indexer/parser/rtf.php @@ -30,12 +30,12 @@ class FinderIndexerParserRtf extends FinderIndexerParser protected function process($input) { // Remove embedded pictures. - $input = preg_replace('#{\\\pict[^}]*}#mis', '', $input); + $input = preg_replace('#{\\\pict[^}]*}#mi', '', $input); // Remove control characters. $input = str_replace(array('{', '}', "\\\n"), array(' ', ' ', "\n"), $input); - $input = preg_replace('#\\\([^;]+?);#mis', ' ', $input); - $input = preg_replace('#\\\[\'a-zA-Z0-9]+#mis', ' ', $input); + $input = preg_replace('#\\\([^;]+?);#m', ' ', $input); + $input = preg_replace('#\\\[\'a-zA-Z0-9]+#mi', ' ', $input); return $input; } diff --git a/administrator/components/com_finder/helpers/indexer/query.php b/administrator/components/com_finder/helpers/indexer/query.php index 02850fc13f73c..468ee32cd7b06 100644 --- a/administrator/components/com_finder/helpers/indexer/query.php +++ b/administrator/components/com_finder/helpers/indexer/query.php @@ -188,34 +188,34 @@ public function __construct($options) $this->dates = new Registry; // Populate the temporary date storage. - if (isset($options['date1']) && !empty($options['date1'])) + if (!empty($options['date1'])) { $this->dates->set('date1', $options['date1']); } - if (isset($options['date2']) && !empty($options['date1'])) + if (!empty($options['date2'])) { $this->dates->set('date2', $options['date2']); } - if (isset($options['when1']) && !empty($options['date1'])) + if (!empty($options['when1'])) { $this->dates->set('when1', $options['when1']); } - if (isset($options['when2']) && !empty($options['date1'])) + if (!empty($options['when2'])) { $this->dates->set('when2', $options['when2']); } // Process the static taxonomy filters. - if (isset($options['filter']) && !empty($options['filter'])) + if (!empty($options['filter'])) { $this->processStaticTaxonomy($options['filter']); } // Process the dynamic taxonomy filters. - if (isset($options['filters']) && !empty($options['filters'])) + if (!empty($options['filters'])) { $this->processDynamicTaxonomy($options['filters']); } @@ -272,10 +272,10 @@ public function __construct($options) * * @since 2.5 */ - public function toUri($base = null) + public function toUri($base = '') { // Set the base if not specified. - if (empty($base)) + if ($base === '') { $base = 'index.php?option=com_finder&view=search'; } @@ -284,7 +284,7 @@ public function toUri($base = null) $uri = JUri::getInstance($base); // Add the static taxonomy filter if present. - if (!empty($this->filter)) + if ((bool) $this->filter) { $uri->setVar('f', $this->filter); } @@ -293,7 +293,7 @@ public function toUri($base = null) $t = JFactory::getApplication()->input->request->get('t', array(), 'array'); // Add the dynamic taxonomy filters if present. - if (!empty($this->filters)) + if ((bool) $this->filters) { foreach ($this->filters as $nodes) { @@ -522,7 +522,7 @@ protected function processStaticTaxonomy($filterId) $filters = ArrayHelper::toInteger($filters); // Remove any values of zero. - if (array_search(0, $filters, true) !== false) + if (in_array(0, $filters, true) !== false) { unset($filters[array_search(0, $filters, true)]); } @@ -585,7 +585,7 @@ protected function processDynamicTaxonomy($filters) $filters = ArrayHelper::toInteger($filters); // Remove any values of zero. - if (array_search(0, $filters, true) !== false) + if (in_array(0, $filters, true) !== false) { unset($filters[array_search(0, $filters, true)]); } @@ -598,6 +598,7 @@ protected function processDynamicTaxonomy($filters) // Get the database object. $db = JFactory::getDbo(); + $query = $db->getQuery(true); /* @@ -633,7 +634,7 @@ protected function processDynamicTaxonomy($filters) foreach ($results as $result) { // Check if the branch has been cleared. - if (!in_array($result->branch, $cleared)) + if (!in_array($result->branch, $cleared, true)) { // Clear the branch. $this->filters[$result->branch] = array(); @@ -690,7 +691,7 @@ protected function processDates($date1, $date2, $when1, $when2) { // Set the date filter. $this->date1 = $date->toSql(); - $this->when1 = in_array($when1, $whens) ? $when1 : 'before'; + $this->when1 = in_array($when1, $whens, true) ? $when1 : 'before'; } // The value of 'today' is a special case that we need to handle. @@ -707,7 +708,7 @@ protected function processDates($date1, $date2, $when1, $when2) { // Set the date filter. $this->date2 = $date->toSql(); - $this->when2 = in_array($when2, $whens) ? $when2 : 'before'; + $this->when2 = in_array($when2, $whens, true) ? $when2 : 'before'; } return true; @@ -814,7 +815,7 @@ protected function processString($input, $lang, $mode) { // Set the date filter. $this->date1 = $date->toSql(); - $this->when1 = in_array($modifier, $whens) ? $modifier : 'before'; + $this->when1 = in_array($modifier, $whens, true) ? $modifier : 'before'; } break; @@ -822,7 +823,7 @@ protected function processString($input, $lang, $mode) // Handle a taxonomy branch filter. default: - { + { // Try to find the node id. $return = FinderIndexerTaxonomy::getNodeByTitle($modifier, $value); @@ -830,7 +831,7 @@ protected function processString($input, $lang, $mode) if ($return) { // Check if the branch has been cleared. - if (!in_array($modifier, $cleared)) + if (!in_array($modifier, $cleared, true)) { // Clear the branch. $this->filters[$modifier] = array(); @@ -863,7 +864,7 @@ protected function processString($input, $lang, $mode) $matches = array(); // Extract the tokens enclosed in double quotes. - if (preg_match_all('#\"([^"]+)\"#mi', $input, $matches)) + if (preg_match_all('#\"([^"]+)\"#m', $input, $matches)) { /* * One or more phrases were found so we need to iterate through @@ -941,7 +942,7 @@ protected function processString($input, $lang, $mode) if (count($chunk)) { $phrases[] = implode(' ', $chunk); - $terms[] = implode(' ', $chunk); + $terms[] = implode(' ', $chunk); } } } @@ -949,14 +950,14 @@ protected function processString($input, $lang, $mode) { // The phrase is <= 3 words so we can use it as is. $phrases[] = $match; - $terms[] = $match; + $terms[] = $match; } } } } // Add the remaining terms if present. - if (!empty($input)) + if ((bool) $input) { $terms = array_merge($terms, explode(' ', $input)); } @@ -972,7 +973,7 @@ protected function processString($input, $lang, $mode) if (JDEBUG) { $debugStrings = array('**', '??'); - $operators = str_replace($debugStrings, '', $operators); + $operators = str_replace($debugStrings, '', $operators); } /* @@ -983,16 +984,18 @@ protected function processString($input, $lang, $mode) 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)) + if (isset($terms[$i + 1]) && in_array($terms[$i + 1], $operators, true)) { // Get the operator mode. - $op = array_search($terms[$i + 1], $operators); + $op = array_search($terms[$i + 1], $operators, true); // Handle the AND operator. if ($op === 'AND' && isset($terms[$i + 2])) { // Tokenize the current term. $token = FinderIndexerHelper::tokenize($terms[$i], $lang, true); + + // Todo: The previous function call may return an array, which seems not to be handled by the next one, which expects an object $token = $this->getTokenData($token); // Set the required flag. @@ -1000,7 +1003,7 @@ protected function processString($input, $lang, $mode) // Add the current token to the stack. $this->included[] = $token; - $this->highlight = array_merge($this->highlight, array_keys($token->matches)); + $this->highlight = array_merge($this->highlight, array_keys($token->matches)); // Skip the next token (the mode operator). $this->operators[] = $terms[$i + 1]; @@ -1014,23 +1017,21 @@ protected function processString($input, $lang, $mode) // Add the token after the next token to the stack. $this->included[] = $other; - $this->highlight = array_merge($this->highlight, array_keys($other->matches)); + $this->highlight = array_merge($this->highlight, array_keys($other->matches)); // Remove the processed phrases if possible. - if (($pk = array_search($terms[$i], $phrases)) !== false) + if (($pk = array_search($terms[$i], $phrases, true)) !== false) { unset($phrases[$pk]); } - if (($pk = array_search($terms[$i + 2], $phrases)) !== false) + if (($pk = array_search($terms[$i + 2], $phrases, true)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. - unset($terms[$i]); - unset($terms[$i + 1]); - unset($terms[$i + 2]); + unset($terms[$i], $terms[$i + 1], $terms[$i + 2]); // Adjust the loop. $i += 2; @@ -1047,10 +1048,10 @@ protected function processString($input, $lang, $mode) $token->required = false; // Add the current token to the stack. - if (count($token->matches)) + if ((bool) $token->matches) { $this->included[] = $token; - $this->highlight = array_merge($this->highlight, array_keys($token->matches)); + $this->highlight = array_merge($this->highlight, array_keys($token->matches)); } else { @@ -1068,10 +1069,10 @@ protected function processString($input, $lang, $mode) $other->required = false; // Add the token after the next token to the stack. - if (count($other->matches)) + if ((bool) $other->matches) { $this->included[] = $other; - $this->highlight = array_merge($this->highlight, array_keys($other->matches)); + $this->highlight = array_merge($this->highlight, array_keys($other->matches)); } else { @@ -1079,20 +1080,18 @@ protected function processString($input, $lang, $mode) } // Remove the processed phrases if possible. - if (($pk = array_search($terms[$i], $phrases)) !== false) + if (($pk = array_search($terms[$i], $phrases, true)) !== false) { unset($phrases[$pk]); } - if (($pk = array_search($terms[$i + 2], $phrases)) !== false) + if (($pk = array_search($terms[$i + 2], $phrases, true)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. - unset($terms[$i]); - unset($terms[$i + 1]); - unset($terms[$i + 2]); + unset($terms[$i], $terms[$i + 1], $terms[$i + 2]); // Adjust the loop. $i += 2; @@ -1100,7 +1099,7 @@ protected function processString($input, $lang, $mode) } } // Handle an orphaned OR operator. - elseif (isset($terms[$i + 1]) && array_search($terms[$i], $operators) === 'OR') + elseif (isset($terms[$i + 1]) && array_search($terms[$i], $operators, true) === 'OR') { // Skip the next token (the mode operator). $this->operators[] = $terms[$i]; @@ -1113,10 +1112,10 @@ protected function processString($input, $lang, $mode) $other->required = false; // Add the token after the next token to the stack. - if (count($other->matches)) + if ((bool) $other->matches) { $this->included[] = $other; - $this->highlight = array_merge($this->highlight, array_keys($other->matches)); + $this->highlight = array_merge($this->highlight, array_keys($other->matches)); } else { @@ -1124,21 +1123,20 @@ protected function processString($input, $lang, $mode) } // Remove the processed phrase if possible. - if (($pk = array_search($terms[$i + 1], $phrases)) !== false) + if (($pk = array_search($terms[$i + 1], $phrases, true)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. - unset($terms[$i]); - unset($terms[$i + 1]); + unset($terms[$i], $terms[$i + 1]); // Adjust the loop. $i++; continue; } // Handle the NOT operator. - elseif (isset($terms[$i + 1]) && array_search($terms[$i], $operators) === 'NOT') + elseif (isset($terms[$i + 1]) && array_search($terms[$i], $operators, true) === 'NOT') { // Skip the next token (the mode operator). $this->operators[] = $terms[$i]; @@ -1151,7 +1149,7 @@ protected function processString($input, $lang, $mode) $other->required = false; // Add the next token to the stack. - if (count($other->matches)) + if ((bool) $other->matches) { $this->excluded[] = $other; } @@ -1161,14 +1159,13 @@ protected function processString($input, $lang, $mode) } // Remove the processed phrase if possible. - if (($pk = array_search($terms[$i + 1], $phrases)) !== false) + if (($pk = array_search($terms[$i + 1], $phrases, true)) !== false) { unset($phrases[$pk]); } // Remove the processed terms. - unset($terms[$i]); - unset($terms[$i + 1]); + unset($terms[$i], $terms[$i + 1]); // Adjust the loop. $i++; @@ -1192,10 +1189,10 @@ protected function processString($input, $lang, $mode) // Add the current token to the stack. $this->included[] = $token; - $this->highlight = array_merge($this->highlight, array_keys($token->matches)); + $this->highlight = array_merge($this->highlight, array_keys($token->matches)); // Remove the processed term if possible. - if (($pk = array_search($phrases[$i], $terms)) !== false) + if (($pk = array_search($phrases[$i], $terms, true)) !== false) { unset($terms[$pk]); } @@ -1207,10 +1204,10 @@ protected function processString($input, $lang, $mode) /* * Handle any remaining tokens using the standard processing mechanism. */ - if (!empty($terms)) + if ((bool) $terms) { // Tokenize the terms. - $terms = implode(' ', $terms); + $terms = implode(' ', $terms); $tokens = FinderIndexerHelper::tokenize($terms, $lang, false); // Make sure we are working with an array. @@ -1223,13 +1220,13 @@ protected function processString($input, $lang, $mode) $token = $this->getTokenData($token); // Set the required flag for the token. - $token->required = $mode === 'AND' ? ($token->phrase ? false : true) : false; + $token->required = $mode === 'AND' ? (!$token->phrase) : false; // Add the token to the appropriate stack. - if (count($token->matches) || $token->required) + if ($token->required || (bool) $token->matches) { $this->included[] = $token; - $this->highlight = array_merge($this->highlight, array_keys($token->matches)); + $this->highlight = array_merge($this->highlight, array_keys($token->matches)); } else { @@ -1299,11 +1296,8 @@ protected function getTokenData($token) $db->setQuery($query); $matches = $db->loadObjectList(); - // Setup the container. - $token->matches = array(); - // Check the matching terms. - if (!empty($matches)) + if ((bool) $matches) { // Add the matches to the token. for ($i = 0, $c = count($matches); $i < $c; $i++) @@ -1355,7 +1349,7 @@ protected function getTokenData($token) // Get the closest match. $keys = array_keys($suggestions); - $key = $keys[0]; + $key = $keys[0]; // Add the suggested term. $token->suggestion = $results[$key]->term; diff --git a/administrator/components/com_finder/helpers/indexer/result.php b/administrator/components/com_finder/helpers/indexer/result.php index 58629d069bf27..bf3590d1ca93b 100644 --- a/administrator/components/com_finder/helpers/indexer/result.php +++ b/administrator/components/com_finder/helpers/indexer/result.php @@ -324,14 +324,11 @@ public function getInstructions() public function addInstruction($group, $property) { // Check if the group exists. We can't add instructions for unknown groups. - if (array_key_exists($group, $this->instructions)) + // Check if the property exists in the group. + if (array_key_exists($group, $this->instructions) && !in_array($property, $this->instructions[$group], true)) { - // Check if the property exists in the group. - if (!in_array($property, $this->instructions[$group])) - { - // Add the property to the group. - $this->instructions[$group][] = $property; - } + // Add the property to the group. + $this->instructions[$group][] = $property; } } diff --git a/administrator/components/com_finder/helpers/indexer/stemmer/fr.php b/administrator/components/com_finder/helpers/indexer/stemmer/fr.php index 8aa080efc5fff..cd99112c4e370 100644 --- a/administrator/components/com_finder/helpers/indexer/stemmer/fr.php +++ b/administrator/components/com_finder/helpers/indexer/stemmer/fr.php @@ -27,7 +27,7 @@ class FinderIndexerStemmerFr extends FinderIndexerStemmer * @var array * @since 3.0 */ - private static $stemRules = null; + private static $stemRules; /** * Method to stem a token and return the root. @@ -48,7 +48,7 @@ public function stem($token, $lang) } // Check if the language is French or All. - if ($lang !== 'fr' && $lang != '*') + if ($lang !== 'fr' && $lang !== '*') { return $token; } @@ -216,7 +216,6 @@ private static function getStem($input) { $vars = static::getStemRules(); - $intact = true; $reversed_input = strrev(utf8_decode($input)); $rule_number = 0; @@ -225,7 +224,7 @@ private static function getStem($input) { $rule_number = self::getFirstRule($reversed_input, $rule_number); - if ($rule_number == -1) + if ($rule_number === -1) { // No other rule can be applied => the stem has been found break; @@ -234,23 +233,15 @@ private static function getStem($input) $rule = $vars['rules'][$rule_number]; preg_match($vars['rule_pattern'], $rule, $matches); - if ($matches[2] != '*' || $intact) - { - $reversed_stem = utf8_decode($matches[4]) . substr($reversed_input, $matches[3], strlen($reversed_input) - $matches[3]); + $reversed_stem = utf8_decode($matches[4]) . substr($reversed_input, $matches[3]); - if (self::check($reversed_stem)) - { - $reversed_input = $reversed_stem; + if (self::check($reversed_stem)) + { + $reversed_input = $reversed_stem; - if ($matches[5] == '.') - { - break; - } - } - else + if ($matches[5] === '.') { - // Go to another rule - $rule_number++; + break; } } else diff --git a/administrator/components/com_finder/helpers/indexer/stemmer/porter_en.php b/administrator/components/com_finder/helpers/indexer/stemmer/porter_en.php index 663cc6cf26f55..0b019c013f5fd 100644 --- a/administrator/components/com_finder/helpers/indexer/stemmer/porter_en.php +++ b/administrator/components/com_finder/helpers/indexer/stemmer/porter_en.php @@ -56,7 +56,7 @@ public function stem($token, $lang) } // Check if the language is English or All. - if ($lang !== 'en' && $lang != '*') + if ($lang !== 'en' && $lang !== '*') { return $token; } @@ -92,7 +92,7 @@ public function stem($token, $lang) private static function step1ab($word) { // Part a - if (substr($word, -1) == 's') + if (substr($word, -1) === 's') { self::replace($word, 'sses', 'ss') || self::replace($word, 'ies', 'i') @@ -101,7 +101,7 @@ private static function step1ab($word) } // Part b - if (substr($word, -2, 1) != 'e' || !self::replace($word, 'eed', 'ee', 0)) + if (substr($word, -2, 1) !== 'e' || !self::replace($word, 'eed', 'ee', 0)) { // First rule $v = self::$regex_vowel; @@ -115,11 +115,13 @@ private static function step1ab($word) if (!self::replace($word, 'at', 'ate') && !self::replace($word, 'bl', 'ble') && !self::replace($word, 'iz', 'ize')) { // Double consonant ending - if (self::doubleConsonant($word) && substr($word, -2) != 'll' && substr($word, -2) != 'ss' && substr($word, -2) != 'zz') + $wordSubStr = substr($word, -2); + + if ($wordSubStr !== 'll' && $wordSubStr !== 'ss' && $wordSubStr !== 'zz' && self::doubleConsonant($word)) { $word = substr($word, 0, -1); } - elseif (self::m($word) == 1 && self::cvc($word)) + elseif (self::m($word) === 1 && self::cvc($word)) { $word .= 'e'; } @@ -143,7 +145,7 @@ private static function step1c($word) { $v = self::$regex_vowel; - if (substr($word, -1) == 'y' && preg_match("#$v+#", substr($word, 0, -1))) + if (substr($word, -1) === 'y' && preg_match("#$v+#", substr($word, 0, -1))) { self::replace($word, 'y', 'i'); } @@ -280,7 +282,9 @@ private static function step4($word) || self::replace($word, 'ent', '', 1); break; case 'o': - if (substr($word, -4) == 'tion' || substr($word, -4) == 'sion') + $wordSubStr = substr($word, -4); + + if ($wordSubStr === 'tion' || $wordSubStr === 'sion') { self::replace($word, 'ion', '', 1); } @@ -322,13 +326,13 @@ private static function step4($word) private static function step5($word) { // Part a - if (substr($word, -1) == 'e') + if (substr($word, -1) === 'e') { if (self::m(substr($word, 0, -1)) > 1) { self::replace($word, 'e', ''); } - elseif (self::m(substr($word, 0, -1)) == 1) + elseif (self::m(substr($word, 0, -1)) === 1) { if (!self::cvc(substr($word, 0, -1))) { @@ -338,7 +342,7 @@ private static function step5($word) } // Part b - if (self::m($word) > 1 && self::doubleConsonant($word) && substr($word, -1) == 'l') + if (self::m($word) > 1 && self::doubleConsonant($word) && substr($word, -1) === 'l') { $word = substr($word, 0, -1); } @@ -365,11 +369,11 @@ private static function replace(&$str, $check, $repl, $m = null) { $len = 0 - strlen($check); - if (substr($str, $len) == $check) + if (substr($str, $len) === $check) { $substr = substr($str, 0, $len); - if (is_null($m) || self::m($substr) > $m) + if ($m === null || self::m($substr) > $m) { $str = $substr . $repl; } @@ -423,7 +427,7 @@ private static function doubleConsonant($str) { $c = self::$regex_consonant; - return preg_match("#$c{2}$#", $str, $matches) && $matches[0]{0} == $matches[0]{1}; + return preg_match("#$c{2}$#", $str, $matches) && $matches[0][0] === $matches[0][1]; } /** @@ -440,7 +444,7 @@ private static function cvc($str) $c = self::$regex_consonant; $v = self::$regex_vowel; - return preg_match("#($c$v$c)$#", $str, $matches) && strlen($matches[1]) == 3 && $matches[1]{2} != 'w' && $matches[1]{2} != 'x' - && $matches[1]{2} != 'y'; + return preg_match("#($c$v$c)$#", $str, $matches) && strlen($matches[1]) === 3 && $matches[1][2] !== 'w' && $matches[1][2] !== 'x' + && $matches[1][2] !== 'y'; } } diff --git a/administrator/components/com_finder/helpers/indexer/stemmer/snowball.php b/administrator/components/com_finder/helpers/indexer/stemmer/snowball.php index 44a8899654a72..89bdec4a85c4d 100644 --- a/administrator/components/com_finder/helpers/indexer/stemmer/snowball.php +++ b/administrator/components/com_finder/helpers/indexer/stemmer/snowball.php @@ -34,7 +34,7 @@ public function stem($token, $lang) static $defaultLang = ''; // If language is All then try to get site default language. - if ($lang == '*' && $defaultLang == '') + if ($lang === '*' && $defaultLang === '') { $languages = JLanguageHelper::getLanguages(); $defaultLang = isset($languages[0]->sef) ? $languages[0]->sef : '*'; diff --git a/administrator/components/com_finder/helpers/indexer/taxonomy.php b/administrator/components/com_finder/helpers/indexer/taxonomy.php index 92637310965b5..52c28b1d13e09 100644 --- a/administrator/components/com_finder/helpers/indexer/taxonomy.php +++ b/administrator/components/com_finder/helpers/indexer/taxonomy.php @@ -65,7 +65,7 @@ public static function addBranch($title, $state = 1, $access = 1) $result = $db->loadObject(); // Check if the database matches the input data. - if (!empty($result) && $result->state == $state && $result->access == $access) + if ((bool) $result && $result->state == $state && $result->access == $access) { // The data matches, add the item to the cache. static::$branches[$title] = $result; @@ -145,7 +145,7 @@ public static function addNode($branch, $title, $state = 1, $access = 1) $result = $db->loadObject(); // Check if the database matches the input data. - if (!empty($result) && $result->state == $state && $result->access == $access) + if ((bool) $result && $result->state == $state && $result->access == $access) { // The data matches, add the item to the cache. static::$nodes[$branch][$title] = $result; diff --git a/administrator/components/com_finder/helpers/indexer/token.php b/administrator/components/com_finder/helpers/indexer/token.php index ec8040983605d..6f7aafc4c7503 100644 --- a/administrator/components/com_finder/helpers/indexer/token.php +++ b/administrator/components/com_finder/helpers/indexer/token.php @@ -87,6 +87,30 @@ class FinderIndexerToken */ public $language; + /** + * The container for matches. + * + * @var array + * @since __DEPLOY_VERSION__ + */ + public $matches = array(); + + /** + * Is derived token (from individual words) + * + * @var boolean + * @since __DEPLOY_VERSION__ + */ + public $derived; + + /** + * The suggested term + * + * @var string + * @since __DEPLOY_VERSION__ + */ + public $suggestion; + /** * Method to construct the token object. * @@ -138,9 +162,9 @@ public function __construct($term, $lang, $spacer = ' ') * 3. If numeric, multiply weight by 1.5. * 4. Round weight to 4 decimal points. */ - $this->weight = (($this->length >= 15 ? 15 : $this->length) / 15); - $this->weight = ($this->common == true ? $this->weight / 8 : $this->weight); - $this->weight = ($this->numeric == true ? $this->weight * 1.5 : $this->weight); + $this->weight = ($this->length >= 15 ? 15 : $this->length) / 15; + $this->weight = $this->common === true ? $this->weight / 8 : $this->weight; + $this->weight = $this->numeric === true ? $this->weight * 1.5 : $this->weight; $this->weight = round($this->weight, 4); } } diff --git a/cli/finder_indexer.php b/cli/finder_indexer.php index be0746f56a962..29cb332b11b6f 100644 --- a/cli/finder_indexer.php +++ b/cli/finder_indexer.php @@ -73,7 +73,7 @@ class FinderCli extends JApplicationCli * @var string * @since 2.5 */ - private $time = null; + private $time; /** * Start time for each batch @@ -81,7 +81,7 @@ class FinderCli extends JApplicationCli * @var string * @since 2.5 */ - private $qtime = null; + private $qtime; /** * Static filters information. @@ -207,7 +207,7 @@ private function index() JEventDispatcher::getInstance()->trigger('onBuildIndex'); // Batch reporting. - $this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', ($i + 1), round(microtime(true) - $this->qtime, 3)), true); + $this->out(JText::sprintf('FINDER_CLI_BATCH_COMPLETE', $i + 1, round(microtime(true) - $this->qtime, 3)), true); } } catch (Exception $e) @@ -342,7 +342,7 @@ private function getFilters() foreach ($filters as $filter) { // Skip empty filters. - if ($filter->data == '') + if ($filter->data === '') { continue; }