1 | <?php |
||
12 | class attachments |
||
13 | { |
||
14 | /** @var \phpbb\auth\auth */ |
||
15 | protected $auth; |
||
16 | |||
17 | /** @var \phpbb\db\driver\driver_interface */ |
||
18 | protected $db; |
||
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * |
||
23 | * @param \phpbb\auth\auth $auth Auth object |
||
24 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
25 | */ |
||
26 | 7 | public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db) |
|
31 | |||
32 | /** |
||
33 | * Get attachments... |
||
34 | * |
||
35 | * @param int $forum_id |
||
36 | * @param array $attach_ids |
||
37 | * @param array $allowed_extensions |
||
38 | * @param int|bool $limit |
||
39 | * @param bool $exclude_in_message |
||
40 | * @param string $order_by |
||
41 | * @return array |
||
42 | */ |
||
43 | 7 | public function get_attachments($forum_id = 0, array $attach_ids = array(), $allowed_extensions = array(), $limit = false, $exclude_in_message = true, $order_by = 'filetime DESC') |
|
44 | { |
||
45 | 7 | $attachments = array(); |
|
46 | 7 | if (!$forum_id || $this->user_can_download_attachments($forum_id)) |
|
47 | 7 | { |
|
48 | 7 | $sql = $this->get_attachment_sql($attach_ids, $allowed_extensions, $exclude_in_message, $order_by); |
|
49 | 7 | $result = $this->db->sql_query_limit($sql, $limit); |
|
50 | |||
51 | 7 | while ($row = $this->db->sql_fetchrow($result)) |
|
52 | { |
||
53 | 7 | $attachments[$row['post_msg_id']][] = $row; |
|
54 | 7 | } |
|
55 | 7 | $this->db->sql_freeresult($result); |
|
56 | 7 | } |
|
57 | |||
58 | 7 | return $attachments; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param int $forum_id |
||
63 | * @return bool |
||
64 | */ |
||
65 | protected function user_can_download_attachments($forum_id) |
||
66 | { |
||
67 | return ($this->auth->acl_get('u_download') && ($this->auth->acl_get('f_download', $forum_id))) ? true : false; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param array $attach_ids |
||
72 | * @param array $allowed_extensions |
||
73 | * @param bool $exclude_in_message |
||
74 | * @param string $order_by |
||
75 | * @return string |
||
76 | */ |
||
77 | 7 | protected function get_attachment_sql(array $attach_ids, array $allowed_extensions, $exclude_in_message, $order_by) |
|
86 | } |
||
87 |