diff options
Diffstat (limited to 'phpBB/phpbb/feed/base.php')
| -rw-r--r-- | phpBB/phpbb/feed/base.php | 217 | 
1 files changed, 129 insertions, 88 deletions
| diff --git a/phpBB/phpbb/feed/base.php b/phpBB/phpbb/feed/base.php index 322e2ee9f1..188d229515 100644 --- a/phpBB/phpbb/feed/base.php +++ b/phpBB/phpbb/feed/base.php @@ -1,27 +1,27 @@  <?php  /** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */  namespace phpbb\feed;  /** -* Base class with some generic functions and settings. -*/ -abstract class base + * Base class with some generic functions and settings. + */ +abstract class base implements feed_interface  {  	/** -	* Feed helper object -	* @var \phpbb\feed\helper -	*/ +	 * Feed helper object +	 * @var \phpbb\feed\helper +	 */  	protected $helper;  	/** @var \phpbb\config\config */ @@ -43,46 +43,46 @@ abstract class base  	protected $phpEx;  	/** -	* SQL Query to be executed to get feed items -	*/ -	var $sql = array(); +	 * SQL Query to be executed to get feed items +	 */ +	protected $sql = array();  	/** -	* Keys specified for retrieval of title, content, etc. -	*/ -	var $keys = array(); +	 * Keys specified for retrieval of title, content, etc. +	 */ +	protected $keys = array();  	/** -	* Number of items to fetch. Usually overwritten by $config['feed_something'] -	*/ -	var $num_items = 15; +	 * Number of items to fetch. Usually overwritten by $config['feed_something'] +	 */ +	protected $num_items = 15;  	/** -	* Separator for title elements to separate items (for example forum / topic) -	*/ -	var $separator = "\xE2\x80\xA2"; // • +	 * Separator for title elements to separate items (for example forum / topic) +	 */ +	protected $separator = "\xE2\x80\xA2"; // •  	/** -	* Separator for the statistics row (Posted by, post date, replies, etc.) -	*/ -	var $separator_stats = "\xE2\x80\x94"; // — +	 * Separator for the statistics row (Posted by, post date, replies, etc.) +	 */ +	protected $separator_stats = "\xE2\x80\x94"; // —  	/** @var mixed Query result handle */  	protected $result;  	/** -	* Constructor -	* -	* @param \phpbb\feed\helper					$helper		Feed helper -	* @param \phpbb\config\config				$config		Config object -	* @param \phpbb\db\driver\driver_interface	$db			Database connection -	* @param \phpbb\cache\driver\driver_interface	$cache	Cache object -	* @param \phpbb\user						$user		User object -	* @param \phpbb\auth\auth					$auth		Auth object -	* @param \phpbb\content_visibility			$content_visibility		Auth object -	* @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) +	 * Constructor +	 * +	 * @param \phpbb\feed\helper					$helper		Feed helper +	 * @param \phpbb\config\config				$config		Config object +	 * @param \phpbb\db\driver\driver_interface	$db			Database connection +	 * @param \phpbb\cache\driver\driver_interface	$cache	Cache object +	 * @param \phpbb\user						$user		User object +	 * @param \phpbb\auth\auth					$auth		Auth object +	 * @param \phpbb\content_visibility			$content_visibility		Auth object +	 * @param string								$phpEx		php file extension +	 */ +	public 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)  	{  		$this->config = $config;  		$this->helper = $helper; @@ -109,23 +109,23 @@ abstract class base  	}  	/** -	* Set keys. -	*/ -	function set_keys() +	 * {@inheritdoc} +	 */ +	public function set_keys()  	{  	}  	/** -	* Open feed -	*/ -	function open() +	 * {@inheritdoc} +	 */ +	public function open()  	{  	}  	/** -	* Close feed -	*/ -	function close() +	 * {@inheritdoc} +	 */ +	public function close()  	{  		if (!empty($this->result))  		{ @@ -134,28 +134,47 @@ abstract class base  	}  	/** -	* Set key -	* -	* @param string $key Key -	* @param mixed $value Value -	*/ -	function set($key, $value) +	 * {@inheritdoc} +	 */ +	public function set($key, $value)  	{  		$this->keys[$key] = $value;  	}  	/** -	* Get key -	* -	* @param string $key Key -	* @return mixed -	*/ -	function get($key) +	 * {@inheritdoc} +	 */ +	public function get($key)  	{  		return (isset($this->keys[$key])) ? $this->keys[$key] : null;  	} -	function get_readable_forums() +	/** +	 * {@inheritdoc} +	 */ +	public function get_item() +	{ +		if (!isset($this->result)) +		{ +			if (!$this->get_sql()) +			{ +				return false; +			} + +			// Query database +			$sql = $this->db->sql_build_query('SELECT', $this->sql); +			$this->result = $this->db->sql_query_limit($sql, $this->num_items); +		} + +		return $this->db->sql_fetchrow($this->result); +	} + +	/** +	 * Returns the ids of the forums readable by the current user. +	 * +	 * @return int[] +	 */ +	protected function get_readable_forums()  	{  		static $forum_ids; @@ -167,7 +186,12 @@ abstract class base  		return $forum_ids;  	} -	function get_moderator_approve_forums() +	/** +	 * Returns the ids of the forum for which the current user can approve the post in the moderation queue. +	 * +	 * @return int[] +	 */ +	protected function get_moderator_approve_forums()  	{  		static $forum_ids; @@ -179,7 +203,13 @@ abstract class base  		return $forum_ids;  	} -	function is_moderator_approve_forum($forum_id) +	/** +	 * Returns true if the current user can approve the post of the given forum +	 * +	 * @param int $forum_id Forum id to check +	 * @return bool +	 */ +	protected function is_moderator_approve_forum($forum_id)  	{  		static $forum_ids; @@ -191,7 +221,12 @@ abstract class base  		return (isset($forum_ids[$forum_id])) ? true : false;  	} -	function get_excluded_forums() +	/** +	 * Returns the ids of the forum excluded from the feeds +	 * +	 * @return int[] +	 */ +	protected function get_excluded_forums()  	{  		static $forum_ids; @@ -218,36 +253,35 @@ abstract class base  		return $forum_ids;  	} -	function is_excluded_forum($forum_id) +	/** +	 * Returns true if the given id is in the excluded forums list. +	 * +	 * @param int $forum_id Id to check +	 * @return bool +	 */ +	protected function is_excluded_forum($forum_id)  	{  		$forum_ids = $this->get_excluded_forums();  		return isset($forum_ids[$forum_id]) ? true : false;  	} -	function get_passworded_forums() +	/** +	 * Returns all password protected forum ids the current user is currently NOT authenticated for. +	 * +	 * @return array     Array of forum ids +	 */ +	protected function get_passworded_forums()  	{  		return $this->user->get_passworded_forums();  	} -	function get_item() -	{ -		if (!isset($this->result)) -		{ -			if (!$this->get_sql()) -			{ -				return false; -			} - -			// Query database -			$sql = $this->db->sql_build_query('SELECT', $this->sql); -			$this->result = $this->db->sql_query_limit($sql, $this->num_items); -		} - -		return $this->db->sql_fetchrow($this->result); -	} - -	function user_viewprofile($row) +	/** +	 * Returns the link to the user profile. +	 * +	 * @return string +	 */ +	protected function user_viewprofile($row)  	{  		$author_id = (int) $row[$this->get('author_id')]; @@ -260,4 +294,11 @@ abstract class base  		return '<a href="' . $this->helper->append_sid('memberlist.' . $this->phpEx, 'mode=viewprofile&u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';  	} + +	/** +	 * Returns the SQL query used to retrieve the posts of the feed. +	 * +	 * @return string SQL SELECT query +	 */ +	protected abstract function get_sql();  } | 
