From a50b0faf4abfb1bba68e03d843c58f07f842cf12 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Fri, 4 May 2012 18:39:41 +0530 Subject: [PATCH 001/259] [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 ++++++++++++++++++++ phpBB/language/en/mods/fulltext_sphinx.php | 65 ++ 4 files changed, 2940 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 create mode 100644 phpBB/language/en/mods/fulltext_sphinx.php 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 diff --git a/phpBB/language/en/mods/fulltext_sphinx.php b/phpBB/language/en/mods/fulltext_sphinx.php new file mode 100644 index 0000000000..e06328afc8 --- /dev/null +++ b/phpBB/language/en/mods/fulltext_sphinx.php @@ -0,0 +1,65 @@ + 'Automatically configure Sphinx', + 'FULLTEXT_SPHINX_AUTOCONF_EXPLAIN' => 'This is the easiest way to install Sphinx, just select the settings here and a config file will be written for you. This requires write permissions on the configuration folder.', + 'FULLTEXT_SPHINX_AUTORUN' => 'Automatically run Sphinx', + 'FULLTEXT_SPHINX_AUTORUN_EXPLAIN' => 'This is the easiest way to run Sphinx. Select the paths in this dialogue and the Sphinx daemon will be started and stopped as needed. You can also create an index from the ACP. If your PHP installation forbids the use of exec you can disable this and run Sphinx manually.', + 'FULLTEXT_SPHINX_BIN_PATH' => 'Path to executables directory', + 'FULLTEXT_SPHINX_BIN_PATH_EXPLAIN' => 'Skip if autorun is disabled. If this path could not be determined automatically you have to enter the path to the directory in which the sphinx executables indexer and searchd reside.', + 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', + 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'Skip if autoconf is disabled. You should create this config directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody).', + 'FULLTEXT_SPHINX_CONFIGURE_FIRST' => 'Before you create an index you have to enable and configure sphinx under GENERAL -> SERVER CONFIGURATION -> Search settings.', + 'FULLTEXT_SPHINX_CONFIGURE_BEFORE' => 'Configure the following settings BEFORE activating Sphinx', + 'FULLTEXT_SPHINX_CONFIGURE_AFTER' => 'The following settings do not have to be configured before activating Sphinx', + 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', + 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'Skip if autorun is disabled. You should create this directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody). It will be used to store the indexes and log files.', + 'FULLTEXT_SPHINX_DELTA_POSTS' => 'Number of posts in frequently updated delta index', + 'FULLTEXT_SPHINX_DIRECTORY_NOT_FOUND' => 'The directory %s does not exist. Please correct your path settings.', + 'FULLTEXT_SPHINX_FILE_NOT_EXECUTABLE' => 'The file %s is not executable for the webserver.', + 'FULLTEXT_SPHINX_FILE_NOT_FOUND' => 'The file %s does not exist. Please correct your path settings.', + 'FULLTEXT_SPHINX_FILE_NOT_WRITABLE' => 'The file %s cannot be written by the webserver.', + 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', + 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', + 'FULLTEXT_SPHINX_LAST_SEARCHES' => 'Recent search queries', + 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', + 'FULLTEXT_SPHINX_PORT' => 'Sphinx search deamon port', + 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', + 'FULLTEXT_SPHINX_REQUIRES_EXEC' => 'The sphinx plugin for phpBB requires PHP’s exec function which is disabled on your system.', + 'FULLTEXT_SPHINX_UNCONFIGURED' => 'Please set all necessary options in the "Fulltext Sphinx" section of the previous page before you try to activate the sphinx plugin.', + 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', + 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', + 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', +)); + +?> \ No newline at end of file From fcf0d04b20f1c862117a8ab962d692bd2b8b074f Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 9 May 2012 19:13:36 +0530 Subject: [PATCH 002/259] [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(-) 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 From 99d4660df68d71ea56cccb150ae858c1dd7575b8 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 20 Jun 2012 05:11:53 +0530 Subject: [PATCH 003/259] [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(-) 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"), From 8d76bc45ee19186f40dd3b459a9bd33e5e4c23d9 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 26 Jun 2012 02:35:36 +0530 Subject: [PATCH 004/259] [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 +- phpBB/language/en/mods/fulltext_sphinx.php | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) 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 +// diff --git a/phpBB/language/en/mods/fulltext_sphinx.php b/phpBB/language/en/mods/fulltext_sphinx.php index e06328afc8..f3fd68aa62 100644 --- a/phpBB/language/en/mods/fulltext_sphinx.php +++ b/phpBB/language/en/mods/fulltext_sphinx.php @@ -62,4 +62,4 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', )); -?> \ No newline at end of file +?> From a3b2caf8416c687306b3c2e83b2fdc6e8708cce0 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Mon, 25 Jun 2012 00:03:46 +0530 Subject: [PATCH 005/259] [feature/sphinx-fulltext-search] include sample sphinx.conf in docs PHPBB3-10946 --- phpBB/docs/sphinx.sample.conf | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 phpBB/docs/sphinx.sample.conf diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf new file mode 100644 index 0000000000..d7e59a11fc --- /dev/null +++ b/phpBB/docs/sphinx.sample.conf @@ -0,0 +1,96 @@ +source source_phpbb_{AVATAR_SALT}_main +{ + type = mysql + sql_host = localhost + sql_user = username + sql_pass = password + sql_db = db_name + sql_port = 3306 #optional, default is 3306 + sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM phpbb_posts + sql_range_step = 5000 + 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 phpbb_posts p, phpbb_topics t \ + WHERE \ + p.topic_id = t.topic_id \ + AND p.post_id >= $start AND p.post_id <= $end + sql_query_post = + sql_query_post_index = REPLACE INTO phpbb_sphinx ( counter_id, max_doc_id ) VALUES ( 1, $maxid ) + sql_query_info = SELECT * FROM phpbb_posts WHERE post_id = $id + sql_query_pre = SET NAMES utf8 + sql_query_pre = REPLACE INTO phpbb_sphinx SELECT 1, MAX(post_id) FROM phpbb_posts + sql_attr_uint = forum_id + sql_attr_uint = topic_id + sql_attr_uint = poster_id + sql_attr_bool = topic_first_post + sql_attr_bool = deleted + sql_attr_timestamp = post_time + sql_attr_timestamp = topic_last_post_time + sql_attr_str2ordinal = post_subject +} +source source_phpbb_{AVATAR_SALT}_delta : source_phpbb_{AVATAR_SALT}_main +{ + sql_query_range = + sql_range_step = + 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 phpbb_posts p, phpbb_topics t \ + WHERE \ + p.topic_id = t.topic_id \ + AND p.post_id >= ( SELECT max_doc_id FROM phpbb_sphinx WHERE counter_id=1 ) + sql_query_pre = +} +index index_phpbb_{AVATAR_SALT}_main +{ + path = {DATA_PATH}/index_phpbb_{AVATAR_SALT}_main + source = source_phpbb_{AVATAR_SALT}_main + docinfo = extern + morphology = none + stopwords = + min_word_len = 2 + charset_type = utf-8 + 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 + min_prefix_len = 0 + min_infix_len = 0 +} +index index_phpbb_{AVATAR_SALT}_delta : index_phpbb_{AVATAR_SALT}_main +{ + path = {DATA_PATH}/index_phpbb_{AVATAR_SALT}_delta + source = source_phpbb_{AVATAR_SALT}_delta +} +indexer +{ + mem_limit = 512M +} +searchd +{ + compat_sphinxql_magics = 0 + listen = 127.0.0.1 + port = 3312 + log = {DATA_PATH}/log/searchd.log + query_log = {DATA_PATH}/log/sphinx-query.log + read_timeout = 5 + max_children = 30 + pid_file = {DATA_PATH}/searchd.pid + max_matches = 20000 +} From 455a35d8361c93657874e140a2ad5b2e5c267757 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 26 Jun 2012 03:56:03 +0530 Subject: [PATCH 006/259] [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 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$ -// From 02588069f045ae48984d68c9948c8ecd1c78580d Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 26 Jun 2012 19:06:19 +0530 Subject: [PATCH 007/259] [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(-) 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'), From 74a7407927cd5b54328a3941a9926ee35caf17b4 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 00:17:39 +0530 Subject: [PATCH 008/259] [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(-) 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--; From f609555b1ae335b5ea996bf26ee2846058e5256a Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 00:28:31 +0530 Subject: [PATCH 009/259] [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 -- phpBB/language/en/acp/search.php | 30 ++++++++++ phpBB/language/en/mods/fulltext_sphinx.php | 65 ---------------------- 3 files changed, 30 insertions(+), 71 deletions(-) delete mode 100644 phpBB/language/en/mods/fulltext_sphinx.php 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', diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index cd319c66a9..3fa7f34c64 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -69,6 +69,36 @@ $lang = array_merge($lang, array( 'FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN' => 'Words with at least this many characters will be included in the query to the database.', 'FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN' => 'Words with no more than this many characters will be included in the query to the database.', + 'FULLTEXT_SPHINX_AUTOCONF' => 'Automatically configure Sphinx', + 'FULLTEXT_SPHINX_AUTOCONF_EXPLAIN' => 'This is the easiest way to install Sphinx, just select the settings here and a config file will be written for you. This requires write permissions on the configuration folder.', + 'FULLTEXT_SPHINX_AUTORUN' => 'Automatically run Sphinx', + 'FULLTEXT_SPHINX_AUTORUN_EXPLAIN' => 'This is the easiest way to run Sphinx. Select the paths in this dialogue and the Sphinx daemon will be started and stopped as needed. You can also create an index from the ACP. If your PHP installation forbids the use of exec you can disable this and run Sphinx manually.', + 'FULLTEXT_SPHINX_BIN_PATH' => 'Path to executables directory', + 'FULLTEXT_SPHINX_BIN_PATH_EXPLAIN' => 'Skip if autorun is disabled. If this path could not be determined automatically you have to enter the path to the directory in which the sphinx executables indexer and searchd reside.', + 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', + 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'Skip if autoconf is disabled. You should create this config directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody).', + 'FULLTEXT_SPHINX_CONFIGURE_FIRST' => 'Before you create an index you have to enable and configure sphinx under GENERAL -> SERVER CONFIGURATION -> Search settings.', + 'FULLTEXT_SPHINX_CONFIGURE_BEFORE' => 'Configure the following settings BEFORE activating Sphinx', + 'FULLTEXT_SPHINX_CONFIGURE_AFTER' => 'The following settings do not have to be configured before activating Sphinx', + 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', + 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'Skip if autorun is disabled. You should create this directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody). It will be used to store the indexes and log files.', + 'FULLTEXT_SPHINX_DELTA_POSTS' => 'Number of posts in frequently updated delta index', + 'FULLTEXT_SPHINX_DIRECTORY_NOT_FOUND' => 'The directory %s does not exist. Please correct your path settings.', + 'FULLTEXT_SPHINX_FILE_NOT_EXECUTABLE' => 'The file %s is not executable for the webserver.', + 'FULLTEXT_SPHINX_FILE_NOT_FOUND' => 'The file %s does not exist. Please correct your path settings.', + 'FULLTEXT_SPHINX_FILE_NOT_WRITABLE' => 'The file %s cannot be written by the webserver.', + 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', + 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', + 'FULLTEXT_SPHINX_LAST_SEARCHES' => 'Recent search queries', + 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', + 'FULLTEXT_SPHINX_PORT' => 'Sphinx search deamon port', + 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', + 'FULLTEXT_SPHINX_REQUIRES_EXEC' => 'The sphinx plugin for phpBB requires PHP’s exec function which is disabled on your system.', + 'FULLTEXT_SPHINX_UNCONFIGURED' => 'Please set all necessary options in the "Fulltext Sphinx" section of the previous page before you try to activate the sphinx plugin.', + 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', + 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', + 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', + 'GENERAL_SEARCH_SETTINGS' => 'General search settings', 'GO_TO_SEARCH_INDEX' => 'Go to search index page', diff --git a/phpBB/language/en/mods/fulltext_sphinx.php b/phpBB/language/en/mods/fulltext_sphinx.php deleted file mode 100644 index f3fd68aa62..0000000000 --- a/phpBB/language/en/mods/fulltext_sphinx.php +++ /dev/null @@ -1,65 +0,0 @@ - 'Automatically configure Sphinx', - 'FULLTEXT_SPHINX_AUTOCONF_EXPLAIN' => 'This is the easiest way to install Sphinx, just select the settings here and a config file will be written for you. This requires write permissions on the configuration folder.', - 'FULLTEXT_SPHINX_AUTORUN' => 'Automatically run Sphinx', - 'FULLTEXT_SPHINX_AUTORUN_EXPLAIN' => 'This is the easiest way to run Sphinx. Select the paths in this dialogue and the Sphinx daemon will be started and stopped as needed. You can also create an index from the ACP. If your PHP installation forbids the use of exec you can disable this and run Sphinx manually.', - 'FULLTEXT_SPHINX_BIN_PATH' => 'Path to executables directory', - 'FULLTEXT_SPHINX_BIN_PATH_EXPLAIN' => 'Skip if autorun is disabled. If this path could not be determined automatically you have to enter the path to the directory in which the sphinx executables indexer and searchd reside.', - 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', - 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'Skip if autoconf is disabled. You should create this config directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody).', - 'FULLTEXT_SPHINX_CONFIGURE_FIRST' => 'Before you create an index you have to enable and configure sphinx under GENERAL -> SERVER CONFIGURATION -> Search settings.', - 'FULLTEXT_SPHINX_CONFIGURE_BEFORE' => 'Configure the following settings BEFORE activating Sphinx', - 'FULLTEXT_SPHINX_CONFIGURE_AFTER' => 'The following settings do not have to be configured before activating Sphinx', - 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', - 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'Skip if autorun is disabled. You should create this directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody). It will be used to store the indexes and log files.', - 'FULLTEXT_SPHINX_DELTA_POSTS' => 'Number of posts in frequently updated delta index', - 'FULLTEXT_SPHINX_DIRECTORY_NOT_FOUND' => 'The directory %s does not exist. Please correct your path settings.', - 'FULLTEXT_SPHINX_FILE_NOT_EXECUTABLE' => 'The file %s is not executable for the webserver.', - 'FULLTEXT_SPHINX_FILE_NOT_FOUND' => 'The file %s does not exist. Please correct your path settings.', - 'FULLTEXT_SPHINX_FILE_NOT_WRITABLE' => 'The file %s cannot be written by the webserver.', - 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', - 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', - 'FULLTEXT_SPHINX_LAST_SEARCHES' => 'Recent search queries', - 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', - 'FULLTEXT_SPHINX_PORT' => 'Sphinx search deamon port', - 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', - 'FULLTEXT_SPHINX_REQUIRES_EXEC' => 'The sphinx plugin for phpBB requires PHP’s exec function which is disabled on your system.', - 'FULLTEXT_SPHINX_UNCONFIGURED' => 'Please set all necessary options in the "Fulltext Sphinx" section of the previous page before you try to activate the sphinx plugin.', - 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', - 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', - 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', -)); - -?> From bfd01f01877bcb9a9be9e2df5c6713c3e338579e Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 01:03:04 +0530 Subject: [PATCH 010/259] [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(-) 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); } } } From 39f8a5fa9f71724d0abd98cdf7a7d82fc7e7bb0f Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Wed, 27 Jun 2012 03:44:03 +0530 Subject: [PATCH 011/259] [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(-) 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); From 10b706674e0fc100ff4e21d5fe100a9b532bb4bf Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 01:49:38 +0530 Subject: [PATCH 012/259] [feature/sphinx-fulltext-search] add binlog_path to config binlog files are now added to the data folder. PHPBB3-10946 --- phpBB/docs/sphinx.sample.conf | 1 + phpBB/includes/search/fulltext_sphinx.php | 1 + 2 files changed, 2 insertions(+) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index d7e59a11fc..000d8157d6 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -93,4 +93,5 @@ searchd max_children = 30 pid_file = {DATA_PATH}/searchd.pid max_matches = 20000 + binlog_path = {DATA_PATH} } 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']), ), ); From 97fda78e7d85444f21ba2b10b3d58c4639b85936 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 01:23:57 +0530 Subject: [PATCH 013/259] [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/search/fulltext_sphinx.php | 7 +- .../sphinx/config.php} | 251 ++---------------- .../includes/search/sphinx/config_comment.php | 45 ++++ .../includes/search/sphinx/config_section.php | 144 ++++++++++ .../search/sphinx/config_variable.php | 72 +++++ 5 files changed, 280 insertions(+), 239 deletions(-) rename phpBB/includes/{functions_sphinx.php => search/sphinx/config.php} (51%) 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 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/functions_sphinx.php b/phpBB/includes/search/sphinx/config.php similarity index 51% rename from phpBB/includes/functions_sphinx.php rename to phpBB/includes/search/sphinx/config.php index a93a1d950f..966cd0f284 100644 --- a/phpBB/includes/functions_sphinx.php +++ b/phpBB/includes/search/sphinx/config.php @@ -1,13 +1,14 @@ 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) + if (($this->sections[$i] instanceof phpbb_search_sphinx_config_section) && $this->sections[$i]->get_name() == $name) { return $this->sections[$i]; } @@ -59,12 +60,12 @@ class sphinx_config /** * 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 + * @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 sphinx_config_section($name, ''); + $this->sections[] = new phpbb_search_sphinx_config_section($name, ''); return $this->sections[sizeof($this->sections) - 1]; } @@ -104,7 +105,7 @@ class sphinx_config // 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]); + $this->sections[] = new phpbb_search_sphinx_config_comment($config_file[$i]); continue; } else @@ -138,7 +139,7 @@ class sphinx_config // and then we create the new section object $section_name = trim($section_name); - $section = new sphinx_config_section($section_name, $section_name_comment); + $section = new phpbb_search_sphinx_config_section($section_name, $section_name_comment); } } else // if we're looking for variables inside a section @@ -152,7 +153,7 @@ class sphinx_config // of this section so they're not deleted on reassembly if (!$line || $line[0] == '#') { - $section->add_variable(new sphinx_config_comment($config_file[$i])); + $section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); continue; } @@ -168,7 +169,7 @@ class sphinx_config } else { - $section->add_variable(new sphinx_config_comment($config_file[$i])); + $section->add_variable(new phpbb_search_sphinx_config_comment($config_file[$i])); continue; } } @@ -234,7 +235,7 @@ class sphinx_config // 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)); + $section->add_variable(new phpbb_search_sphinx_config_variable(trim($name), trim($value), ($end_section) ? '' : $comment)); continue; } @@ -251,7 +252,7 @@ class sphinx_config // 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)); + $section->add_variable(new phpbb_search_sphinx_config_comment($comment)); } } @@ -284,219 +285,3 @@ class sphinx_config 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/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"; + } +} From 4a11a7b97027743b8239d31a4d51824bd807c5ac Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 03:03:15 +0530 Subject: [PATCH 014/259] [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(-) 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); From 06eeed058df75c41496c5306bfa35725c45cf5f3 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 03:17:45 +0530 Subject: [PATCH 015/259] [feature/sphinx-fulltext-search] remove unused arrays PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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) From 0e9174d168a82bde16ec59d615e19b85a50cebcf Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 05:06:51 +0530 Subject: [PATCH 016/259] [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(-) 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; From 2503581cd562b39a108821da85cc0175735e24a5 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 02:33:02 +0530 Subject: [PATCH 017/259] [feature/sphinx-fulltext-search] add class properties indexes & sphinx PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 ++ 1 file changed, 2 insertions(+) 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) { From 8dcdf8a9732a570f26fee802af4bfcbd25f16ec2 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Sun, 1 Jul 2012 12:01:14 +0530 Subject: [PATCH 018/259] [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(-) 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) { From e486f4389c99c27cb723d4e9fd437130752f891e Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 03:51:40 +0530 Subject: [PATCH 019/259] [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(-) 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; -} From 88089194e570edb77240138695034358062ffa58 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 03:55:23 +0530 Subject: [PATCH 020/259] [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(-) 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); } From 569db1471b3000512232732a790d8653250e8012 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 04:15:35 +0530 Subject: [PATCH 021/259] [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(-) 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'] . '
From d2e42d7d619100695e0efe8d472c71f61cbfcb45 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 04:53:51 +0530 Subject: [PATCH 022/259] [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(-) 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()) { From 9711da2763f707408efde160357d51330fd17681 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:04:14 +0530 Subject: [PATCH 023/259] [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 ------------------ phpBB/install/database_update.php | 10 ++++++++++ phpBB/install/schemas/schema_data.sql | 2 ++ 3 files changed, 12 insertions(+), 18 deletions(-) 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']. '
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 594397c815..0ffab8e413 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2260,6 +2260,16 @@ function change_database_data(&$no_updates, $version) set_config('fulltext_postgres_max_word_len', 254); } + if (!isset($config['fulltext_sphinx_stopwords'])) + { + set_config('fulltext_sphinx_stopwords', 0); + } + + if (!isset($config['fulltext_sphinx_indexer_mem_limit'])) + { + set_config('fulltext_sphinx_indexer_mem_limit', 512); + } + if (!isset($config['load_jquery_cdn'])) { set_config('load_jquery_cdn', 0); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index deefdafbc4..797f78e889 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -128,6 +128,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_native_mi INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_postgres_max_word_len', '254'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_postgres_min_word_len', '4'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_postgres_ts_name', 'simple'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_sphinx_indexer_mem_limit', '512'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('fulltext_sphinx_stopwords', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('gzip_compress', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('hot_threshold', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('icons_path', 'images/icons'); From 79432aa4a0698a5a4a518521613aad4adbb40584 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:16:42 +0530 Subject: [PATCH 024/259] [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(-) 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'] . '
'; From 45c0956bcf72e59138c3b05e26c73b657298f562 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:23:23 +0530 Subject: [PATCH 025/259] [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(-) 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; } From 537a16220ea9561332a17004eec79f2854c68df4 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:33:17 +0530 Subject: [PATCH 026/259] [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 --- phpBB/language/en/acp/search.php | 12 +----------- 2 files changed, 1 insertion(+), 14 deletions(-) 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'] = ''; } /** diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 3fa7f34c64..14701459eb 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -57,6 +57,7 @@ $lang = array_merge($lang, array( 'FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN' => 'Words with at least this many characters will be indexed for searching. You or your host can only change this setting by changing the mysql configuration.', 'FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN' => 'Words with no more than this many characters will be indexed for searching. You or your host can only change this setting by changing the mysql configuration.', +<<<<<<< HEAD 'FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE' => 'The PostgreSQL fulltext backend can only be used with PostgreSQL.', 'FULLTEXT_POSTGRES_TS_NOT_USABLE' => 'The PostgreSQL fulltext backend can only be used with PostgreSQL 8.3 and above.', 'FULLTEXT_POSTGRES_TOTAL_POSTS' => 'Total number of indexed posts', @@ -69,10 +70,6 @@ $lang = array_merge($lang, array( 'FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN' => 'Words with at least this many characters will be included in the query to the database.', 'FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN' => 'Words with no more than this many characters will be included in the query to the database.', - 'FULLTEXT_SPHINX_AUTOCONF' => 'Automatically configure Sphinx', - 'FULLTEXT_SPHINX_AUTOCONF_EXPLAIN' => 'This is the easiest way to install Sphinx, just select the settings here and a config file will be written for you. This requires write permissions on the configuration folder.', - 'FULLTEXT_SPHINX_AUTORUN' => 'Automatically run Sphinx', - 'FULLTEXT_SPHINX_AUTORUN_EXPLAIN' => 'This is the easiest way to run Sphinx. Select the paths in this dialogue and the Sphinx daemon will be started and stopped as needed. You can also create an index from the ACP. If your PHP installation forbids the use of exec you can disable this and run Sphinx manually.', 'FULLTEXT_SPHINX_BIN_PATH' => 'Path to executables directory', 'FULLTEXT_SPHINX_BIN_PATH_EXPLAIN' => 'Skip if autorun is disabled. If this path could not be determined automatically you have to enter the path to the directory in which the sphinx executables indexer and searchd reside.', 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', @@ -83,18 +80,11 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'Skip if autorun is disabled. You should create this directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody). It will be used to store the indexes and log files.', 'FULLTEXT_SPHINX_DELTA_POSTS' => 'Number of posts in frequently updated delta index', - 'FULLTEXT_SPHINX_DIRECTORY_NOT_FOUND' => 'The directory %s does not exist. Please correct your path settings.', - 'FULLTEXT_SPHINX_FILE_NOT_EXECUTABLE' => 'The file %s is not executable for the webserver.', - 'FULLTEXT_SPHINX_FILE_NOT_FOUND' => 'The file %s does not exist. Please correct your path settings.', - 'FULLTEXT_SPHINX_FILE_NOT_WRITABLE' => 'The file %s cannot be written by the webserver.', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', - 'FULLTEXT_SPHINX_LAST_SEARCHES' => 'Recent search queries', 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', 'FULLTEXT_SPHINX_PORT' => 'Sphinx search deamon port', 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', - 'FULLTEXT_SPHINX_REQUIRES_EXEC' => 'The sphinx plugin for phpBB requires PHP’s exec function which is disabled on your system.', - 'FULLTEXT_SPHINX_UNCONFIGURED' => 'Please set all necessary options in the "Fulltext Sphinx" section of the previous page before you try to activate the sphinx plugin.', 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', From fdb7e64e29d7b6286b505cf3a75fe53cfdfc7503 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 05:51:52 +0530 Subject: [PATCH 027/259] [feature/sphinx-fulltext-search] fix comments PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 34 +++++++----- phpBB/includes/search/sphinx/config.php | 52 +++++++++++-------- .../includes/search/sphinx/config_section.php | 6 +-- 3 files changed, 53 insertions(+), 39 deletions(-) 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); From 01261179ce71ff0699ae598828ae82ec98751037 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 06:07:42 +0530 Subject: [PATCH 028/259] [feature/sphinx-fulltext-search] improve formatting PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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']; } From f0692bb9e83f6af9725023028f07cba636d04a4b Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 06:38:36 +0530 Subject: [PATCH 029/259] [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 | 265 +++++++++++----------- phpBB/includes/search/sphinx/config.php | 40 ++-- 2 files changed, 146 insertions(+), 159 deletions(-) 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); + 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'); + /* 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']), - ), - ); + $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); - - foreach ($config_data as $section_name => $section_data) + $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->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) - { - $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) + { + $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 + 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); } } + } + $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; } } From b16e70ae1d03587c7d7d7e106299a4e576491751 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Tue, 10 Jul 2012 12:32:42 +0530 Subject: [PATCH 030/259] [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 ----- phpBB/language/en/acp/search.php | 3 --- 2 files changed, 8 deletions(-) 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'] . '
diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 14701459eb..9618bb90c5 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -57,7 +57,6 @@ $lang = array_merge($lang, array( 'FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN' => 'Words with at least this many characters will be indexed for searching. You or your host can only change this setting by changing the mysql configuration.', 'FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN' => 'Words with no more than this many characters will be indexed for searching. You or your host can only change this setting by changing the mysql configuration.', -<<<<<<< HEAD 'FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE' => 'The PostgreSQL fulltext backend can only be used with PostgreSQL.', 'FULLTEXT_POSTGRES_TS_NOT_USABLE' => 'The PostgreSQL fulltext backend can only be used with PostgreSQL 8.3 and above.', 'FULLTEXT_POSTGRES_TOTAL_POSTS' => 'Total number of indexed posts', @@ -70,8 +69,6 @@ $lang = array_merge($lang, array( 'FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN' => 'Words with at least this many characters will be included in the query to the database.', 'FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN' => 'Words with no more than this many characters will be included in the query to the database.', - 'FULLTEXT_SPHINX_BIN_PATH' => 'Path to executables directory', - 'FULLTEXT_SPHINX_BIN_PATH_EXPLAIN' => 'Skip if autorun is disabled. If this path could not be determined automatically you have to enter the path to the directory in which the sphinx executables indexer and searchd reside.', 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'Skip if autoconf is disabled. You should create this config directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody).', 'FULLTEXT_SPHINX_CONFIGURE_FIRST' => 'Before you create an index you have to enable and configure sphinx under GENERAL -> SERVER CONFIGURATION -> Search settings.', From 4b40f0d3c6d14adc2b20b866cbeb42586cf8d874 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 16:25:19 +0530 Subject: [PATCH 031/259] [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 +++++++++++++--------- phpBB/language/en/acp/search.php | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) 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 diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 9618bb90c5..778f9ddec5 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -85,6 +85,9 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', + 'FULLTEXT_SPHINX_CONFIG_FILE' => 'Sphinx config file', + 'FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN' => 'The generated content of the sphinx config file. This data needs to be pasted into the sphinx.conf which is used by sphinx search daemon.', + 'FULLTEXT_SPHINX_NO_CONFIG_DATA' => 'The sphinx data and config directory paths are not defined. Please define them to generate the config file.', 'GENERAL_SEARCH_SETTINGS' => 'General search settings', 'GO_TO_SEARCH_INDEX' => 'Go to search index page', From 172c583f1941a8b162f1a7bf258bb3e38149606d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 16:57:18 +0530 Subject: [PATCH 032/259] [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/docs/sphinx.sample.conf | 16 ++++++++-------- phpBB/includes/search/fulltext_sphinx.php | 15 ++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index 000d8157d6..06595a766f 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -1,4 +1,4 @@ -source source_phpbb_{AVATAR_SALT}_main +source source_phpbb_{SPHINX_ID}_main { type = mysql sql_host = localhost @@ -38,7 +38,7 @@ source source_phpbb_{AVATAR_SALT}_main sql_attr_timestamp = topic_last_post_time sql_attr_str2ordinal = post_subject } -source source_phpbb_{AVATAR_SALT}_delta : source_phpbb_{AVATAR_SALT}_main +source source_phpbb_{SPHINX_ID}_delta : source_phpbb_{SPHINX_ID}_main { sql_query_range = sql_range_step = @@ -60,10 +60,10 @@ source source_phpbb_{AVATAR_SALT}_delta : source_phpbb_{AVATAR_SALT}_main AND p.post_id >= ( SELECT max_doc_id FROM phpbb_sphinx WHERE counter_id=1 ) sql_query_pre = } -index index_phpbb_{AVATAR_SALT}_main +index index_phpbb_{SPHINX_ID}_main { - path = {DATA_PATH}/index_phpbb_{AVATAR_SALT}_main - source = source_phpbb_{AVATAR_SALT}_main + path = {DATA_PATH}/index_phpbb_{SPHINX_ID}_main + source = source_phpbb_{SPHINX_ID}_main docinfo = extern morphology = none stopwords = @@ -73,10 +73,10 @@ index index_phpbb_{AVATAR_SALT}_main min_prefix_len = 0 min_infix_len = 0 } -index index_phpbb_{AVATAR_SALT}_delta : index_phpbb_{AVATAR_SALT}_main +index index_phpbb_{SPHINX_ID}_delta : index_phpbb_{SPHINX_ID}_main { - path = {DATA_PATH}/index_phpbb_{AVATAR_SALT}_delta - source = source_phpbb_{AVATAR_SALT}_delta + path = {DATA_PATH}/index_phpbb_{SPHINX_ID}_delta + source = source_phpbb_{SPHINX_ID}_delta } indexer { 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( From b8103c5c31cbb42a46a40ac10c34ff09dc5efc60 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 17:10:51 +0530 Subject: [PATCH 033/259] [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(-) 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) From 78e7f2a5290dc152cf2e386553e6308c74e2d005 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 17:32:31 +0530 Subject: [PATCH 034/259] [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 ++++++++--- .../includes/search/sphinx/config_comment.php | 6 ++++- .../includes/search/sphinx/config_section.php | 26 ++++++++++++++++--- .../search/sphinx/config_variable.php | 14 +++++++--- 4 files changed, 50 insertions(+), 11 deletions(-) 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() { From f40da411c389cb7718d31f1ee20f8487f25969f0 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 11 Jul 2012 17:46:58 +0530 Subject: [PATCH 035/259] [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 +-- phpBB/language/en/acp/search.php | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) 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'] . '
diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 778f9ddec5..970d9cd41b 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -70,12 +70,10 @@ $lang = array_merge($lang, array( 'FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN' => 'Words with no more than this many characters will be included in the query to the database.', 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', - 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'Skip if autoconf is disabled. You should create this config directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody).', - 'FULLTEXT_SPHINX_CONFIGURE_FIRST' => 'Before you create an index you have to enable and configure sphinx under GENERAL -> SERVER CONFIGURATION -> Search settings.', - 'FULLTEXT_SPHINX_CONFIGURE_BEFORE' => 'Configure the following settings BEFORE activating Sphinx', - 'FULLTEXT_SPHINX_CONFIGURE_AFTER' => 'The following settings do not have to be configured before activating Sphinx', + 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'You should put the sphinx.conf file in this directory. This config directory should be outside the web accessable directories.', + 'FULLTEXT_SPHINX_CONFIGURE' => 'Configure the following settings to generate sphinx config file', 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', - 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'Skip if autorun is disabled. You should create this directory outside the web accessable directories. It has to be writable by the user as which your webserver is running (often www-data or nobody). It will be used to store the indexes and log files.', + 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'It will be used to store the indexes and log files. You should create this directory outside the web accessable directories.', 'FULLTEXT_SPHINX_DELTA_POSTS' => 'Number of posts in frequently updated delta index', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', @@ -84,7 +82,7 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', - 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'This setting only works with autoconf enabled. You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', + 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', 'FULLTEXT_SPHINX_CONFIG_FILE' => 'Sphinx config file', 'FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN' => 'The generated content of the sphinx config file. This data needs to be pasted into the sphinx.conf which is used by sphinx search daemon.', 'FULLTEXT_SPHINX_NO_CONFIG_DATA' => 'The sphinx data and config directory paths are not defined. Please define them to generate the config file.', From 13c451ca2e9a6717a8a98943ba022a6f41dcdd9c Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 04:13:34 +0530 Subject: [PATCH 036/259] [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(-) 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; } From 118b57f71d9f563f8eeda8e5925d482c38ab1af8 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 04:28:55 +0530 Subject: [PATCH 037/259] [feature/sphinx-fulltext-search] minor changes in sphinx.conf PHPBB3-10946 --- phpBB/docs/sphinx.sample.conf | 4 ++-- phpBB/includes/search/fulltext_sphinx.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index 06595a766f..eaef081aa1 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -6,6 +6,8 @@ source source_phpbb_{SPHINX_ID}_main sql_pass = password sql_db = db_name sql_port = 3306 #optional, default is 3306 + sql_query_pre = SET NAMES 'utf8' + sql_query_pre = REPLACE INTO phpbb_sphinx SELECT 1, MAX(post_id) FROM phpbb_posts sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM phpbb_posts sql_range_step = 5000 sql_query = SELECT \ @@ -27,8 +29,6 @@ source source_phpbb_{SPHINX_ID}_main sql_query_post = sql_query_post_index = REPLACE INTO phpbb_sphinx ( counter_id, max_doc_id ) VALUES ( 1, $maxid ) sql_query_info = SELECT * FROM phpbb_posts WHERE post_id = $id - sql_query_pre = SET NAMES utf8 - sql_query_pre = REPLACE INTO phpbb_sphinx SELECT 1, MAX(post_id) FROM phpbb_posts sql_attr_uint = forum_id sql_attr_uint = topic_id sql_attr_uint = poster_id 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'), From b81941a997760eca4f209cc100fe2baec3ef4468 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 16:30:45 +0530 Subject: [PATCH 038/259] [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/docs/sphinx.sample.conf | 4 ++-- phpBB/includes/search/fulltext_sphinx.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index eaef081aa1..3ab2552096 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -15,7 +15,7 @@ source source_phpbb_{SPHINX_ID}_main 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, \ @@ -47,7 +47,7 @@ source source_phpbb_{SPHINX_ID}_delta : source_phpbb_{SPHINX_ID}_main 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, \ 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, From 81959927e53ebc62765ff075d23feeaf9b40a95d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 17:22:03 +0530 Subject: [PATCH 039/259] [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/docs/sphinx.sample.conf | 4 ++-- phpBB/includes/search/fulltext_sphinx.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index 3ab2552096..8ffd54a880 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -7,7 +7,7 @@ source source_phpbb_{SPHINX_ID}_main sql_db = db_name sql_port = 3306 #optional, default is 3306 sql_query_pre = SET NAMES 'utf8' - sql_query_pre = REPLACE INTO phpbb_sphinx SELECT 1, MAX(post_id) FROM phpbb_posts + sql_query_pre = UPDATE phpbb_sphinx SET max_doc_id = MAX(post_id) WHERE counter_id = 1 sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM phpbb_posts sql_range_step = 5000 sql_query = SELECT \ @@ -27,7 +27,7 @@ source source_phpbb_{SPHINX_ID}_main p.topic_id = t.topic_id \ AND p.post_id >= $start AND p.post_id <= $end sql_query_post = - sql_query_post_index = REPLACE INTO phpbb_sphinx ( counter_id, max_doc_id ) VALUES ( 1, $maxid ) + sql_query_post_index = UPDATE phpbb_sphinx SET max_doc_id = $maxid WHERE counter_id = 1 sql_query_info = SELECT * FROM phpbb_posts WHERE post_id = $id sql_attr_uint = forum_id sql_attr_uint = topic_id 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; From 609ce3ae8fb55e717ff188d2ec9c10c6ae252b7a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 17:48:17 +0530 Subject: [PATCH 040/259] [feature/sphinx-fulltext-search] add pgsql functionality PHPBB3-10946 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- phpBB/language/en/acp/search.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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']; } diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 970d9cd41b..4aa9c89cde 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -80,7 +80,7 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', 'FULLTEXT_SPHINX_PORT' => 'Sphinx search deamon port', 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', - 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx plugin for phpBB currently only supports MySQL', + 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx search for phpBB supports MySQL and PostgreSQL only.', 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', 'FULLTEXT_SPHINX_CONFIG_FILE' => 'Sphinx config file', From a3d103c9c03c79fe67963b9db5a5471c766fa401 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 12 Jul 2012 18:08:50 +0530 Subject: [PATCH 041/259] [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(-) 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) . '
'; From 3ecc81f853bb1ec6262fc0615bb0ab8704616db9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 21 Jul 2012 14:14:19 +0530 Subject: [PATCH 042/259] [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(-) 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 { From 1f77b95fe71e727238212ea4632220ae9cab99d7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 01:49:30 +0530 Subject: [PATCH 043/259] [feature/sphinx-fulltext-search] fix language keys' typo PHPBB3-10946 --- phpBB/language/en/acp/search.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 4aa9c89cde..37c403f43d 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -69,8 +69,8 @@ $lang = array_merge($lang, array( 'FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN' => 'Words with at least this many characters will be included in the query to the database.', 'FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN' => 'Words with no more than this many characters will be included in the query to the database.', - 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to configuration directory', - 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'You should put the sphinx.conf file in this directory. This config directory should be outside the web accessable directories.', + 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to config directory', + 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'You should put the sphinx.conf file in this directory. This config directory should be outside the web accessible directories.', 'FULLTEXT_SPHINX_CONFIGURE' => 'Configure the following settings to generate sphinx config file', 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'It will be used to store the indexes and log files. You should create this directory outside the web accessable directories.', @@ -78,8 +78,8 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', - 'FULLTEXT_SPHINX_PORT' => 'Sphinx search deamon port', - 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search deamon on localhost listens. Leave empty to use the default 3312', + 'FULLTEXT_SPHINX_PORT' => 'Sphinx search daemon port', + 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search daemon (searchd) listens. Leave empty to use the default 3312', 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx search for phpBB supports MySQL and PostgreSQL only.', 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', From 0e9eb9401a38fab3139a1df33fa7e0903ccfb18f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 01:53:04 +0530 Subject: [PATCH 044/259] [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(-) 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) . '
'; From 161e469b5a67b2911089ec0dfdb70bef355ed07e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 02:50:53 +0530 Subject: [PATCH 045/259] [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/docs/sphinx.sample.conf | 4 ++-- phpBB/includes/search/fulltext_sphinx.php | 9 +++++++-- phpBB/language/en/acp/search.php | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index 8ffd54a880..d0a897e0cc 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -1,7 +1,7 @@ source source_phpbb_{SPHINX_ID}_main { - type = mysql - sql_host = localhost + type = mysql #mysql or pgsql + sql_host = localhost #SQL server host sphinx connects to sql_user = username sql_pass = password sql_db = db_name 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'] . '
diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 37c403f43d..99fbbac07e 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -75,6 +75,8 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'It will be used to store the indexes and log files. You should create this directory outside the web accessable directories.', 'FULLTEXT_SPHINX_DELTA_POSTS' => 'Number of posts in frequently updated delta index', + 'FULLTEXT_SPHINX_HOST' => 'SQL server host', + 'FULLTEXT_SPHINX_HOST_EXPLAIN' => 'SQL server host, which the sphinx search daemon (searchd) connects to. Leave empty to use the default SQL server host', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT' => 'Indexer memory limit', 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', From e40758db84a23bc7a2c5324dbedcd7f0911abeea Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 03:16:03 +0530 Subject: [PATCH 046/259] [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 ++------------ phpBB/language/en/acp/search.php | 4 ---- 2 files changed, 2 insertions(+), 16 deletions(-) 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'] . '
diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 99fbbac07e..6d9201fb11 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -69,8 +69,6 @@ $lang = array_merge($lang, array( 'FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN' => 'Words with at least this many characters will be included in the query to the database.', 'FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN' => 'Words with no more than this many characters will be included in the query to the database.', - 'FULLTEXT_SPHINX_CONFIG_PATH' => 'Path to config directory', - 'FULLTEXT_SPHINX_CONFIG_PATH_EXPLAIN' => 'You should put the sphinx.conf file in this directory. This config directory should be outside the web accessible directories.', 'FULLTEXT_SPHINX_CONFIGURE' => 'Configure the following settings to generate sphinx config file', 'FULLTEXT_SPHINX_DATA_PATH' => 'Path to data directory', 'FULLTEXT_SPHINX_DATA_PATH_EXPLAIN' => 'It will be used to store the indexes and log files. You should create this directory outside the web accessable directories.', @@ -83,8 +81,6 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_PORT' => 'Sphinx search daemon port', 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search daemon (searchd) listens. Leave empty to use the default 3312', 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx search for phpBB supports MySQL and PostgreSQL only.', - 'FULLTEXT_SPHINX_STOPWORDS_FILE' => 'Stopwords activated', - 'FULLTEXT_SPHINX_STOPWORDS_FILE_EXPLAIN' => 'You can place a file called sphinx_stopwords.txt containing one word in each line in your config directory. If this file is present these words will be excluded from the indexing process.', 'FULLTEXT_SPHINX_CONFIG_FILE' => 'Sphinx config file', 'FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN' => 'The generated content of the sphinx config file. This data needs to be pasted into the sphinx.conf which is used by sphinx search daemon.', 'FULLTEXT_SPHINX_NO_CONFIG_DATA' => 'The sphinx data and config directory paths are not defined. Please define them to generate the config file.', From 39bac86f7db881a1035bebad56507145103218d5 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 22 Jul 2012 03:43:50 +0530 Subject: [PATCH 047/259] [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/docs/sphinx.sample.conf | 5 ++--- phpBB/includes/search/fulltext_sphinx.php | 7 +++---- phpBB/language/en/acp/search.php | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/phpBB/docs/sphinx.sample.conf b/phpBB/docs/sphinx.sample.conf index d0a897e0cc..aa0e8d905d 100644 --- a/phpBB/docs/sphinx.sample.conf +++ b/phpBB/docs/sphinx.sample.conf @@ -5,7 +5,7 @@ source source_phpbb_{SPHINX_ID}_main sql_user = username sql_pass = password sql_db = db_name - sql_port = 3306 #optional, default is 3306 + sql_port = 3306 #optional, default is 3306 for mysql and 5432 for pgsql sql_query_pre = SET NAMES 'utf8' sql_query_pre = UPDATE phpbb_sphinx SET max_doc_id = MAX(post_id) WHERE counter_id = 1 sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM phpbb_posts @@ -85,8 +85,7 @@ indexer searchd { compat_sphinxql_magics = 0 - listen = 127.0.0.1 - port = 3312 + listen = localhost:9312 log = {DATA_PATH}/log/searchd.log query_log = {DATA_PATH}/log/sphinx-query.log read_timeout = 5 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', ); diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index 6d9201fb11..394d408fdb 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -79,7 +79,7 @@ $lang = array_merge($lang, array( 'FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN' => 'This number should at all times be lower than the RAM available on your machine. If you experience periodic performance problems this might be due to the indexer consuming too many resources. It might help to lower the amount of memory available to the indexer.', 'FULLTEXT_SPHINX_MAIN_POSTS' => 'Number of posts in main index', 'FULLTEXT_SPHINX_PORT' => 'Sphinx search daemon port', - 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search daemon (searchd) listens. Leave empty to use the default 3312', + 'FULLTEXT_SPHINX_PORT_EXPLAIN' => 'Port on which the sphinx search daemon (searchd) listens. Leave empty to use the default Sphinx API port 3312 ', 'FULLTEXT_SPHINX_WRONG_DATABASE' => 'The sphinx search for phpBB supports MySQL and PostgreSQL only.', 'FULLTEXT_SPHINX_CONFIG_FILE' => 'Sphinx config file', 'FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN' => 'The generated content of the sphinx config file. This data needs to be pasted into the sphinx.conf which is used by sphinx search daemon.', From 22951e43674d023f43edc8da7ade33f01b5428c8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 23 Jul 2012 17:02:40 +0200 Subject: [PATCH 048/259] [ticket/11004] Make suggestion button a real button and fix it's value PHPBB3-11004 --- phpBB/styles/prosilver/template/timezone_option.html | 2 +- phpBB/styles/subsilver2/template/timezone_option.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/template/timezone_option.html b/phpBB/styles/prosilver/template/timezone_option.html index 94e2bbdfbd..24d6aa677f 100644 --- a/phpBB/styles/prosilver/template/timezone_option.html +++ b/phpBB/styles/prosilver/template/timezone_option.html @@ -6,7 +6,7 @@ {S_TZ_DATE_OPTIONS} - +
diff --git a/phpBB/styles/subsilver2/template/timezone_option.html b/phpBB/styles/subsilver2/template/timezone_option.html index 3f1e14b33d..c7e47a8ee4 100644 --- a/phpBB/styles/subsilver2/template/timezone_option.html +++ b/phpBB/styles/subsilver2/template/timezone_option.html @@ -7,7 +7,7 @@ {S_TZ_DATE_OPTIONS}
- + '; - if ($db->sql_layer == 'postgres' && $this->tsearch_usable) + if ($this->db->sql_layer == 'postgres' && $this->tsearch_usable) { $sql = 'SELECT cfgname AS ts_name FROM pg_ts_config'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { - $tpl .= ''; + $tpl .= ''; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } else { - $tpl .= ''; + $tpl .= ''; } $tpl .= '
-

' . $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'] . '
+
'; From 33c6d7c8be41ddd15b4e03e5dfecfd259c77b327 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 23 Jul 2012 15:41:15 +0530 Subject: [PATCH 064/259] [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(-) 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'] . '
+
%
'; From 2e218776bbac82841e1ced583c83890be5080af0 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 24 Jul 2012 12:10:22 +0530 Subject: [PATCH 065/259] [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 ---- phpBB/search.php | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) 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); } diff --git a/phpBB/search.php b/phpBB/search.php index efbf2f4dfe..68946e2a95 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -280,7 +280,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) } // 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, $config, $db, $user); if ($error) { From d982a37f191ffb731633a6adf6f86416787080db Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 28 Jul 2012 18:25:26 +0530 Subject: [PATCH 066/259] [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(-) 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 From 9eb6c2ba5b6fb1c1090f5a89387a8fa8ae958a85 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 28 Jul 2012 18:50:56 +0530 Subject: [PATCH 067/259] [ticket/11011] remove global keyword from sphinx PHPBB3-11011 --- phpBB/includes/search/fulltext_sphinx.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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)); From 647d395908a6e852acef9ec65aa649eb3754a1d2 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 30 Jul 2012 12:54:00 +0100 Subject: [PATCH 068/259] [ticket/11034] Re-arranged install order to emulate real install PHPBB3-11034 --- tests/test_framework/phpbb_functional_test_case.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index ed8ce9d040..2423299b7c 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -139,13 +139,11 @@ class phpbb_functional_test_case extends phpbb_test_case $this->do_request('create_table', $data); + $this->do_request('config_file', $data); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true)); - $this->do_request('config_file', $data); - - copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); - $this->do_request('final', $data); + copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } private function do_request($sub, $post_data = null) From 828eaecf6ab4f6c013a7955bf6af2a81c049e42f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 15:24:31 -0500 Subject: [PATCH 069/259] [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(-) 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); From edcac438df164764c84ca9fb7a7f751bf76d5c34 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 15:57:51 -0500 Subject: [PATCH 070/259] [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(-) 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); From 2c1da15ae83e292d3aa9c94f740d6bff6bfd238e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 16:23:18 -0500 Subject: [PATCH 071/259] [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(-) 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']))) From 01bc818d465ab168288e260745a045ff2794648d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 18:44:40 -0500 Subject: [PATCH 072/259] [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 +++--- phpBB/install/install_update.php | 2 +- 15 files changed, 31 insertions(+), 31 deletions(-) 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); } diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index c2feaa086a..88b00f1cf1 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -349,7 +349,7 @@ class install_update extends module // We are directly within an update. To make sure our update list is correct we check its status. $update_list = ($request->variable('check_again', false, false, phpbb_request_interface::POST)) ? false : $cache->get('_update_list'); - $modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0; + $modified = ($update_list !== false) ? @filemtime($cache->get_driver()->cache_dir . 'data_update_list.' . $phpEx) : 0; // Make sure the list is up-to-date if ($update_list !== false) From 3c20ac71c51c9e8033884f5694fbad2fa6040ca6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 4 Mar 2011 02:00:54 -0500 Subject: [PATCH 073/259] [feature/events] Started on hooks for advanced last topic titles mod. PHPBB3-9550 --- phpBB/includes/functions_display.php | 9 +++++++++ 1 file changed, 9 insertions(+) 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) From 4da001625df4cc13d71e0ae6a61d573207165a7f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 3 Feb 2012 02:22:29 -0500 Subject: [PATCH 074/259] [feature/events] Replace run_hooks calls with event dispatcher. PHPBB3-9550 --- phpBB/includes/functions_display.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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) From 9877ab1ff36dd66ccc517ffeb00832ff12ee7995 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 4 Feb 2012 07:12:00 -0500 Subject: [PATCH 075/259] [feature/events] Add core.memberlist_profile_data ledge. This is needed by the avatars on memberlist modification. PHPBB3-9550 --- phpBB/memberlist.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 4f9a8cdff3..0845eb23f6 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1693,7 +1693,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f } // Dump it out to the template - return array( + $data = array( 'AGE' => $age, 'RANK_TITLE' => $rank_title, 'JOINED' => $user->format_date($data['user_regdate']), @@ -1741,6 +1741,13 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username), ); + + $vars = array('data'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.memberlist_profile_data', $event); + extract($event->get_data_filtered($vars)); + + return $data; } function _sort_last_active($first, $second) From eda9bcc65de97b9ffb2c432756907ff0411b281f Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 15:14:01 +0000 Subject: [PATCH 076/259] [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(-) 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))); From 77845c147818b4199005363a3168bbb44dc46641 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:55:17 +0100 Subject: [PATCH 077/259] [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(-) 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); } From 5b226c400280588349eb3a4cab9780ae98d20c0f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:58:22 +0100 Subject: [PATCH 078/259] [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(-) 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) { From ae49d6dca2fd17b2b4735c2026871d1a9250b4ad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:59:15 +0100 Subject: [PATCH 079/259] [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(-) 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"; From d4ace75370febea0f9a18ed2f744bee8caecedb2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 21:00:20 +0100 Subject: [PATCH 080/259] [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(-) 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); From 4d87b2254c7762db129b2706b372538451279d13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 21:01:49 +0100 Subject: [PATCH 081/259] [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(-) 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); From bd3024b31875b220f8f00cafd81846b1f6aeeff2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 00:05:18 +0100 Subject: [PATCH 082/259] [feature/events] Adding ledge viewonline_location Used by phpBB Gallery PHPBB3-9550 --- phpBB/viewonline.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 48362a9d67..e709955653 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -317,6 +317,11 @@ while ($row = $db->sql_fetchrow($result)) default: $location = $user->lang['INDEX']; $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); + + $vars = array('on_page', 'row', 'location', 'location_url'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.viewonline_location', $event); + extract($event->get_data_filtered($vars)); break; } From 433442b40261d7d18427b6cd21fbf9acb15edd93 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 00:14:20 +0100 Subject: [PATCH 083/259] [feature/events] Adding ledge viewonline_get_userdata Used by phpBB Gallery PHPBB3-9550 --- phpBB/viewonline.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index e709955653..55d663de20 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -121,13 +121,24 @@ if (!$show_guests) } // Get user list -$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_type, u.user_colour, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_browser, s.session_viewonline, s.session_forum_id - FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . ' s - WHERE u.user_id = s.session_user_id +$sql_ary = array( + 'SELECT' => 'u.user_id, u.username, u.username_clean, u.user_type, u.user_colour, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_browser, s.session_viewonline, s.session_forum_id', + 'FROM' => array( + USERS_TABLE => 'u', + SESSIONS_TABLE => 's', + ), + 'WHERE' => 'u.user_id = s.session_user_id AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) . - ((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : '') . ' - ORDER BY ' . $order_by; -$result = $db->sql_query($sql); + ((!$show_guests) ? ' AND s.session_user_id <> ' . ANONYMOUS : ''), + 'ORDER_BY' => $order_by, +); + +$vars = array('sql_ary', 'show_guests'); +$event = new phpbb_event_data(compact($vars)); +$phpbb_dispatcher->dispatch('core.viewonline_get_userdata', $event); +extract($event->get_data_filtered($vars)); + +$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); $prev_id = $prev_ip = $user_list = array(); $logged_visible_online = $logged_hidden_online = $counter = 0; From 60b21863cada022b9fdcda17de82aa484c4ac571 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 00:38:45 +0100 Subject: [PATCH 084/259] [feature/events] Adding ledge index Used by phpBB Gallery and various others PHPBB3-9550 --- phpBB/index.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/index.php b/phpBB/index.php index a477a876ad..87b0adeafd 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -171,8 +171,15 @@ $template->assign_vars(array( 'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '') ); +$page_title = $user->lang['INDEX']; + +$vars = array('page_title'); +$event = new phpbb_event_data(compact($vars)); +$phpbb_dispatcher->dispatch('core.index', $event); +extract($event->get_data_filtered($vars)); + // Output page -page_header($user->lang['INDEX']); +page_header($page_title); $template->set_filenames(array( 'body' => 'index_body.html') From 34a85639422214af23c6e56d175e5634c24db798 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 00:43:52 +0100 Subject: [PATCH 085/259] [feature/events] Adding ledge ucp_modules Used by phpBB Gallery PHPBB3-9550 --- phpBB/ucp.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/ucp.php b/phpBB/ucp.php index 64afa0be67..2b129f3ec7 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -328,6 +328,11 @@ if (!$auth->acl_get('u_sig')) $module->set_display('profile', 'signature', false); } +$vars = array('module'); +$event = new phpbb_event_data(compact($vars)); +$phpbb_dispatcher->dispatch('core.ucp_modules', $event); +extract($event->get_data_filtered($vars)); + // Select the active module $module->set_active($id, $mode); From ca8de4129cbedf8eff2d97350300f59b4bf47230 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 00:49:38 +0100 Subject: [PATCH 086/259] [feature/events] Adding ledge memberlist_viewprofile Used by phpBB Gallery Note: this one is NOT obsoleted by the ledge in show_profile() PHPBB3-9550 --- phpBB/memberlist.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 0845eb23f6..108195dad8 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -575,6 +575,11 @@ switch ($mode) unset($module); } + $vars = array('member', 'user_notes_enabled', 'warn_user_enabled'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.memberlist_viewprofile', $event); + extract($event->get_data_filtered($vars)); + $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); // Custom Profile Fields From 57c417157761cea7e4c0cdece0bdf9068f25dbbe Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 20:47:59 +0000 Subject: [PATCH 087/259] [feature/events] Add core.viewforum_forumrow PHPBB3-9550 --- phpBB/viewforum.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 18d247f0b6..2d5b7e0758 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -690,7 +690,7 @@ if (sizeof($topic_list)) $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : ''; // Send vars to template - $template->assign_block_vars('topicrow', array( + $forumrow = array( 'FORUM_ID' => $row['forum_id'], 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), @@ -742,11 +742,18 @@ if (sizeof($topic_list)) 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&f=' . $row['forum_id'] . '&t=' . $topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue, - 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test) + 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test ); + $vars = array('forumrow'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.viewforum_forumrow', $event); + extract($event->get_data_filtered($vars)); + + $template->assign_block_vars('topicrow', $forumrow); + phpbb_generate_template_pagination($template, $view_topic_url, 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true); - + $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0; if ($unread_topic) From 6c50f6610f66b865e6fa6ee82235c3ff373fdfd3 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 00:02:35 +0000 Subject: [PATCH 088/259] [feature/events] Fix core.viewforum_topicrow ledge PHPBB3-9550 --- phpBB/viewforum.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 2d5b7e0758..dac4230ce0 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -690,7 +690,7 @@ if (sizeof($topic_list)) $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : ''; // Send vars to template - $forumrow = array( + $topicrow = array( 'FORUM_ID' => $row['forum_id'], 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), @@ -742,15 +742,15 @@ if (sizeof($topic_list)) 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&f=' . $row['forum_id'] . '&t=' . $topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue, - 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test + 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test, ); - $vars = array('forumrow'); + $vars = array('topicrow'); $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.viewforum_forumrow', $event); + $phpbb_dispatcher->dispatch('core.viewforum_topicrow', $event); extract($event->get_data_filtered($vars)); - $template->assign_block_vars('topicrow', $forumrow); + $template->assign_block_vars('topicrow', $topicrow); phpbb_generate_template_pagination($template, $view_topic_url, 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true); From 54caef8f902cf5ea40da0d818b770d15b6d7e7e2 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 20:49:33 +0000 Subject: [PATCH 089/259] [feature/events] Add core.viewtopic_postrow ledge PHPBB3-9550 --- phpBB/viewtopic.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 349f53cbe2..4f95d40e73 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1574,6 +1574,11 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) $postrow = array_merge($postrow, $cp_row['row']); } + $vars = array('postrow'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.viewtopic_postrow', $event); + extract($event->get_data_filtered($vars)); + // Dump vars into template $template->assign_block_vars('postrow', $postrow); From eb7a04d32427d2070befdd10fcec657222bc8fa8 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 21:06:44 +0000 Subject: [PATCH 090/259] [feature/events] Add core.acp_foruns_add_forum_data ledge PHPBB3-9550 --- phpBB/includes/acp/acp_forums.php | 5 +++++ 1 file changed, 5 insertions(+) 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; From 19a3164e80e9e34cab13d25f205789d7eb27aa66 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Thu, 15 Mar 2012 23:59:40 +0000 Subject: [PATCH 091/259] [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(-) 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; From 365a71d63f01d6a8d65b5eafcd4d5fa2fb7ab0ac Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 16 Mar 2012 02:12:29 -0400 Subject: [PATCH 092/259] [feature/events] Add missing dispatcher globalization. PHPBB3-9550 --- phpBB/memberlist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 108195dad8..81369a9b57 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1636,7 +1636,7 @@ page_footer(); */ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false) { - global $config, $auth, $template, $user, $phpEx, $phpbb_root_path; + global $config, $auth, $template, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher; $username = $data['username']; $user_id = $data['user_id']; From 5c0decf4cf7d6f73ffa686e8861aa3c444f51124 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 12:34:26 +0000 Subject: [PATCH 093/259] [feature/events] Adding core.acp_users_overview ledge PHPBB3-9550 --- phpBB/includes/acp/acp_users.php | 5 +++++ 1 file changed, 5 insertions(+) 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': From 74d3555c4c510a76c947bd7c445f254e5b9b104e Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 13:09:33 +0000 Subject: [PATCH 094/259] [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(-) 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() From f362d374cc8e421951d25de038708b06b5b4695d Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 13:33:02 +0000 Subject: [PATCH 095/259] [feature/events] Adding core.acp_profile_edit ledge PHPBB3-9550 --- phpBB/includes/acp/acp_profile.php | 5 +++++ 1 file changed, 5 insertions(+) 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; } From 3339935db316859b38a820b7cf3ebff204b72d7f Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 14:58:29 +0000 Subject: [PATCH 096/259] [feature/events] Adding core.common ledge PHPBB3-9550 --- phpBB/common.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/common.php b/phpBB/common.php index 81fe275008..9cf2617b07 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -143,3 +143,5 @@ if (!$config['use_system_cron']) { $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); } + +$phpbb_dispatcher->dispatch('core.common'); From a47ac64e5f5ad1c01e6ecbb64a5e1c80ab2c90b2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 10:30:28 +0100 Subject: [PATCH 097/259] [feature/events] Adding ledge viewtopic_page_header Used by phpBB Gallery PHPBB3-9550 --- phpBB/viewtopic.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 4f95d40e73..148446490e 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1734,8 +1734,15 @@ if (!request_var('t', 0) && !empty($topic_id)) $request->overwrite('t', $topic_id); } +$page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : ''); + +$vars = array('page_title', 'topic_data', 'forum_id', 'start'); +$event = new phpbb_event_data(compact($vars)); +$phpbb_dispatcher->dispatch('core.viewtopic_page_header', $event); +extract($event->get_data_filtered($vars)); + // Output the page -page_header($topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : ''), true, $forum_id); +page_header($page_title, true, $forum_id); $template->set_filenames(array( 'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html') From dcf97714a56801bcaf41addeadb08bcacc4514df Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 10:38:29 +0100 Subject: [PATCH 098/259] [feature/events] Adding ledge viewtopic_get_userdata Used by phpBB Gallery PHPBB3-9550 --- phpBB/viewtopic.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 148446490e..8bca1973a7 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -987,6 +987,11 @@ $sql_ary = array( AND u.user_id = p.poster_id', ); +$vars = array('sql_ary'); +$event = new phpbb_event_data(compact($vars)); +$phpbb_dispatcher->dispatch('core.viewtopic_get_userdata', $event); +extract($event->get_data_filtered($vars)); + $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); From 2581b0e1e3c68bfae8357dddc1d379914fd67654 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 10:42:40 +0100 Subject: [PATCH 099/259] [feature/events] Adding ledge viewtopic_user_cache_guest Used by phpBB Gallery PHPBB3-9550 --- phpBB/viewtopic.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 8bca1973a7..256bada0d9 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1068,7 +1068,7 @@ while ($row = $db->sql_fetchrow($result)) { if ($poster_id == ANONYMOUS) { - $user_cache[$poster_id] = array( + $user_cache_data = array( 'joined' => '', 'posts' => '', 'from' => '', @@ -1103,6 +1103,13 @@ while ($row = $db->sql_fetchrow($result)) 'allow_pm' => 0, ); + $vars = array('user_cache_data', 'row', 'poster_id'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.viewtopic_user_cache_guest', $event); + extract($event->get_data_filtered($vars)); + + $user_cache[$poster_id] = $user_cache_data; + get_user_rank($row['user_rank'], false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); } else From 713f8e4782cd4c808d6f4a1cbb26f45144eef74e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 10:51:35 +0100 Subject: [PATCH 100/259] [feature/events] Adding ledge viewtopic_user_cache Used by phpBB Gallery PHPBB3-9550 --- phpBB/viewtopic.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 256bada0d9..99b875ae3d 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1124,7 +1124,7 @@ while ($row = $db->sql_fetchrow($result)) $id_cache[] = $poster_id; - $user_cache[$poster_id] = array( + $user_cache_data = array( 'joined' => $user->format_date($row['user_regdate']), 'posts' => $row['user_posts'], 'warnings' => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0, @@ -1162,6 +1162,13 @@ while ($row = $db->sql_fetchrow($result)) 'author_profile' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour']), ); + $vars = array('user_cache_data', 'row', 'poster_id'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.viewtopic_user_cache', $event); + extract($event->get_data_filtered($vars)); + + $user_cache[$poster_id] = $user_cache_data; + get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']); if ((!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_email')) From ddcd1890065258ca5a5d443b8790a9d2287891ad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:03:03 +0100 Subject: [PATCH 101/259] [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(-) 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(); From 69407cae7bc50af526db86a3be3718d68f57d2bc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:21:12 +0100 Subject: [PATCH 102/259] [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(-) 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++; } From 1a7f83948eb9f4c1b8ab7fa411444a11e967fcd0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:22:31 +0100 Subject: [PATCH 103/259] [feature/events] Adding ledge display_custom_bbcodes Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_display.php | 2 ++ 1 file changed, 2 insertions(+) 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'); } /** From 8d4c7d2e80a17b2ec5134e4dbe7fea5bfe57d02f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:29:49 +0100 Subject: [PATCH 104/259] [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(-) 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'])) { From 02244397d1ecb149322c0c7847718e14742c14a2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:37:46 +0100 Subject: [PATCH 105/259] [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(-) 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']); From 4b4e2afd800d34b2f92f709f9199c38334f43b29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:40:01 +0100 Subject: [PATCH 106/259] [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(+) 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; From 1aa7bc81f6200389499080fa3863f6708d94dc70 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Mar 2012 11:47:27 +0100 Subject: [PATCH 107/259] [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(-) 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'); From e17d0daf518f2f4bb22146c195a342858faf1fce Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 18:58:46 +0000 Subject: [PATCH 108/259] [feature/events] Adding core.mcp_check_ids ledge PHPBB3-9550 --- phpBB/mcp.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/mcp.php b/phpBB/mcp.php index d04a297cf9..b5cfa99d4c 100644 --- a/phpBB/mcp.php +++ b/phpBB/mcp.php @@ -823,7 +823,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, */ function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false) { - global $db, $auth; + global $db, $auth, $phpbb_dispatcher; if (!is_array($ids) || empty($ids)) { @@ -889,5 +889,7 @@ function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = fa // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id) + $phpbb_dispatcher->dispatch('core.mcp_check_ids'); + return ($single_forum === false) ? true : (int) $forum_id; } From 643081d56c1a984e3b0cf4f942392c5a392c9ed6 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 16 Mar 2012 19:03:52 +0000 Subject: [PATCH 109/259] [feature/events] Adding core.mcp_forum_topicrow ledge PHPBB3-9550 --- phpBB/includes/mcp/mcp_forum.php | 5 +++++ 1 file changed, 5 insertions(+) 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); From b966551e6bef9dfd272734587fe4bc9ca7e4611c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 00:46:43 +0100 Subject: [PATCH 110/259] [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(-) 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 From ba63df2dce9da69caa31f1f4404b3b79a7f4f75e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 17 Mar 2012 11:45:09 +0100 Subject: [PATCH 111/259] [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(-) 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() From 8af7d225ef481cd26e6fd7862847183d25727117 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Tue, 20 Mar 2012 11:23:03 +0000 Subject: [PATCH 112/259] [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 ++------ phpBB/index.php | 4 +--- phpBB/memberlist.php | 8 ++------ phpBB/ucp.php | 4 +--- phpBB/viewforum.php | 4 +--- phpBB/viewonline.php | 8 ++------ phpBB/viewtopic.php | 20 +++++--------------- 12 files changed, 27 insertions(+), 81 deletions(-) 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); diff --git a/phpBB/index.php b/phpBB/index.php index 87b0adeafd..b7d53b5a7a 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -174,9 +174,7 @@ $template->assign_vars(array( $page_title = $user->lang['INDEX']; $vars = array('page_title'); -$event = new phpbb_event_data(compact($vars)); -$phpbb_dispatcher->dispatch('core.index', $event); -extract($event->get_data_filtered($vars)); +extract($phpbb_dispatcher->trigger_event('core.index', compact($vars), $vars)); // Output page page_header($page_title); diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 81369a9b57..f0c0065261 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -576,9 +576,7 @@ switch ($mode) } $vars = array('member', 'user_notes_enabled', 'warn_user_enabled'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.memberlist_viewprofile', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.memberlist_viewprofile', compact($vars), $vars)); $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); @@ -1748,9 +1746,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f ); $vars = array('data'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.memberlist_profile_data', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.memberlist_profile_data', compact($vars), $vars)); return $data; } diff --git a/phpBB/ucp.php b/phpBB/ucp.php index 2b129f3ec7..02434cc3c8 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -329,9 +329,7 @@ if (!$auth->acl_get('u_sig')) } $vars = array('module'); -$event = new phpbb_event_data(compact($vars)); -$phpbb_dispatcher->dispatch('core.ucp_modules', $event); -extract($event->get_data_filtered($vars)); +extract($phpbb_dispatcher->trigger_event('core.ucp_modules', compact($vars), $vars)); // Select the active module $module->set_active($id, $mode); diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index dac4230ce0..393e8db26c 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -746,9 +746,7 @@ if (sizeof($topic_list)) ); $vars = array('topicrow'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.viewforum_topicrow', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.viewforum_topicrow', compact($vars), $vars)); $template->assign_block_vars('topicrow', $topicrow); diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 55d663de20..08c02464e5 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -134,9 +134,7 @@ $sql_ary = array( ); $vars = array('sql_ary', 'show_guests'); -$event = new phpbb_event_data(compact($vars)); -$phpbb_dispatcher->dispatch('core.viewonline_get_userdata', $event); -extract($event->get_data_filtered($vars)); +extract($phpbb_dispatcher->trigger_event('core.viewonline_get_userdata', compact($vars), $vars)); $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); @@ -330,9 +328,7 @@ while ($row = $db->sql_fetchrow($result)) $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); $vars = array('on_page', 'row', 'location', 'location_url'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.viewonline_location', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.viewonline_location', compact($vars), $vars)); break; } diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 99b875ae3d..34c8bfbc0f 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -988,9 +988,7 @@ $sql_ary = array( ); $vars = array('sql_ary'); -$event = new phpbb_event_data(compact($vars)); -$phpbb_dispatcher->dispatch('core.viewtopic_get_userdata', $event); -extract($event->get_data_filtered($vars)); +extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_userdata', compact($vars), $vars)); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -1104,9 +1102,7 @@ while ($row = $db->sql_fetchrow($result)) ); $vars = array('user_cache_data', 'row', 'poster_id'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.viewtopic_user_cache_guest', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache_guest', compact($vars), $vars)); $user_cache[$poster_id] = $user_cache_data; @@ -1163,9 +1159,7 @@ while ($row = $db->sql_fetchrow($result)) ); $vars = array('user_cache_data', 'row', 'poster_id'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.viewtopic_user_cache', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache', compact($vars), $vars)); $user_cache[$poster_id] = $user_cache_data; @@ -1594,9 +1588,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) } $vars = array('postrow'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.viewtopic_postrow', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars), $vars)); // Dump vars into template $template->assign_block_vars('postrow', $postrow); @@ -1756,9 +1748,7 @@ if (!request_var('t', 0) && !empty($topic_id)) $page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : ''); $vars = array('page_title', 'topic_data', 'forum_id', 'start'); -$event = new phpbb_event_data(compact($vars)); -$phpbb_dispatcher->dispatch('core.viewtopic_page_header', $event); -extract($event->get_data_filtered($vars)); +extract($phpbb_dispatcher->trigger_event('core.viewtopic_page_header', compact($vars), $vars)); // Output the page page_header($page_title, true, $forum_id); From 8da33e2654f89e55352012b197dfef4ae7a1fc7e Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 23 Mar 2012 12:11:45 +0000 Subject: [PATCH 113/259] [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(-) 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() From 3f1b4e83aef7f7344cd551463b59de71bb4bd6fe Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 31 Mar 2012 13:39:41 +0100 Subject: [PATCH 114/259] [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 ++-- phpBB/index.php | 2 +- phpBB/memberlist.php | 4 ++-- phpBB/ucp.php | 2 +- phpBB/viewforum.php | 2 +- phpBB/viewonline.php | 4 ++-- phpBB/viewtopic.php | 10 +++++----- 12 files changed, 27 insertions(+), 27 deletions(-) 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); diff --git a/phpBB/index.php b/phpBB/index.php index b7d53b5a7a..00dcbb5855 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -174,7 +174,7 @@ $template->assign_vars(array( $page_title = $user->lang['INDEX']; $vars = array('page_title'); -extract($phpbb_dispatcher->trigger_event('core.index', compact($vars), $vars)); +extract($phpbb_dispatcher->trigger_event('core.index', compact($vars))); // Output page page_header($page_title); diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index f0c0065261..a417eaac1a 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -576,7 +576,7 @@ switch ($mode) } $vars = array('member', 'user_notes_enabled', 'warn_user_enabled'); - extract($phpbb_dispatcher->trigger_event('core.memberlist_viewprofile', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.memberlist_viewprofile', compact($vars))); $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); @@ -1746,7 +1746,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f ); $vars = array('data'); - extract($phpbb_dispatcher->trigger_event('core.memberlist_profile_data', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.memberlist_profile_data', compact($vars))); return $data; } diff --git a/phpBB/ucp.php b/phpBB/ucp.php index 02434cc3c8..53cd9d2b74 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -329,7 +329,7 @@ if (!$auth->acl_get('u_sig')) } $vars = array('module'); -extract($phpbb_dispatcher->trigger_event('core.ucp_modules', compact($vars), $vars)); +extract($phpbb_dispatcher->trigger_event('core.ucp_modules', compact($vars))); // Select the active module $module->set_active($id, $mode); diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 393e8db26c..524d5c212a 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -746,7 +746,7 @@ if (sizeof($topic_list)) ); $vars = array('topicrow'); - extract($phpbb_dispatcher->trigger_event('core.viewforum_topicrow', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.viewforum_topicrow', compact($vars))); $template->assign_block_vars('topicrow', $topicrow); diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 08c02464e5..227a88f962 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -134,7 +134,7 @@ $sql_ary = array( ); $vars = array('sql_ary', 'show_guests'); -extract($phpbb_dispatcher->trigger_event('core.viewonline_get_userdata', compact($vars), $vars)); +extract($phpbb_dispatcher->trigger_event('core.viewonline_get_userdata', compact($vars))); $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); @@ -328,7 +328,7 @@ while ($row = $db->sql_fetchrow($result)) $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); $vars = array('on_page', 'row', 'location', 'location_url'); - extract($phpbb_dispatcher->trigger_event('core.viewonline_location', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.viewonline_location', compact($vars))); break; } diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 34c8bfbc0f..7a1b9ba9e4 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -988,7 +988,7 @@ $sql_ary = array( ); $vars = array('sql_ary'); -extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_userdata', compact($vars), $vars)); +extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_userdata', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); @@ -1102,7 +1102,7 @@ while ($row = $db->sql_fetchrow($result)) ); $vars = array('user_cache_data', 'row', 'poster_id'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache_guest', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache_guest', compact($vars))); $user_cache[$poster_id] = $user_cache_data; @@ -1159,7 +1159,7 @@ while ($row = $db->sql_fetchrow($result)) ); $vars = array('user_cache_data', 'row', 'poster_id'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache', compact($vars))); $user_cache[$poster_id] = $user_cache_data; @@ -1588,7 +1588,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) } $vars = array('postrow'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars))); // Dump vars into template $template->assign_block_vars('postrow', $postrow); @@ -1748,7 +1748,7 @@ if (!request_var('t', 0) && !empty($topic_id)) $page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : ''); $vars = array('page_title', 'topic_data', 'forum_id', 'start'); -extract($phpbb_dispatcher->trigger_event('core.viewtopic_page_header', compact($vars), $vars)); +extract($phpbb_dispatcher->trigger_event('core.viewtopic_page_header', compact($vars))); // Output the page page_header($page_title, true, $forum_id); From a247bfc2b6ee8f4aeb53f639294932fa16688666 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 1 Apr 2012 20:19:47 +0100 Subject: [PATCH 115/259] [feature/events] Fixing issues with events PHPBB3-9550 --- phpBB/includes/functions.php | 1 - 1 file changed, 1 deletion(-) 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))); 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: [PATCH 116/259] [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(+) 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']) { 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: [PATCH 117/259] [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(+) 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')) From 3d4946f5f017a51c7ae358ae450f4d9bb1cac70c Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 7 Apr 2012 15:47:57 +0100 Subject: [PATCH 118/259] [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(-) 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); } 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: [PATCH 119/259] [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(+) 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; } 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: [PATCH 120/259] [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(+) 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']) { 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: [PATCH 121/259] [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(+) 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')) 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: [PATCH 122/259] [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(+) 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)) 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: [PATCH 123/259] [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(-) 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; 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: [PATCH 124/259] [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(-) 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; } 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: [PATCH 125/259] [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(+) 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; } } 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: [PATCH 126/259] [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(+) 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; From 6059bc7b45a098e4bc846fe3704543137cc1aba1 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 25 May 2012 18:18:27 -0400 Subject: [PATCH 127/259] [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(-) 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 = ''; From 611d965b043c2a566e817f29d618ff841aa02c34 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 11 Jun 2012 08:26:44 -0400 Subject: [PATCH 128/259] [feature/events] Renamed $empty_avatar to $default_avatar PHPBB3-9550 --- phpBB/includes/functions_display.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 = ''; From 2be60b80ae6fc1da09af8eeaffc8d72aafc0c3b1 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 11 Jun 2012 17:49:07 -0400 Subject: [PATCH 129/259] [feature/events] Rename core.index to core.index_page_title This makes it clearer as to what the event actually does. PHPBB3-9550 --- phpBB/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/index.php b/phpBB/index.php index 00dcbb5855..febd630a2b 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -174,7 +174,7 @@ $template->assign_vars(array( $page_title = $user->lang['INDEX']; $vars = array('page_title'); -extract($phpbb_dispatcher->trigger_event('core.index', compact($vars))); +extract($phpbb_dispatcher->trigger_event('core.index_page_title', compact($vars))); // Output page page_header($page_title); From 0f78b4699acd823f773214497f68840178a8b82e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:41:02 +0200 Subject: [PATCH 130/259] [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(-) 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') { From 8637f09b356f2b26a33e9ab2a7d245fb0e016f85 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:43:22 +0200 Subject: [PATCH 131/259] [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(-) 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; } From 3a9b7c9acf7ab0e9bd78cf76d59c30c48fb17c6a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:47:56 +0200 Subject: [PATCH 132/259] [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(-) 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) { From e126c37ea8a0c47ce8a78959a71ca8f9da8340ea Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:49:41 +0200 Subject: [PATCH 133/259] [feature/php-events] Remove _override from event name PHPBB3-9550 --- phpBB/includes/functions_acp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) { From 730bd6eb08aa76dc54e661b03207e2d695d9a8c5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:52:45 +0200 Subject: [PATCH 134/259] [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(-) 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); From 3af0ae69eed6955a23b29087891258efb1a06e33 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:54:55 +0200 Subject: [PATCH 135/259] [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(-) 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; } From 758fb67a7dc3bcc39ec0284c7045b2668f049408 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 15:58:12 +0200 Subject: [PATCH 136/259] [feature/php-events] Add missing global $phpbb_dispatcher PHPBB3-9550 --- phpBB/includes/mcp/mcp_forum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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')); From 4745d4ec6c5c25757818bf528f1019da4ebd2534 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:01:51 +0200 Subject: [PATCH 137/259] [feature/php-events] Do not override the data parameter, so data is available PHPBB3-9550 --- phpBB/memberlist.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index a417eaac1a..06c55e7956 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1696,7 +1696,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f } // Dump it out to the template - $data = array( + $template_data = array( 'AGE' => $age, 'RANK_TITLE' => $rank_title, 'JOINED' => $user->format_date($data['user_regdate']), @@ -1745,10 +1745,10 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username), ); - $vars = array('data'); + $vars = array('data', 'template_data'); extract($phpbb_dispatcher->trigger_event('core.memberlist_profile_data', compact($vars))); - return $data; + return $template_data; } function _sort_last_active($first, $second) From 45d534978b4d5f20666dbf9b8de721fe02197746 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:03:46 +0200 Subject: [PATCH 138/259] [feature/php-events] Make topic db row available in event PHPBB3-9550 --- phpBB/viewforum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 524d5c212a..bc385a6a7a 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -745,7 +745,7 @@ if (sizeof($topic_list)) 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test, ); - $vars = array('topicrow'); + $vars = array('row', 'topicrow'); extract($phpbb_dispatcher->trigger_event('core.viewforum_topicrow', compact($vars))); $template->assign_block_vars('topicrow', $topicrow); From f01d742b5649678de3e5ba4aa45f4176c8ff5aac Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:07:49 +0200 Subject: [PATCH 139/259] [feature/php-events] Add additional vars and control to viewtopic_postrow event PHPBB3-9550 --- phpBB/viewtopic.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 7a1b9ba9e4..20d4c2af1b 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1582,14 +1582,16 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'L_IGNORE_POST' => ($row['hide_post']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), '', '') : '', ); + $user_poster_data = $user_cache[$poster_id]; + + $vars = array('row', 'cp_row', 'user_poster_data', 'postrow'); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars))); + if (isset($cp_row['row']) && sizeof($cp_row['row'])) { $postrow = array_merge($postrow, $cp_row['row']); } - $vars = array('postrow'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars))); - // Dump vars into template $template->assign_block_vars('postrow', $postrow); From 2e5a7ae4dda587bc1f47f2f1fddb4e13235217d4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:22:22 +0200 Subject: [PATCH 140/259] [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(-) 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) { From b1582ece91e7ebd9f635040bbb1a4c6c47786135 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:42:47 +0200 Subject: [PATCH 141/259] [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(-) 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') From bdfedba521ee38ef6b8915bfb130b2f164c040c0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:43:08 +0200 Subject: [PATCH 142/259] [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(-) 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) { From b2884449159305420f52881b7fe9841c1a50c2ed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:43:32 +0200 Subject: [PATCH 143/259] [feature/php-events] Make naming of topicrow consistent with others (topic_row) PHPBB3-9550 --- phpBB/viewforum.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index bc385a6a7a..df5678def1 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -690,7 +690,7 @@ if (sizeof($topic_list)) $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$topic_id", true, $user->session_id) : ''; // Send vars to template - $topicrow = array( + $topic_row = array( 'FORUM_ID' => $row['forum_id'], 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), @@ -745,10 +745,10 @@ if (sizeof($topic_list)) 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test, ); - $vars = array('row', 'topicrow'); + $vars = array('row', 'topic_row'); extract($phpbb_dispatcher->trigger_event('core.viewforum_topicrow', compact($vars))); - $template->assign_block_vars('topicrow', $topicrow); + $template->assign_block_vars('topicrow', $topic_row); phpbb_generate_template_pagination($template, $view_topic_url, 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true); From 16736d4e4cfabc65f84c6339bf81ae01f1edffc2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 16:43:48 +0200 Subject: [PATCH 144/259] [feature/php-events] Make naming of postrow consistent with others (post_row) PHPBB3-9550 --- phpBB/viewtopic.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 20d4c2af1b..ce73001c78 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1506,7 +1506,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) ))); // - $postrow = array( + $post_row = array( 'POST_AUTHOR_FULL' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_full'] : get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_COLOUR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_colour'] : get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_username'] : get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), @@ -1584,16 +1584,16 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) $user_poster_data = $user_cache[$poster_id]; - $vars = array('row', 'cp_row', 'user_poster_data', 'postrow'); + $vars = array('row', 'cp_row', 'user_poster_data', 'post_row'); extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars))); if (isset($cp_row['row']) && sizeof($cp_row['row'])) { - $postrow = array_merge($postrow, $cp_row['row']); + $post_row = array_merge($post_row, $cp_row['row']); } // Dump vars into template - $template->assign_block_vars('postrow', $postrow); + $template->assign_block_vars('postrow', $post_row); if (!empty($cp_row['blockrow'])) { From 97f50c9771fb331d131695db9e3e0f7deedb18be Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 15:02:05 +0200 Subject: [PATCH 145/259] [feature/php-events] Add docs and fix naming of core.viewonline_modify_sql PHPBB3-9550 --- phpBB/viewonline.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 227a88f962..32ea23c182 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -133,8 +133,16 @@ $sql_ary = array( 'ORDER_BY' => $order_by, ); +/** +* Modify the SQL query for getting the user data to display viewonline list +* +* @event core.viewonline_modify_sql +* @var array sql_ary The SQL array +* @var bool show_guests Do we display guests in the list +* @since 3.1-A1 +*/ $vars = array('sql_ary', 'show_guests'); -extract($phpbb_dispatcher->trigger_event('core.viewonline_get_userdata', compact($vars))); +extract($phpbb_dispatcher->trigger_event('core.viewonline_modify_sql', compact($vars))); $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); From 0ebe1f876452edbf2daeaf1e11bfe0b776fdc8af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 16:12:05 +0200 Subject: [PATCH 146/259] [feature/php-events] Fix docs and naming of core.viewonline_override_location PHPBB3-9550 --- phpBB/viewonline.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 32ea23c182..193fa61dd7 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -335,8 +335,18 @@ while ($row = $db->sql_fetchrow($result)) $location = $user->lang['INDEX']; $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); + /** + * Modify the location name and url which are displayed in the list + * + * @event core.viewonline_override_location + * @var array on_page File name and query string + * @var array row Array with the users sql row + * @var string location Page name to displayed in the list + * @var string location_url Page url to displayed in the list + * @since 3.1-A1 + */ $vars = array('on_page', 'row', 'location', 'location_url'); - extract($phpbb_dispatcher->trigger_event('core.viewonline_location', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.viewonline_override_location', compact($vars))); break; } From c903b1512c9926dfbc54e4e48233904385c137c6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 16:53:20 +0200 Subject: [PATCH 147/259] [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(-) 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); From ec957350c14c8b0bb6dc4768b5ad363a39715cab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 17:02:18 +0200 Subject: [PATCH 148/259] [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(-) 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) From 3affe7f229f4c8a3bb4ddb1abd79aca0dc0c15a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 17:03:04 +0200 Subject: [PATCH 149/259] [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(+) 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 From 8d3389448bf65f1bfc78efbfc80d0b658661f3da Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 18:54:00 +0200 Subject: [PATCH 150/259] [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(-) 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')) { From 3ced9f58ea5493e13796766d55059b70bc6d6a3e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 19:27:58 +0200 Subject: [PATCH 151/259] [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(-) 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 From a05cd6d837ad9d2202561ded9c100a9b1350c0c2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 19:50:58 +0200 Subject: [PATCH 152/259] [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(-) 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) { From 099aaab7208123a5fb8195ccd5bdccee80ea2460 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 22:47:00 +0200 Subject: [PATCH 153/259] [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(-) 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); From 14edfd2856b602ea435f5d473322950e23868b6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 14:12:12 +0200 Subject: [PATCH 154/259] [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(-) 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']; From d4f9442e8749152d08ff50ca678b105d0ed2b703 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 15:34:53 +0200 Subject: [PATCH 155/259] [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(-) 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); From 8b7e3739a04bd3ea707493894fa2ebf8dc81410e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 15:47:42 +0200 Subject: [PATCH 156/259] [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(-) 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); From 96f20160bcfa7a08870602b25fa528370f034128 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 16:00:19 +0200 Subject: [PATCH 157/259] [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(-) 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); From 4f13b049f813916e6393c8c4cc0227d3f52c2318 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 16:35:01 +0200 Subject: [PATCH 158/259] [feature/php-events] Fix docs of core.display_custom_bbcodes PHPBB3-9550 --- phpBB/includes/functions_display.php | 6 ++++++ 1 file changed, 6 insertions(+) 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'); } From 39869d46b1c4f3dcc178cdb7cd05e8f28fcc1f47 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 30 Jul 2012 17:01:35 +0200 Subject: [PATCH 159/259] [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(-) 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 = ''; From 01369dd7f826a27e9970e0c0acb126cb2349c87c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 31 Jul 2012 23:50:31 +0200 Subject: [PATCH 160/259] [feature/php-events] Add docs to core.common @todo: Add event to user::setup() after branch is updated to develop, so timezone handling is there PHPBB3-9550 --- phpBB/common.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/phpBB/common.php b/phpBB/common.php index 9cf2617b07..e18c27abd1 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -144,4 +144,17 @@ if (!$config['use_system_cron']) $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); } +/** +* Main event which is triggered on every page +* +* You can use this event to load function files and initiate objects +* +* NOTE: At this point the global session ($user) and permissions ($auth) +* do NOT exist yet. If you need to use the user objec +* (f.e. to use language files) or need to check permissions, please use +* the core.user_setup event instead! +* +* @event core.common +* @since 3.1-A1 +*/ $phpbb_dispatcher->dispatch('core.common'); From d152c20e4b53f26bfcf9425f1efed9d9d4ccef9f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 1 Aug 2012 11:07:34 +0200 Subject: [PATCH 161/259] [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(-) 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); From 6fbbb30a817a44fed1fb90ee35fca0d1caf83fcb Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 1 Aug 2012 22:18:12 +0530 Subject: [PATCH 162/259] [ticket/11032] add sphinx errors to error log PHPBB3-11032 --- phpBB/includes/search/fulltext_sphinx.php | 5 +++++ phpBB/language/en/acp/common.php | 1 + 2 files changed, 6 insertions(+) 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; diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 5cebcc89d7..04df897dba 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -690,6 +690,7 @@ $lang = array_merge($lang, array( 'LOG_SEARCH_INDEX_CREATED' => 'Created search index for
» %s', 'LOG_SEARCH_INDEX_REMOVED' => 'Removed search index for
» %s', + 'LOG_SPHINX_ERROR' => 'Sphinx Error
» %s', 'LOG_STYLE_ADD' => 'Added new style
» %s', 'LOG_STYLE_DELETE' => 'Deleted style
» %s', 'LOG_STYLE_EDIT_DETAILS' => 'Edited style
» %s', From 9358bf3de5fe402ccdc116e6b74e0cd2eee35e37 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 1 Aug 2012 22:23:51 +0530 Subject: [PATCH 163/259] [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(-) 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); From a35ad4e689c204c52d23c07b701433325c27b0dc Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 2 Aug 2012 12:38:49 +0200 Subject: [PATCH 164/259] [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(-) 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; } } From e85afc6b83559742e87d85e7a385bf08b27a8c25 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 2 Aug 2012 20:59:38 +0200 Subject: [PATCH 165/259] [feature/php-events] Fix naming and docs of core.index_modify_page_title PHPBB3-9550 --- phpBB/index.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/index.php b/phpBB/index.php index febd630a2b..90d1d352e0 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -173,8 +173,15 @@ $template->assign_vars(array( $page_title = $user->lang['INDEX']; +/** +* You can use this event to modify the page title and load data for the index +* +* @event core.index_modify_page_title +* @var string page_title Title of the index page +* @since 3.1-A1 +*/ $vars = array('page_title'); -extract($phpbb_dispatcher->trigger_event('core.index_page_title', compact($vars))); +extract($phpbb_dispatcher->trigger_event('core.index_modify_page_title', compact($vars))); // Output page page_header($page_title); From d06adb06e907e31918130a6ef010b73d454f396c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 2 Aug 2012 21:22:52 +0200 Subject: [PATCH 166/259] [feature/php-events] Remove core.mcp_check_ids and invalid comment. We couldn't find a reason for this event, as it even doesn't have any arguments The comment is not correct anymore either. Since 3.1global announcements still have a valid forum_id PHPBB3-9550 --- phpBB/mcp.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/phpBB/mcp.php b/phpBB/mcp.php index b5cfa99d4c..730af65e3d 100644 --- a/phpBB/mcp.php +++ b/phpBB/mcp.php @@ -823,7 +823,7 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, */ function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false) { - global $db, $auth, $phpbb_dispatcher; + global $db, $auth; if (!is_array($ids) || empty($ids)) { @@ -887,9 +887,5 @@ function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = fa return false; } - // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id) - - $phpbb_dispatcher->dispatch('core.mcp_check_ids'); - return ($single_forum === false) ? true : (int) $forum_id; } From a2c59bba858255e3dd9f0dd36983714bf33c27e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 2 Aug 2012 21:56:35 +0200 Subject: [PATCH 167/259] [feature/php-events] Fix naming, vars and docs of core.memberlist_view_profile PHPBB3-9550 --- phpBB/memberlist.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 06c55e7956..29a042409a 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -575,8 +575,25 @@ switch ($mode) unset($module); } - $vars = array('member', 'user_notes_enabled', 'warn_user_enabled'); - extract($phpbb_dispatcher->trigger_event('core.memberlist_viewprofile', compact($vars))); + /** + * Modify user data before we display the profile + * + * @event core.memberlist_view_profile + * @var array member Title of the index page + * @var bool user_notes_enabled Is the mcp user notes module + * enabled? + * @var bool warn_user_enabled Is the mcp warnings module + * enabled? + * @var bool zebra_enabled Is the ucp zebra module + * enabled? + * @var bool friends_enabled Is the ucp friends module + * enabled? + * @var bool foes_enabled Is the ucp foes module + * enabled? + * @since 3.1-A1 + */ + $vars = array('member', 'user_notes_enabled', 'warn_user_enabled', 'zebra_enabled', 'friends_enabled', 'foes_enabled'); + extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars))); $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); From fab13f75590e33beeda2a12bb9653b1fd0ec60bf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 2 Aug 2012 22:05:39 +0200 Subject: [PATCH 168/259] [feature/php-events] Fix naming and docs of memberlist_prepare_profile_data PHPBB3-9550 --- phpBB/memberlist.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 29a042409a..e1e4517643 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1762,8 +1762,16 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username), ); + /** + * Preparing user's data before displaying it in profile and memberlist + * + * @event core.memberlist_prepare_profile_data + * @var array data Array with user's data + * @var array template_data Template array with user's data + * @since 3.1-A1 + */ $vars = array('data', 'template_data'); - extract($phpbb_dispatcher->trigger_event('core.memberlist_profile_data', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars))); return $template_data; } From 10f8c738b60d3acd42e002c334eee8f8d8dd74d5 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Fri, 3 Aug 2012 01:33:51 -0500 Subject: [PATCH 169/259] [ticket/11043] Update template hook name PHPBB3-11043 --- phpBB/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 81fe275008..a3e4af88ec 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -132,7 +132,7 @@ $phpbb_subscriber_loader->load(); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); -$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display'))); +$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'call_hook'))); foreach ($cache->obtain_hooks() as $hook) { From ae612de663dbcd76074df4ea950a3a94745ca0ec Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 3 Aug 2012 12:34:07 +0200 Subject: [PATCH 170/259] [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(-) 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); } } From 3c71f07a3eddd4fa824c401de2e77ce00e5aec15 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 3 Aug 2012 12:34:19 +0200 Subject: [PATCH 171/259] [ticket/11043] Change hook name back to display, since that's where we hook in. PHPBB3-11043 --- phpBB/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index a3e4af88ec..5882bbf9fb 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -132,7 +132,7 @@ $phpbb_subscriber_loader->load(); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); -$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'call_hook'))); +$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); foreach ($cache->obtain_hooks() as $hook) { From 63d17e51813f1b80fd5c2ee33bcc67603c8da78b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 3 Aug 2012 23:26:50 +0200 Subject: [PATCH 172/259] [feature/php-events] Fix naming and doc of core.viewforum_modify_topicrow PHPBB3-9550 --- phpBB/viewforum.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index df5678def1..adf875114b 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -745,8 +745,16 @@ if (sizeof($topic_list)) 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test, ); + /** + * Modify the topic data before it is assigned to the template + * + * @event core.viewforum_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.viewforum_topicrow', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topicrow', compact($vars))); $template->assign_block_vars('topicrow', $topic_row); From b153637cb8bd58d571748f9539e81822be11d8bb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 3 Aug 2012 23:41:00 +0200 Subject: [PATCH 173/259] [feature/php-events] Fix naming and doc of core.ucp_display_module_before PHPBB3-9550 --- phpBB/ucp.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/phpBB/ucp.php b/phpBB/ucp.php index 53cd9d2b74..9730591698 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -328,8 +328,17 @@ if (!$auth->acl_get('u_sig')) $module->set_display('profile', 'signature', false); } -$vars = array('module'); -extract($phpbb_dispatcher->trigger_event('core.ucp_modules', compact($vars))); +/** +* Use this event to enable and disable additional UCP modules +* +* @event core.ucp_display_module_before +* @var p_master module Object holding all modules and their status +* @var mixed id Active module category (can be the int or string) +* @var string mode Active module +* @since 3.1-A1 +*/ +$vars = array('module', 'id', 'mode'); +extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars))); // Select the active module $module->set_active($id, $mode); From 0d182d9e9376a56b314b072c9d4395c18b900478 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:07:35 +0200 Subject: [PATCH 174/259] [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(-) 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(); From a9d4ed0cfcc58f3993bb09f230ad2b11482ddde8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:19:25 +0200 Subject: [PATCH 175/259] [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(-) 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); } From 63a00efdd4eae8c3ad6a52c654107a83db5a2128 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:37:54 +0200 Subject: [PATCH 176/259] [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(-) 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'])) From a53ddec5a32dd208d52e12945490464ed2d363af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:44:46 +0200 Subject: [PATCH 177/259] [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(-) 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; From 4eefba9b3f59618f78f338aa40a05f39ef8214e9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 4 Aug 2012 17:50:16 +0200 Subject: [PATCH 178/259] [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(-) 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); From 70d9c02aae2ae357deb5ab415469fbbf965d0177 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 4 Aug 2012 16:50:03 +0100 Subject: [PATCH 179/259] [ticket/11044] Compress class now deals with file conflicts PHPBB3-11044 --- phpBB/includes/functions_compress.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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'); From 3390712ed7097fb11d564fb6bd82d74c6b8e3731 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 5 Aug 2012 11:29:02 +0100 Subject: [PATCH 180/259] [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(-) 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'); From 6571ea1fc8fa636cb418344f87cc7b010dd8f187 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 14:50:33 +0200 Subject: [PATCH 181/259] [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(-) 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; } From 5db76ee8b0e42cb9773f1b100c533af8ce666098 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 15:03:08 +0200 Subject: [PATCH 182/259] [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(-) 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': From be61bcb7b559d5804f4e6f666e55bf37cd199cb2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 15:27:08 +0200 Subject: [PATCH 183/259] [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(+) 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; From 171c07a0847f695a1c8e2f1f35784c453c47546a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 15:39:42 +0200 Subject: [PATCH 184/259] [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(+) 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 From 1f9b23e721008ca2903b9b4e79008867554eddf4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 16:42:46 +0200 Subject: [PATCH 185/259] [feature/php-events] Add docs for core.page_header PHPBB3-9550 --- phpBB/includes/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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))); From 997075a008b594f62306184aeb9105d5180fdd6d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 16:46:57 +0200 Subject: [PATCH 186/259] [feature/php-events] Add docs for core.page_footer PHPBB3-9550 --- phpBB/includes/functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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))); From e926ec9934348c1e2e556782edbb47630c58facc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 16:51:51 +0200 Subject: [PATCH 187/259] [feature/php-events] Add docs for core.garbage_collection PHPBB3-9550 --- phpBB/includes/functions.php | 6 ++++++ 1 file changed, 6 insertions(+) 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 From 296ab5c168dfb324821c0ba965028be690745eb3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 21:17:29 +0200 Subject: [PATCH 188/259] [feature/php-events] Add docs for core.adm_page_header PHPBB3-9550 --- phpBB/includes/functions_acp.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; From a326dc10cf2aa6f0ec631cbb23625831002da2ff Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 21:24:33 +0200 Subject: [PATCH 189/259] [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(-) 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))); From 48a8482d23d7ab6fb0ef4c14f3d8464a78c14477 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 22:24:15 +0200 Subject: [PATCH 190/259] [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(-) 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; } From c28bd7cc609fecd6750ae0e7b4f1b4256f660818 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 23:09:44 +0200 Subject: [PATCH 191/259] [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(-) 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; } } From 93912a2649eadae1e8cf0f3e24b0ddf7223316b3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 5 Aug 2012 23:11:36 +0200 Subject: [PATCH 192/259] [feature/php-events] Remove double space in comments PHPBB3-9550 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 011b494bc55224e59872621ea09c0f69baed2744 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 5 Aug 2012 22:11:14 +0100 Subject: [PATCH 193/259] [ticket/11044] Preserve the file extension in unique filenames PHPBB3-11044 --- phpBB/includes/functions_compress.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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; From ecb310c6f7a2f8aa5c1f2217d7de6cb878aa85f4 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 6 Aug 2012 08:32:12 +0800 Subject: [PATCH 194/259] [ticket/11044] Added comment explaining filename splitting PHPBB3-11044 --- phpBB/includes/functions_compress.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); } From 3f710b58a5a7c371b8016c808a756616a77f4503 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Aug 2012 15:37:02 +0200 Subject: [PATCH 195/259] [feature/php-events] Fix doc and naming of core.viewtopic_get_post_data PHPBB3-9550 --- phpBB/viewtopic.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index ce73001c78..22b1bd9dea 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -987,8 +987,15 @@ $sql_ary = array( AND u.user_id = p.poster_id', ); +/** +* Event to modify the SQL query before the post and poster data is queried +* +* @event core.viewtopic_get_post_data +* @var array sql_ary The SQL array to get the data of posts and posters +* @since 3.1-A1 +*/ $vars = array('sql_ary'); -extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_userdata', compact($vars))); +extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_post_data', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); From ff12de97b72ef46a8bde5aca561e3cc18b7fa614 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Aug 2012 16:12:17 +0200 Subject: [PATCH 196/259] [feature/php-events] Fix doc and naming of core.viewtopic_cache_guest_data PHPBB3-9550 --- phpBB/viewtopic.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 22b1bd9dea..1939d1f73b 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1108,8 +1108,17 @@ while ($row = $db->sql_fetchrow($result)) 'allow_pm' => 0, ); - $vars = array('user_cache_data', 'row', 'poster_id'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache_guest', compact($vars))); + /** + * Modify the guests user data displayed with the posts + * + * @event core.viewtopic_cache_guest_data + * @var array user_cache_data Array with the user's data + * @var int poster_id Poster's user id + * @var array row Array with original user and post data + * @since 3.1-A1 + */ + $vars = array('user_cache_data', 'poster_id', 'row'); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_cache_guest_data', compact($vars))); $user_cache[$poster_id] = $user_cache_data; From eb80d280b15ddb442f290c9722d394f63a9036e3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Aug 2012 16:17:29 +0200 Subject: [PATCH 197/259] [feature/php-events] Fix doc and naming of core.viewtopic_cache_user_data PHPBB3-9550 --- phpBB/viewtopic.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 1939d1f73b..cad3789fd4 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1174,8 +1174,17 @@ while ($row = $db->sql_fetchrow($result)) 'author_profile' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour']), ); - $vars = array('user_cache_data', 'row', 'poster_id'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_user_cache', compact($vars))); + /** + * Modify the users' data displayed with their posts + * + * @event core.viewtopic_cache_user_data + * @var array user_cache_data Array with the user's data + * @var int poster_id Poster's user id + * @var array row Array with original user and post data + * @since 3.1-A1 + */ + $vars = array('user_cache_data', 'poster_id', 'row'); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_cache_user_data', compact($vars))); $user_cache[$poster_id] = $user_cache_data; From dcb4d3b92612faefc9c7b08c843be24f79d31c21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Aug 2012 16:42:13 +0200 Subject: [PATCH 198/259] [feature/php-events] Fix doc and naming of core.viewtopic_modify_post_row PHPBB3-9550 --- phpBB/viewtopic.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index cad3789fd4..0881fb3e48 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1609,8 +1609,18 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) $user_poster_data = $user_cache[$poster_id]; + /** + * Modify the posts template block + * + * @event core.viewtopic_modify_post_row + * @var array row Array with original post and user data + * @var array cp_row Custom profile field data of the poster + * @var array user_poster_data Poster's data from user cache + * @var array post_row Template block array of the post + * @since 3.1-A1 + */ $vars = array('row', 'cp_row', 'user_poster_data', 'post_row'); - extract($phpbb_dispatcher->trigger_event('core.viewtopic_postrow', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_post_row', compact($vars))); if (isset($cp_row['row']) && sizeof($cp_row['row'])) { From c277c240f83780b527511339068bd25d793712a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Aug 2012 17:05:22 +0200 Subject: [PATCH 199/259] [feature/php-events] Fix doc and naming of core.viewtopic_modify_page_title PHPBB3-9550 --- phpBB/viewtopic.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 0881fb3e48..43aacbff0c 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1784,8 +1784,18 @@ if (!request_var('t', 0) && !empty($topic_id)) $page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang['PAGE_TITLE_NUMBER'], floor($start / $config['posts_per_page']) + 1) : ''); +/** +* You can use this event to modify the page title of the viewtopic page +* +* @event core.viewtopic_modify_page_title +* @var string page_title Title of the index page +* @var array topic_data Array with topic data +* @var int forum_id Forum ID of the topic +* @var int start Start offset used to calculate the page +* @since 3.1-A1 +*/ $vars = array('page_title', 'topic_data', 'forum_id', 'start'); -extract($phpbb_dispatcher->trigger_event('core.viewtopic_page_header', compact($vars))); +extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_page_title', compact($vars))); // Output the page page_header($page_title, true, $forum_id); From 907f1771f9594ee1906c5b0ad7fac765f2a1995d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 15:05:06 -0500 Subject: [PATCH 200/259] [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(-) 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']))) From 1b126908c633fa793cf7f3fba1e88139bb599938 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 15:10:20 -0500 Subject: [PATCH 201/259] [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(-) 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; } From a2dd99b75e308448c309ce4db807ea0091245443 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 14:54:06 -0500 Subject: [PATCH 202/259] [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(-) 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); } } From dcefa16318f6dc1058595a7ba221b75ed6a2504b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 16:26:55 -0500 Subject: [PATCH 203/259] [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 +- tests/cache/cache_test.php | 32 +++++++++++++++++++++++++- tests/mock/cache.php | 2 +- 13 files changed, 45 insertions(+), 11 deletions(-) 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) { diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 564bd35863..81ce9ac1aa 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -class phpbb_cache_test extends phpbb_test_case +class phpbb_cache_test extends phpbb_database_test_case { private $cache_dir; @@ -18,6 +18,11 @@ class phpbb_cache_test extends phpbb_test_case $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/'; } + public function getDataSet() + { + return array(); + } + protected function setUp() { if (file_exists($this->cache_dir)) @@ -67,4 +72,29 @@ class phpbb_cache_test extends phpbb_test_case 'File ACM put and get' ); } + + public function test_cache_sql() + { + $driver = new phpbb_cache_driver_file($this->cache_dir); + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + + $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($first_result, $db->sql_fetchrow($result)); + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'version\''; + $result = $db->sql_query($sql, 300); + + $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); + } } diff --git a/tests/mock/cache.php b/tests/mock/cache.php index c6d08afef0..b64c92ea89 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -121,7 +121,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface public function sql_load($query) { } - public function sql_save($query, &$query_result, $ttl) + public function sql_save($query, $query_result, $ttl) { } public function sql_exists($query_id) From b64ac12bd566a08ff7d4ff3a257dfbb2f8168a56 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 19:41:00 -0500 Subject: [PATCH 204/259] [ticket/10875] Use fixtures for sql cache test PHPBB3-10875 --- tests/cache/cache_test.php | 28 ++++++++++++++++------------ tests/cache/fixtures/config.xml | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 tests/cache/fixtures/config.xml diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 81ce9ac1aa..c73d36973e 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -20,11 +20,13 @@ class phpbb_cache_test extends phpbb_database_test_case public function getDataSet() { - return array(); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } protected function setUp() { + parent::setUp(); + if (file_exists($this->cache_dir)) { // cache directory possibly left after aborted @@ -40,6 +42,8 @@ class phpbb_cache_test extends phpbb_database_test_case { $this->remove_cache_dir(); } + + parent::tearDown(); } private function create_cache_dir() @@ -72,29 +76,29 @@ class phpbb_cache_test extends phpbb_database_test_case 'File ACM put and get' ); } - + public function test_cache_sql() { $driver = new phpbb_cache_driver_file($this->cache_dir); - + global $db, $cache; $db = $this->new_dbal(); $cache = new phpbb_cache_service($driver); - - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); - + $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); - - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'board_disable\''; + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; $result = $db->sql_query($sql, 300); - + $this->assertEquals($first_result, $db->sql_fetchrow($result)); - - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'version\''; + + $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'bar\''; $result = $db->sql_query($sql, 300); - + $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); } } diff --git a/tests/cache/fixtures/config.xml b/tests/cache/fixtures/config.xml new file mode 100644 index 0000000000..9d395b685c --- /dev/null +++ b/tests/cache/fixtures/config.xml @@ -0,0 +1,18 @@ + + + + config_name + config_value + is_dynamic + + foo + 23 + 0 + + + bar + 42 + 1 + +
+
From 44e48817c387ff5ee26746a00a00f900bdd375dd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 31 Jul 2012 14:43:22 -0500 Subject: [PATCH 205/259] [ticket/10875] Close $db connection at end of test Fixes a pgSQL issue PHPBB3-10875 --- tests/cache/cache_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index c73d36973e..06d9d89f68 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -100,5 +100,7 @@ class phpbb_cache_test extends phpbb_database_test_case $result = $db->sql_query($sql, 300); $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); + + $db->sql_close(); } } From 1db91af0000a56b676bf593aab1852190d1d6a7b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 16:28:56 -0500 Subject: [PATCH 206/259] [ticket/10875] Break queries onto separate lines and use double quotes Coding guidelines PHPBB3-10875 --- tests/cache/cache_test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 06d9d89f68..336c009ebe 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -85,18 +85,21 @@ class phpbb_cache_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_cache_service($driver); - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'foo\''; + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); $this->assertEquals($first_result, $db->sql_fetchrow($result)); - $sql = 'SELECT * FROM phpbb_config WHERE config_name = \'bar\''; + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'bar'"; $result = $db->sql_query($sql, 300); $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); From 4b7cdd4264b2669aaf0a0f99db2a9b00b2b58c4e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 6 Aug 2012 18:43:46 -0500 Subject: [PATCH 207/259] [ticket/10875] Fix cache test Check for the correct filename based on the way the cache driver creates it PHPBB3-10875 --- tests/cache/cache_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 336c009ebe..c5f5fac88c 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -90,7 +90,7 @@ class phpbb_cache_test extends phpbb_database_test_case $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); - $this->assertFileExists($this->cache_dir . 'sql_' . md5($sql) . '.php'); + $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; From 321b1f1a39d8319696b9e05834d96811f0d3a19b Mon Sep 17 00:00:00 2001 From: Vinny Date: Tue, 7 Aug 2012 13:18:46 -0300 Subject: [PATCH 208/259] [ticket/11046] Add border-radius for UCP message colours block PHPBB3-11046 --- phpBB/styles/prosilver/theme/cp.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/theme/cp.css b/phpBB/styles/prosilver/theme/cp.css index bf7d304ca4..da3ec1736e 100644 --- a/phpBB/styles/prosilver/theme/cp.css +++ b/phpBB/styles/prosilver/theme/cp.css @@ -260,8 +260,9 @@ ul.cplist { /* Friends list */ .cp-mini { - padding: 0 5px; margin: 10px 15px 10px 5px; + padding: 5px 10px; + border-radius: 7px; } dl.mini dt { From e716c8fe8369c72e2712cbc334fac12ae2d8b064 Mon Sep 17 00:00:00 2001 From: Vinny Date: Tue, 7 Aug 2012 15:21:41 -0300 Subject: [PATCH 209/259] [ticket/11047] Close TOTAL_MESSAGES at ucp_pm_viewfolder.html This problem only occurs in prosilver With the variable unclosed, the language key isnt displayed PHPBB3-11047 --- phpBB/styles/prosilver/template/ucp_pm_viewfolder.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html index 195b212da3..68df22c68e 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewfolder.html @@ -103,7 +103,7 @@