From 8e5e954438b232f4ce7aec6a5db3d52b974c07a8 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sun, 22 Feb 2015 23:36:27 +0100 Subject: [PATCH] [ticket/13645] Move the feeds to controllers PHPBB3-13645 --- .gitignore | 1 + phpBB/config/default/container/services.yml | 5 +- .../default/container/services_feed.yml | 21 +- .../default/container/services_routing.yml | 11 + .../default/container/services_twig.yml | 4 +- phpBB/config/default/routing/feed.yml | 35 ++ phpBB/config/default/routing/routing.yml | 8 + phpBB/feed.php | 220 +--------- phpBB/includes/functions.php | 2 +- phpBB/language/en/common.php | 1 + phpBB/phpbb/controller/helper.php | 93 +---- phpBB/phpbb/di/container_builder.php | 2 +- phpBB/phpbb/feed/controller/feed.php | 387 ++++++++++++++++++ phpBB/phpbb/feed/exception/feed_exception.php | 21 + .../exception/feed_unavailable_exception.php | 19 + .../feed/exception/no_feed_exception.php | 22 + .../feed/exception/no_forum_exception.php | 22 + .../feed/exception/no_topic_exception.php | 22 + .../feed/exception/unauthorized_exception.php | 19 + .../unauthorized_forum_exception.php | 22 + .../unauthorized_topic_exception.php | 22 + phpBB/phpbb/feed/factory.php | 127 ------ phpBB/phpbb/feed/forum.php | 14 +- phpBB/phpbb/feed/topic.php | 15 +- phpBB/phpbb/routing/helper.php | 153 +++++++ .../phpbb/template/twig/extension/routing.php | 43 ++ phpBB/styles/all/template/feed.xml.twig | 37 ++ .../prosilver/template/overall_header.html | 16 +- tests/controller/common_helper_route.php | 25 +- tests/functional/browse_test.php | 2 +- .../controllers_compatibility_test.php | 13 + tests/functional/feed_test.php | 133 +++--- tests/mock/controller_helper.php | 13 - tests/pagination/pagination_test.php | 3 +- 34 files changed, 1019 insertions(+), 534 deletions(-) create mode 100644 phpBB/config/default/routing/feed.yml create mode 100644 phpBB/phpbb/feed/controller/feed.php create mode 100644 phpBB/phpbb/feed/exception/feed_exception.php create mode 100644 phpBB/phpbb/feed/exception/feed_unavailable_exception.php create mode 100644 phpBB/phpbb/feed/exception/no_feed_exception.php create mode 100644 phpBB/phpbb/feed/exception/no_forum_exception.php create mode 100644 phpBB/phpbb/feed/exception/no_topic_exception.php create mode 100644 phpBB/phpbb/feed/exception/unauthorized_exception.php create mode 100644 phpBB/phpbb/feed/exception/unauthorized_forum_exception.php create mode 100644 phpBB/phpbb/feed/exception/unauthorized_topic_exception.php delete mode 100644 phpBB/phpbb/feed/factory.php create mode 100644 phpBB/phpbb/routing/helper.php create mode 100644 phpBB/phpbb/template/twig/extension/routing.php create mode 100644 phpBB/styles/all/template/feed.xml.twig diff --git a/.gitignore b/.gitignore index ef3470488c..8fd9b40073 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ /phpBB/store/* /phpBB/styles/* !/phpBB/styles/prosilver +!/phpBB/styles/all /phpBB/vendor /tests/phpbb_unit_tests.sqlite* /tests/test_config*.php diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index 841b50c38b..1943381f4a 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -84,12 +84,9 @@ services: - @template - @user - @config - - @router - @symfony_request - @request - - @filesystem - - %core.root_path% - - %core.php_ext% + - @routing.helper controller.resolver: class: phpbb\controller\resolver diff --git a/phpBB/config/default/container/services_feed.yml b/phpBB/config/default/container/services_feed.yml index 48bd9fe76f..2133b3c489 100644 --- a/phpBB/config/default/container/services_feed.yml +++ b/phpBB/config/default/container/services_feed.yml @@ -1,4 +1,18 @@ services: + phpbb.feed.controller: + class: phpbb\feed\controller\feed + arguments: + - @template.twig.environment + - @symfony_request + - @controller.helper + - @config + - @dbal.conn + - @service_container + - @feed.helper + - @user + - @auth + - %core.php_ext% + feed.helper: class: phpbb\feed\helper arguments: @@ -7,13 +21,6 @@ services: - %core.root_path% - %core.php_ext% - feed.factory: - class: phpbb\feed\factory - arguments: - - @service_container - - @config - - @dbal.conn - feed.forum: class: phpbb\feed\forum scope: prototype diff --git a/phpBB/config/default/container/services_routing.yml b/phpBB/config/default/container/services_routing.yml index f76b5e5ede..ec5ccd3b89 100644 --- a/phpBB/config/default/container/services_routing.yml +++ b/phpBB/config/default/container/services_routing.yml @@ -18,3 +18,14 @@ services: - @request_stack tags: - { name: kernel.event_subscriber } + + routing.helper: + class: phpbb\routing\helper + arguments: + - @config + - @router + - @symfony_request + - @request + - @filesystem + - %core.root_path% + - %core.php_ext% diff --git a/phpBB/config/default/container/services_twig.yml b/phpBB/config/default/container/services_twig.yml index 2799892376..4132be49fa 100644 --- a/phpBB/config/default/container/services_twig.yml +++ b/phpBB/config/default/container/services_twig.yml @@ -40,9 +40,9 @@ services: - { name: twig.extension } template.twig.extensions.routing: - class: Symfony\Bridge\Twig\Extension\RoutingExtension + class: phpbb\template\twig\extension\routing arguments: - - @router + - @routing.helper tags: - { name: twig.extension } diff --git a/phpBB/config/default/routing/feed.yml b/phpBB/config/default/routing/feed.yml new file mode 100644 index 0000000000..22c9ea5755 --- /dev/null +++ b/phpBB/config/default/routing/feed.yml @@ -0,0 +1,35 @@ +phpbb_feed_forums: + path: /forums + defaults: { _controller: phpbb.feed.controller:forums } + +phpbb_feed_news: + path: /news + defaults: { _controller: phpbb.feed.controller:news } + +phpbb_feed_topics: + path: /topics + defaults: { _controller: phpbb.feed.controller:topics } + +phpbb_feed_topics_active: + path: /topics_active + defaults: { _controller: phpbb.feed.controller:topics_active } + +phpbb_feed_topics_new: + path: /topics_new + defaults: { _controller: phpbb.feed.controller:topics_new } + +phpbb_feed_forum: + path: /forum/{forum_id} + defaults: { _controller: phpbb.feed.controller:forum } + requirements: + forum_id: \d+ + +phpbb_feed_topic: + path: /topic/{topic_id} + defaults: { _controller: phpbb.feed.controller:topic } + requirements: + topic_id: \d+ + +phpbb_feed_overall: + path: /{mode} + defaults: { _controller: phpbb.feed.controller:overall } diff --git a/phpBB/config/default/routing/routing.yml b/phpBB/config/default/routing/routing.yml index b7e7a69b4f..073984841a 100644 --- a/phpBB/config/default/routing/routing.yml +++ b/phpBB/config/default/routing/routing.yml @@ -8,6 +8,14 @@ # instantiate the "foo_service" service and call the "method" method. # +phpbb_feed_routing: + resource: "feed.yml" + prefix: /feed + +phpbb_feed_index: + path: /feed + defaults: { _controller: phpbb.feed.controller:overall } + phpbb_help_routing: resource: "help.yml" prefix: /help diff --git a/phpBB/feed.php b/phpBB/feed.php index a7428ea846..1480867d6c 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -16,6 +16,9 @@ * **/ +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\Routing\Exception\InvalidParameterException; + /** * @ignore **/ @@ -23,222 +26,33 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($phpbb_root_path . 'includes/functions_display.' . $phpEx); -if (!$config['feed_enable']) -{ - trigger_error('NO_FEED_ENABLED'); -} +/** @var \phpbb\controller\helper $controller_helper */ +$controller_helper = $phpbb_container->get('controller.helper'); -// Start session -$user->session_begin(); - -if (!empty($config['feed_http_auth']) && $request->variable('auth', '') == 'http') -{ - phpbb_http_login(array( - 'auth_message' => 'Feed', - 'viewonline' => $request->variable('viewonline', true), - )); -} - -$auth->acl($user->data); -$user->setup('viewtopic'); - -// Initial var setup $forum_id = $request->variable('f', 0); $topic_id = $request->variable('t', 0); -$mode = $request->variable('mode', ''); +$mode = $request->variable('mode', ''); -// We do not use a template, therefore we simply define the global template variables here -$global_vars = $item_vars = array(); -$feed_updated_time = 0; - -// Generate params array for use in append_sid() to correctly link back to this page -$params = false; -if ($forum_id || $topic_id || $mode) +if ($forum_id !== 0) { - $params = array( - 'f' => ($forum_id) ? $forum_id : NULL, - 't' => ($topic_id) ? $topic_id : NULL, - 'mode' => ($mode) ? $mode : NULL, - ); + $url = $controller_helper->route('phpbb_feed_forum', array('forum_id' => $forum_id)); } - -// This boards URL -/* @var $phpbb_feed_helper \phpbb\feed\helper */ -$phpbb_feed_helper = $phpbb_container->get('feed.helper'); -$board_url = $phpbb_feed_helper->get_board_url(); - -// Get correct feed object -/* @var $phpbb_feed_factory \phpbb\feed\factory */ -$phpbb_feed_factory = $phpbb_container->get('feed.factory'); -$feed = $phpbb_feed_factory->get_feed($mode, $forum_id, $topic_id); - -// No feed found -if ($feed === false) +else if ($topic_id !== 0) { - trigger_error('NO_FEED'); + $url = $controller_helper->route('phpbb_feed_topic', array('topic_id' => $topic_id)); } - -// Open Feed -$feed->open(); - -// Iterate through items -while ($row = $feed->get_item()) +else { - // BBCode options to correctly disable urls, smilies, bbcode... - if ($feed->get('options') === NULL) + try { - // Allow all combinations - $options = 7; - - if ($feed->get('enable_bbcode') !== NULL && $feed->get('enable_smilies') !== NULL && $feed->get('enable_magic_url') !== NULL) - { - $options = (($row[$feed->get('enable_bbcode')]) ? OPTION_FLAG_BBCODE : 0) + (($row[$feed->get('enable_smilies')]) ? OPTION_FLAG_SMILIES : 0) + (($row[$feed->get('enable_magic_url')]) ? OPTION_FLAG_LINKS : 0); - } + $url = $controller_helper->route('phpbb_feed_overall', array('mode' => $mode)); } - else + catch (InvalidParameterException $e) { - $options = $row[$feed->get('options')]; - } - - $title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : ''); - - $published = ($feed->get('published') !== NULL) ? (int) $row[$feed->get('published')] : 0; - $updated = ($feed->get('updated') !== NULL) ? (int) $row[$feed->get('updated')] : 0; - - $display_attachments = ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && isset($row['post_attachment']) && $row['post_attachment']) ? true : false; - - $item_row = array( - 'author' => ($feed->get('creator') !== NULL) ? $row[$feed->get('creator')] : '', - 'published' => ($published > 0) ? $phpbb_feed_helper->format_date($published) : '', - 'updated' => ($updated > 0) ? $phpbb_feed_helper->format_date($updated) : '', - 'link' => '', - 'title' => censor_text($title), - 'category' => ($config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $phpEx . '?f=' . $row['forum_id'] : '', - 'category_name' => ($config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '', - 'description' => censor_text($phpbb_feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], ($display_attachments ? $feed->get_attachments($row['post_id']) : array()))), - 'statistics' => '', - ); - - // Adjust items, fill link, etc. - $feed->adjust_item($item_row, $row); - - $item_vars[] = $item_row; - - $feed_updated_time = max($feed_updated_time, $published, $updated); -} - -// If we do not have any items at all, sending the current time is better than sending no time. -if (!$feed_updated_time) -{ - $feed_updated_time = time(); -} - -// Some default assignments -// FEED_IMAGE is not used (atom) -$global_vars = array_merge($global_vars, array( - 'FEED_IMAGE' => '', - 'SELF_LINK' => $phpbb_feed_helper->append_sid('feed.' . $phpEx, $params), - 'FEED_LINK' => $board_url . '/index.' . $phpEx, - 'FEED_TITLE' => $config['sitename'], - 'FEED_SUBTITLE' => $config['site_desc'], - 'FEED_UPDATED' => $phpbb_feed_helper->format_date($feed_updated_time), - 'FEED_LANG' => $user->lang['USER_LANG'], - 'FEED_AUTHOR' => $config['sitename'], -)); - -$feed->close(); - -// Output page - -// gzip_compression -if ($config['gzip_compress']) -{ - if (@extension_loaded('zlib') && !headers_sent()) - { - ob_start('ob_gzhandler'); + $url = $controller_helper->route('phpbb_feed_index'); } } -// IF debug extra is enabled and admin want to "explain" the page we need to set other headers... -if (defined('DEBUG') && $request->variable('explain', 0) && $auth->acl_get('a_')) -{ - header('Content-type: text/html; charset=UTF-8'); - header('Cache-Control: private, no-cache="set-cookie"'); - header('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); - - $mtime = explode(' ', microtime()); - $totaltime = $mtime[0] + $mtime[1] - $starttime; - - if (method_exists($db, 'sql_report')) - { - $db->sql_report('display'); - } - - garbage_collection(); - exit_handler(); -} - -header("Content-Type: application/atom+xml; charset=UTF-8"); -header("Last-Modified: " . gmdate('D, d M Y H:i:s', $feed_updated_time) . ' GMT'); - -if (!empty($user->data['is_bot'])) -{ - // Let reverse proxies know we detected a bot. - header('X-PHPBB-IS-BOT: yes'); -} - -echo '' . "\n"; -echo '' . "\n"; -echo '' . "\n\n"; - -echo (!empty($global_vars['FEED_TITLE'])) ? '' . $global_vars['FEED_TITLE'] . '' . "\n" : ''; -echo (!empty($global_vars['FEED_SUBTITLE'])) ? '' . $global_vars['FEED_SUBTITLE'] . '' . "\n" : ''; -echo (!empty($global_vars['FEED_LINK'])) ? '' . "\n" : ''; -echo '' . $global_vars['FEED_UPDATED'] . '' . "\n\n"; - -echo '' . "\n"; -echo '' . $global_vars['SELF_LINK'] . '' . "\n"; - -foreach ($item_vars as $row) -{ - echo '' . "\n"; - - if (!empty($row['author'])) - { - echo '' . "\n"; - } - - echo '' . ((!empty($row['updated'])) ? $row['updated'] : $row['published']) . '' . "\n"; - - if (!empty($row['published'])) - { - echo '' . $row['published'] . '' . "\n"; - } - - echo '' . $row['link'] . '' . "\n"; - echo '' . "\n"; - echo '<![CDATA[' . $row['title'] . ']]>' . "\n\n"; - - if (!empty($row['category']) && isset($row['category_name']) && $row['category_name'] !== '') - { - echo '' . "\n"; - } - - echo '' . $user->lang['STATISTICS'] . ': ' . $row['statistics'] . '

