function verify_word_allowed(&$word) { global $vbulletin, $phrasequery; $wordlower = strtolower($word); // check if the word contains wildcards if (strpos($wordlower, '*') !== false) { // check if wildcards are allowed if ($vbulletin->options['allowwildcards']) { // check the length of the word with all * characters removed // and make sure it's at least (minsearchlength - 1) characters long // in order to prevent searches like *a**... which would be bad if (vbstrlen(str_replace('*', '', $wordlower)) < $vbulletin->options['minsearchlength'] - 1) { // word is too short $word = htmlspecialchars_uni($word); eval(standard_error(fetch_error('searchinvalidterm', $word, $vbulletin->options['minsearchlength']))); } else { // word is of valid length return true; } } else { // wildcards are not allowed - error $word = htmlspecialchars_uni($word); eval(standard_error(fetch_error('searchinvalidterm', $word, $vbulletin->options['minsearchlength']))); } } else { if ($wordokay = is_index_word($word)) { return true; } else { // word is a bad word (common, too long, or too short; don't search on it) return false; } } }
/** * Prepare meta description to use first 20 keywords of the artile if it's not set. See bug #30456 */ protected function prepareFields() { parent::prepareFields(); if ((empty($this->set_fields['description']) OR $this->set_fields['description'] == (string) new vB_Phrase('vbcms', 'new_article')) AND !empty($this->type_set_fields['pagetext'])) { require_once(DIR . '/includes/functions_databuild.php'); $words = fetch_postindex_text($this->type_set_fields['pagetext']); $wordarray = split_string($words); $scores = array(); foreach ($wordarray AS $word) { if (!is_index_word($word)) { continue; } $scores[$word]++; } // Sort scores arsort($scores, SORT_NUMERIC); $scores = array_slice($scores, 0, 10, true); $this->set_fields['description'] = ''; foreach ($scores as $k => $v) { $this->set_fields['description'] .= $k . ' '; } $this->set_fields['description'] = trim($this->set_fields['description']); } }
function build_post_index($postid, $foruminfo, $firstpost = -1, $post = false) { global $vbulletin; if ($vbulletin->options['fulltextsearch']) { return; } if (!empty($post['postid'])) { $postid = $post['postid']; } $postid = intval($postid); if (!$postid) { // no postid, don't know what to do anyway return; } if ($foruminfo['indexposts']) { global $vbulletin; static $firstpst; if (is_array($post)) { if (isset($post['threadtitle'])) { $threadinfo = array('title' => $post['threadtitle']); } } else { $post = $vbulletin->db->query_first("\n\t\t\t\tSELECT postid, post.title, pagetext, post.threadid, thread.title AS threadtitle\n\t\t\t\tFROM " . TABLE_PREFIX . "post AS post\n\t\t\t\tINNER JOIN " . TABLE_PREFIX . "thread AS thread USING(threadid)\n\t\t\t\tWHERE postid = {$postid}\n\t\t\t"); $threadinfo = array('title' => $post['threadtitle']); } if (isset($firstpst["{$post['threadid']}"])) { if ($firstpst["{$post['threadid']}"] == $postid) { $firstpost = 1; } else { $firstpost = 0; } } if ($firstpost == -1) { $getfirstpost = $vbulletin->db->query_first("\n\t\t\t\tSELECT MIN(postid) AS postid\n\t\t\t\tFROM " . TABLE_PREFIX . "post\n\t\t\t\tWHERE threadid = " . intval($post['threadid'])); if ($getfirstpost['postid'] == $postid) { $firstpost = 1; } else { $firstpost = 0; } } $allwords = ''; if ($firstpost) { if (!is_array($threadinfo)) { $threadinfo = $vbulletin->db->query_first("\n\t\t\t\t\tSELECT title\n\t\t\t\t\tFROM " . TABLE_PREFIX . "thread\n\t\t\t\t\tWHERE threadid = {$post['threadid']}\n\t\t\t\t"); } $firstpst["{$post['threadid']}"] = $postid; $words = fetch_postindex_text($threadinfo['title']); $wordarray = split_string($words); $allwords .= implode(' ', $wordarray); foreach ($wordarray as $word) { #$scores["$word"] += $vbulletin->options['threadtitlescore']; $intitle["{$word}"] = 2; $scores["{$word}"]++; } } $words = fetch_postindex_text($post['title']); $wordarray = split_string($words); $allwords .= ' ' . implode(' ', $wordarray); foreach ($wordarray as $word) { #$scores["$word"] += $vbulletin->options['posttitlescore']; if (empty($intitle["{$word}"])) { $intitle["{$word}"] = 1; } $scores["{$word}"]++; } $words = fetch_postindex_text($post['pagetext']); $wordarray = split_string($words); $allwords .= ' ' . implode(' ', $wordarray); foreach ($wordarray as $word) { $scores["{$word}"]++; } $getwordidsql = "title IN ('" . str_replace(" ", "','", $allwords) . "')"; $words = $vbulletin->db->query_read_slave("SELECT wordid, title FROM " . TABLE_PREFIX . "word WHERE {$getwordidsql}"); while ($word = $vbulletin->db->fetch_array($words)) { $word['title'] = vbstrtolower($word['title']); $wordcache["{$word['title']}"] = $word['wordid']; } $vbulletin->db->free_result($words); $insertsql = ''; $newwords = ''; $newtitlewords = ''; foreach ($scores as $word => $score) { if (!is_index_word($word)) { unset($scores["{$word}"]); continue; } // prevent score going over 255 for overflow control if ($score > 255) { $scores["{$word}"] = 255; } // make sure intitle score is set $intitle["{$word}"] = intval($intitle["{$word}"]); if ($word) { if (isset($wordcache["{$word}"])) { // Does this word already exist in the word table? $insertsql .= ", (" . $vbulletin->db->escape_string($wordcache["{$word}"]) . ", {$postid}, {$score}, {$intitle[$word]})"; // yes so just add a postindex entry for this post/word unset($scores["{$word}"], $intitle["{$word}"]); } else { $newwords .= $word . ' '; // No so add it to the word table } } } if (!empty($insertsql)) { $insertsql = substr($insertsql, 1); /*insert query*/ $vbulletin->db->query_write("\n\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "postindex\n\t\t\t\t(wordid, postid, score, intitle)\n\t\t\t\tVALUES\n\t\t\t\t{$insertsql}\n\t\t\t"); } $newwords = trim($newwords); if ($newwords) { $insertwords = "('" . str_replace(" ", "'),('", $newwords) . "')"; /*insert query*/ $vbulletin->db->query_write("INSERT IGNORE INTO " . TABLE_PREFIX . "word (title) VALUES {$insertwords}"); $selectwords = "title IN ('" . str_replace(" ", "','", $newwords) . "')"; $scoressql = 'CASE title'; foreach ($scores as $word => $score) { $scoressql .= " WHEN '" . $vbulletin->db->escape_string($word) . "' THEN {$score}"; } $scoressql .= ' ELSE 1 END'; $titlesql = 'CASE title'; foreach ($intitle as $word => $intitlescore) { $titlesql .= " WHEN '" . $vbulletin->db->escape_string($word) . "' THEN {$intitlescore}"; } $titlesql .= ' ELSE 0 END'; /*insert query*/ $vbulletin->db->query_write("\n\t\t\t\tINSERT IGNORE INTO " . TABLE_PREFIX . "postindex\n\t\t\t\t(wordid, postid, score, intitle)\n\t\t\t\tSELECT DISTINCT wordid, {$postid}, {$scoressql}, {$titlesql}\n\t\t\t\tFROM " . TABLE_PREFIX . "word\n\t\t\t\tWHERE {$selectwords}\n\t\t\t"); } } }
/** * Make sure that a wildcard string is allowed. * @param string $word -- the word to check for wildcard * @return bool */ private function verify_wildcard($word) { global $vbulletin; //not sure what this is for -- probably doesn't do anything since * doesn't have //an upper case. However the code I cribbed this from does it this way and it //doesn't hurt anything. $wordlower = strtolower($word); $minlength = $vbulletin->options['minsearchlength']; // check if the word contains wildcards if (strpos($wordlower, '*') !== false) { // check if wildcards are allowed if ($vbulletin->options['allowwildcards']) { // check the length of the word with all * characters removed // and make sure it's at least (minsearchlength - 1) characters long // in order to prevent searches like *a**... which would be bad if (vbstrlen(str_replace('*', '', $wordlower)) < $minlength - 1) { // word is too short // $this->errors[] = array('searchinvalidterm', htmlspecialchars_uni($word), $minlength); $this->add_error('searchinvalidterm', htmlspecialchars_uni($word), $minlength); return false; } else { // word is of valid length return true; } } else { // do we need a more descriptive error for this? // wildcards are not allowed - error // $this->errors[] = array('searchinvalidterm', htmlspecialchars_uni($word), $minlength); $this->add_error('searchinvalidterm', htmlspecialchars_uni($word), $minlength); return false; } } else { return is_index_word($word); } return true; }