[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/feed/ -> topics_active.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  * Active Topics feed
  18  *
  19  * This will give you the last {$this->num_items} topics
  20  * with replies made withing the last {$this->sort_days} days
  21  * including the last post.
  22  */
  23  class topics_active extends \phpbb\feed\topic_base
  24  {
  25      var $sort_days = 7;
  26  
  27  	function set_keys()
  28      {
  29          parent::set_keys();
  30  
  31          $this->set('author_id',    'topic_last_poster_id');
  32          $this->set('creator',    'topic_last_poster_name');
  33      }
  34  
  35  	function get_sql()
  36      {
  37          $forum_ids_read = $this->get_readable_forums();
  38          if (empty($forum_ids_read))
  39          {
  40              return false;
  41          }
  42  
  43          $in_fid_ary = array_intersect($forum_ids_read, $this->get_forum_ids());
  44          $in_fid_ary = array_diff($in_fid_ary, $this->get_passworded_forums());
  45          if (empty($in_fid_ary))
  46          {
  47              return false;
  48          }
  49  
  50          // Search for topics in last X days
  51          $last_post_time_sql = ($this->sort_days) ? ' AND topic_last_post_time > ' . (time() - ($this->sort_days * 24 * 3600)) : '';
  52  
  53          // We really have to get the post ids first!
  54          $sql = 'SELECT topic_last_post_id, topic_last_post_time
  55              FROM ' . TOPICS_TABLE . '
  56              WHERE topic_moved_id = 0
  57                  AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $in_fid_ary) . '
  58                  ' . $last_post_time_sql . '
  59              ORDER BY topic_last_post_time DESC, topic_last_post_id DESC';
  60          $result = $this->db->sql_query_limit($sql, $this->num_items);
  61  
  62          $post_ids = array();
  63          while ($row = $this->db->sql_fetchrow($result))
  64          {
  65              $post_ids[] = (int) $row['topic_last_post_id'];
  66          }
  67          $this->db->sql_freeresult($result);
  68  
  69          if (empty($post_ids))
  70          {
  71              return false;
  72          }
  73  
  74          parent::fetch_attachments($post_ids);
  75  
  76          $this->sql = array(
  77              'SELECT'    => 'f.forum_id, f.forum_name,
  78                              t.topic_id, t.topic_title, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views,
  79                              t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time,
  80                              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, p.post_attachment, t.topic_visibility',
  81              'FROM'        => array(
  82                  TOPICS_TABLE    => 't',
  83                  POSTS_TABLE        => 'p',
  84              ),
  85              'LEFT_JOIN'    => array(
  86                  array(
  87                      'FROM'    => array(FORUMS_TABLE => 'f'),
  88                      'ON'    => 'p.forum_id = f.forum_id',
  89                  ),
  90              ),
  91              'WHERE'        => 'p.topic_id = t.topic_id
  92                              AND ' . $this->db->sql_in_set('p.post_id', $post_ids),
  93              'ORDER_BY'    => 'p.post_time DESC, p.post_id DESC',
  94          );
  95  
  96          return true;
  97      }
  98  
  99  	function get_forum_ids()
 100      {
 101          static $forum_ids;
 102  
 103          $cache_name    = 'feed_topic_active_forum_ids';
 104  
 105          if (!isset($forum_ids) && ($forum_ids = $this->cache->get('_' . $cache_name)) === false)
 106          {
 107              $sql = 'SELECT forum_id
 108                  FROM ' . FORUMS_TABLE . '
 109                  WHERE forum_type = ' . FORUM_POST . '
 110                      AND ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_EXCLUDE, '= 0') . '
 111                      AND ' . $this->db->sql_bit_and('forum_flags', log(FORUM_FLAG_ACTIVE_TOPICS, 2), '<> 0');
 112              $result = $this->db->sql_query($sql);
 113  
 114              $forum_ids = array();
 115              while ($forum_id = (int) $this->db->sql_fetchfield('forum_id'))
 116              {
 117                  $forum_ids[$forum_id] = $forum_id;
 118              }
 119              $this->db->sql_freeresult($result);
 120  
 121              $this->cache->put('_' . $cache_name, $forum_ids, 180);
 122          }
 123  
 124          return $forum_ids;
 125      }
 126  
 127  	function adjust_item(&$item_row, &$row)
 128      {
 129          parent::adjust_item($item_row, $row);
 130  
 131          $item_row['title'] = (isset($row['forum_name']) && $row['forum_name'] !== '') ? $row['forum_name'] . ' ' . $this->separator . ' ' . $item_row['title'] : $item_row['title'];
 132      }
 133  }


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