'; - } - - echo '
' . "\n" . ']]>
' . "\n"; - echo '
' . "\n"; -} - -echo '
'; - -garbage_collection(); -exit_handler(); +$response = new RedirectResponse($url, 301); +$response->send(); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c6d63e13f4..56068242dd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4351,7 +4351,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id = 'U_TERMS_USE' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=terms'), 'U_PRIVACY' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=privacy'), 'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '', - 'U_FEED' => generate_board_url() . "/feed.$phpEx", + 'U_FEED' => $controller_helper->route('phpbb_feed_index'), 'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS) ? true : false, 'S_AUTOLOGIN_ENABLED' => ($config['allow_autologin']) ? true : false, diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index cb99183dd8..76fa1c15f7 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -691,6 +691,7 @@ $lang = array_merge($lang, array( 'SKYPE' => 'Skype', 'SMTP_NO_AUTH_SUPPORT' => 'SMTP server does not support authentication.', 'SORRY_AUTH_READ' => 'You are not authorised to read this forum.', + 'SORRY_AUTH_READ_TOPIC' => 'You are not authorised to read this topic.', 'SORRY_AUTH_VIEW_ATTACH' => 'You are not authorised to download this attachment.', 'SORT_BY' => 'Sort by', 'SORT_JOINED' => 'Joined date', diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index 3782512fa4..5722951278 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -16,7 +16,6 @@ namespace phpbb\controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RequestContext; /** * Controller helper class, contains methods that do things for controllers @@ -41,12 +40,6 @@ class helper */ protected $config; - /** - * phpBB router - * @var \phpbb\routing\router - */ - protected $router; - /* @var \phpbb\symfony_request */ protected $symfony_request; @@ -54,21 +47,9 @@ class helper protected $request; /** - * @var \phpbb\filesystem\filesystem_interface The filesystem object - */ - protected $filesystem; - - /** - * phpBB root path - * @var string - */ - protected $phpbb_root_path; - - /** - * PHP file extension - * @var string - */ - protected $php_ext; + * @var \phpbb\routing\helper + */ + protected $routing_helper; /** * Constructor @@ -76,24 +57,18 @@ class helper * @param \phpbb\template\template $template Template object * @param \phpbb\user $user User object * @param \phpbb\config\config $config Config object - * @param \phpbb\routing\router $router phpBB router * @param \phpbb\symfony_request $symfony_request Symfony Request object * @param \phpbb\request\request_interface $request phpBB request object - * @param \phpbb\filesystem\filesystem_interface $filesystem The filesystem object - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext PHP file extension + * @param \phpbb\routing\helper $routing_helper Helper to generate the routes */ - public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext) + public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\routing\helper $routing_helper) { $this->template = $template; $this->user = $user; $this->config = $config; - $this->router = $router; $this->symfony_request = $symfony_request; $this->request = $request; - $this->filesystem = $filesystem; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->routing_helper = $routing_helper; } /** @@ -131,61 +106,7 @@ class helper */ public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) { - $anchor = ''; - if (isset($params['#'])) - { - $anchor = '#' . $params['#']; - unset($params['#']); - } - - $context = new RequestContext(); - $context->fromRequest($this->symfony_request); - - $script_name = $this->symfony_request->getScriptName(); - $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); - - $base_url = $context->getBaseUrl(); - - // Append page name if base URL does not contain it - if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false) - { - $base_url .= '/' . $page_name; - } - - // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it. - $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); - - // We need to update the base url to move to the directory of the app.php file if the current script is not app.php - if ($page_name !== 'app.php') - { - if (empty($this->config['enable_mod_rewrite'])) - { - $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url); - } - else - { - $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path); - } - } - - $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true); - - $context->setBaseUrl($base_url); - - $this->router->setContext($context); - $route_url = $this->router->generate($route, $params, $reference_type); - - if ($is_amp) - { - $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url); - } - - if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) - { - $route_url = 'app.' . $this->php_ext . '/' . $route_url; - } - - return append_sid($route_url . $anchor, false, $is_amp, $session_id, true); + return $this->routing_helper->route($route, $params, $is_amp, $session_id, $reference_type); } /** diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index c9adbe7d63..fb391760ce 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -465,7 +465,7 @@ class container_builder 'core.root_path' => $this->phpbb_root_path, 'core.php_ext' => $this->php_ext, 'core.environment' => $this->get_environment(), - 'core.debug' => DEBUG, + 'core.debug' => defined('DEBUG') ? DEBUG : false, ), $this->get_env_parameters() ); diff --git a/phpBB/phpbb/feed/controller/feed.php b/phpBB/phpbb/feed/controller/feed.php new file mode 100644 index 0000000000..a2dd9393f6 --- /dev/null +++ b/phpBB/phpbb/feed/controller/feed.php @@ -0,0 +1,387 @@ + +* @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\controller; + +use phpbb\auth\auth; +use phpbb\config\config; +use phpbb\db\driver\driver_interface; +use phpbb\exception\http_exception; +use phpbb\feed\base; +use phpbb\feed\exception\feed_unavailable_exception; +use phpbb\feed\exception\unauthorized_exception; +use phpbb\feed\helper as feed_helper; +use phpbb\controller\helper as controller_helper; +use phpbb\symfony_request; +use phpbb\user; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + +class feed +{ + /** + * @var \Twig_Environment + */ + protected $template; + + /** + * @var symfony_request + */ + protected $request; + + /** + * @var controller_helper + */ + protected $controller_helper; + + /** + * @var config + */ + protected $config; + + /** + * @var driver_interface + */ + protected $db; + + /** + * @var ContainerInterface + */ + protected $container; + + /** + * @var feed_helper + */ + protected $feed_helper; + + /** + * @var user + */ + protected $user; + + /** + * @var auth + */ + protected $auth; + + /** + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param symfony_request $request; + * @param controller_helper $controller_helper + * @param config $config + * @param driver_interface $db + * @param ContainerInterface $container + * @param feed_helper $feed_helper + * @param user $user + * @param auth $auth + */ + public function __construct(\Twig_Environment $twig, symfony_request $request, controller_helper $controller_helper, config $config, driver_interface $db, ContainerInterface $container, feed_helper $feed_helper, user $user, auth $auth, $php_ext) + { + $this->request = $request; + $this->controller_helper = $controller_helper; + $this->config = $config; + $this->db = $db; + $this->container = $container; + $this->feed_helper = $feed_helper; + $this->user = $user; + $this->auth = $auth; + $this->php_ext = $php_ext; + $this->template = $twig; + } + + /** + * Controller for /feed/forums route + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function forums() + { + if (!$this->config['feed_overall_forums']) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.forums')); + } + + /** + * Controller for /feed/news route + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function news() + { + // Get at least one news forum + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0'); + $result = $this->db->sql_query_limit($sql, 1, 0, 600); + $s_feed_news = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + if (!$s_feed_news) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.news')); + } + + /** + * Controller for /feed/topics route + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function topics() + { + if (!$this->config['feed_topics_new']) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.topics')); + } + + /** + * Controller for /feed/topics_new route + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function topics_new() + { + return $this->topics(); + } + + /** + * Controller for /feed/topics_active route + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function topics_active() + { + if (!$this->config['feed_topics_active']) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.topics_active')); + } + + /** + * Controller for /feed/forum/{forum_id} route + * + * @param int $forum_id + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function forum($forum_id) + { + if (!$this->config['feed_forum']) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.forum')->set_forum_id($forum_id)); + } + + /** + * Controller for /feed/topic/{topic_id} route + * + * @param int $topic_id + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function topic($topic_id) + { + if (!$this->config['feed_topic']) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.topic')->set_topic_id($topic_id)); + } + + /** + * Controller for /feed/{mode] route + * + * @return Response + * + * @throws http_exception when the feed is disabled + */ + public function overall() + { + if (!$this->config['feed_overall']) + { + $this->send_unavailable(); + } + + return $this->send_feed($this->container->get('feed.overall')); + } + + /** + * Display a given feed + * + * @param base $feed + * + * @return Response + */ + protected function send_feed(base $feed) + { + try + { + return $this->send_feed_do($feed); + } + catch (feed_unavailable_exception $e) + { + throw new http_exception(Response::HTTP_NOT_FOUND, $e->getMessage(), $e->get_parameters(), $e); + } + catch (unauthorized_exception $e) + { + throw new http_exception(Response::HTTP_FORBIDDEN, $e->getMessage(), $e->get_parameters(), $e); + } + } + + /** + * Really send the feed + * + * @param base $feed + * + * @return Response + * + * @throw exception\feed_exception + */ + protected function send_feed_do(base $feed) + { + $feed_updated_time = 0; + $item_vars = array(); + + $board_url = $this->feed_helper->get_board_url(); + + // Open Feed + $feed->open(); + + // Iterate through items + while ($row = $feed->get_item()) + { + // BBCode options to correctly disable urls, smilies, bbcode... + if ($feed->get('options') === null) + { + // Allow all combinations + $options = 7; + + if ($feed->get('enable_bbcode') !== null && $feed->get('enable_smilies') !== null && $feed->get('enable_magic_url') !== null) + { + $options = (($row[$feed->get('enable_bbcode')]) ? OPTION_FLAG_BBCODE : 0) + (($row[$feed->get('enable_smilies')]) ? OPTION_FLAG_SMILIES : 0) + (($row[$feed->get('enable_magic_url')]) ? OPTION_FLAG_LINKS : 0); + } + } + else + { + $options = $row[$feed->get('options')]; + } + + $title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : ''); + + $published = ($feed->get('published') !== null) ? (int) $row[$feed->get('published')] : 0; + $updated = ($feed->get('updated') !== null) ? (int) $row[$feed->get('updated')] : 0; + + $display_attachments = ($this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $row['forum_id']) && isset($row['post_attachment']) && $row['post_attachment']) ? true : false; + + $item_row = array( + 'author' => ($feed->get('creator') !== null) ? $row[$feed->get('creator')] : '', + 'published' => ($published > 0) ? $this->feed_helper->format_date($published) : '', + 'updated' => ($updated > 0) ? $this->feed_helper->format_date($updated) : '', + 'link' => '', + 'title' => censor_text($title), + 'category' => ($this->config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $this->php_ext . '?f=' . $row['forum_id'] : '', + 'category_name' => ($this->config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '', + 'description' => censor_text($this->feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], ($display_attachments ? $feed->get_attachments($row['post_id']) : array()))), + 'statistics' => '', + ); + + // Adjust items, fill link, etc. + $feed->adjust_item($item_row, $row); + + $item_vars[] = $item_row; + + $feed_updated_time = max($feed_updated_time, $published, $updated); + } + + // If we do not have any items at all, sending the current time is better than sending no time. + if (!$feed_updated_time) + { + $feed_updated_time = time(); + } + + $feed->close(); + + $content = $this->template->render('feed.xml.twig', array( + // Some default assignments + // FEED_IMAGE is not used (atom) + 'FEED_IMAGE' => '', + 'SELF_LINK' => $this->controller_helper->route($this->request->attributes->get('_route'), $this->request->attributes->get('_route_params'), true, '', UrlGeneratorInterface::ABSOLUTE_URL), + 'FEED_LINK' => $board_url . '/index.' . $this->php_ext, + 'FEED_TITLE' => $this->config['sitename'], + 'FEED_SUBTITLE' => $this->config['site_desc'], + 'FEED_UPDATED' => $this->feed_helper->format_date($feed_updated_time), + 'FEED_LANG' => $this->user->lang['USER_LANG'], + 'FEED_AUTHOR' => $this->config['sitename'], + + // Feed entries + 'FEED_ROWS' => $item_vars, + )); + + $response = new Response($content); + $response->headers->set('Content-Type', 'application/atom+xml'); + $response->setCharset('UTF-8'); + $response->setLastModified(new \DateTime('@' . $feed_updated_time)); + + if (!empty($this->user->data['is_bot'])) + { + // Let reverse proxies know we detected a bot. + $response->headers->set('X-PHPBB-IS-BOT', 'yes'); + } + + return $response; + } + + /** + * Throw and exception saying that the feed isn't available + * + * @throw http_exception + */ + protected function send_unavailable() + { + throw new http_exception(404, 'FEATURE_NOT_AVAILABLE'); + } +} diff --git a/phpBB/phpbb/feed/exception/feed_exception.php b/phpBB/phpbb/feed/exception/feed_exception.php new file mode 100644 index 0000000000..c9c888211e --- /dev/null +++ b/phpBB/phpbb/feed/exception/feed_exception.php @@ -0,0 +1,21 @@ + + * @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\exception; + +use phpbb\exception\runtime_exception; + +abstract class feed_exception extends runtime_exception +{ + +} diff --git a/phpBB/phpbb/feed/exception/feed_unavailable_exception.php b/phpBB/phpbb/feed/exception/feed_unavailable_exception.php new file mode 100644 index 0000000000..4b6605b47d --- /dev/null +++ b/phpBB/phpbb/feed/exception/feed_unavailable_exception.php @@ -0,0 +1,19 @@ + + * @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\exception; + +abstract class feed_unavailable_exception extends feed_exception +{ + +} diff --git a/phpBB/phpbb/feed/exception/no_feed_exception.php b/phpBB/phpbb/feed/exception/no_feed_exception.php new file mode 100644 index 0000000000..af6357b74c --- /dev/null +++ b/phpBB/phpbb/feed/exception/no_feed_exception.php @@ -0,0 +1,22 @@ + + * @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\exception; + +class no_feed_exception extends feed_unavailable_exception +{ + public function __construct(\Exception $previous = null, $code = 0) + { + parent::__construct('NO_FEED', array(), $previous, $code); + } +} diff --git a/phpBB/phpbb/feed/exception/no_forum_exception.php b/phpBB/phpbb/feed/exception/no_forum_exception.php new file mode 100644 index 0000000000..a60832957a --- /dev/null +++ b/phpBB/phpbb/feed/exception/no_forum_exception.php @@ -0,0 +1,22 @@ + + * @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\exception; + +class no_forum_exception extends feed_unavailable_exception +{ + public function __construct($forum_id, \Exception $previous = null, $code = 0) + { + parent::__construct('NO_FORUM', array($forum_id), $previous, $code); + } +} diff --git a/phpBB/phpbb/feed/exception/no_topic_exception.php b/phpBB/phpbb/feed/exception/no_topic_exception.php new file mode 100644 index 0000000000..b961a65d1c --- /dev/null +++ b/phpBB/phpbb/feed/exception/no_topic_exception.php @@ -0,0 +1,22 @@ + + * @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\exception; + +class no_topic_exception extends feed_unavailable_exception +{ + public function __construct($topic_id, \Exception $previous = null, $code = 0) + { + parent::__construct('NO_TOPIC', array($topic_id), $previous, $code); + } +} diff --git a/phpBB/phpbb/feed/exception/unauthorized_exception.php b/phpBB/phpbb/feed/exception/unauthorized_exception.php new file mode 100644 index 0000000000..7868975779 --- /dev/null +++ b/phpBB/phpbb/feed/exception/unauthorized_exception.php @@ -0,0 +1,19 @@ + + * @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\exception; + +abstract class unauthorized_exception extends feed_exception +{ + +} diff --git a/phpBB/phpbb/feed/exception/unauthorized_forum_exception.php b/phpBB/phpbb/feed/exception/unauthorized_forum_exception.php new file mode 100644 index 0000000000..4384c7b39b --- /dev/null +++ b/phpBB/phpbb/feed/exception/unauthorized_forum_exception.php @@ -0,0 +1,22 @@ + + * @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\exception; + +class unauthorized_forum_exception extends unauthorized_exception +{ + public function __construct($forum_id, \Exception $previous = null, $code = 0) + { + parent::__construct('SORRY_AUTH_READ', array($forum_id), $previous, $code); + } +} diff --git a/phpBB/phpbb/feed/exception/unauthorized_topic_exception.php b/phpBB/phpbb/feed/exception/unauthorized_topic_exception.php new file mode 100644 index 0000000000..f49f0a0476 --- /dev/null +++ b/phpBB/phpbb/feed/exception/unauthorized_topic_exception.php @@ -0,0 +1,22 @@ + + * @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\exception; + +class unauthorized_topic_exception extends unauthorized_exception +{ + public function __construct($topic_id, \Exception $previous = null, $code = 0) + { + parent::__construct('SORRY_AUTH_READ_TOPIC', array($topic_id), $previous, $code); + } +} diff --git a/phpBB/phpbb/feed/factory.php b/phpBB/phpbb/feed/factory.php deleted file mode 100644 index f364f06d03..0000000000 --- a/phpBB/phpbb/feed/factory.php +++ /dev/null @@ -1,127 +0,0 @@ - -* @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; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** -* Factory class to return correct object -*/ -class factory -{ - /** - * Service container object - * @var ContainerInterface - */ - protected $container; - - /** @var \phpbb\config\config */ - protected $config; - - /** @var \phpbb\db\driver\driver_interface */ - protected $db; - - /** - * Constructor - * - * @param ContainerInterface $container Container object - * @param \phpbb\config\config $config Config object - * @param \phpbb\db\driver\driver_interface $db Database connection - */ - public function __construct(ContainerInterface $container, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db) - { - $this->container = $container; - $this->config = $config; - $this->db = $db; - } - - /** - * Return correct object for specified mode - * - * @param string $mode The feeds mode. - * @param int $forum_id Forum id specified by the script if forum feed provided. - * @param int $topic_id Topic id specified by the script if topic feed provided. - * - * @return object Returns correct feeds object for specified mode. - */ - function get_feed($mode, $forum_id, $topic_id) - { - switch ($mode) - { - case 'forums': - if (!$this->config['feed_overall_forums']) - { - return false; - } - - return $this->container->get('feed.forums'); - break; - - case 'topics': - case 'topics_new': - if (!$this->config['feed_topics_new']) - { - return false; - } - - return $this->container->get('feed.topics'); - break; - - case 'topics_active': - if (!$this->config['feed_topics_active']) - { - return false; - } - - return $this->container->get('feed.topics_active'); - break; - - case 'news': - // Get at least one news forum - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0'); - $result = $this->db->sql_query_limit($sql, 1, 0, 600); - $s_feed_news = (int) $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - if (!$s_feed_news) - { - return false; - } - - return $this->container->get('feed.news'); - break; - - default: - if ($topic_id && $this->config['feed_topic']) - { - return $this->container->get('feed.topic') - ->set_topic_id($topic_id); - } - else if ($forum_id && $this->config['feed_forum']) - { - return $this->container->get('feed.forum') - ->set_forum_id($forum_id); - } - else if ($this->config['feed_overall']) - { - return $this->container->get('feed.overall'); - } - - return false; - break; - } - } -} diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php index 7a2087c1cd..f493c4729a 100644 --- a/phpBB/phpbb/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -13,6 +13,10 @@ namespace phpbb\feed; +use phpbb\feed\exception\no_feed_exception; +use phpbb\feed\exception\no_forum_exception; +use phpbb\feed\exception\unauthorized_forum_exception; + /** * Forum feed * @@ -49,25 +53,25 @@ class forum extends \phpbb\feed\post_base if (empty($this->forum_data)) { - trigger_error('NO_FORUM'); + throw new no_forum_exception($this->forum_id); } // Forum needs to be postable if ($this->forum_data['forum_type'] != FORUM_POST) { - trigger_error('NO_FEED'); + throw new no_feed_exception(); } // Make sure forum is not excluded from feed if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->forum_data['forum_options'])) { - trigger_error('NO_FEED'); + throw new no_feed_exception(); } // Make sure we can read this forum if (!$this->auth->acl_get('f_read', $this->forum_id)) { - trigger_error('SORRY_AUTH_READ'); + throw new unauthorized_forum_exception($this->forum_id); } // Make sure forum is not passworded or user is authed @@ -77,7 +81,7 @@ class forum extends \phpbb\feed\post_base if (isset($forum_ids_passworded[$this->forum_id])) { - trigger_error('SORRY_AUTH_READ'); + throw new unauthorized_forum_exception($this->forum_id); } unset($forum_ids_passworded); diff --git a/phpBB/phpbb/feed/topic.php b/phpBB/phpbb/feed/topic.php index 66c49e55cf..c916d3bccc 100644 --- a/phpBB/phpbb/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -13,6 +13,11 @@ namespace phpbb\feed; +use phpbb\feed\exception\no_feed_exception; +use phpbb\feed\exception\no_topic_exception; +use phpbb\feed\exception\unauthorized_forum_exception; +use phpbb\feed\exception\unauthorized_topic_exception; + /** * Topic feed for a specific topic * @@ -50,7 +55,7 @@ class topic extends \phpbb\feed\post_base if (empty($this->topic_data)) { - trigger_error('NO_TOPIC'); + throw new no_topic_exception($this->topic_id); } $this->forum_id = (int) $this->topic_data['forum_id']; @@ -58,19 +63,19 @@ class topic extends \phpbb\feed\post_base // Make sure topic is either approved or user authed if ($this->topic_data['topic_visibility'] != ITEM_APPROVED && !$this->auth->acl_get('m_approve', $this->forum_id)) { - trigger_error('SORRY_AUTH_READ'); + throw new unauthorized_topic_exception($this->topic_id); } // Make sure forum is not excluded from feed if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->topic_data['forum_options'])) { - trigger_error('NO_FEED'); + throw new no_feed_exception(); } // Make sure we can read this forum if (!$this->auth->acl_get('f_read', $this->forum_id)) { - trigger_error('SORRY_AUTH_READ'); + throw new unauthorized_forum_exception($this->forum_id); } // Make sure forum is not passworded or user is authed @@ -80,7 +85,7 @@ class topic extends \phpbb\feed\post_base if (isset($forum_ids_passworded[$this->forum_id])) { - trigger_error('SORRY_AUTH_READ'); + throw new unauthorized_forum_exception($this->forum_id); } unset($forum_ids_passworded); diff --git a/phpBB/phpbb/routing/helper.php b/phpBB/phpbb/routing/helper.php new file mode 100644 index 0000000000..f56974a354 --- /dev/null +++ b/phpBB/phpbb/routing/helper.php @@ -0,0 +1,153 @@ + +* @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\routing; + +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\RequestContext; + +/** +* Controller helper class, contains methods that do things for controllers +*/ +class helper +{ + /** + * config object + * @var \phpbb\config\config + */ + protected $config; + + /** + * phpBB router + * @var \phpbb\routing\router + */ + protected $router; + + /** + * @var \phpbb\symfony_request + */ + protected $symfony_request; + + /** + * @var \phpbb\request\request_interface + */ + protected $request; + + /** + * @var \phpbb\filesystem The filesystem object + */ + protected $filesystem; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP file extension + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param \phpbb\config\config $config Config object + * @param \phpbb\routing\router $router phpBB router + * @param \phpbb\symfony_request $symfony_request Symfony Request object + * @param \phpbb\request\request_interface $request phpBB request object + * @param \phpbb\filesystem\filesystem $filesystem The filesystem object + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP file extension + */ + public function __construct(\phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem $filesystem, $phpbb_root_path, $php_ext) + { + $this->config = $config; + $this->router = $router; + $this->symfony_request = $symfony_request; + $this->request = $request; + $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Generate a URL to a route + * + * @param string $route Name of the route to travel + * @param array $params String or array of additional url parameters + * @param bool $is_amp Is url using & (true) or & (false) + * @param string|bool $session_id Possibility to use a custom session id instead of the global one + * @param bool|string $reference_type The type of reference to be generated (one of the constants) + * @return string The URL already passed through append_sid() + */ + public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) + { + $anchor = ''; + if (isset($params['#'])) + { + $anchor = '#' . $params['#']; + unset($params['#']); + } + + $context = new RequestContext(); + $context->fromRequest($this->symfony_request); + + $script_name = $this->symfony_request->getScriptName(); + $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); + + $base_url = $context->getBaseUrl(); + + // Append page name if base URL does not contain it + if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false) + { + $base_url .= '/' . $page_name; + } + + // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it. + $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); + + // We need to update the base url to move to the directory of the app.php file if the current script is not app.php + if ($page_name !== 'app.php') + { + if (empty($this->config['enable_mod_rewrite'])) + { + $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url); + } + else + { + $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path); + } + } + + $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true); + + $context->setBaseUrl($base_url); + + $this->router->setContext($context); + $route_url = $this->router->generate($route, $params, $reference_type); + + if ($is_amp) + { + $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url); + } + + if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) + { + $route_url = 'app.' . $this->php_ext . '/' . $route_url; + } + + return append_sid($route_url . $anchor, false, $is_amp, $session_id, true); + } +} diff --git a/phpBB/phpbb/template/twig/extension/routing.php b/phpBB/phpbb/template/twig/extension/routing.php new file mode 100644 index 0000000000..829ce738eb --- /dev/null +++ b/phpBB/phpbb/template/twig/extension/routing.php @@ -0,0 +1,43 @@ + +* @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\template\twig\extension; + +use Symfony\Bridge\Twig\Extension\RoutingExtension; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + +class routing extends RoutingExtension +{ + /** @var \phpbb\controller\helper */ + protected $helper; + + /** + * Constructor + * + * @param \phpbb\routing\helper $helper + */ + public function __construct(\phpbb\routing\helper $helper) + { + $this->helper = $helper; + } + + public function getPath($name, $parameters = array(), $relative = false) + { + return $this->helper->route($name, $parameters, true, false, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH); + } + + public function getUrl($name, $parameters = array(), $schemeRelative = false) + { + return $this->helper->route($name, $parameters, true, false, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL); + } +} diff --git a/phpBB/styles/all/template/feed.xml.twig b/phpBB/styles/all/template/feed.xml.twig new file mode 100644 index 0000000000..91467c62cd --- /dev/null +++ b/phpBB/styles/all/template/feed.xml.twig @@ -0,0 +1,37 @@ + + + + + {% if not FEED_TITLE is empty %}{{ FEED_TITLE }}{% endif %} + + {% if not FEED_SUBTITLE is empty %}{{ FEED_SUBTITLE }}{% endif %} + + {% if not FEED_LINK is empty %}{% endif %} + + {{ FEED_UPDATED }} + + + {{ SELF_LINK }} + + {% for row in FEED_ROWS %} + + {% if not row.author is empty %}{% endif %} + + {% if not row.updated is empty %}{{ row.updated }} {% else %}{{ row.published }}{% endif %} + + {% if not row.published is empty %}{{ row.published }}{% endif %} + + {{ row.link }} + + <![CDATA[{{ row.title }}]]> + + {% if not row.category is empty and row.category_name is defined and row.category_name != '' %} + + {% endif %} + + {{ lang('STATISTICS') }}: {{ row.statistics }}

