mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-05 22:14:59 +02:00
Merge remote-tracking branch 'remotes/nickv/ticket/11481' into develop
# By Joas Schilling # Via Joas Schilling * remotes/nickv/ticket/11481: [ticket/11481] Move prepended slash from calls into function [ticket/11481] Remove globals and use dependency injection instead [ticket/11481] Use container for all classes and inject dependencies [ticket/11481] Move functions from feed into helper class [ticket/11481] Move active topics feed to own file [ticket/11481] Move topics feed to own file [ticket/11481] Move news feed to own file [ticket/11481] Move forums feed to own file [ticket/11481] Move topic feed to own file [ticket/11481] Move forum feed to own file [ticket/11481] Move overall feed to own file [ticket/11481] Move feed topic base to own file [ticket/11481] Move feed post base to own file [ticket/11481] Move feed base to own file [ticket/11481] Move feed factory to own file
This commit is contained in:
commit
e5d02f4b0c
98
phpBB/config/feed.yml
Normal file
98
phpBB/config/feed.yml
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
services:
|
||||||
|
feed.helper:
|
||||||
|
class: phpbb_feed_helper
|
||||||
|
arguments:
|
||||||
|
- @config
|
||||||
|
- @user
|
||||||
|
- %core.root_path%
|
||||||
|
|
||||||
|
feed.factory:
|
||||||
|
class: phpbb_feed_factory
|
||||||
|
arguments:
|
||||||
|
- @service_container
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
|
||||||
|
feed.forum:
|
||||||
|
class: phpbb_feed_forum
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
||||||
|
|
||||||
|
feed.forums:
|
||||||
|
class: phpbb_feed_forums
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
||||||
|
|
||||||
|
feed.news:
|
||||||
|
class: phpbb_feed_news
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
||||||
|
|
||||||
|
feed.overall:
|
||||||
|
class: phpbb_feed_overall
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
||||||
|
|
||||||
|
feed.topic:
|
||||||
|
class: phpbb_feed_topic
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
||||||
|
|
||||||
|
feed.topics:
|
||||||
|
class: phpbb_feed_topics
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
||||||
|
|
||||||
|
feed.topics_active:
|
||||||
|
class: phpbb_feed_topics_active
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
- @cache.driver
|
||||||
|
- @user
|
||||||
|
- @auth
|
||||||
|
- %core.php_ext%
|
@ -4,6 +4,7 @@ imports:
|
|||||||
- { resource: notifications.yml }
|
- { resource: notifications.yml }
|
||||||
- { resource: migrator.yml }
|
- { resource: migrator.yml }
|
||||||
- { resource: avatars.yml }
|
- { resource: avatars.yml }
|
||||||
|
- { resource: feed.yml }
|
||||||
|
|
||||||
services:
|
services:
|
||||||
auth:
|
auth:
|
||||||
|
1180
phpBB/feed.php
1180
phpBB/feed.php
File diff suppressed because it is too large
Load Diff
259
phpBB/includes/feed/base.php
Normal file
259
phpBB/includes/feed/base.php
Normal file
@ -0,0 +1,259 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class with some generic functions and settings.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
abstract class phpbb_feed_base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Feed helper object
|
||||||
|
* @var phpbb_feed_helper
|
||||||
|
*/
|
||||||
|
protected $helper;
|
||||||
|
|
||||||
|
/** @var phpbb_config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @var phpbb_db_driver */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
/** @var phpbb_cache_driver_interface */
|
||||||
|
protected $cache;
|
||||||
|
|
||||||
|
/** @var phpbb_user */
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/** @var phpbb_auth */
|
||||||
|
protected $auth;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $phpEx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL Query to be executed to get feed items
|
||||||
|
*/
|
||||||
|
var $sql = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keys specified for retrieval of title, content, etc.
|
||||||
|
*/
|
||||||
|
var $keys = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of items to fetch. Usually overwritten by $config['feed_something']
|
||||||
|
*/
|
||||||
|
var $num_items = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separator for title elements to separate items (for example forum / topic)
|
||||||
|
*/
|
||||||
|
var $separator = "\xE2\x80\xA2"; // •
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separator for the statistics row (Posted by, post date, replies, etc.)
|
||||||
|
*/
|
||||||
|
var $separator_stats = "\xE2\x80\x94"; // —
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param phpbb_feed_helper $helper Feed helper
|
||||||
|
* @param phpbb_config $config Config object
|
||||||
|
* @param phpbb_db_driver $db Database connection
|
||||||
|
* @param phpbb_cache_driver_interface $cache Cache object
|
||||||
|
* @param phpbb_user $user User object
|
||||||
|
* @param phpbb_auth $auth Auth object
|
||||||
|
* @param string $phpEx php file extension
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
function __construct(phpbb_feed_helper $helper, phpbb_config $config, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, phpbb_user $user, phpbb_auth $auth, $phpEx)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
$this->helper = $helper;
|
||||||
|
$this->db = $db;
|
||||||
|
$this->cache = $cache;
|
||||||
|
$this->user = $user;
|
||||||
|
$this->auth = $auth;
|
||||||
|
$this->phpEx = $phpEx;
|
||||||
|
|
||||||
|
$this->set_keys();
|
||||||
|
|
||||||
|
// Allow num_items to be string
|
||||||
|
if (is_string($this->num_items))
|
||||||
|
{
|
||||||
|
$this->num_items = (int) $this->config[$this->num_items];
|
||||||
|
|
||||||
|
// A precaution
|
||||||
|
if (!$this->num_items)
|
||||||
|
{
|
||||||
|
$this->num_items = 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set keys.
|
||||||
|
*/
|
||||||
|
function set_keys()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open feed
|
||||||
|
*/
|
||||||
|
function open()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close feed
|
||||||
|
*/
|
||||||
|
function close()
|
||||||
|
{
|
||||||
|
if (!empty($this->result))
|
||||||
|
{
|
||||||
|
$this->db->sql_freeresult($this->result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set key
|
||||||
|
*/
|
||||||
|
function set($key, $value)
|
||||||
|
{
|
||||||
|
$this->keys[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get key
|
||||||
|
*/
|
||||||
|
function get($key)
|
||||||
|
{
|
||||||
|
return (isset($this->keys[$key])) ? $this->keys[$key] : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_readable_forums()
|
||||||
|
{
|
||||||
|
static $forum_ids;
|
||||||
|
|
||||||
|
if (!isset($forum_ids))
|
||||||
|
{
|
||||||
|
$forum_ids = array_keys($this->auth->acl_getf('f_read', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $forum_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_moderator_approve_forums()
|
||||||
|
{
|
||||||
|
static $forum_ids;
|
||||||
|
|
||||||
|
if (!isset($forum_ids))
|
||||||
|
{
|
||||||
|
$forum_ids = array_keys($this->auth->acl_getf('m_approve', true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $forum_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_moderator_approve_forum($forum_id)
|
||||||
|
{
|
||||||
|
static $forum_ids;
|
||||||
|
|
||||||
|
if (!isset($forum_ids))
|
||||||
|
{
|
||||||
|
$forum_ids = array_flip($this->get_moderator_approve_forums());
|
||||||
|
}
|
||||||
|
|
||||||
|
return (isset($forum_ids[$forum_id])) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_excluded_forums()
|
||||||
|
{
|
||||||
|
static $forum_ids;
|
||||||
|
|
||||||
|
// Matches acp/acp_board.php
|
||||||
|
$cache_name = 'feed_excluded_forum_ids';
|
||||||
|
|
||||||
|
if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT forum_id
|
||||||
|
FROM ' . FORUMS_TABLE . '
|
||||||
|
WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0');
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$forum_ids = array();
|
||||||
|
while ($forum_id = (int) $this->db->sql_fetchfield('forum_id'))
|
||||||
|
{
|
||||||
|
$forum_ids[$forum_id] = $forum_id;
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->cache->put('_' . $cache_name, $forum_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $forum_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_excluded_forum($forum_id)
|
||||||
|
{
|
||||||
|
$forum_ids = $this->get_excluded_forums();
|
||||||
|
|
||||||
|
return isset($forum_ids[$forum_id]) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_passworded_forums()
|
||||||
|
{
|
||||||
|
return $this->user->get_passworded_forums();
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_item()
|
||||||
|
{
|
||||||
|
static $result;
|
||||||
|
|
||||||
|
if (!isset($result))
|
||||||
|
{
|
||||||
|
if (!$this->get_sql())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query database
|
||||||
|
$sql = $this->db->sql_build_query('SELECT', $this->sql);
|
||||||
|
$result = $this->db->sql_query_limit($sql, $this->num_items);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->db->sql_fetchrow($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function user_viewprofile($row)
|
||||||
|
{
|
||||||
|
$author_id = (int) $row[$this->get('author_id')];
|
||||||
|
|
||||||
|
if ($author_id == ANONYMOUS)
|
||||||
|
{
|
||||||
|
// Since we cannot link to a profile, we just return GUEST
|
||||||
|
// instead of $row['username']
|
||||||
|
return $this->user->lang['GUEST'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<a href="' . $this->helper->append_sid('memberlist.' . $this->phpEx, 'mode=viewprofile&u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
|
||||||
|
}
|
||||||
|
}
|
129
phpBB/includes/feed/factory.php
Normal file
129
phpBB/includes/feed/factory.php
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory class to return correct object
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Service container object
|
||||||
|
* @var object
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
|
/** @var phpbb_config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @var phpbb_db_driver */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param objec $container Container object
|
||||||
|
* @param phpbb_config $config Config object
|
||||||
|
* @param phpbb_db_driver $db Database connection
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function __construct($container, phpbb_config $config, phpbb_db_driver $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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
147
phpBB/includes/feed/forum.php
Normal file
147
phpBB/includes/feed/forum.php
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forum feed
|
||||||
|
*
|
||||||
|
* This will give you the last {$this->num_items} posts made
|
||||||
|
* within a specific forum.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_forum extends phpbb_feed_post_base
|
||||||
|
{
|
||||||
|
var $forum_id = 0;
|
||||||
|
var $forum_data = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Forum ID
|
||||||
|
*
|
||||||
|
* @param int $forum_id Forum ID
|
||||||
|
* @return phpbb_feed_forum
|
||||||
|
*/
|
||||||
|
public function set_forum_id($topic_id)
|
||||||
|
{
|
||||||
|
$this->forum_id = (int) $forum_id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function open()
|
||||||
|
{
|
||||||
|
// Check if forum exists
|
||||||
|
$sql = 'SELECT forum_id, forum_name, forum_password, forum_type, forum_options
|
||||||
|
FROM ' . FORUMS_TABLE . '
|
||||||
|
WHERE forum_id = ' . $this->forum_id;
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$this->forum_data = $this->db->sql_fetchrow($result);
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($this->forum_data))
|
||||||
|
{
|
||||||
|
trigger_error('NO_FORUM');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forum needs to be postable
|
||||||
|
if ($this->forum_data['forum_type'] != FORUM_POST)
|
||||||
|
{
|
||||||
|
trigger_error('NO_FEED');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure forum is not excluded from feed
|
||||||
|
if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->forum_data['forum_options']))
|
||||||
|
{
|
||||||
|
trigger_error('NO_FEED');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we can read this forum
|
||||||
|
if (!$this->auth->acl_get('f_read', $this->forum_id))
|
||||||
|
{
|
||||||
|
trigger_error('SORRY_AUTH_READ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure forum is not passworded or user is authed
|
||||||
|
if ($this->forum_data['forum_password'])
|
||||||
|
{
|
||||||
|
$forum_ids_passworded = $this->get_passworded_forums();
|
||||||
|
|
||||||
|
if (isset($forum_ids_passworded[$this->forum_id]))
|
||||||
|
{
|
||||||
|
trigger_error('SORRY_AUTH_READ');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($forum_ids_passworded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
$m_approve = ($this->auth->acl_get('m_approve', $this->forum_id)) ? true : false;
|
||||||
|
|
||||||
|
// Determine topics with recent activity
|
||||||
|
$sql = 'SELECT topic_id, topic_last_post_time
|
||||||
|
FROM ' . TOPICS_TABLE . '
|
||||||
|
WHERE forum_id = ' . $this->forum_id . '
|
||||||
|
AND topic_moved_id = 0
|
||||||
|
' . ((!$m_approve) ? 'AND topic_approved = 1' : '') . '
|
||||||
|
ORDER BY topic_last_post_time DESC';
|
||||||
|
$result = $this->db->sql_query_limit($sql, $this->num_items);
|
||||||
|
|
||||||
|
$topic_ids = array();
|
||||||
|
$min_post_time = 0;
|
||||||
|
while ($row = $this->db->sql_fetchrow())
|
||||||
|
{
|
||||||
|
$topic_ids[] = (int) $row['topic_id'];
|
||||||
|
|
||||||
|
$min_post_time = (int) $row['topic_last_post_time'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($topic_ids))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sql = array(
|
||||||
|
'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
|
||||||
|
'u.username, u.user_id',
|
||||||
|
'FROM' => array(
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
|
USERS_TABLE => 'u',
|
||||||
|
),
|
||||||
|
'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . '
|
||||||
|
' . ((!$m_approve) ? 'AND p.post_approved = 1' : '') . '
|
||||||
|
AND p.post_time >= ' . $min_post_time . '
|
||||||
|
AND p.poster_id = u.user_id',
|
||||||
|
'ORDER_BY' => 'p.post_time DESC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjust_item(&$item_row, &$row)
|
||||||
|
{
|
||||||
|
parent::adjust_item($item_row, $row);
|
||||||
|
|
||||||
|
$item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_item()
|
||||||
|
{
|
||||||
|
return ($row = parent::get_item()) ? array_merge($this->forum_data, $row) : $row;
|
||||||
|
}
|
||||||
|
}
|
72
phpBB/includes/feed/forums.php
Normal file
72
phpBB/includes/feed/forums.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* '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
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_forums extends phpbb_feed_base
|
||||||
|
{
|
||||||
|
var $num_items = 0;
|
||||||
|
|
||||||
|
function set_keys()
|
||||||
|
{
|
||||||
|
$this->set('title', 'forum_name');
|
||||||
|
$this->set('text', 'forum_desc');
|
||||||
|
$this->set('bitfield', 'forum_desc_bitfield');
|
||||||
|
$this->set('bbcode_uid','forum_desc_uid');
|
||||||
|
$this->set('updated', 'forum_last_post_time');
|
||||||
|
$this->set('options', 'forum_desc_options');
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
$in_fid_ary = array_diff($this->get_readable_forums(), $this->get_excluded_forums());
|
||||||
|
if (empty($in_fid_ary))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build SQL Query
|
||||||
|
$this->sql = array(
|
||||||
|
'SELECT' => 'f.forum_id, f.left_id, f.forum_name, f.forum_last_post_time,
|
||||||
|
f.forum_desc, f.forum_desc_bitfield, f.forum_desc_uid, f.forum_desc_options,
|
||||||
|
f.forum_topics, f.forum_posts',
|
||||||
|
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||||
|
'WHERE' => 'f.forum_type = ' . FORUM_POST . '
|
||||||
|
AND ' . $this->db->sql_in_set('f.forum_id', $in_fid_ary),
|
||||||
|
'ORDER_BY' => 'f.left_id ASC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjust_item(&$item_row, &$row)
|
||||||
|
{
|
||||||
|
$item_row['link'] = $this->helper->append_sid('viewforum.' . $this->phpEx, 'f=' . $row['forum_id']);
|
||||||
|
|
||||||
|
if ($this->config['feed_item_statistics'])
|
||||||
|
{
|
||||||
|
$item_row['statistics'] = $this->user->lang('TOTAL_TOPICS', (int) $row['forum_topics'])
|
||||||
|
. ' ' . $this->separator_stats . ' ' . $this->user->lang('TOTAL_POSTS_COUNT', (int) $row['forum_posts']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
159
phpBB/includes/feed/helper.php
Normal file
159
phpBB/includes/feed/helper.php
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class with some helpful functions used in feeds
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_helper
|
||||||
|
{
|
||||||
|
/** @var phpbb_config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @var phpbb_user */
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $phpbb_root_path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param phpbb_config $config Config object
|
||||||
|
* @param phpbb_user $user User object
|
||||||
|
* @param string $phpbb_root_path Root path
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function __construct(phpbb_config $config, phpbb_user $user, $phpbb_root_path)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
$this->user = $user;
|
||||||
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run links through append_sid(), prepend generate_board_url() and remove session id
|
||||||
|
*/
|
||||||
|
public function get_board_url()
|
||||||
|
{
|
||||||
|
static $board_url;
|
||||||
|
|
||||||
|
if (empty($board_url))
|
||||||
|
{
|
||||||
|
$board_url = generate_board_url();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $board_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
public function format_date($time)
|
||||||
|
{
|
||||||
|
static $zone_offset;
|
||||||
|
static $offset_string;
|
||||||
|
|
||||||
|
if (empty($offset_string))
|
||||||
|
{
|
||||||
|
$zone_offset = $this->user->create_datetime()->getOffset();
|
||||||
|
$offset_string = phpbb_format_timezone_offset($zone_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate text content
|
||||||
|
*/
|
||||||
|
public function generate_content($content, $uid, $bitfield, $options)
|
||||||
|
{
|
||||||
|
if (empty($content))
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare some bbcodes for better parsing
|
||||||
|
$content = preg_replace("#\[quote(=".*?")?:$uid\]\s*(.*?)\s*\[/quote:$uid\]#si", "[quote$1:$uid]<br />$2<br />[/quote:$uid]", $content);
|
||||||
|
|
||||||
|
$content = generate_text_for_display($content, $uid, $bitfield, $options);
|
||||||
|
|
||||||
|
// Add newlines
|
||||||
|
$content = str_replace('<br />', '<br />' . "\n", $content);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
$content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Make text strong :P
|
||||||
|
// $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);
|
||||||
|
|
||||||
|
// Underline
|
||||||
|
// $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);
|
||||||
|
|
||||||
|
// Do not use < and >, because we want to retain code contained in [code][/code]
|
||||||
|
|
||||||
|
// Remove embed and objects
|
||||||
|
$content = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' <a href=$4 target="_blank"><strong>$1</strong></a> ',$content);
|
||||||
|
|
||||||
|
// Remove some specials html tag, because somewhere there are a mod to allow html tags ;)
|
||||||
|
$content = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
|
||||||
|
|
||||||
|
// Remove Comments from inline attachments [ia]
|
||||||
|
$content = preg_replace('#<div class="(inline-attachment|attachtitle)">(.*?)<!-- ia(.*?) -->(.*?)<!-- ia(.*?) -->(.*?)</div>#si','$4',$content);
|
||||||
|
|
||||||
|
// Replace some entities with their unicode counterpart
|
||||||
|
$entities = array(
|
||||||
|
' ' => "\xC2\xA0",
|
||||||
|
'•' => "\xE2\x80\xA2",
|
||||||
|
'·' => "\xC2\xB7",
|
||||||
|
'©' => "\xC2\xA9",
|
||||||
|
);
|
||||||
|
|
||||||
|
$content = str_replace(array_keys($entities), array_values($entities), $content);
|
||||||
|
|
||||||
|
// Remove CDATA blocks. ;)
|
||||||
|
$content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content);
|
||||||
|
|
||||||
|
// Other control characters
|
||||||
|
$content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content);
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
112
phpBB/includes/feed/news.php
Normal file
112
phpBB/includes/feed/news.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* News feed
|
||||||
|
*
|
||||||
|
* This will give you {$this->num_items} first posts
|
||||||
|
* of all topics in the selected news forums.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_news extends phpbb_feed_topic_base
|
||||||
|
{
|
||||||
|
function get_news_forums()
|
||||||
|
{
|
||||||
|
static $forum_ids;
|
||||||
|
|
||||||
|
// Matches acp/acp_board.php
|
||||||
|
$cache_name = 'feed_news_forum_ids';
|
||||||
|
|
||||||
|
if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false)
|
||||||
|
{
|
||||||
|
$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($sql);
|
||||||
|
|
||||||
|
$forum_ids = array();
|
||||||
|
while ($forum_id = (int) $this->db->sql_fetchfield('forum_id'))
|
||||||
|
{
|
||||||
|
$forum_ids[$forum_id] = $forum_id;
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->cache->put('_' . $cache_name, $forum_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $forum_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
// Determine forum ids
|
||||||
|
$in_fid_ary = array_intersect($this->get_news_forums(), $this->get_readable_forums());
|
||||||
|
if (empty($in_fid_ary))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums());
|
||||||
|
if (empty($in_fid_ary))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We really have to get the post ids first!
|
||||||
|
$sql = 'SELECT topic_first_post_id, topic_time
|
||||||
|
FROM ' . TOPICS_TABLE . '
|
||||||
|
WHERE ' . $this->db->sql_in_set('forum_id', $in_fid_ary) . '
|
||||||
|
AND topic_moved_id = 0
|
||||||
|
AND topic_approved = 1
|
||||||
|
ORDER BY topic_time DESC';
|
||||||
|
$result = $this->db->sql_query_limit($sql, $this->num_items);
|
||||||
|
|
||||||
|
$post_ids = array();
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$post_ids[] = (int) $row['topic_first_post_id'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($post_ids))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sql = array(
|
||||||
|
'SELECT' => 'f.forum_id, f.forum_name,
|
||||||
|
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time,
|
||||||
|
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
|
||||||
|
'FROM' => array(
|
||||||
|
TOPICS_TABLE => 't',
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
|
),
|
||||||
|
'LEFT_JOIN' => array(
|
||||||
|
array(
|
||||||
|
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||||
|
'ON' => 'p.forum_id = f.forum_id',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'WHERE' => 'p.topic_id = t.topic_id
|
||||||
|
AND ' . $this->db->sql_in_set('p.post_id', $post_ids),
|
||||||
|
'ORDER_BY' => 'p.post_time DESC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
97
phpBB/includes/feed/overall.php
Normal file
97
phpBB/includes/feed/overall.php
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Board wide feed (aka overall feed)
|
||||||
|
*
|
||||||
|
* This will give you the newest {$this->num_items} posts
|
||||||
|
* from the whole board.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_overall extends phpbb_feed_post_base
|
||||||
|
{
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
$forum_ids = array_diff($this->get_readable_forums(), $this->get_excluded_forums(), $this->get_passworded_forums());
|
||||||
|
if (empty($forum_ids))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// m_approve forums
|
||||||
|
$fid_m_approve = $this->get_moderator_approve_forums();
|
||||||
|
$sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $this->db->sql_in_set('forum_id', $fid_m_approve) : '';
|
||||||
|
|
||||||
|
// Determine topics with recent activity
|
||||||
|
$sql = 'SELECT topic_id, topic_last_post_time
|
||||||
|
FROM ' . TOPICS_TABLE . '
|
||||||
|
WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . '
|
||||||
|
AND topic_moved_id = 0
|
||||||
|
AND (topic_approved = 1
|
||||||
|
' . $sql_m_approve . ')
|
||||||
|
ORDER BY topic_last_post_time DESC';
|
||||||
|
$result = $this->db->sql_query_limit($sql, $this->num_items);
|
||||||
|
|
||||||
|
$topic_ids = array();
|
||||||
|
$min_post_time = 0;
|
||||||
|
while ($row = $this->db->sql_fetchrow())
|
||||||
|
{
|
||||||
|
$topic_ids[] = (int) $row['topic_id'];
|
||||||
|
|
||||||
|
$min_post_time = (int) $row['topic_last_post_time'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($topic_ids))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
|
||||||
|
'u.username, u.user_id',
|
||||||
|
'FROM' => array(
|
||||||
|
USERS_TABLE => 'u',
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
|
),
|
||||||
|
'LEFT_JOIN' => array(
|
||||||
|
array(
|
||||||
|
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||||
|
'ON' => 'f.forum_id = p.forum_id',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'WHERE' => $this->db->sql_in_set('p.topic_id', $topic_ids) . '
|
||||||
|
AND (p.post_approved = 1
|
||||||
|
' . str_replace('forum_id', 'p.forum_id', $sql_m_approve) . ')
|
||||||
|
AND p.post_time >= ' . $min_post_time . '
|
||||||
|
AND u.user_id = p.poster_id',
|
||||||
|
'ORDER_BY' => 'p.post_time DESC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjust_item(&$item_row, &$row)
|
||||||
|
{
|
||||||
|
parent::adjust_item($item_row, $row);
|
||||||
|
|
||||||
|
$item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
|
||||||
|
}
|
||||||
|
}
|
57
phpBB/includes/feed/post_base.php
Normal file
57
phpBB/includes/feed/post_base.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for post based feeds
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
abstract class phpbb_feed_post_base extends phpbb_feed_base
|
||||||
|
{
|
||||||
|
var $num_items = 'feed_limit_post';
|
||||||
|
|
||||||
|
function set_keys()
|
||||||
|
{
|
||||||
|
$this->set('title', 'post_subject');
|
||||||
|
$this->set('title2', 'topic_title');
|
||||||
|
|
||||||
|
$this->set('author_id', 'user_id');
|
||||||
|
$this->set('creator', 'username');
|
||||||
|
$this->set('published', 'post_time');
|
||||||
|
$this->set('updated', 'post_edit_time');
|
||||||
|
$this->set('text', 'post_text');
|
||||||
|
|
||||||
|
$this->set('bitfield', 'bbcode_bitfield');
|
||||||
|
$this->set('bbcode_uid','bbcode_uid');
|
||||||
|
|
||||||
|
$this->set('enable_bbcode', 'enable_bbcode');
|
||||||
|
$this->set('enable_smilies', 'enable_smilies');
|
||||||
|
$this->set('enable_magic_url', 'enable_magic_url');
|
||||||
|
}
|
||||||
|
|
||||||
|
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']}");
|
||||||
|
|
||||||
|
if ($this->config['feed_item_statistics'])
|
||||||
|
{
|
||||||
|
$item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
|
||||||
|
. ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')])
|
||||||
|
. (($this->is_moderator_approve_forum($row['forum_id']) && !$row['post_approved']) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POST_UNAPPROVED'] : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
116
phpBB/includes/feed/topic.php
Normal file
116
phpBB/includes/feed/topic.php
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Topic feed for a specific topic
|
||||||
|
*
|
||||||
|
* This will give you the last {$this->num_items} posts made within this topic.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_topic extends phpbb_feed_post_base
|
||||||
|
{
|
||||||
|
var $topic_id = 0;
|
||||||
|
var $forum_id = 0;
|
||||||
|
var $topic_data = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function open()
|
||||||
|
{
|
||||||
|
$sql = 'SELECT f.forum_options, f.forum_password, t.topic_id, t.forum_id, t.topic_approved, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_type
|
||||||
|
FROM ' . TOPICS_TABLE . ' t
|
||||||
|
LEFT JOIN ' . FORUMS_TABLE . ' f
|
||||||
|
ON (f.forum_id = t.forum_id)
|
||||||
|
WHERE t.topic_id = ' . $this->topic_id;
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$this->topic_data = $this->db->sql_fetchrow($result);
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($this->topic_data))
|
||||||
|
{
|
||||||
|
trigger_error('NO_TOPIC');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->forum_id = (int) $this->topic_data['forum_id'];
|
||||||
|
|
||||||
|
// Make sure topic is either approved or user authed
|
||||||
|
if (!$this->topic_data['topic_approved'] && !$this->auth->acl_get('m_approve', $this->forum_id))
|
||||||
|
{
|
||||||
|
trigger_error('SORRY_AUTH_READ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure forum is not excluded from feed
|
||||||
|
if (phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $this->topic_data['forum_options']))
|
||||||
|
{
|
||||||
|
trigger_error('NO_FEED');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we can read this forum
|
||||||
|
if (!$this->auth->acl_get('f_read', $this->forum_id))
|
||||||
|
{
|
||||||
|
trigger_error('SORRY_AUTH_READ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure forum is not passworded or user is authed
|
||||||
|
if ($this->topic_data['forum_password'])
|
||||||
|
{
|
||||||
|
$forum_ids_passworded = $this->get_passworded_forums();
|
||||||
|
|
||||||
|
if (isset($forum_ids_passworded[$this->forum_id]))
|
||||||
|
{
|
||||||
|
trigger_error('SORRY_AUTH_READ');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($forum_ids_passworded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
$this->sql = array(
|
||||||
|
'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_approved, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' .
|
||||||
|
'u.username, u.user_id',
|
||||||
|
'FROM' => array(
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
|
USERS_TABLE => 'u',
|
||||||
|
),
|
||||||
|
'WHERE' => 'p.topic_id = ' . $this->topic_id . '
|
||||||
|
' . ($this->forum_id && !$this->auth->acl_get('m_approve', $this->forum_id) ? 'AND p.post_approved = 1' : '') . '
|
||||||
|
AND p.poster_id = u.user_id',
|
||||||
|
'ORDER_BY' => 'p.post_time DESC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_item()
|
||||||
|
{
|
||||||
|
return ($row = parent::get_item()) ? array_merge($this->topic_data, $row) : $row;
|
||||||
|
}
|
||||||
|
}
|
59
phpBB/includes/feed/topic_base.php
Normal file
59
phpBB/includes/feed/topic_base.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for topic based feeds
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
abstract class phpbb_feed_topic_base extends phpbb_feed_base
|
||||||
|
{
|
||||||
|
var $num_items = 'feed_limit_topic';
|
||||||
|
|
||||||
|
function set_keys()
|
||||||
|
{
|
||||||
|
$this->set('title', 'topic_title');
|
||||||
|
$this->set('title2', 'forum_name');
|
||||||
|
|
||||||
|
$this->set('author_id', 'topic_poster');
|
||||||
|
$this->set('creator', 'topic_first_poster_name');
|
||||||
|
$this->set('published', 'post_time');
|
||||||
|
$this->set('updated', 'post_edit_time');
|
||||||
|
$this->set('text', 'post_text');
|
||||||
|
|
||||||
|
$this->set('bitfield', 'bbcode_bitfield');
|
||||||
|
$this->set('bbcode_uid','bbcode_uid');
|
||||||
|
|
||||||
|
$this->set('enable_bbcode', 'enable_bbcode');
|
||||||
|
$this->set('enable_smilies', 'enable_smilies');
|
||||||
|
$this->set('enable_magic_url', 'enable_magic_url');
|
||||||
|
}
|
||||||
|
|
||||||
|
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']);
|
||||||
|
|
||||||
|
if ($this->config['feed_item_statistics'])
|
||||||
|
{
|
||||||
|
$item_row['statistics'] = $this->user->lang['POSTED'] . ' ' . $this->user->lang['POST_BY_AUTHOR'] . ' ' . $this->user_viewprofile($row)
|
||||||
|
. ' ' . $this->separator_stats . ' ' . $this->user->format_date($row[$this->get('published')])
|
||||||
|
. ' ' . $this->separator_stats . ' ' . $this->user->lang['REPLIES'] . ' ' . (($this->is_moderator_approve_forum($row['forum_id'])) ? $row['topic_replies_real'] : $row['topic_replies'])
|
||||||
|
. ' ' . $this->separator_stats . ' ' . $this->user->lang['VIEWS'] . ' ' . $row['topic_views']
|
||||||
|
. (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $this->user->lang['POSTS_UNAPPROVED'] : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
91
phpBB/includes/feed/topics.php
Normal file
91
phpBB/includes/feed/topics.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New Topics feed
|
||||||
|
*
|
||||||
|
* This will give you the last {$this->num_items} created topics
|
||||||
|
* including the first post.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_topics extends phpbb_feed_topic_base
|
||||||
|
{
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
$forum_ids_read = $this->get_readable_forums();
|
||||||
|
if (empty($forum_ids_read))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$in_fid_ary = array_diff($forum_ids_read, $this->get_excluded_forums(), $this->get_passworded_forums());
|
||||||
|
if (empty($in_fid_ary))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We really have to get the post ids first!
|
||||||
|
$sql = 'SELECT topic_first_post_id, topic_time
|
||||||
|
FROM ' . TOPICS_TABLE . '
|
||||||
|
WHERE ' . $this->db->sql_in_set('forum_id', $in_fid_ary) . '
|
||||||
|
AND topic_moved_id = 0
|
||||||
|
AND topic_approved = 1
|
||||||
|
ORDER BY topic_time DESC';
|
||||||
|
$result = $this->db->sql_query_limit($sql, $this->num_items);
|
||||||
|
|
||||||
|
$post_ids = array();
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$post_ids[] = (int) $row['topic_first_post_id'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($post_ids))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sql = array(
|
||||||
|
'SELECT' => 'f.forum_id, f.forum_name,
|
||||||
|
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time,
|
||||||
|
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
|
||||||
|
'FROM' => array(
|
||||||
|
TOPICS_TABLE => 't',
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
|
),
|
||||||
|
'LEFT_JOIN' => array(
|
||||||
|
array(
|
||||||
|
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||||
|
'ON' => 'p.forum_id = f.forum_id',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'WHERE' => 'p.topic_id = t.topic_id
|
||||||
|
AND ' . $this->db->sql_in_set('p.post_id', $post_ids),
|
||||||
|
'ORDER_BY' => 'p.post_time DESC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjust_item(&$item_row, &$row)
|
||||||
|
{
|
||||||
|
parent::adjust_item($item_row, $row);
|
||||||
|
|
||||||
|
$item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
|
||||||
|
}
|
||||||
|
}
|
136
phpBB/includes/feed/topics_active.php
Normal file
136
phpBB/includes/feed/topics_active.php
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
*/
|
||||||
|
class phpbb_feed_topics_active extends phpbb_feed_topic_base
|
||||||
|
{
|
||||||
|
var $sort_days = 7;
|
||||||
|
|
||||||
|
function set_keys()
|
||||||
|
{
|
||||||
|
parent::set_keys();
|
||||||
|
|
||||||
|
$this->set('author_id', 'topic_last_poster_id');
|
||||||
|
$this->set('creator', 'topic_last_poster_name');
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sql()
|
||||||
|
{
|
||||||
|
$forum_ids_read = $this->get_readable_forums();
|
||||||
|
if (empty($forum_ids_read))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$in_fid_ary = array_intersect($forum_ids_read, $this->get_forum_ids());
|
||||||
|
$in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums());
|
||||||
|
if (empty($in_fid_ary))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for topics in last X days
|
||||||
|
$last_post_time_sql = ($this->sort_days) ? ' AND topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : '';
|
||||||
|
|
||||||
|
// We really have to get the post ids first!
|
||||||
|
$sql = 'SELECT topic_last_post_id, topic_last_post_time
|
||||||
|
FROM ' . TOPICS_TABLE . '
|
||||||
|
WHERE ' . $this->db->sql_in_set('forum_id', $in_fid_ary) . '
|
||||||
|
AND topic_moved_id = 0
|
||||||
|
AND topic_approved = 1
|
||||||
|
' . $last_post_time_sql . '
|
||||||
|
ORDER BY topic_last_post_time DESC';
|
||||||
|
$result = $this->db->sql_query_limit($sql, $this->num_items);
|
||||||
|
|
||||||
|
$post_ids = array();
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$post_ids[] = (int) $row['topic_last_post_id'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (empty($post_ids))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sql = array(
|
||||||
|
'SELECT' => 'f.forum_id, f.forum_name,
|
||||||
|
t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_views,
|
||||||
|
t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time,
|
||||||
|
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
|
||||||
|
'FROM' => array(
|
||||||
|
TOPICS_TABLE => 't',
|
||||||
|
POSTS_TABLE => 'p',
|
||||||
|
),
|
||||||
|
'LEFT_JOIN' => array(
|
||||||
|
array(
|
||||||
|
'FROM' => array(FORUMS_TABLE => 'f'),
|
||||||
|
'ON' => 'p.forum_id = f.forum_id',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'WHERE' => 'p.topic_id = t.topic_id
|
||||||
|
AND ' . $this->db->sql_in_set('p.post_id', $post_ids),
|
||||||
|
'ORDER_BY' => 'p.post_time DESC',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_forum_ids()
|
||||||
|
{
|
||||||
|
static $forum_ids;
|
||||||
|
|
||||||
|
$cache_name = 'feed_topic_active_forum_ids';
|
||||||
|
|
||||||
|
if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT forum_id
|
||||||
|
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');
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$forum_ids = array();
|
||||||
|
while ($forum_id = (int) $this->db->sql_fetchfield('forum_id'))
|
||||||
|
{
|
||||||
|
$forum_ids[$forum_id] = $forum_id;
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->cache->put('_' . $cache_name, $forum_ids, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $forum_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjust_item(&$item_row, &$row)
|
||||||
|
{
|
||||||
|
parent::adjust_item($item_row, $row);
|
||||||
|
|
||||||
|
$item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user