[ticket/14688] Add core events to the feeds

PHPBB3-14688
This commit is contained in:
rxu 2016-06-21 12:47:30 +07:00
parent 9595946508
commit 3df9b2c8f8
3 changed files with 56 additions and 2 deletions

View file

@ -25,6 +25,7 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%
feed.forums: feed.forums:
@ -38,6 +39,7 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%
feed.news: feed.news:
@ -51,6 +53,7 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%
feed.overall: feed.overall:
@ -64,6 +67,7 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%
feed.topic: feed.topic:
@ -77,6 +81,7 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%
feed.topics: feed.topics:
@ -90,6 +95,7 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%
feed.topics_active: feed.topics_active:
@ -103,4 +109,5 @@ services:
- @user - @user
- @auth - @auth
- @content.visibility - @content.visibility
- @dispatcher
- %core.php_ext% - %core.php_ext%

View file

@ -84,6 +84,20 @@ $feed->open();
// Iterate through items // Iterate through items
while ($row = $feed->get_item()) 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($phpbb_dispatcher->trigger_event('core.feed_modify_feed_row', compact($vars)));
// BBCode options to correctly disable urls, smilies, bbcode... // BBCode options to correctly disable urls, smilies, bbcode...
if ($feed->get('options') === NULL) if ($feed->get('options') === NULL)
{ {

View file

@ -39,6 +39,12 @@ abstract class base
/** @var \phpbb\auth\auth */ /** @var \phpbb\auth\auth */
protected $auth; protected $auth;
/** @var \phpbb\content_visibility */
protected $content_visibility;
/** @var \phpbb\event\dispatcher_interface */
protected $phpbb_dispatcher;
/** @var string */ /** @var string */
protected $phpEx; protected $phpEx;
@ -79,10 +85,21 @@ abstract class base
* @param \phpbb\cache\driver\driver_interface $cache Cache object * @param \phpbb\cache\driver\driver_interface $cache Cache object
* @param \phpbb\user $user User object * @param \phpbb\user $user User object
* @param \phpbb\auth\auth $auth Auth object * @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\content_visibility $content_visibility 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 * @param string $phpEx php file extension
*/ */
function __construct(\phpbb\feed\helper $helper, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\content_visibility $content_visibility, $phpEx) function __construct(
\phpbb\feed\helper $helper,
\phpbb\config\config $config,
\phpbb\db\driver\driver_interface $db,
\phpbb\cache\driver\driver_interface $cache,
\phpbb\user $user,
\phpbb\auth\auth $auth,
\phpbb\content_visibility $content_visibility,
\phpbb\event\dispatcher_interface $phpbb_dispatcher,
$phpEx
)
{ {
$this->config = $config; $this->config = $config;
$this->helper = $helper; $this->helper = $helper;
@ -91,6 +108,7 @@ abstract class base
$this->user = $user; $this->user = $user;
$this->auth = $auth; $this->auth = $auth;
$this->content_visibility = $content_visibility; $this->content_visibility = $content_visibility;
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->phpEx = $phpEx; $this->phpEx = $phpEx;
$this->set_keys(); $this->set_keys();
@ -239,6 +257,21 @@ abstract class base
return false; 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 // Query database
$sql = $this->db->sql_build_query('SELECT', $this->sql); $sql = $this->db->sql_build_query('SELECT', $this->sql);
$this->result = $this->db->sql_query_limit($sql, $this->num_items); $this->result = $this->db->sql_query_limit($sql, $this->num_items);