{% endif %}
+]]>
+
+ {% endfor %} +
diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 45f8eaa1c9..40e735c5c2 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -7,13 +7,13 @@ <!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --> - - - - - - - + + + + + + + @@ -46,7 +46,7 @@ - + diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 3c74c16bae..4c0c8569a3 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -125,6 +125,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case $this->router = new phpbb_mock_router($container, $this->filesystem, dirname(__FILE__) . '/', 'php', PHPBB_ENVIRONMENT, $this->extension_manager); $this->router->find_routing_files($this->extension_manager->all_enabled(false)); $this->router->find(dirname(__FILE__) . '/'); + // Set correct current phpBB root path $this->root_path = $this->get_phpbb_root_path(); } @@ -168,7 +169,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description); } @@ -211,7 +213,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description); } @@ -254,7 +257,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_absolute($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); } @@ -297,7 +301,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_relative_path($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); } @@ -340,7 +345,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_network($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); } @@ -383,7 +389,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_absolute_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); } @@ -423,7 +430,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_relative_path_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); } @@ -466,7 +474,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case public function test_helper_url_network_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) { $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); } } diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 4f28879687..280e814c06 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -48,7 +48,7 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case public function test_feed() { - $crawler = self::request('GET', 'feed.php', array(), false); + $crawler = self::request('GET', 'app.php/feed', array(), false); self::assert_response_xml(); $this->assertGreaterThan(0, $crawler->filter('entry')->count()); } diff --git a/tests/functional/controllers_compatibility_test.php b/tests/functional/controllers_compatibility_test.php index 7ba0b0d991..9499888a1a 100644 --- a/tests/functional/controllers_compatibility_test.php +++ b/tests/functional/controllers_compatibility_test.php @@ -24,6 +24,19 @@ class phpbb_functional_controllers_compatibility_test extends phpbb_functional_t $this->assert301('report.php?pm=1', 'app.php/pm/1/report'); } + public function test_feed_compatibility() + { + $this->assert301('feed.php', 'app.php/feed'); + $this->assert301('feed.php?mode=foobar', 'app.php/feed/foobar'); + $this->assert301('feed.php?mode=news', 'app.php/feed/news'); + $this->assert301('feed.php?mode=topics', 'app.php/feed/topics'); + $this->assert301('feed.php?mode=topics_news', 'app.php/feed/topics_news'); + $this->assert301('feed.php?mode=topics_active', 'app.php/feed/topics_active'); + $this->assert301('feed.php?mode=forums', 'app.php/feed/forums'); + $this->assert301('feed.php?f=1', 'app.php/feed/forum/1'); + $this->assert301('feed.php?t=1', 'app.php/feed/topic/1'); + } + protected function assert301($from, $to) { self::$client->followRedirects(false); diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index 9041c8dc69..fc3f052e91 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + /** * @group functional */ @@ -24,9 +26,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case { parent::__construct($name, $data, $dataName); - $this->backupStaticAttributesBlacklist += array( - 'phpbb_functional_feed_test' => array('init_values'), - ); + $this->backupStaticAttributesBlacklist['phpbb_functional_feed_test'] = array('init_values'); + + $this->purge_cache(); } public function test_setup_config_before_state() @@ -55,66 +57,64 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form->setValues($values); $crawler = self::submit($form); - $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); // Special config (Guest can't see attachments) $this->add_lang('acp/permissions'); $crawler = self::request('GET', "adm/index.php?i=acp_permissions&sid={$this->sid}&icat=16&mode=setting_group_global&group_id[0]=1"); - $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + self::assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); $form['setting[1][0][u_download]']->select(-1); $crawler = self::submit($form); - $this->assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text()); + self::assertContainsLang('AUTH_UPDATED', $crawler->filter('.successbox')->text()); } public function test_dump_board_state() { - $crawler = self::request('GET', 'feed.php?mode=forums', array(), false); + $crawler = self::request('GET', 'app.php/feed/forums', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['forums_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=overall', array(), false); + $crawler = self::request('GET', 'app.php/feed/overall', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['overall_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['topics_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_new', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['topics_new_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_active', array(), false); self::assert_response_xml(); self::$init_values['disapprove_user']['topics_active_value'] = $crawler->filterXPath('//entry')->count(); $this->login(); - $crawler = self::request('GET', 'feed.php?mode=forums', array(), false); + $crawler = self::request('GET', 'app.php/feed/forums', array(), false); self::assert_response_xml(); self::$init_values['admin']['forums_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=overall', array(), false); + $crawler = self::request('GET', 'app.php/feed/overall', array(), false); self::assert_response_xml(); self::$init_values['admin']['overall_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics', array(), false); self::assert_response_xml(); self::$init_values['admin']['topics_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_new', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_new', array(), false); self::assert_response_xml(); self::$init_values['admin']['topics_new_value'] = $crawler->filterXPath('//entry')->count(); - $crawler = self::request('GET', 'feed.php?mode=topics_active', array(), false); + $crawler = self::request('GET', 'app.php/feed/topics_active', array(), false); self::assert_response_xml(); self::$init_values['admin']['topics_active_value'] = $crawler->filterXPath('//entry')->count(); - - } public function test_setup_forums() @@ -132,7 +132,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); $this->load_ids(array( 'forums' => array( @@ -149,7 +149,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); // 'Feeds #news' will be used for feed.php?mode=news $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); @@ -160,9 +160,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); - // 'Feeds #exclude' will not be displayed on feed.php?mode=forums + // 'Feeds #exclude' will not be displayed on app.php/feed/forums $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); $form = $crawler->selectButton('addforum')->form(array( 'forum_name' => 'Feeds #exclude', @@ -171,7 +171,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, )); - $crawler = self::submit($form); + self::submit($form); } public function test_setup_config_after_forums() @@ -195,7 +195,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form['feed_exclude_id']->select(array($this->data['forums']['Feeds #exclude'])); $crawler = self::submit($form); - $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); } public function test_feeds_empty() @@ -266,6 +266,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'id' => $this->data['forums']['Feeds #exclude'], 'contents_lang' => array('NO_FEED'), 'invalid' => true, + 'response_code' => 404, ), ), 't' => array( @@ -273,6 +274,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'id' => $this->data['topics']['Feeds #exclude - Topic #1'], 'contents_lang' => array('NO_FEED'), 'invalid' => true, + 'response_code' => 404, ), ), 'overall' => array( @@ -325,7 +327,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text()); + self::assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text()); $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id']; $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); @@ -333,7 +335,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post2 = $this->create_post($this->data['forums']['Feeds #news'], $post['topic_id'], 'Re: Feeds #news - Topic #2', 'This is a test post posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); - $this->assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text()); + self::assertContains('Re: Feeds #news - Topic #2', $crawler->filter('html')->text()); $this->data['posts']['Re: Feeds #news - Topic #2'] = (int) $post2['post_id']; } @@ -489,7 +491,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); - $this->assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text()); + self::assertContains('Re: Feeds #1 - Topic #2', $crawler->filter('html')->text()); $this->data['posts']['Re: Feeds #1 - Topic #2'] = (int) $post2['post_id']; } @@ -510,14 +512,14 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->add_lang('posting'); $crawler = self::request('GET', "posting.php?mode=delete&f={$this->data['forums']['Feeds #1']}&p={$this->data['posts']['Re: Feeds #1 - Topic #2']}&sid={$this->sid}"); - $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + self::assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); $form = $crawler->selectButton('Yes')->form(); $crawler = self::submit($form); - $this->assertContainsLang('POST_DELETED', $crawler->text()); + self::assertContainsLang('POST_DELETED', $crawler->text()); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}"); - $this->assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); + self::assertContains($this->lang('POST_DISPLAY', '', ''), $crawler->text()); } public function test_feeds_softdeleted_post_admin() @@ -609,15 +611,15 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->add_lang('posting'); $crawler = $this->get_quickmod_page($this->data['topics']['Feeds #1 - Topic #2'], 'DELETE_TOPIC'); - $this->assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); + self::assertContainsLang('DELETE_PERMANENTLY', $crawler->text()); $this->add_lang('mcp'); $form = $crawler->selectButton('Yes')->form(); $crawler = self::submit($form); - $this->assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); + self::assertContainsLang('TOPIC_DELETED_SUCCESS', $crawler->text()); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1 - Topic #2']}&sid={$this->sid}"); - $this->assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text()); + self::assertContains('Feeds #1 - Topic #2', $crawler->filter('h2')->text()); } public function test_feeds_softdeleted_topic_admin() @@ -710,8 +712,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 't' => array( array( 'id' => $this->data['topics']['Feeds #1 - Topic #2'], - 'contents_lang' => array('SORRY_AUTH_READ'), + 'contents_lang' => array('SORRY_AUTH_READ_TOPIC'), 'invalid' => true, + 'response_code' => 403, ), ), 'overall' => array( @@ -752,10 +755,10 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case // Test creating a reply $this->login('disapprove_user'); - $post2 = $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD'); + $this->create_post($this->data['forums']['Feeds #1.1'], $post['topic_id'], 'Re: Feeds #1.1 - Topic #2', 'This is a test post posted by the testing framework.', array(), 'POST_STORED_MOD'); $crawler = self::request('GET', "viewtopic.php?t={$this->data['topics']['Feeds #1.1 - Topic #2']}&sid={$this->sid}"); - $this->assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text()); + self::assertNotContains('Re: Feeds #1.1 - Topic #2', $crawler->filter('html')->text()); } public function test_feeds_unapproved_post_admin() @@ -847,7 +850,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id']; $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}"); - $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); + self::assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); $this->logout(); $this->set_flood_interval(15); @@ -863,10 +866,10 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $form = $crawler->selectButton('Submit')->form(); $values = $form->getValues(); - $values["config[flood_interval]"] = $flood_interval; + $values['config[flood_interval]'] = $flood_interval; $form->setValues($values); $crawler = self::submit($form); - $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + self::assertGreaterThan(0, $crawler->filter('.successbox')->count()); $this->logout(); } @@ -958,8 +961,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 't' => array( array( 'id' => $this->data['topics']['Feeds #1.1 - Topic #3'], - 'contents_lang' => array('SORRY_AUTH_READ'), + 'contents_lang' => array('SORRY_AUTH_READ_TOPIC'), 'invalid' => true, + 'response_code' => 403, ), ), 'overall' => array( @@ -998,7 +1002,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #3', 'This is a test topic posted by the testing framework. [attachment=0]Attachment #0[/attachment]', array('upload_files' => 1)); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - $this->assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text()); + self::assertContains('Feeds #1 - Topic #3', $crawler->filter('html')->text()); $this->data['topics']['Feeds #1 - Topic #3'] = (int) $post['topic_id']; } @@ -1216,7 +1220,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post2 = $this->create_post($this->data['forums']['Feeds #1'], $this->data['topics']['Feeds #1 - Topic #3'], 'Re: Feeds #1 - Topic #3-1', 'This is a test post posted by the testing framework. [attachment=0]Attachment #0[/attachment]'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); - $this->assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text()); + self::assertContains('Re: Feeds #1 - Topic #3-1', $crawler->filter('html')->text()); $this->data['posts']['Re: Feeds #1 - Topic #3-1'] = (int) $post2['post_id']; } @@ -1316,9 +1320,14 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case { foreach ($feeds as $feed_data) { - if ($mode === 'f' || $mode === 't') + if ($mode === 'f') { - $params = "?{$mode}={$feed_data['id']}"; + $params = "/forum/{$feed_data['id']}"; + $this->assert_feed($params, $feed_data); + } + else if ($mode === 't') + { + $params = "/topic/{$feed_data['id']}"; $this->assert_feed($params, $feed_data); } else @@ -1342,10 +1351,10 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case case 'news': break; default: - $this->fail('Unsupported feed mode: ' . $mode); + self::fail('Unsupported feed mode: ' . $mode); } - $params = "?mode={$mode}"; + $params = "/{$mode}"; $this->assert_feed($params, $feed_data); } } @@ -1354,19 +1363,19 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case protected function assert_feed($params, $data) { - $crawler = self::request('GET', 'feed.php' . $params, array(), false); + $crawler = self::request('GET', 'app.php/feed' . $params, array(), false); if (empty($data['invalid'])) { self::assert_response_xml(); - $this->assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'feed.php{$params}'"); + self::assertEquals($data['nb_entries'], $crawler->filter('entry')->count(), "Tested feed : 'app.php/feed{$params}'"); if (!empty($data['xpath'])) { foreach($data['xpath'] as $xpath => $count_expected) { - $this->assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'feed.php{$params}', Search for {$xpath}"); + self::assertCount($count_expected, $crawler->filterXPath($xpath), "Tested feed : 'app.php/feed{$params}', Search for {$xpath}"); } } @@ -1375,7 +1384,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case foreach($data['contents'] as $entry_id => $string) { $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); - $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContains($string, $content, "Tested feed : 'app.php/feed{$params}'"); } } @@ -1384,7 +1393,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case foreach($data['contents_lang'] as $entry_id => $string) { $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); - $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContainsLang($string, $content, "Tested feed : 'app.php/feed{$params}'"); } } @@ -1392,21 +1401,21 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case { foreach($data['attachments'] as $entry_id => $attachments) { + $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); foreach ($attachments as $i => $attachment) { - $content = $crawler->filterXPath("//entry[{$entry_id}]/content")->text(); $url = "./download/file.php?id={$attachment['id']}"; $string = "Attachment #{$i}"; if ($attachment['displayed']) { - $this->assertContains($url, $content, "Tested feed : 'feed.php{$params}'"); - $this->assertNotContains($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContains($url, $content, "Tested feed : 'app.php/feed{$params}'"); + self::assertNotContains($string, $content, "Tested feed : 'app.php/feed{$params}'"); } else { - $this->assertContains($string, $content, "Tested feed : 'feed.php{$params}'"); - $this->assertNotContains($url, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContains($string, $content, "Tested feed : 'app.php/feed{$params}'"); + self::assertNotContains($url, $content, "Tested feed : 'app.php/feed{$params}'"); } } } @@ -1414,14 +1423,14 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case } else { - self::assert_response_html(); + self::assert_response_html($data['response_code'] ?: 202); if (!empty($data['contents_lang'])) { + $content = $crawler->filter('html')->text(); foreach($data['contents_lang'] as $string) { - $content = $crawler->filter('html')->text(); - $this->assertContainsLang($string, $content, "Tested feed : 'feed.php{$params}'"); + self::assertContainsLang($string, $content, "Tested feed : 'app.php/feed{$params}'"); } } } @@ -1439,7 +1448,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (in_array($row['forum_name'], $data['forums'])) + if (in_array($row['forum_name'], $data['forums'], false)) { $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; } @@ -1455,7 +1464,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (in_array($row['topic_title'], $data['topics'])) + if (in_array($row['topic_title'], $data['topics'], false)) { $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; } @@ -1472,7 +1481,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - if (in_array($row['post_subject'], $data['posts'])) + if (in_array($row['post_subject'], $data['posts'], false)) { $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; $post_ids[] = (int) $row['post_id']; diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php index 1d9f5dc5bf..0116dced49 100644 --- a/tests/mock/controller_helper.php +++ b/tests/mock/controller_helper.php @@ -13,19 +13,6 @@ class phpbb_mock_controller_helper extends \phpbb\controller\helper { - public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\routing\router $router, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path, $php_ext, $phpbb_root_path_ext) - { - $this->template = $template; - $this->user = $user; - $this->config = $config; - $this->symfony_request = $symfony_request; - $this->request = $request; - $this->filesystem = $filesystem; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->router = $router; - } - public function get_current_url() { return ''; diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 07f9ec9c56..0607098d93 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -54,7 +54,8 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case $request ); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $router, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->routing_helper = new \phpbb\routing\helper($this->config, $router, $symfony_request, $request, $filesystem, '', 'php'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $symfony_request, $request, $this->routing_helper); $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher); }