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