From a50b0faf4abfb1bba68e03d843c58f07f842cf12 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Fri, 4 May 2012 18:39:41 +0530 Subject: [feature/sphinx-fulltext-search] MOD by naderman installed in phpbb PHPBB3-10946 --- phpBB/includes/functions_sphinx.php | 507 ++++++++++++ phpBB/includes/search/fulltext_sphinx.php | 1166 ++++++++++++++++++++++++++++ phpBB/includes/sphinxapi-0.9.8.php | 1202 +++++++++++++++++++++++++++++ 3 files changed, 2875 insertions(+) create mode 100644 phpBB/includes/functions_sphinx.php create mode 100644 phpBB/includes/search/fulltext_sphinx.php create mode 100644 phpBB/includes/sphinxapi-0.9.8.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_sphinx.php b/phpBB/includes/functions_sphinx.php new file mode 100644 index 0000000000..976f93f77c --- /dev/null +++ b/phpBB/includes/functions_sphinx.php @@ -0,0 +1,507 @@ +read($filename); + } + } + + /** + * Get a section object by its name + * + * @param string $name The name of the section that shall be returned + * @return sphinx_config_section The section object or null if none was found + */ + function &get_section_by_name($name) + { + for ($i = 0, $n = sizeof($this->sections); $i < $n; $i++) + { + // make sure this is really a section object and not a comment + if (is_a($this->sections[$i], 'sphinx_config_section') && $this->sections[$i]->get_name() == $name) + { + return $this->sections[$i]; + } + } + $null = null; + return $null; + } + + /** + * Appends a new empty section to the end of the config + * + * @param string $name The name for the new section + * @return sphinx_config_section The newly created section object + */ + function &add_section($name) + { + $this->sections[] = new sphinx_config_section($name, ''); + return $this->sections[sizeof($this->sections) - 1]; + } + + /** + * Parses the config file at the given path, which is stored in $this->loaded for later use + * + * @param string $filename The path to the config file + */ + function read($filename) + { + // split the file into lines, we'll process it line by line + $config_file = file($filename); + + $this->sections = array(); + + $section = null; + $found_opening_bracket = false; + $in_value = false; + + foreach ($config_file as $i => $line) + { + // if the value of a variable continues to the next line because the line break was escaped + // then we don't trim leading space but treat it as a part of the value + if ($in_value) + { + $line = rtrim($line); + } + else + { + $line = trim($line); + } + + // if we're not inside a section look for one + if (!$section) + { + // add empty lines and comments as comment objects to the section list + // that way they're not deleted when reassembling the file from the sections + if (!$line || $line[0] == '#') + { + $this->sections[] = new sphinx_config_comment($config_file[$i]); + continue; + } + else + { + // otherwise we scan the line reading the section name until we find + // an opening curly bracket or a comment + $section_name = ''; + $section_name_comment = ''; + $found_opening_bracket = false; + for ($j = 0, $n = strlen($line); $j < $n; $j++) + { + if ($line[$j] == '#') + { + $section_name_comment = substr($line, $j); + break; + } + + if ($found_opening_bracket) + { + continue; + } + + if ($line[$j] == '{') + { + $found_opening_bracket = true; + continue; + } + + $section_name .= $line[$j]; + } + + // and then we create the new section object + $section_name = trim($section_name); + $section = new sphinx_config_section($section_name, $section_name_comment); + } + } + else // if we're looking for variables inside a section + { + $skip_first = false; + + // if we're not in a value continuing over the line feed + if (!$in_value) + { + // then add empty lines and comments as comment objects to the variable list + // of this section so they're not deleted on reassembly + if (!$line || $line[0] == '#') + { + $section->add_variable(new sphinx_config_comment($config_file[$i])); + continue; + } + + // as long as we haven't yet actually found an opening bracket for this section + // we treat everything as comments so it's not deleted either + if (!$found_opening_bracket) + { + if ($line[0] == '{') + { + $skip_first = true; + $line = substr($line, 1); + $found_opening_bracket = true; + } + else + { + $section->add_variable(new sphinx_config_comment($config_file[$i])); + continue; + } + } + } + + // if we did not find a comment in this line or still add to the previous line's value ... + if ($line || $in_value) + { + if (!$in_value) + { + $name = ''; + $value = ''; + $comment = ''; + $found_assignment = false; + } + $in_value = false; + $end_section = false; + + // ... then we should prase this line char by char: + // - first there's the variable name + // - then an equal sign + // - the variable value + // - possibly a backslash before the linefeed in this case we need to continue + // parsing the value in the next line + // - a # indicating that the rest of the line is a comment + // - a closing curly bracket indicating the end of this section + for ($j = 0, $n = strlen($line); $j < $n; $j++) + { + if ($line[$j] == '#') + { + $comment = substr($line, $j); + break; + } + else if ($line[$j] == '}') + { + $comment = substr($line, $j + 1); + $end_section = true; + break; + } + else if (!$found_assignment) + { + if ($line[$j] == '=') + { + $found_assignment = true; + } + else + { + $name .= $line[$j]; + } + } + else + { + if ($line[$j] == '\\' && $j == $n - 1) + { + $value .= "\n"; + $in_value = true; + continue 2; // go to the next line and keep processing the value in there + } + $value .= $line[$j]; + } + } + + // if a name and an equal sign were found then we have append a new variable object to the section + if ($name && $found_assignment) + { + $section->add_variable(new sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); + continue; + } + + // if we found a closing curly bracket this section has been completed and we can append it to the section list + // and continue with looking for the next section + if ($end_section) + { + $section->set_end_comment($comment); + $this->sections[] = $section; + $section = null; + continue; + } + } + + // if we did not find anything meaningful up to here, then just treat it as a comment + $comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i]; + $section->add_variable(new sphinx_config_comment($comment)); + } + } + + // keep the filename for later use + $this->loaded = $filename; + } + + /** + * Writes the config data into a file + * + * @param string $filename The optional filename into which the config data shall be written. + * If it's not specified it will be written into the file that the config + * was originally read from. + */ + function write($filename = false) + { + if ($filename === false && $this->loaded) + { + $filename = $this->loaded; + } + + $data = ""; + foreach ($this->sections as $section) + { + $data .= $section->to_string(); + } + + $fp = fopen($filename, 'wb'); + fwrite($fp, $data); + fclose($fp); + } +} + +/** +* sphinx_config_section +* Represents a single section inside the sphinx configuration +*/ +class sphinx_config_section +{ + var $name; + var $comment; + var $end_comment; + var $variables = array(); + + /** + * Construct a new section + * + * @param string $name Name of the section + * @param string $comment Comment that should be appended after the name in the + * textual format. + */ + function sphinx_config_section($name, $comment) + { + $this->name = $name; + $this->comment = $comment; + $this->end_comment = ''; + } + + /** + * Add a variable object to the list of variables in this section + * + * @param sphinx_config_variable $variable The variable object + */ + function add_variable($variable) + { + $this->variables[] = $variable; + } + + /** + * Adds a comment after the closing bracket in the textual representation + */ + function set_end_comment($end_comment) + { + $this->end_comment = $end_comment; + } + + /** + * Getter for the name of this section + * + * @return string Section's name + */ + function get_name() + { + return $this->name; + } + + /** + * Get a variable object by its name + * + * @param string $name The name of the variable that shall be returned + * @return sphinx_config_section The first variable object from this section with the + * given name or null if none was found + */ + function &get_variable_by_name($name) + { + for ($i = 0, $n = sizeof($this->variables); $i < $n; $i++) + { + // make sure this is a variable object and not a comment + if (is_a($this->variables[$i], 'sphinx_config_variable') && $this->variables[$i]->get_name() == $name) + { + return $this->variables[$i]; + } + } + $null = null; + return $null; + } + + /** + * Deletes all variables with the given name + * + * @param string $name The name of the variable objects that are supposed to be removed + */ + function delete_variables_by_name($name) + { + for ($i = 0; $i < sizeof($this->variables); $i++) + { + // make sure this is a variable object and not a comment + if (is_a($this->variables[$i], 'sphinx_config_variable') && $this->variables[$i]->get_name() == $name) + { + array_splice($this->variables, $i, 1); + $i--; + } + } + } + + /** + * Create a new variable object and append it to the variable list of this section + * + * @param string $name The name for the new variable + * @param string $value The value for the new variable + * @return sphinx_config_variable Variable object that was created + */ + function &create_variable($name, $value) + { + $this->variables[] = new sphinx_config_variable($name, $value, ''); + return $this->variables[sizeof($this->variables) - 1]; + } + + /** + * Turns this object into a string which can be written to a config file + * + * @return string Config data in textual form, parsable for sphinx + */ + function to_string() + { + $content = $this->name . " " . $this->comment . "\n{\n"; + + // make sure we don't get too many newlines after the opening bracket + while (trim($this->variables[0]->to_string()) == "") + { + array_shift($this->variables); + } + + foreach ($this->variables as $variable) + { + $content .= $variable->to_string(); + } + $content .= '}' . $this->end_comment . "\n"; + + return $content; + } +} + +/** +* sphinx_config_variable +* Represents a single variable inside the sphinx configuration +*/ +class sphinx_config_variable +{ + var $name; + var $value; + var $comment; + + /** + * Constructs a new variable object + * + * @param string $name Name of the variable + * @param string $value Value of the variable + * @param string $comment Optional comment after the variable in the + * config file + */ + function sphinx_config_variable($name, $value, $comment) + { + $this->name = $name; + $this->value = $value; + $this->comment = $comment; + } + + /** + * Getter for the variable's name + * + * @return string The variable object's name + */ + function get_name() + { + return $this->name; + } + + /** + * Allows changing the variable's value + * + * @param string $value New value for this variable + */ + function set_value($value) + { + $this->value = $value; + } + + /** + * Turns this object into a string readable by sphinx + * + * @return string Config data in textual form + */ + function to_string() + { + return "\t" . $this->name . ' = ' . str_replace("\n", "\\\n", $this->value) . ' ' . $this->comment . "\n"; + } +} + + +/** +* sphinx_config_comment +* Represents a comment inside the sphinx configuration +*/ +class sphinx_config_comment +{ + var $exact_string; + + /** + * Create a new comment + * + * @param string $exact_string The content of the comment including newlines, leading whitespace, etc. + */ + function sphinx_config_comment($exact_string) + { + $this->exact_string = $exact_string; + } + + /** + * Simply returns the comment as it was created + * + * @return string The exact string that was specified in the constructor + */ + function to_string() + { + return $this->exact_string; + } +} + +?> \ No newline at end of file diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php new file mode 100644 index 0000000000..e0c467df93 --- /dev/null +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -0,0 +1,1166 @@ +id = $config['avatar_salt']; + $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; + + $this->sphinx = new SphinxClient (); + + if (!empty($config['fulltext_sphinx_configured'])) + { + if ($config['fulltext_sphinx_autorun'] && !file_exists($config['fulltext_sphinx_data_path'] . 'searchd.pid') && $this->index_created(true)) + { + $this->shutdown_searchd(); +// $cwd = getcwd(); +// chdir($config['fulltext_sphinx_bin_path']); + exec($config['fulltext_sphinx_bin_path'] . SEARCHD_NAME . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf >> ' . $config['fulltext_sphinx_data_path'] . 'log/searchd-startup.log 2>&1 &'); +// chdir($cwd); + } + + // we only support localhost for now + $this->sphinx->SetServer('localhost', (isset($config['fulltext_sphinx_port']) && $config['fulltext_sphinx_port']) ? (int) $config['fulltext_sphinx_port'] : 3312); + } + + $config['fulltext_sphinx_min_word_len'] = 2; + $config['fulltext_sphinx_max_word_len'] = 400; + + $error = false; + } + + /** + * Checks permissions and paths, if everything is correct it generates the config file + */ + function init() + { + global $db, $user, $config; + + if ($db->sql_layer != 'mysql' && $db->sql_layer != 'mysql4' && $db->sql_layer != 'mysqli') + { + return $user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; + } + + if ($error = $this->config_updated()) + { + return $error; + } + + // move delta to main index each hour + set_config('search_gc', 3600); + + return false; + } + + function config_updated() + { + global $db, $user, $config, $phpbb_root_path, $phpEx; + + if ($config['fulltext_sphinx_autoconf']) + { + $paths = array('fulltext_sphinx_bin_path', 'fulltext_sphinx_config_path', 'fulltext_sphinx_data_path'); + + // check for completeness and add trailing slash if it's not present + foreach ($paths as $path) + { + if (empty($config[$path])) + { + return $user->lang['FULLTEXT_SPHINX_UNCONFIGURED']; + } + if ($config[$path] && substr($config[$path], -1) != '/') + { + set_config($path, $config[$path] . '/'); + } + } + } + + $executables = array( + $config['fulltext_sphinx_bin_path'] . INDEXER_NAME, + $config['fulltext_sphinx_bin_path'] . SEARCHD_NAME, + ); + + if ($config['fulltext_sphinx_autorun']) + { + foreach ($executables as $executable) + { + if (!file_exists($executable)) + { + return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_FOUND'], $executable); + } + + if (!function_exists('exec')) + { + return $user->lang['FULLTEXT_SPHINX_REQUIRES_EXEC']; + } + + $output = array(); + @exec($executable, $output); + + $output = implode("\n", $output); + if (strpos($output, 'Sphinx ') === false) + { + return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_EXECUTABLE'], $executable); + } + } + } + + $writable_paths = array( + $config['fulltext_sphinx_config_path'] => array('config' => 'fulltext_sphinx_autoconf', 'subdir' => false), + $config['fulltext_sphinx_data_path'] => array('config' => 'fulltext_sphinx_autorun', 'subdir' => 'log'), + $config['fulltext_sphinx_data_path'] . 'log/' => array('config' => 'fulltext_sphinx_autorun', 'subdir' => false), + ); + + foreach ($writable_paths as $path => $info) + { + if ($config[$info['config']]) + { + // make sure directory exists + // if we could drop the @ here and figure out whether the file really + // doesn't exist or whether open_basedir is in effect, would be nice + if (!@file_exists($path)) + { + return sprintf($user->lang['FULLTEXT_SPHINX_DIRECTORY_NOT_FOUND'], $path); + } + + // now check if it is writable by storing a simple file + $filename = $path . 'write_test'; + $fp = @fopen($filename, 'wb'); + if ($fp === false) + { + return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_WRITABLE'], $filename); + } + @fclose($fp); + + @unlink($filename); + + if ($info['subdir'] !== false) + { + if (!is_dir($path . $info['subdir'])) + { + mkdir($path . $info['subdir']); + } + } + } + } + + if ($config['fulltext_sphinx_autoconf']) + { + include ($phpbb_root_path . 'config.' . $phpEx); + + // now that we're sure everything was entered correctly, generate a config for the index + // we misuse the avatar_salt for this, as it should be unique ;-) + + if (!class_exists('sphinx_config')) + { + include($phpbb_root_path . 'includes/functions_sphinx.php'); + } + + if (!file_exists($config['fulltext_sphinx_config_path'] . 'sphinx.conf')) + { + $filename = $config['fulltext_sphinx_config_path'] . 'sphinx.conf'; + $fp = @fopen($filename, 'wb'); + if ($fp === false) + { + return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_WRITABLE'], $filename); + } + @fclose($fp); + } + + $config_object = new sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); + + $config_data = array( + "source source_phpbb_{$this->id}_main" => array( + array('type', 'mysql'), + array('sql_host', $dbhost), + array('sql_user', $dbuser), + array('sql_pass', $dbpasswd), + array('sql_db', $dbname), + array('sql_port', $dbport), + array('sql_query_pre', 'SET NAMES utf8'), + array('sql_query_pre', 'REPLACE INTO ' . SPHINX_TABLE . ' SELECT 1, MAX(post_id) FROM ' . POSTS_TABLE . ''), + array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), + array('sql_range_step', '5000'), + array('sql_query', 'SELECT + p.post_id AS id, + p.forum_id, + p.topic_id, + p.poster_id, + IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, + p.post_time, + p.post_subject, + p.post_subject as title, + p.post_text as data, + t.topic_last_post_time, + 0 as deleted + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t + WHERE + p.topic_id = t.topic_id + AND p.post_id >= $start AND p.post_id <= $end'), + array('sql_query_post', ''), + array('sql_query_post_index', 'REPLACE INTO ' . SPHINX_TABLE . ' ( counter_id, max_doc_id ) VALUES ( 1, $maxid )'), + array('sql_query_info', 'SELECT * FROM ' . POSTS_TABLE . ' WHERE post_id = $id'), + array('sql_attr_uint', 'forum_id'), + array('sql_attr_uint', 'topic_id'), + array('sql_attr_uint', 'poster_id'), + array('sql_attr_bool', 'topic_first_post'), + array('sql_attr_bool', 'deleted'), + array('sql_attr_timestamp' , 'post_time'), + array('sql_attr_timestamp' , 'topic_last_post_time'), + array('sql_attr_str2ordinal', 'post_subject'), + ), + "source source_phpbb_{$this->id}_delta : source_phpbb_{$this->id}_main" => array( + array('sql_query_pre', ''), + array('sql_query_range', ''), + array('sql_range_step', ''), + array('sql_query', 'SELECT + p.post_id AS id, + p.forum_id, + p.topic_id, + p.poster_id, + IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, + p.post_time, + p.post_subject, + p.post_subject as title, + p.post_text as data, + t.topic_last_post_time, + 0 as deleted + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t + WHERE + p.topic_id = t.topic_id + AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'), + ), + "index index_phpbb_{$this->id}_main" => array( + array('path', $config['fulltext_sphinx_data_path'] . "index_phpbb_{$this->id}_main"), + array('source', "source_phpbb_{$this->id}_main"), + array('docinfo', 'extern'), + array('morphology', 'none'), + array('stopwords', (file_exists($config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt') && $config['fulltext_sphinx_stopwords']) ? $config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), + array('min_word_len', '2'), + array('charset_type', 'utf-8'), + array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+ß410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), + array('min_prefix_len', '0'), + array('min_infix_len', '0'), + ), + "index index_phpbb_{$this->id}_delta : index_phpbb_{$this->id}_main" => array( + array('path', $config['fulltext_sphinx_data_path'] . "index_phpbb_{$this->id}_delta"), + array('source', "source_phpbb_{$this->id}_delta"), + ), + 'indexer' => array( + array('mem_limit', $config['fulltext_sphinx_indexer_mem_limit'] . 'M'), + ), + 'searchd' => array( + array('address' , '127.0.0.1'), + array('port', ($config['fulltext_sphinx_port']) ? $config['fulltext_sphinx_port'] : '3312'), + array('log', $config['fulltext_sphinx_data_path'] . "log/searchd.log"), + array('query_log', $config['fulltext_sphinx_data_path'] . "log/sphinx-query.log"), + array('read_timeout', '5'), + array('max_children', '30'), + array('pid_file', $config['fulltext_sphinx_data_path'] . "searchd.pid"), + array('max_matches', (string) MAX_MATCHES), + ), + ); + + $non_unique = array('sql_query_pre' => true, 'sql_attr_uint' => true, 'sql_attr_timestamp' => true, 'sql_attr_str2ordinal' => true, 'sql_attr_bool' => true); + $delete = array('sql_group_column' => true, 'sql_date_column' => true, 'sql_str2ordinal_column' => true); + + foreach ($config_data as $section_name => $section_data) + { + $section = &$config_object->get_section_by_name($section_name); + if (!$section) + { + $section = &$config_object->add_section($section_name); + } + + foreach ($delete as $key => $void) + { + $section->delete_variables_by_name($key); + } + + foreach ($non_unique as $key => $void) + { + $section->delete_variables_by_name($key); + } + + foreach ($section_data as $entry) + { + $key = $entry[0]; + $value = $entry[1]; + + if (!isset($non_unique[$key])) + { + $variable = &$section->get_variable_by_name($key); + if (!$variable) + { + $variable = &$section->create_variable($key, $value); + } + else + { + $variable->set_value($value); + } + } + else + { + $variable = &$section->create_variable($key, $value); + } + } + } + + $config_object->write($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); + } + + set_config('fulltext_sphinx_configured', '1'); + + $this->shutdown_searchd(); + $this->tidy(); + + return false; + } + + /** + * Splits keywords entered by a user into an array of words stored in $this->split_words + * Stores the tidied search query in $this->search_query + * + * @param string $keywords Contains the keyword as entered by the user + * @param string $terms is either 'all' or 'any' + * @return false if no valid keywords were found and otherwise true + */ + function split_keywords(&$keywords, $terms) + { + global $config; + + if ($terms == 'all') + { + $match = array('#\sand\s#i', '#\sor\s#i', '#\snot\s#i', '#\+#', '#-#', '#\|#', '#@#'); + $replace = array(' & ', ' | ', ' - ', ' +', ' -', ' |', ''); + + $replacements = 0; + $keywords = preg_replace($match, $replace, $keywords); + $this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED); + } + else + { + $this->sphinx->SetMatchMode(SPH_MATCH_ANY); + } + + $match = array(); + // Keep quotes + $match[] = "#"#"; + // KeepNew lines + $match[] = "#[\n]+#"; + + $replace = array('"', " "); + + $keywords = str_replace(array('"', "\n"), array('"', ' '), trim($keywords)); + + if (strlen($keywords) > 0) + { + $this->search_query = str_replace('"', '"', $keywords); + return true; + } + + return false; + } + + /** + * Performs a search on keywords depending on display specific params. You have to run split_keywords() first. + * + * @param string $type contains either posts or topics depending on what should be searched for + * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched) + * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words) + * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query + * @param string $sort_key is the key of $sort_by_sql for the selected sorting + * @param string $sort_dir is either a or d representing ASC and DESC + * @param string $sort_days specifies the maximum amount of days a post may be old + * @param array $ex_fid_ary specifies an array of forum ids which should not be searched + * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched + * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty + * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match + * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered + * @param int $start indicates the first index of the page + * @param int $per_page number of ids each page is supposed to contain + * @return boolean|int total number of results + * + * @access public + */ + function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + { + global $config, $db, $auth; + + // No keywords? No posts. + if (!strlen($this->search_query) && !sizeof($author_ary)) + { + return false; + } + + $id_ary = array(); + + $join_topic = ($type == 'posts') ? false : true; + + // sorting + + if ($type == 'topics') + { + switch ($sort_key) + { + case 'a': + $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'poster_id ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); + break; + case 'f': + $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'forum_id ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); + break; + case 'i': + case 's': + $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'post_subject ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); + break; + case 't': + default: + $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'topic_last_post_time ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); + break; + } + } + else + { + switch ($sort_key) + { + case 'a': + $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'poster_id'); + break; + case 'f': + $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'forum_id'); + break; + case 'i': + case 's': + $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_subject'); + break; + case 't': + default: + $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_time'); + break; + } + } + + // most narrow filters first + if ($topic_id) + { + $this->sphinx->SetFilter('topic_id', array($topic_id)); + } + + $search_query_prefix = ''; + + switch($fields) + { + case 'titleonly': + // only search the title + if ($terms == 'all') + { + $search_query_prefix = '@title '; + } + $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); // weight for the title + $this->sphinx->SetFilter('topic_first_post', array(1)); // 1 is first_post, 0 is not first post + break; + + case 'msgonly': + // only search the body + if ($terms == 'all') + { + $search_query_prefix = '@data '; + } + $this->sphinx->SetFieldWeights(array("title" => 1, "data" => 5)); // weight for the body + break; + + case 'firstpost': + $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); // more relative weight for the title, also search the body + $this->sphinx->SetFilter('topic_first_post', array(1)); // 1 is first_post, 0 is not first post + break; + + default: + $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); // more relative weight for the title, also search the body + break; + } + + if (sizeof($author_ary)) + { + $this->sphinx->SetFilter('poster_id', $author_ary); + } + + if (sizeof($ex_fid_ary)) + { + // All forums that a user is allowed to access + $fid_ary = array_unique(array_intersect(array_keys($auth->acl_getf('f_read', true)), array_keys($auth->acl_getf('f_search', true)))); + // All forums that the user wants to and can search in + $search_forums = array_diff($fid_ary, $ex_fid_ary); + + if (sizeof($search_forums)) + { + $this->sphinx->SetFilter('forum_id', $search_forums); + } + } + + $this->sphinx->SetFilter('deleted', array(0)); + + $this->sphinx->SetLimits($start, (int) $per_page, MAX_MATCHES); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + + // could be connection to localhost:3312 failed (errno=111, msg=Connection refused) during rotate, retry if so + $retries = CONNECT_RETRIES; + while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--) + { + usleep(CONNECT_WAIT_TIME); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + } + + $id_ary = array(); + if (isset($result['matches'])) + { + if ($type == 'posts') + { + $id_ary = array_keys($result['matches']); + } + else + { + foreach($result['matches'] as $key => $value) + { + $id_ary[] = $value['attrs']['topic_id']; + } + } + } + else + { + return false; + } + + $result_count = $result['total_found']; + + $id_ary = array_slice($id_ary, 0, (int) $per_page); + + return $result_count; + } + + /** + * Performs a search on an author's posts without caring about message contents. Depends on display specific params + * + * @param string $type contains either posts or topics depending on what should be searched for + * @param boolean $firstpost_only if true, only topic starting posts will be considered + * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query + * @param string $sort_key is the key of $sort_by_sql for the selected sorting + * @param string $sort_dir is either a or d representing ASC and DESC + * @param string $sort_days specifies the maximum amount of days a post may be old + * @param array $ex_fid_ary specifies an array of forum ids which should not be searched + * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts + * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched + * @param array $author_ary an array of author ids + * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match + * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered + * @param int $start indicates the first index of the page + * @param int $per_page number of ids each page is supposed to contain + * @return boolean|int total number of results + * + * @access public + */ + function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + { + $this->search_query = ''; + + $this->sphinx->SetMatchMode(SPH_MATCH_FULLSCAN); + $fields = ($firstpost_only) ? 'firstpost' : 'all'; + $terms = 'all'; + return $this->keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, $id_ary, $start, $per_page); + } + + /** + * Updates wordlist and wordmatch tables when a message is posted or changed + * + * @param string $mode Contains the post mode: edit, post, reply, quote + * @param int $post_id The id of the post which is modified/created + * @param string &$message New or updated post content + * @param string &$subject New or updated post subject + * @param int $poster_id Post author's user id + * @param int $forum_id The id of the forum in which the post is located + * + * @access public + */ + function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + { + global $config, $db; + + if ($mode == 'edit') + { + $this->sphinx->UpdateAttributes($this->indexes, array('forum_id', 'poster_id'), array((int)$post_id => array((int)$forum_id, (int)$poster_id))); + } + else if ($mode != 'post' && $post_id) + { + // update topic_last_post_time for full topic + $sql = 'SELECT p1.post_id + FROM ' . POSTS_TABLE . ' p1 + LEFT JOIN ' . POSTS_TABLE . ' p2 ON (p1.topic_id = p2.topic_id) + WHERE p2.post_id = ' . $post_id; + $result = $db->sql_query($sql); + + $post_updates = array(); + $post_time = time(); + while ($row = $db->sql_fetchrow($result)) + { + $post_updates[(int)$row['post_id']] = array((int) $post_time); + } + $db->sql_freeresult($result); + + if (sizeof($post_updates)) + { + $this->sphinx->UpdateAttributes($this->indexes, array('topic_last_post_time'), $post_updates); + } + } + + if ($config['fulltext_sphinx_autorun']) + { + if ($this->index_created()) + { + $rotate = ($this->searchd_running()) ? ' --rotate' : ''; + + $cwd = getcwd(); + chdir($config['fulltext_sphinx_bin_path']); + exec('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_delta >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); + var_dump('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_delta >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); + chdir($cwd); + } + } + } + + /** + * Delete a post from the index after it was deleted + */ + function index_remove($post_ids, $author_ids, $forum_ids) + { + $values = array(); + foreach ($post_ids as $post_id) + { + $values[$post_id] = array(1); + } + + $this->sphinx->UpdateAttributes($this->indexes, array('deleted'), $values); + } + + /** + * Destroy old cache entries + */ + function tidy($create = false) + { + global $config; + + if ($config['fulltext_sphinx_autorun']) + { + if ($this->index_created() || $create) + { + $rotate = ($this->searchd_running()) ? ' --rotate' : ''; + + $cwd = getcwd(); + chdir($config['fulltext_sphinx_bin_path']); + exec('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_main >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); + exec('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_delta >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); + chdir($cwd); + } + } + + set_config('search_last_gc', time(), true); + } + + /** + * Create sphinx table + */ + function create_index($acp_module, $u_action) + { + global $db, $user, $config; + + $this->shutdown_searchd(); + + if (!isset($config['fulltext_sphinx_configured']) || !$config['fulltext_sphinx_configured']) + { + $user->add_lang('mods/fulltext_sphinx'); + + return $user->lang['FULLTEXT_SPHINX_CONFIGURE_FIRST']; + } + + if (!$this->index_created()) + { + $sql = 'CREATE TABLE IF NOT EXISTS ' . SPHINX_TABLE . ' ( + counter_id INT NOT NULL PRIMARY KEY, + max_doc_id INT NOT NULL + )'; + $db->sql_query($sql); + + $sql = 'TRUNCATE TABLE ' . SPHINX_TABLE; + $db->sql_query($sql); + } + + // start indexing process + $this->tidy(true); + + $this->shutdown_searchd(); + + return false; + } + + /** + * Drop sphinx table + */ + function delete_index($acp_module, $u_action) + { + global $db, $config; + + $this->shutdown_searchd(); + + if ($config['fulltext_sphinx_autorun']) + { + sphinx_unlink_by_pattern($config['fulltext_sphinx_data_path'], '#^index_phpbb_' . $this->id . '.*$#'); + } + + if (!$this->index_created()) + { + return false; + } + + $sql = 'DROP TABLE ' . SPHINX_TABLE; + $db->sql_query($sql); + + $this->shutdown_searchd(); + + return false; + } + + /** + * Returns true if the sphinx table was created + */ + function index_created($allow_new_files = true) + { + global $db, $config; + + $sql = 'SHOW TABLES LIKE \'' . SPHINX_TABLE . '\''; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $created = false; + + if ($row) + { + if ($config['fulltext_sphinx_autorun']) + { + if ((file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main.spd') && file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta.spd')) || ($allow_new_files && file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main.new.spd') && file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta.new.spd'))) + { + $created = true; + } + } + else + { + $created = true; + } + } + + return $created; + } + + /** + * Kills the searchd process and makes sure there's no locks left over + */ + function shutdown_searchd() + { + global $config; + + if ($config['fulltext_sphinx_autorun']) + { + if (!function_exists('exec')) + { + set_config('fulltext_sphinx_autorun', '0'); + return; + } + + exec('killall -9 ' . SEARCHD_NAME . ' >> /dev/null 2>&1 &'); + + if (file_exists($config['fulltext_sphinx_data_path'] . 'searchd.pid')) + { + unlink($config['fulltext_sphinx_data_path'] . 'searchd.pid'); + } + + sphinx_unlink_by_pattern($config['fulltext_sphinx_data_path'], '#^.*\.spl$#'); + } + } + + /** + * Checks whether searchd is running, if it's not running it makes sure there's no left over + * files by calling shutdown_searchd. + * + * @return boolean Whether searchd is running or not + */ + function searchd_running() + { + global $config; + + // if we cannot manipulate the service assume it is running + if (!$config['fulltext_sphinx_autorun']) + { + return true; + } + + if (file_exists($config['fulltext_sphinx_data_path'] . 'searchd.pid')) + { + $pid = trim(file_get_contents($config['fulltext_sphinx_data_path'] . 'searchd.pid')); + + if ($pid) + { + $output = array(); + $pidof_command = 'pidof'; + + exec('whereis -b pidof', $output); + if (sizeof($output) > 1) + { + $output = explode(' ', trim($output[0])); + $pidof_command = $output[1]; // 0 is pidof: + } + + $output = array(); + exec($pidof_command . ' ' . SEARCHD_NAME, $output); + if (sizeof($output) && (trim($output[0]) == $pid || trim($output[1]) == $pid)) + { + return true; + } + } + } + + // make sure it's really not running + $this->shutdown_searchd(); + + return false; + } + + /** + * Returns an associative array containing information about the indexes + */ + function index_stats() + { + global $user; + + if (empty($this->stats)) + { + $this->get_stats(); + } + + $user->add_lang('mods/fulltext_sphinx'); + + return array( + $user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0, + $user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, + $user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $user->lang['FULLTEXT_SPHINX_LAST_SEARCHES'] => nl2br($this->stats['last_searches']), + ); + } + + /** + * Collects stats that can be displayed on the index maintenance page + */ + function get_stats() + { + global $db, $config; + + if ($this->index_created()) + { + $sql = 'SELECT COUNT(post_id) as total_posts + FROM ' . POSTS_TABLE; + $result = $db->sql_query($sql); + $this->stats['total_posts'] = (int) $db->sql_fetchfield('total_posts'); + $db->sql_freeresult($result); + + $sql = 'SELECT COUNT(p.post_id) as main_posts + FROM ' . POSTS_TABLE . ' p, ' . SPHINX_TABLE . ' m + WHERE p.post_id <= m.max_doc_id + AND m.counter_id = 1'; + $result = $db->sql_query($sql); + $this->stats['main_posts'] = (int) $db->sql_fetchfield('main_posts'); + $db->sql_freeresult($result); + } + + $this->stats['last_searches'] = ''; + if ($config['fulltext_sphinx_autorun']) + { + if (file_exists($config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log')) + { + $last_searches = explode("\n", utf8_htmlspecialchars(sphinx_read_last_lines($config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log', 3))); + + foreach($last_searches as $i => $search) + { + if (strpos($search, '[' . $this->indexes . ']') !== false) + { + $last_searches[$i] = str_replace('[' . $this->indexes . ']', '', $search); + } + else + { + $last_searches[$i] = ''; + } + } + $this->stats['last_searches'] = implode("\n", $last_searches); + } + } + } + + /** + * Returns a list of options for the ACP to display + */ + function acp() + { + global $user, $config; + + $user->add_lang('mods/fulltext_sphinx'); + + $config_vars = array( + 'fulltext_sphinx_autoconf' => 'bool', + 'fulltext_sphinx_autorun' => 'bool', + 'fulltext_sphinx_config_path' => 'string', + 'fulltext_sphinx_data_path' => 'string', + 'fulltext_sphinx_bin_path' => 'string', + 'fulltext_sphinx_port' => 'int', + 'fulltext_sphinx_stopwords' => 'bool', + 'fulltext_sphinx_indexer_mem_limit' => 'int', + ); + + $defaults = array( + 'fulltext_sphinx_autoconf' => '1', + 'fulltext_sphinx_autorun' => '1', + 'fulltext_sphinx_indexer_mem_limit' => '512', + ); + + foreach ($config_vars as $config_var => $type) + { + if (!isset($config[$config_var])) + { + $default = ''; + if (isset($defaults[$config_var])) + { + $default = $defaults[$config_var]; + } + set_config($config_var, $default); + } + } + + $no_autoconf = false; + $no_autorun = false; + $bin_path = $config['fulltext_sphinx_bin_path']; + + // try to guess the path if it is empty + if (empty($bin_path)) + { + if (@file_exists('/usr/local/bin/' . INDEXER_NAME) && @file_exists('/usr/local/bin/' . SEARCHD_NAME)) + { + $bin_path = '/usr/local/bin/'; + } + else if (@file_exists('/usr/bin/' . INDEXER_NAME) && @file_exists('/usr/bin/' . SEARCHD_NAME)) + { + $bin_path = '/usr/bin/'; + } + else + { + $output = array(); + if (!function_exists('exec') || null === @exec('whereis -b ' . INDEXER_NAME, $output)) + { + $no_autorun = true; + } + else if (sizeof($output)) + { + $output = explode(' ', $output[0]); + array_shift($output); // remove indexer: + + foreach ($output as $path) + { + $path = dirname($path) . '/'; + + if (file_exists($path . INDEXER_NAME) && file_exists($path . SEARCHD_NAME)) + { + $bin_path = $path; + break; + } + } + } + } + } + + if ($no_autorun) + { + set_config('fulltext_sphinx_autorun', '0'); + } + + if ($no_autoconf) + { + set_config('fulltext_sphinx_autoconf', '0'); + } + + // rewrite config if fulltext sphinx is enabled + if ($config['fulltext_sphinx_autoconf'] && isset($config['fulltext_sphinx_configured']) && $config['fulltext_sphinx_configured']) + { + $this->config_updated(); + } + + // check whether stopwords file is available and enabled + if (@file_exists($config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt')) + { + $stopwords_available = true; + $stopwords_active = $config['fulltext_sphinx_stopwords']; + } + else + { + $stopwords_available = false; + $stopwords_active = false; + set_config('fulltext_sphinx_stopwords', '0'); + } + + $tpl = ' + ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. ' +
+

' . $user->lang['FULLTEXT_SPHINX_AUTOCONF_EXPLAIN'] . '
+
+
+
+

' . $user->lang['FULLTEXT_SPHINX_AUTORUN_EXPLAIN'] . '
+
+
+
+

' . $user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
+
+
+
+

' . $user->lang['FULLTEXT_SPHINX_BIN_PATH_EXPLAIN'] . '
+
+
+
+

' . $user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
+
+
+ ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_AFTER']. ' +
+

' . $user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
+
+
+
+

' . $user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
+
+
+
+

' . $user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN'] . '
+
' . $user->lang['MIB'] . '
+
+ '; + + // These are fields required in the config table + return array( + 'tpl' => $tpl, + 'config' => $config_vars + ); + } +} + +/** +* Deletes all files from a directory that match a certain pattern +* +* @param string $path Path from which files shall be deleted +* @param string $pattern PCRE pattern that a file needs to match in order to be deleted +*/ +function sphinx_unlink_by_pattern($path, $pattern) +{ + $dir = opendir($path); + while (false !== ($file = readdir($dir))) + { + if (is_file($path . $file) && preg_match($pattern, $file)) + { + unlink($path . $file); + } + } + closedir($dir); +} + +/** +* Reads the last from a file +* +* @param string $file The filename from which the lines shall be read +* @param int $amount The number of lines to be read from the end +* @return string Last lines of the file +*/ +function sphinx_read_last_lines($file, $amount) +{ + $fp = fopen($file, 'r'); + fseek($fp, 0, SEEK_END); + + $c = ''; + $i = 0; + + while ($i < $amount) + { + fseek($fp, -2, SEEK_CUR); + $c = fgetc($fp); + if ($c == "\n") + { + $i++; + } + if (feof($fp)) + { + break; + } + } + + $string = fread($fp, 8192); + fclose($fp); + + return $string; +} + +?> \ No newline at end of file diff --git a/phpBB/includes/sphinxapi-0.9.8.php b/phpBB/includes/sphinxapi-0.9.8.php new file mode 100644 index 0000000000..6a7ea17760 --- /dev/null +++ b/phpBB/includes/sphinxapi-0.9.8.php @@ -0,0 +1,1202 @@ +=8 ) + { + $i = (int)$v; + return pack ( "NN", $i>>32, $i&((1<<32)-1) ); + } + + // x32 route, bcmath + $x = "4294967296"; + if ( function_exists("bcmul") ) + { + $h = bcdiv ( $v, $x, 0 ); + $l = bcmod ( $v, $x ); + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit + } + + // x32 route, 15 or less decimal digits + // we can use float, because its actually double and has 52 precision bits + if ( strlen($v)<=15 ) + { + $f = (float)$v; + $h = (int)($f/$x); + $l = (int)($f-$x*$h); + return pack ( "NN", $h, $l ); + } + + // x32 route, 16 or more decimal digits + // well, let me know if you *really* need this + die ( "INTERNAL ERROR: packing more than 15-digit numeric on 32-bit PHP is not implemented yet (contact support)" ); +} + + +/// portably unpack 64 unsigned bits, network order to numeric +function sphUnpack64 ( $v ) +{ + list($h,$l) = array_values ( unpack ( "N*N*", $v ) ); + + // x64 route + if ( PHP_INT_SIZE>=8 ) + { + if ( $h<0 ) $h += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again + if ( $l<0 ) $l += (1<<32); + return ($h<<32) + $l; + } + + // x32 route + $h = sprintf ( "%u", $h ); + $l = sprintf ( "%u", $l ); + $x = "4294967296"; + + // bcmath + if ( function_exists("bcmul") ) + return bcadd ( $l, bcmul ( $x, $h ) ); + + // no bcmath, 15 or less decimal digits + // we can use float, because its actually double and has 52 precision bits + if ( $h<1048576 ) + { + $f = ((float)$h)*$x + (float)$l; + return sprintf ( "%.0f", $f ); // builtin conversion is only about 39-40 bits precise! + } + + // x32 route, 16 or more decimal digits + // well, let me know if you *really* need this + die ( "INTERNAL ERROR: unpacking more than 15-digit numeric on 32-bit PHP is not implemented yet (contact support)" ); +} + + +/// sphinx searchd client class +class SphinxClient +{ + var $_host; ///< searchd host (default is "localhost") + var $_port; ///< searchd port (default is 3312) + var $_offset; ///< how many records to seek from result-set start (default is 0) + var $_limit; ///< how many records to return from result-set starting at offset (default is 20) + var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) + var $_weights; ///< per-field weights (default is 1 for all fields) + var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) + var $_sortby; ///< attribute to sort by (defualt is "") + var $_min_id; ///< min ID to match (default is 0, which means no limit) + var $_max_id; ///< max ID to match (default is 0, which means no limit) + var $_filters; ///< search filters + var $_groupby; ///< group-by attribute name + var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) + var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) + var $_groupdistinct;///< group-by count-distinct attribute + var $_maxmatches; ///< max matches to retrieve + var $_cutoff; ///< cutoff to stop searching at (default is 0) + var $_retrycount; ///< distributed retries count + var $_retrydelay; ///< distributed retries delay + var $_anchor; ///< geographical anchor point + var $_indexweights; ///< per-index weights + var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) + var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) + var $_fieldweights; ///< per-field-name weights + + var $_error; ///< last error message + var $_warning; ///< last warning message + + var $_reqs; ///< requests array for multi-query + var $_mbenc; ///< stored mbstring encoding + var $_arrayresult; ///< whether $result["matches"] should be a hash or an array + var $_timeout; ///< connect timeout + + ///////////////////////////////////////////////////////////////////////////// + // common stuff + ///////////////////////////////////////////////////////////////////////////// + + /// create a new client object and fill defaults + function SphinxClient () + { + // per-client-object settings + $this->_host = "localhost"; + $this->_port = 3312; + + // per-query settings + $this->_offset = 0; + $this->_limit = 20; + $this->_mode = SPH_MATCH_ALL; + $this->_weights = array (); + $this->_sort = SPH_SORT_RELEVANCE; + $this->_sortby = ""; + $this->_min_id = 0; + $this->_max_id = 0; + $this->_filters = array (); + $this->_groupby = ""; + $this->_groupfunc = SPH_GROUPBY_DAY; + $this->_groupsort = "@group desc"; + $this->_groupdistinct= ""; + $this->_maxmatches = 1000; + $this->_cutoff = 0; + $this->_retrycount = 0; + $this->_retrydelay = 0; + $this->_anchor = array (); + $this->_indexweights= array (); + $this->_ranker = SPH_RANK_PROXIMITY_BM25; + $this->_maxquerytime= 0; + $this->_fieldweights= array(); + + $this->_error = ""; // per-reply fields (for single-query case) + $this->_warning = ""; + $this->_reqs = array (); // requests storage (for multi-query case) + $this->_mbenc = ""; + $this->_arrayresult = false; + $this->_timeout = 0; + } + + /// get last error message (string) + function GetLastError () + { + return $this->_error; + } + + /// get last warning message (string) + function GetLastWarning () + { + return $this->_warning; + } + + /// set searchd host name (string) and port (integer) + function SetServer ( $host, $port ) + { + assert ( is_string($host) ); + assert ( is_int($port) ); + $this->_host = $host; + $this->_port = $port; + } + + /// set server connection timeout (0 to remove) + function SetConnectTimeout ( $timeout ) + { + assert ( is_numeric($timeout) ); + $this->_timeout = $timeout; + } + + ///////////////////////////////////////////////////////////////////////////// + + /// enter mbstring workaround mode + function _MBPush () + { + $this->_mbenc = ""; + if ( ini_get ( "mbstring.func_overload" ) & 2 ) + { + $this->_mbenc = mb_internal_encoding(); + mb_internal_encoding ( "latin1" ); + } + } + + /// leave mbstring workaround mode + function _MBPop () + { + if ( $this->_mbenc ) + mb_internal_encoding ( $this->_mbenc ); + } + + /// connect to searchd server + function _Connect ($allow_retry = true) + { + $errno = 0; + $errstr = ""; + if ( $this->_timeout<=0 ) + $fp = @fsockopen ( $this->_host, $this->_port, $errno, $errstr ); + else + $fp = @fsockopen ( $this->_host, $this->_port, $errno, $errstr, $this->_timeout ); + + if ( !$fp ) + { + $errstr = trim ( $errstr ); + $this->_error = "connection to {$this->_host}:{$this->_port} failed (errno=$errno, msg=$errstr)"; + return false; + } + + // check version + //list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); + $version_data = unpack ( "N*", fread ( $fp, 4 ) ); + if (!isset($version_data[1])) + { + // this should not happen, try to reconnect ONCE + if ($allow_retry) + { + return $this->_Connect(false); + } + else + { + $this->_error = "unexpected version data"; + return false; + } + } + $v = $version_data[1]; + $v = (int)$v; + if ( $v<1 ) + { + fclose ( $fp ); + $this->_error = "expected searchd protocol version 1+, got version '$v'"; + return false; + } + + // all ok, send my version + fwrite ( $fp, pack ( "N", 1 ) ); + return $fp; + } + + /// get and check response packet from searchd server + function _GetResponse ( $fp, $client_ver ) + { + $response = ""; + $len = 0; + + $header = fread ( $fp, 8 ); + if ( strlen($header)==8 ) + { + list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); + $left = $len; + while ( $left>0 && !feof($fp) ) + { + $chunk = fread ( $fp, $left ); + if ( $chunk ) + { + $response .= $chunk; + $left -= strlen($chunk); + } + } + } + fclose ( $fp ); + + // check response + $read = strlen ( $response ); + if ( !$response || $read!=$len ) + { + $this->_error = $len + ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" + : "received zero-sized searchd response"; + return false; + } + + // check status + if ( $status==SEARCHD_WARNING ) + { + list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); + $this->_warning = substr ( $response, 4, $wlen ); + return substr ( $response, 4+$wlen ); + } + if ( $status==SEARCHD_ERROR ) + { + $this->_error = "searchd error: " . substr ( $response, 4 ); + return false; + } + if ( $status==SEARCHD_RETRY ) + { + $this->_error = "temporary searchd error: " . substr ( $response, 4 ); + return false; + } + if ( $status!=SEARCHD_OK ) + { + $this->_error = "unknown status code '$status'"; + return false; + } + + // check version + if ( $ver<$client_ver ) + { + $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", + $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); + } + + return $response; + } + + ///////////////////////////////////////////////////////////////////////////// + // searching + ///////////////////////////////////////////////////////////////////////////// + + /// set offset and count into result set, + /// and optionally set max-matches and cutoff limits + function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) + { + assert ( is_int($offset) ); + assert ( is_int($limit) ); + assert ( $offset>=0 ); + assert ( $limit>0 ); + assert ( $max>=0 ); + $this->_offset = $offset; + $this->_limit = $limit; + if ( $max>0 ) + $this->_maxmatches = $max; + if ( $cutoff>0 ) + $this->_cutoff = $cutoff; + } + + /// set maximum query time, in milliseconds, per-index + /// integer, 0 means "do not limit" + function SetMaxQueryTime ( $max ) + { + assert ( is_int($max) ); + assert ( $max>=0 ); + $this->_maxquerytime = $max; + } + + /// set matching mode + function SetMatchMode ( $mode ) + { + assert ( $mode==SPH_MATCH_ALL + || $mode==SPH_MATCH_ANY + || $mode==SPH_MATCH_PHRASE + || $mode==SPH_MATCH_BOOLEAN + || $mode==SPH_MATCH_EXTENDED + || $mode==SPH_MATCH_FULLSCAN + || $mode==SPH_MATCH_EXTENDED2 ); + $this->_mode = $mode; + } + + /// set ranking mode + function SetRankingMode ( $ranker ) + { + assert ( $ranker==SPH_RANK_PROXIMITY_BM25 + || $ranker==SPH_RANK_BM25 + || $ranker==SPH_RANK_NONE + || $ranker==SPH_RANK_WORDCOUNT ); + $this->_ranker = $ranker; + } + + /// set matches sorting mode + function SetSortMode ( $mode, $sortby="" ) + { + assert ( + $mode==SPH_SORT_RELEVANCE || + $mode==SPH_SORT_ATTR_DESC || + $mode==SPH_SORT_ATTR_ASC || + $mode==SPH_SORT_TIME_SEGMENTS || + $mode==SPH_SORT_EXTENDED || + $mode==SPH_SORT_EXPR ); + assert ( is_string($sortby) ); + assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); + + $this->_sort = $mode; + $this->_sortby = $sortby; + } + + /// bind per-field weights by order + /// DEPRECATED; use SetFieldWeights() instead + function SetWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $weight ) + assert ( is_int($weight) ); + + $this->_weights = $weights; + } + + /// bind per-field weights by name + function SetFieldWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $name=>$weight ) + { + assert ( is_string($name) ); + assert ( is_int($weight) ); + } + $this->_fieldweights = $weights; + } + + /// bind per-index weights by name + function SetIndexWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $index=>$weight ) + { + assert ( is_string($index) ); + assert ( is_int($weight) ); + } + $this->_indexweights = $weights; + } + + /// set IDs range to match + /// only match records if document ID is beetwen $min and $max (inclusive) + function SetIDRange ( $min, $max ) + { + assert ( is_numeric($min) ); + assert ( is_numeric($max) ); + assert ( $min<=$max ); + $this->_min_id = $min; + $this->_max_id = $max; + } + + /// set values set filter + /// only match records where $attribute value is in given set + function SetFilter ( $attribute, $values, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_array($values) ); + assert ( count($values) ); + + if ( is_array($values) && count($values) ) + { + foreach ( $values as $value ) + assert ( is_numeric($value) ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); + } + } + + /// set range filter + /// only match records if $attribute value is beetwen $min and $max (inclusive) + function SetFilterRange ( $attribute, $min, $max, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_int($min) ); + assert ( is_int($max) ); + assert ( $min<=$max ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); + } + + /// set float range filter + /// only match records if $attribute value is beetwen $min and $max (inclusive) + function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_float($min) ); + assert ( is_float($max) ); + assert ( $min<=$max ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); + } + + /// setup anchor point for geosphere distance calculations + /// required to use @geodist in filters and sorting + /// latitude and longitude must be in radians + function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) + { + assert ( is_string($attrlat) ); + assert ( is_string($attrlong) ); + assert ( is_float($lat) ); + assert ( is_float($long) ); + + $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); + } + + /// set grouping attribute and function + function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) + { + assert ( is_string($attribute) ); + assert ( is_string($groupsort) ); + assert ( $func==SPH_GROUPBY_DAY + || $func==SPH_GROUPBY_WEEK + || $func==SPH_GROUPBY_MONTH + || $func==SPH_GROUPBY_YEAR + || $func==SPH_GROUPBY_ATTR + || $func==SPH_GROUPBY_ATTRPAIR ); + + $this->_groupby = $attribute; + $this->_groupfunc = $func; + $this->_groupsort = $groupsort; + } + + /// set count-distinct attribute for group-by queries + function SetGroupDistinct ( $attribute ) + { + assert ( is_string($attribute) ); + $this->_groupdistinct = $attribute; + } + + /// set distributed retries count and delay + function SetRetries ( $count, $delay=0 ) + { + assert ( is_int($count) && $count>=0 ); + assert ( is_int($delay) && $delay>=0 ); + $this->_retrycount = $count; + $this->_retrydelay = $delay; + } + + /// set result set format (hash or array; hash by default) + /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs + function SetArrayResult ( $arrayresult ) + { + assert ( is_bool($arrayresult) ); + $this->_arrayresult = $arrayresult; + } + + ////////////////////////////////////////////////////////////////////////////// + + /// clear all filters (for multi-queries) + function ResetFilters () + { + $this->_filters = array(); + $this->_anchor = array(); + } + + /// clear groupby settings (for multi-queries) + function ResetGroupBy () + { + $this->_groupby = ""; + $this->_groupfunc = SPH_GROUPBY_DAY; + $this->_groupsort = "@group desc"; + $this->_groupdistinct= ""; + } + + ////////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, run given search query through given indexes, + /// and return the search results + function Query ( $query, $index="*", $comment="" ) + { + assert ( empty($this->_reqs) ); + + $this->AddQuery ( $query, $index, $comment ); + $results = $this->RunQueries (); + $this->_reqs = array (); // just in case it failed too early + + if ( !is_array($results) ) + return false; // probably network error; error message should be already filled + + $this->_error = $results[0]["error"]; + $this->_warning = $results[0]["warning"]; + if ( $results[0]["status"]==SEARCHD_ERROR ) + return false; + else + return $results[0]; + } + + /// helper to pack floats in network byte order + function _PackFloat ( $f ) + { + $t1 = pack ( "f", $f ); // machine order + list(,$t2) = unpack ( "L*", $t1 ); // int in machine order + return pack ( "N", $t2 ); + } + + /// add query to multi-query batch + /// returns index into results array from RunQueries() call + function AddQuery ( $query, $index="*", $comment="" ) + { + // mbstring workaround + $this->_MBPush (); + + // build request + $req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort ); // mode and limits + $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; + $req .= pack ( "N", strlen($query) ) . $query; // query itself + $req .= pack ( "N", count($this->_weights) ); // weights + foreach ( $this->_weights as $weight ) + $req .= pack ( "N", (int)$weight ); + $req .= pack ( "N", strlen($index) ) . $index; // indexes + $req .= pack ( "N", 1 ); // id64 range marker + $req .= sphPack64 ( $this->_min_id ) . sphPack64 ( $this->_max_id ); // id64 range + + // filters + $req .= pack ( "N", count($this->_filters) ); + foreach ( $this->_filters as $filter ) + { + $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; + $req .= pack ( "N", $filter["type"] ); + switch ( $filter["type"] ) + { + case SPH_FILTER_VALUES: + $req .= pack ( "N", count($filter["values"]) ); + foreach ( $filter["values"] as $value ) + $req .= pack ( "N", floatval($value) ); // this uberhack is to workaround 32bit signed int limit on x32 platforms + break; + + case SPH_FILTER_RANGE: + $req .= pack ( "NN", $filter["min"], $filter["max"] ); + break; + + case SPH_FILTER_FLOATRANGE: + $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); + break; + + default: + assert ( 0 && "internal error: unhandled filter type" ); + } + $req .= pack ( "N", $filter["exclude"] ); + } + + // group-by clause, max-matches count, group-sort clause, cutoff count + $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; + $req .= pack ( "N", $this->_maxmatches ); + $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; + $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); + $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; + + // anchor point + if ( empty($this->_anchor) ) + { + $req .= pack ( "N", 0 ); + } else + { + $a =& $this->_anchor; + $req .= pack ( "N", 1 ); + $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; + $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; + $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); + } + + // per-index weights + $req .= pack ( "N", count($this->_indexweights) ); + foreach ( $this->_indexweights as $idx=>$weight ) + $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); + + // max query time + $req .= pack ( "N", $this->_maxquerytime ); + + // per-field weights + $req .= pack ( "N", count($this->_fieldweights) ); + foreach ( $this->_fieldweights as $field=>$weight ) + $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); + + // comment + $req .= pack ( "N", strlen($comment) ) . $comment; + + // mbstring workaround + $this->_MBPop (); + + // store request to requests array + $this->_reqs[] = $req; + return count($this->_reqs)-1; + } + + /// connect to searchd, run queries batch, and return an array of result sets + function RunQueries () + { + if ( empty($this->_reqs) ) + { + $this->_error = "no queries defined, issue AddQuery() first"; + return false; + } + + // mbstring workaround + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop (); + return false; + } + + //////////////////////////// + // send query, get response + //////////////////////////// + + $nreqs = count($this->_reqs); + $req = join ( "", $this->_reqs ); + $len = 4+strlen($req); + $req = pack ( "nnNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, $nreqs ) . $req; // add header + + fwrite ( $fp, $req, $len+8 ); + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) )) + { + $this->_MBPop (); + return false; + } + + $this->_reqs = array (); + + ////////////////// + // parse response + ////////////////// + + $p = 0; // current position + $max = strlen($response); // max position for checks, to protect against broken responses + + $results = array (); + for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) + { + $results[] = array(); + $result =& $results[$ires]; + + $result["error"] = ""; + $result["warning"] = ""; + + // extract status + list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $result["status"] = $status; + if ( $status!=SEARCHD_OK ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $message = substr ( $response, $p, $len ); $p += $len; + + if ( $status==SEARCHD_WARNING ) + { + $result["warning"] = $message; + } else + { + $result["error"] = $message; + continue; + } + } + + // read schema + $fields = array (); + $attrs = array (); + + list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + while ( $nfields-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $fields[] = substr ( $response, $p, $len ); $p += $len; + } + $result["fields"] = $fields; + + list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + while ( $nattrs-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attr = substr ( $response, $p, $len ); $p += $len; + list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attrs[$attr] = $type; + } + $result["attrs"] = $attrs; + + // read match count + list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + + // read matches + $idx = -1; + while ( $count-->0 && $p<$max ) + { + // index into result array + $idx++; + + // parse document id and weight + if ( $id64 ) + { + $doc = sphUnpack64 ( substr ( $response, $p, 8 ) ); $p += 8; + list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + } else + { + list ( $doc, $weight ) = array_values ( unpack ( "N*N*", + substr ( $response, $p, 8 ) ) ); + $p += 8; + + if ( PHP_INT_SIZE>=8 ) + { + // x64 route, workaround broken unpack() in 5.2.2+ + if ( $doc<0 ) $doc += (1<<32); + } else + { + // x32 route, workaround php signed/unsigned braindamage + $doc = sprintf ( "%u", $doc ); + } + } + $weight = sprintf ( "%u", $weight ); + + // create match entry + if ( $this->_arrayresult ) + $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); + else + $result["matches"][$doc]["weight"] = $weight; + + // parse and create attributes + $attrvals = array (); + foreach ( $attrs as $attr=>$type ) + { + // handle floats + if ( $type==SPH_ATTR_FLOAT ) + { + list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); + $attrvals[$attr] = $fval; + continue; + } + + // handle everything else as unsigned ints + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + if ( $type & SPH_ATTR_MULTI ) + { + $attrvals[$attr] = array (); + $nvalues = $val; + while ( $nvalues-->0 && $p<$max ) + { + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attrvals[$attr][] = sprintf ( "%u", $val ); + } + } else + { + $attrvals[$attr] = sprintf ( "%u", $val ); + } + } + + if ( $this->_arrayresult ) + $result["matches"][$idx]["attrs"] = $attrvals; + else + $result["matches"][$doc]["attrs"] = $attrvals; + } + + list ( $total, $total_found, $msecs, $words ) = + array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); + $result["total"] = sprintf ( "%u", $total ); + $result["total_found"] = sprintf ( "%u", $total_found ); + $result["time"] = sprintf ( "%.3f", $msecs/1000 ); + $p += 16; + + while ( $words-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $word = substr ( $response, $p, $len ); $p += $len; + list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; + $result["words"][$word] = array ( + "docs"=>sprintf ( "%u", $docs ), + "hits"=>sprintf ( "%u", $hits ) ); + } + } + + $this->_MBPop (); + return $results; + } + + ///////////////////////////////////////////////////////////////////////////// + // excerpts generation + ///////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, and generate exceprts (snippets) + /// of given documents for given query. returns false on failure, + /// an array of snippets on success + function BuildExcerpts ( $docs, $index, $words, $opts=array() ) + { + assert ( is_array($docs) ); + assert ( is_string($index) ); + assert ( is_string($words) ); + assert ( is_array($opts) ); + + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + ///////////////// + // fixup options + ///////////////// + + if ( !isset($opts["before_match"]) ) $opts["before_match"] = ""; + if ( !isset($opts["after_match"]) ) $opts["after_match"] = ""; + if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; + if ( !isset($opts["limit"]) ) $opts["limit"] = 256; + if ( !isset($opts["around"]) ) $opts["around"] = 5; + if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; + if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; + if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; + if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; + + ///////////////// + // build request + ///////////////// + + // v.1.0 req + $flags = 1; // remove spaces + if ( $opts["exact_phrase"] ) $flags |= 2; + if ( $opts["single_passage"] ) $flags |= 4; + if ( $opts["use_boundaries"] ) $flags |= 8; + if ( $opts["weight_order"] ) $flags |= 16; + $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags + $req .= pack ( "N", strlen($index) ) . $index; // req index + $req .= pack ( "N", strlen($words) ) . $words; // req words + + // options + $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; + $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; + $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; + $req .= pack ( "N", (int)$opts["limit"] ); + $req .= pack ( "N", (int)$opts["around"] ); + + // documents + $req .= pack ( "N", count($docs) ); + foreach ( $docs as $doc ) + { + assert ( is_string($doc) ); + $req .= pack ( "N", strlen($doc) ) . $doc; + } + + //////////////////////////// + // send query, get response + //////////////////////////// + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header + $wrote = fwrite ( $fp, $req, $len+8 ); + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) )) + { + $this->_MBPop (); + return false; + } + + ////////////////// + // parse response + ////////////////// + + $pos = 0; + $res = array (); + $rlen = strlen($response); + for ( $i=0; $i $rlen ) + { + $this->_error = "incomplete reply"; + $this->_MBPop (); + return false; + } + $res[] = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + } + + $this->_MBPop (); + return $res; + } + + + ///////////////////////////////////////////////////////////////////////////// + // keyword generation + ///////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, and generate keyword list for a given query + /// returns false on failure, + /// an array of words on success + function BuildKeywords ( $query, $index, $hits ) + { + assert ( is_string($query) ); + assert ( is_string($index) ); + assert ( is_bool($hits) ); + + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + ///////////////// + // build request + ///////////////// + + // v.1.0 req + $req = pack ( "N", strlen($query) ) . $query; // req query + $req .= pack ( "N", strlen($index) ) . $index; // req index + $req .= pack ( "N", (int)$hits ); + + //////////////////////////// + // send query, get response + //////////////////////////// + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header + $wrote = fwrite ( $fp, $req, $len+8 ); + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) )) + { + $this->_MBPop (); + return false; + } + + ////////////////// + // parse response + ////////////////// + + $pos = 0; + $res = array (); + $rlen = strlen($response); + list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); + $pos += 4; + for ( $i=0; $i<$nwords; $i++ ) + { + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; + $tokenized = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; + $normalized = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + + $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); + + if ( $hits ) + { + list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); + $pos += 8; + $res [$i]["docs"] = $ndocs; + $res [$i]["hits"] = $nhits; + } + + if ( $pos > $rlen ) + { + $this->_error = "incomplete reply"; + $this->_MBPop (); + return false; + } + } + + $this->_MBPop (); + return $res; + } + + function EscapeString ( $string ) + { + $from = array ( '(',')','|','-','!','@','~','"','&', '/' ); + $to = array ( '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/' ); + + return str_replace ( $from, $to, $string ); + } + + ///////////////////////////////////////////////////////////////////////////// + // attribute updates + ///////////////////////////////////////////////////////////////////////////// + + /// update given attribute values on given documents in given indexes + /// returns amount of updated documents (0 or more) on success, or -1 on failure + function UpdateAttributes ( $index, $attrs, $values ) + { + // verify everything + assert ( is_string($index) ); + + assert ( is_array($attrs) ); + foreach ( $attrs as $attr ) + assert ( is_string($attr) ); + + assert ( is_array($values) ); + foreach ( $values as $id=>$entry ) + { + assert ( is_numeric($id) ); + assert ( is_array($entry) ); + assert ( count($entry)==count($attrs) ); + foreach ( $entry as $v ) + assert ( is_int($v) ); + } + + // build request + $req = pack ( "N", strlen($index) ) . $index; + + $req .= pack ( "N", count($attrs) ); + foreach ( $attrs as $attr ) + $req .= pack ( "N", strlen($attr) ) . $attr; + + $req .= pack ( "N", count($values) ); + foreach ( $values as $id=>$entry ) + { + $req .= sphPack64 ( $id ); + foreach ( $entry as $v ) + $req .= pack ( "N", $v ); + } + + // mbstring workaround + $this->_MBPush (); + + // connect, send query, get response + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop (); + return -1; + } + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header + fwrite ( $fp, $req, $len+8 ); + + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) + { + $this->_MBPop (); + return -1; + } + + // parse response + list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); + $this->_MBPop (); + return $updated; + } +} + +// +// $Id$ +// \ No newline at end of file -- cgit v1.2.1 From fcf0d04b20f1c862117a8ab962d692bd2b8b074f Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 9 May 2012 19:13:36 +0530 Subject: [feature/sphinx-fulltext-search] minor changes some minor code changes to make it working against current develop and comply with other search backend coding convetions. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index e0c467df93..ef357970a0 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -18,33 +18,27 @@ if (!defined('IN_PHPBB')) /** * @ignore */ +/** +* This statement is necessary as this file is sometimes included from within a +* function and the variables used are in global space. +*/ +global $phpbb_root_path, $phpEx, $table_prefix; require($phpbb_root_path . "includes/sphinxapi-0.9.8." . $phpEx); define('INDEXER_NAME', 'indexer'); define('SEARCHD_NAME', 'searchd'); -define('SPHINX_TABLE', table_prefix() . 'sphinx'); +define('SPHINX_TABLE', $table_prefix . 'sphinx'); define('MAX_MATCHES', 20000); define('CONNECT_RETRIES', 3); define('CONNECT_WAIT_TIME', 300); -/** -* Returns the global table prefix -* This function is necessary as this file is sometimes included from within a -* function and table_prefix is in global space. -*/ -function table_prefix() -{ - global $table_prefix; - return $table_prefix; -} - /** * fulltext_sphinx * Fulltext search based on the sphinx search deamon * @package search */ -class fulltext_sphinx +class phpbb_search_fulltext_sphinx { var $stats = array(); var $word_length = array(); @@ -53,7 +47,7 @@ class fulltext_sphinx var $common_words = array(); var $id; - function fulltext_sphinx(&$error) + public function __construct(&$error) { global $config; @@ -82,6 +76,16 @@ class fulltext_sphinx $error = false; } + + /** + * Returns the name of this search backend to be displayed to administrators + * + * @return string Name + */ + public function get_name() + { + return 'Sphinx Fulltext'; + } /** * Checks permissions and paths, if everything is correct it generates the config file -- cgit v1.2.1 From 99d4660df68d71ea56cccb150ae858c1dd7575b8 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 20 Jun 2012 05:11:53 +0530 Subject: [feature/sphinx-fulltext-search] update config file Sphinx config file updated according to new documentation. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index ef357970a0..6c5092f4aa 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -295,7 +295,7 @@ class phpbb_search_fulltext_sphinx array('stopwords', (file_exists($config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt') && $config['fulltext_sphinx_stopwords']) ? $config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), array('min_word_len', '2'), array('charset_type', 'utf-8'), - array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+ß410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), + array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), array('min_prefix_len', '0'), array('min_infix_len', '0'), ), @@ -307,7 +307,8 @@ class phpbb_search_fulltext_sphinx array('mem_limit', $config['fulltext_sphinx_indexer_mem_limit'] . 'M'), ), 'searchd' => array( - array('address' , '127.0.0.1'), + array('compat_sphinxql_magics' , '0'), + array('listen' , '127.0.0.1'), array('port', ($config['fulltext_sphinx_port']) ? $config['fulltext_sphinx_port'] : '3312'), array('log', $config['fulltext_sphinx_data_path'] . "log/searchd.log"), array('query_log', $config['fulltext_sphinx_data_path'] . "log/sphinx-query.log"), -- cgit v1.2.1 From 8d76bc45ee19186f40dd3b459a9bd33e5e4c23d9 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 26 Jun 2012 02:35:36 +0530 Subject: [feature/sphinx-fulltext-search] minor fixes in formatting Add a newline at the end of files. Update License information in package docbloc. PHPBB3-10946 --- phpBB/includes/functions_sphinx.php | 5 ++--- phpBB/includes/search/fulltext_sphinx.php | 5 +---- phpBB/includes/sphinxapi-0.9.8.php | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_sphinx.php b/phpBB/includes/functions_sphinx.php index 976f93f77c..0f83f8cfb5 100644 --- a/phpBB/includes/functions_sphinx.php +++ b/phpBB/includes/functions_sphinx.php @@ -2,9 +2,8 @@ /** * * @package search -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -504,4 +503,4 @@ class sphinx_config_comment } } -?> \ No newline at end of file +?> diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 6c5092f4aa..9ae6438af2 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -2,9 +2,8 @@ /** * * @package search -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -1167,5 +1166,3 @@ function sphinx_read_last_lines($file, $amount) return $string; } - -?> \ No newline at end of file diff --git a/phpBB/includes/sphinxapi-0.9.8.php b/phpBB/includes/sphinxapi-0.9.8.php index 6a7ea17760..816895d464 100644 --- a/phpBB/includes/sphinxapi-0.9.8.php +++ b/phpBB/includes/sphinxapi-0.9.8.php @@ -1199,4 +1199,4 @@ class SphinxClient // // $Id$ -// \ No newline at end of file +// -- cgit v1.2.1 From 455a35d8361c93657874e140a2ad5b2e5c267757 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 26 Jun 2012 03:56:03 +0530 Subject: [feature/sphinx-fulltext-search] temporary commit to pull out sphinx-api also need to add the latest sphinx api instead of this. PHPBB3-10946 --- phpBB/includes/sphinxapi-0.9.8.php | 1202 ------------------------------------ 1 file changed, 1202 deletions(-) delete mode 100644 phpBB/includes/sphinxapi-0.9.8.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/sphinxapi-0.9.8.php b/phpBB/includes/sphinxapi-0.9.8.php deleted file mode 100644 index 816895d464..0000000000 --- a/phpBB/includes/sphinxapi-0.9.8.php +++ /dev/null @@ -1,1202 +0,0 @@ -=8 ) - { - $i = (int)$v; - return pack ( "NN", $i>>32, $i&((1<<32)-1) ); - } - - // x32 route, bcmath - $x = "4294967296"; - if ( function_exists("bcmul") ) - { - $h = bcdiv ( $v, $x, 0 ); - $l = bcmod ( $v, $x ); - return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit - } - - // x32 route, 15 or less decimal digits - // we can use float, because its actually double and has 52 precision bits - if ( strlen($v)<=15 ) - { - $f = (float)$v; - $h = (int)($f/$x); - $l = (int)($f-$x*$h); - return pack ( "NN", $h, $l ); - } - - // x32 route, 16 or more decimal digits - // well, let me know if you *really* need this - die ( "INTERNAL ERROR: packing more than 15-digit numeric on 32-bit PHP is not implemented yet (contact support)" ); -} - - -/// portably unpack 64 unsigned bits, network order to numeric -function sphUnpack64 ( $v ) -{ - list($h,$l) = array_values ( unpack ( "N*N*", $v ) ); - - // x64 route - if ( PHP_INT_SIZE>=8 ) - { - if ( $h<0 ) $h += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again - if ( $l<0 ) $l += (1<<32); - return ($h<<32) + $l; - } - - // x32 route - $h = sprintf ( "%u", $h ); - $l = sprintf ( "%u", $l ); - $x = "4294967296"; - - // bcmath - if ( function_exists("bcmul") ) - return bcadd ( $l, bcmul ( $x, $h ) ); - - // no bcmath, 15 or less decimal digits - // we can use float, because its actually double and has 52 precision bits - if ( $h<1048576 ) - { - $f = ((float)$h)*$x + (float)$l; - return sprintf ( "%.0f", $f ); // builtin conversion is only about 39-40 bits precise! - } - - // x32 route, 16 or more decimal digits - // well, let me know if you *really* need this - die ( "INTERNAL ERROR: unpacking more than 15-digit numeric on 32-bit PHP is not implemented yet (contact support)" ); -} - - -/// sphinx searchd client class -class SphinxClient -{ - var $_host; ///< searchd host (default is "localhost") - var $_port; ///< searchd port (default is 3312) - var $_offset; ///< how many records to seek from result-set start (default is 0) - var $_limit; ///< how many records to return from result-set starting at offset (default is 20) - var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) - var $_weights; ///< per-field weights (default is 1 for all fields) - var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) - var $_sortby; ///< attribute to sort by (defualt is "") - var $_min_id; ///< min ID to match (default is 0, which means no limit) - var $_max_id; ///< max ID to match (default is 0, which means no limit) - var $_filters; ///< search filters - var $_groupby; ///< group-by attribute name - var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) - var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) - var $_groupdistinct;///< group-by count-distinct attribute - var $_maxmatches; ///< max matches to retrieve - var $_cutoff; ///< cutoff to stop searching at (default is 0) - var $_retrycount; ///< distributed retries count - var $_retrydelay; ///< distributed retries delay - var $_anchor; ///< geographical anchor point - var $_indexweights; ///< per-index weights - var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) - var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) - var $_fieldweights; ///< per-field-name weights - - var $_error; ///< last error message - var $_warning; ///< last warning message - - var $_reqs; ///< requests array for multi-query - var $_mbenc; ///< stored mbstring encoding - var $_arrayresult; ///< whether $result["matches"] should be a hash or an array - var $_timeout; ///< connect timeout - - ///////////////////////////////////////////////////////////////////////////// - // common stuff - ///////////////////////////////////////////////////////////////////////////// - - /// create a new client object and fill defaults - function SphinxClient () - { - // per-client-object settings - $this->_host = "localhost"; - $this->_port = 3312; - - // per-query settings - $this->_offset = 0; - $this->_limit = 20; - $this->_mode = SPH_MATCH_ALL; - $this->_weights = array (); - $this->_sort = SPH_SORT_RELEVANCE; - $this->_sortby = ""; - $this->_min_id = 0; - $this->_max_id = 0; - $this->_filters = array (); - $this->_groupby = ""; - $this->_groupfunc = SPH_GROUPBY_DAY; - $this->_groupsort = "@group desc"; - $this->_groupdistinct= ""; - $this->_maxmatches = 1000; - $this->_cutoff = 0; - $this->_retrycount = 0; - $this->_retrydelay = 0; - $this->_anchor = array (); - $this->_indexweights= array (); - $this->_ranker = SPH_RANK_PROXIMITY_BM25; - $this->_maxquerytime= 0; - $this->_fieldweights= array(); - - $this->_error = ""; // per-reply fields (for single-query case) - $this->_warning = ""; - $this->_reqs = array (); // requests storage (for multi-query case) - $this->_mbenc = ""; - $this->_arrayresult = false; - $this->_timeout = 0; - } - - /// get last error message (string) - function GetLastError () - { - return $this->_error; - } - - /// get last warning message (string) - function GetLastWarning () - { - return $this->_warning; - } - - /// set searchd host name (string) and port (integer) - function SetServer ( $host, $port ) - { - assert ( is_string($host) ); - assert ( is_int($port) ); - $this->_host = $host; - $this->_port = $port; - } - - /// set server connection timeout (0 to remove) - function SetConnectTimeout ( $timeout ) - { - assert ( is_numeric($timeout) ); - $this->_timeout = $timeout; - } - - ///////////////////////////////////////////////////////////////////////////// - - /// enter mbstring workaround mode - function _MBPush () - { - $this->_mbenc = ""; - if ( ini_get ( "mbstring.func_overload" ) & 2 ) - { - $this->_mbenc = mb_internal_encoding(); - mb_internal_encoding ( "latin1" ); - } - } - - /// leave mbstring workaround mode - function _MBPop () - { - if ( $this->_mbenc ) - mb_internal_encoding ( $this->_mbenc ); - } - - /// connect to searchd server - function _Connect ($allow_retry = true) - { - $errno = 0; - $errstr = ""; - if ( $this->_timeout<=0 ) - $fp = @fsockopen ( $this->_host, $this->_port, $errno, $errstr ); - else - $fp = @fsockopen ( $this->_host, $this->_port, $errno, $errstr, $this->_timeout ); - - if ( !$fp ) - { - $errstr = trim ( $errstr ); - $this->_error = "connection to {$this->_host}:{$this->_port} failed (errno=$errno, msg=$errstr)"; - return false; - } - - // check version - //list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); - $version_data = unpack ( "N*", fread ( $fp, 4 ) ); - if (!isset($version_data[1])) - { - // this should not happen, try to reconnect ONCE - if ($allow_retry) - { - return $this->_Connect(false); - } - else - { - $this->_error = "unexpected version data"; - return false; - } - } - $v = $version_data[1]; - $v = (int)$v; - if ( $v<1 ) - { - fclose ( $fp ); - $this->_error = "expected searchd protocol version 1+, got version '$v'"; - return false; - } - - // all ok, send my version - fwrite ( $fp, pack ( "N", 1 ) ); - return $fp; - } - - /// get and check response packet from searchd server - function _GetResponse ( $fp, $client_ver ) - { - $response = ""; - $len = 0; - - $header = fread ( $fp, 8 ); - if ( strlen($header)==8 ) - { - list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); - $left = $len; - while ( $left>0 && !feof($fp) ) - { - $chunk = fread ( $fp, $left ); - if ( $chunk ) - { - $response .= $chunk; - $left -= strlen($chunk); - } - } - } - fclose ( $fp ); - - // check response - $read = strlen ( $response ); - if ( !$response || $read!=$len ) - { - $this->_error = $len - ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" - : "received zero-sized searchd response"; - return false; - } - - // check status - if ( $status==SEARCHD_WARNING ) - { - list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); - $this->_warning = substr ( $response, 4, $wlen ); - return substr ( $response, 4+$wlen ); - } - if ( $status==SEARCHD_ERROR ) - { - $this->_error = "searchd error: " . substr ( $response, 4 ); - return false; - } - if ( $status==SEARCHD_RETRY ) - { - $this->_error = "temporary searchd error: " . substr ( $response, 4 ); - return false; - } - if ( $status!=SEARCHD_OK ) - { - $this->_error = "unknown status code '$status'"; - return false; - } - - // check version - if ( $ver<$client_ver ) - { - $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", - $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); - } - - return $response; - } - - ///////////////////////////////////////////////////////////////////////////// - // searching - ///////////////////////////////////////////////////////////////////////////// - - /// set offset and count into result set, - /// and optionally set max-matches and cutoff limits - function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) - { - assert ( is_int($offset) ); - assert ( is_int($limit) ); - assert ( $offset>=0 ); - assert ( $limit>0 ); - assert ( $max>=0 ); - $this->_offset = $offset; - $this->_limit = $limit; - if ( $max>0 ) - $this->_maxmatches = $max; - if ( $cutoff>0 ) - $this->_cutoff = $cutoff; - } - - /// set maximum query time, in milliseconds, per-index - /// integer, 0 means "do not limit" - function SetMaxQueryTime ( $max ) - { - assert ( is_int($max) ); - assert ( $max>=0 ); - $this->_maxquerytime = $max; - } - - /// set matching mode - function SetMatchMode ( $mode ) - { - assert ( $mode==SPH_MATCH_ALL - || $mode==SPH_MATCH_ANY - || $mode==SPH_MATCH_PHRASE - || $mode==SPH_MATCH_BOOLEAN - || $mode==SPH_MATCH_EXTENDED - || $mode==SPH_MATCH_FULLSCAN - || $mode==SPH_MATCH_EXTENDED2 ); - $this->_mode = $mode; - } - - /// set ranking mode - function SetRankingMode ( $ranker ) - { - assert ( $ranker==SPH_RANK_PROXIMITY_BM25 - || $ranker==SPH_RANK_BM25 - || $ranker==SPH_RANK_NONE - || $ranker==SPH_RANK_WORDCOUNT ); - $this->_ranker = $ranker; - } - - /// set matches sorting mode - function SetSortMode ( $mode, $sortby="" ) - { - assert ( - $mode==SPH_SORT_RELEVANCE || - $mode==SPH_SORT_ATTR_DESC || - $mode==SPH_SORT_ATTR_ASC || - $mode==SPH_SORT_TIME_SEGMENTS || - $mode==SPH_SORT_EXTENDED || - $mode==SPH_SORT_EXPR ); - assert ( is_string($sortby) ); - assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); - - $this->_sort = $mode; - $this->_sortby = $sortby; - } - - /// bind per-field weights by order - /// DEPRECATED; use SetFieldWeights() instead - function SetWeights ( $weights ) - { - assert ( is_array($weights) ); - foreach ( $weights as $weight ) - assert ( is_int($weight) ); - - $this->_weights = $weights; - } - - /// bind per-field weights by name - function SetFieldWeights ( $weights ) - { - assert ( is_array($weights) ); - foreach ( $weights as $name=>$weight ) - { - assert ( is_string($name) ); - assert ( is_int($weight) ); - } - $this->_fieldweights = $weights; - } - - /// bind per-index weights by name - function SetIndexWeights ( $weights ) - { - assert ( is_array($weights) ); - foreach ( $weights as $index=>$weight ) - { - assert ( is_string($index) ); - assert ( is_int($weight) ); - } - $this->_indexweights = $weights; - } - - /// set IDs range to match - /// only match records if document ID is beetwen $min and $max (inclusive) - function SetIDRange ( $min, $max ) - { - assert ( is_numeric($min) ); - assert ( is_numeric($max) ); - assert ( $min<=$max ); - $this->_min_id = $min; - $this->_max_id = $max; - } - - /// set values set filter - /// only match records where $attribute value is in given set - function SetFilter ( $attribute, $values, $exclude=false ) - { - assert ( is_string($attribute) ); - assert ( is_array($values) ); - assert ( count($values) ); - - if ( is_array($values) && count($values) ) - { - foreach ( $values as $value ) - assert ( is_numeric($value) ); - - $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); - } - } - - /// set range filter - /// only match records if $attribute value is beetwen $min and $max (inclusive) - function SetFilterRange ( $attribute, $min, $max, $exclude=false ) - { - assert ( is_string($attribute) ); - assert ( is_int($min) ); - assert ( is_int($max) ); - assert ( $min<=$max ); - - $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); - } - - /// set float range filter - /// only match records if $attribute value is beetwen $min and $max (inclusive) - function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) - { - assert ( is_string($attribute) ); - assert ( is_float($min) ); - assert ( is_float($max) ); - assert ( $min<=$max ); - - $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); - } - - /// setup anchor point for geosphere distance calculations - /// required to use @geodist in filters and sorting - /// latitude and longitude must be in radians - function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) - { - assert ( is_string($attrlat) ); - assert ( is_string($attrlong) ); - assert ( is_float($lat) ); - assert ( is_float($long) ); - - $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); - } - - /// set grouping attribute and function - function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) - { - assert ( is_string($attribute) ); - assert ( is_string($groupsort) ); - assert ( $func==SPH_GROUPBY_DAY - || $func==SPH_GROUPBY_WEEK - || $func==SPH_GROUPBY_MONTH - || $func==SPH_GROUPBY_YEAR - || $func==SPH_GROUPBY_ATTR - || $func==SPH_GROUPBY_ATTRPAIR ); - - $this->_groupby = $attribute; - $this->_groupfunc = $func; - $this->_groupsort = $groupsort; - } - - /// set count-distinct attribute for group-by queries - function SetGroupDistinct ( $attribute ) - { - assert ( is_string($attribute) ); - $this->_groupdistinct = $attribute; - } - - /// set distributed retries count and delay - function SetRetries ( $count, $delay=0 ) - { - assert ( is_int($count) && $count>=0 ); - assert ( is_int($delay) && $delay>=0 ); - $this->_retrycount = $count; - $this->_retrydelay = $delay; - } - - /// set result set format (hash or array; hash by default) - /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs - function SetArrayResult ( $arrayresult ) - { - assert ( is_bool($arrayresult) ); - $this->_arrayresult = $arrayresult; - } - - ////////////////////////////////////////////////////////////////////////////// - - /// clear all filters (for multi-queries) - function ResetFilters () - { - $this->_filters = array(); - $this->_anchor = array(); - } - - /// clear groupby settings (for multi-queries) - function ResetGroupBy () - { - $this->_groupby = ""; - $this->_groupfunc = SPH_GROUPBY_DAY; - $this->_groupsort = "@group desc"; - $this->_groupdistinct= ""; - } - - ////////////////////////////////////////////////////////////////////////////// - - /// connect to searchd server, run given search query through given indexes, - /// and return the search results - function Query ( $query, $index="*", $comment="" ) - { - assert ( empty($this->_reqs) ); - - $this->AddQuery ( $query, $index, $comment ); - $results = $this->RunQueries (); - $this->_reqs = array (); // just in case it failed too early - - if ( !is_array($results) ) - return false; // probably network error; error message should be already filled - - $this->_error = $results[0]["error"]; - $this->_warning = $results[0]["warning"]; - if ( $results[0]["status"]==SEARCHD_ERROR ) - return false; - else - return $results[0]; - } - - /// helper to pack floats in network byte order - function _PackFloat ( $f ) - { - $t1 = pack ( "f", $f ); // machine order - list(,$t2) = unpack ( "L*", $t1 ); // int in machine order - return pack ( "N", $t2 ); - } - - /// add query to multi-query batch - /// returns index into results array from RunQueries() call - function AddQuery ( $query, $index="*", $comment="" ) - { - // mbstring workaround - $this->_MBPush (); - - // build request - $req = pack ( "NNNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker, $this->_sort ); // mode and limits - $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; - $req .= pack ( "N", strlen($query) ) . $query; // query itself - $req .= pack ( "N", count($this->_weights) ); // weights - foreach ( $this->_weights as $weight ) - $req .= pack ( "N", (int)$weight ); - $req .= pack ( "N", strlen($index) ) . $index; // indexes - $req .= pack ( "N", 1 ); // id64 range marker - $req .= sphPack64 ( $this->_min_id ) . sphPack64 ( $this->_max_id ); // id64 range - - // filters - $req .= pack ( "N", count($this->_filters) ); - foreach ( $this->_filters as $filter ) - { - $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; - $req .= pack ( "N", $filter["type"] ); - switch ( $filter["type"] ) - { - case SPH_FILTER_VALUES: - $req .= pack ( "N", count($filter["values"]) ); - foreach ( $filter["values"] as $value ) - $req .= pack ( "N", floatval($value) ); // this uberhack is to workaround 32bit signed int limit on x32 platforms - break; - - case SPH_FILTER_RANGE: - $req .= pack ( "NN", $filter["min"], $filter["max"] ); - break; - - case SPH_FILTER_FLOATRANGE: - $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); - break; - - default: - assert ( 0 && "internal error: unhandled filter type" ); - } - $req .= pack ( "N", $filter["exclude"] ); - } - - // group-by clause, max-matches count, group-sort clause, cutoff count - $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; - $req .= pack ( "N", $this->_maxmatches ); - $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; - $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); - $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; - - // anchor point - if ( empty($this->_anchor) ) - { - $req .= pack ( "N", 0 ); - } else - { - $a =& $this->_anchor; - $req .= pack ( "N", 1 ); - $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; - $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; - $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); - } - - // per-index weights - $req .= pack ( "N", count($this->_indexweights) ); - foreach ( $this->_indexweights as $idx=>$weight ) - $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); - - // max query time - $req .= pack ( "N", $this->_maxquerytime ); - - // per-field weights - $req .= pack ( "N", count($this->_fieldweights) ); - foreach ( $this->_fieldweights as $field=>$weight ) - $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); - - // comment - $req .= pack ( "N", strlen($comment) ) . $comment; - - // mbstring workaround - $this->_MBPop (); - - // store request to requests array - $this->_reqs[] = $req; - return count($this->_reqs)-1; - } - - /// connect to searchd, run queries batch, and return an array of result sets - function RunQueries () - { - if ( empty($this->_reqs) ) - { - $this->_error = "no queries defined, issue AddQuery() first"; - return false; - } - - // mbstring workaround - $this->_MBPush (); - - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop (); - return false; - } - - //////////////////////////// - // send query, get response - //////////////////////////// - - $nreqs = count($this->_reqs); - $req = join ( "", $this->_reqs ); - $len = 4+strlen($req); - $req = pack ( "nnNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, $nreqs ) . $req; // add header - - fwrite ( $fp, $req, $len+8 ); - if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) )) - { - $this->_MBPop (); - return false; - } - - $this->_reqs = array (); - - ////////////////// - // parse response - ////////////////// - - $p = 0; // current position - $max = strlen($response); // max position for checks, to protect against broken responses - - $results = array (); - for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) - { - $results[] = array(); - $result =& $results[$ires]; - - $result["error"] = ""; - $result["warning"] = ""; - - // extract status - list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $result["status"] = $status; - if ( $status!=SEARCHD_OK ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $message = substr ( $response, $p, $len ); $p += $len; - - if ( $status==SEARCHD_WARNING ) - { - $result["warning"] = $message; - } else - { - $result["error"] = $message; - continue; - } - } - - // read schema - $fields = array (); - $attrs = array (); - - list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - while ( $nfields-->0 && $p<$max ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $fields[] = substr ( $response, $p, $len ); $p += $len; - } - $result["fields"] = $fields; - - list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - while ( $nattrs-->0 && $p<$max ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $attr = substr ( $response, $p, $len ); $p += $len; - list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $attrs[$attr] = $type; - } - $result["attrs"] = $attrs; - - // read match count - list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - - // read matches - $idx = -1; - while ( $count-->0 && $p<$max ) - { - // index into result array - $idx++; - - // parse document id and weight - if ( $id64 ) - { - $doc = sphUnpack64 ( substr ( $response, $p, 8 ) ); $p += 8; - list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - } else - { - list ( $doc, $weight ) = array_values ( unpack ( "N*N*", - substr ( $response, $p, 8 ) ) ); - $p += 8; - - if ( PHP_INT_SIZE>=8 ) - { - // x64 route, workaround broken unpack() in 5.2.2+ - if ( $doc<0 ) $doc += (1<<32); - } else - { - // x32 route, workaround php signed/unsigned braindamage - $doc = sprintf ( "%u", $doc ); - } - } - $weight = sprintf ( "%u", $weight ); - - // create match entry - if ( $this->_arrayresult ) - $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); - else - $result["matches"][$doc]["weight"] = $weight; - - // parse and create attributes - $attrvals = array (); - foreach ( $attrs as $attr=>$type ) - { - // handle floats - if ( $type==SPH_ATTR_FLOAT ) - { - list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); - $attrvals[$attr] = $fval; - continue; - } - - // handle everything else as unsigned ints - list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - if ( $type & SPH_ATTR_MULTI ) - { - $attrvals[$attr] = array (); - $nvalues = $val; - while ( $nvalues-->0 && $p<$max ) - { - list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $attrvals[$attr][] = sprintf ( "%u", $val ); - } - } else - { - $attrvals[$attr] = sprintf ( "%u", $val ); - } - } - - if ( $this->_arrayresult ) - $result["matches"][$idx]["attrs"] = $attrvals; - else - $result["matches"][$doc]["attrs"] = $attrvals; - } - - list ( $total, $total_found, $msecs, $words ) = - array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); - $result["total"] = sprintf ( "%u", $total ); - $result["total_found"] = sprintf ( "%u", $total_found ); - $result["time"] = sprintf ( "%.3f", $msecs/1000 ); - $p += 16; - - while ( $words-->0 && $p<$max ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $word = substr ( $response, $p, $len ); $p += $len; - list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; - $result["words"][$word] = array ( - "docs"=>sprintf ( "%u", $docs ), - "hits"=>sprintf ( "%u", $hits ) ); - } - } - - $this->_MBPop (); - return $results; - } - - ///////////////////////////////////////////////////////////////////////////// - // excerpts generation - ///////////////////////////////////////////////////////////////////////////// - - /// connect to searchd server, and generate exceprts (snippets) - /// of given documents for given query. returns false on failure, - /// an array of snippets on success - function BuildExcerpts ( $docs, $index, $words, $opts=array() ) - { - assert ( is_array($docs) ); - assert ( is_string($index) ); - assert ( is_string($words) ); - assert ( is_array($opts) ); - - $this->_MBPush (); - - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop(); - return false; - } - - ///////////////// - // fixup options - ///////////////// - - if ( !isset($opts["before_match"]) ) $opts["before_match"] = ""; - if ( !isset($opts["after_match"]) ) $opts["after_match"] = ""; - if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; - if ( !isset($opts["limit"]) ) $opts["limit"] = 256; - if ( !isset($opts["around"]) ) $opts["around"] = 5; - if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; - if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; - if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; - if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; - - ///////////////// - // build request - ///////////////// - - // v.1.0 req - $flags = 1; // remove spaces - if ( $opts["exact_phrase"] ) $flags |= 2; - if ( $opts["single_passage"] ) $flags |= 4; - if ( $opts["use_boundaries"] ) $flags |= 8; - if ( $opts["weight_order"] ) $flags |= 16; - $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags - $req .= pack ( "N", strlen($index) ) . $index; // req index - $req .= pack ( "N", strlen($words) ) . $words; // req words - - // options - $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; - $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; - $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; - $req .= pack ( "N", (int)$opts["limit"] ); - $req .= pack ( "N", (int)$opts["around"] ); - - // documents - $req .= pack ( "N", count($docs) ); - foreach ( $docs as $doc ) - { - assert ( is_string($doc) ); - $req .= pack ( "N", strlen($doc) ) . $doc; - } - - //////////////////////////// - // send query, get response - //////////////////////////// - - $len = strlen($req); - $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header - $wrote = fwrite ( $fp, $req, $len+8 ); - if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) )) - { - $this->_MBPop (); - return false; - } - - ////////////////// - // parse response - ////////////////// - - $pos = 0; - $res = array (); - $rlen = strlen($response); - for ( $i=0; $i $rlen ) - { - $this->_error = "incomplete reply"; - $this->_MBPop (); - return false; - } - $res[] = $len ? substr ( $response, $pos, $len ) : ""; - $pos += $len; - } - - $this->_MBPop (); - return $res; - } - - - ///////////////////////////////////////////////////////////////////////////// - // keyword generation - ///////////////////////////////////////////////////////////////////////////// - - /// connect to searchd server, and generate keyword list for a given query - /// returns false on failure, - /// an array of words on success - function BuildKeywords ( $query, $index, $hits ) - { - assert ( is_string($query) ); - assert ( is_string($index) ); - assert ( is_bool($hits) ); - - $this->_MBPush (); - - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop(); - return false; - } - - ///////////////// - // build request - ///////////////// - - // v.1.0 req - $req = pack ( "N", strlen($query) ) . $query; // req query - $req .= pack ( "N", strlen($index) ) . $index; // req index - $req .= pack ( "N", (int)$hits ); - - //////////////////////////// - // send query, get response - //////////////////////////// - - $len = strlen($req); - $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header - $wrote = fwrite ( $fp, $req, $len+8 ); - if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) )) - { - $this->_MBPop (); - return false; - } - - ////////////////// - // parse response - ////////////////// - - $pos = 0; - $res = array (); - $rlen = strlen($response); - list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); - $pos += 4; - for ( $i=0; $i<$nwords; $i++ ) - { - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; - $tokenized = $len ? substr ( $response, $pos, $len ) : ""; - $pos += $len; - - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; - $normalized = $len ? substr ( $response, $pos, $len ) : ""; - $pos += $len; - - $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); - - if ( $hits ) - { - list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); - $pos += 8; - $res [$i]["docs"] = $ndocs; - $res [$i]["hits"] = $nhits; - } - - if ( $pos > $rlen ) - { - $this->_error = "incomplete reply"; - $this->_MBPop (); - return false; - } - } - - $this->_MBPop (); - return $res; - } - - function EscapeString ( $string ) - { - $from = array ( '(',')','|','-','!','@','~','"','&', '/' ); - $to = array ( '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/' ); - - return str_replace ( $from, $to, $string ); - } - - ///////////////////////////////////////////////////////////////////////////// - // attribute updates - ///////////////////////////////////////////////////////////////////////////// - - /// update given attribute values on given documents in given indexes - /// returns amount of updated documents (0 or more) on success, or -1 on failure - function UpdateAttributes ( $index, $attrs, $values ) - { - // verify everything - assert ( is_string($index) ); - - assert ( is_array($attrs) ); - foreach ( $attrs as $attr ) - assert ( is_string($attr) ); - - assert ( is_array($values) ); - foreach ( $values as $id=>$entry ) - { - assert ( is_numeric($id) ); - assert ( is_array($entry) ); - assert ( count($entry)==count($attrs) ); - foreach ( $entry as $v ) - assert ( is_int($v) ); - } - - // build request - $req = pack ( "N", strlen($index) ) . $index; - - $req .= pack ( "N", count($attrs) ); - foreach ( $attrs as $attr ) - $req .= pack ( "N", strlen($attr) ) . $attr; - - $req .= pack ( "N", count($values) ); - foreach ( $values as $id=>$entry ) - { - $req .= sphPack64 ( $id ); - foreach ( $entry as $v ) - $req .= pack ( "N", $v ); - } - - // mbstring workaround - $this->_MBPush (); - - // connect, send query, get response - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop (); - return -1; - } - - $len = strlen($req); - $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header - fwrite ( $fp, $req, $len+8 ); - - if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) - { - $this->_MBPop (); - return -1; - } - - // parse response - list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); - $this->_MBPop (); - return $updated; - } -} - -// -// $Id$ -// -- cgit v1.2.1 From 02588069f045ae48984d68c9948c8ecd1c78580d Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 26 Jun 2012 19:06:19 +0530 Subject: [feature/sphinx-fulltext-search] fix config variables config variables now use class property for unique id PHPBB3-10946 Conflicts: phpBB/includes/search/fulltext_sphinx.php --- phpBB/includes/search/fulltext_sphinx.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 9ae6438af2..fb16c5639b 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -226,7 +226,7 @@ class phpbb_search_fulltext_sphinx $config_object = new sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); $config_data = array( - "source source_phpbb_{$this->id}_main" => array( + 'source source_phpbb_' . $this->id . '_main' => array( array('type', 'mysql'), array('sql_host', $dbhost), array('sql_user', $dbuser), @@ -265,7 +265,7 @@ class phpbb_search_fulltext_sphinx array('sql_attr_timestamp' , 'topic_last_post_time'), array('sql_attr_str2ordinal', 'post_subject'), ), - "source source_phpbb_{$this->id}_delta : source_phpbb_{$this->id}_main" => array( + 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array( array('sql_query_pre', ''), array('sql_query_range', ''), array('sql_range_step', ''), @@ -286,9 +286,9 @@ class phpbb_search_fulltext_sphinx p.topic_id = t.topic_id AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'), ), - "index index_phpbb_{$this->id}_main" => array( - array('path', $config['fulltext_sphinx_data_path'] . "index_phpbb_{$this->id}_main"), - array('source', "source_phpbb_{$this->id}_main"), + 'index index_phpbb_' . $this->id . '_main' => array( + array('path', $config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), + array('source', 'source_phpbb_' . $this->id . '_main'), array('docinfo', 'extern'), array('morphology', 'none'), array('stopwords', (file_exists($config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt') && $config['fulltext_sphinx_stopwords']) ? $config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), @@ -298,9 +298,9 @@ class phpbb_search_fulltext_sphinx array('min_prefix_len', '0'), array('min_infix_len', '0'), ), - "index index_phpbb_{$this->id}_delta : index_phpbb_{$this->id}_main" => array( - array('path', $config['fulltext_sphinx_data_path'] . "index_phpbb_{$this->id}_delta"), - array('source', "source_phpbb_{$this->id}_delta"), + 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array( + array('path', $config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'), + array('source', 'source_phpbb_' . $this->id . '_delta'), ), 'indexer' => array( array('mem_limit', $config['fulltext_sphinx_indexer_mem_limit'] . 'M'), -- cgit v1.2.1 From 74a7407927cd5b54328a3941a9926ee35caf17b4 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 00:17:39 +0530 Subject: [feature/sphinx-fulltext-search] improve classes in functions-sphinx.php PHPBB3-10946 --- phpBB/includes/functions_sphinx.php | 38 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_sphinx.php b/phpBB/includes/functions_sphinx.php index 0f83f8cfb5..a4f0e41491 100644 --- a/phpBB/includes/functions_sphinx.php +++ b/phpBB/includes/functions_sphinx.php @@ -46,16 +46,14 @@ class sphinx_config */ function &get_section_by_name($name) { - for ($i = 0, $n = sizeof($this->sections); $i < $n; $i++) + for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++) { // make sure this is really a section object and not a comment - if (is_a($this->sections[$i], 'sphinx_config_section') && $this->sections[$i]->get_name() == $name) + if (($this->sections[$i] instanceof sphinx_config_section) && $this->sections[$i]->get_name() == $name) { return $this->sections[$i]; } } - $null = null; - return $null; } /** @@ -116,7 +114,7 @@ class sphinx_config $section_name = ''; $section_name_comment = ''; $found_opening_bracket = false; - for ($j = 0, $n = strlen($line); $j < $n; $j++) + for ($j = 0, $length = strlen($line); $j < $length; $j++) { if ($line[$j] == '#') { @@ -189,15 +187,15 @@ class sphinx_config $in_value = false; $end_section = false; - // ... then we should prase this line char by char: - // - first there's the variable name - // - then an equal sign - // - the variable value - // - possibly a backslash before the linefeed in this case we need to continue - // parsing the value in the next line - // - a # indicating that the rest of the line is a comment - // - a closing curly bracket indicating the end of this section - for ($j = 0, $n = strlen($line); $j < $n; $j++) + /* ... then we should prase this line char by char: + - first there's the variable name + - then an equal sign + - the variable value + - possibly a backslash before the linefeed in this case we need to continue + parsing the value in the next line + - a # indicating that the rest of the line is a comment + - a closing curly bracket indicating the end of this section*/ + for ($j = 0, $length = strlen($line); $j < $length; $j++) { if ($line[$j] == '#') { @@ -223,7 +221,7 @@ class sphinx_config } else { - if ($line[$j] == '\\' && $j == $n - 1) + if ($line[$j] == '\\' && $j == $length - 1) { $value .= "\n"; $in_value = true; @@ -349,16 +347,14 @@ class sphinx_config_section */ function &get_variable_by_name($name) { - for ($i = 0, $n = sizeof($this->variables); $i < $n; $i++) + for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) { // make sure this is a variable object and not a comment - if (is_a($this->variables[$i], 'sphinx_config_variable') && $this->variables[$i]->get_name() == $name) + if (($this->variables[$i] instanceof sphinx_config_variable) && $this->variables[$i]->get_name() == $name) { return $this->variables[$i]; } } - $null = null; - return $null; } /** @@ -368,10 +364,10 @@ class sphinx_config_section */ function delete_variables_by_name($name) { - for ($i = 0; $i < sizeof($this->variables); $i++) + for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) { // make sure this is a variable object and not a comment - if (is_a($this->variables[$i], 'sphinx_config_variable') && $this->variables[$i]->get_name() == $name) + if (($this->variables[$i] instanceof sphinx_config_variable) && $this->variables[$i]->get_name() == $name) { array_splice($this->variables, $i, 1); $i--; -- cgit v1.2.1 From f609555b1ae335b5ea996bf26ee2846058e5256a Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 00:28:31 +0530 Subject: [feature/sphinx-fulltext-search] integrate sphinx language keys with core Language keys removed from mods folder and added to language/en/acp/search.php PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index fb16c5639b..2e263c1b55 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -733,8 +733,6 @@ class phpbb_search_fulltext_sphinx if (!isset($config['fulltext_sphinx_configured']) || !$config['fulltext_sphinx_configured']) { - $user->add_lang('mods/fulltext_sphinx'); - return $user->lang['FULLTEXT_SPHINX_CONFIGURE_FIRST']; } @@ -902,8 +900,6 @@ class phpbb_search_fulltext_sphinx $this->get_stats(); } - $user->add_lang('mods/fulltext_sphinx'); - return array( $user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0, $user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, @@ -966,8 +962,6 @@ class phpbb_search_fulltext_sphinx { global $user, $config; - $user->add_lang('mods/fulltext_sphinx'); - $config_vars = array( 'fulltext_sphinx_autoconf' => 'bool', 'fulltext_sphinx_autorun' => 'bool', -- cgit v1.2.1 From bfd01f01877bcb9a9be9e2df5c6713c3e338579e Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 01:03:04 +0530 Subject: [feature/sphinx-fulltext-search] remove all reference returns PHPBB3-10946 --- phpBB/includes/functions_sphinx.php | 8 ++++---- phpBB/includes/search/fulltext_sphinx.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_sphinx.php b/phpBB/includes/functions_sphinx.php index a4f0e41491..a93a1d950f 100644 --- a/phpBB/includes/functions_sphinx.php +++ b/phpBB/includes/functions_sphinx.php @@ -44,7 +44,7 @@ class sphinx_config * @param string $name The name of the section that shall be returned * @return sphinx_config_section The section object or null if none was found */ - function &get_section_by_name($name) + function get_section_by_name($name) { for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++) { @@ -62,7 +62,7 @@ class sphinx_config * @param string $name The name for the new section * @return sphinx_config_section The newly created section object */ - function &add_section($name) + function add_section($name) { $this->sections[] = new sphinx_config_section($name, ''); return $this->sections[sizeof($this->sections) - 1]; @@ -345,7 +345,7 @@ class sphinx_config_section * @return sphinx_config_section The first variable object from this section with the * given name or null if none was found */ - function &get_variable_by_name($name) + function get_variable_by_name($name) { for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) { @@ -382,7 +382,7 @@ class sphinx_config_section * @param string $value The value for the new variable * @return sphinx_config_variable Variable object that was created */ - function &create_variable($name, $value) + function create_variable($name, $value) { $this->variables[] = new sphinx_config_variable($name, $value, ''); return $this->variables[sizeof($this->variables) - 1]; diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 2e263c1b55..477b1646fb 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -323,10 +323,10 @@ class phpbb_search_fulltext_sphinx foreach ($config_data as $section_name => $section_data) { - $section = &$config_object->get_section_by_name($section_name); + $section = $config_object->get_section_by_name($section_name); if (!$section) { - $section = &$config_object->add_section($section_name); + $section = $config_object->add_section($section_name); } foreach ($delete as $key => $void) @@ -346,10 +346,10 @@ class phpbb_search_fulltext_sphinx if (!isset($non_unique[$key])) { - $variable = &$section->get_variable_by_name($key); + $variable = $section->get_variable_by_name($key); if (!$variable) { - $variable = &$section->create_variable($key, $value); + $variable = $section->create_variable($key, $value); } else { @@ -358,7 +358,7 @@ class phpbb_search_fulltext_sphinx } else { - $variable = &$section->create_variable($key, $value); + $variable = $section->create_variable($key, $value); } } } -- cgit v1.2.1 From 39f8a5fa9f71724d0abd98cdf7a7d82fc7e7bb0f Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 03:44:03 +0530 Subject: [feature/sphinx-fulltext-search] use sql_build_query for query Uses sql_build_query for JOIN query. Remove casting to int and space for phpbb conventions to be followed PHPBB3-10946 Conflicts: phpBB/includes/search/fulltext_sphinx.php --- phpBB/includes/search/fulltext_sphinx.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 477b1646fb..2690612b1a 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -53,7 +53,7 @@ class phpbb_search_fulltext_sphinx $this->id = $config['avatar_salt']; $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; - $this->sphinx = new SphinxClient (); + $this->sphinx = new SphinxClient(); if (!empty($config['fulltext_sphinx_configured'])) { @@ -648,18 +648,28 @@ class phpbb_search_fulltext_sphinx } else if ($mode != 'post' && $post_id) { - // update topic_last_post_time for full topic - $sql = 'SELECT p1.post_id - FROM ' . POSTS_TABLE . ' p1 - LEFT JOIN ' . POSTS_TABLE . ' p2 ON (p1.topic_id = p2.topic_id) - WHERE p2.post_id = ' . $post_id; + // Update topic_last_post_time for full topic + $sql_array = array( + 'SELECT' => 'p1.post_id', + 'FROM' => array( + POSTS_TABLE => 'p1', + ), + 'LEFT_JOIN' => array(array( + 'FROM' => array( + POSTS_TABLE => 'p2' + ), + 'ON' => 'p1.topic_id = p2.topic_id', + )), + ); + + $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $post_updates = array(); $post_time = time(); while ($row = $db->sql_fetchrow($result)) { - $post_updates[(int)$row['post_id']] = array((int) $post_time); + $post_updates[(int)$row['post_id']] = array($post_time); } $db->sql_freeresult($result); -- cgit v1.2.1 From 10b706674e0fc100ff4e21d5fe100a9b532bb4bf Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 01:49:38 +0530 Subject: [feature/sphinx-fulltext-search] add binlog_path to config binlog files are now added to the data folder. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 2690612b1a..8514b9cabb 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -315,6 +315,7 @@ class phpbb_search_fulltext_sphinx array('max_children', '30'), array('pid_file', $config['fulltext_sphinx_data_path'] . "searchd.pid"), array('max_matches', (string) MAX_MATCHES), + array('binlog_path', $config['fulltext_sphinx_data_path']), ), ); -- cgit v1.2.1 From 97fda78e7d85444f21ba2b10b3d58c4639b85936 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 01:23:57 +0530 Subject: [feature/sphinx-fulltext-search] Make different files for different classes Break the classes in functions-sphinx.php into different files with proper class names according to phpbb class auto loader conventions. PHPBB3-10946 Conflicts: phpBB/includes/search/sphinx/config.php --- phpBB/includes/functions_sphinx.php | 502 ----------------------- phpBB/includes/search/fulltext_sphinx.php | 7 +- phpBB/includes/search/sphinx/config.php | 287 +++++++++++++ phpBB/includes/search/sphinx/config_comment.php | 45 ++ phpBB/includes/search/sphinx/config_section.php | 144 +++++++ phpBB/includes/search/sphinx/config_variable.php | 72 ++++ 6 files changed, 549 insertions(+), 508 deletions(-) delete mode 100644 phpBB/includes/functions_sphinx.php create mode 100644 phpBB/includes/search/sphinx/config.php create mode 100644 phpBB/includes/search/sphinx/config_comment.php create mode 100644 phpBB/includes/search/sphinx/config_section.php create mode 100644 phpBB/includes/search/sphinx/config_variable.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_sphinx.php b/phpBB/includes/functions_sphinx.php deleted file mode 100644 index a93a1d950f..0000000000 --- a/phpBB/includes/functions_sphinx.php +++ /dev/null @@ -1,502 +0,0 @@ -read($filename); - } - } - - /** - * Get a section object by its name - * - * @param string $name The name of the section that shall be returned - * @return sphinx_config_section The section object or null if none was found - */ - function get_section_by_name($name) - { - for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++) - { - // make sure this is really a section object and not a comment - if (($this->sections[$i] instanceof sphinx_config_section) && $this->sections[$i]->get_name() == $name) - { - return $this->sections[$i]; - } - } - } - - /** - * Appends a new empty section to the end of the config - * - * @param string $name The name for the new section - * @return sphinx_config_section The newly created section object - */ - function add_section($name) - { - $this->sections[] = new sphinx_config_section($name, ''); - return $this->sections[sizeof($this->sections) - 1]; - } - - /** - * Parses the config file at the given path, which is stored in $this->loaded for later use - * - * @param string $filename The path to the config file - */ - function read($filename) - { - // split the file into lines, we'll process it line by line - $config_file = file($filename); - - $this->sections = array(); - - $section = null; - $found_opening_bracket = false; - $in_value = false; - - foreach ($config_file as $i => $line) - { - // if the value of a variable continues to the next line because the line break was escaped - // then we don't trim leading space but treat it as a part of the value - if ($in_value) - { - $line = rtrim($line); - } - else - { - $line = trim($line); - } - - // if we're not inside a section look for one - if (!$section) - { - // add empty lines and comments as comment objects to the section list - // that way they're not deleted when reassembling the file from the sections - if (!$line || $line[0] == '#') - { - $this->sections[] = new sphinx_config_comment($config_file[$i]); - continue; - } - else - { - // otherwise we scan the line reading the section name until we find - // an opening curly bracket or a comment - $section_name = ''; - $section_name_comment = ''; - $found_opening_bracket = false; - for ($j = 0, $length = strlen($line); $j < $length; $j++) - { - if ($line[$j] == '#') - { - $section_name_comment = substr($line, $j); - break; - } - - if ($found_opening_bracket) - { - continue; - } - - if ($line[$j] == '{') - { - $found_opening_bracket = true; - continue; - } - - $section_name .= $line[$j]; - } - - // and then we create the new section object - $section_name = trim($section_name); - $section = new sphinx_config_section($section_name, $section_name_comment); - } - } - else // if we're looking for variables inside a section - { - $skip_first = false; - - // if we're not in a value continuing over the line feed - if (!$in_value) - { - // then add empty lines and comments as comment objects to the variable list - // of this section so they're not deleted on reassembly - if (!$line || $line[0] == '#') - { - $section->add_variable(new sphinx_config_comment($config_file[$i])); - continue; - } - - // as long as we haven't yet actually found an opening bracket for this section - // we treat everything as comments so it's not deleted either - if (!$found_opening_bracket) - { - if ($line[0] == '{') - { - $skip_first = true; - $line = substr($line, 1); - $found_opening_bracket = true; - } - else - { - $section->add_variable(new sphinx_config_comment($config_file[$i])); - continue; - } - } - } - - // if we did not find a comment in this line or still add to the previous line's value ... - if ($line || $in_value) - { - if (!$in_value) - { - $name = ''; - $value = ''; - $comment = ''; - $found_assignment = false; - } - $in_value = false; - $end_section = false; - - /* ... then we should prase this line char by char: - - first there's the variable name - - then an equal sign - - the variable value - - possibly a backslash before the linefeed in this case we need to continue - parsing the value in the next line - - a # indicating that the rest of the line is a comment - - a closing curly bracket indicating the end of this section*/ - for ($j = 0, $length = strlen($line); $j < $length; $j++) - { - if ($line[$j] == '#') - { - $comment = substr($line, $j); - break; - } - else if ($line[$j] == '}') - { - $comment = substr($line, $j + 1); - $end_section = true; - break; - } - else if (!$found_assignment) - { - if ($line[$j] == '=') - { - $found_assignment = true; - } - else - { - $name .= $line[$j]; - } - } - else - { - if ($line[$j] == '\\' && $j == $length - 1) - { - $value .= "\n"; - $in_value = true; - continue 2; // go to the next line and keep processing the value in there - } - $value .= $line[$j]; - } - } - - // if a name and an equal sign were found then we have append a new variable object to the section - if ($name && $found_assignment) - { - $section->add_variable(new sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); - continue; - } - - // if we found a closing curly bracket this section has been completed and we can append it to the section list - // and continue with looking for the next section - if ($end_section) - { - $section->set_end_comment($comment); - $this->sections[] = $section; - $section = null; - continue; - } - } - - // if we did not find anything meaningful up to here, then just treat it as a comment - $comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i]; - $section->add_variable(new sphinx_config_comment($comment)); - } - } - - // keep the filename for later use - $this->loaded = $filename; - } - - /** - * Writes the config data into a file - * - * @param string $filename The optional filename into which the config data shall be written. - * If it's not specified it will be written into the file that the config - * was originally read from. - */ - function write($filename = false) - { - if ($filename === false && $this->loaded) - { - $filename = $this->loaded; - } - - $data = ""; - foreach ($this->sections as $section) - { - $data .= $section->to_string(); - } - - $fp = fopen($filename, 'wb'); - fwrite($fp, $data); - fclose($fp); - } -} - -/** -* sphinx_config_section -* Represents a single section inside the sphinx configuration -*/ -class sphinx_config_section -{ - var $name; - var $comment; - var $end_comment; - var $variables = array(); - - /** - * Construct a new section - * - * @param string $name Name of the section - * @param string $comment Comment that should be appended after the name in the - * textual format. - */ - function sphinx_config_section($name, $comment) - { - $this->name = $name; - $this->comment = $comment; - $this->end_comment = ''; - } - - /** - * Add a variable object to the list of variables in this section - * - * @param sphinx_config_variable $variable The variable object - */ - function add_variable($variable) - { - $this->variables[] = $variable; - } - - /** - * Adds a comment after the closing bracket in the textual representation - */ - function set_end_comment($end_comment) - { - $this->end_comment = $end_comment; - } - - /** - * Getter for the name of this section - * - * @return string Section's name - */ - function get_name() - { - return $this->name; - } - - /** - * Get a variable object by its name - * - * @param string $name The name of the variable that shall be returned - * @return sphinx_config_section The first variable object from this section with the - * given name or null if none was found - */ - function get_variable_by_name($name) - { - for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) - { - // make sure this is a variable object and not a comment - if (($this->variables[$i] instanceof sphinx_config_variable) && $this->variables[$i]->get_name() == $name) - { - return $this->variables[$i]; - } - } - } - - /** - * Deletes all variables with the given name - * - * @param string $name The name of the variable objects that are supposed to be removed - */ - function delete_variables_by_name($name) - { - for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) - { - // make sure this is a variable object and not a comment - if (($this->variables[$i] instanceof sphinx_config_variable) && $this->variables[$i]->get_name() == $name) - { - array_splice($this->variables, $i, 1); - $i--; - } - } - } - - /** - * Create a new variable object and append it to the variable list of this section - * - * @param string $name The name for the new variable - * @param string $value The value for the new variable - * @return sphinx_config_variable Variable object that was created - */ - function create_variable($name, $value) - { - $this->variables[] = new sphinx_config_variable($name, $value, ''); - return $this->variables[sizeof($this->variables) - 1]; - } - - /** - * Turns this object into a string which can be written to a config file - * - * @return string Config data in textual form, parsable for sphinx - */ - function to_string() - { - $content = $this->name . " " . $this->comment . "\n{\n"; - - // make sure we don't get too many newlines after the opening bracket - while (trim($this->variables[0]->to_string()) == "") - { - array_shift($this->variables); - } - - foreach ($this->variables as $variable) - { - $content .= $variable->to_string(); - } - $content .= '}' . $this->end_comment . "\n"; - - return $content; - } -} - -/** -* sphinx_config_variable -* Represents a single variable inside the sphinx configuration -*/ -class sphinx_config_variable -{ - var $name; - var $value; - var $comment; - - /** - * Constructs a new variable object - * - * @param string $name Name of the variable - * @param string $value Value of the variable - * @param string $comment Optional comment after the variable in the - * config file - */ - function sphinx_config_variable($name, $value, $comment) - { - $this->name = $name; - $this->value = $value; - $this->comment = $comment; - } - - /** - * Getter for the variable's name - * - * @return string The variable object's name - */ - function get_name() - { - return $this->name; - } - - /** - * Allows changing the variable's value - * - * @param string $value New value for this variable - */ - function set_value($value) - { - $this->value = $value; - } - - /** - * Turns this object into a string readable by sphinx - * - * @return string Config data in textual form - */ - function to_string() - { - return "\t" . $this->name . ' = ' . str_replace("\n", "\\\n", $this->value) . ' ' . $this->comment . "\n"; - } -} - - -/** -* sphinx_config_comment -* Represents a comment inside the sphinx configuration -*/ -class sphinx_config_comment -{ - var $exact_string; - - /** - * Create a new comment - * - * @param string $exact_string The content of the comment including newlines, leading whitespace, etc. - */ - function sphinx_config_comment($exact_string) - { - $this->exact_string = $exact_string; - } - - /** - * Simply returns the comment as it was created - * - * @return string The exact string that was specified in the constructor - */ - function to_string() - { - return $this->exact_string; - } -} - -?> diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 8514b9cabb..6f3c688aed 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -207,11 +207,6 @@ class phpbb_search_fulltext_sphinx // now that we're sure everything was entered correctly, generate a config for the index // we misuse the avatar_salt for this, as it should be unique ;-) - if (!class_exists('sphinx_config')) - { - include($phpbb_root_path . 'includes/functions_sphinx.php'); - } - if (!file_exists($config['fulltext_sphinx_config_path'] . 'sphinx.conf')) { $filename = $config['fulltext_sphinx_config_path'] . 'sphinx.conf'; @@ -223,7 +218,7 @@ class phpbb_search_fulltext_sphinx @fclose($fp); } - $config_object = new sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); + $config_object = new phpbb_search_sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/includes/search/sphinx/config.php new file mode 100644 index 0000000000..966cd0f284 --- /dev/null +++ b/phpBB/includes/search/sphinx/config.php @@ -0,0 +1,287 @@ +read($filename); + } + } + + /** + * Get a section object by its name + * + * @param string $name The name of the section that shall be returned + * @return phpbb_search_sphinx_config_section The section object or null if none was found + */ + function get_section_by_name($name) + { + for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++) + { + // make sure this is really a section object and not a comment + if (($this->sections[$i] instanceof phpbb_search_sphinx_config_section) && $this->sections[$i]->get_name() == $name) + { + return $this->sections[$i]; + } + } + } + + /** + * Appends a new empty section to the end of the config + * + * @param string $name The name for the new section + * @return phpbb_search_sphinx_config_section The newly created section object + */ + function add_section($name) + { + $this->sections[] = new phpbb_search_sphinx_config_section($name, ''); + return $this->sections[sizeof($this->sections) - 1]; + } + + /** + * Parses the config file at the given path, which is stored in $this->loaded for later use + * + * @param string $filename The path to the config file + */ + function read($filename) + { + // split the file into lines, we'll process it line by line + $config_file = file($filename); + + $this->sections = array(); + + $section = null; + $found_opening_bracket = false; + $in_value = false; + + foreach ($config_file as $i => $line) + { + // if the value of a variable continues to the next line because the line break was escaped + // then we don't trim leading space but treat it as a part of the value + if ($in_value) + { + $line = rtrim($line); + } + else + { + $line = trim($line); + } + + // if we're not inside a section look for one + if (!$section) + { + // add empty lines and comments as comment objects to the section list + // that way they're not deleted when reassembling the file from the sections + if (!$line || $line[0] == '#') + { + $this->sections[] = new phpbb_search_sphinx_config_comment($config_file[$i]); + continue; + } + else + { + // otherwise we scan the line reading the section name until we find + // an opening curly bracket or a comment + $section_name = ''; + $section_name_comment = ''; + $found_opening_bracket = false; + for ($j = 0, $length = strlen($line); $j < $length; $j++) + { + if ($line[$j] == '#') + { + $section_name_comment = substr($line, $j); + break; + } + + if ($found_opening_bracket) + { + continue; + } + + if ($line[$j] == '{') + { + $found_opening_bracket = true; + continue; + } + + $section_name .= $line[$j]; + } + + // and then we create the new section object + $section_name = trim($section_name); + $section = new phpbb_search_sphinx_config_section($section_name, $section_name_comment); + } + } + else // if we're looking for variables inside a section + { + $skip_first = false; + + // if we're not in a value continuing over the line feed + if (!$in_value) + { + // then add empty lines and comments as comment objects to the variable list + // of this section so they're not deleted on reassembly + if (!$line || $line[0] == '#') + { + $section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); + continue; + } + + // as long as we haven't yet actually found an opening bracket for this section + // we treat everything as comments so it's not deleted either + if (!$found_opening_bracket) + { + if ($line[0] == '{') + { + $skip_first = true; + $line = substr($line, 1); + $found_opening_bracket = true; + } + else + { + $section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); + continue; + } + } + } + + // if we did not find a comment in this line or still add to the previous line's value ... + if ($line || $in_value) + { + if (!$in_value) + { + $name = ''; + $value = ''; + $comment = ''; + $found_assignment = false; + } + $in_value = false; + $end_section = false; + + /* ... then we should prase this line char by char: + - first there's the variable name + - then an equal sign + - the variable value + - possibly a backslash before the linefeed in this case we need to continue + parsing the value in the next line + - a # indicating that the rest of the line is a comment + - a closing curly bracket indicating the end of this section*/ + for ($j = 0, $length = strlen($line); $j < $length; $j++) + { + if ($line[$j] == '#') + { + $comment = substr($line, $j); + break; + } + else if ($line[$j] == '}') + { + $comment = substr($line, $j + 1); + $end_section = true; + break; + } + else if (!$found_assignment) + { + if ($line[$j] == '=') + { + $found_assignment = true; + } + else + { + $name .= $line[$j]; + } + } + else + { + if ($line[$j] == '\\' && $j == $length - 1) + { + $value .= "\n"; + $in_value = true; + continue 2; // go to the next line and keep processing the value in there + } + $value .= $line[$j]; + } + } + + // if a name and an equal sign were found then we have append a new variable object to the section + if ($name && $found_assignment) + { + $section->add_variable(new phpbb_search_sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); + continue; + } + + // if we found a closing curly bracket this section has been completed and we can append it to the section list + // and continue with looking for the next section + if ($end_section) + { + $section->set_end_comment($comment); + $this->sections[] = $section; + $section = null; + continue; + } + } + + // if we did not find anything meaningful up to here, then just treat it as a comment + $comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i]; + $section->add_variable(new phpbb_search_sphinx_config_comment($comment)); + } + } + + // keep the filename for later use + $this->loaded = $filename; + } + + /** + * Writes the config data into a file + * + * @param string $filename The optional filename into which the config data shall be written. + * If it's not specified it will be written into the file that the config + * was originally read from. + */ + function write($filename = false) + { + if ($filename === false && $this->loaded) + { + $filename = $this->loaded; + } + + $data = ""; + foreach ($this->sections as $section) + { + $data .= $section->to_string(); + } + + $fp = fopen($filename, 'wb'); + fwrite($fp, $data); + fclose($fp); + } +} diff --git a/phpBB/includes/search/sphinx/config_comment.php b/phpBB/includes/search/sphinx/config_comment.php new file mode 100644 index 0000000000..63d3488aef --- /dev/null +++ b/phpBB/includes/search/sphinx/config_comment.php @@ -0,0 +1,45 @@ +exact_string = $exact_string; + } + + /** + * Simply returns the comment as it was created + * + * @return string The exact string that was specified in the constructor + */ + function to_string() + { + return $this->exact_string; + } +} diff --git a/phpBB/includes/search/sphinx/config_section.php b/phpBB/includes/search/sphinx/config_section.php new file mode 100644 index 0000000000..529254dd5a --- /dev/null +++ b/phpBB/includes/search/sphinx/config_section.php @@ -0,0 +1,144 @@ +name = $name; + $this->comment = $comment; + $this->end_comment = ''; + } + + /** + * Add a variable object to the list of variables in this section + * + * @param phpbb_search_sphinx_config_variable $variable The variable object + */ + function add_variable($variable) + { + $this->variables[] = $variable; + } + + /** + * Adds a comment after the closing bracket in the textual representation + */ + function set_end_comment($end_comment) + { + $this->end_comment = $end_comment; + } + + /** + * Getter for the name of this section + * + * @return string Section's name + */ + function get_name() + { + return $this->name; + } + + /** + * Get a variable object by its name + * + * @param string $name The name of the variable that shall be returned + * @return phpbb_search_sphinx_config_section The first variable object from this section with the + * given name or null if none was found + */ + function get_variable_by_name($name) + { + for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) + { + // make sure this is a variable object and not a comment + if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name) + { + return $this->variables[$i]; + } + } + } + + /** + * Deletes all variables with the given name + * + * @param string $name The name of the variable objects that are supposed to be removed + */ + function delete_variables_by_name($name) + { + for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) + { + // make sure this is a variable object and not a comment + if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name) + { + array_splice($this->variables, $i, 1); + $i--; + } + } + } + + /** + * Create a new variable object and append it to the variable list of this section + * + * @param string $name The name for the new variable + * @param string $value The value for the new variable + * @return phpbb_search_sphinx_config_variable Variable object that was created + */ + function create_variable($name, $value) + { + $this->variables[] = new phpbb_search_sphinx_config_variable($name, $value, ''); + return $this->variables[sizeof($this->variables) - 1]; + } + + /** + * Turns this object into a string which can be written to a config file + * + * @return string Config data in textual form, parsable for sphinx + */ + function to_string() + { + $content = $this->name . ' ' . $this->comment . "\n{\n"; + + // make sure we don't get too many newlines after the opening bracket + while (trim($this->variables[0]->to_string()) == '') + { + array_shift($this->variables); + } + + foreach ($this->variables as $variable) + { + $content .= $variable->to_string(); + } + $content .= '}' . $this->end_comment . "\n"; + + return $content; + } +} diff --git a/phpBB/includes/search/sphinx/config_variable.php b/phpBB/includes/search/sphinx/config_variable.php new file mode 100644 index 0000000000..dd7836f7c8 --- /dev/null +++ b/phpBB/includes/search/sphinx/config_variable.php @@ -0,0 +1,72 @@ +name = $name; + $this->value = $value; + $this->comment = $comment; + } + + /** + * Getter for the variable's name + * + * @return string The variable object's name + */ + function get_name() + { + return $this->name; + } + + /** + * Allows changing the variable's value + * + * @param string $value New value for this variable + */ + function set_value($value) + { + $this->value = $value; + } + + /** + * Turns this object into a string readable by sphinx + * + * @return string Config data in textual form + */ + function to_string() + { + return "\t" . $this->name . ' = ' . str_replace("\n", "\\\n", $this->value) . ' ' . $this->comment . "\n"; + } +} -- cgit v1.2.1 From 4a11a7b97027743b8239d31a4d51824bd807c5ac Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 03:03:15 +0530 Subject: [feature/sphinx-fulltext-search] add sphinx_table constant to constants.php PHPBB3-10946 --- phpBB/includes/constants.php | 1 + phpBB/includes/search/fulltext_sphinx.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 66d2a003c6..68af41ab20 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -260,6 +260,7 @@ define('SESSIONS_TABLE', $table_prefix . 'sessions'); define('SESSIONS_KEYS_TABLE', $table_prefix . 'sessions_keys'); define('SITELIST_TABLE', $table_prefix . 'sitelist'); define('SMILIES_TABLE', $table_prefix . 'smilies'); +define('SPHINX_TABLE', $table_prefix . 'sphinx'); define('STYLES_TABLE', $table_prefix . 'styles'); define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template'); define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data'); diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 6f3c688aed..53bff898eb 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -26,7 +26,6 @@ require($phpbb_root_path . "includes/sphinxapi-0.9.8." . $phpEx); define('INDEXER_NAME', 'indexer'); define('SEARCHD_NAME', 'searchd'); -define('SPHINX_TABLE', $table_prefix . 'sphinx'); define('MAX_MATCHES', 20000); define('CONNECT_RETRIES', 3); -- cgit v1.2.1 From 06eeed058df75c41496c5306bfa35725c45cf5f3 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 03:17:45 +0530 Subject: [feature/sphinx-fulltext-search] remove unused arrays PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 53bff898eb..4c0adcd99e 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -395,14 +395,7 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetMatchMode(SPH_MATCH_ANY); } - $match = array(); - // Keep quotes - $match[] = "#"#"; - // KeepNew lines - $match[] = "#[\n]+#"; - - $replace = array('"', " "); - + // Keep quotes and new lines $keywords = str_replace(array('"', "\n"), array('"', ' '), trim($keywords)); if (strlen($keywords) > 0) -- cgit v1.2.1 From 0e9174d168a82bde16ec59d615e19b85a50cebcf Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 05:06:51 +0530 Subject: [feature/sphinx-fulltext-search] use keywords_search instead of get_name using keyword_search method instead of get_name to distinguish between the search backend classes present in includes/search and other helper classes. PHPBB3-10946 --- phpBB/includes/acp/acp_search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 54a3e7aaa1..82d9b021fe 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -598,7 +598,7 @@ class acp_search { global $phpbb_root_path, $phpEx, $user; - if (!class_exists($type) || !method_exists($type, 'get_name')) + if (!class_exists($type) || !method_exists($type, 'keyword_search')) { $error = $user->lang['NO_SUCH_SEARCH_MODULE']; return $error; -- cgit v1.2.1 From 2503581cd562b39a108821da85cc0175735e24a5 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 02:33:02 +0530 Subject: [feature/sphinx-fulltext-search] add class properties indexes & sphinx PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 4c0adcd99e..4ace7c9753 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -44,6 +44,8 @@ class phpbb_search_fulltext_sphinx var $search_query; var $common_words = array(); var $id; + var $indexes; + var $sphinx; public function __construct(&$error) { -- cgit v1.2.1 From 8dcdf8a9732a570f26fee802af4bfcbd25f16ec2 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 12:01:14 +0530 Subject: [feature/sphinx-fulltext-search] add docblock and access modifiers PHPBB3-10946 Conflicts: phpBB/includes/search/fulltext_sphinx.php --- phpBB/includes/search/fulltext_sphinx.php | 85 +++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 4ace7c9753..82addca28a 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -38,15 +38,21 @@ define('CONNECT_WAIT_TIME', 300); */ class phpbb_search_fulltext_sphinx { - var $stats = array(); - var $word_length = array(); - var $split_words = array(); - var $search_query; - var $common_words = array(); - var $id; - var $indexes; - var $sphinx; + private $stats = array(); + private $split_words = array(); + private $id; + private $indexes; + private $sphinx; + public $word_length = array(); + public $search_query; + public $common_words = array(); + /** + * Constructor + * Creates a new phpbb_search_fulltext_postgres, which is used as a search backend. + * + * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false + */ public function __construct(&$error) { global $config; @@ -81,6 +87,8 @@ class phpbb_search_fulltext_sphinx * Returns the name of this search backend to be displayed to administrators * * @return string Name + * + * @access public */ public function get_name() { @@ -89,6 +97,10 @@ class phpbb_search_fulltext_sphinx /** * Checks permissions and paths, if everything is correct it generates the config file + * + * @return string|bool Language key of the error/incompatiblity occured + * + * @access public */ function init() { @@ -110,6 +122,13 @@ class phpbb_search_fulltext_sphinx return false; } + /** + * Updates the config file sphinx.conf and generates the same in case autoconf is selected + * + * @return string|bool Language key of the error/incompatiblity occured otherwise false + * + * @access private + */ function config_updated() { global $db, $user, $config, $phpbb_root_path, $phpEx; @@ -378,6 +397,8 @@ class phpbb_search_fulltext_sphinx * @param string $keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return false if no valid keywords were found and otherwise true + * + * @access public */ function split_keywords(&$keywords, $terms) { @@ -619,14 +640,14 @@ class phpbb_search_fulltext_sphinx /** * Updates wordlist and wordmatch tables when a message is posted or changed * - * @param string $mode Contains the post mode: edit, post, reply, quote - * @param int $post_id The id of the post which is modified/created - * @param string &$message New or updated post content - * @param string &$subject New or updated post subject - * @param int $poster_id Post author's user id - * @param int $forum_id The id of the forum in which the post is located + * @param string $mode Contains the post mode: edit, post, reply, quote + * @param int $post_id The id of the post which is modified/created + * @param string &$message New or updated post content + * @param string &$subject New or updated post subject + * @param int $poster_id Post author's user id + * @param int $forum_id The id of the forum in which the post is located * - * @access public + * @access public */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { @@ -686,6 +707,8 @@ class phpbb_search_fulltext_sphinx /** * Delete a post from the index after it was deleted + * + * @access public */ function index_remove($post_ids, $author_ids, $forum_ids) { @@ -700,6 +723,8 @@ class phpbb_search_fulltext_sphinx /** * Destroy old cache entries + * + * @access public */ function tidy($create = false) { @@ -724,6 +749,10 @@ class phpbb_search_fulltext_sphinx /** * Create sphinx table + * + * @return string|bool error string is returned incase of errors otherwise false + * + * @access public */ function create_index($acp_module, $u_action) { @@ -758,6 +787,10 @@ class phpbb_search_fulltext_sphinx /** * Drop sphinx table + * + * @return string|bool error string is returned incase of errors otherwise false + * + * @access public */ function delete_index($acp_module, $u_action) { @@ -785,6 +818,10 @@ class phpbb_search_fulltext_sphinx /** * Returns true if the sphinx table was created + * + * @return bool true if sphinx table was created + * + * @access public */ function index_created($allow_new_files = true) { @@ -817,6 +854,8 @@ class phpbb_search_fulltext_sphinx /** * Kills the searchd process and makes sure there's no locks left over + * + * @access private */ function shutdown_searchd() { @@ -846,6 +885,8 @@ class phpbb_search_fulltext_sphinx * files by calling shutdown_searchd. * * @return boolean Whether searchd is running or not + * + * @access private */ function searchd_running() { @@ -890,6 +931,10 @@ class phpbb_search_fulltext_sphinx /** * Returns an associative array containing information about the indexes + * + * @return string|bool Language string of error false otherwise + * + * @access public */ function index_stats() { @@ -910,6 +955,8 @@ class phpbb_search_fulltext_sphinx /** * Collects stats that can be displayed on the index maintenance page + * + * @access private */ function get_stats() { @@ -957,6 +1004,10 @@ class phpbb_search_fulltext_sphinx /** * Returns a list of options for the ACP to display + * + * @return associative array containing template and config variables + * + * @access public */ function acp() { @@ -1112,6 +1163,8 @@ class phpbb_search_fulltext_sphinx * * @param string $path Path from which files shall be deleted * @param string $pattern PCRE pattern that a file needs to match in order to be deleted +* +* @access private */ function sphinx_unlink_by_pattern($path, $pattern) { @@ -1132,6 +1185,8 @@ function sphinx_unlink_by_pattern($path, $pattern) * @param string $file The filename from which the lines shall be read * @param int $amount The number of lines to be read from the end * @return string Last lines of the file +* +* @access private */ function sphinx_read_last_lines($file, $amount) { -- cgit v1.2.1 From e486f4389c99c27cb723d4e9fd437130752f891e Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 03:51:40 +0530 Subject: [feature/sphinx-fulltext-search] remove autoconf Remove all code related to sphinx automatic configuration and all exec calls. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 386 +----------------------------- 1 file changed, 1 insertion(+), 385 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 82addca28a..984bda68c2 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -24,9 +24,6 @@ if (!defined('IN_PHPBB')) global $phpbb_root_path, $phpEx, $table_prefix; require($phpbb_root_path . "includes/sphinxapi-0.9.8." . $phpEx); -define('INDEXER_NAME', 'indexer'); -define('SEARCHD_NAME', 'searchd'); - define('MAX_MATCHES', 20000); define('CONNECT_RETRIES', 3); define('CONNECT_WAIT_TIME', 300); @@ -64,15 +61,6 @@ class phpbb_search_fulltext_sphinx if (!empty($config['fulltext_sphinx_configured'])) { - if ($config['fulltext_sphinx_autorun'] && !file_exists($config['fulltext_sphinx_data_path'] . 'searchd.pid') && $this->index_created(true)) - { - $this->shutdown_searchd(); -// $cwd = getcwd(); -// chdir($config['fulltext_sphinx_bin_path']); - exec($config['fulltext_sphinx_bin_path'] . SEARCHD_NAME . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf >> ' . $config['fulltext_sphinx_data_path'] . 'log/searchd-startup.log 2>&1 &'); -// chdir($cwd); - } - // we only support localhost for now $this->sphinx->SetServer('localhost', (isset($config['fulltext_sphinx_port']) && $config['fulltext_sphinx_port']) ? (int) $config['fulltext_sphinx_port'] : 3312); } @@ -133,111 +121,10 @@ class phpbb_search_fulltext_sphinx { global $db, $user, $config, $phpbb_root_path, $phpEx; - if ($config['fulltext_sphinx_autoconf']) - { - $paths = array('fulltext_sphinx_bin_path', 'fulltext_sphinx_config_path', 'fulltext_sphinx_data_path'); - - // check for completeness and add trailing slash if it's not present - foreach ($paths as $path) - { - if (empty($config[$path])) - { - return $user->lang['FULLTEXT_SPHINX_UNCONFIGURED']; - } - if ($config[$path] && substr($config[$path], -1) != '/') - { - set_config($path, $config[$path] . '/'); - } - } - } - - $executables = array( - $config['fulltext_sphinx_bin_path'] . INDEXER_NAME, - $config['fulltext_sphinx_bin_path'] . SEARCHD_NAME, - ); - - if ($config['fulltext_sphinx_autorun']) - { - foreach ($executables as $executable) - { - if (!file_exists($executable)) - { - return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_FOUND'], $executable); - } - - if (!function_exists('exec')) - { - return $user->lang['FULLTEXT_SPHINX_REQUIRES_EXEC']; - } - - $output = array(); - @exec($executable, $output); - - $output = implode("\n", $output); - if (strpos($output, 'Sphinx ') === false) - { - return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_EXECUTABLE'], $executable); - } - } - } - - $writable_paths = array( - $config['fulltext_sphinx_config_path'] => array('config' => 'fulltext_sphinx_autoconf', 'subdir' => false), - $config['fulltext_sphinx_data_path'] => array('config' => 'fulltext_sphinx_autorun', 'subdir' => 'log'), - $config['fulltext_sphinx_data_path'] . 'log/' => array('config' => 'fulltext_sphinx_autorun', 'subdir' => false), - ); - - foreach ($writable_paths as $path => $info) - { - if ($config[$info['config']]) - { - // make sure directory exists - // if we could drop the @ here and figure out whether the file really - // doesn't exist or whether open_basedir is in effect, would be nice - if (!@file_exists($path)) - { - return sprintf($user->lang['FULLTEXT_SPHINX_DIRECTORY_NOT_FOUND'], $path); - } - - // now check if it is writable by storing a simple file - $filename = $path . 'write_test'; - $fp = @fopen($filename, 'wb'); - if ($fp === false) - { - return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_WRITABLE'], $filename); - } - @fclose($fp); - - @unlink($filename); - - if ($info['subdir'] !== false) - { - if (!is_dir($path . $info['subdir'])) - { - mkdir($path . $info['subdir']); - } - } - } - } - - if ($config['fulltext_sphinx_autoconf']) - { include ($phpbb_root_path . 'config.' . $phpEx); // now that we're sure everything was entered correctly, generate a config for the index // we misuse the avatar_salt for this, as it should be unique ;-) - - if (!file_exists($config['fulltext_sphinx_config_path'] . 'sphinx.conf')) - { - $filename = $config['fulltext_sphinx_config_path'] . 'sphinx.conf'; - $fp = @fopen($filename, 'wb'); - if ($fp === false) - { - return sprintf($user->lang['FULLTEXT_SPHINX_FILE_NOT_WRITABLE'], $filename); - } - @fclose($fp); - } - $config_object = new phpbb_search_sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); $config_data = array( @@ -379,12 +266,8 @@ class phpbb_search_fulltext_sphinx } } - $config_object->write($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); - } - set_config('fulltext_sphinx_configured', '1'); - $this->shutdown_searchd(); $this->tidy(); return false; @@ -689,20 +572,6 @@ class phpbb_search_fulltext_sphinx $this->sphinx->UpdateAttributes($this->indexes, array('topic_last_post_time'), $post_updates); } } - - if ($config['fulltext_sphinx_autorun']) - { - if ($this->index_created()) - { - $rotate = ($this->searchd_running()) ? ' --rotate' : ''; - - $cwd = getcwd(); - chdir($config['fulltext_sphinx_bin_path']); - exec('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_delta >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); - var_dump('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_delta >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); - chdir($cwd); - } - } } /** @@ -730,20 +599,6 @@ class phpbb_search_fulltext_sphinx { global $config; - if ($config['fulltext_sphinx_autorun']) - { - if ($this->index_created() || $create) - { - $rotate = ($this->searchd_running()) ? ' --rotate' : ''; - - $cwd = getcwd(); - chdir($config['fulltext_sphinx_bin_path']); - exec('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_main >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); - exec('./' . INDEXER_NAME . $rotate . ' --config ' . $config['fulltext_sphinx_config_path'] . 'sphinx.conf index_phpbb_' . $this->id . '_delta >> ' . $config['fulltext_sphinx_data_path'] . 'log/indexer.log 2>&1 &'); - chdir($cwd); - } - } - set_config('search_last_gc', time(), true); } @@ -758,8 +613,6 @@ class phpbb_search_fulltext_sphinx { global $db, $user, $config; - $this->shutdown_searchd(); - if (!isset($config['fulltext_sphinx_configured']) || !$config['fulltext_sphinx_configured']) { return $user->lang['FULLTEXT_SPHINX_CONFIGURE_FIRST']; @@ -780,8 +633,6 @@ class phpbb_search_fulltext_sphinx // start indexing process $this->tidy(true); - $this->shutdown_searchd(); - return false; } @@ -796,13 +647,6 @@ class phpbb_search_fulltext_sphinx { global $db, $config; - $this->shutdown_searchd(); - - if ($config['fulltext_sphinx_autorun']) - { - sphinx_unlink_by_pattern($config['fulltext_sphinx_data_path'], '#^index_phpbb_' . $this->id . '.*$#'); - } - if (!$this->index_created()) { return false; @@ -811,8 +655,6 @@ class phpbb_search_fulltext_sphinx $sql = 'DROP TABLE ' . SPHINX_TABLE; $db->sql_query($sql); - $this->shutdown_searchd(); - return false; } @@ -836,99 +678,12 @@ class phpbb_search_fulltext_sphinx if ($row) { - if ($config['fulltext_sphinx_autorun']) - { - if ((file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main.spd') && file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta.spd')) || ($allow_new_files && file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main.new.spd') && file_exists($config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta.new.spd'))) - { - $created = true; - } - } - else - { - $created = true; - } + $created = true; } return $created; } - /** - * Kills the searchd process and makes sure there's no locks left over - * - * @access private - */ - function shutdown_searchd() - { - global $config; - - if ($config['fulltext_sphinx_autorun']) - { - if (!function_exists('exec')) - { - set_config('fulltext_sphinx_autorun', '0'); - return; - } - - exec('killall -9 ' . SEARCHD_NAME . ' >> /dev/null 2>&1 &'); - - if (file_exists($config['fulltext_sphinx_data_path'] . 'searchd.pid')) - { - unlink($config['fulltext_sphinx_data_path'] . 'searchd.pid'); - } - - sphinx_unlink_by_pattern($config['fulltext_sphinx_data_path'], '#^.*\.spl$#'); - } - } - - /** - * Checks whether searchd is running, if it's not running it makes sure there's no left over - * files by calling shutdown_searchd. - * - * @return boolean Whether searchd is running or not - * - * @access private - */ - function searchd_running() - { - global $config; - - // if we cannot manipulate the service assume it is running - if (!$config['fulltext_sphinx_autorun']) - { - return true; - } - - if (file_exists($config['fulltext_sphinx_data_path'] . 'searchd.pid')) - { - $pid = trim(file_get_contents($config['fulltext_sphinx_data_path'] . 'searchd.pid')); - - if ($pid) - { - $output = array(); - $pidof_command = 'pidof'; - - exec('whereis -b pidof', $output); - if (sizeof($output) > 1) - { - $output = explode(' ', trim($output[0])); - $pidof_command = $output[1]; // 0 is pidof: - } - - $output = array(); - exec($pidof_command . ' ' . SEARCHD_NAME, $output); - if (sizeof($output) && (trim($output[0]) == $pid || trim($output[1]) == $pid)) - { - return true; - } - } - } - - // make sure it's really not running - $this->shutdown_searchd(); - - return false; - } - /** * Returns an associative array containing information about the indexes * @@ -980,26 +735,6 @@ class phpbb_search_fulltext_sphinx } $this->stats['last_searches'] = ''; - if ($config['fulltext_sphinx_autorun']) - { - if (file_exists($config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log')) - { - $last_searches = explode("\n", utf8_htmlspecialchars(sphinx_read_last_lines($config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log', 3))); - - foreach($last_searches as $i => $search) - { - if (strpos($search, '[' . $this->indexes . ']') !== false) - { - $last_searches[$i] = str_replace('[' . $this->indexes . ']', '', $search); - } - else - { - $last_searches[$i] = ''; - } - } - $this->stats['last_searches'] = implode("\n", $last_searches); - } - } } /** @@ -1014,8 +749,6 @@ class phpbb_search_fulltext_sphinx global $user, $config; $config_vars = array( - 'fulltext_sphinx_autoconf' => 'bool', - 'fulltext_sphinx_autorun' => 'bool', 'fulltext_sphinx_config_path' => 'string', 'fulltext_sphinx_data_path' => 'string', 'fulltext_sphinx_bin_path' => 'string', @@ -1025,8 +758,6 @@ class phpbb_search_fulltext_sphinx ); $defaults = array( - 'fulltext_sphinx_autoconf' => '1', - 'fulltext_sphinx_autorun' => '1', 'fulltext_sphinx_indexer_mem_limit' => '512', ); @@ -1043,57 +774,8 @@ class phpbb_search_fulltext_sphinx } } - $no_autoconf = false; - $no_autorun = false; $bin_path = $config['fulltext_sphinx_bin_path']; - // try to guess the path if it is empty - if (empty($bin_path)) - { - if (@file_exists('/usr/local/bin/' . INDEXER_NAME) && @file_exists('/usr/local/bin/' . SEARCHD_NAME)) - { - $bin_path = '/usr/local/bin/'; - } - else if (@file_exists('/usr/bin/' . INDEXER_NAME) && @file_exists('/usr/bin/' . SEARCHD_NAME)) - { - $bin_path = '/usr/bin/'; - } - else - { - $output = array(); - if (!function_exists('exec') || null === @exec('whereis -b ' . INDEXER_NAME, $output)) - { - $no_autorun = true; - } - else if (sizeof($output)) - { - $output = explode(' ', $output[0]); - array_shift($output); // remove indexer: - - foreach ($output as $path) - { - $path = dirname($path) . '/'; - - if (file_exists($path . INDEXER_NAME) && file_exists($path . SEARCHD_NAME)) - { - $bin_path = $path; - break; - } - } - } - } - } - - if ($no_autorun) - { - set_config('fulltext_sphinx_autorun', '0'); - } - - if ($no_autoconf) - { - set_config('fulltext_sphinx_autoconf', '0'); - } - // rewrite config if fulltext sphinx is enabled if ($config['fulltext_sphinx_autoconf'] && isset($config['fulltext_sphinx_configured']) && $config['fulltext_sphinx_configured']) { @@ -1115,14 +797,6 @@ class phpbb_search_fulltext_sphinx $tpl = ' ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. ' -
-

' . $user->lang['FULLTEXT_SPHINX_AUTOCONF_EXPLAIN'] . '
-
-
-
-

' . $user->lang['FULLTEXT_SPHINX_AUTORUN_EXPLAIN'] . '
-
-

' . $user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
@@ -1157,61 +831,3 @@ class phpbb_search_fulltext_sphinx ); } } - -/** -* Deletes all files from a directory that match a certain pattern -* -* @param string $path Path from which files shall be deleted -* @param string $pattern PCRE pattern that a file needs to match in order to be deleted -* -* @access private -*/ -function sphinx_unlink_by_pattern($path, $pattern) -{ - $dir = opendir($path); - while (false !== ($file = readdir($dir))) - { - if (is_file($path . $file) && preg_match($pattern, $file)) - { - unlink($path . $file); - } - } - closedir($dir); -} - -/** -* Reads the last from a file -* -* @param string $file The filename from which the lines shall be read -* @param int $amount The number of lines to be read from the end -* @return string Last lines of the file -* -* @access private -*/ -function sphinx_read_last_lines($file, $amount) -{ - $fp = fopen($file, 'r'); - fseek($fp, 0, SEEK_END); - - $c = ''; - $i = 0; - - while ($i < $amount) - { - fseek($fp, -2, SEEK_CUR); - $c = fgetc($fp); - if ($c == "\n") - { - $i++; - } - if (feof($fp)) - { - break; - } - } - - $string = fread($fp, 8192); - fclose($fp); - - return $string; -} -- cgit v1.2.1 From 88089194e570edb77240138695034358062ffa58 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 03:55:23 +0530 Subject: [feature/sphinx-fulltext-search] prefix sphinx with constant names All constant names are prefixed with SPHINX_ PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 984bda68c2..7386833151 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -24,9 +24,9 @@ if (!defined('IN_PHPBB')) global $phpbb_root_path, $phpEx, $table_prefix; require($phpbb_root_path . "includes/sphinxapi-0.9.8." . $phpEx); -define('MAX_MATCHES', 20000); -define('CONNECT_RETRIES', 3); -define('CONNECT_WAIT_TIME', 300); +define('SPHINX_MAX_MATCHES', 20000); +define('SPHINX_CONNECT_RETRIES', 3); +define('SPHINX_CONNECT_WAIT_TIME', 300); /** * fulltext_sphinx @@ -216,7 +216,7 @@ class phpbb_search_fulltext_sphinx array('read_timeout', '5'), array('max_children', '30'), array('pid_file', $config['fulltext_sphinx_data_path'] . "searchd.pid"), - array('max_matches', (string) MAX_MATCHES), + array('max_matches', (string) SPHINX_MAX_MATCHES), array('binlog_path', $config['fulltext_sphinx_data_path']), ), ); @@ -451,14 +451,14 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetFilter('deleted', array(0)); - $this->sphinx->SetLimits($start, (int) $per_page, MAX_MATCHES); + $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); // could be connection to localhost:3312 failed (errno=111, msg=Connection refused) during rotate, retry if so - $retries = CONNECT_RETRIES; + $retries = SPHINX_CONNECT_RETRIES; while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--) { - usleep(CONNECT_WAIT_TIME); + usleep(SPHINX_CONNECT_WAIT_TIME); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); } -- cgit v1.2.1 From 569db1471b3000512232732a790d8653250e8012 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 04:15:35 +0530 Subject: [feature/sphinx-fulltext-search] fix stopwords option Stopwords option can be configured in ACP to generate correct sphinx config file. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 7386833151..710c3d56be 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -193,7 +193,7 @@ class phpbb_search_fulltext_sphinx array('source', 'source_phpbb_' . $this->id . '_main'), array('docinfo', 'extern'), array('morphology', 'none'), - array('stopwords', (file_exists($config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt') && $config['fulltext_sphinx_stopwords']) ? $config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), + array('stopwords', $config['fulltext_sphinx_stopwords'] ? $config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), array('min_word_len', '2'), array('charset_type', 'utf-8'), array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), @@ -759,6 +759,7 @@ class phpbb_search_fulltext_sphinx $defaults = array( 'fulltext_sphinx_indexer_mem_limit' => '512', + 'fulltext_sphinx_stopwords' => '0', ); foreach ($config_vars as $config_var => $type) @@ -774,27 +775,6 @@ class phpbb_search_fulltext_sphinx } } - $bin_path = $config['fulltext_sphinx_bin_path']; - - // rewrite config if fulltext sphinx is enabled - if ($config['fulltext_sphinx_autoconf'] && isset($config['fulltext_sphinx_configured']) && $config['fulltext_sphinx_configured']) - { - $this->config_updated(); - } - - // check whether stopwords file is available and enabled - if (@file_exists($config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt')) - { - $stopwords_available = true; - $stopwords_active = $config['fulltext_sphinx_stopwords']; - } - else - { - $stopwords_available = false; - $stopwords_active = false; - set_config('fulltext_sphinx_stopwords', '0'); - } - $tpl = ' ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. '
@@ -809,11 +789,11 @@ class phpbb_search_fulltext_sphinx

' . $user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
- ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_AFTER']. '

' . $user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
-
+
+ ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_AFTER']. '

' . $user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
-- cgit v1.2.1 From d2e42d7d619100695e0efe8d472c71f61cbfcb45 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 04:53:51 +0530 Subject: [feature/sphinx-fulltext-search] remove unnecessary code Some extra conditions and variables used in autoconf are removed. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 710c3d56be..48855ef7d8 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -59,11 +59,8 @@ class phpbb_search_fulltext_sphinx $this->sphinx = new SphinxClient(); - if (!empty($config['fulltext_sphinx_configured'])) - { - // we only support localhost for now - $this->sphinx->SetServer('localhost', (isset($config['fulltext_sphinx_port']) && $config['fulltext_sphinx_port']) ? (int) $config['fulltext_sphinx_port'] : 3312); - } + // We only support localhost for now + $this->sphinx->SetServer('localhost', (isset($config['fulltext_sphinx_port']) && $config['fulltext_sphinx_port']) ? (int) $config['fulltext_sphinx_port'] : 3312); $config['fulltext_sphinx_min_word_len'] = 2; $config['fulltext_sphinx_max_word_len'] = 400; @@ -125,7 +122,7 @@ class phpbb_search_fulltext_sphinx // now that we're sure everything was entered correctly, generate a config for the index // we misuse the avatar_salt for this, as it should be unique ;-) - $config_object = new phpbb_search_sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); + $config_object = new phpbb_search_sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( @@ -266,10 +263,6 @@ class phpbb_search_fulltext_sphinx } } - set_config('fulltext_sphinx_configured', '1'); - - $this->tidy(); - return false; } @@ -613,11 +606,6 @@ class phpbb_search_fulltext_sphinx { global $db, $user, $config; - if (!isset($config['fulltext_sphinx_configured']) || !$config['fulltext_sphinx_configured']) - { - return $user->lang['FULLTEXT_SPHINX_CONFIGURE_FIRST']; - } - if (!$this->index_created()) { $sql = 'CREATE TABLE IF NOT EXISTS ' . SPHINX_TABLE . ' ( @@ -630,9 +618,6 @@ class phpbb_search_fulltext_sphinx $db->sql_query($sql); } - // start indexing process - $this->tidy(true); - return false; } @@ -645,7 +630,7 @@ class phpbb_search_fulltext_sphinx */ function delete_index($acp_module, $u_action) { - global $db, $config; + global $db; if (!$this->index_created()) { @@ -715,7 +700,7 @@ class phpbb_search_fulltext_sphinx */ function get_stats() { - global $db, $config; + global $db; if ($this->index_created()) { -- cgit v1.2.1 From 9711da2763f707408efde160357d51330fd17681 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:04:14 +0530 Subject: [feature/sphinx-fulltext-search] adds default config values Default config values are added to config table in new install as well as database_update. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 48855ef7d8..36c5c68a3b 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -742,24 +742,6 @@ class phpbb_search_fulltext_sphinx 'fulltext_sphinx_indexer_mem_limit' => 'int', ); - $defaults = array( - 'fulltext_sphinx_indexer_mem_limit' => '512', - 'fulltext_sphinx_stopwords' => '0', - ); - - foreach ($config_vars as $config_var => $type) - { - if (!isset($config[$config_var])) - { - $default = ''; - if (isset($defaults[$config_var])) - { - $default = $defaults[$config_var]; - } - set_config($config_var, $default); - } - } - $tpl = ' ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. '
-- cgit v1.2.1 From 79432aa4a0698a5a4a518521613aad4adbb40584 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:16:42 +0530 Subject: [feature/sphinx-fulltext-search] assign all globals to class properties PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 126 +++++++++++++----------------- 1 file changed, 56 insertions(+), 70 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 36c5c68a3b..f858b199b2 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -40,6 +40,10 @@ class phpbb_search_fulltext_sphinx private $id; private $indexes; private $sphinx; + private $auth; + private $config; + private $db; + private $user; public $word_length = array(); public $search_query; public $common_words = array(); @@ -52,7 +56,11 @@ class phpbb_search_fulltext_sphinx */ public function __construct(&$error) { - global $config; + global $config, $db, $user, $auth; + $this->config = $config; + $this->user = $user; + $this->db = $db; + $this->auth = $auth; $this->id = $config['avatar_salt']; $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; @@ -89,11 +97,9 @@ class phpbb_search_fulltext_sphinx */ function init() { - global $db, $user, $config; - - if ($db->sql_layer != 'mysql' && $db->sql_layer != 'mysql4' && $db->sql_layer != 'mysqli') + if ($this->db->sql_layer != 'mysql' && $this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli') { - return $user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; + return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; } if ($error = $this->config_updated()) @@ -116,13 +122,13 @@ class phpbb_search_fulltext_sphinx */ function config_updated() { - global $db, $user, $config, $phpbb_root_path, $phpEx; + global $phpbb_root_path, $phpEx; include ($phpbb_root_path . 'config.' . $phpEx); // now that we're sure everything was entered correctly, generate a config for the index // we misuse the avatar_salt for this, as it should be unique ;-) - $config_object = new phpbb_search_sphinx_config($config['fulltext_sphinx_config_path'] . 'sphinx.conf'); + $config_object = new phpbb_search_sphinx_config($this->config['fulltext_sphinx_config_path'] . 'sphinx.conf'); $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( @@ -186,11 +192,11 @@ class phpbb_search_fulltext_sphinx AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'), ), 'index index_phpbb_' . $this->id . '_main' => array( - array('path', $config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), + array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), array('source', 'source_phpbb_' . $this->id . '_main'), array('docinfo', 'extern'), array('morphology', 'none'), - array('stopwords', $config['fulltext_sphinx_stopwords'] ? $config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), + array('stopwords', $this->config['fulltext_sphinx_stopwords'] ? $this->config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), array('min_word_len', '2'), array('charset_type', 'utf-8'), array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), @@ -198,23 +204,23 @@ class phpbb_search_fulltext_sphinx array('min_infix_len', '0'), ), 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array( - array('path', $config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'), + array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'), array('source', 'source_phpbb_' . $this->id . '_delta'), ), 'indexer' => array( - array('mem_limit', $config['fulltext_sphinx_indexer_mem_limit'] . 'M'), + array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M'), ), 'searchd' => array( array('compat_sphinxql_magics' , '0'), array('listen' , '127.0.0.1'), - array('port', ($config['fulltext_sphinx_port']) ? $config['fulltext_sphinx_port'] : '3312'), - array('log', $config['fulltext_sphinx_data_path'] . "log/searchd.log"), - array('query_log', $config['fulltext_sphinx_data_path'] . "log/sphinx-query.log"), + array('port', ($this->config['fulltext_sphinx_port']) ? $this->config['fulltext_sphinx_port'] : '3312'), + array('log', $this->config['fulltext_sphinx_data_path'] . "log/searchd.log"), + array('query_log', $this->config['fulltext_sphinx_data_path'] . "log/sphinx-query.log"), array('read_timeout', '5'), array('max_children', '30'), - array('pid_file', $config['fulltext_sphinx_data_path'] . "searchd.pid"), + array('pid_file', $this->config['fulltext_sphinx_data_path'] . "searchd.pid"), array('max_matches', (string) SPHINX_MAX_MATCHES), - array('binlog_path', $config['fulltext_sphinx_data_path']), + array('binlog_path', $this->config['fulltext_sphinx_data_path']), ), ); @@ -278,8 +284,6 @@ class phpbb_search_fulltext_sphinx */ function split_keywords(&$keywords, $terms) { - global $config; - if ($terms == 'all') { $match = array('#\sand\s#i', '#\sor\s#i', '#\snot\s#i', '#\+#', '#-#', '#\|#', '#@#'); @@ -330,8 +334,6 @@ class phpbb_search_fulltext_sphinx */ function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db, $auth; - // No keywords? No posts. if (!strlen($this->search_query) && !sizeof($author_ary)) { @@ -432,7 +434,7 @@ class phpbb_search_fulltext_sphinx if (sizeof($ex_fid_ary)) { // All forums that a user is allowed to access - $fid_ary = array_unique(array_intersect(array_keys($auth->acl_getf('f_read', true)), array_keys($auth->acl_getf('f_search', true)))); + $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($auth->acl_getf('f_search', true)))); // All forums that the user wants to and can search in $search_forums = array_diff($fid_ary, $ex_fid_ary); @@ -527,8 +529,6 @@ class phpbb_search_fulltext_sphinx */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $config, $db; - if ($mode == 'edit') { $this->sphinx->UpdateAttributes($this->indexes, array('forum_id', 'poster_id'), array((int)$post_id => array((int)$forum_id, (int)$poster_id))); @@ -549,16 +549,16 @@ class phpbb_search_fulltext_sphinx )), ); - $sql = $db->sql_build_query('SELECT', $sql_array); - $result = $db->sql_query($sql); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query($sql); $post_updates = array(); $post_time = time(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $post_updates[(int)$row['post_id']] = array($post_time); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($post_updates)) { @@ -590,8 +590,6 @@ class phpbb_search_fulltext_sphinx */ function tidy($create = false) { - global $config; - set_config('search_last_gc', time(), true); } @@ -604,18 +602,16 @@ class phpbb_search_fulltext_sphinx */ function create_index($acp_module, $u_action) { - global $db, $user, $config; - if (!$this->index_created()) { $sql = 'CREATE TABLE IF NOT EXISTS ' . SPHINX_TABLE . ' ( counter_id INT NOT NULL PRIMARY KEY, max_doc_id INT NOT NULL )'; - $db->sql_query($sql); + $this->db->sql_query($sql); $sql = 'TRUNCATE TABLE ' . SPHINX_TABLE; - $db->sql_query($sql); + $this->db->sql_query($sql); } return false; @@ -630,15 +626,13 @@ class phpbb_search_fulltext_sphinx */ function delete_index($acp_module, $u_action) { - global $db; - if (!$this->index_created()) { return false; } $sql = 'DROP TABLE ' . SPHINX_TABLE; - $db->sql_query($sql); + $this->db->sql_query($sql); return false; } @@ -652,12 +646,10 @@ class phpbb_search_fulltext_sphinx */ function index_created($allow_new_files = true) { - global $db, $config; - $sql = 'SHOW TABLES LIKE \'' . SPHINX_TABLE . '\''; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); $created = false; @@ -678,18 +670,16 @@ class phpbb_search_fulltext_sphinx */ function index_stats() { - global $user; - if (empty($this->stats)) { $this->get_stats(); } return array( - $user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0, - $user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, - $user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, - $user->lang['FULLTEXT_SPHINX_LAST_SEARCHES'] => nl2br($this->stats['last_searches']), + $this->user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0, + $this->user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, + $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->user->lang['FULLTEXT_SPHINX_LAST_SEARCHES'] => nl2br($this->stats['last_searches']), ); } @@ -700,23 +690,21 @@ class phpbb_search_fulltext_sphinx */ function get_stats() { - global $db; - if ($this->index_created()) { $sql = 'SELECT COUNT(post_id) as total_posts FROM ' . POSTS_TABLE; - $result = $db->sql_query($sql); - $this->stats['total_posts'] = (int) $db->sql_fetchfield('total_posts'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->stats['total_posts'] = (int) $this->db->sql_fetchfield('total_posts'); + $this->db->sql_freeresult($result); $sql = 'SELECT COUNT(p.post_id) as main_posts FROM ' . POSTS_TABLE . ' p, ' . SPHINX_TABLE . ' m WHERE p.post_id <= m.max_doc_id AND m.counter_id = 1'; - $result = $db->sql_query($sql); - $this->stats['main_posts'] = (int) $db->sql_fetchfield('main_posts'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->stats['main_posts'] = (int) $this->db->sql_fetchfield('main_posts'); + $this->db->sql_freeresult($result); } $this->stats['last_searches'] = ''; @@ -731,8 +719,6 @@ class phpbb_search_fulltext_sphinx */ function acp() { - global $user, $config; - $config_vars = array( 'fulltext_sphinx_config_path' => 'string', 'fulltext_sphinx_data_path' => 'string', @@ -743,31 +729,31 @@ class phpbb_search_fulltext_sphinx ); $tpl = ' - ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. ' + ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. '
-

' . $user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
+
-

' . $user->lang['FULLTEXT_SPHINX_BIN_PATH_EXPLAIN'] . '
+

' . $this->user->lang['FULLTEXT_SPHINX_BIN_PATH_EXPLAIN'] . '
-

' . $user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
+
-

' . $user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
+
- ' . $user->lang['FULLTEXT_SPHINX_CONFIGURE_AFTER']. ' + ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE_AFTER']. '
-

' . $user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
+
-

' . $user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN'] . '
-
' . $user->lang['MIB'] . '
+

' . $this->user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN'] . '
+
' . $this->user->lang['MIB'] . '
'; -- cgit v1.2.1 From 45c0956bcf72e59138c3b05e26c73b657298f562 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:23:23 +0530 Subject: [feature/sphinx-fulltext-search] implementing db_tools Use db_tools class for creating/dropping sphinx table. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index f858b199b2..317a35937d 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -43,6 +43,7 @@ class phpbb_search_fulltext_sphinx private $auth; private $config; private $db; + private $db_tools; private $user; public $word_length = array(); public $search_query; @@ -56,12 +57,20 @@ class phpbb_search_fulltext_sphinx */ public function __construct(&$error) { - global $config, $db, $user, $auth; + global $config, $db, $user, $auth, $phpbb_root_path, $phpEx; $this->config = $config; $this->user = $user; $this->db = $db; $this->auth = $auth; + if (!class_exists('phpbb_db_tools')) + { + require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + + // Initialize phpbb_db_tools object + $this->db_tools = new phpbb_db_tools($this->db); + $this->id = $config['avatar_salt']; $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; @@ -604,11 +613,14 @@ class phpbb_search_fulltext_sphinx { if (!$this->index_created()) { - $sql = 'CREATE TABLE IF NOT EXISTS ' . SPHINX_TABLE . ' ( - counter_id INT NOT NULL PRIMARY KEY, - max_doc_id INT NOT NULL - )'; - $this->db->sql_query($sql); + $table_data = array( + 'COLUMNS' => array( + 'counter_id' => array('UINT', 0), + 'max_doc_id' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'counter_id', + ); + $this->db_tools->sql_create_table(SPHINX_TABLE, $table_data); $sql = 'TRUNCATE TABLE ' . SPHINX_TABLE; $this->db->sql_query($sql); @@ -631,8 +643,7 @@ class phpbb_search_fulltext_sphinx return false; } - $sql = 'DROP TABLE ' . SPHINX_TABLE; - $this->db->sql_query($sql); + $this->db_tools->sql_table_drop(SPHINX_TABLE); return false; } -- cgit v1.2.1 From 537a16220ea9561332a17004eec79f2854c68df4 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:33:17 +0530 Subject: [feature/sphinx-fulltext-search] remove recent search queries remove recent search queries from the stats as they can't be retreived and remove other language keys being used no more. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 317a35937d..1ff6ab21b5 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -690,7 +690,6 @@ class phpbb_search_fulltext_sphinx $this->user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0, $this->user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, - $this->user->lang['FULLTEXT_SPHINX_LAST_SEARCHES'] => nl2br($this->stats['last_searches']), ); } @@ -717,8 +716,6 @@ class phpbb_search_fulltext_sphinx $this->stats['main_posts'] = (int) $this->db->sql_fetchfield('main_posts'); $this->db->sql_freeresult($result); } - - $this->stats['last_searches'] = ''; } /** -- cgit v1.2.1 From fdb7e64e29d7b6286b505cf3a75fe53cfdfc7503 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:51:52 +0530 Subject: [feature/sphinx-fulltext-search] fix comments PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 34 +++++++++------- phpBB/includes/search/sphinx/config.php | 52 ++++++++++++++----------- phpBB/includes/search/sphinx/config_section.php | 6 +-- 3 files changed, 53 insertions(+), 39 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 1ff6ab21b5..c72db1862e 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -116,7 +116,7 @@ class phpbb_search_fulltext_sphinx return $error; } - // move delta to main index each hour + // Move delta to main index each hour set_config('search_gc', 3600); return false; @@ -135,8 +135,9 @@ class phpbb_search_fulltext_sphinx include ($phpbb_root_path . 'config.' . $phpEx); - // now that we're sure everything was entered correctly, generate a config for the index - // we misuse the avatar_salt for this, as it should be unique ;-) + /* Now that we're sure everything was entered correctly, + generate a config for the index. We misuse the avatar_salt + for this, as it should be unique. */ $config_object = new phpbb_search_sphinx_config($this->config['fulltext_sphinx_config_path'] . 'sphinx.conf'); $config_data = array( @@ -396,7 +397,7 @@ class phpbb_search_fulltext_sphinx } } - // most narrow filters first + // Most narrow filters first if ($topic_id) { $this->sphinx->SetFilter('topic_id', array($topic_id)); @@ -407,31 +408,37 @@ class phpbb_search_fulltext_sphinx switch($fields) { case 'titleonly': - // only search the title + // Only search the title if ($terms == 'all') { $search_query_prefix = '@title '; } - $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); // weight for the title - $this->sphinx->SetFilter('topic_first_post', array(1)); // 1 is first_post, 0 is not first post + // Weight for the title + $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); + // 1 is first_post, 0 is not first post + $this->sphinx->SetFilter('topic_first_post', array(1)); break; case 'msgonly': - // only search the body + // Only search the body if ($terms == 'all') { $search_query_prefix = '@data '; } - $this->sphinx->SetFieldWeights(array("title" => 1, "data" => 5)); // weight for the body + // Weight for the body + $this->sphinx->SetFieldWeights(array("title" => 1, "data" => 5)); break; case 'firstpost': - $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); // more relative weight for the title, also search the body - $this->sphinx->SetFilter('topic_first_post', array(1)); // 1 is first_post, 0 is not first post + // More relative weight for the title, also search the body + $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); + // 1 is first_post, 0 is not first post + $this->sphinx->SetFilter('topic_first_post', array(1)); break; default: - $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); // more relative weight for the title, also search the body + // More relative weight for the title, also search the body + $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1)); break; } @@ -458,7 +465,8 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); - // could be connection to localhost:3312 failed (errno=111, msg=Connection refused) during rotate, retry if so + /* Could be connection to localhost:3312 failed (errno=111, + msg=Connection refused) during rotate, retry if so */ $retries = SPHINX_CONNECT_RETRIES; while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--) { diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/includes/search/sphinx/config.php index 966cd0f284..3820eff178 100644 --- a/phpBB/includes/search/sphinx/config.php +++ b/phpBB/includes/search/sphinx/config.php @@ -49,7 +49,7 @@ class phpbb_search_sphinx_config { for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++) { - // make sure this is really a section object and not a comment + // Make sure this is really a section object and not a comment if (($this->sections[$i] instanceof phpbb_search_sphinx_config_section) && $this->sections[$i]->get_name() == $name) { return $this->sections[$i]; @@ -76,7 +76,7 @@ class phpbb_search_sphinx_config */ function read($filename) { - // split the file into lines, we'll process it line by line + // Split the file into lines, we'll process it line by line $config_file = file($filename); $this->sections = array(); @@ -87,8 +87,8 @@ class phpbb_search_sphinx_config foreach ($config_file as $i => $line) { - // if the value of a variable continues to the next line because the line break was escaped - // then we don't trim leading space but treat it as a part of the value + /* If the value of a variable continues to the next line because the line + break was escaped then we don't trim leading space but treat it as a part of the value */ if ($in_value) { $line = rtrim($line); @@ -98,11 +98,11 @@ class phpbb_search_sphinx_config $line = trim($line); } - // if we're not inside a section look for one + // If we're not inside a section look for one if (!$section) { - // add empty lines and comments as comment objects to the section list - // that way they're not deleted when reassembling the file from the sections + /* add empty lines and comments as comment objects to the section list + that way they're not deleted when reassembling the file from the sections*/ if (!$line || $line[0] == '#') { $this->sections[] = new phpbb_search_sphinx_config_comment($config_file[$i]); @@ -110,8 +110,8 @@ class phpbb_search_sphinx_config } else { - // otherwise we scan the line reading the section name until we find - // an opening curly bracket or a comment + /* otherwise we scan the line reading the section name until we find + an opening curly bracket or a comment */ $section_name = ''; $section_name_comment = ''; $found_opening_bracket = false; @@ -137,28 +137,29 @@ class phpbb_search_sphinx_config $section_name .= $line[$j]; } - // and then we create the new section object + // And then we create the new section object $section_name = trim($section_name); $section = new phpbb_search_sphinx_config_section($section_name, $section_name_comment); } } - else // if we're looking for variables inside a section + else { + // If we're looking for variables inside a section $skip_first = false; - // if we're not in a value continuing over the line feed + // If we're not in a value continuing over the line feed if (!$in_value) { - // then add empty lines and comments as comment objects to the variable list - // of this section so they're not deleted on reassembly + /* then add empty lines and comments as comment objects to the variable list + of this section so they're not deleted on reassembly */ if (!$line || $line[0] == '#') { $section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); continue; } - // as long as we haven't yet actually found an opening bracket for this section - // we treat everything as comments so it's not deleted either + /* As long as we haven't yet actually found an opening bracket for this section + we treat everything as comments so it's not deleted either */ if (!$found_opening_bracket) { if ($line[0] == '{') @@ -175,7 +176,8 @@ class phpbb_search_sphinx_config } } - // if we did not find a comment in this line or still add to the previous line's value ... + /* If we did not find a comment in this line or still add to the previous + line's value ... */ if ($line || $in_value) { if (!$in_value) @@ -226,21 +228,24 @@ class phpbb_search_sphinx_config { $value .= "\n"; $in_value = true; - continue 2; // go to the next line and keep processing the value in there + // Go to the next line and keep processing the value in there + continue 2; } $value .= $line[$j]; } } - // if a name and an equal sign were found then we have append a new variable object to the section + /* If a name and an equal sign were found then we have append a + new variable object to the section */ if ($name && $found_assignment) { $section->add_variable(new phpbb_search_sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); continue; } - // if we found a closing curly bracket this section has been completed and we can append it to the section list - // and continue with looking for the next section + /* if we found a closing curly bracket this section has been completed + and we can append it to the section list and continue with looking for + the next section */ if ($end_section) { $section->set_end_comment($comment); @@ -250,13 +255,14 @@ class phpbb_search_sphinx_config } } - // if we did not find anything meaningful up to here, then just treat it as a comment + /* If we did not find anything meaningful up to here, then just treat it + as a comment */ $comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i]; $section->add_variable(new phpbb_search_sphinx_config_comment($comment)); } } - // keep the filename for later use + // Keep the filename for later use $this->loaded = $filename; } diff --git a/phpBB/includes/search/sphinx/config_section.php b/phpBB/includes/search/sphinx/config_section.php index 529254dd5a..ed20dba279 100644 --- a/phpBB/includes/search/sphinx/config_section.php +++ b/phpBB/includes/search/sphinx/config_section.php @@ -79,7 +79,7 @@ class phpbb_search_sphinx_config_section { for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) { - // make sure this is a variable object and not a comment + // Make sure this is a variable object and not a comment if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name) { return $this->variables[$i]; @@ -96,7 +96,7 @@ class phpbb_search_sphinx_config_section { for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++) { - // make sure this is a variable object and not a comment + // Make sure this is a variable object and not a comment if (($this->variables[$i] instanceof phpbb_search_sphinx_config_variable) && $this->variables[$i]->get_name() == $name) { array_splice($this->variables, $i, 1); @@ -127,7 +127,7 @@ class phpbb_search_sphinx_config_section { $content = $this->name . ' ' . $this->comment . "\n{\n"; - // make sure we don't get too many newlines after the opening bracket + // Make sure we don't get too many newlines after the opening bracket while (trim($this->variables[0]->to_string()) == '') { array_shift($this->variables); -- cgit v1.2.1 From 01261179ce71ff0699ae598828ae82ec98751037 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 06:07:42 +0530 Subject: [feature/sphinx-fulltext-search] improve formatting PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index c72db1862e..5d92c1ff01 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * function and the variables used are in global space. */ global $phpbb_root_path, $phpEx, $table_prefix; -require($phpbb_root_path . "includes/sphinxapi-0.9.8." . $phpEx); +require($phpbb_root_path . 'includes/sphinxapi-0.9.8.' . $phpEx); define('SPHINX_MAX_MATCHES', 20000); define('SPHINX_CONNECT_RETRIES', 3); @@ -224,11 +224,11 @@ class phpbb_search_fulltext_sphinx array('compat_sphinxql_magics' , '0'), array('listen' , '127.0.0.1'), array('port', ($this->config['fulltext_sphinx_port']) ? $this->config['fulltext_sphinx_port'] : '3312'), - array('log', $this->config['fulltext_sphinx_data_path'] . "log/searchd.log"), - array('query_log', $this->config['fulltext_sphinx_data_path'] . "log/sphinx-query.log"), + array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), + array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), array('read_timeout', '5'), array('max_children', '30'), - array('pid_file', $this->config['fulltext_sphinx_data_path'] . "searchd.pid"), + array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'), array('max_matches', (string) SPHINX_MAX_MATCHES), array('binlog_path', $this->config['fulltext_sphinx_data_path']), ), @@ -352,9 +352,9 @@ class phpbb_search_fulltext_sphinx $id_ary = array(); - $join_topic = ($type == 'posts') ? false : true; + $join_topic = ($type != 'posts'); - // sorting + // Sorting if ($type == 'topics') { @@ -405,7 +405,7 @@ class phpbb_search_fulltext_sphinx $search_query_prefix = ''; - switch($fields) + switch ($fields) { case 'titleonly': // Only search the title @@ -483,7 +483,7 @@ class phpbb_search_fulltext_sphinx } else { - foreach($result['matches'] as $key => $value) + foreach ($result['matches'] as $key => $value) { $id_ary[] = $value['attrs']['topic_id']; } -- cgit v1.2.1 From f0692bb9e83f6af9725023028f07cba636d04a4b Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 06:38:36 +0530 Subject: [feature/sphinx-fulltext-search] modify config class Sphinx config class is modified to return the configuration data instead of writing it to a file. Search backend property config_file_data stores the generated data. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 263 +++++++++++++++--------------- phpBB/includes/search/sphinx/config.php | 40 ++--- 2 files changed, 145 insertions(+), 158 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 5d92c1ff01..a54ebe1a59 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -45,6 +45,7 @@ class phpbb_search_fulltext_sphinx private $db; private $db_tools; private $user; + private $config_file_data = ''; public $word_length = array(); public $search_query; public $common_words = array(); @@ -133,151 +134,151 @@ class phpbb_search_fulltext_sphinx { global $phpbb_root_path, $phpEx; - include ($phpbb_root_path . 'config.' . $phpEx); - - /* Now that we're sure everything was entered correctly, - generate a config for the index. We misuse the avatar_salt - for this, as it should be unique. */ - $config_object = new phpbb_search_sphinx_config($this->config['fulltext_sphinx_config_path'] . 'sphinx.conf'); - - $config_data = array( - 'source source_phpbb_' . $this->id . '_main' => array( - array('type', 'mysql'), - array('sql_host', $dbhost), - array('sql_user', $dbuser), - array('sql_pass', $dbpasswd), - array('sql_db', $dbname), - array('sql_port', $dbport), - array('sql_query_pre', 'SET NAMES utf8'), - array('sql_query_pre', 'REPLACE INTO ' . SPHINX_TABLE . ' SELECT 1, MAX(post_id) FROM ' . POSTS_TABLE . ''), - array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), - array('sql_range_step', '5000'), - array('sql_query', 'SELECT - p.post_id AS id, - p.forum_id, - p.topic_id, - p.poster_id, - IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, - p.post_time, - p.post_subject, - p.post_subject as title, - p.post_text as data, - t.topic_last_post_time, - 0 as deleted - FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t - WHERE - p.topic_id = t.topic_id - AND p.post_id >= $start AND p.post_id <= $end'), - array('sql_query_post', ''), - array('sql_query_post_index', 'REPLACE INTO ' . SPHINX_TABLE . ' ( counter_id, max_doc_id ) VALUES ( 1, $maxid )'), - array('sql_query_info', 'SELECT * FROM ' . POSTS_TABLE . ' WHERE post_id = $id'), - array('sql_attr_uint', 'forum_id'), - array('sql_attr_uint', 'topic_id'), - array('sql_attr_uint', 'poster_id'), - array('sql_attr_bool', 'topic_first_post'), - array('sql_attr_bool', 'deleted'), - array('sql_attr_timestamp' , 'post_time'), - array('sql_attr_timestamp' , 'topic_last_post_time'), - array('sql_attr_str2ordinal', 'post_subject'), - ), - 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array( - array('sql_query_pre', ''), - array('sql_query_range', ''), - array('sql_range_step', ''), - array('sql_query', 'SELECT - p.post_id AS id, - p.forum_id, - p.topic_id, - p.poster_id, - IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, - p.post_time, - p.post_subject, - p.post_subject as title, - p.post_text as data, - t.topic_last_post_time, - 0 as deleted - FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t - WHERE - p.topic_id = t.topic_id - AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'), - ), - 'index index_phpbb_' . $this->id . '_main' => array( - array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), - array('source', 'source_phpbb_' . $this->id . '_main'), - array('docinfo', 'extern'), - array('morphology', 'none'), - array('stopwords', $this->config['fulltext_sphinx_stopwords'] ? $this->config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), - array('min_word_len', '2'), - array('charset_type', 'utf-8'), - array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), - array('min_prefix_len', '0'), - array('min_infix_len', '0'), - ), - 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array( - array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'), - array('source', 'source_phpbb_' . $this->id . '_delta'), - ), - 'indexer' => array( - array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M'), - ), - 'searchd' => array( - array('compat_sphinxql_magics' , '0'), - array('listen' , '127.0.0.1'), - array('port', ($this->config['fulltext_sphinx_port']) ? $this->config['fulltext_sphinx_port'] : '3312'), - array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), - array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), - array('read_timeout', '5'), - array('max_children', '30'), - array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'), - array('max_matches', (string) SPHINX_MAX_MATCHES), - array('binlog_path', $this->config['fulltext_sphinx_data_path']), - ), - ); + include ($phpbb_root_path . 'config.' . $phpEx); + + /* Now that we're sure everything was entered correctly, + generate a config for the index. We misuse the avatar_salt + for this, as it should be unique. */ + $config_object = new phpbb_search_sphinx_config($this->config_file_data); + + $config_data = array( + 'source source_phpbb_' . $this->id . '_main' => array( + array('type', 'mysql'), + array('sql_host', $dbhost), + array('sql_user', $dbuser), + array('sql_pass', $dbpasswd), + array('sql_db', $dbname), + array('sql_port', $dbport), + array('sql_query_pre', 'SET NAMES utf8'), + array('sql_query_pre', 'REPLACE INTO ' . SPHINX_TABLE . ' SELECT 1, MAX(post_id) FROM ' . POSTS_TABLE . ''), + array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), + array('sql_range_step', '5000'), + array('sql_query', 'SELECT + p.post_id AS id, + p.forum_id, + p.topic_id, + p.poster_id, + IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, + p.post_time, + p.post_subject, + p.post_subject as title, + p.post_text as data, + t.topic_last_post_time, + 0 as deleted + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t + WHERE + p.topic_id = t.topic_id + AND p.post_id >= $start AND p.post_id <= $end'), + array('sql_query_post', ''), + array('sql_query_post_index', 'REPLACE INTO ' . SPHINX_TABLE . ' ( counter_id, max_doc_id ) VALUES ( 1, $maxid )'), + array('sql_query_info', 'SELECT * FROM ' . POSTS_TABLE . ' WHERE post_id = $id'), + array('sql_attr_uint', 'forum_id'), + array('sql_attr_uint', 'topic_id'), + array('sql_attr_uint', 'poster_id'), + array('sql_attr_bool', 'topic_first_post'), + array('sql_attr_bool', 'deleted'), + array('sql_attr_timestamp' , 'post_time'), + array('sql_attr_timestamp' , 'topic_last_post_time'), + array('sql_attr_str2ordinal', 'post_subject'), + ), + 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array( + array('sql_query_pre', ''), + array('sql_query_range', ''), + array('sql_range_step', ''), + array('sql_query', 'SELECT + p.post_id AS id, + p.forum_id, + p.topic_id, + p.poster_id, + IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, + p.post_time, + p.post_subject, + p.post_subject as title, + p.post_text as data, + t.topic_last_post_time, + 0 as deleted + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t + WHERE + p.topic_id = t.topic_id + AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'), + ), + 'index index_phpbb_' . $this->id . '_main' => array( + array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), + array('source', 'source_phpbb_' . $this->id . '_main'), + array('docinfo', 'extern'), + array('morphology', 'none'), + array('stopwords', $this->config['fulltext_sphinx_stopwords'] ? $this->config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), + array('min_word_len', '2'), + array('charset_type', 'utf-8'), + array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), + array('min_prefix_len', '0'), + array('min_infix_len', '0'), + ), + 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array( + array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'), + array('source', 'source_phpbb_' . $this->id . '_delta'), + ), + 'indexer' => array( + array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M'), + ), + 'searchd' => array( + array('compat_sphinxql_magics' , '0'), + array('listen' , '127.0.0.1'), + array('port', ($this->config['fulltext_sphinx_port']) ? $this->config['fulltext_sphinx_port'] : '3312'), + array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), + array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), + array('read_timeout', '5'), + array('max_children', '30'), + array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'), + array('max_matches', (string) SPHINX_MAX_MATCHES), + array('binlog_path', $this->config['fulltext_sphinx_data_path']), + ), + ); - $non_unique = array('sql_query_pre' => true, 'sql_attr_uint' => true, 'sql_attr_timestamp' => true, 'sql_attr_str2ordinal' => true, 'sql_attr_bool' => true); - $delete = array('sql_group_column' => true, 'sql_date_column' => true, 'sql_str2ordinal_column' => true); + $non_unique = array('sql_query_pre' => true, 'sql_attr_uint' => true, 'sql_attr_timestamp' => true, 'sql_attr_str2ordinal' => true, 'sql_attr_bool' => true); + $delete = array('sql_group_column' => true, 'sql_date_column' => true, 'sql_str2ordinal_column' => true); + foreach ($config_data as $section_name => $section_data) + { + $section = $config_object->get_section_by_name($section_name); + if (!$section) + { + $section = $config_object->add_section($section_name); + } - foreach ($config_data as $section_name => $section_data) + foreach ($delete as $key => $void) { - $section = $config_object->get_section_by_name($section_name); - if (!$section) - { - $section = $config_object->add_section($section_name); - } + $section->delete_variables_by_name($key); + } - foreach ($delete as $key => $void) - { - $section->delete_variables_by_name($key); - } + foreach ($non_unique as $key => $void) + { + $section->delete_variables_by_name($key); + } - foreach ($non_unique as $key => $void) - { - $section->delete_variables_by_name($key); - } + foreach ($section_data as $entry) + { + $key = $entry[0]; + $value = $entry[1]; - foreach ($section_data as $entry) + if (!isset($non_unique[$key])) { - $key = $entry[0]; - $value = $entry[1]; - - if (!isset($non_unique[$key])) + $variable = $section->get_variable_by_name($key); + if (!$variable) { - $variable = $section->get_variable_by_name($key); - if (!$variable) - { - $variable = $section->create_variable($key, $value); - } - else - { - $variable->set_value($value); - } + $variable = $section->create_variable($key, $value); } else { - $variable = $section->create_variable($key, $value); + $variable->set_value($value); } } + else + { + $variable = $section->create_variable($key, $value); + } } + } + $this->config_file_data = $config_object->get_data(); return false; } diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/includes/search/sphinx/config.php index 3820eff178..e0ad667fb6 100644 --- a/phpBB/includes/search/sphinx/config.php +++ b/phpBB/includes/search/sphinx/config.php @@ -27,15 +27,15 @@ class phpbb_search_sphinx_config var $sections = array(); /** - * Constructor which optionally loads data from a file + * Constructor which optionally loads data from a variable * - * @param string $filename The path to a file containing the sphinx configuration + * @param string $config_data Variable containing the sphinx configuration data */ - function __construct($filename = false) + function __construct($config_data) { - if ($filename !== false && file_exists($filename)) + if ($config_data != '') { - $this->read($filename); + $this->read($config_data); } } @@ -70,22 +70,19 @@ class phpbb_search_sphinx_config } /** - * Parses the config file at the given path, which is stored in $this->loaded for later use + * Reads the config file data * - * @param string $filename The path to the config file + * @param string $config_data The config file data */ - function read($filename) + function read($config_data) { - // Split the file into lines, we'll process it line by line - $config_file = file($filename); - $this->sections = array(); $section = null; $found_opening_bracket = false; $in_value = false; - foreach ($config_file as $i => $line) + foreach ($config_data as $i => $line) { /* If the value of a variable continues to the next line because the line break was escaped then we don't trim leading space but treat it as a part of the value */ @@ -262,32 +259,21 @@ class phpbb_search_sphinx_config } } - // Keep the filename for later use - $this->loaded = $filename; } /** - * Writes the config data into a file + * Returns the config data * - * @param string $filename The optional filename into which the config data shall be written. - * If it's not specified it will be written into the file that the config - * was originally read from. + * @return string $data The config data that is generated. */ - function write($filename = false) + function get_data() { - if ($filename === false && $this->loaded) - { - $filename = $this->loaded; - } - $data = ""; foreach ($this->sections as $section) { $data .= $section->to_string(); } - $fp = fopen($filename, 'wb'); - fwrite($fp, $data); - fclose($fp); + return $data; } } -- cgit v1.2.1 From b16e70ae1d03587c7d7d7e106299a4e576491751 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 12:32:42 +0530 Subject: [feature/sphinx-fulltext-search] remove bin_path fulltext_sphinx_bin_path from ACP as it is no longer required. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index a54ebe1a59..6488cbcd40 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -739,7 +739,6 @@ class phpbb_search_fulltext_sphinx $config_vars = array( 'fulltext_sphinx_config_path' => 'string', 'fulltext_sphinx_data_path' => 'string', - 'fulltext_sphinx_bin_path' => 'string', 'fulltext_sphinx_port' => 'int', 'fulltext_sphinx_stopwords' => 'bool', 'fulltext_sphinx_indexer_mem_limit' => 'int', @@ -751,10 +750,6 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
-
-

' . $this->user->lang['FULLTEXT_SPHINX_BIN_PATH_EXPLAIN'] . '
-
-

' . $this->user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
-- cgit v1.2.1 From 4b40f0d3c6d14adc2b20b866cbeb42586cf8d874 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 16:25:19 +0530 Subject: [feature/sphinx-fulltext-search] display config file in ACP sphinx config file is generated and displayed in the ACP for user to use it to start sphinx search daemon. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 6488cbcd40..6e554eec00 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -112,11 +112,6 @@ class phpbb_search_fulltext_sphinx return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; } - if ($error = $this->config_updated()) - { - return $error; - } - // Move delta to main index each hour set_config('search_gc', 3600); @@ -124,16 +119,21 @@ class phpbb_search_fulltext_sphinx } /** - * Updates the config file sphinx.conf and generates the same in case autoconf is selected + * Generates content of sphinx.conf * - * @return string|bool Language key of the error/incompatiblity occured otherwise false + * @return bool True if sphinx.conf content is correctly generated, false otherwise * * @access private */ - function config_updated() + function config_generate() { global $phpbb_root_path, $phpEx; + if (!$this->config['fulltext_sphinx_data_path'] || !$this->config['fulltext_sphinx_config_path']) + { + return false; + } + include ($phpbb_root_path . 'config.' . $phpEx); /* Now that we're sure everything was entered correctly, @@ -280,7 +280,7 @@ class phpbb_search_fulltext_sphinx } $this->config_file_data = $config_object->get_data(); - return false; + return true; } /** @@ -767,6 +767,10 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN'] . '
' . $this->user->lang['MIB'] . '
+
+

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
+
' . (($this->config_generate()) ? '' : $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA')) . '
+
'; // These are fields required in the config table -- cgit v1.2.1 From 172c583f1941a8b162f1a7bf258bb3e38149606d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 16:57:18 +0530 Subject: [feature/sphinx-fulltext-search] use new unique id instead of salt a new unique id is generated by sphinx and stored in the config table instead of using avatar_salt. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 6e554eec00..5bdbbff119 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -72,16 +72,17 @@ class phpbb_search_fulltext_sphinx // Initialize phpbb_db_tools object $this->db_tools = new phpbb_db_tools($this->db); - $this->id = $config['avatar_salt']; + if(!$this->config['fulltext_sphinx_id']) + { + set_config('fulltext_sphinx_id', unique_id()); + } + $this->id = $this->config['fulltext_sphinx_id']; $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; $this->sphinx = new SphinxClient(); // We only support localhost for now - $this->sphinx->SetServer('localhost', (isset($config['fulltext_sphinx_port']) && $config['fulltext_sphinx_port']) ? (int) $config['fulltext_sphinx_port'] : 3312); - - $config['fulltext_sphinx_min_word_len'] = 2; - $config['fulltext_sphinx_max_word_len'] = 400; + $this->sphinx->SetServer('localhost', (isset($this->config['fulltext_sphinx_port']) && $this->config['fulltext_sphinx_port']) ? (int) $this->config['fulltext_sphinx_port'] : 3312); $error = false; } @@ -137,8 +138,8 @@ class phpbb_search_fulltext_sphinx include ($phpbb_root_path . 'config.' . $phpEx); /* Now that we're sure everything was entered correctly, - generate a config for the index. We misuse the avatar_salt - for this, as it should be unique. */ + generate a config for the index. We use a config value + fulltext_sphinx_id for this, as it should be unique. */ $config_object = new phpbb_search_sphinx_config($this->config_file_data); $config_data = array( -- cgit v1.2.1 From b8103c5c31cbb42a46a40ac10c34ff09dc5efc60 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 17:10:51 +0530 Subject: [feature/sphinx-fulltext-search] fix comments and indentation PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- phpBB/includes/search/sphinx/config.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 5bdbbff119..d942d0f027 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -135,7 +135,7 @@ class phpbb_search_fulltext_sphinx return false; } - include ($phpbb_root_path . 'config.' . $phpEx); + include($phpbb_root_path . 'config.' . $phpEx); /* Now that we're sure everything was entered correctly, generate a config for the index. We use a config value diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/includes/search/sphinx/config.php index e0ad667fb6..173193adc5 100644 --- a/phpBB/includes/search/sphinx/config.php +++ b/phpBB/includes/search/sphinx/config.php @@ -98,7 +98,7 @@ class phpbb_search_sphinx_config // If we're not inside a section look for one if (!$section) { - /* add empty lines and comments as comment objects to the section list + /* Add empty lines and comments as comment objects to the section list that way they're not deleted when reassembling the file from the sections*/ if (!$line || $line[0] == '#') { @@ -107,7 +107,7 @@ class phpbb_search_sphinx_config } else { - /* otherwise we scan the line reading the section name until we find + /* Otherwise we scan the line reading the section name until we find an opening curly bracket or a comment */ $section_name = ''; $section_name_comment = ''; @@ -147,7 +147,7 @@ class phpbb_search_sphinx_config // If we're not in a value continuing over the line feed if (!$in_value) { - /* then add empty lines and comments as comment objects to the variable list + /* Then add empty lines and comments as comment objects to the variable list of this section so they're not deleted on reassembly */ if (!$line || $line[0] == '#') { @@ -240,7 +240,7 @@ class phpbb_search_sphinx_config continue; } - /* if we found a closing curly bracket this section has been completed + /* If we found a closing curly bracket this section has been completed and we can append it to the section list and continue with looking for the next section */ if ($end_section) -- cgit v1.2.1 From 78e7f2a5290dc152cf2e386553e6308c74e2d005 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 17:32:31 +0530 Subject: [feature/sphinx-fulltext-search] improve sphinx helper classes add access modifiers and docblocks to properties and methods of sphinx helper classes. PHPBB3-10946 --- phpBB/includes/search/sphinx/config.php | 15 +++++++++++--- phpBB/includes/search/sphinx/config_comment.php | 6 +++++- phpBB/includes/search/sphinx/config_section.php | 26 ++++++++++++++++++++---- phpBB/includes/search/sphinx/config_variable.php | 14 ++++++++++--- 4 files changed, 50 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/includes/search/sphinx/config.php index 173193adc5..795dff07ed 100644 --- a/phpBB/includes/search/sphinx/config.php +++ b/phpBB/includes/search/sphinx/config.php @@ -23,13 +23,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_sphinx_config { - var $loaded = false; - var $sections = array(); + private $sections = array(); /** * Constructor which optionally loads data from a variable * * @param string $config_data Variable containing the sphinx configuration data + * + * @access public */ function __construct($config_data) { @@ -44,6 +45,8 @@ class phpbb_search_sphinx_config * * @param string $name The name of the section that shall be returned * @return phpbb_search_sphinx_config_section The section object or null if none was found + * + * @access public */ function get_section_by_name($name) { @@ -62,6 +65,8 @@ class phpbb_search_sphinx_config * * @param string $name The name for the new section * @return phpbb_search_sphinx_config_section The newly created section object + * + * @access public */ function add_section($name) { @@ -73,6 +78,8 @@ class phpbb_search_sphinx_config * Reads the config file data * * @param string $config_data The config file data + * + * @access private */ function read($config_data) { @@ -264,7 +271,9 @@ class phpbb_search_sphinx_config /** * Returns the config data * - * @return string $data The config data that is generated. + * @return string $data The config data that is generated + * + * @access public */ function get_data() { diff --git a/phpBB/includes/search/sphinx/config_comment.php b/phpBB/includes/search/sphinx/config_comment.php index 63d3488aef..7f695dbf0c 100644 --- a/phpBB/includes/search/sphinx/config_comment.php +++ b/phpBB/includes/search/sphinx/config_comment.php @@ -21,12 +21,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_sphinx_config_comment { - var $exact_string; + private $exact_string; /** * Create a new comment * * @param string $exact_string The content of the comment including newlines, leading whitespace, etc. + * + * @access public */ function __construct($exact_string) { @@ -37,6 +39,8 @@ class phpbb_search_sphinx_config_comment * Simply returns the comment as it was created * * @return string The exact string that was specified in the constructor + * + * @access public */ function to_string() { diff --git a/phpBB/includes/search/sphinx/config_section.php b/phpBB/includes/search/sphinx/config_section.php index ed20dba279..79c9c8563d 100644 --- a/phpBB/includes/search/sphinx/config_section.php +++ b/phpBB/includes/search/sphinx/config_section.php @@ -21,10 +21,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_sphinx_config_section { - var $name; - var $comment; - var $end_comment; - var $variables = array(); + private $name; + private $comment; + private $end_comment; + private $variables = array(); /** * Construct a new section @@ -32,6 +32,8 @@ class phpbb_search_sphinx_config_section * @param string $name Name of the section * @param string $comment Comment that should be appended after the name in the * textual format. + * + * @access public */ function __construct($name, $comment) { @@ -44,6 +46,8 @@ class phpbb_search_sphinx_config_section * Add a variable object to the list of variables in this section * * @param phpbb_search_sphinx_config_variable $variable The variable object + * + * @access public */ function add_variable($variable) { @@ -52,6 +56,10 @@ class phpbb_search_sphinx_config_section /** * Adds a comment after the closing bracket in the textual representation + * + * @param string $end_comment + * + * @access public */ function set_end_comment($end_comment) { @@ -62,6 +70,8 @@ class phpbb_search_sphinx_config_section * Getter for the name of this section * * @return string Section's name + * + * @access public */ function get_name() { @@ -74,6 +84,8 @@ class phpbb_search_sphinx_config_section * @param string $name The name of the variable that shall be returned * @return phpbb_search_sphinx_config_section The first variable object from this section with the * given name or null if none was found + * + * @access public */ function get_variable_by_name($name) { @@ -91,6 +103,8 @@ class phpbb_search_sphinx_config_section * Deletes all variables with the given name * * @param string $name The name of the variable objects that are supposed to be removed + * + * @access public */ function delete_variables_by_name($name) { @@ -111,6 +125,8 @@ class phpbb_search_sphinx_config_section * @param string $name The name for the new variable * @param string $value The value for the new variable * @return phpbb_search_sphinx_config_variable Variable object that was created + * + * @access public */ function create_variable($name, $value) { @@ -122,6 +138,8 @@ class phpbb_search_sphinx_config_section * Turns this object into a string which can be written to a config file * * @return string Config data in textual form, parsable for sphinx + * + * @access public */ function to_string() { diff --git a/phpBB/includes/search/sphinx/config_variable.php b/phpBB/includes/search/sphinx/config_variable.php index dd7836f7c8..35abe281cb 100644 --- a/phpBB/includes/search/sphinx/config_variable.php +++ b/phpBB/includes/search/sphinx/config_variable.php @@ -21,9 +21,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_sphinx_config_variable { - var $name; - var $value; - var $comment; + private $name; + private $value; + private $comment; /** * Constructs a new variable object @@ -32,6 +32,8 @@ class phpbb_search_sphinx_config_variable * @param string $value Value of the variable * @param string $comment Optional comment after the variable in the * config file + * + * @access public */ function __construct($name, $value, $comment) { @@ -44,6 +46,8 @@ class phpbb_search_sphinx_config_variable * Getter for the variable's name * * @return string The variable object's name + * + * @access public */ function get_name() { @@ -54,6 +58,8 @@ class phpbb_search_sphinx_config_variable * Allows changing the variable's value * * @param string $value New value for this variable + * + * @access public */ function set_value($value) { @@ -64,6 +70,8 @@ class phpbb_search_sphinx_config_variable * Turns this object into a string readable by sphinx * * @return string Config data in textual form + * + * @access public */ function to_string() { -- cgit v1.2.1 From f40da411c389cb7718d31f1ee20f8487f25969f0 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 17:46:58 +0530 Subject: [feature/sphinx-fulltext-search] modify language keys Modify language keys according to what the config setting actually does. Remove references to autoconf. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index d942d0f027..08948803ba 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -746,7 +746,7 @@ class phpbb_search_fulltext_sphinx ); $tpl = ' - ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE_BEFORE']. ' + ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE']. '

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
@@ -759,7 +759,6 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
- ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE_AFTER']. '

' . $this->user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
-- cgit v1.2.1 From 13c451ca2e9a6717a8a98943ba022a6f41dcdd9c Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 04:13:34 +0530 Subject: [feature/sphinx-fulltext-search] use sql_table_exists Use sql_table_exists( ) method in db_tools to support all database types. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 08948803ba..747c22a3ef 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -667,14 +667,9 @@ class phpbb_search_fulltext_sphinx */ function index_created($allow_new_files = true) { - $sql = 'SHOW TABLES LIKE \'' . SPHINX_TABLE . '\''; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - $created = false; - if ($row) + if ($this->db_tools->sql_table_exists(SPHINX_TABLE)) { $created = true; } -- cgit v1.2.1 From 118b57f71d9f563f8eeda8e5925d482c38ab1af8 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 04:28:55 +0530 Subject: [feature/sphinx-fulltext-search] minor changes in sphinx.conf PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 747c22a3ef..c223284c72 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -150,7 +150,7 @@ class phpbb_search_fulltext_sphinx array('sql_pass', $dbpasswd), array('sql_db', $dbname), array('sql_port', $dbport), - array('sql_query_pre', 'SET NAMES utf8'), + array('sql_query_pre', 'SET NAMES \'utf8\''), array('sql_query_pre', 'REPLACE INTO ' . SPHINX_TABLE . ' SELECT 1, MAX(post_id) FROM ' . POSTS_TABLE . ''), array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), array('sql_range_step', '5000'), -- cgit v1.2.1 From b81941a997760eca4f209cc100fe2baec3ef4468 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 16:30:45 +0530 Subject: [feature/sphinx-fulltext-search] use CASE instead of IF IF is not supported in pgsql, use CASE instead supported in both mysql and pgsql. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index c223284c72..f505703c09 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -159,7 +159,7 @@ class phpbb_search_fulltext_sphinx p.forum_id, p.topic_id, p.poster_id, - IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, + CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, p.post_time, p.post_subject, p.post_subject as title, @@ -191,7 +191,7 @@ class phpbb_search_fulltext_sphinx p.forum_id, p.topic_id, p.poster_id, - IF(p.post_id = t.topic_first_post_id, 1, 0) as topic_first_post, + CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post, p.post_time, p.post_subject, p.post_subject as title, -- cgit v1.2.1 From 81959927e53ebc62765ff075d23feeaf9b40a95d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 17:22:03 +0530 Subject: [feature/sphinx-fulltext-search] use Update in sphinx query Instead of REPLACE use UPDATE since pgsql does not support REPLACE. A row is inserted at time of creating table so REPLACE is no longer needed. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index f505703c09..d82a56c6f4 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -151,7 +151,7 @@ class phpbb_search_fulltext_sphinx array('sql_db', $dbname), array('sql_port', $dbport), array('sql_query_pre', 'SET NAMES \'utf8\''), - array('sql_query_pre', 'REPLACE INTO ' . SPHINX_TABLE . ' SELECT 1, MAX(post_id) FROM ' . POSTS_TABLE . ''), + array('sql_query_pre', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ') WHERE counter_id = 1'), array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), array('sql_range_step', '5000'), array('sql_query', 'SELECT @@ -171,7 +171,7 @@ class phpbb_search_fulltext_sphinx p.topic_id = t.topic_id AND p.post_id >= $start AND p.post_id <= $end'), array('sql_query_post', ''), - array('sql_query_post_index', 'REPLACE INTO ' . SPHINX_TABLE . ' ( counter_id, max_doc_id ) VALUES ( 1, $maxid )'), + array('sql_query_post_index', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = $maxid WHERE counter_id = 1'), array('sql_query_info', 'SELECT * FROM ' . POSTS_TABLE . ' WHERE post_id = $id'), array('sql_attr_uint', 'forum_id'), array('sql_attr_uint', 'topic_id'), @@ -634,6 +634,13 @@ class phpbb_search_fulltext_sphinx $sql = 'TRUNCATE TABLE ' . SPHINX_TABLE; $this->db->sql_query($sql); + + $data = array( + 'counter_id' => '1', + 'max_doc_id' => '0', + ); + $sql = 'INSERT INTO ' . SPHINX_TABLE . ' ' . $this->db->sql_build_array('INSERT', $data); + $this->db->sql_query($sql); } return false; -- cgit v1.2.1 From 609ce3ae8fb55e717ff188d2ec9c10c6ae252b7a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 17:48:17 +0530 Subject: [feature/sphinx-fulltext-search] add pgsql functionality PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index d82a56c6f4..76caf9ae8c 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -108,7 +108,7 @@ class phpbb_search_fulltext_sphinx */ function init() { - if ($this->db->sql_layer != 'mysql' && $this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli') + if ($this->db->sql_layer != 'mysql' && $this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli' && $this->db->sql_layer != 'postgres') { return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; } -- cgit v1.2.1 From a3d103c9c03c79fe67963b9db5a5471c766fa401 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 18:08:50 +0530 Subject: [feature/sphinx-fulltext-search] add support for postgres Don't generate sphinx config file if database is not supported. Add property $dbtype to write into sphinx config file according to sql_layer. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 76caf9ae8c..a4341f46e0 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -44,6 +44,7 @@ class phpbb_search_fulltext_sphinx private $config; private $db; private $db_tools; + private $dbtype; private $user; private $config_file_data = ''; public $word_length = array(); @@ -130,8 +131,25 @@ class phpbb_search_fulltext_sphinx { global $phpbb_root_path, $phpEx; + // Check if Database is supported by Sphinx + if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli') + { + $this->dbtype = 'mysql'; + } + else if ($this->db->sql_layer == 'postgres') + { + $this->dbtype = 'pgsql'; + } + else + { + $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_WRONG_DATABASE'); + return false; + } + + // Check if directory paths have been filled if (!$this->config['fulltext_sphinx_data_path'] || !$this->config['fulltext_sphinx_config_path']) { + $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA'); return false; } @@ -141,10 +159,9 @@ class phpbb_search_fulltext_sphinx generate a config for the index. We use a config value fulltext_sphinx_id for this, as it should be unique. */ $config_object = new phpbb_search_sphinx_config($this->config_file_data); - $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( - array('type', 'mysql'), + array('type', $this->dbtype), array('sql_host', $dbhost), array('sql_user', $dbuser), array('sql_pass', $dbpasswd), @@ -771,7 +788,7 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
-
' . (($this->config_generate()) ? '' : $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA')) . '
+
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 3ecc81f853bb1ec6262fc0615bb0ab8704616db9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 21 Jul 2012 14:14:19 +0530 Subject: [feature/sphinx-fulltext-search] remove note from db_tools Note saying db_tools not being used currently is remove from db_tools.php We utilize db_tools in sphinx search. PHPBB3-10946 --- phpBB/includes/db/db_tools.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 73eae4e967..6df3aac9ce 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -20,7 +20,6 @@ if (!defined('IN_PHPBB')) * Currently not supported is returning SQL for creating tables. * * @package dbal -* @note currently not used within phpBB3, but may be utilized later. */ class phpbb_db_tools { -- cgit v1.2.1 From 0e9eb9401a38fab3139a1df33fa7e0903ccfb18f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 01:53:04 +0530 Subject: [feature/sphinx-fulltext-search] use readonly instead of disabled PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index a4341f46e0..1888057db4 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -788,7 +788,7 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
-
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
+
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 161e469b5a67b2911089ec0dfdb70bef355ed07e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 02:50:53 +0530 Subject: [feature/sphinx-fulltext-search] makes sql host configurable The SQL server host which sphinx connects to index the posts is now configurable via ACP. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 1888057db4..3bdce5dfb9 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -162,11 +162,11 @@ class phpbb_search_fulltext_sphinx $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( array('type', $this->dbtype), - array('sql_host', $dbhost), + array('sql_host', $this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : $dbhost), array('sql_user', $dbuser), array('sql_pass', $dbpasswd), array('sql_db', $dbname), - array('sql_port', $dbport), + array('sql_port', $this->config['fulltext_sphinx_port']), array('sql_query_pre', 'SET NAMES \'utf8\''), array('sql_query_pre', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ') WHERE counter_id = 1'), array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), @@ -759,6 +759,7 @@ class phpbb_search_fulltext_sphinx $config_vars = array( 'fulltext_sphinx_config_path' => 'string', 'fulltext_sphinx_data_path' => 'string', + 'fulltext_sphinx_host' => 'string', 'fulltext_sphinx_port' => 'int', 'fulltext_sphinx_stopwords' => 'bool', 'fulltext_sphinx_indexer_mem_limit' => 'int', @@ -778,6 +779,10 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
+
+

' . $this->user->lang['FULLTEXT_SPHINX_HOST_EXPLAIN'] . '
+
+

' . $this->user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
-- cgit v1.2.1 From e40758db84a23bc7a2c5324dbedcd7f0911abeea Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 03:16:03 +0530 Subject: [feature/sphinx-fulltext-search] remove stopwords and config path Remove stopwords and config_path options from ACP. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 3bdce5dfb9..e1052ee7da 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -147,7 +147,7 @@ class phpbb_search_fulltext_sphinx } // Check if directory paths have been filled - if (!$this->config['fulltext_sphinx_data_path'] || !$this->config['fulltext_sphinx_config_path']) + if (!$this->config['fulltext_sphinx_data_path']) { $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA'); return false; @@ -225,7 +225,7 @@ class phpbb_search_fulltext_sphinx array('source', 'source_phpbb_' . $this->id . '_main'), array('docinfo', 'extern'), array('morphology', 'none'), - array('stopwords', $this->config['fulltext_sphinx_stopwords'] ? $this->config['fulltext_sphinx_config_path'] . 'sphinx_stopwords.txt' : ''), + array('stopwords', ''), array('min_word_len', '2'), array('charset_type', 'utf-8'), array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'), @@ -757,28 +757,18 @@ class phpbb_search_fulltext_sphinx function acp() { $config_vars = array( - 'fulltext_sphinx_config_path' => 'string', 'fulltext_sphinx_data_path' => 'string', 'fulltext_sphinx_host' => 'string', 'fulltext_sphinx_port' => 'int', - 'fulltext_sphinx_stopwords' => 'bool', 'fulltext_sphinx_indexer_mem_limit' => 'int', ); $tpl = ' ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE']. ' -
-

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN'] . '
-
-

' . $this->user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
-
-

' . $this->user->lang['FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN'] . '
-
-

' . $this->user->lang['FULLTEXT_SPHINX_HOST_EXPLAIN'] . '
-- cgit v1.2.1 From 39bac86f7db881a1035bebad56507145103218d5 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 03:43:50 +0530 Subject: [feature/sphinx-fulltext-search] improve port option Use listen instead of deprecated port value in sphinx config file. sqlhost uses default $dbhost. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index e1052ee7da..18037a2be0 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -166,7 +166,7 @@ class phpbb_search_fulltext_sphinx array('sql_user', $dbuser), array('sql_pass', $dbpasswd), array('sql_db', $dbname), - array('sql_port', $this->config['fulltext_sphinx_port']), + array('sql_port', $dbport), array('sql_query_pre', 'SET NAMES \'utf8\''), array('sql_query_pre', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ') WHERE counter_id = 1'), array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''), @@ -241,8 +241,7 @@ class phpbb_search_fulltext_sphinx ), 'searchd' => array( array('compat_sphinxql_magics' , '0'), - array('listen' , '127.0.0.1'), - array('port', ($this->config['fulltext_sphinx_port']) ? $this->config['fulltext_sphinx_port'] : '3312'), + array('listen' , 'localhost' . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '3312')), array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), array('read_timeout', '5'), @@ -759,7 +758,7 @@ class phpbb_search_fulltext_sphinx $config_vars = array( 'fulltext_sphinx_data_path' => 'string', 'fulltext_sphinx_host' => 'string', - 'fulltext_sphinx_port' => 'int', + 'fulltext_sphinx_port' => 'string', 'fulltext_sphinx_indexer_mem_limit' => 'int', ); -- cgit v1.2.1 From 747af894a0b8d47079e704c66dcfce8ce00a7251 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 26 Jul 2012 16:18:53 +0530 Subject: [feature/sphinx-fulltext-search] fixing comments Use // for two liners in comments. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 4 ++-- phpBB/includes/search/sphinx/config.php | 32 +++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 18037a2be0..9319a57236 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -483,8 +483,8 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); - /* Could be connection to localhost:3312 failed (errno=111, - msg=Connection refused) during rotate, retry if so */ + // Could be connection to localhost:3312 failed (errno=111, + // msg=Connection refused) during rotate, retry if so $retries = SPHINX_CONNECT_RETRIES; while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--) { diff --git a/phpBB/includes/search/sphinx/config.php b/phpBB/includes/search/sphinx/config.php index 795dff07ed..f1864f0c8c 100644 --- a/phpBB/includes/search/sphinx/config.php +++ b/phpBB/includes/search/sphinx/config.php @@ -91,8 +91,8 @@ class phpbb_search_sphinx_config foreach ($config_data as $i => $line) { - /* If the value of a variable continues to the next line because the line - break was escaped then we don't trim leading space but treat it as a part of the value */ + // If the value of a variable continues to the next line because the line + // break was escaped then we don't trim leading space but treat it as a part of the value if ($in_value) { $line = rtrim($line); @@ -105,8 +105,8 @@ class phpbb_search_sphinx_config // If we're not inside a section look for one if (!$section) { - /* Add empty lines and comments as comment objects to the section list - that way they're not deleted when reassembling the file from the sections*/ + // Add empty lines and comments as comment objects to the section list + // that way they're not deleted when reassembling the file from the sections if (!$line || $line[0] == '#') { $this->sections[] = new phpbb_search_sphinx_config_comment($config_file[$i]); @@ -114,8 +114,8 @@ class phpbb_search_sphinx_config } else { - /* Otherwise we scan the line reading the section name until we find - an opening curly bracket or a comment */ + // Otherwise we scan the line reading the section name until we find + // an opening curly bracket or a comment $section_name = ''; $section_name_comment = ''; $found_opening_bracket = false; @@ -154,16 +154,16 @@ class phpbb_search_sphinx_config // If we're not in a value continuing over the line feed if (!$in_value) { - /* Then add empty lines and comments as comment objects to the variable list - of this section so they're not deleted on reassembly */ + // Then add empty lines and comments as comment objects to the variable list + // of this section so they're not deleted on reassembly if (!$line || $line[0] == '#') { $section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); continue; } - /* As long as we haven't yet actually found an opening bracket for this section - we treat everything as comments so it's not deleted either */ + // As long as we haven't yet actually found an opening bracket for this section + // we treat everything as comments so it's not deleted either if (!$found_opening_bracket) { if ($line[0] == '{') @@ -180,8 +180,8 @@ class phpbb_search_sphinx_config } } - /* If we did not find a comment in this line or still add to the previous - line's value ... */ + // If we did not find a comment in this line or still add to the previous + // line's value ... if ($line || $in_value) { if (!$in_value) @@ -239,8 +239,8 @@ class phpbb_search_sphinx_config } } - /* If a name and an equal sign were found then we have append a - new variable object to the section */ + // If a name and an equal sign were found then we have append a + // new variable object to the section if ($name && $found_assignment) { $section->add_variable(new phpbb_search_sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); @@ -259,8 +259,8 @@ class phpbb_search_sphinx_config } } - /* If we did not find anything meaningful up to here, then just treat it - as a comment */ + // If we did not find anything meaningful up to here, then just treat it + // as a comment $comment = ($skip_first) ? "\t" . substr(ltrim($config_file[$i]), 1) : $config_file[$i]; $section->add_variable(new phpbb_search_sphinx_config_comment($comment)); } -- cgit v1.2.1 From eb4298c646d2b41a46dfef5ad2a72ea520b13539 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 26 Jul 2012 16:55:11 +0530 Subject: [feature/sphinx-fulltext-search] coding changes acc to phbb conventions Add a new line after break. Change docblocks to be more informative. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 9319a57236..303b6feae8 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -103,7 +103,7 @@ class phpbb_search_fulltext_sphinx /** * Checks permissions and paths, if everything is correct it generates the config file * - * @return string|bool Language key of the error/incompatiblity occured + * @return string|bool Language key of the error/incompatiblity encountered, or false if successful * * @access public */ @@ -381,14 +381,19 @@ class phpbb_search_fulltext_sphinx case 'a': $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'poster_id ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); break; + case 'f': $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'forum_id ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); break; + case 'i': + case 's': $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'post_subject ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); break; + case 't': + default: $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'topic_last_post_time ' . (($sort_dir == 'a') ? 'ASC' : 'DESC')); break; @@ -401,14 +406,19 @@ class phpbb_search_fulltext_sphinx case 'a': $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'poster_id'); break; + case 'f': $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'forum_id'); break; + case 'i': + case 's': $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_subject'); break; + case 't': + default: $this->sphinx->SetSortMode(($sort_dir == 'a') ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_time'); break; @@ -619,7 +629,7 @@ class phpbb_search_fulltext_sphinx } /** - * Destroy old cache entries + * Nothing needs to be destroyed * * @access public */ -- cgit v1.2.1 From a6b5b2784fc45764bce077481c40572b49c8b60d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 26 Jul 2012 17:32:06 +0530 Subject: [feature/sphinx-fulltext-search] fix sphinx for arbitary host PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 303b6feae8..3d16438ab8 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -82,8 +82,7 @@ class phpbb_search_fulltext_sphinx $this->sphinx = new SphinxClient(); - // We only support localhost for now - $this->sphinx->SetServer('localhost', (isset($this->config['fulltext_sphinx_port']) && $this->config['fulltext_sphinx_port']) ? (int) $this->config['fulltext_sphinx_port'] : 3312); + $this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 3312)); $error = false; } @@ -162,7 +161,8 @@ class phpbb_search_fulltext_sphinx $config_data = array( 'source source_phpbb_' . $this->id . '_main' => array( array('type', $this->dbtype), - array('sql_host', $this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : $dbhost), + // This config value sql_host needs to be changed incase sphinx and sql are on different servers + array('sql_host', $dbhost), array('sql_user', $dbuser), array('sql_pass', $dbpasswd), array('sql_db', $dbname), @@ -241,7 +241,7 @@ class phpbb_search_fulltext_sphinx ), 'searchd' => array( array('compat_sphinxql_magics' , '0'), - array('listen' , 'localhost' . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '3312')), + array('listen' , ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '3312')), array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), array('read_timeout', '5'), -- cgit v1.2.1 From 654798922574ef086d618b50a8a8d16eceaa5320 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 27 Jul 2012 02:48:25 +0530 Subject: [feature/sphinx-fulltext-search] use 9312 as default port Uses 9312 instead of 3312 as default port for searchd to listen on according to latest sphinx documentation. Use filename sphinxapi.php instead of old one. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 3d16438ab8..e9772239bf 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * function and the variables used are in global space. */ global $phpbb_root_path, $phpEx, $table_prefix; -require($phpbb_root_path . 'includes/sphinxapi-0.9.8.' . $phpEx); +require($phpbb_root_path . 'includes/sphinxapi.' . $phpEx); define('SPHINX_MAX_MATCHES', 20000); define('SPHINX_CONNECT_RETRIES', 3); @@ -82,7 +82,7 @@ class phpbb_search_fulltext_sphinx $this->sphinx = new SphinxClient(); - $this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 3312)); + $this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 9312)); $error = false; } @@ -241,7 +241,7 @@ class phpbb_search_fulltext_sphinx ), 'searchd' => array( array('compat_sphinxql_magics' , '0'), - array('listen' , ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '3312')), + array('listen' , ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '9312')), array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'), array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'), array('read_timeout', '5'), @@ -493,7 +493,7 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); - // Could be connection to localhost:3312 failed (errno=111, + // Could be connection to localhost:9312 failed (errno=111, // msg=Connection refused) during rotate, retry if so $retries = SPHINX_CONNECT_RETRIES; while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--) -- cgit v1.2.1 From cec9f7d54e360bc2b6b4b12c3123d9c5216d2b62 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 27 Jul 2012 02:49:44 +0530 Subject: [feature/sphinx-fulltext-search] remove unused property Removes unused property $word_length PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index e9772239bf..9cf6f41fa0 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -47,7 +47,6 @@ class phpbb_search_fulltext_sphinx private $dbtype; private $user; private $config_file_data = ''; - public $word_length = array(); public $search_query; public $common_words = array(); -- cgit v1.2.1 From fe8a0d3bc6767f43e7df0b6c964a7f19fa3a5ccc Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 27 Jul 2012 10:50:20 +0530 Subject: [feature/sphinx-fulltext-search] fix auth bug $this->auth replaces $auth as at other occurences of auth. PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 9cf6f41fa0..8371f6b377 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -477,7 +477,7 @@ class phpbb_search_fulltext_sphinx if (sizeof($ex_fid_ary)) { // All forums that a user is allowed to access - $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($auth->acl_getf('f_search', true)))); + $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($this->auth->acl_getf('f_search', true)))); // All forums that the user wants to and can search in $search_forums = array_diff($fid_ary, $ex_fid_ary); -- cgit v1.2.1 From 033a2328c4f4451d6ec1f3eb310b5ad4e846e28e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 27 Jul 2012 11:27:25 +0530 Subject: [feature/sphinx-fulltext-search] add sphinxapi.php file PHPBB3-10946 --- phpBB/includes/sphinxapi.php | 1712 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1712 insertions(+) create mode 100644 phpBB/includes/sphinxapi.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/sphinxapi.php b/phpBB/includes/sphinxapi.php new file mode 100644 index 0000000000..bd83b1d2e0 --- /dev/null +++ b/phpBB/includes/sphinxapi.php @@ -0,0 +1,1712 @@ +=8 ) + { + $v = (int)$v; + return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); + } + + // x32, int + if ( is_int($v) ) + return pack ( "NN", $v < 0 ? -1 : 0, $v ); + + // x32, bcmath + if ( function_exists("bcmul") ) + { + if ( bccomp ( $v, 0 ) == -1 ) + $v = bcadd ( "18446744073709551616", $v ); + $h = bcdiv ( $v, "4294967296", 0 ); + $l = bcmod ( $v, "4294967296" ); + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit + } + + // x32, no-bcmath + $p = max(0, strlen($v) - 13); + $lo = abs((float)substr($v, $p)); + $hi = abs((float)substr($v, 0, $p)); + + $m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 + $q = floor($m/4294967296.0); + $l = $m - ($q*4294967296.0); + $h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 + + if ( $v<0 ) + { + if ( $l==0 ) + $h = 4294967296.0 - $h; + else + { + $h = 4294967295.0 - $h; + $l = 4294967296.0 - $l; + } + } + return pack ( "NN", $h, $l ); +} + +/// pack 64-bit unsigned +function sphPackU64 ( $v ) +{ + assert ( is_numeric($v) ); + + // x64 + if ( PHP_INT_SIZE>=8 ) + { + assert ( $v>=0 ); + + // x64, int + if ( is_int($v) ) + return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); + + // x64, bcmath + if ( function_exists("bcmul") ) + { + $h = bcdiv ( $v, 4294967296, 0 ); + $l = bcmod ( $v, 4294967296 ); + return pack ( "NN", $h, $l ); + } + + // x64, no-bcmath + $p = max ( 0, strlen($v) - 13 ); + $lo = (int)substr ( $v, $p ); + $hi = (int)substr ( $v, 0, $p ); + + $m = $lo + $hi*1316134912; + $l = $m % 4294967296; + $h = $hi*2328 + (int)($m/4294967296); + + return pack ( "NN", $h, $l ); + } + + // x32, int + if ( is_int($v) ) + return pack ( "NN", 0, $v ); + + // x32, bcmath + if ( function_exists("bcmul") ) + { + $h = bcdiv ( $v, "4294967296", 0 ); + $l = bcmod ( $v, "4294967296" ); + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit + } + + // x32, no-bcmath + $p = max(0, strlen($v) - 13); + $lo = (float)substr($v, $p); + $hi = (float)substr($v, 0, $p); + + $m = $lo + $hi*1316134912.0; + $q = floor($m / 4294967296.0); + $l = $m - ($q * 4294967296.0); + $h = $hi*2328.0 + $q; + + return pack ( "NN", $h, $l ); +} + +// unpack 64-bit unsigned +function sphUnpackU64 ( $v ) +{ + list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); + + if ( PHP_INT_SIZE>=8 ) + { + if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again + if ( $lo<0 ) $lo += (1<<32); + + // x64, int + if ( $hi<=2147483647 ) + return ($hi<<32) + $lo; + + // x64, bcmath + if ( function_exists("bcmul") ) + return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); + + // x64, no-bcmath + $C = 100000; + $h = ((int)($hi / $C) << 32) + (int)($lo / $C); + $l = (($hi % $C) << 32) + ($lo % $C); + if ( $l>$C ) + { + $h += (int)($l / $C); + $l = $l % $C; + } + + if ( $h==0 ) + return $l; + return sprintf ( "%d%05d", $h, $l ); + } + + // x32, int + if ( $hi==0 ) + { + if ( $lo>0 ) + return $lo; + return sprintf ( "%u", $lo ); + } + + $hi = sprintf ( "%u", $hi ); + $lo = sprintf ( "%u", $lo ); + + // x32, bcmath + if ( function_exists("bcmul") ) + return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); + + // x32, no-bcmath + $hi = (float)$hi; + $lo = (float)$lo; + + $q = floor($hi/10000000.0); + $r = $hi - $q*10000000.0; + $m = $lo + $r*4967296.0; + $mq = floor($m/10000000.0); + $l = $m - $mq*10000000.0; + $h = $q*4294967296.0 + $r*429.0 + $mq; + + $h = sprintf ( "%.0f", $h ); + $l = sprintf ( "%07.0f", $l ); + if ( $h=="0" ) + return sprintf( "%.0f", (float)$l ); + return $h . $l; +} + +// unpack 64-bit signed +function sphUnpackI64 ( $v ) +{ + list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); + + // x64 + if ( PHP_INT_SIZE>=8 ) + { + if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again + if ( $lo<0 ) $lo += (1<<32); + + return ($hi<<32) + $lo; + } + + // x32, int + if ( $hi==0 ) + { + if ( $lo>0 ) + return $lo; + return sprintf ( "%u", $lo ); + } + // x32, int + elseif ( $hi==-1 ) + { + if ( $lo<0 ) + return $lo; + return sprintf ( "%.0f", $lo - 4294967296.0 ); + } + + $neg = ""; + $c = 0; + if ( $hi<0 ) + { + $hi = ~$hi; + $lo = ~$lo; + $c = 1; + $neg = "-"; + } + + $hi = sprintf ( "%u", $hi ); + $lo = sprintf ( "%u", $lo ); + + // x32, bcmath + if ( function_exists("bcmul") ) + return $neg . bcadd ( bcadd ( $lo, bcmul ( $hi, "4294967296" ) ), $c ); + + // x32, no-bcmath + $hi = (float)$hi; + $lo = (float)$lo; + + $q = floor($hi/10000000.0); + $r = $hi - $q*10000000.0; + $m = $lo + $r*4967296.0; + $mq = floor($m/10000000.0); + $l = $m - $mq*10000000.0 + $c; + $h = $q*4294967296.0 + $r*429.0 + $mq; + if ( $l==10000000 ) + { + $l = 0; + $h += 1; + } + + $h = sprintf ( "%.0f", $h ); + $l = sprintf ( "%07.0f", $l ); + if ( $h=="0" ) + return $neg . sprintf( "%.0f", (float)$l ); + return $neg . $h . $l; +} + + +function sphFixUint ( $value ) +{ + if ( PHP_INT_SIZE>=8 ) + { + // x64 route, workaround broken unpack() in 5.2.2+ + if ( $value<0 ) $value += (1<<32); + return $value; + } + else + { + // x32 route, workaround php signed/unsigned braindamage + return sprintf ( "%u", $value ); + } +} + + +/// sphinx searchd client class +class SphinxClient +{ + var $_host; ///< searchd host (default is "localhost") + var $_port; ///< searchd port (default is 9312) + var $_offset; ///< how many records to seek from result-set start (default is 0) + var $_limit; ///< how many records to return from result-set starting at offset (default is 20) + var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) + var $_weights; ///< per-field weights (default is 1 for all fields) + var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) + var $_sortby; ///< attribute to sort by (defualt is "") + var $_min_id; ///< min ID to match (default is 0, which means no limit) + var $_max_id; ///< max ID to match (default is 0, which means no limit) + var $_filters; ///< search filters + var $_groupby; ///< group-by attribute name + var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) + var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) + var $_groupdistinct;///< group-by count-distinct attribute + var $_maxmatches; ///< max matches to retrieve + var $_cutoff; ///< cutoff to stop searching at (default is 0) + var $_retrycount; ///< distributed retries count + var $_retrydelay; ///< distributed retries delay + var $_anchor; ///< geographical anchor point + var $_indexweights; ///< per-index weights + var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) + var $_rankexpr; ///< ranking mode expression (for SPH_RANK_EXPR) + var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) + var $_fieldweights; ///< per-field-name weights + var $_overrides; ///< per-query attribute values overrides + var $_select; ///< select-list (attributes or expressions, with optional aliases) + + var $_error; ///< last error message + var $_warning; ///< last warning message + var $_connerror; ///< connection error vs remote error flag + + var $_reqs; ///< requests array for multi-query + var $_mbenc; ///< stored mbstring encoding + var $_arrayresult; ///< whether $result["matches"] should be a hash or an array + var $_timeout; ///< connect timeout + + ///////////////////////////////////////////////////////////////////////////// + // common stuff + ///////////////////////////////////////////////////////////////////////////// + + /// create a new client object and fill defaults + function SphinxClient () + { + // per-client-object settings + $this->_host = "localhost"; + $this->_port = 9312; + $this->_path = false; + $this->_socket = false; + + // per-query settings + $this->_offset = 0; + $this->_limit = 20; + $this->_mode = SPH_MATCH_ALL; + $this->_weights = array (); + $this->_sort = SPH_SORT_RELEVANCE; + $this->_sortby = ""; + $this->_min_id = 0; + $this->_max_id = 0; + $this->_filters = array (); + $this->_groupby = ""; + $this->_groupfunc = SPH_GROUPBY_DAY; + $this->_groupsort = "@group desc"; + $this->_groupdistinct= ""; + $this->_maxmatches = 1000; + $this->_cutoff = 0; + $this->_retrycount = 0; + $this->_retrydelay = 0; + $this->_anchor = array (); + $this->_indexweights= array (); + $this->_ranker = SPH_RANK_PROXIMITY_BM25; + $this->_rankexpr = ""; + $this->_maxquerytime= 0; + $this->_fieldweights= array(); + $this->_overrides = array(); + $this->_select = "*"; + + $this->_error = ""; // per-reply fields (for single-query case) + $this->_warning = ""; + $this->_connerror = false; + + $this->_reqs = array (); // requests storage (for multi-query case) + $this->_mbenc = ""; + $this->_arrayresult = false; + $this->_timeout = 0; + } + + function __destruct() + { + if ( $this->_socket !== false ) + fclose ( $this->_socket ); + } + + /// get last error message (string) + function GetLastError () + { + return $this->_error; + } + + /// get last warning message (string) + function GetLastWarning () + { + return $this->_warning; + } + + /// get last error flag (to tell network connection errors from searchd errors or broken responses) + function IsConnectError() + { + return $this->_connerror; + } + + /// set searchd host name (string) and port (integer) + function SetServer ( $host, $port = 0 ) + { + assert ( is_string($host) ); + if ( $host[0] == '/') + { + $this->_path = 'unix://' . $host; + return; + } + if ( substr ( $host, 0, 7 )=="unix://" ) + { + $this->_path = $host; + return; + } + + assert ( is_int($port) ); + $this->_host = $host; + $this->_port = $port; + $this->_path = ''; + + } + + /// set server connection timeout (0 to remove) + function SetConnectTimeout ( $timeout ) + { + assert ( is_numeric($timeout) ); + $this->_timeout = $timeout; + } + + + function _Send ( $handle, $data, $length ) + { + if ( feof($handle) || fwrite ( $handle, $data, $length ) !== $length ) + { + $this->_error = 'connection unexpectedly closed (timed out?)'; + $this->_connerror = true; + return false; + } + return true; + } + + ///////////////////////////////////////////////////////////////////////////// + + /// enter mbstring workaround mode + function _MBPush () + { + $this->_mbenc = ""; + if ( ini_get ( "mbstring.func_overload" ) & 2 ) + { + $this->_mbenc = mb_internal_encoding(); + mb_internal_encoding ( "latin1" ); + } + } + + /// leave mbstring workaround mode + function _MBPop () + { + if ( $this->_mbenc ) + mb_internal_encoding ( $this->_mbenc ); + } + + /// connect to searchd server + function _Connect () + { + if ( $this->_socket!==false ) + { + // we are in persistent connection mode, so we have a socket + // however, need to check whether it's still alive + if ( !@feof ( $this->_socket ) ) + return $this->_socket; + + // force reopen + $this->_socket = false; + } + + $errno = 0; + $errstr = ""; + $this->_connerror = false; + + if ( $this->_path ) + { + $host = $this->_path; + $port = 0; + } + else + { + $host = $this->_host; + $port = $this->_port; + } + + if ( $this->_timeout<=0 ) + $fp = @fsockopen ( $host, $port, $errno, $errstr ); + else + $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); + + if ( !$fp ) + { + if ( $this->_path ) + $location = $this->_path; + else + $location = "{$this->_host}:{$this->_port}"; + + $errstr = trim ( $errstr ); + $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; + $this->_connerror = true; + return false; + } + + // send my version + // this is a subtle part. we must do it before (!) reading back from searchd. + // because otherwise under some conditions (reported on FreeBSD for instance) + // TCP stack could throttle write-write-read pattern because of Nagle. + if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) ) + { + fclose ( $fp ); + $this->_error = "failed to send client protocol version"; + return false; + } + + // check version + list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); + $v = (int)$v; + if ( $v<1 ) + { + fclose ( $fp ); + $this->_error = "expected searchd protocol version 1+, got version '$v'"; + return false; + } + + return $fp; + } + + /// get and check response packet from searchd server + function _GetResponse ( $fp, $client_ver ) + { + $response = ""; + $len = 0; + + $header = fread ( $fp, 8 ); + if ( strlen($header)==8 ) + { + list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); + $left = $len; + while ( $left>0 && !feof($fp) ) + { + $chunk = fread ( $fp, min ( 8192, $left ) ); + if ( $chunk ) + { + $response .= $chunk; + $left -= strlen($chunk); + } + } + } + if ( $this->_socket === false ) + fclose ( $fp ); + + // check response + $read = strlen ( $response ); + if ( !$response || $read!=$len ) + { + $this->_error = $len + ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" + : "received zero-sized searchd response"; + return false; + } + + // check status + if ( $status==SEARCHD_WARNING ) + { + list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); + $this->_warning = substr ( $response, 4, $wlen ); + return substr ( $response, 4+$wlen ); + } + if ( $status==SEARCHD_ERROR ) + { + $this->_error = "searchd error: " . substr ( $response, 4 ); + return false; + } + if ( $status==SEARCHD_RETRY ) + { + $this->_error = "temporary searchd error: " . substr ( $response, 4 ); + return false; + } + if ( $status!=SEARCHD_OK ) + { + $this->_error = "unknown status code '$status'"; + return false; + } + + // check version + if ( $ver<$client_ver ) + { + $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", + $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); + } + + return $response; + } + + ///////////////////////////////////////////////////////////////////////////// + // searching + ///////////////////////////////////////////////////////////////////////////// + + /// set offset and count into result set, + /// and optionally set max-matches and cutoff limits + function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) + { + assert ( is_int($offset) ); + assert ( is_int($limit) ); + assert ( $offset>=0 ); + assert ( $limit>0 ); + assert ( $max>=0 ); + $this->_offset = $offset; + $this->_limit = $limit; + if ( $max>0 ) + $this->_maxmatches = $max; + if ( $cutoff>0 ) + $this->_cutoff = $cutoff; + } + + /// set maximum query time, in milliseconds, per-index + /// integer, 0 means "do not limit" + function SetMaxQueryTime ( $max ) + { + assert ( is_int($max) ); + assert ( $max>=0 ); + $this->_maxquerytime = $max; + } + + /// set matching mode + function SetMatchMode ( $mode ) + { + assert ( $mode==SPH_MATCH_ALL + || $mode==SPH_MATCH_ANY + || $mode==SPH_MATCH_PHRASE + || $mode==SPH_MATCH_BOOLEAN + || $mode==SPH_MATCH_EXTENDED + || $mode==SPH_MATCH_FULLSCAN + || $mode==SPH_MATCH_EXTENDED2 ); + $this->_mode = $mode; + } + + /// set ranking mode + function SetRankingMode ( $ranker, $rankexpr="" ) + { + assert ( $ranker>=0 && $ranker_ranker = $ranker; + $this->_rankexpr = $rankexpr; + } + + /// set matches sorting mode + function SetSortMode ( $mode, $sortby="" ) + { + assert ( + $mode==SPH_SORT_RELEVANCE || + $mode==SPH_SORT_ATTR_DESC || + $mode==SPH_SORT_ATTR_ASC || + $mode==SPH_SORT_TIME_SEGMENTS || + $mode==SPH_SORT_EXTENDED || + $mode==SPH_SORT_EXPR ); + assert ( is_string($sortby) ); + assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); + + $this->_sort = $mode; + $this->_sortby = $sortby; + } + + /// bind per-field weights by order + /// DEPRECATED; use SetFieldWeights() instead + function SetWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $weight ) + assert ( is_int($weight) ); + + $this->_weights = $weights; + } + + /// bind per-field weights by name + function SetFieldWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $name=>$weight ) + { + assert ( is_string($name) ); + assert ( is_int($weight) ); + } + $this->_fieldweights = $weights; + } + + /// bind per-index weights by name + function SetIndexWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $index=>$weight ) + { + assert ( is_string($index) ); + assert ( is_int($weight) ); + } + $this->_indexweights = $weights; + } + + /// set IDs range to match + /// only match records if document ID is beetwen $min and $max (inclusive) + function SetIDRange ( $min, $max ) + { + assert ( is_numeric($min) ); + assert ( is_numeric($max) ); + assert ( $min<=$max ); + $this->_min_id = $min; + $this->_max_id = $max; + } + + /// set values set filter + /// only match records where $attribute value is in given set + function SetFilter ( $attribute, $values, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_array($values) ); + assert ( count($values) ); + + if ( is_array($values) && count($values) ) + { + foreach ( $values as $value ) + assert ( is_numeric($value) ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); + } + } + + /// set range filter + /// only match records if $attribute value is beetwen $min and $max (inclusive) + function SetFilterRange ( $attribute, $min, $max, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_numeric($min) ); + assert ( is_numeric($max) ); + assert ( $min<=$max ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); + } + + /// set float range filter + /// only match records if $attribute value is beetwen $min and $max (inclusive) + function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_float($min) ); + assert ( is_float($max) ); + assert ( $min<=$max ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); + } + + /// setup anchor point for geosphere distance calculations + /// required to use @geodist in filters and sorting + /// latitude and longitude must be in radians + function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) + { + assert ( is_string($attrlat) ); + assert ( is_string($attrlong) ); + assert ( is_float($lat) ); + assert ( is_float($long) ); + + $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); + } + + /// set grouping attribute and function + function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) + { + assert ( is_string($attribute) ); + assert ( is_string($groupsort) ); + assert ( $func==SPH_GROUPBY_DAY + || $func==SPH_GROUPBY_WEEK + || $func==SPH_GROUPBY_MONTH + || $func==SPH_GROUPBY_YEAR + || $func==SPH_GROUPBY_ATTR + || $func==SPH_GROUPBY_ATTRPAIR ); + + $this->_groupby = $attribute; + $this->_groupfunc = $func; + $this->_groupsort = $groupsort; + } + + /// set count-distinct attribute for group-by queries + function SetGroupDistinct ( $attribute ) + { + assert ( is_string($attribute) ); + $this->_groupdistinct = $attribute; + } + + /// set distributed retries count and delay + function SetRetries ( $count, $delay=0 ) + { + assert ( is_int($count) && $count>=0 ); + assert ( is_int($delay) && $delay>=0 ); + $this->_retrycount = $count; + $this->_retrydelay = $delay; + } + + /// set result set format (hash or array; hash by default) + /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs + function SetArrayResult ( $arrayresult ) + { + assert ( is_bool($arrayresult) ); + $this->_arrayresult = $arrayresult; + } + + /// set attribute values override + /// there can be only one override per attribute + /// $values must be a hash that maps document IDs to attribute values + function SetOverride ( $attrname, $attrtype, $values ) + { + assert ( is_string ( $attrname ) ); + assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) ); + assert ( is_array ( $values ) ); + + $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values ); + } + + /// set select-list (attributes or expressions), SQL-like syntax + function SetSelect ( $select ) + { + assert ( is_string ( $select ) ); + $this->_select = $select; + } + + ////////////////////////////////////////////////////////////////////////////// + + /// clear all filters (for multi-queries) + function ResetFilters () + { + $this->_filters = array(); + $this->_anchor = array(); + } + + /// clear groupby settings (for multi-queries) + function ResetGroupBy () + { + $this->_groupby = ""; + $this->_groupfunc = SPH_GROUPBY_DAY; + $this->_groupsort = "@group desc"; + $this->_groupdistinct= ""; + } + + /// clear all attribute value overrides (for multi-queries) + function ResetOverrides () + { + $this->_overrides = array (); + } + + ////////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, run given search query through given indexes, + /// and return the search results + function Query ( $query, $index="*", $comment="" ) + { + assert ( empty($this->_reqs) ); + + $this->AddQuery ( $query, $index, $comment ); + $results = $this->RunQueries (); + $this->_reqs = array (); // just in case it failed too early + + if ( !is_array($results) ) + return false; // probably network error; error message should be already filled + + $this->_error = $results[0]["error"]; + $this->_warning = $results[0]["warning"]; + if ( $results[0]["status"]==SEARCHD_ERROR ) + return false; + else + return $results[0]; + } + + /// helper to pack floats in network byte order + function _PackFloat ( $f ) + { + $t1 = pack ( "f", $f ); // machine order + list(,$t2) = unpack ( "L*", $t1 ); // int in machine order + return pack ( "N", $t2 ); + } + + /// add query to multi-query batch + /// returns index into results array from RunQueries() call + function AddQuery ( $query, $index="*", $comment="" ) + { + // mbstring workaround + $this->_MBPush (); + + // build request + $req = pack ( "NNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker ); + if ( $this->_ranker==SPH_RANK_EXPR ) + $req .= pack ( "N", strlen($this->_rankexpr) ) . $this->_rankexpr; + $req .= pack ( "N", $this->_sort ); // (deprecated) sort mode + $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; + $req .= pack ( "N", strlen($query) ) . $query; // query itself + $req .= pack ( "N", count($this->_weights) ); // weights + foreach ( $this->_weights as $weight ) + $req .= pack ( "N", (int)$weight ); + $req .= pack ( "N", strlen($index) ) . $index; // indexes + $req .= pack ( "N", 1 ); // id64 range marker + $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range + + // filters + $req .= pack ( "N", count($this->_filters) ); + foreach ( $this->_filters as $filter ) + { + $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; + $req .= pack ( "N", $filter["type"] ); + switch ( $filter["type"] ) + { + case SPH_FILTER_VALUES: + $req .= pack ( "N", count($filter["values"]) ); + foreach ( $filter["values"] as $value ) + $req .= sphPackI64 ( $value ); + break; + + case SPH_FILTER_RANGE: + $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); + break; + + case SPH_FILTER_FLOATRANGE: + $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); + break; + + default: + assert ( 0 && "internal error: unhandled filter type" ); + } + $req .= pack ( "N", $filter["exclude"] ); + } + + // group-by clause, max-matches count, group-sort clause, cutoff count + $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; + $req .= pack ( "N", $this->_maxmatches ); + $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; + $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); + $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; + + // anchor point + if ( empty($this->_anchor) ) + { + $req .= pack ( "N", 0 ); + } else + { + $a =& $this->_anchor; + $req .= pack ( "N", 1 ); + $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; + $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; + $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); + } + + // per-index weights + $req .= pack ( "N", count($this->_indexweights) ); + foreach ( $this->_indexweights as $idx=>$weight ) + $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); + + // max query time + $req .= pack ( "N", $this->_maxquerytime ); + + // per-field weights + $req .= pack ( "N", count($this->_fieldweights) ); + foreach ( $this->_fieldweights as $field=>$weight ) + $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); + + // comment + $req .= pack ( "N", strlen($comment) ) . $comment; + + // attribute overrides + $req .= pack ( "N", count($this->_overrides) ); + foreach ( $this->_overrides as $key => $entry ) + { + $req .= pack ( "N", strlen($entry["attr"]) ) . $entry["attr"]; + $req .= pack ( "NN", $entry["type"], count($entry["values"]) ); + foreach ( $entry["values"] as $id=>$val ) + { + assert ( is_numeric($id) ); + assert ( is_numeric($val) ); + + $req .= sphPackU64 ( $id ); + switch ( $entry["type"] ) + { + case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; + case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; + default: $req .= pack ( "N", $val ); break; + } + } + } + + // select-list + $req .= pack ( "N", strlen($this->_select) ) . $this->_select; + + // mbstring workaround + $this->_MBPop (); + + // store request to requests array + $this->_reqs[] = $req; + return count($this->_reqs)-1; + } + + /// connect to searchd, run queries batch, and return an array of result sets + function RunQueries () + { + if ( empty($this->_reqs) ) + { + $this->_error = "no queries defined, issue AddQuery() first"; + return false; + } + + // mbstring workaround + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop (); + return false; + } + + // send query, get response + $nreqs = count($this->_reqs); + $req = join ( "", $this->_reqs ); + $len = 8+strlen($req); + $req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header + + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) ) + { + $this->_MBPop (); + return false; + } + + // query sent ok; we can reset reqs now + $this->_reqs = array (); + + // parse and return response + return $this->_ParseSearchResponse ( $response, $nreqs ); + } + + /// parse and return search query (or queries) response + function _ParseSearchResponse ( $response, $nreqs ) + { + $p = 0; // current position + $max = strlen($response); // max position for checks, to protect against broken responses + + $results = array (); + for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) + { + $results[] = array(); + $result =& $results[$ires]; + + $result["error"] = ""; + $result["warning"] = ""; + + // extract status + list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $result["status"] = $status; + if ( $status!=SEARCHD_OK ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $message = substr ( $response, $p, $len ); $p += $len; + + if ( $status==SEARCHD_WARNING ) + { + $result["warning"] = $message; + } else + { + $result["error"] = $message; + continue; + } + } + + // read schema + $fields = array (); + $attrs = array (); + + list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + while ( $nfields-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $fields[] = substr ( $response, $p, $len ); $p += $len; + } + $result["fields"] = $fields; + + list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + while ( $nattrs-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attr = substr ( $response, $p, $len ); $p += $len; + list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attrs[$attr] = $type; + } + $result["attrs"] = $attrs; + + // read match count + list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + + // read matches + $idx = -1; + while ( $count-->0 && $p<$max ) + { + // index into result array + $idx++; + + // parse document id and weight + if ( $id64 ) + { + $doc = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; + list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + } + else + { + list ( $doc, $weight ) = array_values ( unpack ( "N*N*", + substr ( $response, $p, 8 ) ) ); + $p += 8; + $doc = sphFixUint($doc); + } + $weight = sprintf ( "%u", $weight ); + + // create match entry + if ( $this->_arrayresult ) + $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); + else + $result["matches"][$doc]["weight"] = $weight; + + // parse and create attributes + $attrvals = array (); + foreach ( $attrs as $attr=>$type ) + { + // handle 64bit ints + if ( $type==SPH_ATTR_BIGINT ) + { + $attrvals[$attr] = sphUnpackI64 ( substr ( $response, $p, 8 ) ); $p += 8; + continue; + } + + // handle floats + if ( $type==SPH_ATTR_FLOAT ) + { + list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); + $attrvals[$attr] = $fval; + continue; + } + + // handle everything else as unsigned ints + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + if ( $type==SPH_ATTR_MULTI ) + { + $attrvals[$attr] = array (); + $nvalues = $val; + while ( $nvalues-->0 && $p<$max ) + { + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attrvals[$attr][] = sphFixUint($val); + } + } else if ( $type==SPH_ATTR_MULTI64 ) + { + $attrvals[$attr] = array (); + $nvalues = $val; + while ( $nvalues>0 && $p<$max ) + { + $attrvals[$attr][] = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; + $nvalues -= 2; + } + } else if ( $type==SPH_ATTR_STRING ) + { + $attrvals[$attr] = substr ( $response, $p, $val ); + $p += $val; + } else + { + $attrvals[$attr] = sphFixUint($val); + } + } + + if ( $this->_arrayresult ) + $result["matches"][$idx]["attrs"] = $attrvals; + else + $result["matches"][$doc]["attrs"] = $attrvals; + } + + list ( $total, $total_found, $msecs, $words ) = + array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); + $result["total"] = sprintf ( "%u", $total ); + $result["total_found"] = sprintf ( "%u", $total_found ); + $result["time"] = sprintf ( "%.3f", $msecs/1000 ); + $p += 16; + + while ( $words-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $word = substr ( $response, $p, $len ); $p += $len; + list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; + $result["words"][$word] = array ( + "docs"=>sprintf ( "%u", $docs ), + "hits"=>sprintf ( "%u", $hits ) ); + } + } + + $this->_MBPop (); + return $results; + } + + ///////////////////////////////////////////////////////////////////////////// + // excerpts generation + ///////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, and generate exceprts (snippets) + /// of given documents for given query. returns false on failure, + /// an array of snippets on success + function BuildExcerpts ( $docs, $index, $words, $opts=array() ) + { + assert ( is_array($docs) ); + assert ( is_string($index) ); + assert ( is_string($words) ); + assert ( is_array($opts) ); + + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + ///////////////// + // fixup options + ///////////////// + + if ( !isset($opts["before_match"]) ) $opts["before_match"] = ""; + if ( !isset($opts["after_match"]) ) $opts["after_match"] = ""; + if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; + if ( !isset($opts["limit"]) ) $opts["limit"] = 256; + if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0; + if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0; + if ( !isset($opts["around"]) ) $opts["around"] = 5; + if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; + if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; + if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; + if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; + if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false; + if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false; + if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1; + if ( !isset($opts["load_files"]) ) $opts["load_files"] = false; + if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index"; + if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false; + if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; + if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; + if ( !isset($opts["load_files_scattered"]) ) $opts["load_files_scattered"] = false; + + + ///////////////// + // build request + ///////////////// + + // v.1.2 req + $flags = 1; // remove spaces + if ( $opts["exact_phrase"] ) $flags |= 2; + if ( $opts["single_passage"] ) $flags |= 4; + if ( $opts["use_boundaries"] ) $flags |= 8; + if ( $opts["weight_order"] ) $flags |= 16; + if ( $opts["query_mode"] ) $flags |= 32; + if ( $opts["force_all_words"] ) $flags |= 64; + if ( $opts["load_files"] ) $flags |= 128; + if ( $opts["allow_empty"] ) $flags |= 256; + if ( $opts["emit_zones"] ) $flags |= 512; + if ( $opts["load_files_scattered"] ) $flags |= 1024; + $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags + $req .= pack ( "N", strlen($index) ) . $index; // req index + $req .= pack ( "N", strlen($words) ) . $words; // req words + + // options + $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; + $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; + $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; + $req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] ); + $req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2 + $req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"]; + $req .= pack ( "N", strlen($opts["passage_boundary"]) ) . $opts["passage_boundary"]; + + // documents + $req .= pack ( "N", count($docs) ); + foreach ( $docs as $doc ) + { + assert ( is_string($doc) ); + $req .= pack ( "N", strlen($doc) ) . $doc; + } + + //////////////////////////// + // send query, get response + //////////////////////////// + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) ) + { + $this->_MBPop (); + return false; + } + + ////////////////// + // parse response + ////////////////// + + $pos = 0; + $res = array (); + $rlen = strlen($response); + for ( $i=0; $i $rlen ) + { + $this->_error = "incomplete reply"; + $this->_MBPop (); + return false; + } + $res[] = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + } + + $this->_MBPop (); + return $res; + } + + + ///////////////////////////////////////////////////////////////////////////// + // keyword generation + ///////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, and generate keyword list for a given query + /// returns false on failure, + /// an array of words on success + function BuildKeywords ( $query, $index, $hits ) + { + assert ( is_string($query) ); + assert ( is_string($index) ); + assert ( is_bool($hits) ); + + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + ///////////////// + // build request + ///////////////// + + // v.1.0 req + $req = pack ( "N", strlen($query) ) . $query; // req query + $req .= pack ( "N", strlen($index) ) . $index; // req index + $req .= pack ( "N", (int)$hits ); + + //////////////////////////// + // send query, get response + //////////////////////////// + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) ) + { + $this->_MBPop (); + return false; + } + + ////////////////// + // parse response + ////////////////// + + $pos = 0; + $res = array (); + $rlen = strlen($response); + list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); + $pos += 4; + for ( $i=0; $i<$nwords; $i++ ) + { + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; + $tokenized = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; + $normalized = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + + $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); + + if ( $hits ) + { + list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); + $pos += 8; + $res [$i]["docs"] = $ndocs; + $res [$i]["hits"] = $nhits; + } + + if ( $pos > $rlen ) + { + $this->_error = "incomplete reply"; + $this->_MBPop (); + return false; + } + } + + $this->_MBPop (); + return $res; + } + + function EscapeString ( $string ) + { + $from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' ); + $to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' ); + + return str_replace ( $from, $to, $string ); + } + + ///////////////////////////////////////////////////////////////////////////// + // attribute updates + ///////////////////////////////////////////////////////////////////////////// + + /// batch update given attributes in given rows in given indexes + /// returns amount of updated documents (0 or more) on success, or -1 on failure + function UpdateAttributes ( $index, $attrs, $values, $mva=false ) + { + // verify everything + assert ( is_string($index) ); + assert ( is_bool($mva) ); + + assert ( is_array($attrs) ); + foreach ( $attrs as $attr ) + assert ( is_string($attr) ); + + assert ( is_array($values) ); + foreach ( $values as $id=>$entry ) + { + assert ( is_numeric($id) ); + assert ( is_array($entry) ); + assert ( count($entry)==count($attrs) ); + foreach ( $entry as $v ) + { + if ( $mva ) + { + assert ( is_array($v) ); + foreach ( $v as $vv ) + assert ( is_int($vv) ); + } else + assert ( is_int($v) ); + } + } + + // build request + $this->_MBPush (); + $req = pack ( "N", strlen($index) ) . $index; + + $req .= pack ( "N", count($attrs) ); + foreach ( $attrs as $attr ) + { + $req .= pack ( "N", strlen($attr) ) . $attr; + $req .= pack ( "N", $mva ? 1 : 0 ); + } + + $req .= pack ( "N", count($values) ); + foreach ( $values as $id=>$entry ) + { + $req .= sphPackU64 ( $id ); + foreach ( $entry as $v ) + { + $req .= pack ( "N", $mva ? count($v) : $v ); + if ( $mva ) + foreach ( $v as $vv ) + $req .= pack ( "N", $vv ); + } + } + + // connect, send query, get response + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop (); + return -1; + } + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header + if ( !$this->_Send ( $fp, $req, $len+8 ) ) + { + $this->_MBPop (); + return -1; + } + + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) + { + $this->_MBPop (); + return -1; + } + + // parse response + list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); + $this->_MBPop (); + return $updated; + } + + ///////////////////////////////////////////////////////////////////////////// + // persistent connections + ///////////////////////////////////////////////////////////////////////////// + + function Open() + { + if ( $this->_socket !== false ) + { + $this->_error = 'already connected'; + return false; + } + if ( !$fp = $this->_Connect() ) + return false; + + // command, command version = 0, body length = 4, body = 1 + $req = pack ( "nnNN", SEARCHD_COMMAND_PERSIST, 0, 4, 1 ); + if ( !$this->_Send ( $fp, $req, 12 ) ) + return false; + + $this->_socket = $fp; + return true; + } + + function Close() + { + if ( $this->_socket === false ) + { + $this->_error = 'not connected'; + return false; + } + + fclose ( $this->_socket ); + $this->_socket = false; + + return true; + } + + ////////////////////////////////////////////////////////////////////////// + // status + ////////////////////////////////////////////////////////////////////////// + + function Status () + { + $this->_MBPush (); + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + $req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1 ); // len=4, body=1 + if ( !( $this->_Send ( $fp, $req, 12 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) ) + { + $this->_MBPop (); + return false; + } + + $res = substr ( $response, 4 ); // just ignore length, error handling, etc + $p = 0; + list ( $rows, $cols ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; + + $res = array(); + for ( $i=0; $i<$rows; $i++ ) + for ( $j=0; $j<$cols; $j++ ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $res[$i][] = substr ( $response, $p, $len ); $p += $len; + } + + $this->_MBPop (); + return $res; + } + + ////////////////////////////////////////////////////////////////////////// + // flush + ////////////////////////////////////////////////////////////////////////// + + function FlushAttributes () + { + $this->_MBPush (); + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return -1; + } + + $req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0 + if ( !( $this->_Send ( $fp, $req, 8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) ) + { + $this->_MBPop (); + return -1; + } + + $tag = -1; + if ( strlen($response)==4 ) + list(,$tag) = unpack ( "N*", $response ); + else + $this->_error = "unexpected response length"; + + $this->_MBPop (); + return $tag; + } +} + +// +// $Id: sphinxapi.php 3087 2012-01-30 23:07:35Z shodan $ +// -- cgit v1.2.1 From db1c80dee9c923326683252d70b6712c8432673a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 21 Jul 2012 17:38:28 +0530 Subject: [ticket/11011] add access specifiers and docblocks Add access specifiers and docblocks to mysql search backend. PHPBB3-11011 --- phpBB/includes/search/fulltext_mysql.php | 61 ++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 20dcb74c0d..64b3feb30c 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -22,12 +22,18 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_fulltext_mysql extends phpbb_search_base { - var $stats = array(); - var $word_length = array(); - var $split_words = array(); - var $search_query; - var $common_words = array(); + private $stats = array(); + private $split_words = array(); + public $word_length = array(); + public $search_query; + public $common_words = array(); + /** + * Constructor + * Creates a new phpbb_search_fulltext_mysql, which is used as a search backend. + * + * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false + */ public function __construct(&$error) { global $config; @@ -41,6 +47,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Returns the name of this search backend to be displayed to administrators * * @return string Name + * + * @access public */ public function get_name() { @@ -49,6 +57,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Checks for correct MySQL version and stores min/max word length in the config + * + * @return string|bool Language key of the error/incompatiblity occured + * + * @access public */ function init() { @@ -102,6 +114,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string &$keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return bool false if no valid keywords were found and otherwise true + * + * @access public */ function split_keywords(&$keywords, $terms) { @@ -221,6 +235,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Turns text into an array of words + * @param string $text contains post text/subject + * + * @access public */ function split_message($text) { @@ -607,7 +624,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroys cached search results, that contained one of the new words in a post so the results won't be outdated. * - * @param string $mode contains the post mode: edit, post, reply, quote ... + * @param string $mode contains the post mode: edit, post, reply, quote ... + * @param int $post_id contains the post id of the post to index + * @param string $message contains the post text of the post + * @param string $subject contains the subject of the post to index + * @param int $poster_id contains the user id of the poster + * @param int $forum_id contains the forum id of parent forum of the post + * + * @access public */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { @@ -630,6 +654,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroy cached results, that might be outdated after deleting a post + * + * @access public */ function index_remove($post_ids, $author_ids, $forum_ids) { @@ -638,6 +664,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroy old cache entries + * + * @access public */ function tidy() { @@ -651,6 +679,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Create fulltext index + * + * @return string|bool error string is returned incase of errors otherwise false + * + * @access public */ function create_index($acp_module, $u_action) { @@ -712,6 +744,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Drop fulltext index + * + * @return string|bool error string is returned incase of errors otherwise false + * + * @access public */ function delete_index($acp_module, $u_action) { @@ -757,6 +793,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Returns true if both FULLTEXT indexes exist + * + * @access public */ function index_created() { @@ -770,6 +808,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Returns an associative array containing information about the indexes + * + * @access public */ function index_stats() { @@ -785,6 +825,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base ); } + /** + * Computes the stats and store them in the $this->stats associative array + * + * @access private + */ function get_stats() { global $db; @@ -827,6 +872,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Display a note, that UTF-8 support is not available with certain versions of PHP + * + * @return associative array containing template and config variables + * + * @access public */ function acp() { -- cgit v1.2.1 From 9c7a1a147236ec21f99f6894cb0ef5324869de3d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 21 Jul 2012 18:32:52 +0530 Subject: [ticket/11011] global variables as constructor parameters Pass global variables into the search backend class constructor. PHPBB3-11011 --- phpBB/includes/search/fulltext_mysql.php | 135 +++++++++++++------------------ 1 file changed, 58 insertions(+), 77 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 64b3feb30c..ccf9f49612 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -24,6 +24,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { private $stats = array(); private $split_words = array(); + private $config; + private $db; + private $user; public $word_length = array(); public $search_query; public $common_words = array(); @@ -34,11 +37,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $config; + $this->config = $config; + $this->db = $db; + $this->user = $user; - $this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']); + $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); $error = false; } @@ -64,16 +69,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function init() { - global $db, $user; - - if ($db->sql_layer != 'mysql4' && $db->sql_layer != 'mysqli') + if ($this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli') { - return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE']; + return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE']; } - $result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); - $info = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); + $info = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); $engine = ''; if (isset($info['Engine'])) @@ -87,19 +90,19 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($engine != 'MyISAM') { - return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; + return $this->user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; } $sql = 'SHOW VARIABLES LIKE \'ft\_%\''; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $mysql_info = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $mysql_info[$row['Variable_name']] = $row['Value']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); set_config('fulltext_mysql_max_word_len', $mysql_info['ft_max_word_len']); set_config('fulltext_mysql_min_word_len', $mysql_info['ft_min_word_len']); @@ -119,8 +122,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function split_keywords(&$keywords, $terms) { - global $config, $user; - if ($terms == 'all') { $match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#(^|\s)\+#', '#(^|\s)-#', '#(^|\s)\|#'); @@ -139,9 +140,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $this->split_words = $matches[1]; // We limit the number of allowed keywords to minimize load on the database - if ($config['max_num_search_keywords'] && sizeof($this->split_words) > $config['max_num_search_keywords']) + if ($this->config['max_num_search_keywords'] && sizeof($this->split_words) > $this->config['max_num_search_keywords']) { - trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], sizeof($this->split_words))); + trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], sizeof($this->split_words))); } // to allow phrase search, we need to concatenate quoted words @@ -183,7 +184,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // check word length $clean_len = utf8_strlen(str_replace('*', '', $clean_word)); - if (($clean_len < $config['fulltext_mysql_min_word_len']) || ($clean_len > $config['fulltext_mysql_max_word_len'])) + if (($clean_len < $this->config['fulltext_mysql_min_word_len']) || ($clean_len > $this->config['fulltext_mysql_max_word_len'])) { $this->common_words[] = $word; unset($this->split_words[$i]); @@ -241,8 +242,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function split_message($text) { - global $config; - // Split words $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); $matches = array(); @@ -254,7 +253,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base for ($i = 0, $n = sizeof($text); $i < $n; $i++) { $text[$i] = trim($text[$i]); - if (utf8_strlen($text[$i]) < $config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_mysql_max_word_len']) + if (utf8_strlen($text[$i]) < $this->config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len']) { unset($text[$i]); } @@ -287,8 +286,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No keywords? No posts. if (!$this->search_query) { @@ -377,7 +374,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; @@ -387,11 +384,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (sizeof($author_ary) && $author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = ' AND (' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = ' AND (' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else if (sizeof($author_ary)) { - $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary); } else { @@ -401,7 +398,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql_where_options = $sql_sort_join; $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; - $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_where_options .= $m_approve_fid_sql; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; @@ -409,16 +406,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql = "SELECT $sql_select FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE MATCH ($sql_match) AGAINST ('" . $db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) + WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) $sql_where_options ORDER BY $sql_sort"; - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $id_ary = array_unique($id_ary); @@ -431,9 +428,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!$result_count) { $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $db->sql_query($sql); - $result_count = (int) $db->sql_fetchfield('result_count'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $result_count = (int) $this->db->sql_fetchfield('result_count'); + $this->db->sql_freeresult($result); if (!$result_count) { @@ -471,8 +468,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No author? No posts. if (!sizeof($author_ary)) { @@ -508,13 +503,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } - $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; @@ -550,7 +545,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } // If the cache was completely empty count the results @@ -589,21 +584,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } // Only read one block of posts from the db and then cache it - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // retrieve the total result count if needed if (!$result_count) { $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $db->sql_query($sql); - $result_count = (int) $db->sql_fetchfield('result_count'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $result_count = (int) $this->db->sql_fetchfield('result_count'); + $this->db->sql_freeresult($result); if (!$result_count) { @@ -635,8 +630,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $db; - // Split old and new post/subject to obtain array of words $split_text = $this->split_message($message); $split_title = ($subject) ? $this->split_message($subject) : array(); @@ -669,8 +662,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function tidy() { - global $db, $config; - // destroy too old cached search results $this->destroy_cache(array()); @@ -686,8 +677,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function create_index($acp_module, $u_action) { - global $db; - // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) { @@ -703,7 +692,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!isset($this->stats['post_subject'])) { - if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>=')) + if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) { $alter[] = 'MODIFY post_subject varchar(255) COLLATE utf8_unicode_ci DEFAULT \'\' NOT NULL'; } @@ -716,7 +705,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!isset($this->stats['post_text'])) { - if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>=')) + if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) { $alter[] = 'MODIFY post_text mediumtext COLLATE utf8_unicode_ci NOT NULL'; } @@ -734,10 +723,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (sizeof($alter)) { - $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); + $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -751,8 +740,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function delete_index($acp_module, $u_action) { - global $db; - // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) { @@ -783,10 +770,10 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (sizeof($alter)) { - $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); + $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter)); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -813,15 +800,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function index_stats() { - global $user; - if (empty($this->stats)) { $this->get_stats(); } return array( - $user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -832,9 +817,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function get_stats() { - global $db; - - if (strpos($db->sql_layer, 'mysql') === false) + if (strpos($this->db->sql_layer, 'mysql') === false) { $this->stats = array(); return; @@ -842,9 +825,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $sql = 'SHOW INDEX FROM ' . POSTS_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { // deal with older MySQL versions which didn't use Index_type $index_type = (isset($row['Index_type'])) ? $row['Index_type'] : $row['Comment']; @@ -865,9 +848,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $this->stats['total_posts'] = empty($this->stats) ? 0 : $db->get_estimated_row_count(POSTS_TABLE); + $this->stats['total_posts'] = empty($this->stats) ? 0 : $this->db->get_estimated_row_count(POSTS_TABLE); } /** @@ -879,16 +862,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base */ function acp() { - global $user, $config; - $tpl = '
-

' . $user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '
-
' . $config['fulltext_mysql_min_word_len'] . '
+

' . $this->user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '
+
' . $this->config['fulltext_mysql_min_word_len'] . '
-

' . $user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '
-
' . $config['fulltext_mysql_max_word_len'] . '
+

' . $this->user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '
+
' . $this->config['fulltext_mysql_max_word_len'] . '
'; -- cgit v1.2.1 From a1da7ff86182f44ad4c01698e2c526216b86031e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 16:50:09 +0530 Subject: [ticket/11011] remove global keyword in pgsql search Pass global variables into the search backend class constructor. PHPBB3-11011 --- phpBB/includes/search/fulltext_postgres.php | 134 ++++++++++++---------------- 1 file changed, 57 insertions(+), 77 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 84ce674564..75cb48ecc6 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -28,6 +28,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base private $version; private $tsearch_query; private $phrase_search = false; + private $config; + private $db; + private $user; public $search_query; public $common_words = array(); public $word_length = array(); @@ -38,16 +41,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $db, $config; + $this->config = $config; + $this->db = $db; + $this->user = $user; - $this->word_length = array('min' => $config['fulltext_postgres_min_word_len'], 'max' => $config['fulltext_postgres_max_word_len']); + $this->word_length = array('min' => $this->config['fulltext_postgres_min_word_len'], 'max' => $this->config['fulltext_postgres_max_word_len']); - - if ($db->sql_layer == 'postgres') + if ($this->db->sql_layer == 'postgres') { - $pgsql_version = explode(',', substr($db->sql_server_info(), 10)); + $pgsql_version = explode(',', substr($this->db->sql_server_info(), 10)); $this->version = trim($pgsql_version[0]); if (version_compare($this->version, '8.3', '>=')) { @@ -91,16 +95,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function init() { - global $db, $user; - - if ($db->sql_layer != 'postgres') + if ($this->db->sql_layer != 'postgres') { - return $user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; + return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; } if (!$this->tsearch_usable) { - return $user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE']; + return $this->user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE']; } return false; @@ -118,8 +120,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function split_keywords(&$keywords, $terms) { - global $config; - if ($terms == 'all') { $match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#\+#', '#-#', '#\|#'); @@ -143,7 +143,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base // check word length $clean_len = utf8_strlen(str_replace('*', '', $clean_word)); - if (($clean_len < $config['fulltext_postgres_min_word_len']) || ($clean_len > $config['fulltext_postgres_max_word_len'])) + if (($clean_len < $this->config['fulltext_postgres_min_word_len']) || ($clean_len > $this->config['fulltext_postgres_max_word_len'])) { $this->common_words[] = $word; unset($this->split_words[$i]); @@ -213,8 +213,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function split_message($text) { - global $config; - // Split words $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); $matches = array(); @@ -226,7 +224,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base for ($i = 0, $n = sizeof($text); $i < $n; $i++) { $text[$i] = trim($text[$i]); - if (utf8_strlen($text[$i]) < $config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_postgres_max_word_len']) + if (utf8_strlen($text[$i]) < $this->config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_postgres_max_word_len']) { unset($text[$i]); } @@ -259,8 +257,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No keywords? No posts. if (!$this->search_query) { @@ -349,7 +345,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } $sql_select = ($type == 'posts') ? 'p.post_id' : 'DISTINCT t.topic_id'; @@ -360,11 +356,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (sizeof($author_ary) && $author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else if (sizeof($author_ary)) { - $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary); } else { @@ -374,7 +370,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $sql_where_options = $sql_sort_join; $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; - $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_where_options .= $m_approve_fid_sql; $sql_where_options .= $sql_author; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; @@ -383,7 +379,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $tmp_sql_match = array(); foreach (explode(',', $sql_match) as $sql_match_column) { - $tmp_sql_match[] = "to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', '" . $db->sql_escape($this->tsearch_query) . "')"; + $tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')"; } $sql = "SELECT $sql_select @@ -391,13 +387,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base WHERE (" . implode(' OR ', $tmp_sql_match) . ") $sql_where_options ORDER BY $sql_sort"; - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $id_ary = array_unique($id_ary); @@ -447,8 +443,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No author? No posts. if (!sizeof($author_ary)) { @@ -484,13 +478,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } - $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; @@ -526,7 +520,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } // Build the query for really selecting the post_ids @@ -562,13 +556,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } // Only read one block of posts from the db and then cache it - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // retrieve the total result count if needed if (!$result_count) @@ -605,8 +599,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $db; - // Split old and new post/subject to obtain array of words $split_text = $this->split_message($message); $split_title = ($subject) ? $this->split_message($subject) : array(); @@ -639,8 +631,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function tidy() { - global $db, $config; - // destroy too old cached search results $this->destroy_cache(array()); @@ -656,8 +646,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function create_index($acp_module, $u_action) { - global $db, $config; - // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) { @@ -671,15 +659,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (!isset($this->stats['post_subject'])) { - $db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_subject))"); + $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))"); } if (!isset($this->stats['post_text'])) { - $db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_text))"); + $this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text))"); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -693,8 +681,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function delete_index($acp_module, $u_action) { - global $db; - // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) { @@ -708,15 +694,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (isset($this->stats['post_subject'])) { - $db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']); + $this->db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']); } if (isset($this->stats['post_text'])) { - $db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']); + $this->db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']); } - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); return false; } @@ -743,15 +729,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function index_stats() { - global $user; - if (empty($this->stats)) { $this->get_stats(); } return array( - $user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -762,9 +746,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function get_stats() { - global $db, $config; - - if ($db->sql_layer != 'postgres') + if ($this->db->sql_layer != 'postgres') { $this->stats = array(); return; @@ -776,26 +758,26 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base AND pg_catalog.pg_table_is_visible(c1.oid) AND c1.oid = i.indrelid AND i.indexrelid = c2.oid"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { // deal with older PostgreSQL versions which didn't use Index_type if (strpos($row['indexdef'], 'to_tsvector') !== false) { - if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text') + if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text') { $this->stats['post_text'] = $row; } - else if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject') + else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject') { $this->stats['post_subject'] = $row; } } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); - $this->stats['total_posts'] = $config['num_posts']; + $this->stats['total_posts'] = $this->config['num_posts']; } /** @@ -807,43 +789,41 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base */ function acp() { - global $user, $config, $db; - $tpl = '
-

' . $user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '
-
' . (($this->tsearch_usable) ? $user->lang['YES'] : $user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')
+

' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '
+
' . (($this->tsearch_usable) ? $this->user->lang['YES'] : $this->user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')
-

' . $user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '
+

' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '
-

' . $user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '
+
-

' . $user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '
-
+

' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '
+
'; -- cgit v1.2.1 From 33c6d7c8be41ddd15b4e03e5dfecfd259c77b327 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 23 Jul 2012 15:41:15 +0530 Subject: [ticket/11011] remove global keyword in native search Pass global variables into the search backend class constructor. PHPBB3-11011 --- phpBB/includes/search/fulltext_native.php | 274 ++++++++++++++---------------- 1 file changed, 132 insertions(+), 142 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 1e2074b1b1..b9818d7919 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -31,23 +31,33 @@ class phpbb_search_fulltext_native extends phpbb_search_base var $must_not_contain_ids = array(); var $must_exclude_one_ids = array(); + private $phpbb_root_path; + private $phpEx; + private $config; + private $db; + private $user; + /** * Initialises the fulltext_native search backend with min/max word length and makes sure the UTF-8 normalizer is loaded. * * @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure. */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $phpbb_root_path, $phpEx, $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + $this->user = $user; - $this->word_length = array('min' => $config['fulltext_native_min_chars'], 'max' => $config['fulltext_native_max_chars']); + $this->word_length = array('min' => $this->config['fulltext_native_min_chars'], 'max' => $this->config['fulltext_native_max_chars']); /** * Load the UTF tools */ if (!class_exists('utf_normalizer')) { - include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); + include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->phpEx); } $error = false; @@ -82,8 +92,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function split_keywords($keywords, $terms) { - global $db, $user, $config; - $tokens = '+-|()*'; $keywords = trim($this->cleanup($keywords, $tokens)); @@ -182,9 +190,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base $num_keywords = sizeof(explode(' ', $keywords)); // We limit the number of allowed keywords to minimize load on the database - if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords']) + if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords']) { - trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords)); + trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], $num_keywords)); } // $keywords input format: each word separated by a space, words in a bracket are not separated @@ -214,12 +222,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql = 'SELECT word_id, word_text, word_common FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE ' . $db->sql_in_set('word_text', $exact_words) . ' + WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . ' ORDER BY word_count ASC'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); // store an array of words and ids, remove common words - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if ($row['word_common']) { @@ -230,7 +238,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $words[$row['word_text']] = (int) $row['word_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } unset($exact_words); @@ -301,7 +309,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base { if (strpos($word_part, '*') !== false) { - $id_words[] = '\'' . $db->sql_escape(str_replace('*', '%', $word_part)) . '\''; + $id_words[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word_part)) . '\''; $non_common_words[] = $word_part; } else if (isset($words[$word_part])) @@ -334,7 +342,11 @@ class phpbb_search_fulltext_native extends phpbb_search_base // throw an error if we shall not ignore unexistant words else if (!$ignore_no_id && sizeof($non_common_words)) { +<<<<<<< HEAD trigger_error(sprintf($user->lang['WORDS_IN_NO_POST'], implode($user->lang['COMMA_SEPARATOR'], $non_common_words))); +======= + trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode(', ', $non_common_words))); +>>>>>>> 1ee5f46... [ticket/11011] remove global keyword in native search } unset($non_common_words); } @@ -346,7 +358,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $len = utf8_strlen(str_replace('*', '', $word)); if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) { - $this->{$mode . '_ids'}[] = '\'' . $db->sql_escape(str_replace('*', '%', $word)) . '\''; + $this->{$mode . '_ids'}[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word)) . '\''; } else { @@ -366,7 +378,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $len = utf8_strlen($word); if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) { - trigger_error(sprintf($user->lang['WORD_IN_NO_POST'], $word)); + trigger_error(sprintf($this->user->lang['WORD_IN_NO_POST'], $word)); } else { @@ -421,8 +433,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No keywords? No posts. if (empty($this->search_query)) { @@ -537,7 +547,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } } - $sql_where[] = $db->sql_in_set("m$m_num.word_id", $word_ids); + $sql_where[] = $this->db->sql_in_set("m$m_num.word_id", $word_ids); unset($word_id_sql); unset($word_ids); @@ -591,7 +601,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql_array['LEFT_JOIN'][] = array( 'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), - 'ON' => $db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id" + 'ON' => $this->db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id" ); $sql_where[] = "m$m_num.word_id IS NULL"; @@ -632,7 +642,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } else if ($m_approve_fid_ary !== array(-1)) { - $sql_where[] = '(p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } if ($topic_id) @@ -645,18 +655,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } $sql_where[] = $sql_author; } if (sizeof($ex_fid_ary)) { - $sql_where[] = $db->sql_in_set('p.forum_id', $ex_fid_ary, true); + $sql_where[] = $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true); } if ($sort_days) @@ -681,7 +691,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base ); } - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'mysql4': case 'mysqli': @@ -695,17 +705,17 @@ class phpbb_search_fulltext_native extends phpbb_search_base case 'sqlite': $sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id'; $sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results - FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')'; + FROM (' . $this->db->sql_build_query('SELECT', $sql_array_count) . ')'; // no break default: $sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; - $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; + $sql = (!$sql) ? $this->db->sql_build_query('SELECT', $sql_array_count) : $sql; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -751,14 +761,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base unset($sql_where, $sql_sort, $group_by); - $sql = $db->sql_build_query('SELECT', $sql_array); - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!sizeof($id_ary)) { @@ -772,16 +782,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_array_copy = $sql_array; $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id '; - $sql = $db->sql_build_query('SELECT', $sql_array_copy); + $sql = $this->db->sql_build_query('SELECT', $sql_array_copy); unset($sql_array_copy); - $db->sql_query($sql); - $db->sql_freeresult($result); + $this->db->sql_query($sql); + $this->db->sql_freeresult($result); $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -819,8 +829,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { - global $config, $db; - // No author? No posts. if (!sizeof($author_ary)) { @@ -856,13 +864,13 @@ class phpbb_search_fulltext_native extends phpbb_search_base if ($author_name) { // first one matches post of registered users, second one guests and deleted users - $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; + $sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; } else { - $sql_author = $db->sql_in_set('p.poster_id', $author_ary); + $sql_author = $this->db->sql_in_set('p.poster_id', $author_ary); } - $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; + $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; @@ -898,7 +906,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } else { - $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; } $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; @@ -907,7 +915,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base // If the cache was completely empty count the results if (!$total_results) { - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'mysql4': case 'mysqli': @@ -929,7 +937,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base } else { - if ($db->sql_layer == 'sqlite') + if ($this->db->sql_layer == 'sqlite') { $sql = 'SELECT COUNT(topic_id) as total_results FROM (SELECT DISTINCT t.topic_id'; @@ -946,12 +954,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base $m_approve_fid_sql $sql_fora AND t.topic_id = p.topic_id - $sql_time" . (($db->sql_layer == 'sqlite') ? ')' : ''); + $sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : ''); } - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -994,26 +1002,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base } // Only read one block of posts from the db and then cache it - $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $id_ary[] = (int) $row[$field]; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!$total_results && $is_mysql) { // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); - $db->sql_query($sql); - $db->sql_freeresult($result); + $this->db->sql_query($sql); + $this->db->sql_freeresult($result); $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $db->sql_query($sql); - $total_results = (int) $db->sql_fetchfield('total_results'); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $total_results = (int) $this->db->sql_fetchfield('total_results'); + $this->db->sql_freeresult($result); if (!$total_results) { @@ -1046,8 +1054,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function split_message($text) { - global $phpbb_root_path, $phpEx, $user; - $match = $words = array(); /** @@ -1125,9 +1131,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { - global $config, $db, $user; - - if (!$config['fulltext_native_load_upd']) + if (!$this->config['fulltext_native_load_upd']) { /** * The search indexer is disabled, return @@ -1153,14 +1157,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m WHERE m.post_id = $post_id AND w.word_id = m.word_id"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $which = ($row['title_match']) ? 'title' : 'post'; $cur_words[$which][$row['word_text']] = $row['word_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $words['add']['post'] = array_diff($split_text, array_keys($cur_words['post'])); $words['add']['title'] = array_diff($split_title, array_keys($cur_words['title'])); @@ -1188,18 +1192,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql = 'SELECT word_id, word_text FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE ' . $db->sql_in_set('word_text', $unique_add_words); - $result = $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words); + $result = $this->db->sql_query($sql); $word_ids = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $word_ids[$row['word_text']] = $row['word_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $new_words = array_diff($unique_add_words, array_keys($word_ids)); - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); if (sizeof($new_words)) { $sql_ary = array(); @@ -1208,15 +1212,15 @@ class phpbb_search_fulltext_native extends phpbb_search_base { $sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0); } - $db->sql_return_on_error(true); - $db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); - $db->sql_return_on_error(false); + $this->db->sql_return_on_error(true); + $this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); + $this->db->sql_return_on_error(false); } unset($new_words, $sql_ary); } else { - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); } // now update the search match table, remove links to removed words and add links to new words @@ -1233,22 +1237,22 @@ class phpbb_search_fulltext_native extends phpbb_search_base } $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' - WHERE ' . $db->sql_in_set('word_id', $sql_in) . ' + WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND post_id = ' . intval($post_id) . " AND title_match = $title_match"; - $db->sql_query($sql); + $this->db->sql_query($sql); $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 - WHERE ' . $db->sql_in_set('word_id', $sql_in) . ' + WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND word_count > 0'; - $db->sql_query($sql); + $this->db->sql_query($sql); unset($sql_in); } } - $db->sql_return_on_error(true); + $this->db->sql_return_on_error(true); foreach ($words['add'] as $word_in => $word_ary) { $title_match = ($word_in == 'title') ? 1 : 0; @@ -1258,18 +1262,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match) SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . ' FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE ' . $db->sql_in_set('word_text', $word_ary); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_text', $word_ary); + $this->db->sql_query($sql); $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count + 1 - WHERE ' . $db->sql_in_set('word_text', $word_ary); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_text', $word_ary); + $this->db->sql_query($sql); } } - $db->sql_return_on_error(false); + $this->db->sql_return_on_error(false); - $db->sql_transaction('commit'); + $this->db->sql_transaction('commit'); // destroy cached search results containing any of the words removed or added $this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id)); @@ -1284,18 +1288,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function index_remove($post_ids, $author_ids, $forum_ids) { - global $db; - if (sizeof($post_ids)) { $sql = 'SELECT w.word_id, w.word_text, m.title_match FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w - WHERE ' . $db->sql_in_set('m.post_id', $post_ids) . ' + WHERE ' . $this->db->sql_in_set('m.post_id', $post_ids) . ' AND w.word_id = m.word_id'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $message_word_ids = $title_word_ids = $word_texts = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if ($row['title_match']) { @@ -1307,32 +1309,32 @@ class phpbb_search_fulltext_native extends phpbb_search_base } $word_texts[] = $row['word_text']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($title_word_ids)) { $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 - WHERE ' . $db->sql_in_set('word_id', $title_word_ids) . ' + WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . ' AND word_count > 0'; - $db->sql_query($sql); + $this->db->sql_query($sql); } if (sizeof($message_word_ids)) { $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 - WHERE ' . $db->sql_in_set('word_id', $message_word_ids) . ' + WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . ' AND word_count > 0'; - $db->sql_query($sql); + $this->db->sql_query($sql); } unset($title_word_ids); unset($message_word_ids); $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' - WHERE ' . $db->sql_in_set('post_id', $post_ids); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('post_id', $post_ids); + $this->db->sql_query($sql); } $this->destroy_cache(array_unique($word_texts), array_unique($author_ids)); @@ -1344,11 +1346,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function tidy() { - global $db, $config; - // Is the fulltext indexer disabled? If yes then we need not // carry on ... it's okay ... I know when I'm not wanted boo hoo - if (!$config['fulltext_native_load_upd']) + if (!$this->config['fulltext_native_load_upd']) { set_config('search_last_gc', time(), true); return; @@ -1357,31 +1357,31 @@ class phpbb_search_fulltext_native extends phpbb_search_base $destroy_cache_words = array(); // Remove common words - if ($config['num_posts'] >= 100 && $config['fulltext_native_common_thres']) + if ($this->config['num_posts'] >= 100 && $this->config['fulltext_native_common_thres']) { - $common_threshold = ((double) $config['fulltext_native_common_thres']) / 100.0; + $common_threshold = ((double) $this->config['fulltext_native_common_thres']) / 100.0; // First, get the IDs of common words $sql = 'SELECT word_id, word_text FROM ' . SEARCH_WORDLIST_TABLE . ' - WHERE word_count > ' . floor($config['num_posts'] * $common_threshold) . ' + WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . ' OR word_common = 1'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $sql_in = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $sql_in[] = $row['word_id']; $destroy_cache_words[] = $row['word_text']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (sizeof($sql_in)) { // Flag the words $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_common = 1 - WHERE ' . $db->sql_in_set('word_id', $sql_in); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_id', $sql_in); + $this->db->sql_query($sql); // by setting search_last_gc to the new time here we make sure that if a user reloads because the // following query takes too long, he won't run into it again @@ -1389,8 +1389,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base // Delete the matches $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' - WHERE ' . $db->sql_in_set('word_id', $sql_in); - $db->sql_query($sql); + WHERE ' . $this->db->sql_in_set('word_id', $sql_in); + $this->db->sql_query($sql); } unset($sql_in); } @@ -1409,21 +1409,19 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function delete_index($acp_module, $u_action) { - global $db; - - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'sqlite': case 'firebird': - $db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); - $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); - $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); + $this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); + $this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); break; default: - $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); - $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); - $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); break; } } @@ -1446,24 +1444,20 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function index_stats() { - global $user; - if (!sizeof($this->stats)) { $this->get_stats(); } return array( - $user->lang['TOTAL_WORDS'] => $this->stats['total_words'], - $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); + $this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'], + $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); } function get_stats() { - global $db; - - $this->stats['total_words'] = $db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); - $this->stats['total_matches'] = $db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); + $this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); + $this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); } /** @@ -1483,7 +1477,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') { - global $phpbb_root_path, $phpEx; static $conv = array(), $conv_loaded = array(); $words = $allow = array(); @@ -1680,7 +1673,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base if (!isset($conv_loaded[$idx])) { $conv_loaded[$idx] = 1; - $file = $phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $phpEx; + $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->phpEx; if (file_exists($file)) { @@ -1713,29 +1706,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ function acp() { - global $user, $config; - - /** * if we need any options, copied from fulltext_native for now, will have to be adjusted or removed */ $tpl = '
-

' . $user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '
-
+

' . $this->user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '
+
-

' . $user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '
-
+

' . $this->user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '
+
-

' . $user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '
-
+

' . $this->user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '
+
-

' . $user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '
-
%
+

' . $this->user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '
+
%
'; -- cgit v1.2.1 From 2e218776bbac82841e1ced583c83890be5080af0 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 24 Jul 2012 12:10:22 +0530 Subject: [ticket/11011] passing global variables Pass global variables to class constructor when making a new object. PHPBB3-11011 --- phpBB/includes/acp/acp_search.php | 4 ++-- phpBB/includes/search/fulltext_native.php | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 82d9b021fe..5ae9f363f0 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -596,7 +596,7 @@ class acp_search */ function init_search($type, &$search, &$error) { - global $phpbb_root_path, $phpEx, $user; + global $phpbb_root_path, $phpEx, $user, $config, $db; if (!class_exists($type) || !method_exists($type, 'keyword_search')) { @@ -605,7 +605,7 @@ class acp_search } $error = false; - $search = new $type($error); + $search = new $type($error, $phpbb_root_path, $phpEx, $config, $db, $user); return $error; } diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index b9818d7919..a470a92458 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -342,11 +342,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base // throw an error if we shall not ignore unexistant words else if (!$ignore_no_id && sizeof($non_common_words)) { -<<<<<<< HEAD trigger_error(sprintf($user->lang['WORDS_IN_NO_POST'], implode($user->lang['COMMA_SEPARATOR'], $non_common_words))); -======= - trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode(', ', $non_common_words))); ->>>>>>> 1ee5f46... [ticket/11011] remove global keyword in native search } unset($non_common_words); } -- cgit v1.2.1 From d982a37f191ffb731633a6adf6f86416787080db Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 28 Jul 2012 18:25:26 +0530 Subject: [ticket/11011] pass global variables in construct Use global variables passed through constructor instead of using global keyword in sphinx search backend. PHPBB3-11011 --- phpBB/includes/search/fulltext_sphinx.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 8371f6b377..9dc6e66e3a 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -40,6 +40,8 @@ class phpbb_search_fulltext_sphinx private $id; private $indexes; private $sphinx; + private $phpbb_root_path; + private $phpEx; private $auth; private $config; private $db; @@ -56,9 +58,10 @@ class phpbb_search_fulltext_sphinx * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error) + public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) { - global $config, $db, $user, $auth, $phpbb_root_path, $phpEx; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; $this->config = $config; $this->user = $user; $this->db = $db; @@ -66,7 +69,7 @@ class phpbb_search_fulltext_sphinx if (!class_exists('phpbb_db_tools')) { - require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->phpEx); } // Initialize phpbb_db_tools object @@ -127,8 +130,6 @@ class phpbb_search_fulltext_sphinx */ function config_generate() { - global $phpbb_root_path, $phpEx; - // Check if Database is supported by Sphinx if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli') { @@ -151,7 +152,7 @@ class phpbb_search_fulltext_sphinx return false; } - include($phpbb_root_path . 'config.' . $phpEx); + include($this->phpbb_root_path . 'config.' . $this->phpEx); /* Now that we're sure everything was entered correctly, generate a config for the index. We use a config value -- cgit v1.2.1 From 9eb6c2ba5b6fb1c1090f5a89387a8fa8ae958a85 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 28 Jul 2012 18:50:56 +0530 Subject: [ticket/11011] remove global keyword from sphinx PHPBB3-11011 --- phpBB/includes/search/fulltext_sphinx.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 9dc6e66e3a..0662b70a2b 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -17,13 +17,6 @@ if (!defined('IN_PHPBB')) /** * @ignore */ -/** -* This statement is necessary as this file is sometimes included from within a -* function and the variables used are in global space. -*/ -global $phpbb_root_path, $phpEx, $table_prefix; -require($phpbb_root_path . 'includes/sphinxapi.' . $phpEx); - define('SPHINX_MAX_MATCHES', 20000); define('SPHINX_CONNECT_RETRIES', 3); define('SPHINX_CONNECT_WAIT_TIME', 300); @@ -82,6 +75,12 @@ class phpbb_search_fulltext_sphinx $this->id = $this->config['fulltext_sphinx_id']; $this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main'; + if (!class_exists('SphinxClient')) + { + require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->phpEx); + } + + // Initialize sphinx client $this->sphinx = new SphinxClient(); $this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 9312)); -- cgit v1.2.1 From 828eaecf6ab4f6c013a7955bf6af2a81c049e42f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 15:24:31 -0500 Subject: [ticket/10875] Changes to Cache Driver caused method_exists checks to fail SQL Cache and other functions using the check method_exists($cache, failed because of the changes to the cache system. method_exists($cache has been changed to method_exists($cache->get_driver() PHPBB3-10875 --- phpBB/includes/cron/task/core/tidy_cache.php | 2 +- phpBB/includes/db/firebird.php | 4 ++-- phpBB/includes/db/mssql.php | 4 ++-- phpBB/includes/db/mssql_odbc.php | 4 ++-- phpBB/includes/db/mssqlnative.php | 4 ++-- phpBB/includes/db/mysql.php | 4 ++-- phpBB/includes/db/mysqli.php | 4 ++-- phpBB/includes/db/oracle.php | 4 ++-- phpBB/includes/db/postgres.php | 4 ++-- phpBB/includes/db/sqlite.php | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index c9dc0bd9ae..991b0725eb 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -44,7 +44,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base public function is_runnable() { global $cache; - return method_exists($cache, 'tidy'); + return method_exists($cache->get_driver(), 'tidy'); } /** diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 7709e8fdf5..f89d5134c1 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -156,7 +156,7 @@ class dbal_firebird extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -269,7 +269,7 @@ class dbal_firebird extends dbal } } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index fb044b492f..4fad3f2297 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -144,7 +144,7 @@ class dbal_mssql extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -159,7 +159,7 @@ class dbal_mssql extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 64fa9634d1..594de28b8b 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -163,7 +163,7 @@ class dbal_mssql_odbc extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -178,7 +178,7 @@ class dbal_mssql_odbc extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 1f37d54ecb..7f64ca1784 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -318,7 +318,7 @@ class dbal_mssqlnative extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -335,7 +335,7 @@ class dbal_mssqlnative extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 8d1f805870..31bb59711a 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -172,7 +172,7 @@ class dbal_mysql extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -187,7 +187,7 @@ class dbal_mysql extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index e07cd35e24..538cd23015 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -179,7 +179,7 @@ class dbal_mysqli extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -194,7 +194,7 @@ class dbal_mysqli extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $cache->sql_save($query, $this->query_result, $cache_ttl); } diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 2e801532f0..fbad325eb9 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -242,7 +242,7 @@ class dbal_oracle extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -418,7 +418,7 @@ class dbal_oracle extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index bf22cffafa..e40fe5e370 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -200,7 +200,7 @@ class dbal_postgres extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -215,7 +215,7 @@ class dbal_postgres extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 86bfa75a13..e770dc0a91 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -117,7 +117,7 @@ class dbal_sqlite extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -132,7 +132,7 @@ class dbal_sqlite extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache, 'sql_save')) + if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); -- cgit v1.2.1 From edcac438df164764c84ca9fb7a7f751bf76d5c34 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 15:57:51 -0500 Subject: [ticket/10875] method_exists check is not required, interface declares them The changes to the cache drivers added an interface, which requires many cache functions exist. For these, we can remove the method_exists() check PHPBB3-10875 --- phpBB/includes/cron/task/core/tidy_cache.php | 3 +-- phpBB/includes/db/firebird.php | 4 ++-- phpBB/includes/db/mssql.php | 4 ++-- phpBB/includes/db/mssql_odbc.php | 4 ++-- phpBB/includes/db/mssqlnative.php | 4 ++-- phpBB/includes/db/mysql.php | 4 ++-- phpBB/includes/db/mysqli.php | 4 ++-- phpBB/includes/db/oracle.php | 4 ++-- phpBB/includes/db/postgres.php | 4 ++-- phpBB/includes/db/sqlite.php | 4 ++-- 10 files changed, 19 insertions(+), 20 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 991b0725eb..f6cf77d01d 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -43,8 +43,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function is_runnable() { - global $cache; - return method_exists($cache->get_driver(), 'tidy'); + return true; } /** diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index f89d5134c1..06c76fa94a 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -156,7 +156,7 @@ class dbal_firebird extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -269,7 +269,7 @@ class dbal_firebird extends dbal } } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index 4fad3f2297..e40510835a 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -144,7 +144,7 @@ class dbal_mssql extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -159,7 +159,7 @@ class dbal_mssql extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 594de28b8b..3c9a9599ec 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -163,7 +163,7 @@ class dbal_mssql_odbc extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -178,7 +178,7 @@ class dbal_mssql_odbc extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 7f64ca1784..d35337d05b 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -318,7 +318,7 @@ class dbal_mssqlnative extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -335,7 +335,7 @@ class dbal_mssqlnative extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 31bb59711a..dbab1ec0b8 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -172,7 +172,7 @@ class dbal_mysql extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -187,7 +187,7 @@ class dbal_mysql extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 538cd23015..fc98de31fb 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -179,7 +179,7 @@ class dbal_mysqli extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -194,7 +194,7 @@ class dbal_mysqli extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $cache->sql_save($query, $this->query_result, $cache_ttl); } diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index fbad325eb9..4954f4d398 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -242,7 +242,7 @@ class dbal_oracle extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -418,7 +418,7 @@ class dbal_oracle extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index e40fe5e370..41838d2613 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -200,7 +200,7 @@ class dbal_postgres extends dbal } $this->last_query_text = $query; - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -215,7 +215,7 @@ class dbal_postgres extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index e770dc0a91..d930567773 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -117,7 +117,7 @@ class dbal_sqlite extends dbal $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl && method_exists($cache->get_driver(), 'sql_load')) ? $cache->sql_load($query) : false; + $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -132,7 +132,7 @@ class dbal_sqlite extends dbal $this->sql_report('stop', $query); } - if ($cache_ttl && method_exists($cache->get_driver(), 'sql_save')) + if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $cache->sql_save($query, $this->query_result, $cache_ttl); -- cgit v1.2.1 From 2c1da15ae83e292d3aa9c94f740d6bff6bfd238e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 16:23:18 -0500 Subject: [ticket/11029] Cache obtain_cfg_items should return empty array on failure continue was used where it should not have been, causing a fatal error This file is loaded on every page to check if style.cfg has changed. If it has not, the user is not affected, so if it does not exist, the user should not be affected either. PHPBB3-11029 --- phpBB/includes/cache/service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php index 37f32aa753..5946241825 100644 --- a/phpBB/includes/cache/service.php +++ b/phpBB/includes/cache/service.php @@ -337,7 +337,7 @@ class phpbb_cache_service if (!file_exists($filename)) { - continue; + return array(); } if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) -- cgit v1.2.1 From 01bc818d465ab168288e260745a045ff2794648d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 18:44:40 -0500 Subject: [ticket/10875] Fix SQL Caching The sql_save function cannot take arguments by reference since it is called by call_user_func_array() Replace use of isset($cache->sql_rowset[$query_id]) with $cache->sql_exists Replace $cache->cache_dir with $cache->get_driver()->cache_dir PHPBB3-10875 --- phpBB/includes/cache/driver/file.php | 2 +- phpBB/includes/cache/driver/interface.php | 2 +- phpBB/includes/cache/driver/memory.php | 2 +- phpBB/includes/cache/driver/null.php | 2 +- phpBB/includes/db/dbal.php | 4 ++-- phpBB/includes/db/firebird.php | 4 ++-- phpBB/includes/db/mssql.php | 6 +++--- phpBB/includes/db/mssql_odbc.php | 4 ++-- phpBB/includes/db/mssqlnative.php | 4 ++-- phpBB/includes/db/mysql.php | 6 +++--- phpBB/includes/db/mysqli.php | 6 +++--- phpBB/includes/db/oracle.php | 6 +++--- phpBB/includes/db/postgres.php | 6 +++--- phpBB/includes/db/sqlite.php | 6 +++--- 14 files changed, 30 insertions(+), 30 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 0d3b06f621..da942b921c 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -364,7 +364,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base /** * Save sql query */ - function sql_save($query, &$query_result, $ttl) + function sql_save($query, $query_result, $ttl) { global $db; diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 313a2d4b31..847ba97262 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -75,7 +75,7 @@ interface phpbb_cache_driver_interface /** * Save sql query */ - public function sql_save($query, &$query_result, $ttl); + public function sql_save($query, $query_result, $ttl); /** * Ceck if a given sql query exist in cache diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index e25c9229a1..aabad2bb6c 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -280,7 +280,7 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base /** * Save sql query */ - function sql_save($query, &$query_result, $ttl) + function sql_save($query, $query_result, $ttl) { global $db; diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php index c143803d0e..df2c6c026f 100644 --- a/phpBB/includes/cache/driver/null.php +++ b/phpBB/includes/cache/driver/null.php @@ -107,7 +107,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base /** * Save sql query */ - function sql_save($query, &$query_result, $ttl) + function sql_save($query, $query_result, $ttl) { } diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 159703d3be..1de236d3de 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -206,7 +206,7 @@ class dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -256,7 +256,7 @@ class dbal $this->sql_rowseek($rownum, $query_id); } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchfield($query_id, $field); } diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 06c76fa94a..99deb5603e 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -332,7 +332,7 @@ class dbal_firebird extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -398,7 +398,7 @@ class dbal_firebird extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index e40510835a..d92fe27b99 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -234,7 +234,7 @@ class dbal_mssql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -271,7 +271,7 @@ class dbal_mssql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -310,7 +310,7 @@ class dbal_mssql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 3c9a9599ec..6292792a55 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -254,7 +254,7 @@ class dbal_mssql_odbc extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -295,7 +295,7 @@ class dbal_mssql_odbc extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index d35337d05b..0d8786171a 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -418,7 +418,7 @@ class dbal_mssqlnative extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -478,7 +478,7 @@ class dbal_mssqlnative extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index dbab1ec0b8..fd567af076 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -249,7 +249,7 @@ class dbal_mysql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -270,7 +270,7 @@ class dbal_mysql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -298,7 +298,7 @@ class dbal_mysql extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index fc98de31fb..26cade2ff0 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -251,7 +251,7 @@ class dbal_mysqli extends dbal $query_id = $this->query_result; } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -278,7 +278,7 @@ class dbal_mysqli extends dbal $query_id = $this->query_result; } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -306,7 +306,7 @@ class dbal_mysqli extends dbal $query_id = $this->query_result; } - if (!is_object($query_id) && isset($cache->sql_rowset[$query_id])) + if (!is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 4954f4d398..e9ff2f4434 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -473,7 +473,7 @@ class dbal_oracle extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -525,7 +525,7 @@ class dbal_oracle extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -594,7 +594,7 @@ class dbal_oracle extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 41838d2613..c35199e917 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -285,7 +285,7 @@ class dbal_postgres extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -306,7 +306,7 @@ class dbal_postgres extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -355,7 +355,7 @@ class dbal_postgres extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index d930567773..814b593f05 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -193,7 +193,7 @@ class dbal_sqlite extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -214,7 +214,7 @@ class dbal_sqlite extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -242,7 +242,7 @@ class dbal_sqlite extends dbal $query_id = $this->query_result; } - if (isset($cache->sql_rowset[$query_id])) + if ($cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } -- cgit v1.2.1 From 3c20ac71c51c9e8033884f5694fbad2fa6040ca6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 4 Mar 2011 02:00:54 -0500 Subject: [feature/events] Started on hooks for advanced last topic titles mod. PHPBB3-9550 --- phpBB/includes/functions_display.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 00efd281c0..b23540bcbd 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -119,6 +119,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'ORDER_BY' => 'f.left_id', ); + run_hooks('display_forums_sql_inject', &$sql_ary); + $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -127,6 +129,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod while ($row = $db->sql_fetchrow($result)) { + run_hooks('display_forums_row_inject', &$row); + $forum_id = $row['forum_id']; // Mark forums read? @@ -223,6 +227,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; + + $data = array(&$forum_rows, &$parent_id, &$row); + run_hooks('display_forums_row_values_inject', &$data); } else if ($row['forum_type'] != FORUM_CAT) { @@ -482,6 +489,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST' => $last_post_url) ); + + run_hooks('display_forums_assign_block_vars', &$row); // Assign subforums loop for style authors foreach ($subforums_list as $subforum) -- cgit v1.2.1 From 4da001625df4cc13d71e0ae6a61d573207165a7f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 3 Feb 2012 02:22:29 -0500 Subject: [feature/events] Replace run_hooks calls with event dispatcher. PHPBB3-9550 --- phpBB/includes/functions_display.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index b23540bcbd..b320d35e09 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -22,7 +22,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod { global $db, $auth, $user, $template; global $phpbb_root_path, $phpEx, $config; - global $request; + global $request, $phpbb_dispatcher; $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; @@ -119,7 +119,10 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'ORDER_BY' => 'f.left_id', ); - run_hooks('display_forums_sql_inject', &$sql_ary); + $vars = array('sql_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.display_forums_sql_inject', $event); + extract($event->get_data_filtered($vars)); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -129,7 +132,10 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod while ($row = $db->sql_fetchrow($result)) { - run_hooks('display_forums_row_inject', &$row); + $vars = array('row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.display_forums_row_inject', $event); + extract($event->get_data_filtered($vars)); $forum_id = $row['forum_id']; @@ -227,9 +233,11 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; - - $data = array(&$forum_rows, &$parent_id, &$row); - run_hooks('display_forums_row_values_inject', &$data); + + $vars = array('forum_rows', 'parent_id', 'row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.display_forums_row_values_inject', $event); + extract($event->get_data_filtered($vars)); } else if ($row['forum_type'] != FORUM_CAT) { @@ -489,8 +497,11 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST' => $last_post_url) ); - - run_hooks('display_forums_assign_block_vars', &$row); + + $vars = array('row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.display_forums_assign_block_vars', $event); + extract($event->get_data_filtered($vars)); // Assign subforums loop for style authors foreach ($subforums_list as $subforum) -- cgit v1.2.1 From eda9bcc65de97b9ffb2c432756907ff0411b281f Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 15:14:01 +0000 Subject: [feature/events] Add core.common_template_vars ledge Needed by board3portal PHPBB3-9550 --- phpBB/includes/functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e5b721b1f5..a16e8d6eeb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4909,7 +4909,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } // The following assigns all _common_ variables that may be used at any point in a template. - $template->assign_vars(array( + $template_vars = array( 'SITENAME' => $config['sitename'], 'SITE_DESCRIPTION' => $config['site_desc'], 'PAGE_TITLE' => $page_title, @@ -5031,7 +5031,15 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'SITE_LOGO_IMG' => $user->img('site_logo'), 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), - )); + ); + + $vars = array('template_vars'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.common_template_vars', $event); + extract($event->get_data_filtered($vars)); + + $template->assign_vars($template_vars); + $vars = array('page_title', 'display_online_list', 'item_id', 'item'); extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); -- cgit v1.2.1 From 77845c147818b4199005363a3168bbb44dc46641 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:55:17 +0100 Subject: [feature/events] Adding ledge user_update_name Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6e658b4ef4..b50dcac49c 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -112,7 +112,7 @@ function update_last_username() */ function user_update_name($old_name, $new_name) { - global $config, $db, $cache; + global $config, $db, $cache, $phpbb_dispatcher; $update_ary = array( FORUMS_TABLE => array('forum_last_poster_name'), @@ -137,6 +137,11 @@ function user_update_name($old_name, $new_name) set_config('newest_username', $new_name, true); } + $vars = array('old_name', 'new_name'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.user_update_name', $event); + extract($event->get_data_filtered($vars)); + // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); } -- cgit v1.2.1 From 5b226c400280588349eb3a4cab9780ae98d20c0f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:58:22 +0100 Subject: [feature/events] Adding ledges user_delete Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index b50dcac49c..32529ec308 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -336,7 +336,7 @@ function user_add($user_row, $cp_data = false) */ function user_delete($mode, $user_id, $post_username = false) { - global $cache, $config, $db, $user, $auth; + global $cache, $config, $db, $user, $auth, $phpbb_dispatcher; global $phpbb_root_path, $phpEx; $sql = 'SELECT * @@ -540,6 +540,11 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); + $vars = array('mode', 'user_id', 'post_username'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.user_delete', $event); + extract($event->get_data_filtered($vars)); + // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) { -- cgit v1.2.1 From ae49d6dca2fd17b2b4735c2026871d1a9250b4ad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:59:15 +0100 Subject: [feature/events] Adding ledge group_delete Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 32529ec308..0e751ba890 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2769,7 +2769,7 @@ function avatar_remove_db($avatar_name) */ function group_delete($group_id, $group_name = false) { - global $db, $phpbb_root_path, $phpEx; + global $db, $phpbb_root_path, $phpEx, $phpbb_dispatcher; if (!$group_name) { @@ -2818,6 +2818,11 @@ function group_delete($group_id, $group_name = false) $teampage->delete_group($group_id); unset($teampage); + $vars = array('group_id', 'group_name'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.group_delete', $event); + extract($event->get_data_filtered($vars)); + // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " WHERE group_id = $group_id"; -- cgit v1.2.1 From d4ace75370febea0f9a18ed2f744bee8caecedb2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 21:00:20 +0100 Subject: [feature/events] Adding ledge group_user_del Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 0e751ba890..a32f14e48f 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2955,7 +2955,7 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false, */ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, $group_name = false) { - global $db, $auth, $config; + global $db, $auth, $config, $phpbb_dispatcher; if ($config['coppa_enable']) { @@ -3054,6 +3054,11 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, } unset($special_group_data); + $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.group_user_del', $event); + extract($event->get_data_filtered($vars)); + $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id AND " . $db->sql_in_set('user_id', $user_id_ary); -- cgit v1.2.1 From 4d87b2254c7762db129b2706b372538451279d13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 21:01:49 +0100 Subject: [feature/events] Adding ledge group_set_user_default Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index a32f14e48f..82400de932 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3376,7 +3376,7 @@ function group_validate_groupname($group_id, $group_name) */ function group_set_user_default($group_id, $user_id_ary, $group_attributes = false, $update_listing = false) { - global $cache, $db; + global $cache, $db, $phpbb_dispatcher; if (empty($user_id_ary)) { @@ -3472,6 +3472,11 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } + $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.group_set_user_default', $event); + extract($event->get_data_filtered($vars)); + if ($update_listing) { group_update_listings($group_id); -- cgit v1.2.1 From eb7a04d32427d2070befdd10fcec657222bc8fa8 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 21:06:44 +0000 Subject: [feature/events] Add core.acp_foruns_add_forum_data ledge PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 3a3b2021eb..f4d0a93b8d 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -220,6 +220,11 @@ class acp_forums } trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); + + $vars = array('forum_data'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.acp_forums_add_forum_data', $event); + extract($event->get_data_filtered($vars)); } break; -- cgit v1.2.1 From 19a3164e80e9e34cab13d25f205789d7eb27aa66 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 23:59:40 +0000 Subject: [feature/events] Fixing core.acp_forums_add_forum_data PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index f4d0a93b8d..11843384ed 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -107,6 +107,11 @@ class acp_forums 'forum_id' => $forum_id ); + $vars = array('forum_data'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.acp_forums_add_forum_data', $event); + extract($event->get_data_filtered($vars)); + // No break here case 'add': @@ -220,11 +225,6 @@ class acp_forums } trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); - - $vars = array('forum_data'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.acp_forums_add_forum_data', $event); - extract($event->get_data_filtered($vars)); } break; -- cgit v1.2.1 From 5c0decf4cf7d6f73ffa686e8861aa3c444f51124 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 12:34:26 +0000 Subject: [feature/events] Adding core.acp_users_overview ledge PHPBB3-9550 --- phpBB/includes/acp/acp_users.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 79c91dd7ee..68077b4048 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1039,6 +1039,11 @@ class acp_users 'USER_INACTIVE_REASON' => $inactive_reason, )); + $vars = array('data', 'check_ary', 'sql_ary', 'user_row', 'quick_tool_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.acp_users_overview', $event); + extract($event->get_data_filtered($vars)); + break; case 'feedback': -- cgit v1.2.1 From 74d3555c4c510a76c947bd7c445f254e5b9b104e Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 13:09:33 +0000 Subject: [feature/events] Adding core.acp_modules_modules ledge PHPBB3-9550 --- phpBB/includes/acp/info/acp_modules.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/info/acp_modules.php b/phpBB/includes/acp/info/acp_modules.php index c9d2cffa72..fc04eec698 100644 --- a/phpBB/includes/acp/info/acp_modules.php +++ b/phpBB/includes/acp/info/acp_modules.php @@ -14,16 +14,27 @@ class acp_modules_info { function module() { - return array( - 'filename' => 'acp_modules', - 'title' => 'ACP_MODULE_MANAGEMENT', - 'version' => '1.0.0', - 'modes' => array( + global $phpbb_dispatcher; + + $modules = array( 'acp' => array('title' => 'ACP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), 'ucp' => array('title' => 'UCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), 'mcp' => array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - ), + ), + + $vars = array('modules'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.acp_modules_modules', $event); + extract($event->get_data_filtered($vars)); + + $data = array( + 'filename' => 'acp_modules', + 'title' => 'ACP_MODULE_MANAGEMENT', + 'version' => '1.0.0', + 'modes' => $modules ); + + return $data } function install() -- cgit v1.2.1 From f362d374cc8e421951d25de038708b06b5b4695d Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 13:33:02 +0000 Subject: [feature/events] Adding core.acp_profile_edit ledge PHPBB3-9550 --- phpBB/includes/acp/acp_profile.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 3ffffd3047..6704fce26f 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -876,6 +876,11 @@ class acp_profile } } + $vars = array('field_row', 'visibility_ary', 'exclude'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.acp_profile_edit', $event); + extract($event->get_data_filtered($vars)); + break; } -- cgit v1.2.1 From ddcd1890065258ca5a5d443b8790a9d2287891ad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:03:03 +0100 Subject: [feature/events] Adding ledge generate_smilies_footer Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_posting.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6c21b0f412..d3550aafba 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) */ function generate_smilies($mode, $forum_id) { - global $db, $user, $config, $template; + global $db, $user, $config, $template, $phpbb_dispatcher; global $phpEx, $phpbb_root_path; $start = request_var('start', 0); @@ -131,6 +131,11 @@ function generate_smilies($mode, $forum_id) ); } + $vars = array('mode', 'forum_id', 'display_link'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.generate_smilies_footer', $event); + extract($event->get_data_filtered($vars)); + if ($mode == 'window') { page_footer(); -- cgit v1.2.1 From 69407cae7bc50af526db86a3be3718d68f57d2bc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:21:12 +0100 Subject: [feature/events] Adding ledge display_custom_bbcodes_row Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_display.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index b320d35e09..604197b2eb 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -850,7 +850,7 @@ function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$fold */ function display_custom_bbcodes() { - global $db, $template, $user; + global $db, $template, $user, $phpbb_dispatcher; // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing) $num_predefined_bbcodes = 22; @@ -870,13 +870,20 @@ function display_custom_bbcodes() $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])]; } - $template->assign_block_vars('custom_tags', array( + $custom_tags = array( 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'", 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2), 'BBCODE_TAG' => $row['bbcode_tag'], 'BBCODE_HELPLINE' => $row['bbcode_helpline'], 'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']), - )); + ); + + $vars = array('custom_tags', 'row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.display_custom_bbcodes_row', $event); + extract($event->get_data_filtered($vars)); + + $template->assign_block_vars('custom_tags', $custom_tags); $i++; } -- cgit v1.2.1 From 1a7f83948eb9f4c1b8ab7fa411444a11e967fcd0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:22:31 +0100 Subject: [feature/events] Adding ledge display_custom_bbcodes Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_display.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 604197b2eb..684729fc0d 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -888,6 +888,8 @@ function display_custom_bbcodes() $i++; } $db->sql_freeresult($result); + + $phpbb_dispatcher->dispatch('core.display_custom_bbcodes'); } /** -- cgit v1.2.1 From 8d4c7d2e80a17b2ec5134e4dbe7fea5bfe57d02f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:29:49 +0100 Subject: [feature/events] Adding ledge ucp_pm_viewmesssage Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/ucp/ucp_pm_viewmessage.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index c55e8850a6..caaecfb741 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) { global $user, $template, $auth, $db, $cache; - global $phpbb_root_path, $request, $phpEx, $config; + global $phpbb_root_path, $request, $phpEx, $config, $phpbb_dispatcher; $user->add_lang(array('viewtopic', 'memberlist')); @@ -268,6 +268,11 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'U_FORWARD_PM' => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&mode=compose&action=forward&f=$folder_id&p=" . $message_row['msg_id'] : '') ); + $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.ucp_pm_viewmesssage', $event); + extract($event->get_data_filtered($vars)); + // Display the custom profile fields if (!empty($cp_row['row'])) { -- cgit v1.2.1 From 02244397d1ecb149322c0c7847718e14742c14a2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:37:46 +0100 Subject: [feature/events] Adding ledge ucp_zebra_remove Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/ucp/ucp_zebra.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index efe928b387..fd4f4ccaf4 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -25,7 +25,7 @@ class ucp_zebra function main($id, $mode) { - global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request; + global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request, $phpbb_dispatcher; $submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false; $s_hidden_fields = ''; @@ -54,6 +54,11 @@ class ucp_zebra // Remove users if (!empty($data['usernames'])) { + $vars = array('data'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.ucp_zebra_remove', $event); + extract($event->get_data_filtered($vars)); + $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' AND ' . $db->sql_in_set('zebra_id', $data['usernames']); -- cgit v1.2.1 From 4b4e2afd800d34b2f92f709f9199c38334f43b29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:40:01 +0100 Subject: [feature/events] Adding ledge ucp_zebra_add Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/ucp/ucp_zebra.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index fd4f4ccaf4..f8012fdcdf 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -191,6 +191,11 @@ class ucp_zebra ); } + $vars = array('mode', 'sql_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.ucp_zebra_add', $event); + extract($event->get_data_filtered($vars)); + $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary); $updated = true; -- cgit v1.2.1 From 1aa7bc81f6200389499080fa3863f6708d94dc70 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:47:27 +0100 Subject: [feature/events] Remove unnecessary ledge common_template_vars core.page_header is more powerful and includes all functionality of this one. PHPBB3-9550 --- phpBB/includes/functions.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index a16e8d6eeb..de0cb8766b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4909,7 +4909,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } // The following assigns all _common_ variables that may be used at any point in a template. - $template_vars = array( + $template->assign_vars(array( 'SITENAME' => $config['sitename'], 'SITE_DESCRIPTION' => $config['site_desc'], 'PAGE_TITLE' => $page_title, @@ -5031,14 +5031,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'SITE_LOGO_IMG' => $user->img('site_logo'), 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), - ); - - $vars = array('template_vars'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.common_template_vars', $event); - extract($event->get_data_filtered($vars)); - - $template->assign_vars($template_vars); + )); $vars = array('page_title', 'display_online_list', 'item_id', 'item'); -- cgit v1.2.1 From 643081d56c1a984e3b0cf4f942392c5a392c9ed6 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 19:03:52 +0000 Subject: [feature/events] Adding core.mcp_forum_topicrow ledge PHPBB3-9550 --- phpBB/includes/mcp/mcp_forum.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 4518e7b7cf..d40b8b5279 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -288,6 +288,11 @@ function mcp_forum_view($id, $mode, $action, $forum_info) )); } + $vars = array('topic_row', 'row'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.mcp_forum_topicrow', $event); + extract($event->get_data_filtered($vars)); + $template->assign_block_vars('topicrow', $topic_row); } unset($topic_rows); -- cgit v1.2.1 From b966551e6bef9dfd272734587fe4bc9ca7e4611c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 00:46:43 +0100 Subject: [feature/events] Fix ledges in ACP and apply coding guidelines PHPBB3-9550 --- phpBB/includes/acp/acp_profile.php | 2 +- phpBB/includes/acp/acp_users.php | 2 +- phpBB/includes/acp/info/acp_modules.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 6704fce26f..43426e86a7 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -27,7 +27,7 @@ class acp_profile function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache; + global $config, $db, $user, $auth, $template, $cache, $phpbb_dispatcher; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $request; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 68077b4048..f6c2ecfc87 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -30,7 +30,7 @@ class acp_users function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache; + global $config, $db, $user, $auth, $template, $cache, $phpbb_dispatcher; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; $user->add_lang(array('posting', 'ucp', 'acp/users')); diff --git a/phpBB/includes/acp/info/acp_modules.php b/phpBB/includes/acp/info/acp_modules.php index fc04eec698..97616af22d 100644 --- a/phpBB/includes/acp/info/acp_modules.php +++ b/phpBB/includes/acp/info/acp_modules.php @@ -17,9 +17,9 @@ class acp_modules_info global $phpbb_dispatcher; $modules = array( - 'acp' => array('title' => 'ACP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - 'ucp' => array('title' => 'UCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - 'mcp' => array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), + 'acp' => array('title' => 'ACP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), + 'ucp' => array('title' => 'UCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), + 'mcp' => array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), ), $vars = array('modules'); @@ -31,7 +31,7 @@ class acp_modules_info 'filename' => 'acp_modules', 'title' => 'ACP_MODULE_MANAGEMENT', 'version' => '1.0.0', - 'modes' => $modules + 'modes' => $modules, ); return $data -- cgit v1.2.1 From ba63df2dce9da69caa31f1f4404b3b79a7f4f75e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 11:45:09 +0100 Subject: [feature/events] Fix info/acp_modules.php completly PHPBB3-9550 --- phpBB/includes/acp/info/acp_modules.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/info/acp_modules.php b/phpBB/includes/acp/info/acp_modules.php index 97616af22d..39091875d1 100644 --- a/phpBB/includes/acp/info/acp_modules.php +++ b/phpBB/includes/acp/info/acp_modules.php @@ -20,7 +20,7 @@ class acp_modules_info 'acp' => array('title' => 'ACP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), 'ucp' => array('title' => 'UCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), 'mcp' => array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - ), + ); $vars = array('modules'); $event = new phpbb_event_data(compact($vars)); @@ -34,7 +34,7 @@ class acp_modules_info 'modes' => $modules, ); - return $data + return $data; } function install() -- cgit v1.2.1 From 8af7d225ef481cd26e6fd7862847183d25727117 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Tue, 20 Mar 2012 11:23:03 +0000 Subject: [feature/events] Change to use the new method of adding events PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 4 +--- phpBB/includes/functions_display.php | 20 +++++--------------- phpBB/includes/functions_posting.php | 4 +--- phpBB/includes/functions_user.php | 20 +++++--------------- phpBB/includes/ucp/ucp_pm_viewmessage.php | 4 +--- phpBB/includes/ucp/ucp_zebra.php | 8 ++------ 6 files changed, 15 insertions(+), 45 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 11843384ed..d86925dfab 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -108,9 +108,7 @@ class acp_forums ); $vars = array('forum_data'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.acp_forums_add_forum_data', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_add_forum_data', compact($vars), $vars)); // No break here diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 684729fc0d..507576b1d6 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -120,9 +120,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod ); $vars = array('sql_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.display_forums_sql_inject', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_sql_inject', compact($vars), $vars)); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -133,9 +131,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod while ($row = $db->sql_fetchrow($result)) { $vars = array('row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.display_forums_row_inject', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_row_inject', compact($vars), $vars)); $forum_id = $row['forum_id']; @@ -235,9 +231,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; $vars = array('forum_rows', 'parent_id', 'row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.display_forums_row_values_inject', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_row_values_inject', compact($vars), $vars)); } else if ($row['forum_type'] != FORUM_CAT) { @@ -499,9 +493,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod ); $vars = array('row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.display_forums_assign_block_vars', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_assign_block_vars', compact($vars), $vars)); // Assign subforums loop for style authors foreach ($subforums_list as $subforum) @@ -879,9 +871,7 @@ function display_custom_bbcodes() ); $vars = array('custom_tags', 'row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.display_custom_bbcodes_row', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_row', compact($vars), $vars)); $template->assign_block_vars('custom_tags', $custom_tags); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d3550aafba..6c7cb3f0b2 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -132,9 +132,7 @@ function generate_smilies($mode, $forum_id) } $vars = array('mode', 'forum_id', 'display_link'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.generate_smilies_footer', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.generate_smilies_footer', compact($vars), $vars)); if ($mode == 'window') { diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 82400de932..761ce6436a 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -138,9 +138,7 @@ function user_update_name($old_name, $new_name) } $vars = array('old_name', 'new_name'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.user_update_name', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars), $vars)); // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); @@ -541,9 +539,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); $vars = array('mode', 'user_id', 'post_username'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.user_delete', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars), $vars)); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) @@ -2819,9 +2815,7 @@ function group_delete($group_id, $group_name = false) unset($teampage); $vars = array('group_id', 'group_name'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.group_delete', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars), $vars)); // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " @@ -3055,9 +3049,7 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, unset($special_group_data); $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.group_user_del', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars), $vars)); $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id @@ -3473,9 +3465,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.group_set_user_default', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars), $vars)); if ($update_listing) { diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index caaecfb741..a381521813 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -269,9 +269,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) ); $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.ucp_pm_viewmesssage', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.ucp_pm_viewmesssage', compact($vars), $vars)); // Display the custom profile fields if (!empty($cp_row['row'])) diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index f8012fdcdf..a2eb5dbdaa 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -55,9 +55,7 @@ class ucp_zebra if (!empty($data['usernames'])) { $vars = array('data'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.ucp_zebra_remove', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_remove', compact($vars), $vars)); $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' @@ -192,9 +190,7 @@ class ucp_zebra } $vars = array('mode', 'sql_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.ucp_zebra_add', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_add', compact($vars), $vars)); $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary); -- cgit v1.2.1 From 8da33e2654f89e55352012b197dfef4ae7a1fc7e Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 23 Mar 2012 12:11:45 +0000 Subject: [feature/events] Remove core.acp_modules_modules event PHPBB3-9550 --- phpBB/includes/acp/info/acp_modules.php | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/info/acp_modules.php b/phpBB/includes/acp/info/acp_modules.php index 39091875d1..c9d2cffa72 100644 --- a/phpBB/includes/acp/info/acp_modules.php +++ b/phpBB/includes/acp/info/acp_modules.php @@ -14,27 +14,16 @@ class acp_modules_info { function module() { - global $phpbb_dispatcher; - - $modules = array( - 'acp' => array('title' => 'ACP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - 'ucp' => array('title' => 'UCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - 'mcp' => array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), - ); - - $vars = array('modules'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.acp_modules_modules', $event); - extract($event->get_data_filtered($vars)); - - $data = array( + return array( 'filename' => 'acp_modules', 'title' => 'ACP_MODULE_MANAGEMENT', 'version' => '1.0.0', - 'modes' => $modules, + 'modes' => array( + 'acp' => array('title' => 'ACP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), + 'ucp' => array('title' => 'UCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), + 'mcp' => array('title' => 'MCP', 'auth' => 'acl_a_modules', 'cat' => array('ACP_MODULE_MANAGEMENT')), + ), ); - - return $data; } function install() -- cgit v1.2.1 From 3f1b4e83aef7f7344cd551463b59de71bb4bd6fe Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 31 Mar 2012 13:39:41 +0100 Subject: [feature/events] Removing the third trigger_event parameter PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 2 +- phpBB/includes/functions_display.php | 10 +++++----- phpBB/includes/functions_posting.php | 2 +- phpBB/includes/functions_user.php | 10 +++++----- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 +- phpBB/includes/ucp/ucp_zebra.php | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index d86925dfab..f71e5f85b0 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -108,7 +108,7 @@ class acp_forums ); $vars = array('forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_add_forum_data', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_add_forum_data', compact($vars))); // No break here diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 507576b1d6..003724a8f5 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -120,7 +120,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod ); $vars = array('sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_sql_inject', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_sql_inject', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -131,7 +131,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod while ($row = $db->sql_fetchrow($result)) { $vars = array('row'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_row_inject', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_row_inject', compact($vars))); $forum_id = $row['forum_id']; @@ -231,7 +231,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; $vars = array('forum_rows', 'parent_id', 'row'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_row_values_inject', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_row_values_inject', compact($vars))); } else if ($row['forum_type'] != FORUM_CAT) { @@ -493,7 +493,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod ); $vars = array('row'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_assign_block_vars', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.display_forums_assign_block_vars', compact($vars))); // Assign subforums loop for style authors foreach ($subforums_list as $subforum) @@ -871,7 +871,7 @@ function display_custom_bbcodes() ); $vars = array('custom_tags', 'row'); - extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_row', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_row', compact($vars))); $template->assign_block_vars('custom_tags', $custom_tags); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6c7cb3f0b2..0476c9b5d5 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -132,7 +132,7 @@ function generate_smilies($mode, $forum_id) } $vars = array('mode', 'forum_id', 'display_link'); - extract($phpbb_dispatcher->trigger_event('core.generate_smilies_footer', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.generate_smilies_footer', compact($vars))); if ($mode == 'window') { diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 761ce6436a..cf6a99c2b7 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -138,7 +138,7 @@ function user_update_name($old_name, $new_name) } $vars = array('old_name', 'new_name'); - extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars))); // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); @@ -539,7 +539,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); $vars = array('mode', 'user_id', 'post_username'); - extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars))); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) @@ -2815,7 +2815,7 @@ function group_delete($group_id, $group_name = false) unset($teampage); $vars = array('group_id', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars))); // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " @@ -3049,7 +3049,7 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, unset($special_group_data); $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars))); $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id @@ -3465,7 +3465,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars))); if ($update_listing) { diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index a381521813..ba297b96dd 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -269,7 +269,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) ); $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row'); - extract($phpbb_dispatcher->trigger_event('core.ucp_pm_viewmesssage', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.ucp_pm_viewmesssage', compact($vars))); // Display the custom profile fields if (!empty($cp_row['row'])) diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index a2eb5dbdaa..f153fd6aed 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -55,7 +55,7 @@ class ucp_zebra if (!empty($data['usernames'])) { $vars = array('data'); - extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_remove', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_remove', compact($vars))); $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' @@ -190,7 +190,7 @@ class ucp_zebra } $vars = array('mode', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_add', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_add', compact($vars))); $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary); -- cgit v1.2.1 From a247bfc2b6ee8f4aeb53f639294932fa16688666 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 1 Apr 2012 20:19:47 +0100 Subject: [feature/events] Fixing issues with events PHPBB3-9550 --- phpBB/includes/functions.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index de0cb8766b..e5b721b1f5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5033,7 +5033,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - $vars = array('page_title', 'display_online_list', 'item_id', 'item'); extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); -- cgit v1.2.1 From 6b1ca27a86ea8122d98d26ed4252754237d6cc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Mon, 2 Apr 2012 11:53:12 +0200 Subject: [feature/events] Add `core.page_header_override` Add a ledge that will allow listeners to override the build in `page_header` function. http://area51.phpbb.com/phpBB/viewtopic.php?f=111&t=42741&p=237037 PHPBB3-9550 --- phpBB/includes/functions.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e5b721b1f5..4ad1ba5c82 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4753,6 +4753,16 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 define('HEADER_INC', true); + // A listener can set this variable to `true` when it overrides this function + $page_header_override = false; + + $vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override'); + extract($phpbb_dispatcher->trigger_event('core.page_header_override', compact($vars))); + if ($page_header_override) + { + return; + } + // gzip_compression if ($config['gzip_compress']) { -- cgit v1.2.1 From 1a1ae60d8d8c84f39f5d6a2497d5e1965e5d1f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Mon, 2 Apr 2012 11:57:25 +0200 Subject: [feature/events] Add `core.page_footer_override` Add a ledge that will allow listeners to override the build in `page_footer` function. http://area51.phpbb.com/phpBB/viewtopic.php?f=111&t=42741&p=237037 PHPBB3-9550 --- phpBB/includes/functions.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4ad1ba5c82..f31a657687 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5069,6 +5069,17 @@ function page_footer($run_cron = true) { global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx; global $request; + global $phpbb_dispatcher; + + // A listener can set this variable to `true` when it overrides this function + $page_footer_override = false; + + $vars = array('run_cron', 'page_footer_override'); + extract($phpbb_dispatcher->trigger_event('core.page_footer_override', compact($vars))); + if ($page_footer_override) + { + return; + } // Output page creation time if (defined('DEBUG')) -- cgit v1.2.1 From 3d4946f5f017a51c7ae358ae450f4d9bb1cac70c Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 7 Apr 2012 15:47:57 +0100 Subject: [feature/events] Fixing events issues PHPBB3-9550 --- phpBB/includes/functions.php | 1 + phpBB/includes/mcp/mcp_forum.php | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index f31a657687..86a2d14315 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5076,6 +5076,7 @@ function page_footer($run_cron = true) $vars = array('run_cron', 'page_footer_override'); extract($phpbb_dispatcher->trigger_event('core.page_footer_override', compact($vars))); + if ($page_footer_override) { return; diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index d40b8b5279..a43e896b07 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -289,9 +289,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) } $vars = array('topic_row', 'row'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.mcp_forum_topicrow', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.mcp_forum_topicrow', compact($vars))); $template->assign_block_vars('topicrow', $topic_row); } -- cgit v1.2.1 From c7b84eb32935ad78ae56fbf6382f95e8df11cdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 20:29:40 +0200 Subject: [feature/events] Adding core.build_cfg_template event See: http://area51.phpbb.com/phpBB/viewtopic.php?f=111&t=42801 for referance. PHPBB3-9550 --- phpBB/includes/functions_acp.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index dc61859363..47caecef02 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -194,6 +194,7 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key = function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) { global $user, $module; + global $phpbb_dispatcher; $tpl = ''; $name = 'config[' . $config_key . ']'; @@ -305,6 +306,9 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) $tpl .= $vars['append']; } + $vars = array('tpl_type', 'key', 'new', 'config_key', 'vars', 'tpl'); + extract($phpbb_dispatcher->trigger_event('core.build_cfg_template', compact($vars))); + return $tpl; } -- cgit v1.2.1 From 95e81fb402c1eccf2c7772914ef301fd4043d9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 20:18:05 +0200 Subject: [feature/events] Adding core.adm_page_header_override event Add an event that adds the possibility to override the phpBB `adm_page_header` function. PHPBB3-9550 --- phpBB/includes/functions_acp.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 47caecef02..c2ed623ece 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -22,6 +22,7 @@ function adm_page_header($page_title) { global $config, $db, $user, $template; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID; + global $phpbb_dispatcher; if (defined('HEADER_INC')) { @@ -30,6 +31,16 @@ function adm_page_header($page_title) define('HEADER_INC', true); + // A listener can set this variable to `true` when it overrides this function + $adm_page_header_override = false; + + $vars = array('page_title', 'adm_page_header_override'); + extract($phpbb_dispatcher->trigger_event('core.adm_page_header_override', compact($vars))); + if ($adm_page_header_override) + { + return; + } + // gzip_compression if ($config['gzip_compress']) { -- cgit v1.2.1 From 586912882833707a51edc44a810c5f174bdce72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 20:21:45 +0200 Subject: [feature/events] Adding adm_page_footer_override event Add an event that adds the possibility to override the phpBB `adm_page_footer` function. PHPBB3-9550 --- phpBB/includes/functions_acp.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index c2ed623ece..c8dc68fea1 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -108,6 +108,18 @@ function adm_page_footer($copyright_html = true) global $db, $config, $template, $user, $auth, $cache; global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx; global $request; + global $phpbb_dispatcher; + + // A listener can set this variable to `true` when it overrides this function + $adm_page_footer_override = false; + + $vars = array('copyright_html', 'adm_page_footer_override'); + extract($phpbb_dispatcher->trigger_event('core.adm_page_footer_override', compact($vars))); + + if ($adm_page_footer_override) + { + return; + } // Output page creation time if (defined('DEBUG')) -- cgit v1.2.1 From e21861b488ad4daf88b02aedf4e93d218d250ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 20:35:30 +0200 Subject: [feature/events] Adding core.garbage_collection event See: http://area51.phpbb.com/phpBB/viewtopic.php?f=111&t=42799 for reference. PHPBB3-9550 --- phpBB/includes/functions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 86a2d14315..086755f49d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5165,6 +5165,9 @@ function page_footer($run_cron = true) function garbage_collection() { global $cache, $db; + global $phpbb_dispatcher; + + $phpbb_dispatcher->dispatch('core.garbage_collection'); // Unload cache, must be done before the DB connection if closed if (!empty($cache)) -- cgit v1.2.1 From b04141b14f2fe5a804e55c6e4f94869b9f4e4a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 22:22:29 +0200 Subject: [feature/events] Correct core.acp_users_overview event The event still used the "old" method. PHPBB3-9550 --- phpBB/includes/acp/acp_users.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index f6c2ecfc87..de1e9afc83 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -30,8 +30,9 @@ class acp_users function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache, $phpbb_dispatcher; + global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $phpbb_dispatcher; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -1040,9 +1041,7 @@ class acp_users )); $vars = array('data', 'check_ary', 'sql_ary', 'user_row', 'quick_tool_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.acp_users_overview', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.acp_users_overview', compact($vars))); break; -- cgit v1.2.1 From 05c0d1ad177342eb40ee97c1ae7452aa90f6583f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 22:19:18 +0200 Subject: [feature/events] Correct core.acp_profile_edit event Still used the "old" way. PHPBB3-9550 --- phpBB/includes/acp/acp_profile.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 43426e86a7..1b542c2bfb 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -27,9 +27,10 @@ class acp_profile function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache, $phpbb_dispatcher; + global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $request; + global $phpbb_dispatcher; include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); include($phpbb_root_path . 'includes/functions_user.' . $phpEx); @@ -876,10 +877,8 @@ class acp_profile } } - $vars = array('field_row', 'visibility_ary', 'exclude'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.acp_profile_edit', $event); - extract($event->get_data_filtered($vars)); + $vars = array('field_row', 'visibility_ary', 'exclude'); + extract($phpbb_dispatcher->trigger_event('core.acp_profile_edit', compact($vars))); break; } -- cgit v1.2.1 From 57617b048f7ab1deb2a7019be29a24d782a00fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Tue, 10 Apr 2012 22:56:45 +0200 Subject: [feature/events] Adding core.validate_config_vars event Allows a MOD author to define additional "configuration types" and add the logic to validate these option types as well. PHPBB3-9550 --- phpBB/includes/functions_acp.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index c8dc68fea1..4ff126260f 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -342,6 +342,8 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) function validate_config_vars($config_vars, &$cfg_array, &$error) { global $phpbb_root_path, $user; + global $phpbb_dispatcher; + $type = 0; $min = 1; $max = 2; @@ -516,6 +518,11 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) } break; + + default: + $vars = array('cfg_array', 'config_name', 'config_definition', 'error'); + extract($phpbb_dispatcher->trigger_event('core.validate_config_vars', compact($vars))); + break; } } -- cgit v1.2.1 From c51e8716c5a2d0f5efc02abb7de08cab087f9442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=A8rejean?= Date: Thu, 19 Apr 2012 13:00:28 +0200 Subject: [feature/events] Add blank line Add an additional blank line as requested in #680 PHPBB3-9550 --- phpBB/includes/functions.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 086755f49d..85449a8cd3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4758,6 +4758,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override'); extract($phpbb_dispatcher->trigger_event('core.page_header_override', compact($vars))); + if ($page_header_override) { return; -- cgit v1.2.1 From 6059bc7b45a098e4bc846fe3704543137cc1aba1 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 25 May 2012 18:18:27 -0400 Subject: [feature/events] Added core.user_default_avatar event This way, extension authors can overwrite the empty value returned when a user does not have an avatar with a default value to display instead of nothing in the avatar space. PHPBB3-9550 --- phpBB/includes/functions_display.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 003724a8f5..53a07d5591 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1267,10 +1267,19 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) { global $user, $config, $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config)) { - return ''; + $empty_avatar = ''; + if ($config['allow_avatar'] || $ignore_config) + { + // This allows extensions to change the default return when no avatar is given + // Useful for default avatars + $vars = array('empty_avatar'); + extract($phpbb_dispatcher->trigger_event('core.user_default_avatar', compact($vars))); + } + return $empty_avatar; } $avatar_img = ''; -- cgit v1.2.1 From 611d965b043c2a566e817f29d618ff841aa02c34 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 11 Jun 2012 08:26:44 -0400 Subject: [feature/events] Renamed $empty_avatar to $default_avatar PHPBB3-9550 --- phpBB/includes/functions_display.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 53a07d5591..6b145ea422 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1271,15 +1271,15 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config)) { - $empty_avatar = ''; + $default_avatar = ''; if ($config['allow_avatar'] || $ignore_config) { // This allows extensions to change the default return when no avatar is given // Useful for default avatars - $vars = array('empty_avatar'); + $vars = array('default_avatar'); extract($phpbb_dispatcher->trigger_event('core.user_default_avatar', compact($vars))); } - return $empty_avatar; + return $default_avatar; } $avatar_img = ''; -- cgit v1.2.1 From 0f78b4699acd823f773214497f68840178a8b82e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:41:02 +0200 Subject: [feature/php-events] Replace core.acp_forums_add_forum_data Add missing global $phpbb_dispatcher, add $action and name the event better PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index f71e5f85b0..b634a3d9a0 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -25,7 +25,7 @@ class acp_forums function main($id, $mode) { - global $db, $user, $auth, $template, $cache, $request; + global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher; global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx; $user->add_lang('acp/forums'); @@ -107,9 +107,6 @@ class acp_forums 'forum_id' => $forum_id ); - $vars = array('forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_add_forum_data', compact($vars))); - // No break here case 'add': @@ -153,6 +150,9 @@ class acp_forums 'forum_password_unset' => request_var('forum_password_unset', false), ); + $vars = array('action', 'forum_data'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_modify_forum_data', compact($vars))); + // On add, add empty forum_options... else do not consider it (not updating it) if ($action == 'add') { -- cgit v1.2.1 From 8637f09b356f2b26a33e9ab2a7d245fb0e016f85 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:43:22 +0200 Subject: [feature/php-events] Fix name of event when changing a profile field PHPBB3-9550 --- phpBB/includes/acp/acp_profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 1b542c2bfb..d84c4c2ed5 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -878,7 +878,7 @@ class acp_profile } $vars = array('field_row', 'visibility_ary', 'exclude'); - extract($phpbb_dispatcher->trigger_event('core.acp_profile_edit', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.acp_profile_field_edit', compact($vars))); break; } -- cgit v1.2.1 From 3a9b7c9acf7ab0e9bd78cf76d59c30c48fb17c6a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:47:56 +0200 Subject: [feature/php-events] Remove duplicated event and name the events properly PHPBB3-9550 --- phpBB/includes/functions.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 85449a8cd3..442b125657 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4757,7 +4757,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $page_header_override = false; $vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override'); - extract($phpbb_dispatcher->trigger_event('core.page_header_override', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); if ($page_header_override) { @@ -5044,9 +5044,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - $vars = array('page_title', 'display_online_list', 'item_id', 'item'); - extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); - // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); @@ -5076,7 +5073,7 @@ function page_footer($run_cron = true) $page_footer_override = false; $vars = array('run_cron', 'page_footer_override'); - extract($phpbb_dispatcher->trigger_event('core.page_footer_override', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.page_footer', compact($vars))); if ($page_footer_override) { -- cgit v1.2.1 From e126c37ea8a0c47ce8a78959a71ca8f9da8340ea Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:49:41 +0200 Subject: [feature/php-events] Remove _override from event name PHPBB3-9550 --- phpBB/includes/functions_acp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 4ff126260f..f59c8cd4c6 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -35,7 +35,7 @@ function adm_page_header($page_title) $adm_page_header_override = false; $vars = array('page_title', 'adm_page_header_override'); - extract($phpbb_dispatcher->trigger_event('core.adm_page_header_override', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.adm_page_header', compact($vars))); if ($adm_page_header_override) { return; @@ -114,7 +114,7 @@ function adm_page_footer($copyright_html = true) $adm_page_footer_override = false; $vars = array('copyright_html', 'adm_page_footer_override'); - extract($phpbb_dispatcher->trigger_event('core.adm_page_footer_override', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.adm_page_footer', compact($vars))); if ($adm_page_footer_override) { -- cgit v1.2.1 From 730bd6eb08aa76dc54e661b03207e2d695d9a8c5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:52:45 +0200 Subject: [feature/php-events] Rename display_forums_sql_inject to be less misleading PHPBB3-9550 --- phpBB/includes/functions_display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 6b145ea422..68c49c2457 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -120,7 +120,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod ); $vars = array('sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_sql_inject', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.display_forums_build_query', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); -- cgit v1.2.1 From 3af0ae69eed6955a23b29087891258efb1a06e33 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:54:55 +0200 Subject: [feature/php-events] Properly name user_default_avatar and add additional vars PHPBB3-9550 --- phpBB/includes/functions_display.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 68c49c2457..ca2bfc3b65 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1276,8 +1276,8 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ { // This allows extensions to change the default return when no avatar is given // Useful for default avatars - $vars = array('default_avatar'); - extract($phpbb_dispatcher->trigger_event('core.user_default_avatar', compact($vars))); + $vars = array('avatar', 'avatar_type', 'ignore_config', 'default_avatar'); + extract($phpbb_dispatcher->trigger_event('core.get_user_avatar_default', compact($vars))); } return $default_avatar; } -- cgit v1.2.1 From 758fb67a7dc3bcc39ec0284c7045b2668f049408 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:58:12 +0200 Subject: [feature/php-events] Add missing global $phpbb_dispatcher PHPBB3-9550 --- phpBB/includes/mcp/mcp_forum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index a43e896b07..9b3c002968 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -22,7 +22,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) { global $template, $db, $user, $auth, $cache, $module; global $phpEx, $phpbb_root_path, $config; - global $request; + global $request, $phpbb_dispatcher; $user->add_lang(array('viewtopic', 'viewforum')); -- cgit v1.2.1 From 2e5a7ae4dda587bc1f47f2f1fddb4e13235217d4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:22:22 +0200 Subject: [feature/php-events] Add additional events to acp_forums.php PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index b634a3d9a0..1c798a12da 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -151,7 +151,7 @@ class acp_forums ); $vars = array('action', 'forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_modify_forum_data', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_get_forum_data', compact($vars))); // On add, add empty forum_options... else do not consider it (not updating it) if ($action == 'add') @@ -416,6 +416,9 @@ class acp_forums $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false); $forum_data['forum_password_confirm'] = $forum_data['forum_password']; + + $vars = array('forum_id', 'row', 'forum_data'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_modify_forum_data', compact($vars))); } else { @@ -453,6 +456,9 @@ class acp_forums 'forum_password' => '', 'forum_password_confirm'=> '', ); + + $vars = array('forum_id', 'forum_data'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_init_forum_data', compact($vars))); } } @@ -585,7 +591,7 @@ class acp_forums $errors[] = $user->lang['FORUM_PASSWORD_OLD']; } - $template->assign_vars(array( + $template_data = array( 'S_EDIT_FORUM' => true, 'S_ERROR' => (sizeof($errors)) ? true : false, 'S_PARENT_ID' => $this->parent_id, @@ -650,7 +656,12 @@ class acp_forums 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false, 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false, 'S_CAN_COPY_PERMISSIONS' => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false, - )); + ); + + $vars = array('forum_id', 'action', 'forum_data', 'template_data', 'old_forum_type', 'forum_desc_data', 'forum_rules_data'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_assign_template_forum_data', compact($vars))); + + $template->assign_vars($template_data); return; @@ -875,10 +886,13 @@ class acp_forums */ function update_forum_data(&$forum_data) { - global $db, $user, $cache, $phpbb_root_path; + global $db, $user, $cache, $phpbb_root_path, $phpbb_dispatcher; $errors = array(); + $vars = array('forum_data', 'errors'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_update_forum_data', compact($vars))); + if ($forum_data['forum_name'] == '') { $errors[] = $user->lang['FORUM_NAME_EMPTY']; @@ -1242,6 +1256,9 @@ class acp_forums add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']); } + $vars = array('forum_data', 'errors'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_update_forum_data_after', compact($vars))); + return $errors; } @@ -1250,10 +1267,13 @@ class acp_forums */ function move_forum($from_id, $to_id) { - global $db, $user; + global $db, $user, $phpbb_dispatcher; $to_data = $moved_ids = $errors = array(); + $vars = array('from_id', 'to_id'); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_move_forum', compact($vars))); + // Check if we want to move to a parent with link type if ($to_id > 0) { -- cgit v1.2.1 From b1582ece91e7ebd9f635040bbb1a4c6c47786135 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:42:47 +0200 Subject: [feature/php-events] Proper name for request forum data to avoid confusion PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 1c798a12da..6631edf438 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -151,7 +151,7 @@ class acp_forums ); $vars = array('action', 'forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_get_forum_data', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.acp_forums_request_forum_data', compact($vars))); // On add, add empty forum_options... else do not consider it (not updating it) if ($action == 'add') -- cgit v1.2.1 From bdfedba521ee38ef6b8915bfb130b2f164c040c0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:43:08 +0200 Subject: [feature/php-events] Make handling of forumrow consistent with others PHPBB3-9550 --- phpBB/includes/functions_display.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index ca2bfc3b65..9ab90a6482 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -452,7 +452,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } } - $template->assign_block_vars('forumrow', array( + $forum_row = array( 'S_IS_CAT' => false, 'S_NO_CAT' => $catless && !$last_catless, 'S_IS_LINK' => ($row['forum_type'] == FORUM_LINK) ? true : false, @@ -489,12 +489,14 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'U_UNAPPROVED_TOPICS' => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=unapproved_topics&f=' . $row['forum_id_unapproved_topics']) : '', 'U_VIEWFORUM' => $u_viewforum, 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), - 'U_LAST_POST' => $last_post_url) + 'U_LAST_POST' => $last_post_url, ); - $vars = array('row'); + $vars = array('row', 'forum_row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_assign_block_vars', compact($vars))); + $template->assign_block_vars('forumrow', $forum_row); + // Assign subforums loop for style authors foreach ($subforums_list as $subforum) { -- cgit v1.2.1 From c903b1512c9926dfbc54e4e48233904385c137c6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 16:53:20 +0200 Subject: [feature/php-events] Fix docs and naming of core.update_username PHPBB3-9550 --- phpBB/includes/functions_user.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index cf6a99c2b7..eef75b8430 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -137,8 +137,16 @@ function user_update_name($old_name, $new_name) set_config('newest_username', $new_name, true); } + /** + * Update username when it is changed + * + * @event core.update_username + * @var string old_name The old username that is replaced + * @var string new_name The new username + * @since 3.1-A1 + */ $vars = array('old_name', 'new_name'); - extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.update_username', compact($vars))); // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); -- cgit v1.2.1 From ec957350c14c8b0bb6dc4768b5ad363a39715cab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 17:02:18 +0200 Subject: [feature/php-events] Fix docs and naming of core.delete_user_after PHPBB3-9550 --- phpBB/includes/functions_user.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index eef75b8430..de65d86e3f 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -546,8 +546,17 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); + /** + * Event after an user is deleted + * + * @event core.delete_user_after + * @var string mode Mode of deletion (retain/delete posts) + * @var int user_id ID of the deleted user + * @var mixed post_username Guest username that is being used or false + * @since 3.1-A1 + */ $vars = array('mode', 'user_id', 'post_username'); - extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.delete_user_after', compact($vars))); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) -- cgit v1.2.1 From 3affe7f229f4c8a3bb4ddb1abd79aca0dc0c15a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 17:03:04 +0200 Subject: [feature/php-events] Fix docs and naming of core.delete_user_before PHPBB3-9550 --- phpBB/includes/functions_user.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index de65d86e3f..8f91a66549 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -357,6 +357,18 @@ function user_delete($mode, $user_id, $post_username = false) return false; } + /** + * Event before an user is deleted + * + * @event core.delete_user_before + * @var string mode Mode of deletion (retain/delete posts) + * @var int user_id ID of the deleted user + * @var mixed post_username Guest username that is being used or false + * @since 3.1-A1 + */ + $vars = array('mode', 'user_id', 'post_username'); + extract($phpbb_dispatcher->trigger_event('core.delete_user_before', compact($vars))); + // Before we begin, we will remove the reports the user issued. $sql = 'SELECT r.post_id, p.topic_id FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p -- cgit v1.2.1 From 8d3389448bf65f1bfc78efbfc80d0b658661f3da Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 18:54:00 +0200 Subject: [feature/php-events] Fix docs and naming of core.delete_group_after PHPBB3-9550 --- phpBB/includes/functions_user.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 8f91a66549..c78c74bd76 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2843,9 +2843,6 @@ function group_delete($group_id, $group_name = false) $teampage->delete_group($group_id); unset($teampage); - $vars = array('group_id', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars))); - // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " WHERE group_id = $group_id"; @@ -2856,6 +2853,17 @@ function group_delete($group_id, $group_name = false) WHERE group_id = $group_id"; $db->sql_query($sql); + /** + * Event after a group is deleted + * + * @event core.delete_group_after + * @var int group_id ID of the deleted group + * @var string group_name Name of the deleted group + * @since 3.1-A1 + */ + $vars = array('group_id', 'group_name'); + extract($phpbb_dispatcher->trigger_event('core.delete_group_after', compact($vars))); + // Re-cache moderators if (!function_exists('cache_moderators')) { -- cgit v1.2.1 From 3ced9f58ea5493e13796766d55059b70bc6d6a3e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 19:27:58 +0200 Subject: [feature/php-events] Fix docs and naming of core.group_delete_user_before PHPBB3-9550 --- phpBB/includes/functions_user.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c78c74bd76..d65d59f6c5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3085,8 +3085,18 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, } unset($special_group_data); - $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars))); + /** + * Event before users are removed from a group + * + * @event core.group_delete_user_before + * @var int group_id ID of the group from which users are deleted + * @var string group_name Name of the group + * @var array user_id_ary IDs of the users which are removed + * @var array username_ary names of the users which are removed + * @since 3.1-A1 + */ + $vars = array('group_id', 'group_name', 'user_id_ary', 'username_ary'); + extract($phpbb_dispatcher->trigger_event('core.group_delete_user_before', compact($vars))); $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id -- cgit v1.2.1 From a05cd6d837ad9d2202561ded9c100a9b1350c0c2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 19:50:58 +0200 Subject: [feature/php-events] Fix docs and naming of core.user_set_default_group PHPBB3-9550 --- phpBB/includes/functions_user.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index d65d59f6c5..733a6fd9bd 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3511,8 +3511,19 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } + /** + * Event when the default group is set for an array of user + * + * @event core.user_set_default_group + * @var int group_id ID of the group + * @var array user_id_ary IDs of the users + * @var array group_attributes Group attributes which were changed + * @var array update_listing Update the list of moderators and foes + * @var array sql_ary User attributes which were changed + * @since 3.1-A1 + */ $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.user_set_default_group', compact($vars))); if ($update_listing) { -- cgit v1.2.1 From 099aaab7208123a5fb8195ccd5bdccee80ea2460 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 22:47:00 +0200 Subject: [feature/php-events] Fix docs and naming of core.display_forums_modify_sql PHPBB3-9550 --- phpBB/includes/functions_display.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 9ab90a6482..7111153fd4 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -119,8 +119,15 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'ORDER_BY' => 'f.left_id', ); + /** + * Event to modify the SQL query before the forum data is queried + * + * @event core.display_forums_modify_sql + * @var array sql_ary The SQL array to get the data of the forums + * @since 3.1-A1 + */ $vars = array('sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_build_query', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); -- cgit v1.2.1 From 14edfd2856b602ea435f5d473322950e23868b6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 14:12:12 +0200 Subject: [feature/php-events] Fix docs of core.display_forums_modify_row PHPBB3-9550 --- phpBB/includes/functions_display.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 7111153fd4..a022b9a807 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -137,8 +137,18 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod while ($row = $db->sql_fetchrow($result)) { - $vars = array('row'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_row_inject', compact($vars))); + /** + * Event to modify the data set of a forum + * + * This event is triggered once per forum + * + * @event core.display_forums_modify_row + * @var int branch_root_id Last top-level forum + * @var array row The data of the forum + * @since 3.1-A1 + */ + $vars = array('branch_root_id', 'row'); + extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars))); $forum_id = $row['forum_id']; -- cgit v1.2.1 From d4f9442e8749152d08ff50ca678b105d0ed2b703 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 15:34:53 +0200 Subject: [feature/php-events] Move core.display_forums_modify_forum_rows to better point PHPBB3-9550 --- phpBB/includes/functions_display.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index a022b9a807..3f37f227f6 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -246,9 +246,6 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; - - $vars = array('forum_rows', 'parent_id', 'row'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_row_values_inject', compact($vars))); } else if ($row['forum_type'] != FORUM_CAT) { @@ -286,6 +283,22 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id; } } + + /** + * Event to modify the forum rows data set + * + * This event is triggered once per forum + * + * @event core.display_forums_modify_forum_rows + * @var array forum_rows Data array of all forums we display + * @var array subforums Data array of all subforums we display + * @var int branch_root_id Current top-level forum + * @var int parent_id Current parent forum + * @var array row The data of the forum + * @since 3.1-A1 + */ + $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row'); + extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars))); } $db->sql_freeresult($result); -- cgit v1.2.1 From 8b7e3739a04bd3ea707493894fa2ebf8dc81410e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 15:47:42 +0200 Subject: [feature/php-events] Fix docs and naming of display_forums_modify_template_vars PHPBB3-9550 --- phpBB/includes/functions_display.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 3f37f227f6..448c261580 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -522,8 +522,18 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'U_LAST_POST' => $last_post_url, ); - $vars = array('row', 'forum_row'); - extract($phpbb_dispatcher->trigger_event('core.display_forums_assign_block_vars', compact($vars))); + /** + * Modify the template data block of the forum + * + * This event is triggered once per forum + * + * @event core.display_forums_modify_template_vars + * @var array forum_row Template data of the forum + * @var array row The data of the forum + * @since 3.1-A1 + */ + $vars = array('forum_row', 'row'); + extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars))); $template->assign_block_vars('forumrow', $forum_row); -- cgit v1.2.1 From 96f20160bcfa7a08870602b25fa528370f034128 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 16:00:19 +0200 Subject: [feature/php-events] Fix docs and naming of display_custom_bbcodes_modify_row PHPBB3-9550 --- phpBB/includes/functions_display.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 448c261580..807f5a2192 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -912,8 +912,18 @@ function display_custom_bbcodes() 'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']), ); + /** + * Modify the template data block of a bbcode + * + * This event is triggered once per bbcode + * + * @event core.display_custom_bbcodes_modify_row + * @var array custom_tags Template data of the bbcode + * @var array row The data of the bbcode + * @since 3.1-A1 + */ $vars = array('custom_tags', 'row'); - extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_row', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars))); $template->assign_block_vars('custom_tags', $custom_tags); -- cgit v1.2.1 From 4f13b049f813916e6393c8c4cc0227d3f52c2318 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 16:35:01 +0200 Subject: [feature/php-events] Fix docs of core.display_custom_bbcodes PHPBB3-9550 --- phpBB/includes/functions_display.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 807f5a2192..1e093e6811 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -931,6 +931,12 @@ function display_custom_bbcodes() } $db->sql_freeresult($result); + /** + * Display custom bbcodes + * + * @event core.display_custom_bbcodes + * @since 3.1-A1 + */ $phpbb_dispatcher->dispatch('core.display_custom_bbcodes'); } -- cgit v1.2.1 From 39869d46b1c4f3dcc178cdb7cd05e8f28fcc1f47 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 17:01:35 +0200 Subject: [feature/php-events] Allow core.user_get_avatar to overwrite all avatars PHPBB3-9550 --- phpBB/includes/functions_display.php | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 1e093e6811..bf379a40f4 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1327,17 +1327,33 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ global $user, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher; + $overwrite_avatar = ''; + + /** + * Overwrite users avatar + * + * @event core.display_custom_bbcodes_modify_row + * @var string avatar Users assigned avatar name + * @var int avatar_type Type of avatar + * @var string avatar_width Width of users avatar + * @var string avatar_height Height of users avatar + * @var string alt Language string for alt tag within image + * Can be a language key or text + * @var bool ignore_config Ignores config and force displaying avatar + * @var string overwrite_avatar If set, this string will be the avatar + * @since 3.1-A1 + */ + $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar'); + extract($phpbb_dispatcher->trigger_event('core.user_get_avatar', compact($vars))); + + if ($overwrite_avatar) + { + return $overwrite_avatar; + } + if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config)) { - $default_avatar = ''; - if ($config['allow_avatar'] || $ignore_config) - { - // This allows extensions to change the default return when no avatar is given - // Useful for default avatars - $vars = array('avatar', 'avatar_type', 'ignore_config', 'default_avatar'); - extract($phpbb_dispatcher->trigger_event('core.get_user_avatar_default', compact($vars))); - } - return $default_avatar; + return ''; } $avatar_img = ''; -- cgit v1.2.1 From d152c20e4b53f26bfcf9425f1efed9d9d4ccef9f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 1 Aug 2012 11:07:34 +0200 Subject: [feature/php-events] Add core.user_setup event This event can be used to load language files globally so it fixes PHPBB3-8270 PHPBB3-8270 PHPBB3-9550 --- phpBB/includes/user.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index fcbfaaddfa..93557f3558 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -76,18 +76,18 @@ class phpbb_user extends phpbb_session function setup($lang_set = false, $style_id = false) { global $db, $phpbb_style, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; + global $phpbb_dispatcher; if ($this->data['user_id'] != ANONYMOUS) { - $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); - - $this->date_format = $this->data['user_dateformat']; + $user_lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']); + $user_date_format = $this->data['user_dateformat']; $user_timezone = $this->data['user_timezone']; } else { - $this->lang_name = basename($config['default_lang']); - $this->date_format = $config['default_dateformat']; + $user_lang_name = basename($config['default_lang']); + $user_date_format = $config['default_dateformat']; $user_timezone = $config['board_timezone']; /** @@ -107,7 +107,7 @@ class phpbb_user extends phpbb_session if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx")) { - $this->lang_name = $config['default_lang'] = $accept_lang; + $user_lang_name = $config['default_lang'] = $accept_lang; break; } else @@ -118,7 +118,7 @@ class phpbb_user extends phpbb_session if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx")) { - $this->lang_name = $config['default_lang'] = $accept_lang; + $user_lang_name = $config['default_lang'] = $accept_lang; break; } } @@ -127,6 +127,28 @@ class phpbb_user extends phpbb_session */ } + $user_data = $this->data; + + /** + * Event to load language files and modify user data on every page + * + * @event core.user_setup + * @var array user_data Array with user's data row + * @var string user_lang_name Basename of the user's langauge + * @var string user_date_format User's date/time format + * @var string user_timezone User's timezone, should be one of + * http://www.php.net/manual/en/timezones.php + * @var mixed lang_set String or array of language files + * @var mixed style_id Style we are going to display + * @since 3.1-A1 + */ + $vars = array('user_data', 'user_lang_name', 'user_date_format', 'user_timezone', 'lang_set', 'style_id'); + extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars))); + + $this->data = $user_data; + $this->lang_name = $user_lang_name; + $this->date_format = $user_date_format; + try { $this->timezone = new DateTimeZone($user_timezone); -- cgit v1.2.1 From 6fbbb30a817a44fed1fb90ee35fca0d1caf83fcb Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 1 Aug 2012 22:18:12 +0530 Subject: [ticket/11032] add sphinx errors to error log PHPBB3-11032 --- phpBB/includes/search/fulltext_sphinx.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 8371f6b377..a2ebf1eb69 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -492,6 +492,11 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + if ($this->sphinx->GetLastError()) + { + add_log('critical', 'LOG_SPHINX_ERROR', $this->sphinx->GetLastError()); + } + // Could be connection to localhost:9312 failed (errno=111, // msg=Connection refused) during rotate, retry if so $retries = SPHINX_CONNECT_RETRIES; -- cgit v1.2.1 From 9358bf3de5fe402ccdc116e6b74e0cd2eee35e37 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 1 Aug 2012 22:23:51 +0530 Subject: [ticket/11032] use method GetLastError to get error Instead of using _error property, use method GetLastError to retrieve the error as sphinx API documentation states. PHPBB3-11032 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index a2ebf1eb69..90ceb29616 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -500,7 +500,7 @@ class phpbb_search_fulltext_sphinx // Could be connection to localhost:9312 failed (errno=111, // msg=Connection refused) during rotate, retry if so $retries = SPHINX_CONNECT_RETRIES; - while (!$result && (strpos($this->sphinx->_error, "errno=111,") !== false) && $retries--) + while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--) { usleep(SPHINX_CONNECT_WAIT_TIME); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); -- cgit v1.2.1 From a35ad4e689c204c52d23c07b701433325c27b0dc Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 2 Aug 2012 12:38:49 +0200 Subject: [ticket/11041] Correctly import PHP file extension from global space. 85bcdbad468cd255a02d6c48b2dcd1d128978eed shouldn't have changed imports of "global $phpEx". PHPBB3-11041 --- phpBB/includes/acp/acp_styles.php | 6 +++--- phpBB/includes/extension/controller.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index d41ef571dd..db77825ae7 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -40,7 +40,7 @@ class acp_styles public function main($id, $mode) { - global $db, $user, $phpbb_admin_path, $phpbb_root_path, $php_ext, $template, $request, $cache, $auth, $config; + global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; $this->db = $db; $this->user = $user; @@ -50,12 +50,12 @@ class acp_styles $this->auth = $auth; $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->php_ext = $phpEx; $this->default_style = $config['default_style']; $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/'; - $this->u_base_action = append_sid("{$phpbb_admin_path}index.$php_ext", "i={$id}"); + $this->u_base_action = append_sid("{$phpbb_admin_path}index.{$this->php_ext}", "i={$id}"); $this->s_hidden_fields = array( 'mode' => $mode, ); diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index ec051c756f..2b8c50aafb 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -64,14 +64,14 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ public function __construct() { global $request, $db, $user, $template, $config; - global $php_ext, $phpbb_root_path; + global $phpEx, $phpbb_root_path; $this->request = $request; $this->db = $db; $this->user = $user; $this->template = $template; $this->config = $config; - $this->php_ext = $php_ext; + $this->php_ext = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } } -- cgit v1.2.1 From ae612de663dbcd76074df4ea950a3a94745ca0ec Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 3 Aug 2012 12:34:07 +0200 Subject: [ticket/11043] Allow call_hook() to be called from more than one location. Allow the helper function call_hook() of class phpbb_template to be called from more than once location and thus for more than one hook (although there is only one) by adding the method name as a parameter. PHPBB3-11043 --- phpBB/includes/template/template.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 13fa845659..b7c3e00dee 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -139,7 +139,7 @@ class phpbb_template */ public function display($handle) { - $result = $this->call_hook($handle); + $result = $this->call_hook($handle, __FUNCTION__); if ($result !== false) { return $result[0]; @@ -174,16 +174,17 @@ class phpbb_template * Calls hook if any is defined. * * @param string $handle Template handle being displayed. + * @param string $method Method name of the caller. */ - private function call_hook($handle) + private function call_hook($handle, $method) { global $phpbb_hook; - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $this)) + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) { - if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) + if ($phpbb_hook->hook_return(array(__CLASS__, $method))) { - $result = $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__)); + $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); return array($result); } } -- cgit v1.2.1 From 0d182d9e9376a56b314b072c9d4395c18b900478 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:07:35 +0200 Subject: [feature/php-events] Fix naming and doc of core.generate_smilies_after PHPBB3-9550 --- phpBB/includes/functions_posting.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 0476c9b5d5..7ac56588af 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -123,6 +123,18 @@ function generate_smilies($mode, $forum_id) } } + /** + * This event is called when the smilies got populated + * + * @event core.generate_smilies_after + * @var string mode Mode of the smilies: window|inline + * @var int forum_id The forum ID we are currently in + * @var bool display_link Shall we display the "more smilies" link? + * @since 3.1-A1 + */ + $vars = array('mode', 'forum_id', 'display_link'); + extract($phpbb_dispatcher->trigger_event('core.generate_smilies_after', compact($vars))); + if ($mode == 'inline' && $display_link) { $template->assign_vars(array( @@ -131,9 +143,6 @@ function generate_smilies($mode, $forum_id) ); } - $vars = array('mode', 'forum_id', 'display_link'); - extract($phpbb_dispatcher->trigger_event('core.generate_smilies_footer', compact($vars))); - if ($mode == 'window') { page_footer(); -- cgit v1.2.1 From a9d4ed0cfcc58f3993bb09f230ad2b11482ddde8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:19:25 +0200 Subject: [feature/php-events] Fix naming and doc of core.mcp_view_forum_modify_topicrow PHPBB3-9550 --- phpBB/includes/mcp/mcp_forum.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 9b3c002968..7b3bc82093 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -288,8 +288,16 @@ function mcp_forum_view($id, $mode, $action, $forum_info) )); } - $vars = array('topic_row', 'row'); - extract($phpbb_dispatcher->trigger_event('core.mcp_forum_topicrow', compact($vars))); + /** + * Modify the topic data before it is assigned to the template in MCP + * + * @event core.mcp_view_forum_modify_topicrow + * @var array row Array with topic data + * @var array topic_row Template array with topic data + * @since 3.1-A1 + */ + $vars = array('row', 'topic_row'); + extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars))); $template->assign_block_vars('topicrow', $topic_row); } -- cgit v1.2.1 From 63a00efdd4eae8c3ad6a52c654107a83db5a2128 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:37:54 +0200 Subject: [feature/php-events] Fix naming and doc of core.ucp_pm_view_messsage PHPBB3-9550 --- phpBB/includes/ucp/ucp_pm_viewmessage.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index ba297b96dd..569232d878 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -204,7 +204,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) } } - $template->assign_vars(array( + $msg_data = array( 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), 'MESSAGE_AUTHOR' => get_username_string('username', $author_id, $user_info['username'], $user_info['user_colour'], $user_info['username']), @@ -265,11 +265,27 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'S_CUSTOM_FIELDS' => (!empty($cp_row['row'])) ? true : false, 'U_PRINT_PM' => ($config['print_pm'] && $auth->acl_get('u_pm_printpm')) ? "$url&f=$folder_id&p=" . $message_row['msg_id'] . "&view=print" : '', - 'U_FORWARD_PM' => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&mode=compose&action=forward&f=$folder_id&p=" . $message_row['msg_id'] : '') + 'U_FORWARD_PM' => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&mode=compose&action=forward&f=$folder_id&p=" . $message_row['msg_id'] : '', ); - $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row'); - extract($phpbb_dispatcher->trigger_event('core.ucp_pm_viewmesssage', compact($vars))); + /** + * Modify pm and sender data before it is assigned to the template + * + * @event core.ucp_pm_view_messsage + * @var mixed id Active module category (can be int or string) + * @var string mode Active module + * @var int folder_id ID of the folder the message is in + * @var int msg_id ID of the private message + * var array folder Array with data of user's message folders + * @var array message_row Array with message data + * @var array cp_row Array with senders custom profile field data + * @var array msg_data Template array with message data + * @since 3.1-A1 + */ + $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row', 'msg_data'); + extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_messsage', compact($vars))); + + $template->assign_vars($msg_data); // Display the custom profile fields if (!empty($cp_row['row'])) -- cgit v1.2.1 From a53ddec5a32dd208d52e12945490464ed2d363af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:44:46 +0200 Subject: [feature/php-events] Fix naming and doc of core.ucp_remove_zebra PHPBB3-9550 --- phpBB/includes/ucp/ucp_zebra.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index f153fd6aed..2e3bada7bc 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -54,12 +54,22 @@ class ucp_zebra // Remove users if (!empty($data['usernames'])) { - $vars = array('data'); - extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_remove', compact($vars))); + $user_ids = $data['usernames']; + + /** + * Remove users from friends/foes + * + * @event core.ucp_remove_zebra + * @var string mode Zebra type: friends|foes + * @var array user_ids User ids we remove + * @since 3.1-A1 + */ + $vars = array('user_ids'); + extract($phpbb_dispatcher->trigger_event('core.ucp_remove_zebra', compact($vars))); $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' - AND ' . $db->sql_in_set('zebra_id', $data['usernames']); + AND ' . $db->sql_in_set('zebra_id', $user_ids); $db->sql_query($sql); $updated = true; -- cgit v1.2.1 From 4eefba9b3f59618f78f338aa40a05f39ef8214e9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:50:16 +0200 Subject: [feature/php-events] Fix naming and doc of core.ucp_add_zebra PHPBB3-9550 --- phpBB/includes/ucp/ucp_zebra.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index 2e3bada7bc..a669c450a4 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -199,8 +199,18 @@ class ucp_zebra ); } + /** + * Add users to friends/foes + * + * @event core.ucp_add_zebra + * @var string mode Zebra type: + * friends|foes + * @var array sql_ary Array of + * entries we add + * @since 3.1-A1 + */ $vars = array('mode', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.ucp_zebra_add', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.ucp_add_zebra', compact($vars))); $db->sql_multi_insert(ZEBRA_TABLE, $sql_ary); -- cgit v1.2.1 From 70d9c02aae2ae357deb5ab415469fbbf965d0177 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 4 Aug 2012 16:50:03 +0100 Subject: [ticket/11044] Compress class now deals with file conflicts PHPBB3-11044 --- phpBB/includes/functions_compress.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 72d8eabe76..2d8ad84657 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -23,6 +23,11 @@ class compress { var $fp = 0; + /** + * @var array + */ + private $filelist = array(); + /** * Add file to archive */ @@ -122,6 +127,24 @@ class compress return true; } + /** + * Checks if a file by that name as already been added and, if it has, + * returns a new, unique name. + * + * @param string $name The filename + * @return string A unique string + */ + private function check_name($name) + { + if (isset($this->filelist[$name])) { + $this->filelist[$name]++; + return $name . '.' . $this->filelist[$name]; + } + + $this->filelist[$name] = 0; + return $name; + } + /** * Return available methods */ @@ -361,6 +384,7 @@ class compress_zip extends compress function data($name, $data, $is_dir = false, $stat) { $name = str_replace('\\', '/', $name); + $name = $this->check_name($name); $hexdtime = pack('V', $this->unix_to_dos_time($stat[9])); @@ -633,6 +657,7 @@ class compress_tar extends compress */ function data($name, $data, $is_dir = false, $stat) { + $name = $this->check_name($name); $this->wrote = true; $fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && @extension_loaded('zlib')) ? 'gzwrite' : 'fwrite'); -- cgit v1.2.1 From 3390712ed7097fb11d564fb6bd82d74c6b8e3731 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 5 Aug 2012 11:29:02 +0100 Subject: [ticket/11044] Minor adjustments as per PR comments Changed private to protected, renamed check_name to unique_filename. PHPBB3-11044 --- phpBB/includes/functions_compress.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 2d8ad84657..869ed21cea 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -26,7 +26,7 @@ class compress /** * @var array */ - private $filelist = array(); + protected $filelist = array(); /** * Add file to archive @@ -132,11 +132,12 @@ class compress * returns a new, unique name. * * @param string $name The filename - * @return string A unique string + * @return string A unique filename */ - private function check_name($name) + protected function unique_filename($name) { - if (isset($this->filelist[$name])) { + if (isset($this->filelist[$name])) + { $this->filelist[$name]++; return $name . '.' . $this->filelist[$name]; } @@ -384,7 +385,7 @@ class compress_zip extends compress function data($name, $data, $is_dir = false, $stat) { $name = str_replace('\\', '/', $name); - $name = $this->check_name($name); + $name = $this->unique_filename($name); $hexdtime = pack('V', $this->unix_to_dos_time($stat[9])); @@ -657,7 +658,7 @@ class compress_tar extends compress */ function data($name, $data, $is_dir = false, $stat) { - $name = $this->check_name($name); + $name = $this->unique_filename($name); $this->wrote = true; $fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && @extension_loaded('zlib')) ? 'gzwrite' : 'fwrite'); -- cgit v1.2.1 From 6571ea1fc8fa636cb418344f87cc7b010dd8f187 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 14:50:33 +0200 Subject: [feature/php-events] Remove event core.acp_profile_field_edit The currently implemented event is useless and we couldn't find a MOD, which requires editing this file in that position. PHPBB3-9550 --- phpBB/includes/acp/acp_profile.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index d84c4c2ed5..3ffffd3047 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -30,7 +30,6 @@ class acp_profile global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $request; - global $phpbb_dispatcher; include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); include($phpbb_root_path . 'includes/functions_user.' . $phpEx); @@ -877,9 +876,6 @@ class acp_profile } } - $vars = array('field_row', 'visibility_ary', 'exclude'); - extract($phpbb_dispatcher->trigger_event('core.acp_profile_field_edit', compact($vars))); - break; } -- cgit v1.2.1 From 5db76ee8b0e42cb9773f1b100c533af8ce666098 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 15:03:08 +0200 Subject: [feature/php-events] Move and fix event core.acp_users_display_overview The event had some invalid variables, so the event was moved to give it some more power. PHPBB3-9550 --- phpBB/includes/acp/acp_users.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index de1e9afc83..20d93ed525 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -946,12 +946,6 @@ class acp_users } } - $s_action_options = ''; - foreach ($quick_tool_ary as $value => $lang) - { - $s_action_options .= ''; - } - if ($config['load_onlinetrack']) { $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline @@ -966,6 +960,23 @@ class acp_users unset($row); } + /** + * Add additional quick tool options and overwrite user data + * + * @event core.acp_users_display_overview + * @var array user_row Array with user data + * @var array quick_tool_ary Ouick tool options + * @since 3.1-A1 + */ + $vars = array('user_row', 'quick_tool_ary'); + extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars))); + + $s_action_options = ''; + foreach ($quick_tool_ary as $value => $lang) + { + $s_action_options .= ''; + } + $last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit']; $inactive_reason = ''; @@ -1040,9 +1051,6 @@ class acp_users 'USER_INACTIVE_REASON' => $inactive_reason, )); - $vars = array('data', 'check_ary', 'sql_ary', 'user_row', 'quick_tool_ary'); - extract($phpbb_dispatcher->trigger_event('core.acp_users_overview', compact($vars))); - break; case 'feedback': -- cgit v1.2.1 From be61bcb7b559d5804f4e6f666e55bf37cd199cb2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 15:27:08 +0200 Subject: [feature/php-events] Add core.acp_users_overview_modify_data This event was split from core.acp_users_display_overview to make it work as expected. PHPBB3-9550 --- phpBB/includes/acp/acp_users.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 20d93ed525..ae345b99cf 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -856,6 +856,18 @@ class acp_users } } + /** + * Modify user data before we update it + * + * @event core.acp_users_overview_modify_data + * @var array user_row Current user data + * @var array data Submitted user data + * @var array sql_ary User data we udpate + * @since 3.1-A1 + */ + $vars = array('user_row', 'data', 'sql_ary'); + extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars))); + if ($update_username !== false) { $sql_ary['username'] = $update_username; -- cgit v1.2.1 From 171c07a0847f695a1c8e2f1f35784c453c47546a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 15:39:42 +0200 Subject: [feature/php-events] Add core.acp_users_overview_run_quicktool This event was split from core.acp_users_display_overview to make it work as expected. PHPBB3-9550 --- phpBB/includes/acp/acp_users.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index ae345b99cf..ceda41c764 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -750,6 +750,19 @@ class acp_users } break; + + default: + /** + * Run custom quicktool code + * + * @event core.acp_users_overview_run_quicktool + * @var array user_row Current user data + * @var string action Quick tool that should be run + * @since 3.1-A1 + */ + $vars = array('action', 'user_row'); + extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars))); + break; } // Handle registration info updates -- cgit v1.2.1 From 1f9b23e721008ca2903b9b4e79008867554eddf4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 16:42:46 +0200 Subject: [feature/php-events] Add docs for core.page_header PHPBB3-9550 --- phpBB/includes/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 442b125657..e39d5ee13e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4756,6 +4756,20 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // A listener can set this variable to `true` when it overrides this function $page_header_override = false; + /** + * Execute code and/or overwrite page_header() + * + * @event core.page_header + * @var string page_title Page title + * @var bool display_online_list Do we display online users list + * @var string item Restrict online users to a certain + * session item, e.g. forum for + * session_forum_id + * @var int item_id Restrict online users to item id + * @var bool page_header_override Shall we return instead of running + * the rest of page_header() + * @since 3.1-A1 + */ $vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override'); extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); -- cgit v1.2.1 From 997075a008b594f62306184aeb9105d5180fdd6d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 16:46:57 +0200 Subject: [feature/php-events] Add docs for core.page_footer PHPBB3-9550 --- phpBB/includes/functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e39d5ee13e..43bdb757e5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5080,12 +5080,20 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 function page_footer($run_cron = true) { global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx; - global $request; - global $phpbb_dispatcher; + global $request, $phpbb_dispatcher; // A listener can set this variable to `true` when it overrides this function $page_footer_override = false; + /** + * Execute code and/or overwrite page_footer() + * + * @event core.page_footer + * @var bool run_cron Shall we run cron tasks + * @var bool page_footer_override Shall we return instead of running + * the rest of page_footer() + * @since 3.1-A1 + */ $vars = array('run_cron', 'page_footer_override'); extract($phpbb_dispatcher->trigger_event('core.page_footer', compact($vars))); -- cgit v1.2.1 From e926ec9934348c1e2e556782edbb47630c58facc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 16:51:51 +0200 Subject: [feature/php-events] Add docs for core.garbage_collection PHPBB3-9550 --- phpBB/includes/functions.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 43bdb757e5..949b66072b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5187,6 +5187,12 @@ function garbage_collection() global $cache, $db; global $phpbb_dispatcher; + /** + * Unload some objects, to free some memory, before we finish our task + * + * @event core.garbage_collection + * @since 3.1-A1 + */ $phpbb_dispatcher->dispatch('core.garbage_collection'); // Unload cache, must be done before the DB connection if closed -- cgit v1.2.1 From 296ab5c168dfb324821c0ba965028be690745eb3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 21:17:29 +0200 Subject: [feature/php-events] Add docs for core.adm_page_header PHPBB3-9550 --- phpBB/includes/functions_acp.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index f59c8cd4c6..19f2873208 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -34,8 +34,18 @@ function adm_page_header($page_title) // A listener can set this variable to `true` when it overrides this function $adm_page_header_override = false; + /** + * Execute code and/or overwrite adm_page_header() + * + * @event core.adm_page_header + * @var string page_title Page title + * @var bool adm_page_header_override Shall we return instead of + * running the rest of adm_page_header() + * @since 3.1-A1 + */ $vars = array('page_title', 'adm_page_header_override'); extract($phpbb_dispatcher->trigger_event('core.adm_page_header', compact($vars))); + if ($adm_page_header_override) { return; -- cgit v1.2.1 From a326dc10cf2aa6f0ec631cbb23625831002da2ff Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 21:24:33 +0200 Subject: [feature/php-events] Add docs for core.adm_page_footer PHPBB3-9550 --- phpBB/includes/functions_acp.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 19f2873208..8ee506377d 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -117,12 +117,20 @@ function adm_page_footer($copyright_html = true) { global $db, $config, $template, $user, $auth, $cache; global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx; - global $request; - global $phpbb_dispatcher; + global $request, $phpbb_dispatcher; // A listener can set this variable to `true` when it overrides this function $adm_page_footer_override = false; + /** + * Execute code and/or overwrite adm_page_footer() + * + * @event core.adm_page_footer + * @var bool copyright_html Shall we display the copyright? + * @var bool adm_page_footer_override Shall we return instead of + * running the rest of adm_page_footer() + * @since 3.1-A1 + */ $vars = array('copyright_html', 'adm_page_footer_override'); extract($phpbb_dispatcher->trigger_event('core.adm_page_footer', compact($vars))); -- cgit v1.2.1 From 48a8482d23d7ab6fb0ef4c14f3d8464a78c14477 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 22:24:15 +0200 Subject: [feature/php-events] Fix docs and naming of core.build_config_template PHPBB3-9550 --- phpBB/includes/functions_acp.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 8ee506377d..23517f23aa 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -234,8 +234,7 @@ function h_radio($name, $input_ary, $input_default = false, $id = false, $key = */ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) { - global $user, $module; - global $phpbb_dispatcher; + global $user, $module, $phpbb_dispatcher; $tpl = ''; $name = 'config[' . $config_key . ']'; @@ -347,8 +346,23 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) $tpl .= $vars['append']; } - $vars = array('tpl_type', 'key', 'new', 'config_key', 'vars', 'tpl'); - extract($phpbb_dispatcher->trigger_event('core.build_cfg_template', compact($vars))); + /** + * Overwrite the html code we display for the config value + * + * @event core.build_config_template + * @var array tpl_type Config type array: + * 0 => data type + * 1 [optional] => string: size, int: minimum + * 2 [optional] => string: max. length, int: maximum + * @var string key Should be used for the id attribute in html + * @var array new Array with the config values we display + * @var string name Should be used for the name attribute + * @var array vars Array with the options for the config + * @var string tpl The resulting html code we display + * @since 3.1-A1 + */ + $vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl'); + extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars))); return $tpl; } -- cgit v1.2.1 From c28bd7cc609fecd6750ae0e7b4f1b4256f660818 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 23:09:44 +0200 Subject: [feature/php-events] Fix docs and naming of core.validate_config_variable PHPBB3-9550 --- phpBB/includes/functions_acp.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 23517f23aa..2f0188289b 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -373,8 +373,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) */ function validate_config_vars($config_vars, &$cfg_array, &$error) { - global $phpbb_root_path, $user; - global $phpbb_dispatcher; + global $phpbb_root_path, $user, $phpbb_dispatcher; $type = 0; $min = 1; @@ -552,8 +551,21 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) break; default: + /** + * Validate a config value + * + * @event core.validate_config_variable + * @var array cfg_array Array with config values + * @var string config_name Name of the config we validate + * @var array config_definition Array with the options for + * this config + * @var array error Array of errors, the errors should + * be strings only, language keys are + * not replaced afterwards + * @since 3.1-A1 + */ $vars = array('cfg_array', 'config_name', 'config_definition', 'error'); - extract($phpbb_dispatcher->trigger_event('core.validate_config_vars', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.validate_config_variable', compact($vars))); break; } } -- cgit v1.2.1 From 93912a2649eadae1e8cf0f3e24b0ddf7223316b3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 23:11:36 +0200 Subject: [feature/php-events] Remove double space in comments PHPBB3-9550 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 949b66072b..ecec1e5e4a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4757,7 +4757,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $page_header_override = false; /** - * Execute code and/or overwrite page_header() + * Execute code and/or overwrite page_header() * * @event core.page_header * @var string page_title Page title @@ -5086,7 +5086,7 @@ function page_footer($run_cron = true) $page_footer_override = false; /** - * Execute code and/or overwrite page_footer() + * Execute code and/or overwrite page_footer() * * @event core.page_footer * @var bool run_cron Shall we run cron tasks -- cgit v1.2.1 From 011b494bc55224e59872621ea09c0f69baed2744 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 5 Aug 2012 22:11:14 +0100 Subject: [ticket/11044] Preserve the file extension in unique filenames PHPBB3-11044 --- phpBB/includes/functions_compress.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 869ed21cea..80c0242517 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -138,8 +138,16 @@ class compress { if (isset($this->filelist[$name])) { + $start = $name; + $ext = ''; $this->filelist[$name]++; - return $name . '.' . $this->filelist[$name]; + + if (($pos = strrpos($name, '.')) !== false) { + $start = substr($name, 0, $pos); + $ext = substr($name, $pos); + } + + return $start . '_' . $this->filelist[$name] . $ext; } $this->filelist[$name] = 0; -- cgit v1.2.1 From ecb310c6f7a2f8aa5c1f2217d7de6cb878aa85f4 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 6 Aug 2012 08:32:12 +0800 Subject: [ticket/11044] Added comment explaining filename splitting PHPBB3-11044 --- phpBB/includes/functions_compress.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 80c0242517..8e07e6d1b8 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -142,7 +142,10 @@ class compress $ext = ''; $this->filelist[$name]++; - if (($pos = strrpos($name, '.')) !== false) { + // Separate the extension off the end of the filename to preserve it + $pos = strrpos($name, '.'); + if ($pos !== false) + { $start = substr($name, 0, $pos); $ext = substr($name, $pos); } -- cgit v1.2.1 From 907f1771f9594ee1906c5b0ad7fac765f2a1995d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 15:05:06 -0500 Subject: [ticket/11029] Return $parsed_array (may have loaded from the cache) Even if the file does not exist, it may be in the cache, so return $parsed_array just in case PHPBB3-11029 --- phpBB/includes/cache/service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php index 5946241825..b29af3c531 100644 --- a/phpBB/includes/cache/service.php +++ b/phpBB/includes/cache/service.php @@ -337,7 +337,7 @@ class phpbb_cache_service if (!file_exists($filename)) { - return array(); + return $parsed_array; } if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) -- cgit v1.2.1 From 1b126908c633fa793cf7f3fba1e88139bb599938 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 15:10:20 -0500 Subject: [ticket/11029] Remove $reparse variable Its only set to false, then true in one case, and only checked once. So remove it because it is unnecessary. PHPBB3-11029 --- phpBB/includes/cache/service.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php index b29af3c531..e63ec6e33a 100644 --- a/phpBB/includes/cache/service.php +++ b/phpBB/includes/cache/service.php @@ -332,7 +332,6 @@ class phpbb_cache_service $parsed_array = array(); } - $reparse = false; $filename = $phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg'; if (!file_exists($filename)) @@ -342,17 +341,13 @@ class phpbb_cache_service if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) { - $reparse = true; - } - - // Re-parse cfg file - if ($reparse) - { + // Re-parse cfg file $parsed_array = parse_cfg_file($filename); $parsed_array['filetime'] = @filemtime($filename); $this->driver->put('_cfg_' . $style['style_path'], $parsed_array); } + return $parsed_array; } -- cgit v1.2.1 From a2dd99b75e308448c309ce4db807ea0091245443 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 14:54:06 -0500 Subject: [ticket/10885] Fix UCP Main Error if no forums exist This error is caused by an empty set passed to sql_in_set if the user cannot read any forums PHPBB3-10885 --- phpBB/includes/ucp/ucp_main.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php index f21ea2471b..94fd59433b 100644 --- a/phpBB/includes/ucp/ucp_main.php +++ b/phpBB/includes/ucp/ucp_main.php @@ -69,17 +69,16 @@ class ucp_main // Get cleaned up list... return only those forums having the f_read permission $forum_ary = $auth->acl_getf('f_read', true); $forum_ary = array_unique(array_keys($forum_ary)); - - $sql = "SELECT t.* $sql_select - FROM $sql_from - WHERE t.topic_type = " . POST_GLOBAL . ' - AND ' . $db->sql_in_set('t.forum_id', $forum_ary) . ' - ORDER BY t.topic_last_post_time DESC'; - $topic_list = $rowset = array(); + // If the user can't see any forums, he can't read any posts because fid of 0 is invalid if (!empty($forum_ary)) { + $sql = "SELECT t.* $sql_select + FROM $sql_from + WHERE t.topic_type = " . POST_GLOBAL . ' + AND ' . $db->sql_in_set('t.forum_id', $forum_ary) . ' + ORDER BY t.topic_last_post_time DESC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -671,7 +670,7 @@ class ucp_main if ($topics_count) { phpbb_generate_template_pagination($template, $this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'PAGE_NUMBER' => phpbb_on_page($template, $user, $this->u_action, $topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count), @@ -837,7 +836,7 @@ class ucp_main 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id), )); - + phpbb_generate_template_pagination($template, append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . "&t=$topic_id"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true); } } -- cgit v1.2.1 From dcefa16318f6dc1058595a7ba221b75ed6a2504b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 16:26:55 -0500 Subject: [ticket/10875] Return $query_id from sql_save Have to return the $query_id from sql_save so that the results can be pulled Updated cache test to do some basic sql cache testing. PHPBB3-10875 --- phpBB/includes/cache/driver/file.php | 2 ++ phpBB/includes/cache/driver/memory.php | 2 ++ phpBB/includes/db/firebird.php | 2 +- phpBB/includes/db/mssql.php | 2 +- phpBB/includes/db/mssql_odbc.php | 2 +- phpBB/includes/db/mssqlnative.php | 2 +- phpBB/includes/db/mysql.php | 2 +- phpBB/includes/db/mysqli.php | 2 +- phpBB/includes/db/oracle.php | 2 +- phpBB/includes/db/postgres.php | 2 +- phpBB/includes/db/sqlite.php | 2 +- 11 files changed, 13 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index da942b921c..f64a9e3ea8 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -385,6 +385,8 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base { $query_result = $query_id; } + + return $query_id; } /** diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index aabad2bb6c..92971c6cb2 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -335,6 +335,8 @@ class phpbb_cache_driver_memory extends phpbb_cache_driver_base $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); $query_result = $query_id; + + return $query_id; } /** diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 99deb5603e..9f9b8a1abd 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -272,7 +272,7 @@ class dbal_firebird extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index d92fe27b99..bde283c3ea 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -162,7 +162,7 @@ class dbal_mssql extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 6292792a55..687bc52abc 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -181,7 +181,7 @@ class dbal_mssql_odbc extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 0d8786171a..36ff461a29 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -338,7 +338,7 @@ class dbal_mssqlnative extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index fd567af076..5b4ff86579 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -190,7 +190,7 @@ class dbal_mysql extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 26cade2ff0..1f13bd5459 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -196,7 +196,7 @@ class dbal_mysqli extends dbal if ($cache_ttl) { - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } } else if (defined('DEBUG_EXTRA')) diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index e9ff2f4434..de2729e973 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -421,7 +421,7 @@ class dbal_oracle extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index c35199e917..f0a4a7a7a2 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -218,7 +218,7 @@ class dbal_postgres extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 814b593f05..2cf55b07e2 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -135,7 +135,7 @@ class dbal_sqlite extends dbal if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { -- cgit v1.2.1 From 794d6ec443bd16ad2f7776d1ba2abcf2ce1c5553 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 8 Aug 2012 11:07:47 +0530 Subject: [ticket/11011] pass $auth to search backend constructor $auth global var is passed to search backend constructor, as it is used by sphinx backend. PHPBB3-11011 --- phpBB/includes/acp/acp_search.php | 4 ++-- phpBB/includes/search/fulltext_mysql.php | 2 +- phpBB/includes/search/fulltext_native.php | 2 +- phpBB/includes/search/fulltext_postgres.php | 2 +- phpBB/includes/search/fulltext_sphinx.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 5ae9f363f0..6618e2c3f9 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -596,7 +596,7 @@ class acp_search */ function init_search($type, &$search, &$error) { - global $phpbb_root_path, $phpEx, $user, $config, $db; + global $phpbb_root_path, $phpEx, $user, $auth, $config, $db; if (!class_exists($type) || !method_exists($type, 'keyword_search')) { @@ -605,7 +605,7 @@ class acp_search } $error = false; - $search = new $type($error, $phpbb_root_path, $phpEx, $config, $db, $user); + $search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); return $error; } diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index ccf9f49612..8320b8e760 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -37,7 +37,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->config = $config; $this->db = $db; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index a470a92458..b5f1a4f52f 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -42,7 +42,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure. */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 75cb48ecc6..0e6f72f142 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -41,7 +41,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->config = $config; $this->db = $db; diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 0662b70a2b..d4ded8efc0 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -51,7 +51,7 @@ class phpbb_search_fulltext_sphinx * * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false */ - public function __construct(&$error, $phpbb_root_path, $phpEx, $config, $db, $user) + public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; -- cgit v1.2.1 From a422ddfe31af469123f3fa830a3ae313dc9e8ec7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 8 Aug 2012 11:16:46 +0530 Subject: [ticket/11011] rename property phpEx to php_ext PHPBB3-11011 --- phpBB/includes/search/fulltext_native.php | 8 ++++---- phpBB/includes/search/fulltext_sphinx.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index b5f1a4f52f..ea9d050b60 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -32,7 +32,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base var $must_exclude_one_ids = array(); private $phpbb_root_path; - private $phpEx; + private $php_ext; private $config; private $db; private $user; @@ -45,7 +45,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $phpEx; $this->config = $config; $this->db = $db; $this->user = $user; @@ -57,7 +57,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base */ if (!class_exists('utf_normalizer')) { - include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->php_ext); } $error = false; @@ -1669,7 +1669,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base if (!isset($conv_loaded[$idx])) { $conv_loaded[$idx] = 1; - $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->phpEx; + $file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->php_ext; if (file_exists($file)) { diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index d4ded8efc0..d10d5d4942 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -34,7 +34,7 @@ class phpbb_search_fulltext_sphinx private $indexes; private $sphinx; private $phpbb_root_path; - private $phpEx; + private $php_ext; private $auth; private $config; private $db; @@ -54,7 +54,7 @@ class phpbb_search_fulltext_sphinx public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user) { $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $phpEx; $this->config = $config; $this->user = $user; $this->db = $db; @@ -62,7 +62,7 @@ class phpbb_search_fulltext_sphinx if (!class_exists('phpbb_db_tools')) { - require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->phpEx); + require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->php_ext); } // Initialize phpbb_db_tools object @@ -77,7 +77,7 @@ class phpbb_search_fulltext_sphinx if (!class_exists('SphinxClient')) { - require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->phpEx); + require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->php_ext); } // Initialize sphinx client @@ -151,7 +151,7 @@ class phpbb_search_fulltext_sphinx return false; } - include($this->phpbb_root_path . 'config.' . $this->phpEx); + include($this->phpbb_root_path . 'config.' . $this->php_ext); /* Now that we're sure everything was entered correctly, generate a config for the index. We use a config value -- cgit v1.2.1 From e3a9bf0376a9e4d6e9f5730e5118d11ce75296bd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Aug 2012 17:43:46 +0200 Subject: [feature/php-events] Fix doc and naming of core.acp_forums_request_forum_data PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 6631edf438..564181be9e 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -150,8 +150,16 @@ class acp_forums 'forum_password_unset' => request_var('forum_password_unset', false), ); + /** + * Request forum data and operate on it (parse texts, etc.) + * + * @event core.acp_manage_forums_request_data + * @var string action Type of the action: add|edit + * @var array forum_data Array with new forum data + * @since 3.1-A1 + */ $vars = array('action', 'forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_request_forum_data', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_request_data', compact($vars))); // On add, add empty forum_options... else do not consider it (not updating it) if ($action == 'add') -- cgit v1.2.1 From 38ba09e707c1fd97fe79d6b8165e1315346cbfef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 12:01:09 +0200 Subject: [feature/php-events] Fix naming and doc of acp_manage_forums_initialise_data PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 564181be9e..54085d856b 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -397,6 +397,9 @@ class acp_forums $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0; } + // Initialise $row, so we always have it in the event + $row = array(); + // Show form to create/modify a forum if ($action == 'edit') { @@ -424,9 +427,6 @@ class acp_forums $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false); $forum_data['forum_password_confirm'] = $forum_data['forum_password']; - - $vars = array('forum_id', 'row', 'forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_modify_forum_data', compact($vars))); } else { @@ -464,12 +464,27 @@ class acp_forums 'forum_password' => '', 'forum_password_confirm'=> '', ); - - $vars = array('forum_id', 'forum_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_init_forum_data', compact($vars))); } } + /** + * Initialise data before we display the add/edit form + * + * @event core.acp_manage_forums_initialise_data + * @var string action Type of the action: add|edit + * @var bool update Do we display the form only + * or did the user press submit + * @var int forum_id When editing: the forum id, + * when creating: the parent forum id + * @var array row Array with current forum data + * empty when creating new forum + * @var array forum_data Array with new forum data + * @var string parents_list List of parent options + * @since 3.1-A1 + */ + $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list'); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_initialise_data', compact($vars))); + $forum_rules_data = array( 'text' => $forum_data['forum_rules'], 'allow_bbcode' => true, -- cgit v1.2.1 From 3beda0cbabe704b661e3d810db4c62a8d28a6bd6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 12:44:28 +0200 Subject: [feature/php-events] Fix naming and doc of core.acp_manage_forums_display_form PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 54085d856b..c9225744bf 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -681,8 +681,27 @@ class acp_forums 'S_CAN_COPY_PERMISSIONS' => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false, ); - $vars = array('forum_id', 'action', 'forum_data', 'template_data', 'old_forum_type', 'forum_desc_data', 'forum_rules_data'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_assign_template_forum_data', compact($vars))); + /** + * Modify forum template data before we display the form + * + * @event core.acp_manage_forums_display_form + * @var string action Type of the action: add|edit + * @var bool update Do we display the form only + * or did the user press submit + * @var int forum_id When editing: the forum id, + * when creating: the parent forum id + * @var array row Array with current forum data + * empty when creating new forum + * @var array forum_data Array with new forum data + * @var string parents_list List of parent options + * @var array errors Array of errors, if you add errors + * ensure to update the template variables + * S_ERROR and ERROR_MSG to display it + * @var array template_data Array with new forum data + * @since 3.1-A1 + */ + $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list', 'errors', 'template_data'); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_display_form', compact($vars))); $template->assign_vars($template_data); -- cgit v1.2.1 From caf76b4cebccbfd7e348c89f7bce8d731fa2fd43 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 12:50:47 +0200 Subject: [feature/php-events] Fix naming and doc of core.acp_manage_forums_validate_data PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index c9225744bf..7af2fb822e 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -932,8 +932,17 @@ class acp_forums $errors = array(); + /** + * Validate the forum data before we create/update the forum + * + * @event core.acp_manage_forums_validate_data + * @var array forum_data Array with new forum data + * @var array errors Array of errors, should be strings and not + * language key. + * @since 3.1-A1 + */ $vars = array('forum_data', 'errors'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_update_forum_data', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_validate_data', compact($vars))); if ($forum_data['forum_name'] == '') { -- cgit v1.2.1 From cfd5fcbe2609024f57c900435b02346d5c7e28e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 12:58:20 +0200 Subject: [feature/php-events] Add new event core.acp_manage_forums_update_data_before Allows you to remove data from forum_data_sql before we update/create the forum PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 7af2fb822e..151e03f18f 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1036,7 +1036,25 @@ class acp_forums } unset($forum_data_sql['forum_password_unset']); - if (!isset($forum_data_sql['forum_id'])) + $is_new_forum = !isset($forum_data_sql['forum_id']); + + /** + * Remove invalid values from forum_data_sql that should not be updated + * + * @event core.acp_manage_forums_update_data_before + * @var array forum_data Array with forum data + * @var array forum_data_sql Array with data we are going to update + * @var bool is_new_forum Do we create a forum or update one + * If you want to overwrite this value, + * ensure to set forum_data_sql[forum_id] + * @since 3.1-A1 + */ + $vars = array('forum_data', 'forum_data_sql'); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_before', compact($vars))); + + $is_new_forum = !isset($forum_data_sql['forum_id']); + + if ($is_new_forum) { // no forum_id means we're creating a new forum unset($forum_data_sql['type_action']); -- cgit v1.2.1 From 70c90bea4f8ba6cc0c4f34f2f55f8171f1b7ba87 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 13:06:20 +0200 Subject: [feature/php-events] Fix doc and naming of acp_manage_forums_update_data_after PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 151e03f18f..542c3ffd77 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1325,8 +1325,21 @@ class acp_forums add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']); } - $vars = array('forum_data', 'errors'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_update_forum_data_after', compact($vars))); + /** + * Event after a forum was updated or created + * + * @event core.acp_manage_forums_update_data_after + * @var array forum_data Array with forum data + * @var array forum_data_sql Array with data we updated + * @var bool is_new_forum Did we create a forum or update one + * If you want to overwrite this value, + * ensure to set forum_data_sql[forum_id] + * @var array errors Array of errors, should be strings and not + * language key. + * @since 3.1-A1 + */ + $vars = array('forum_data', 'forum_data_sql' 'is_new_forum', 'errors'); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars))); return $errors; } -- cgit v1.2.1 From 43d17b2337eefa0530dea57516138eaf9724862b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 13:16:18 +0200 Subject: [feature/php-events] Fix doc and naming of core.acp_manage_forums_move_children PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 542c3ffd77..d6d8879f7b 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1353,9 +1353,6 @@ class acp_forums $to_data = $moved_ids = $errors = array(); - $vars = array('from_id', 'to_id'); - extract($phpbb_dispatcher->trigger_event('core.acp_forums_move_forum', compact($vars))); - // Check if we want to move to a parent with link type if ($to_id > 0) { @@ -1364,10 +1361,30 @@ class acp_forums if ($to_data['forum_type'] == FORUM_LINK) { $errors[] = $user->lang['PARENT_IS_LINK_FORUM']; - return $errors; } } + /** + * Event when we move all children of one forum to another + * + * This event may be triggered, when a forum is deleted + * + * @event core.acp_manage_forums_move_children + * @var int from_id If of the current parent forum + * @var int to_id If of the new parent forum + * @var array errors Array of errors, should be strings and not + * language key. + * @since 3.1-A1 + */ + $vars = array('from_id', 'to_id', 'errors'); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_children', compact($vars))); + + // Return if there were errors + if (!empty($errors)) + { + return $errors; + } + $moved_forums = get_forum_branch($from_id, 'children', 'descending'); $from_data = $moved_forums[0]; $diff = sizeof($moved_forums) * 2; -- cgit v1.2.1 From cdcadf72c4d613e262a06589e7dfe4c81803344c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Aug 2012 13:20:34 +0200 Subject: [feature/php-events] Add event core.acp_manage_forums_move_content PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index d6d8879f7b..6fb246458c 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1464,7 +1464,30 @@ class acp_forums */ function move_forum_content($from_id, $to_id, $sync = true) { - global $db; + global $db, $phpbb_dispatcher; + + $errors = array(); + + /** + * Event when we move content from one forum to another + * + * @event core.acp_manage_forums_move_children + * @var int from_id If of the current parent forum + * @var int to_id If of the new parent forum + * @var bool sync Shall we sync the "to"-forum's data + * @var array errors Array of errors, should be strings and not + * language key. If this array is not empty, + * The content will not be moved. + * @since 3.1-A1 + */ + $vars = array('from_id', 'to_id', 'sync', 'errors'); + extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_content', compact($vars))); + + // Return if there were errors + if (!empty($errors)) + { + return $errors; + } $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); -- cgit v1.2.1 From 698b7999c4dd389c7d0e970f72e4a594fc99dd5a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 10:46:32 +0530 Subject: [ticket/11032] trigger error in case search fails Admins are shown actual error while users are shown a search failed error in case sphinx search fails. PHPBB3-11032 --- phpBB/includes/search/fulltext_sphinx.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 5f4a0deaa0..fa7bd01f39 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -495,6 +495,14 @@ class phpbb_search_fulltext_sphinx if ($this->sphinx->GetLastError()) { add_log('critical', 'LOG_SPHINX_ERROR', $this->sphinx->GetLastError()); + if ($this->auth->acl_get('a_')) + { + trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError())); + } + else + { + trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->user->lang('SPHINX_SEARCH_ERROR_LOG'))); + } } // Could be connection to localhost:9312 failed (errno=111, -- cgit v1.2.1 From b2e166dbfaab846a1aba82b4439999e98a003f82 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 11:30:02 +0530 Subject: [ticket/11048] add access specifiers to pgsql search PHPBB3-11048 --- phpBB/includes/search/fulltext_postgres.php | 60 +++++++---------------------- 1 file changed, 14 insertions(+), 46 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 0e6f72f142..d897c73745 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -66,8 +66,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * Returns the name of this search backend to be displayed to administrators * * @return string Name - * - * @access public */ public function get_name() { @@ -78,8 +76,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * Returns if phrase search is supported or not * * @return bool - * - * @access public */ public function supports_phrase_search() { @@ -90,10 +86,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * Checks for correct PostgreSQL version and stores min/max word length in the config * * @return string|bool Language key of the error/incompatiblity occured - * - * @access public */ - function init() + public function init() { if ($this->db->sql_layer != 'postgres') { @@ -115,10 +109,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param string &$keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return bool false if no valid keywords were found and otherwise true - * - * @access public */ - function split_keywords(&$keywords, $terms) + public function split_keywords(&$keywords, $terms) { if ($terms == 'all') { @@ -208,10 +200,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Turns text into an array of words * @param string $text contains post text/subject - * - * @access public */ - function split_message($text) + public function split_message($text) { // Split words $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); @@ -252,10 +242,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ - function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (!$this->search_query) @@ -438,10 +426,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ - function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No author? No posts. if (!sizeof($author_ary)) @@ -594,10 +580,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param string $subject contains the subject of the post to index * @param int $poster_id contains the user id of the poster * @param int $forum_id contains the forum id of parent forum of the post - * - * @access public */ - function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { // Split old and new post/subject to obtain array of words $split_text = $this->split_message($message); @@ -616,20 +600,16 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Destroy cached results, that might be outdated after deleting a post - * - * @access public */ - function index_remove($post_ids, $author_ids, $forum_ids) + public function index_remove($post_ids, $author_ids, $forum_ids) { $this->destroy_cache(array(), $author_ids); } /** * Destroy old cache entries - * - * @access public */ - function tidy() + public function tidy() { // destroy too old cached search results $this->destroy_cache(array()); @@ -641,10 +621,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * Create fulltext index * * @return string|bool error string is returned incase of errors otherwise false - * - * @access public */ - function create_index($acp_module, $u_action) + public function create_index($acp_module, $u_action) { // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) @@ -676,10 +654,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * Drop fulltext index * * @return string|bool error string is returned incase of errors otherwise false - * - * @access public */ - function delete_index($acp_module, $u_action) + public function delete_index($acp_module, $u_action) { // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) @@ -709,10 +685,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Returns true if both FULLTEXT indexes exist - * - * @access public */ - function index_created() + public function index_created() { if (empty($this->stats)) { @@ -724,10 +698,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Returns an associative array containing information about the indexes - * - * @access public */ - function index_stats() + public function index_stats() { if (empty($this->stats)) { @@ -741,10 +713,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Computes the stats and store them in the $this->stats associative array - * - * @access private */ - function get_stats() + private function get_stats() { if ($this->db->sql_layer != 'postgres') { @@ -784,10 +754,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * Display various options that can be configured for the backend from the acp * * @return associative array containing template and config variables - * - * @access public */ - function acp() + public function acp() { $tpl = '
-- cgit v1.2.1 From de8b7c0b7d07859b1110e32024209faadca64a6b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 11:35:50 +0530 Subject: [ticket/11048] add access specifiers to mysql search PHPBB3-11048 --- phpBB/includes/search/fulltext_mysql.php | 58 ++++++++------------------------ 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 8320b8e760..8684258982 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -52,8 +52,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Returns the name of this search backend to be displayed to administrators * * @return string Name - * - * @access public */ public function get_name() { @@ -64,10 +62,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Checks for correct MySQL version and stores min/max word length in the config * * @return string|bool Language key of the error/incompatiblity occured - * - * @access public */ - function init() + public function init() { if ($this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli') { @@ -117,10 +113,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string &$keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return bool false if no valid keywords were found and otherwise true - * - * @access public */ - function split_keywords(&$keywords, $terms) + public function split_keywords(&$keywords, $terms) { if ($terms == 'all') { @@ -237,10 +231,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Turns text into an array of words * @param string $text contains post text/subject - * - * @access public */ - function split_message($text) + public function split_message($text) { // Split words $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text))); @@ -281,10 +273,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ - function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (!$this->search_query) @@ -463,10 +453,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ - function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No author? No posts. if (!sizeof($author_ary)) @@ -625,10 +613,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param string $subject contains the subject of the post to index * @param int $poster_id contains the user id of the poster * @param int $forum_id contains the forum id of parent forum of the post - * - * @access public */ - function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { // Split old and new post/subject to obtain array of words $split_text = $this->split_message($message); @@ -647,20 +633,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Destroy cached results, that might be outdated after deleting a post - * - * @access public */ - function index_remove($post_ids, $author_ids, $forum_ids) + public function index_remove($post_ids, $author_ids, $forum_ids) { $this->destroy_cache(array(), array_unique($author_ids)); } /** * Destroy old cache entries - * - * @access public */ - function tidy() + public function tidy() { // destroy too old cached search results $this->destroy_cache(array()); @@ -672,10 +654,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Create fulltext index * * @return string|bool error string is returned incase of errors otherwise false - * - * @access public */ - function create_index($acp_module, $u_action) + public function create_index($acp_module, $u_action) { // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) @@ -735,10 +715,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Drop fulltext index * * @return string|bool error string is returned incase of errors otherwise false - * - * @access public */ - function delete_index($acp_module, $u_action) + public function delete_index($acp_module, $u_action) { // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) @@ -780,10 +758,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Returns true if both FULLTEXT indexes exist - * - * @access public */ - function index_created() + public function index_created() { if (empty($this->stats)) { @@ -795,10 +771,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Returns an associative array containing information about the indexes - * - * @access public */ - function index_stats() + public function index_stats() { if (empty($this->stats)) { @@ -812,10 +786,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Computes the stats and store them in the $this->stats associative array - * - * @access private */ - function get_stats() + private function get_stats() { if (strpos($this->db->sql_layer, 'mysql') === false) { @@ -857,10 +829,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * Display a note, that UTF-8 support is not available with certain versions of PHP * * @return associative array containing template and config variables - * - * @access public */ - function acp() + public function acp() { $tpl = '
-- cgit v1.2.1 From dd56c401af495655fe729e3d5919623114812f1a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 12:23:25 +0530 Subject: [ticket/11048] add access specifiers to phpbb native search PHPBB3-11048 --- phpBB/includes/search/fulltext_native.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index ea9d050b60..478b1f2c82 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -90,7 +90,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @access public */ - function split_keywords($keywords, $terms) + public function split_keywords($keywords, $terms) { $tokens = '+-|()*'; @@ -427,7 +427,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @access public */ - function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (empty($this->search_query)) @@ -823,7 +823,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @access public */ - function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No author? No posts. if (!sizeof($author_ary)) @@ -1048,7 +1048,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @access private */ - function split_message($text) + public function split_message($text) { $match = $words = array(); @@ -1125,7 +1125,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @access public */ - function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { if (!$this->config['fulltext_native_load_upd']) { @@ -1282,7 +1282,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base /** * Removes entries from the wordmatch table for the specified post_ids */ - function index_remove($post_ids, $author_ids, $forum_ids) + public function index_remove($post_ids, $author_ids, $forum_ids) { if (sizeof($post_ids)) { @@ -1340,7 +1340,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * Tidy up indexes: Tag 'common words' and remove * words no longer referenced in the match table */ - function tidy() + public function tidy() { // Is the fulltext indexer disabled? If yes then we need not // carry on ... it's okay ... I know when I'm not wanted boo hoo @@ -1403,7 +1403,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base /** * Deletes all words from the index */ - function delete_index($acp_module, $u_action) + public function delete_index($acp_module, $u_action) { switch ($this->db->sql_layer) { @@ -1425,7 +1425,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base /** * Returns true if both FULLTEXT indexes exist */ - function index_created() + public function index_created() { if (!sizeof($this->stats)) { @@ -1438,7 +1438,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base /** * Returns an associative array containing information about the indexes */ - function index_stats() + public function index_stats() { if (!sizeof($this->stats)) { @@ -1450,7 +1450,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); } - function get_stats() + private function get_stats() { $this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); $this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); @@ -1471,7 +1471,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @todo normalizer::cleanup being able to be used? */ - function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') + private function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') { static $conv = array(), $conv_loaded = array(); $words = $allow = array(); @@ -1700,7 +1700,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base /** * Returns a list of options for the ACP to display */ - function acp() + public function acp() { /** * if we need any options, copied from fulltext_native for now, will have to be adjusted or removed -- cgit v1.2.1 From 42d6e0715feacd4bea4cdfc31272546c414df6ef Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 14:06:25 +0530 Subject: [ticket/11048] add access specifiers to sphinx search PHPBB3-11048 --- phpBB/includes/search/fulltext_sphinx.php | 58 ++++++++----------------------- 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 5f4a0deaa0..9b98bf038b 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -92,8 +92,6 @@ class phpbb_search_fulltext_sphinx * Returns the name of this search backend to be displayed to administrators * * @return string Name - * - * @access public */ public function get_name() { @@ -104,10 +102,8 @@ class phpbb_search_fulltext_sphinx * Checks permissions and paths, if everything is correct it generates the config file * * @return string|bool Language key of the error/incompatiblity encountered, or false if successful - * - * @access public */ - function init() + public function init() { if ($this->db->sql_layer != 'mysql' && $this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli' && $this->db->sql_layer != 'postgres') { @@ -124,10 +120,8 @@ class phpbb_search_fulltext_sphinx * Generates content of sphinx.conf * * @return bool True if sphinx.conf content is correctly generated, false otherwise - * - * @access private */ - function config_generate() + private function config_generate() { // Check if Database is supported by Sphinx if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli') @@ -306,10 +300,8 @@ class phpbb_search_fulltext_sphinx * @param string $keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return false if no valid keywords were found and otherwise true - * - * @access public */ - function split_keywords(&$keywords, $terms) + public function split_keywords(&$keywords, $terms) { if ($terms == 'all') { @@ -356,10 +348,8 @@ class phpbb_search_fulltext_sphinx * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ - function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { // No keywords? No posts. if (!strlen($this->search_query) && !sizeof($author_ary)) @@ -551,10 +541,8 @@ class phpbb_search_fulltext_sphinx * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ - function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { $this->search_query = ''; @@ -573,10 +561,8 @@ class phpbb_search_fulltext_sphinx * @param string &$subject New or updated post subject * @param int $poster_id Post author's user id * @param int $forum_id The id of the forum in which the post is located - * - * @access public */ - function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) + public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { if ($mode == 'edit') { @@ -618,10 +604,8 @@ class phpbb_search_fulltext_sphinx /** * Delete a post from the index after it was deleted - * - * @access public */ - function index_remove($post_ids, $author_ids, $forum_ids) + public function index_remove($post_ids, $author_ids, $forum_ids) { $values = array(); foreach ($post_ids as $post_id) @@ -634,10 +618,8 @@ class phpbb_search_fulltext_sphinx /** * Nothing needs to be destroyed - * - * @access public */ - function tidy($create = false) + public function tidy($create = false) { set_config('search_last_gc', time(), true); } @@ -646,10 +628,8 @@ class phpbb_search_fulltext_sphinx * Create sphinx table * * @return string|bool error string is returned incase of errors otherwise false - * - * @access public */ - function create_index($acp_module, $u_action) + public function create_index($acp_module, $u_action) { if (!$this->index_created()) { @@ -680,10 +660,8 @@ class phpbb_search_fulltext_sphinx * Drop sphinx table * * @return string|bool error string is returned incase of errors otherwise false - * - * @access public */ - function delete_index($acp_module, $u_action) + public function delete_index($acp_module, $u_action) { if (!$this->index_created()) { @@ -699,10 +677,8 @@ class phpbb_search_fulltext_sphinx * Returns true if the sphinx table was created * * @return bool true if sphinx table was created - * - * @access public */ - function index_created($allow_new_files = true) + public function index_created($allow_new_files = true) { $created = false; @@ -718,10 +694,8 @@ class phpbb_search_fulltext_sphinx * Returns an associative array containing information about the indexes * * @return string|bool Language string of error false otherwise - * - * @access public */ - function index_stats() + public function index_stats() { if (empty($this->stats)) { @@ -737,10 +711,8 @@ class phpbb_search_fulltext_sphinx /** * Collects stats that can be displayed on the index maintenance page - * - * @access private */ - function get_stats() + private function get_stats() { if ($this->index_created()) { @@ -764,10 +736,8 @@ class phpbb_search_fulltext_sphinx * Returns a list of options for the ACP to display * * @return associative array containing template and config variables - * - * @access public */ - function acp() + public function acp() { $config_vars = array( 'fulltext_sphinx_data_path' => 'string', -- cgit v1.2.1 From a3a359d80ac5a4594ac6e7eee0b851d40d6ccf66 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 16:35:06 +0530 Subject: [ticket/11048] add access specifiers to phpbb native search properties PHPBB3-11048 --- phpBB/includes/search/fulltext_native.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 478b1f2c82..d66e690c76 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -22,14 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_fulltext_native extends phpbb_search_base { - var $stats = array(); - var $word_length = array(); - var $search_query; - var $common_words = array(); - - var $must_contain_ids = array(); - var $must_not_contain_ids = array(); - var $must_exclude_one_ids = array(); + private $stats = array(); + public $word_length = array(); + public $search_query; + public $common_words = array(); + + private $must_contain_ids = array(); + private $must_not_contain_ids = array(); + private $must_exclude_one_ids = array(); private $phpbb_root_path; private $php_ext; -- cgit v1.2.1 From 17b871914476d74f5e61d41d842ab1f6dd50db82 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 10 Aug 2012 12:33:25 +0530 Subject: [ticket/11032] sphinx retries before triggering error Sphinx connection retries should be done before error is triggered. PHPBB3-11032 --- phpBB/includes/search/fulltext_sphinx.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index fa7bd01f39..0319f971dc 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -492,6 +492,15 @@ class phpbb_search_fulltext_sphinx $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES); $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + // Could be connection to localhost:9312 failed (errno=111, + // msg=Connection refused) during rotate, retry if so + $retries = SPHINX_CONNECT_RETRIES; + while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--) + { + usleep(SPHINX_CONNECT_WAIT_TIME); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + } + if ($this->sphinx->GetLastError()) { add_log('critical', 'LOG_SPHINX_ERROR', $this->sphinx->GetLastError()); @@ -505,15 +514,6 @@ class phpbb_search_fulltext_sphinx } } - // Could be connection to localhost:9312 failed (errno=111, - // msg=Connection refused) during rotate, retry if so - $retries = SPHINX_CONNECT_RETRIES; - while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--) - { - usleep(SPHINX_CONNECT_WAIT_TIME); - $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); - } - $id_ary = array(); if (isset($result['matches'])) { -- cgit v1.2.1 From d0cdf445fba40401171b672ebd8fd1549b15a78f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 14 Aug 2012 17:33:44 +0530 Subject: [ticket/11048] use protected instead of private in sphinx PHPBB3-11048 --- phpBB/includes/search/fulltext_sphinx.php | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 9b98bf038b..f586860311 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -28,20 +28,20 @@ define('SPHINX_CONNECT_WAIT_TIME', 300); */ class phpbb_search_fulltext_sphinx { - private $stats = array(); - private $split_words = array(); - private $id; - private $indexes; - private $sphinx; - private $phpbb_root_path; - private $php_ext; - private $auth; - private $config; - private $db; - private $db_tools; - private $dbtype; - private $user; - private $config_file_data = ''; + protected $stats = array(); + protected $split_words = array(); + protected $id; + protected $indexes; + protected $sphinx; + protected $phpbb_root_path; + protected $php_ext; + protected $auth; + protected $config; + protected $db; + protected $db_tools; + protected $dbtype; + protected $user; + protected $config_file_data = ''; public $search_query; public $common_words = array(); @@ -121,7 +121,7 @@ class phpbb_search_fulltext_sphinx * * @return bool True if sphinx.conf content is correctly generated, false otherwise */ - private function config_generate() + protected function config_generate() { // Check if Database is supported by Sphinx if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli') @@ -712,7 +712,7 @@ class phpbb_search_fulltext_sphinx /** * Collects stats that can be displayed on the index maintenance page */ - private function get_stats() + protected function get_stats() { if ($this->index_created()) { -- cgit v1.2.1 From 5698d03ead081d167264a1a561b61b7ba9af1587 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 14 Aug 2012 17:35:24 +0530 Subject: [ticket/11048] use protected instead of private in mysql fulltext PHPBB3-11048 --- phpBB/includes/search/fulltext_mysql.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 8684258982..cf89ab1c24 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -22,11 +22,11 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_fulltext_mysql extends phpbb_search_base { - private $stats = array(); - private $split_words = array(); - private $config; - private $db; - private $user; + protected $stats = array(); + protected $split_words = array(); + protected $config; + protected $db; + protected $user; public $word_length = array(); public $search_query; public $common_words = array(); @@ -787,7 +787,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base /** * Computes the stats and store them in the $this->stats associative array */ - private function get_stats() + protected function get_stats() { if (strpos($this->db->sql_layer, 'mysql') === false) { -- cgit v1.2.1 From 8e8e94ec4c43fa67366ae4c317ff123965f4fe0b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 14 Aug 2012 17:43:01 +0530 Subject: [ticket/11048] remove @access from all docblocks PHPBB3-11048 --- phpBB/includes/search/fulltext_native.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index d66e690c76..56a610a392 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -87,8 +87,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string $terms is either 'all' (use search query as entered, default words to 'must be contained in post') * or 'any' (find all posts containing at least one of the given words) * @return boolean false if no valid keywords were found and otherwise true - * - * @access public */ public function split_keywords($keywords, $terms) { @@ -424,8 +422,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { @@ -820,8 +816,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results - * - * @access public */ public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) { @@ -1045,8 +1039,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @param string $text Text to split, encoded in UTF-8 * @return array Array of UTF-8 words - * - * @access private */ public function split_message($text) { @@ -1122,8 +1114,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param string &$subject New or updated post subject * @param int $poster_id Post author's user id * @param int $forum_id The id of the forum in which the post is located - * - * @access public */ public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { -- cgit v1.2.1 From 469d8083656e455dc52cd1e4e65fdd7c86c5e2ab Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 14 Aug 2012 17:46:17 +0530 Subject: [ticket/11048] use protected instead of private in native search PHPBB3-11048 --- phpBB/includes/search/fulltext_native.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 56a610a392..96b3f02ec6 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -22,20 +22,20 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_fulltext_native extends phpbb_search_base { - private $stats = array(); + protected $stats = array(); public $word_length = array(); public $search_query; public $common_words = array(); - private $must_contain_ids = array(); - private $must_not_contain_ids = array(); - private $must_exclude_one_ids = array(); + protected $must_contain_ids = array(); + protected $must_not_contain_ids = array(); + protected $must_exclude_one_ids = array(); - private $phpbb_root_path; - private $php_ext; - private $config; - private $db; - private $user; + protected $phpbb_root_path; + protected $php_ext; + protected $config; + protected $db; + protected $user; /** * Initialises the fulltext_native search backend with min/max word length and makes sure the UTF-8 normalizer is loaded. @@ -1440,7 +1440,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); } - private function get_stats() + protected function get_stats() { $this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); $this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); @@ -1461,7 +1461,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * * @todo normalizer::cleanup being able to be used? */ - private function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') + protected function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') { static $conv = array(), $conv_loaded = array(); $words = $allow = array(); -- cgit v1.2.1 From a9fd98c1366cc63032bcfa5d5409ebf891ea5095 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 14 Aug 2012 17:47:01 +0530 Subject: [ticket/11048] use protected instead of private in pgsql fulltext PHPBB3-11048 --- phpBB/includes/search/fulltext_postgres.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index d897c73745..50ed785093 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -22,15 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_search_fulltext_postgres extends phpbb_search_base { - private $stats = array(); - private $split_words = array(); - private $tsearch_usable = false; - private $version; - private $tsearch_query; - private $phrase_search = false; - private $config; - private $db; - private $user; + protected $stats = array(); + protected $split_words = array(); + protected $tsearch_usable = false; + protected $version; + protected $tsearch_query; + protected $phrase_search = false; + protected $config; + protected $db; + protected $user; public $search_query; public $common_words = array(); public $word_length = array(); @@ -714,7 +714,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base /** * Computes the stats and store them in the $this->stats associative array */ - private function get_stats() + protected function get_stats() { if ($this->db->sql_layer != 'postgres') { -- cgit v1.2.1 From fe579cac8385381f52a26cd61a2de29a71434f2b Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 14 Aug 2012 09:57:17 -0400 Subject: [ticket/11054] Fixed documentation syntax for @var in extension/controller.php PHPBB3-11054 --- phpBB/includes/extension/controller.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 2b8c50aafb..1099bc128e 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -23,37 +23,44 @@ if (!defined('IN_PHPBB')) abstract class phpbb_extension_controller implements phpbb_extension_controller_interface { /** - * @var phpbb_request Request class object + * Request class object + * @var phpbb_request */ protected $request; /** - * @var dbal DBAL class object + * DBAL class object + * @var dbal */ protected $db; /** - * @var user User class object + * User class object + * @var user */ protected $user; /** - * @var phpbb_template Template class object + * Template class object + * @var phpbb_template */ protected $template; /** - * @var array Config array + * Config array + * @var array */ protected $config; /** - * @var string PHP Extension + * PHP Extension + * @var string */ protected $php_ext; /** - * @var string Relative path to board root + * Relative path to board root + * @var string */ protected $phpbb_root_path; -- cgit v1.2.1 From 0b70c3d0d6e96854ab517244e8ae745c24b862f4 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 14 Aug 2012 10:02:16 -0400 Subject: [ticket/11054] The user class is phpbb_user PHPBB3-11054 --- phpBB/includes/extension/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 1099bc128e..3e9eadf2dd 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -36,7 +36,7 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ /** * User class object - * @var user + * @var phpbb_user */ protected $user; -- cgit v1.2.1 From b729609fb29ba653b168a8bcb2e071e3bd72dda6 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 15 Aug 2012 09:15:18 -0400 Subject: [ticket/11054] Fixed $config var description PHPBB3-11054 --- phpBB/includes/extension/controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 3e9eadf2dd..f97b69c7ed 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -47,8 +47,8 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ protected $template; /** - * Config array - * @var array + * Config object + * @var phpbb_config */ protected $config; -- cgit v1.2.1 From 938805106c75499eb953d1a22a1ce772c21252de Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 15 Aug 2012 21:09:42 +0530 Subject: [ticket/11052] pass parametes to search construct while posting Proper parameters are passed in search backend constructor in functions_posting.php PHPBB3-11052 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6c21b0f412..4d09367934 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2370,7 +2370,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); if ($error) { -- cgit v1.2.1 From 7c406e1e8123758c20b92c7ff424bbf9b9190cf2 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 15 Aug 2012 22:05:26 +0530 Subject: [ticket/11052] update search backend constructor everywhere PHPBB3-11052 --- phpBB/includes/cron/task/core/tidy_search.php | 4 ++-- phpBB/includes/functions_admin.php | 4 ++-- phpBB/includes/mcp/mcp_main.php | 2 +- phpBB/includes/mcp/mcp_post.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 8a0b1b690a..7855c3760a 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -31,7 +31,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $config, $error; + global $phpbb_root_path, $phpEx, $config, $error, $auth, $db, $user; // Select the search method $search_type = basename($config['search_type']); @@ -43,7 +43,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base // We do some additional checks in the module to ensure it can actually be utilised $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); if (!$error) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 5d19cd7adb..5e2ee8c8f6 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -723,7 +723,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s */ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true) { - global $db, $config, $phpbb_root_path, $phpEx; + global $db, $config, $phpbb_root_path, $phpEx, $auth, $user; if ($where_type === 'range') { @@ -855,7 +855,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); if ($error) { diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index a21c67924d..95ca7c2e1b 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -915,7 +915,7 @@ function mcp_fork_topic($topic_ids) } $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); $search_mode = 'post'; if ($error) diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php index 2a52a858b3..520c964228 100644 --- a/phpBB/includes/mcp/mcp_post.php +++ b/phpBB/includes/mcp/mcp_post.php @@ -393,7 +393,7 @@ function mcp_post_details($id, $mode, $action) */ function change_poster(&$post_info, $userdata) { - global $auth, $db, $config, $phpbb_root_path, $phpEx; + global $auth, $db, $config, $phpbb_root_path, $phpEx, $user; if (empty($userdata) || $userdata['user_id'] == $post_info['user_id']) { @@ -470,7 +470,7 @@ function change_poster(&$post_info, $userdata) { // We do some additional checks in the module to ensure it can actually be utilised $error = false; - $search = new $search_type($error); + $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); if (!$error && method_exists($search, 'destroy_cache')) { -- cgit v1.2.1 From d4f1e71d5eca1204880de3199245e0167ac7f3f6 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 15 Aug 2012 22:57:02 +0530 Subject: [ticket/11032] fix language of error displayed Language of the error displayed is modified. PHPBB3-11032 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 0319f971dc..6b93d40c66 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -510,7 +510,7 @@ class phpbb_search_fulltext_sphinx } else { - trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->user->lang('SPHINX_SEARCH_ERROR_LOG'))); + trigger_error($this->user->lang('SPHINX_SEARCH_FAILED_LOG')); } } -- cgit v1.2.1 From b32d5a3edf418e2c9cdfa8cbe027c9da7e31d2f6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Aug 2012 20:25:11 +0200 Subject: [feature/php-events] Fix core.acp_manage_forums_update_data_after vars PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 6fb246458c..39bc7e39ad 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1338,7 +1338,7 @@ class acp_forums * language key. * @since 3.1-A1 */ - $vars = array('forum_data', 'forum_data_sql' 'is_new_forum', 'errors'); + $vars = array('forum_data', 'forum_data_sql', 'is_new_forum', 'errors'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars))); return $errors; -- cgit v1.2.1 From 90ed6e734d7a8587e73fb0e37251982adc8d10ab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Aug 2012 20:28:14 +0200 Subject: [feature/php-events] Fix acp_manage_forums_update_data_before and is_new_forum PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 39bc7e39ad..c6dbf5eb9c 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -1036,17 +1036,14 @@ class acp_forums } unset($forum_data_sql['forum_password_unset']); - $is_new_forum = !isset($forum_data_sql['forum_id']); - /** * Remove invalid values from forum_data_sql that should not be updated * * @event core.acp_manage_forums_update_data_before * @var array forum_data Array with forum data * @var array forum_data_sql Array with data we are going to update - * @var bool is_new_forum Do we create a forum or update one - * If you want to overwrite this value, - * ensure to set forum_data_sql[forum_id] + * If forum_data_sql[forum_id] is set, we update + * that forum, otherwise a new one is created. * @since 3.1-A1 */ $vars = array('forum_data', 'forum_data_sql'); -- cgit v1.2.1 From aea60f9323e8753535d0dbf5ffa1ffa09ff3c02e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:08:28 +0200 Subject: [feature/php-events] Fix doc of core.update_username PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 733a6fd9bd..a561daa334 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -138,7 +138,7 @@ function user_update_name($old_name, $new_name) } /** - * Update username when it is changed + * Update a username when it is changed * * @event core.update_username * @var string old_name The old username that is replaced -- cgit v1.2.1 From 74d9ef0becb1558d12a7372ba68553421963ccbe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:08:59 +0200 Subject: [feature/php-events] Fix doc of core.delete_user_before PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index a561daa334..1a75e96dd6 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -358,7 +358,7 @@ function user_delete($mode, $user_id, $post_username = false) } /** - * Event before an user is deleted + * Event before a user is deleted * * @event core.delete_user_before * @var string mode Mode of deletion (retain/delete posts) -- cgit v1.2.1 From 48b54ed1e0e5b354618fb92f9559b653e61fb530 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:09:29 +0200 Subject: [feature/php-events] Fix doc of core.delete_user_after PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 1a75e96dd6..3de7b5d7c7 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -559,7 +559,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); /** - * Event after an user is deleted + * Event after a user is deleted * * @event core.delete_user_after * @var string mode Mode of deletion (retain/delete posts) -- cgit v1.2.1 From 01db8144d49e263a1cb36621090b54854b0f8bff Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:10:52 +0200 Subject: [feature/php-events] Fix doc of core.generate_smilies_after PHPBB3-9550 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7ac56588af..1161dd8462 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -124,7 +124,7 @@ function generate_smilies($mode, $forum_id) } /** - * This event is called when the smilies got populated + * This event is called after the smilies are populated * * @event core.generate_smilies_after * @var string mode Mode of the smilies: window|inline -- cgit v1.2.1 From 365d95c1fee2b5e73dd16d0d741df6cc64956ed7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:11:52 +0200 Subject: [feature/php-events] Fix doc of core.user_set_default_group PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3de7b5d7c7..9e33a5122e 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3512,7 +3512,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } /** - * Event when the default group is set for an array of user + * Event when the default group is set for an array of users * * @event core.user_set_default_group * @var int group_id ID of the group -- cgit v1.2.1