Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ucp_attachments.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 9.23 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  /**
023  * ucp_attachments
024  * User attachments
025  */
026  class ucp_attachments
027  {
028      var $u_action;
029   
030      function main($id, $mode)
031      {
032          global $template, $user, $db, $config, $phpEx, $phpbb_root_path, $phpbb_container, $request, $auth;
033   
034          $start        = $request->variable('start', 0);
035          $sort_key    = $request->variable('sk', 'a');
036          $sort_dir    = $request->variable('sd', 'a');
037   
038          $delete        = (isset($_POST['delete'])) ? true : false;
039          $delete_ids    = array_keys($request->variable('attachment', array(0)));
040   
041          if ($delete && count($delete_ids))
042          {
043              // Validate $delete_ids...
044              $sql = 'SELECT a.attach_id, a.in_message, p.post_edit_locked, p.post_time, t.topic_status, f.forum_id, f.forum_status, pt.folder_id
045                  FROM ' . ATTACHMENTS_TABLE . ' a
046                  LEFT JOIN ' . POSTS_TABLE . ' p
047                      ON (a.post_msg_id = p.post_id AND a.in_message = 0)
048                  LEFT JOIN ' . TOPICS_TABLE . ' t
049                      ON (t.topic_id = p.topic_id AND a.in_message = 0)
050                  LEFT JOIN ' . FORUMS_TABLE . ' f
051                      ON (f.forum_id = t.forum_id AND a.in_message = 0)
052                  LEFT JOIN ' . PRIVMSGS_TABLE . ' pr
053                      ON (a.post_msg_id = pr.msg_id AND a.in_message = 1)
054                  LEFT JOIN ' . PRIVMSGS_TO_TABLE . ' pt
055                      ON (a.post_msg_id = pt.msg_id AND a.poster_id = pt.author_id AND a.poster_id = pt.user_id AND a.in_message = 1)
056                  WHERE a.poster_id = ' . $user->data['user_id'] . '
057                      AND a.is_orphan = 0
058                      AND ' . $db->sql_in_set('a.attach_id', $delete_ids);
059              $result = $db->sql_query($sql);
060   
061              $delete_ids = array();
062              while ($row = $db->sql_fetchrow($result))
063              {
064                  if (!$this->can_delete_file($row))
065                  {
066                      continue;
067                  }
068   
069                  $delete_ids[] = $row['attach_id'];
070              }
071              $db->sql_freeresult($result);
072          }
073   
074          if ($delete && count($delete_ids))
075          {
076              $s_hidden_fields = array(
077                  'delete'    => 1
078              );
079   
080              foreach ($delete_ids as $attachment_id)
081              {
082                  $s_hidden_fields['attachment'][$attachment_id] = 1;
083              }
084   
085              if (confirm_box(true))
086              {
087                  /** @var \phpbb\attachment\manager $attachment_manager */
088                  $attachment_manager = $phpbb_container->get('attachment.manager');
089                  $attachment_manager->delete('attach', $delete_ids);
090                  unset($attachment_manager);
091   
092                  meta_refresh(3, $this->u_action);
093                  $message = ((count($delete_ids) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']) . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
094                  trigger_error($message);
095              }
096              else
097              {
098                  confirm_box(false, (count($delete_ids) == 1) ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
099              }
100          }
101   
102          // Select box eventually
103          $sort_key_text = array('a' => $user->lang['SORT_FILENAME'], 'b' => $user->lang['SORT_COMMENT'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
104          $sort_key_sql = array('a' => 'a.real_filename', 'b' => 'a.attach_comment', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
105   
106          $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
107   
108          $s_sort_key = '';
109          foreach ($sort_key_text as $key => $value)
110          {
111              $selected = ($sort_key == $key) ? ' selected="selected"' : '';
112              $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
113          }
114   
115          $s_sort_dir = '';
116          foreach ($sort_dir_text as $key => $value)
117          {
118              $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
119              $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
120          }
121   
122          if (!isset($sort_key_sql[$sort_key]))
123          {
124              $sort_key = 'a';
125          }
126   
127          $order_by = $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
128   
129          $sql = 'SELECT COUNT(attach_id) as num_attachments
130              FROM ' . ATTACHMENTS_TABLE . '
131              WHERE poster_id = ' . $user->data['user_id'] . '
132                  AND is_orphan = 0';
133          $result = $db->sql_query($sql);
134          $num_attachments = $db->sql_fetchfield('num_attachments');
135          $db->sql_freeresult($result);
136   
137          // Ensure start is a valid value
138          /* @var $pagination \phpbb\pagination */
139          $pagination = $phpbb_container->get('pagination');
140          $start = $pagination->validate_start($start, $config['topics_per_page'], $num_attachments);
141   
142          $sql = 'SELECT a.*, t.topic_title, pr.message_subject as message_title, pr.message_time as message_time, pt.folder_id, p.post_edit_locked, p.post_time, t.topic_status, f.forum_id, f.forum_status
143              FROM ' . ATTACHMENTS_TABLE . ' a
144                  LEFT JOIN ' . POSTS_TABLE . ' p ON (a.post_msg_id = p.post_id AND a.in_message = 0)
145                  LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
146                  LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id AND a.in_message = 0)
147                  LEFT JOIN ' . PRIVMSGS_TABLE . ' pr ON (a.post_msg_id = pr.msg_id AND a.in_message = 1)
148                  LEFT JOIN ' . PRIVMSGS_TO_TABLE . ' pt ON (a.post_msg_id = pt.msg_id AND a.poster_id = pt.author_id AND a.poster_id = pt.user_id AND a.in_message = 1)
149              WHERE a.poster_id = ' . $user->data['user_id'] . "
150                  AND a.is_orphan = 0
151              ORDER BY $order_by";
152          $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
153   
154          $row_count = 0;
155          if ($row = $db->sql_fetchrow($result))
156          {
157              $template->assign_var('S_ATTACHMENT_ROWS', true);
158   
159              do
160              {
161                  if ($row['in_message'])
162                  {
163                      $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
164                  }
165                  else
166                  {
167                      $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
168                  }
169   
170                  $template->assign_block_vars('attachrow', array(
171                      'ROW_NUMBER'        => $row_count + ($start + 1),
172                      'FILENAME'            => $row['real_filename'],
173                      'COMMENT'            => bbcode_nl2br($row['attach_comment']),
174                      'EXTENSION'            => $row['extension'],
175                      'SIZE'                => get_formatted_filesize($row['filesize']),
176                      'DOWNLOAD_COUNT'    => $row['download_count'],
177                      'POST_TIME'            => $user->format_date($row['filetime']),
178                      'TOPIC_TITLE'        => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
179   
180                      'ATTACH_ID'            => $row['attach_id'],
181                      'POST_ID'            => $row['post_msg_id'],
182                      'TOPIC_ID'            => $row['topic_id'],
183   
184                      'S_IN_MESSAGE'        => $row['in_message'],
185                      'S_LOCKED'            => !$this->can_delete_file($row),
186   
187                      'U_VIEW_ATTACHMENT'    => append_sid("{$phpbb_root_path}download/file.$phpEx", 'id=' . $row['attach_id']),
188                      'U_VIEW_TOPIC'        => $view_topic)
189                  );
190   
191                  $row_count++;
192              }
193              while ($row = $db->sql_fetchrow($result));
194          }
195          $db->sql_freeresult($result);
196   
197          $base_url = $this->u_action . "&amp;sk=$sort_key&amp;sd=$sort_dir";
198          $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
199   
200          $template->assign_vars(array(
201              'TOTAL_ATTACHMENTS'        => $num_attachments,
202              'NUM_ATTACHMENTS'        => $user->lang('NUM_ATTACHMENTS', (int) $num_attachments),
203   
204              'L_TITLE'                => $user->lang['UCP_ATTACHMENTS'],
205   
206              'U_SORT_FILENAME'        => $this->u_action . "&amp;sk=a&amp;sd=" . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
207              'U_SORT_FILE_COMMENT'    => $this->u_action . "&amp;sk=b&amp;sd=" . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
208              'U_SORT_EXTENSION'        => $this->u_action . "&amp;sk=c&amp;sd=" . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
209              'U_SORT_FILESIZE'        => $this->u_action . "&amp;sk=d&amp;sd=" . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
210              'U_SORT_DOWNLOADS'        => $this->u_action . "&amp;sk=e&amp;sd=" . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
211              'U_SORT_POST_TIME'        => $this->u_action . "&amp;sk=f&amp;sd=" . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
212              'U_SORT_TOPIC_TITLE'    => $this->u_action . "&amp;sk=g&amp;sd=" . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
213   
214              'S_DISPLAY_MARK_ALL'    => ($num_attachments) ? true : false,
215              'S_DISPLAY_PAGINATION'    => ($num_attachments) ? true : false,
216              'S_UCP_ACTION'            => $this->u_action,
217              'S_SORT_OPTIONS'         => $s_sort_key,
218              'S_ORDER_SELECT'        => $s_sort_dir)
219          );
220   
221          $this->tpl_name = 'ucp_attachments';
222          $this->page_title = 'UCP_ATTACHMENTS';
223      }
224   
225      /**
226       * Check if the user can delete the file
227       *
228       * @param array $row
229       *
230       * @return bool True if user can delete the file, false if not
231       */
232      private function can_delete_file(array $row): bool
233      {
234          global $auth, $config;
235   
236          if ($row['in_message'])
237          {
238              return ($row['message_time'] > (time() - ($config['pm_edit_time'] * 60)) || !$config['pm_edit_time']) && $row['folder_id'] == PRIVMSGS_OUTBOX && $auth->acl_get('u_pm_edit');
239          }
240          else
241          {
242              $can_edit_time = !$config['edit_time'] || $row['post_time'] > (time() - ($config['edit_time'] * 60));
243              $can_delete_time = !$config['delete_time'] || $row['post_time'] > (time() - ($config['delete_time'] * 60));
244              $item_locked = !$auth->acl_get('m_edit', $row['forum_id']) && ($row['forum_status'] == ITEM_LOCKED || $row['topic_status'] == ITEM_LOCKED || $row['post_edit_locked']);
245   
246              return !$item_locked && $can_edit_time && $can_delete_time;
247          }
248      }
249  }
250