[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/feed/ -> base.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\feed;
  15  
  16  /**
  17  * Base class with some generic functions and settings.
  18  */
  19  abstract class base
  20  {
  21      /**
  22      * Feed helper object
  23      * @var \phpbb\feed\helper
  24      */
  25      protected $helper;
  26  
  27      /** @var \phpbb\config\config */
  28      protected $config;
  29  
  30      /** @var \phpbb\db\driver\driver_interface */
  31      protected $db;
  32  
  33      /** @var \phpbb\cache\driver\driver_interface */
  34      protected $cache;
  35  
  36      /** @var \phpbb\user */
  37      protected $user;
  38  
  39      /** @var \phpbb\auth\auth */
  40      protected $auth;
  41  
  42      /** @var \phpbb\content_visibility */
  43      protected $content_visibility;
  44  
  45      /** @var \phpbb\event\dispatcher_interface */
  46      protected $phpbb_dispatcher;
  47  
  48      /** @var string */
  49      protected $phpEx;
  50  
  51      /**
  52      * SQL Query to be executed to get feed items
  53      */
  54      var $sql = array();
  55  
  56      /**
  57      * Keys specified for retrieval of title, content, etc.
  58      */
  59      var $keys = array();
  60  
  61      /**
  62      * Number of items to fetch. Usually overwritten by $config['feed_something']
  63      */
  64      var $num_items = 15;
  65  
  66      /**
  67      * Separator for title elements to separate items (for example forum / topic)
  68      */
  69      var $separator = "\xE2\x80\xA2"; // &bull;
  70  
  71      /**
  72      * Separator for the statistics row (Posted by, post date, replies, etc.)
  73      */
  74      var $separator_stats = "\xE2\x80\x94"; // &mdash;
  75  
  76      /** @var mixed Query result handle */
  77      protected $result;
  78  
  79      /**
  80      * Constructor
  81      *
  82      * @param \phpbb\feed\helper                    $helper        Feed helper
  83      * @param \phpbb\config\config                $config        Config object
  84      * @param \phpbb\db\driver\driver_interface    $db            Database connection
  85      * @param \phpbb\cache\driver\driver_interface    $cache    Cache object
  86      * @param \phpbb\user                        $user        User object
  87      * @param \phpbb\auth\auth                    $auth        Auth object
  88      * @param \phpbb\content_visibility            $content_visibility        Content visibility object
  89      * @param \phpbb\event\dispatcher_interface    $phpbb_dispatcher        Event dispatcher object
  90      * @param string                                $phpEx        php file extension
  91      */
  92  	function __construct(
  93          \phpbb\feed\helper $helper,
  94          \phpbb\config\config $config,
  95          \phpbb\db\driver\driver_interface $db,
  96          \phpbb\cache\driver\driver_interface $cache,
  97          \phpbb\user $user,
  98          \phpbb\auth\auth $auth,
  99          \phpbb\content_visibility $content_visibility,
 100          \phpbb\event\dispatcher_interface $phpbb_dispatcher,
 101          $phpEx
 102      )
 103      {
 104          $this->config = $config;
 105          $this->helper = $helper;
 106          $this->db = $db;
 107          $this->cache = $cache;
 108          $this->user = $user;
 109          $this->auth = $auth;
 110          $this->content_visibility = $content_visibility;
 111          $this->phpbb_dispatcher = $phpbb_dispatcher;
 112          $this->phpEx = $phpEx;
 113  
 114          $this->set_keys();
 115  
 116          // Allow num_items to be string
 117          if (is_string($this->num_items))
 118          {
 119              $this->num_items = (int) $this->config[$this->num_items];
 120  
 121              // A precaution
 122              if (!$this->num_items)
 123              {
 124                  $this->num_items = 10;
 125              }
 126          }
 127      }
 128  
 129      /**
 130      * Set keys.
 131      */
 132  	function set_keys()
 133      {
 134      }
 135  
 136      /**
 137      * Open feed
 138      */
 139  	function open()
 140      {
 141      }
 142  
 143      /**
 144      * Close feed
 145      */
 146  	function close()
 147      {
 148          if (!empty($this->result))
 149          {
 150              $this->db->sql_freeresult($this->result);
 151          }
 152      }
 153  
 154      /**
 155      * Set key
 156      *
 157      * @param string $key Key
 158      * @param mixed $value Value
 159      */
 160  	function set($key, $value)
 161      {
 162          $this->keys[$key] = $value;
 163      }
 164  
 165      /**
 166      * Get key
 167      *
 168      * @param string $key Key
 169      * @return mixed
 170      */
 171  	function get($key)
 172      {
 173          return (isset($this->keys[$key])) ? $this->keys[$key] : null;
 174      }
 175  
 176  	function get_readable_forums()
 177      {
 178          static $forum_ids;
 179  
 180          if (!isset($forum_ids))
 181          {
 182              $forum_ids = array_keys($this->auth->acl_getf('f_read', true));
 183          }
 184  
 185          return $forum_ids;
 186      }
 187  
 188  	function get_moderator_approve_forums()
 189      {
 190          static $forum_ids;
 191  
 192          if (!isset($forum_ids))
 193          {
 194              $forum_ids = array_keys($this->auth->acl_getf('m_approve', true));
 195          }
 196  
 197          return $forum_ids;
 198      }
 199  
 200  	function is_moderator_approve_forum($forum_id)
 201      {
 202          static $forum_ids;
 203  
 204          if (!isset($forum_ids))
 205          {
 206              $forum_ids = array_flip($this->get_moderator_approve_forums());
 207          }
 208  
 209          return (isset($forum_ids[$forum_id])) ? true : false;
 210      }
 211  
 212  	function get_excluded_forums()
 213      {
 214          static $forum_ids;
 215  
 216          // Matches acp/acp_board.php
 217          $cache_name    = 'feed_excluded_forum_ids';
 218  
 219          if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false)
 220          {
 221              $sql = 'SELECT forum_id
 222                  FROM ' . FORUMS_TABLE . '
 223                  WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '<> 0');
 224              $result = $this->db->sql_query($sql);
 225  
 226              $forum_ids = array();
 227              while ($forum_id = (int) $this->db->sql_fetchfield('forum_id'))
 228              {
 229                  $forum_ids[$forum_id] = $forum_id;
 230              }
 231              $this->db->sql_freeresult($result);
 232  
 233              $this->cache->put('_' . $cache_name, $forum_ids);
 234          }
 235  
 236          return $forum_ids;
 237      }
 238  
 239  	function is_excluded_forum($forum_id)
 240      {
 241          $forum_ids = $this->get_excluded_forums();
 242  
 243          return isset($forum_ids[$forum_id]) ? true : false;
 244      }
 245  
 246  	function get_passworded_forums()
 247      {
 248          return $this->user->get_passworded_forums();
 249      }
 250  
 251  	function get_item()
 252      {
 253          if (!isset($this->result))
 254          {
 255              if (!$this->get_sql())
 256              {
 257                  return false;
 258              }
 259  
 260              $sql_ary = $this->sql;
 261  
 262              /**
 263              * Event to modify the feed item sql
 264              *
 265              * @event core.feed_base_modify_item_sql
 266              * @var    array    sql_ary        The SQL array to get the feed item data
 267              *
 268              * @since 3.1.10-RC1
 269              */
 270              $vars = array('sql_ary');
 271              extract($this->phpbb_dispatcher->trigger_event('core.feed_base_modify_item_sql', compact($vars)));
 272              $this->sql = $sql_ary;
 273              unset($sql_ary);
 274  
 275              // Query database
 276              $sql = $this->db->sql_build_query('SELECT', $this->sql);
 277              $this->result = $this->db->sql_query_limit($sql, $this->num_items);
 278          }
 279  
 280          return $this->db->sql_fetchrow($this->result);
 281      }
 282  
 283  	function user_viewprofile($row)
 284      {
 285          $author_id = (int) $row[$this->get('author_id')];
 286  
 287          if ($author_id == ANONYMOUS)
 288          {
 289              // Since we cannot link to a profile, we just return GUEST
 290              // instead of $row['username']
 291              return $this->user->lang['GUEST'];
 292          }
 293  
 294          return '<a href="' . $this->helper->append_sid('memberlist.' . $this->phpEx, 'mode=viewprofile&amp;u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
 295      }
 296  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1