diff options
author | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
---|---|---|
committer | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
commit | 8ea437e30605e0f66b5220bf904a61d7c1d11ddd (patch) | |
tree | e0db2bb4a012d5b06a633160b19f62f4868ecd28 /phpBB/phpbb/feed | |
parent | 36bc1870f21fac04736a1049c1d5b8e127d729f4 (diff) | |
parent | 2fdd46b36431ae0f58bb2e78e42553168db9a0ff (diff) | |
download | forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.gz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.bz2 forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.xz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.zip |
Merge remote-tracking branch 'upstream/prep-release-3.2.9'
Diffstat (limited to 'phpBB/phpbb/feed')
24 files changed, 1218 insertions, 488 deletions
diff --git a/phpBB/phpbb/feed/attachments_base.php b/phpBB/phpbb/feed/attachments_base.php index df8f29a626..5d3272e0d9 100644 --- a/phpBB/phpbb/feed/attachments_base.php +++ b/phpBB/phpbb/feed/attachments_base.php @@ -16,7 +16,7 @@ namespace phpbb\feed; /** * Abstract class for feeds displaying attachments */ -abstract class attachments_base extends \phpbb\feed\base +abstract class attachments_base extends base { /** * Attachments that may be displayed diff --git a/phpBB/phpbb/feed/base.php b/phpBB/phpbb/feed/base.php index eeea0a55df..d4be0dc592 100644 --- a/phpBB/phpbb/feed/base.php +++ b/phpBB/phpbb/feed/base.php @@ -1,27 +1,27 @@ <?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. -* -*/ + * + * 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; /** -* Base class with some generic functions and settings. -*/ -abstract class base + * Base class with some generic functions and settings. + */ +abstract class base implements feed_interface { /** - * Feed helper object - * @var \phpbb\feed\helper - */ + * Feed helper object + * @var \phpbb\feed\helper + */ protected $helper; /** @var \phpbb\config\config */ @@ -49,47 +49,47 @@ abstract class base protected $phpEx; /** - * SQL Query to be executed to get feed items - */ - var $sql = array(); + * SQL Query to be executed to get feed items + */ + protected $sql = array(); /** - * Keys specified for retrieval of title, content, etc. - */ - var $keys = array(); + * Keys specified for retrieval of title, content, etc. + */ + protected $keys = array(); /** - * Number of items to fetch. Usually overwritten by $config['feed_something'] - */ - var $num_items = 15; + * Number of items to fetch. Usually overwritten by $config['feed_something'] + */ + protected $num_items = 15; /** - * Separator for title elements to separate items (for example forum / topic) - */ - var $separator = "\xE2\x80\xA2"; // • + * Separator for title elements to separate items (for example forum / topic) + */ + protected $separator = "\xE2\x80\xA2"; // • /** - * Separator for the statistics row (Posted by, post date, replies, etc.) - */ - var $separator_stats = "\xE2\x80\x94"; // — + * Separator for the statistics row (Posted by, post date, replies, etc.) + */ + protected $separator_stats = "\xE2\x80\x94"; // — /** @var mixed Query result handle */ protected $result; /** - * Constructor - * - * @param \phpbb\feed\helper $helper Feed helper - * @param \phpbb\config\config $config Config object - * @param \phpbb\db\driver\driver_interface $db Database connection - * @param \phpbb\cache\driver\driver_interface $cache Cache object - * @param \phpbb\user $user User object - * @param \phpbb\auth\auth $auth Auth object - * @param \phpbb\content_visibility $content_visibility Content visibility object - * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object - * @param string $phpEx php file extension - */ - function __construct( + * Constructor + * + * @param \phpbb\feed\helper $helper Feed helper + * @param \phpbb\config\config $config Config object + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param \phpbb\cache\driver\driver_interface $cache Cache object + * @param \phpbb\user $user User object + * @param \phpbb\auth\auth $auth Auth object + * @param \phpbb\content_visibility $content_visibility Auth object + * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object + * @param string $phpEx php file extension + */ + public function __construct( \phpbb\feed\helper $helper, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, @@ -127,23 +127,23 @@ abstract class base } /** - * Set keys. - */ - function set_keys() + * {@inheritdoc} + */ + public function set_keys() { } /** - * Open feed - */ - function open() + * {@inheritdoc} + */ + public function open() { } /** - * Close feed - */ - function close() + * {@inheritdoc} + */ + public function close() { if (!empty($this->result)) { @@ -152,28 +152,62 @@ abstract class base } /** - * Set key - * - * @param string $key Key - * @param mixed $value Value - */ - function set($key, $value) + * {@inheritdoc} + */ + public function set($key, $value) { $this->keys[$key] = $value; } /** - * Get key - * - * @param string $key Key - * @return mixed - */ - function get($key) + * {@inheritdoc} + */ + public function get($key) { return (isset($this->keys[$key])) ? $this->keys[$key] : null; } - function get_readable_forums() + /** + * {@inheritdoc} + */ + public function get_item() + { + if (!isset($this->result)) + { + if (!$this->get_sql()) + { + return false; + } + + $sql_ary = $this->sql; + + /** + * Event to modify the feed item sql + * + * @event core.feed_base_modify_item_sql + * @var array sql_ary The SQL array to get the feed item data + * + * @since 3.1.10-RC1 + */ + $vars = array('sql_ary'); + extract($this->phpbb_dispatcher->trigger_event('core.feed_base_modify_item_sql', compact($vars))); + $this->sql = $sql_ary; + unset($sql_ary); + + // Query database + $sql = $this->db->sql_build_query('SELECT', $this->sql); + $this->result = $this->db->sql_query_limit($sql, $this->num_items); + } + + return $this->db->sql_fetchrow($this->result); + } + + /** + * Returns the ids of the forums readable by the current user. + * + * @return int[] + */ + protected function get_readable_forums() { static $forum_ids; @@ -185,7 +219,12 @@ abstract class base return $forum_ids; } - function get_moderator_approve_forums() + /** + * Returns the ids of the forum for which the current user can approve the post in the moderation queue. + * + * @return int[] + */ + protected function get_moderator_approve_forums() { static $forum_ids; @@ -197,7 +236,13 @@ abstract class base return $forum_ids; } - function is_moderator_approve_forum($forum_id) + /** + * Returns true if the current user can approve the post of the given forum + * + * @param int $forum_id Forum id to check + * @return bool + */ + protected function is_moderator_approve_forum($forum_id) { static $forum_ids; @@ -209,7 +254,12 @@ abstract class base return (isset($forum_ids[$forum_id])) ? true : false; } - function get_excluded_forums() + /** + * Returns the ids of the forum excluded from the feeds + * + * @return int[] + */ + protected function get_excluded_forums() { static $forum_ids; @@ -236,51 +286,35 @@ abstract class base return $forum_ids; } - function is_excluded_forum($forum_id) + /** + * Returns true if the given id is in the excluded forums list. + * + * @param int $forum_id Id to check + * @return bool + */ + protected function is_excluded_forum($forum_id) { $forum_ids = $this->get_excluded_forums(); return isset($forum_ids[$forum_id]) ? true : false; } - function get_passworded_forums() + /** + * Returns all password protected forum ids the current user is currently NOT authenticated for. + * + * @return array Array of forum ids + */ + protected function get_passworded_forums() { return $this->user->get_passworded_forums(); } - function get_item() - { - if (!isset($this->result)) - { - if (!$this->get_sql()) - { - return false; - } - - $sql_ary = $this->sql; - - /** - * Event to modify the feed item sql - * - * @event core.feed_base_modify_item_sql - * @var array sql_ary The SQL array to get the feed item data - * - * @since 3.1.10-RC1 - */ - $vars = array('sql_ary'); - extract($this->phpbb_dispatcher->trigger_event('core.feed_base_modify_item_sql', compact($vars))); - $this->sql = $sql_ary; - unset($sql_ary); - - // Query database - $sql = $this->db->sql_build_query('SELECT', $this->sql); - $this->result = $this->db->sql_query_limit($sql, $this->num_items); - } - - return $this->db->sql_fetchrow($this->result); - } - - function user_viewprofile($row) + /** + * Returns the link to the user profile. + * + * @return string + */ + protected function user_viewprofile($row) { $author_id = (int) $row[$this->get('author_id')]; @@ -293,4 +327,11 @@ abstract class base return '<a href="' . $this->helper->append_sid('memberlist.' . $this->phpEx, 'mode=viewprofile&u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>'; } + + /** + * Returns the SQL query used to retrieve the posts of the feed. + * + * @return string SQL SELECT query + */ + protected abstract function get_sql(); } diff --git a/phpBB/phpbb/feed/controller/feed.php b/phpBB/phpbb/feed/controller/feed.php new file mode 100644 index 0000000000..c0d7bc72ec --- /dev/null +++ b/phpBB/phpbb/feed/controller/feed.php @@ -0,0 +1,411 @@ +<?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\controller; + +use phpbb\auth\auth; +use phpbb\config\config; +use phpbb\db\driver\driver_interface; +use \phpbb\event\dispatcher_interface; +use phpbb\exception\http_exception; +use phpbb\feed\feed_interface; +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 dispatcher_interface + */ + protected $phpbb_dispatcher; + + /** + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param \Twig_Environment $twig + * @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 + * @param dispatcher_interface $phpbb_dispatcher + * @param string $php_ext + */ + 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, dispatcher_interface $phpbb_dispatcher, $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; + $this->phpbb_dispatcher = $phpbb_dispatcher; + } + + /** + * 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 feed_interface $feed + * + * @return Response + */ + protected function send_feed(feed_interface $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 feed_interface $feed + * + * @return Response + * + * @throw exception\feed_exception + */ + protected function send_feed_do(feed_interface $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()) + { + /** + * Event to modify the feed row + * + * @event core.feed_modify_feed_row + * @var int forum_id Forum ID + * @var string mode Feeds mode (forums|topics|topics_new|topics_active|news) + * @var array row Array with feed data + * @var int topic_id Topic ID + * + * @since 3.1.10-RC1 + */ + $vars = array('forum_id', 'mode', 'row', 'topic_id'); + extract($this->phpbb_dispatcher->trigger_event('core.feed_modify_feed_row', compact($vars))); + + // 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 @@ +<?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\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 @@ +<?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\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 @@ +<?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\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 @@ +<?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\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 @@ +<?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\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 @@ +<?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\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 @@ +<?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\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 @@ +<?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\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 @@ -<?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; - -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/feed_interface.php b/phpBB/phpbb/feed/feed_interface.php new file mode 100644 index 0000000000..c185cd249c --- /dev/null +++ b/phpBB/phpbb/feed/feed_interface.php @@ -0,0 +1,67 @@ +<?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; + +/** + * Interface implemented by all feeds types + */ +interface feed_interface +{ + /** + * Set keys. + */ + public function set_keys(); + + /** + * Open feed + */ + public function open(); + + /** + * Close feed + */ + public function close(); + + /** + * Set key + * + * @param string $key Key + * @param mixed $value Value + */ + public function set($key, $value); + + /** + * Get key + * + * @param string $key Key + * @return mixed + */ + public function get($key); + + /** + * Get the next post in the feed + * + * @return array + */ + public function get_item(); + + /** + * Adjust a feed entry + * + * @param $item_row + * @param $row + * @return array + */ + public function adjust_item(&$item_row, &$row); +} diff --git a/phpBB/phpbb/feed/forum.php b/phpBB/phpbb/feed/forum.php index 6aba12a147..0c142e8cc8 100644 --- a/phpBB/phpbb/feed/forum.php +++ b/phpBB/phpbb/feed/forum.php @@ -1,35 +1,39 @@ <?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. -* -*/ + * + * 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; +use phpbb\feed\exception\no_feed_exception; +use phpbb\feed\exception\no_forum_exception; +use phpbb\feed\exception\unauthorized_forum_exception; + /** -* Forum feed -* -* This will give you the last {$this->num_items} posts made -* within a specific forum. -*/ -class forum extends \phpbb\feed\post_base + * Forum feed + * + * This will give you the last {$this->num_items} posts made + * within a specific forum. + */ +class forum extends post_base { - var $forum_id = 0; - var $forum_data = array(); + protected $forum_id = 0; + protected $forum_data = array(); /** - * Set the Forum ID - * - * @param int $forum_id Forum ID - * @return \phpbb\feed\forum - */ + * Set the Forum ID + * + * @param int $forum_id Forum ID + * @return \phpbb\feed\forum + */ public function set_forum_id($forum_id) { $this->forum_id = (int) $forum_id; @@ -37,7 +41,10 @@ class forum extends \phpbb\feed\post_base return $this; } - function open() + /** + * {@inheritdoc} + */ + public function open() { // Check if forum exists $sql = 'SELECT forum_id, forum_name, forum_password, forum_type, forum_options @@ -49,25 +56,33 @@ 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'); + if ($this->user->data['user_id'] != ANONYMOUS) + { + send_status_line(403, 'Forbidden'); + } + else + { + send_status_line(401, 'Unauthorized'); + } + throw new unauthorized_forum_exception($this->forum_id); } // Make sure forum is not passworded or user is authed @@ -77,7 +92,15 @@ class forum extends \phpbb\feed\post_base if (isset($forum_ids_passworded[$this->forum_id])) { - trigger_error('SORRY_AUTH_READ'); + if ($this->user->data['user_id'] != ANONYMOUS) + { + send_status_line(403, 'Forbidden'); + } + else + { + send_status_line(401, 'Unauthorized'); + } + throw new unauthorized_forum_exception($this->forum_id); } unset($forum_ids_passworded); @@ -86,7 +109,10 @@ class forum extends \phpbb\feed\post_base parent::open(); } - function get_sql() + /** + * {@inheritdoc} + */ + protected function get_sql() { // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time @@ -116,7 +142,7 @@ class forum extends \phpbb\feed\post_base $this->sql = array( 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' . - 'u.username, u.user_id', + 'u.username, u.user_id', 'FROM' => array( POSTS_TABLE => 'p', USERS_TABLE => 'u', @@ -131,7 +157,10 @@ class forum extends \phpbb\feed\post_base return true; } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { parent::adjust_item($item_row, $row); @@ -139,7 +168,10 @@ class forum extends \phpbb\feed\post_base $item_row['forum_id'] = $this->forum_id; } - function get_item() + /** + * {@inheritdoc} + */ + public function get_item() { return ($row = parent::get_item()) ? array_merge($this->forum_data, $row) : $row; } diff --git a/phpBB/phpbb/feed/forums.php b/phpBB/phpbb/feed/forums.php index ee14a5bc76..92f2b2dd4d 100644 --- a/phpBB/phpbb/feed/forums.php +++ b/phpBB/phpbb/feed/forums.php @@ -1,29 +1,32 @@ <?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. -* -*/ + * + * 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; /** -* 'All Forums' feed -* -* This will give you a list of all postable forums where feeds are enabled -* including forum description, topic stats and post stats -*/ -class forums extends \phpbb\feed\base + * 'All Forums' feed + * + * This will give you a list of all postable forums where feeds are enabled + * including forum description, topic stats and post stats + */ +class forums extends base { - var $num_items = 0; + protected $num_items = 0; - function set_keys() + /** + * {@inheritdoc} + */ + public function set_keys() { $this->set('title', 'forum_name'); $this->set('text', 'forum_desc'); @@ -33,7 +36,10 @@ class forums extends \phpbb\feed\base $this->set('options', 'forum_desc_options'); } - function get_sql() + /** + * {@inheritdoc} + */ + public function get_sql() { $in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums()); if (empty($in_fid_ary)) @@ -55,7 +61,10 @@ class forums extends \phpbb\feed\base return true; } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { $item_row['link'] = $this->helper->append_sid('viewforum.' . $this->phpEx, 'f=' . $row['forum_id']); diff --git a/phpBB/phpbb/feed/helper.php b/phpBB/phpbb/feed/helper.php index f2030f5ced..7d50b7ce7d 100644 --- a/phpBB/phpbb/feed/helper.php +++ b/phpBB/phpbb/feed/helper.php @@ -1,54 +1,65 @@ <?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. -* -*/ + * + * 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; +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 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 - */ - public function __construct(\phpbb\config\config $config, \phpbb\user $user, $phpbb_root_path, $phpEx) + * Constructor + * + * @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(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() { static $board_url; @@ -62,16 +73,16 @@ class helper } /** - * Run links through append_sid(), prepend generate_board_url() and remove session id - */ + * Run links through append_sid(), prepend generate_board_url() and remove session id + */ public function append_sid($url, $params) { return append_sid($this->get_board_url() . '/' . $url, $params, true, ''); } /** - * Generate ISO 8601 date string (RFC 3339) - */ + * Generate ISO 8601 date string (RFC 3339) + */ public function format_date($time) { static $zone_offset; @@ -87,16 +98,16 @@ class helper } /** - * Generate text content - * - * @param string $content is feed text content - * @param string $uid is bbcode_uid - * @param string $bitfield is bbcode bitfield - * @param int $options bbcode flag options - * @param int $forum_id is the forum id - * @param array $post_attachments is an array containing the attachments and their respective info - * @return string the html content to be printed for the feed - */ + * Generate text content + * + * @param string $content is feed text content + * @param string $uid is bbcode_uid + * @param string $bitfield is bbcode bitfield + * @param int $options bbcode flag options + * @param int $forum_id is the forum id + * @param array $post_attachments is an array containing the attachments and their respective info + * @return string the html content to be printed for the feed + */ public function generate_content($content, $uid, $bitfield, $options, $forum_id, $post_attachments) { if (empty($content)) @@ -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); + // Setup our own quote_helper to remove all attributes from quotes + $this->renderer->configure_quote_helper($this->container->get('feed.quote_helper')); - $content = generate_text_for_display($content, $uid, $bitfield, $options); - - // 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); @@ -122,16 +129,16 @@ class helper // Firefox does not support CSS for feeds, though // Remove font sizes - // $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content); + // $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content); // Make text strong :P - // $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content); + // $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content); // Italic - // $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content); + // $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content); // Underline - // $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content); + // $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content); // Remove embed Windows Media Streams $content = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--<!\[endif\]-->#si', '', $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/news.php b/phpBB/phpbb/feed/news.php index 5d4786518b..13ca82c093 100644 --- a/phpBB/phpbb/feed/news.php +++ b/phpBB/phpbb/feed/news.php @@ -1,27 +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. -* -*/ + * + * 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; /** -* News feed -* -* This will give you {$this->num_items} first posts -* of all topics in the selected news forums. -*/ -class news extends \phpbb\feed\topic_base + * News feed + * + * This will give you {$this->num_items} first posts + * of all topics in the selected news forums. + */ +class news extends topic_base { - function get_news_forums() + /** + * Returns the ids of the 'news forums' + * @return int[] + */ + private function get_news_forums() { static $forum_ids; @@ -48,7 +52,10 @@ class news extends \phpbb\feed\topic_base return $forum_ids; } - function get_sql() + /** + * {@inheritdoc} + */ + protected function get_sql() { // Determine forum ids $in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums()); diff --git a/phpBB/phpbb/feed/overall.php b/phpBB/phpbb/feed/overall.php index 1176a9c182..b083df922d 100644 --- a/phpBB/phpbb/feed/overall.php +++ b/phpBB/phpbb/feed/overall.php @@ -1,27 +1,30 @@ <?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. -* -*/ + * + * 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; /** -* Board wide feed (aka overall feed) -* -* This will give you the newest {$this->num_items} posts -* from the whole board. -*/ -class overall extends \phpbb\feed\post_base + * Board wide feed (aka overall feed) + * + * This will give you the newest {$this->num_items} posts + * from the whole board. + */ +class overall extends post_base { - function get_sql() + /** + * {@inheritdoc} + */ + protected function get_sql() { $forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums()); if (empty($forum_ids)) @@ -57,8 +60,8 @@ class overall extends \phpbb\feed\post_base // Get the actual data $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, ' . - 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' . - 'u.username, u.user_id', + 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' . + 'u.username, u.user_id', 'FROM' => array( USERS_TABLE => 'u', POSTS_TABLE => 'p', @@ -79,7 +82,10 @@ class overall extends \phpbb\feed\post_base return true; } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { parent::adjust_item($item_row, $row); diff --git a/phpBB/phpbb/feed/post_base.php b/phpBB/phpbb/feed/post_base.php index 011775b6af..f6dc39cbec 100644 --- a/phpBB/phpbb/feed/post_base.php +++ b/phpBB/phpbb/feed/post_base.php @@ -1,27 +1,29 @@ <?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. -* -*/ + * + * 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; /** -* Abstract class for post based feeds -*/ -abstract class post_base extends \phpbb\feed\attachments_base + * Abstract class for post based feeds + */ +abstract class post_base extends attachments_base { - var $num_items = 'feed_limit_post'; - var $attachments = array(); + protected $num_items = 'feed_limit_post'; - function set_keys() + /** + * {@inheritdoc} + */ + public function set_keys() { $this->set('title', 'post_subject'); $this->set('title2', 'topic_title'); @@ -40,7 +42,10 @@ abstract class post_base extends \phpbb\feed\attachments_base $this->set('enable_magic_url', 'enable_magic_url'); } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { $item_row['link'] = $this->helper->append_sid('viewtopic.' . $this->phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}"); 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/feed/topic.php b/phpBB/phpbb/feed/topic.php index 295bf3f795..2504e411b1 100644 --- a/phpBB/phpbb/feed/topic.php +++ b/phpBB/phpbb/feed/topic.php @@ -1,35 +1,40 @@ <?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. -* -*/ + * + * 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; +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 -* -* This will give you the last {$this->num_items} posts made within this topic. -*/ -class topic extends \phpbb\feed\post_base + * Topic feed for a specific topic + * + * This will give you the last {$this->num_items} posts made within this topic. + */ +class topic extends post_base { - var $topic_id = 0; - var $forum_id = 0; - var $topic_data = array(); + protected $topic_id = 0; + protected $forum_id = 0; + protected $topic_data = array(); /** - * Set the Topic ID - * - * @param int $topic_id Topic ID - * @return \phpbb\feed\topic - */ + * Set the Topic ID + * + * @param int $topic_id Topic ID + * @return \phpbb\feed\topic + */ public function set_topic_id($topic_id) { $this->topic_id = (int) $topic_id; @@ -37,7 +42,10 @@ class topic extends \phpbb\feed\post_base return $this; } - function open() + /** + * {@inheritdoc} + */ + public function open() { $sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_visibility, t.topic_title, t.topic_time, t.topic_views, t.topic_posts_approved, t.topic_type FROM ' . TOPICS_TABLE . ' t @@ -50,7 +58,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 +66,35 @@ 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'); + if ($this->user->data['user_id'] != ANONYMOUS) + { + send_status_line(403, 'Forbidden'); + } + else + { + send_status_line(401, 'Unauthorized'); + } + 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'); + if ($this->user->data['user_id'] != ANONYMOUS) + { + send_status_line(403, 'Forbidden'); + } + else + { + send_status_line(401, 'Unauthorized'); + } + throw new unauthorized_forum_exception($this->forum_id); } // Make sure forum is not passworded or user is authed @@ -80,7 +104,15 @@ class topic extends \phpbb\feed\post_base if (isset($forum_ids_passworded[$this->forum_id])) { - trigger_error('SORRY_AUTH_READ'); + if ($this->user->data['user_id'] != ANONYMOUS) + { + send_status_line(403, 'Forbidden'); + } + else + { + send_status_line(401, 'Unauthorized'); + } + throw new unauthorized_forum_exception($this->forum_id); } unset($forum_ids_passworded); @@ -89,13 +121,16 @@ class topic extends \phpbb\feed\post_base parent::open(); } - function get_sql() + /** + * {@inheritdoc} + */ + protected function get_sql() { parent::fetch_attachments(); $this->sql = array( 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, ' . - 'u.username, u.user_id', + 'u.username, u.user_id', 'FROM' => array( POSTS_TABLE => 'p', USERS_TABLE => 'u', @@ -109,14 +144,20 @@ class topic extends \phpbb\feed\post_base return true; } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { parent::adjust_item($item_row, $row); $item_row['forum_id'] = $this->forum_id; } - function get_item() + /** + * {@inheritdoc} + */ + public function get_item() { return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row; } diff --git a/phpBB/phpbb/feed/topic_base.php b/phpBB/phpbb/feed/topic_base.php index f9ff368cba..0f1a9ccb70 100644 --- a/phpBB/phpbb/feed/topic_base.php +++ b/phpBB/phpbb/feed/topic_base.php @@ -1,26 +1,29 @@ <?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. -* -*/ + * + * 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; /** -* Abstract class for topic based feeds -*/ -abstract class topic_base extends \phpbb\feed\attachments_base + * Abstract class for topic based feeds + */ +abstract class topic_base extends attachments_base { - var $num_items = 'feed_limit_topic'; + protected $num_items = 'feed_limit_topic'; - function set_keys() + /** + * {@inheritdoc} + */ + public function set_keys() { $this->set('title', 'topic_title'); $this->set('title2', 'forum_name'); @@ -39,7 +42,10 @@ abstract class topic_base extends \phpbb\feed\attachments_base $this->set('enable_magic_url', 'enable_magic_url'); } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { $item_row['link'] = $this->helper->append_sid('viewtopic.' . $this->phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']); diff --git a/phpBB/phpbb/feed/topics.php b/phpBB/phpbb/feed/topics.php index e6416bc064..183c29d11c 100644 --- a/phpBB/phpbb/feed/topics.php +++ b/phpBB/phpbb/feed/topics.php @@ -1,27 +1,30 @@ <?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. -* -*/ + * + * 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; /** -* New Topics feed -* -* This will give you the last {$this->num_items} created topics -* including the first post. -*/ -class topics extends \phpbb\feed\topic_base + * New Topics feed + * + * This will give you the last {$this->num_items} created topics + * including the first post. + */ +class topics extends topic_base { - function get_sql() + /** + * {@inheritdoc} + */ + protected function get_sql() { $forum_ids_read = $this->get_readable_forums(); if (empty($forum_ids_read)) @@ -79,7 +82,10 @@ class topics extends \phpbb\feed\topic_base return true; } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { parent::adjust_item($item_row, $row); diff --git a/phpBB/phpbb/feed/topics_active.php b/phpBB/phpbb/feed/topics_active.php index 3b751f3233..ea9ee97b9d 100644 --- a/phpBB/phpbb/feed/topics_active.php +++ b/phpBB/phpbb/feed/topics_active.php @@ -1,30 +1,33 @@ <?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. -* -*/ + * + * 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; /** -* Active Topics feed -* -* This will give you the last {$this->num_items} topics -* with replies made withing the last {$this->sort_days} days -* including the last post. -*/ -class topics_active extends \phpbb\feed\topic_base + * Active Topics feed + * + * This will give you the last {$this->num_items} topics + * with replies made withing the last {$this->sort_days} days + * including the last post. + */ +class topics_active extends topic_base { - var $sort_days = 7; + protected $sort_days = 7; - function set_keys() + /** + * {@inheritdoc} + */ + public function set_keys() { parent::set_keys(); @@ -32,7 +35,10 @@ class topics_active extends \phpbb\feed\topic_base $this->set('creator', 'topic_last_poster_name'); } - function get_sql() + /** + * {@inheritdoc} + */ + protected function get_sql() { $forum_ids_read = $this->get_readable_forums(); if (empty($forum_ids_read)) @@ -96,7 +102,12 @@ class topics_active extends \phpbb\feed\topic_base return true; } - function get_forum_ids() + /** + * Returns the ids of the forums not excluded from the active list + * + * @return int[] + */ + private function get_forum_ids() { static $forum_ids; @@ -108,7 +119,7 @@ class topics_active extends \phpbb\feed\topic_base FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . ' AND ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . ' - AND ' . $this->db->sql_bit_and('forum_flags', log(FORUM_FLAG_ACTIVE_TOPICS, 2), '<> 0'); + AND ' . $this->db->sql_bit_and('forum_flags', round(log(FORUM_FLAG_ACTIVE_TOPICS, 2)), '<> 0'); $result = $this->db->sql_query($sql); $forum_ids = array(); @@ -124,7 +135,10 @@ class topics_active extends \phpbb\feed\topic_base return $forum_ids; } - function adjust_item(&$item_row, &$row) + /** + * {@inheritdoc} + */ + public function adjust_item(&$item_row, &$row) { parent::adjust_item($item_row, $row); |