Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

local.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.13 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  namespace phpbb\avatar\driver;
 015   
 016  /**
 017  * Handles avatars selected from the board gallery
 018  */
 019  class local extends \phpbb\avatar\driver\driver
 020  {
 021      /**
 022      * {@inheritdoc}
 023      */
 024      public function get_data($row)
 025      {
 026          return array(
 027              'src' => $this->path_helper->get_web_root_path() . $this->config['avatar_gallery_path'] . '/' . $row['avatar'],
 028              'width' => $row['avatar_width'],
 029              'height' => $row['avatar_height'],
 030          );
 031      }
 032   
 033      /**
 034      * {@inheritdoc}
 035      */
 036      public function prepare_form($request, $template, $user, $row, &$error)
 037      {
 038          $avatar_list = $this->get_avatar_list($user);
 039          $category = $request->variable('avatar_local_cat', key($avatar_list));
 040   
 041          foreach ($avatar_list as $cat => $null)
 042          {
 043              if (!empty($avatar_list[$cat]))
 044              {
 045                  $template->assign_block_vars('avatar_local_cats', array(
 046                      'NAME' => $cat,
 047                      'SELECTED' => ($cat == $category),
 048                  ));
 049              }
 050   
 051              if ($cat != $category)
 052              {
 053                  unset($avatar_list[$cat]);
 054              }
 055          }
 056   
 057          if (!empty($avatar_list[$category]))
 058          {
 059              $template->assign_vars(array(
 060                  'AVATAR_LOCAL_SHOW' => true,
 061              ));
 062   
 063              $table_cols = isset($row['avatar_gallery_cols']) ? $row['avatar_gallery_cols'] : 4;
 064              $row_count = $col_count = $avatar_pos = 0;
 065              $avatar_count = sizeof($avatar_list[$category]);
 066   
 067              reset($avatar_list[$category]);
 068   
 069              while ($avatar_pos < $avatar_count)
 070              {
 071                  $img = current($avatar_list[$category]);
 072                  next($avatar_list[$category]);
 073   
 074                  if ($col_count == 0)
 075                  {
 076                      ++$row_count;
 077                      $template->assign_block_vars('avatar_local_row', array(
 078                      ));
 079                  }
 080   
 081                  $template->assign_block_vars('avatar_local_row.avatar_local_col', array(
 082                      'AVATAR_IMAGE'  => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'],
 083                      'AVATAR_NAME'     => $img['name'],
 084                      'AVATAR_FILE'     => $img['filename'],
 085                  ));
 086   
 087                  $template->assign_block_vars('avatar_local_row.avatar_local_option', array(
 088                      'AVATAR_FILE'         => $img['filename'],
 089                      'S_OPTIONS_AVATAR'    => $img['filename']
 090                  ));
 091   
 092                  $col_count = ($col_count + 1) % $table_cols;
 093   
 094                  ++$avatar_pos;
 095              }
 096          }
 097   
 098          return true;
 099      }
 100   
 101      /**
 102      * {@inheritdoc}
 103      */
 104      public function prepare_form_acp($user)
 105      {
 106          return array(
 107              'avatar_gallery_path'    => array('lang' => 'AVATAR_GALLERY_PATH',    'validate' => 'rpath',    'type' => 'text:20:255', 'explain' => true),
 108          );
 109      }
 110   
 111      /**
 112      * {@inheritdoc}
 113      */
 114      public function process_form($request, $template, $user, $row, &$error)
 115      {
 116          $avatar_list = $this->get_avatar_list($user);
 117          $category = $request->variable('avatar_local_cat', '');
 118   
 119          $file = $request->variable('avatar_local_file', '');
 120   
 121          if (empty($category) || empty($file))
 122          {
 123              return false;
 124          }
 125   
 126          if (!isset($avatar_list[$category][urldecode($file)]))
 127          {
 128              $error[] = 'AVATAR_URL_NOT_FOUND';
 129              return false;
 130          }
 131   
 132          return array(
 133              'avatar' => ($category != $user->lang['NO_AVATAR_CATEGORY']) ? $category . '/' . $file : $file,
 134              'avatar_width' => $avatar_list[$category][urldecode($file)]['width'],
 135              'avatar_height' => $avatar_list[$category][urldecode($file)]['height'],
 136          );
 137      }
 138   
 139      /**
 140      * {@inheritdoc}
 141      */
 142      public function get_template_name()
 143      {
 144          return 'ucp_avatar_options_local.html';
 145      }
 146   
 147      /**
 148      * Get a list of avatars that are locally available
 149      * Results get cached for 24 hours (86400 seconds)
 150      *
 151      * @param \phpbb\user $user User object
 152      *
 153      * @return array Array containing the locally available avatars
 154      */
 155      protected function get_avatar_list($user)
 156      {
 157          $avatar_list = ($this->cache == null) ? false : $this->cache->get('_avatar_local_list');
 158   
 159          if ($avatar_list === false)
 160          {
 161              $avatar_list = array();
 162              $path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
 163   
 164              $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS), \RecursiveIteratorIterator::SELF_FIRST);
 165              foreach ($iterator as $file_info)
 166              {
 167                  $file_path = $file_info->getPath();
 168                  $image = $file_info->getFilename();
 169   
 170                  // Match all images in the gallery folder
 171                  if (preg_match('#^[^&\'"<>]+\.(?:' . implode('|', $this->allowed_extensions) . ')$#i', $image) && is_file($file_path . '/' . $image))
 172                  {
 173                      if (function_exists('getimagesize'))
 174                      {
 175                          $dims = getimagesize($file_path . '/' . $image);
 176                      }
 177                      else
 178                      {
 179                          $dims = array(0, 0);
 180                      }
 181                      $cat = ($path == $file_path) ? $user->lang['NO_AVATAR_CATEGORY'] : str_replace("$path/", '', $file_path);
 182                      $avatar_list[$cat][$image] = array(
 183                          'file'      => ($cat != $user->lang['NO_AVATAR_CATEGORY']) ? rawurlencode($cat) . '/' . rawurlencode($image) : rawurlencode($image),
 184                          'filename'  => rawurlencode($image),
 185                          'name'      => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
 186                          'width'     => $dims[0],
 187                          'height'    => $dims[1],
 188                      );
 189                  }
 190              }
 191              ksort($avatar_list);
 192   
 193              if ($this->cache != null)
 194              {
 195                  $this->cache->put('_avatar_local_list', $avatar_list, 86400);
 196              }
 197          }
 198   
 199          return $avatar_list;
 200      }
 201  }
 202