mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/13645] Move the feeds to controllers
PHPBB3-13645
This commit is contained in:
committed by
Tristan Darricau
parent
f56fe0ba8d
commit
8e5e954438
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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()
|
||||
);
|
||||
|
387
phpBB/phpbb/feed/controller/feed.php
Normal file
387
phpBB/phpbb/feed/controller/feed.php
Normal file
@@ -0,0 +1,387 @@
|
||||
<?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\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');
|
||||
}
|
||||
}
|
21
phpBB/phpbb/feed/exception/feed_exception.php
Normal file
21
phpBB/phpbb/feed/exception/feed_exception.php
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
19
phpBB/phpbb/feed/exception/feed_unavailable_exception.php
Normal file
19
phpBB/phpbb/feed/exception/feed_unavailable_exception.php
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
22
phpBB/phpbb/feed/exception/no_feed_exception.php
Normal file
22
phpBB/phpbb/feed/exception/no_feed_exception.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
22
phpBB/phpbb/feed/exception/no_forum_exception.php
Normal file
22
phpBB/phpbb/feed/exception/no_forum_exception.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
22
phpBB/phpbb/feed/exception/no_topic_exception.php
Normal file
22
phpBB/phpbb/feed/exception/no_topic_exception.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
19
phpBB/phpbb/feed/exception/unauthorized_exception.php
Normal file
19
phpBB/phpbb/feed/exception/unauthorized_exception.php
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
22
phpBB/phpbb/feed/exception/unauthorized_forum_exception.php
Normal file
22
phpBB/phpbb/feed/exception/unauthorized_forum_exception.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
22
phpBB/phpbb/feed/exception/unauthorized_topic_exception.php
Normal file
22
phpBB/phpbb/feed/exception/unauthorized_topic_exception.php
Normal file
@@ -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);
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
153
phpBB/phpbb/routing/helper.php
Normal file
153
phpBB/phpbb/routing/helper.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?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\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);
|
||||
}
|
||||
}
|
43
phpBB/phpbb/template/twig/extension/routing.php
Normal file
43
phpBB/phpbb/template/twig/extension/routing.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user