[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/feed/ -> attachments_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  * Abstract class for feeds displaying attachments
  18  */
  19  abstract class attachments_base extends base
  20  {
  21      /**
  22      * Attachments that may be displayed
  23      */
  24      protected $attachments = array();
  25  
  26      /**
  27      * Retrieve the list of attachments that may be displayed
  28      *
  29      * @param array $post_ids Specify for which post IDs to fetch the attachments (optional)
  30      * @param array $topic_ids Specify for which topic IDs to fetch the attachments (optional)
  31      */
  32  	protected function fetch_attachments($post_ids = array(), $topic_ids = array())
  33      {
  34          $sql_array = array(
  35              'SELECT'   => 'a.*',
  36              'FROM'     => array(
  37                  ATTACHMENTS_TABLE => 'a'
  38              ),
  39              'WHERE'    => 'a.in_message = 0 ',
  40              'ORDER_BY' => 'a.filetime DESC, a.post_msg_id ASC',
  41          );
  42  
  43          if (!empty($post_ids))
  44          {
  45              $sql_array['WHERE'] .= 'AND ' . $this->db->sql_in_set('a.post_msg_id', $post_ids);
  46          }
  47          else if (!empty($topic_ids))
  48          {
  49              if (isset($this->topic_id))
  50              {
  51                  $topic_ids[] = $this->topic_id;
  52              }
  53  
  54              $sql_array['WHERE'] .= 'AND ' . $this->db->sql_in_set('a.topic_id', $topic_ids);
  55          }
  56          else if (isset($this->topic_id))
  57          {
  58              $sql_array['WHERE'] .= 'AND a.topic_id = ' . (int) $this->topic_id;
  59          }
  60          else if (isset($this->forum_id))
  61          {
  62              $sql_array['LEFT_JOIN'] = array(
  63                  array(
  64                      'FROM' => array(TOPICS_TABLE => 't'),
  65                      'ON'   => 'a.topic_id = t.topic_id',
  66                  )
  67              );
  68              $sql_array['WHERE'] .= 'AND t.forum_id = ' . (int) $this->forum_id;
  69          }
  70          else
  71          {
  72              // Do not allow querying the full attachments table
  73              throw new \RuntimeException($this->user->lang('INVALID_FEED_ATTACHMENTS'));
  74          }
  75  
  76          $sql = $this->db->sql_build_query('SELECT', $sql_array);
  77          $result = $this->db->sql_query($sql);
  78  
  79          // Set attachments in feed items
  80          while ($row = $this->db->sql_fetchrow($result))
  81          {
  82              $this->attachments[$row['post_msg_id']][] = $row;
  83          }
  84          $this->db->sql_freeresult($result);
  85      }
  86  
  87      /**
  88      * Get attachments related to a given post
  89      *
  90      * @param $post_id  int  Post id
  91      * @return mixed Attachments related to $post_id
  92      */
  93  	public function get_attachments($post_id)
  94      {
  95          return $this->attachments[$post_id];
  96      }
  97  }


Generated: Sat Oct 26 11:28:42 2019 Cross-referenced by PHPXref 0.7.1