diff options
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/console/exception_subscriber.php | 13 | ||||
-rw-r--r-- | phpBB/phpbb/db/migration/data/v32x/f_list_topics_permission_add.php | 31 | ||||
-rw-r--r-- | phpBB/phpbb/event/dispatcher.php | 7 | ||||
-rw-r--r-- | phpBB/phpbb/event/php_exporter.php | 36 | ||||
-rw-r--r-- | phpBB/phpbb/feed/helper.php | 55 | ||||
-rw-r--r-- | phpBB/phpbb/feed/quote_helper.php | 36 | ||||
-rw-r--r-- | phpBB/phpbb/log/log.php | 14 | ||||
-rw-r--r-- | phpBB/phpbb/pagination.php | 5 | ||||
-rw-r--r-- | phpBB/phpbb/permissions.php | 1 | ||||
-rw-r--r-- | phpBB/phpbb/search/fulltext_sphinx.php | 3 | ||||
-rw-r--r-- | phpBB/phpbb/template/context.php | 88 |
11 files changed, 180 insertions, 109 deletions
diff --git a/phpBB/phpbb/console/exception_subscriber.php b/phpBB/phpbb/console/exception_subscriber.php index b920d4abae..b240993203 100644 --- a/phpBB/phpbb/console/exception_subscriber.php +++ b/phpBB/phpbb/console/exception_subscriber.php @@ -29,12 +29,10 @@ class exception_subscriber implements EventSubscriberInterface * Construct method * * @param \phpbb\language\language $language Language object - * @param bool $debug Debug mode */ - public function __construct(\phpbb\language\language $language, $debug = false) + public function __construct(\phpbb\language\language $language) { $this->language = $language; - $this->debug = $debug; } /** @@ -52,14 +50,7 @@ class exception_subscriber implements EventSubscriberInterface $parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters()); $message = call_user_func_array(array($this->language, 'lang'), $parameters); - if ($this->debug) - { - $exception = new \RuntimeException($message , $original_exception->getCode(), $original_exception); - } - else - { - $exception = new \RuntimeException($message , $original_exception->getCode()); - } + $exception = new \RuntimeException($message , $original_exception->getCode(), $original_exception); $event->setException($exception); } diff --git a/phpBB/phpbb/db/migration/data/v32x/f_list_topics_permission_add.php b/phpBB/phpbb/db/migration/data/v32x/f_list_topics_permission_add.php new file mode 100644 index 0000000000..49727e5a62 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v32x/f_list_topics_permission_add.php @@ -0,0 +1,31 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\db\migration\data\v32x; + +class f_list_topics_permission_add extends \phpbb\db\migration\migration +{ + static public function depends_on() + { + return array( + '\phpbb\db\migration\data\v32x\v321', + ); + } + + public function update_data() + { + return array( + array('permission.add', array('f_list_topics', false, 'f_read')), + ); + } +} diff --git a/phpBB/phpbb/event/dispatcher.php b/phpBB/phpbb/event/dispatcher.php index 1c4abeb108..1ba2ab8987 100644 --- a/phpBB/phpbb/event/dispatcher.php +++ b/phpBB/phpbb/event/dispatcher.php @@ -57,7 +57,12 @@ class dispatcher extends ContainerAwareEventDispatcher implements dispatcher_int return $event; } - return parent::dispatch($eventName, $event); + foreach ((array) $eventName as $name) + { + $event = parent::dispatch($name, $event); + } + + return $event; } /** diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 26d7e2b426..7b80863305 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -196,13 +196,13 @@ class php_exporter $content = file_get_contents($this->path . $this->current_file); $num_events_found = 0; - if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('")) + if (strpos($content, 'dispatcher->trigger_event(') || strpos($content, 'dispatcher->dispatch(')) { $this->set_content(explode("\n", $content)); for ($i = 0, $num_lines = sizeof($this->file_lines); $i < $num_lines; $i++) { $event_line = false; - $found_trigger_event = strpos($this->file_lines[$i], "dispatcher->trigger_event('"); + $found_trigger_event = strpos($this->file_lines[$i], 'dispatcher->trigger_event('); $arguments = array(); if ($found_trigger_event !== false) { @@ -216,7 +216,7 @@ class php_exporter } else { - $found_dispatch = strpos($this->file_lines[$i], "dispatcher->dispatch('"); + $found_dispatch = strpos($this->file_lines[$i], 'dispatcher->dispatch('); if ($found_dispatch !== false) { $event_line = $i; @@ -316,17 +316,17 @@ class php_exporter if ($is_dispatch) { - $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; - $regex .= '->dispatch\('; - $regex .= '\'' . $this->preg_match_event_name() . '\''; - $regex .= '\);#'; + $regex = '#\$[a-z](?:[a-z0-9_]|->)*'; + $regex .= '->dispatch\((\[)?'; + $regex .= '\'' . $this->preg_match_event_name() . '(?(1)\', \'(?2))+\''; + $regex .= '(?(1)\])\);#'; } else { - $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; - $regex .= '->trigger_event\('; - $regex .= '\'' . $this->preg_match_event_name() . '\''; - $regex .= ', compact\(\$vars\)\)\);#'; + $regex = '#extract\(\$[a-z](?:[a-z0-9_]|->)*'; + $regex .= '->trigger_event\((\[)?'; + $regex .= '\'' . $this->preg_match_event_name() . '(?(1)\', \'(?2))+\''; + $regex .= '(?(1)\]), compact\(\$vars\)\)\);#'; } $match = array(); @@ -359,7 +359,7 @@ class php_exporter public function get_vars_from_array() { $line = ltrim($this->file_lines[$this->current_event_line - 1], "\t"); - if ($line === ');') + if ($line === ');' || $line === '];') { $vars_array = $this->get_vars_from_multi_line_array(); } @@ -370,7 +370,7 @@ class php_exporter foreach ($vars_array as $var) { - if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) + if (!preg_match('#^[a-z_][a-z0-9_]*$#i', $var)) { throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3); } @@ -392,11 +392,11 @@ class php_exporter public function get_vars_from_single_line_array($line, $throw_multiline = true) { $match = array(); - preg_match('#^\$vars = (?:\[|array\()\'([a-zA-Z0-9_\' ,]+)\'[\)\]];$#', $line, $match); + preg_match('#^\$vars = (?:(\[)|array\()\'([a-z0-9_\' ,]+)\'(?(1)\]|\));$#i', $line, $match); - if (isset($match[1])) + if (isset($match[2])) { - $vars_array = explode("', '", $match[1]); + $vars_array = explode("', '", $match[2]); if ($throw_multiline && sizeof($vars_array) > 6) { throw new \LogicException('Should use multiple lines for $vars definition ' @@ -420,7 +420,7 @@ class php_exporter { $current_vars_line = 2; $var_lines = array(); - while (ltrim($this->file_lines[$this->current_event_line - $current_vars_line], "\t") !== '$vars = array(') + while (!in_array(ltrim($this->file_lines[$this->current_event_line - $current_vars_line], "\t"), ['$vars = array(', '$vars = ['])) { $var_lines[] = substr(trim($this->file_lines[$this->current_event_line - $current_vars_line]), 0, -1); @@ -485,7 +485,7 @@ class php_exporter foreach ($doc_vars as $var) { - if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) + if (!preg_match('#^[a-z_][a-z0-9_]*$#i', $var)) { throw new \LogicException("Found invalid @var '{$var}' in docblock for event " . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 4); diff --git a/phpBB/phpbb/feed/helper.php b/phpBB/phpbb/feed/helper.php index e15d1e131e..7d50b7ce7d 100644 --- a/phpBB/phpbb/feed/helper.php +++ b/phpBB/phpbb/feed/helper.php @@ -13,41 +13,52 @@ namespace phpbb\feed; +use phpbb\config\config; +use phpbb\path_helper; +use phpbb\textformatter\s9e\renderer; +use phpbb\user; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Class with some helpful functions used in feeds */ class helper { - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\user */ - protected $user; + /** @var ContainerInterface */ + protected $container; - /** @var string */ - protected $phpbb_root_path; + /** @var path_helper */ + protected $path_helper; - /** @var string */ - protected $phpEx; + /** @var renderer */ + protected $renderer; + + /** @var user */ + protected $user; /** * Constructor * - * @param \phpbb\config\config $config Config object - * @param \phpbb\user $user User object - * @param string $phpbb_root_path Root path - * @param string $phpEx PHP file extension + * @param config $config Config object + * @param ContainerInterface $container Service container object + * @param path_helper $path_helper Path helper object + * @param renderer $renderer TextFormatter renderer object + * @param user $user User object */ - public function __construct(\phpbb\config\config $config, \phpbb\user $user, $phpbb_root_path, $phpEx) + public function __construct(config $config, ContainerInterface $container, path_helper $path_helper, renderer $renderer, user $user) { $this->config = $config; + $this->container = $container; + $this->path_helper = $path_helper; + $this->renderer = $renderer; $this->user = $user; - $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; } /** - * Run links through append_sid(), prepend generate_board_url() and remove session id + * Returns the board url (and caches it in the function) */ public function get_board_url() { @@ -104,16 +115,12 @@ class helper return ''; } - // Prepare some bbcodes for better parsing - $content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content); - - $content = generate_text_for_display($content, $uid, $bitfield, $options); + // Setup our own quote_helper to remove all attributes from quotes + $this->renderer->configure_quote_helper($this->container->get('feed.quote_helper')); - // Add newlines - $content = str_replace('<br />', '<br />' . "\n", $content); + $this->renderer->set_smilies_path($this->get_board_url() . '/' . $this->config['smilies_path']); - // Convert smiley Relative paths to Absolute path, Windows style - $content = str_replace($this->phpbb_root_path . $this->config['smilies_path'], $this->get_board_url() . '/' . $this->config['smilies_path'], $content); + $content = generate_text_for_display($content, $uid, $bitfield, $options); // Remove "Select all" link and mouse events $content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $this->user->lang['SELECT_ALL_CODE'] . '</a>', '', $content); @@ -152,7 +159,7 @@ class helper $content .= implode('<br />', $post_attachments); // Convert attachments' relative path to absolute path - $content = str_replace($this->phpbb_root_path . 'download/file.' . $this->phpEx, $this->get_board_url() . '/download/file.' . $this->phpEx, $content); + $content = str_replace($this->path_helper->get_web_root_path() . 'download/file.' . $this->path_helper->get_php_ext(), $this->get_board_url() . '/download/file.' . $this->path_helper->get_php_ext(), $content); } // Remove Comments from inline attachments [ia] diff --git a/phpBB/phpbb/feed/quote_helper.php b/phpBB/phpbb/feed/quote_helper.php new file mode 100644 index 0000000000..843d075028 --- /dev/null +++ b/phpBB/phpbb/feed/quote_helper.php @@ -0,0 +1,36 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\feed; + +/** + * Modified quote_helper for feeds (basically just removing all attributes) + */ +class quote_helper extends \phpbb\textformatter\s9e\quote_helper +{ + /** + * {@inheritdoc} + */ + public function inject_metadata($xml) + { + // In feeds we don't want any attributes, so delete all of them + return \s9e\TextFormatter\Utils::replaceAttributes( + $xml, + 'QUOTE', + function () + { + return []; + } + ); + } +} diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 5aad7ee326..dcc4cdde51 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -933,6 +933,20 @@ class log implements \phpbb\log\log_interface $forum_auth['f_read'][$row['topic_id']] = $row['forum_id']; } + /** + * Allow modifying SQL query after topic data is retrieved (inside loop). + * + * @event core.phpbb_log_get_topic_auth_sql_after + * @var array forum_auth Forum permissions + * @var array row One row of data from SQL query + * @since 3.2.2-RC1 + */ + $vars = array( + 'forum_auth', + 'row', + ); + extract($this->dispatcher->trigger_event('core.phpbb_log_get_topic_auth_sql_after', compact($vars))); + if ($this->auth->acl_gets('a_', 'm_', $row['forum_id'])) { $forum_auth['m_'][$row['topic_id']] = $row['forum_id']; diff --git a/phpBB/phpbb/pagination.php b/phpBB/phpbb/pagination.php index a5a95b096d..40af5eda6b 100644 --- a/phpBB/phpbb/pagination.php +++ b/phpBB/phpbb/pagination.php @@ -136,6 +136,11 @@ class pagination */ public function generate_template_pagination($base_url, $block_var_name, $start_name, $num_items, $per_page, $start = 1, $reverse_count = false, $ignore_on_page = false) { + if (empty($base_url)) + { + return; + } + $total_pages = ceil($num_items / $per_page); $on_page = $this->get_on_page($per_page, $start); $u_previous_page = $u_next_page = ''; diff --git a/phpBB/phpbb/permissions.php b/phpBB/phpbb/permissions.php index c9181e6202..7697884b6a 100644 --- a/phpBB/phpbb/permissions.php +++ b/phpBB/phpbb/permissions.php @@ -260,6 +260,7 @@ class permissions // Forum Permissions 'f_list' => array('lang' => 'ACL_F_LIST', 'cat' => 'actions'), + 'f_list_topics' => array('lang' => 'ACL_F_LIST_TOPICS', 'cat' => 'actions'), 'f_read' => array('lang' => 'ACL_F_READ', 'cat' => 'actions'), 'f_search' => array('lang' => 'ACL_F_SEARCH', 'cat' => 'actions'), 'f_subscribe' => array('lang' => 'ACL_F_SUBSCRIBE', 'cat' => 'actions'), diff --git a/phpBB/phpbb/search/fulltext_sphinx.php b/phpBB/phpbb/search/fulltext_sphinx.php index 59c3d55076..a20e3ad4b5 100644 --- a/phpBB/phpbb/search/fulltext_sphinx.php +++ b/phpBB/phpbb/search/fulltext_sphinx.php @@ -304,7 +304,7 @@ class fulltext_sphinx array('sql_attr_string', 'post_subject'), ), 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array( - array('sql_query_pre', ''), + array('sql_query_pre', 'SET NAMES \'utf8\''), array('sql_query_range', ''), array('sql_range_step', ''), array('sql_query', 'SELECT @@ -324,6 +324,7 @@ class fulltext_sphinx WHERE p.topic_id = t.topic_id AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'), + array('sql_query_post_index', ''), ), 'index index_phpbb_' . $this->id . '_main' => array( array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'), diff --git a/phpBB/phpbb/template/context.php b/phpBB/phpbb/template/context.php index 392efd5933..c1e971c148 100644 --- a/phpBB/phpbb/template/context.php +++ b/phpBB/phpbb/template/context.php @@ -190,70 +190,50 @@ class context public function assign_block_vars($blockname, array $vararray) { $this->num_rows_is_set = false; - if (strpos($blockname, '.') !== false) - { - // Nested block. - $blocks = explode('.', $blockname); - $blockcount = sizeof($blocks) - 1; - $str = &$this->tpldata; - for ($i = 0; $i < $blockcount; $i++) - { - $str = &$str[$blocks[$i]]; - $str = &$str[sizeof($str) - 1]; - } - - $s_row_count = isset($str[$blocks[$blockcount]]) ? sizeof($str[$blocks[$blockcount]]) : 0; - $vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count; + // For nested block, $blockcount > 0, for top-level block, $blockcount == 0 + $blocks = explode('.', $blockname); + $blockcount = count($blocks) - 1; - // Assign S_FIRST_ROW - if (!$s_row_count) - { - $vararray['S_FIRST_ROW'] = true; - } + $block = &$this->tpldata; + for ($i = 0; $i < $blockcount; $i++) + { + $pos = strpos($blocks[$i], '['); + $name = ($pos !== false) ? substr($blocks[$i], 0, $pos) : $blocks[$i]; + $block = &$block[$name]; + $index = (!$pos || strpos($blocks[$i], '[]') === $pos) ? (count($block) - 1) : (min((int) substr($blocks[$i], $pos + 1, -1), count($block) - 1)); + $block = &$block[$index]; + } - // Assign S_BLOCK_NAME - $vararray['S_BLOCK_NAME'] = $blocks[$blockcount]; + // $block = &$block[$blocks[$i]]; // Do not traverse the last block as it might be empty + $name = $blocks[$i]; - // Now the tricky part, we always assign S_LAST_ROW and remove the entry before - // This is much more clever than going through the complete template data on display (phew) - $vararray['S_LAST_ROW'] = true; - if ($s_row_count > 0) - { - unset($str[$blocks[$blockcount]][($s_row_count - 1)]['S_LAST_ROW']); - } + // Assign S_ROW_COUNT and S_ROW_NUM + $s_row_count = isset($block[$name]) ? count($block[$name]) : 0; + $vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count; - // Now we add the block that we're actually assigning to. - // We're adding a new iteration to this block with the given - // variable assignments. - $str[$blocks[$blockcount]][] = $vararray; - } - else + // Assign S_FIRST_ROW + if (!$s_row_count) { - // Top-level block. - $s_row_count = (isset($this->tpldata[$blockname])) ? sizeof($this->tpldata[$blockname]) : 0; - $vararray['S_ROW_COUNT'] = $vararray['S_ROW_NUM'] = $s_row_count; - - // Assign S_FIRST_ROW - if (!$s_row_count) - { - $vararray['S_FIRST_ROW'] = true; - } - - // Assign S_BLOCK_NAME - $vararray['S_BLOCK_NAME'] = $blockname; + $vararray['S_FIRST_ROW'] = true; + } - // We always assign S_LAST_ROW and remove the entry before - $vararray['S_LAST_ROW'] = true; - if ($s_row_count > 0) - { - unset($this->tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']); - } + // Assign S_BLOCK_NAME + $vararray['S_BLOCK_NAME'] = $name; - // Add a new iteration to this block with the variable assignments we were given. - $this->tpldata[$blockname][] = $vararray; + // Now the tricky part, we always assign S_LAST_ROW and remove the entry before + // This is much more clever than going through the complete template data on display (phew) + $vararray['S_LAST_ROW'] = true; + if ($s_row_count > 0) + { + unset($block[$name][($s_row_count - 1)]['S_LAST_ROW']); } + // Now we add the block that we're actually assigning to. + // We're adding a new iteration to this block with the given + // variable assignments. + $block[$name][] = $vararray; + return true; } |