[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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\avatar\driver; 15 16 /** 17 * Handles avatars selected from the board gallery 18 */ 19 class local extends \phpbb\avatar\driver\driver 20 { 21 /** 22 * {@inheritdoc} 23 */ 24 public function get_data($row) 25 { 26 $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $this->path_helper->get_web_root_path(); 27 28 return array( 29 'src' => $root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], 30 'width' => $row['avatar_width'], 31 'height' => $row['avatar_height'], 32 ); 33 } 34 35 /** 36 * {@inheritdoc} 37 */ 38 public function prepare_form($request, $template, $user, $row, &$error) 39 { 40 $avatar_list = $this->get_avatar_list($user); 41 $category = $request->variable('avatar_local_cat', key($avatar_list)); 42 43 foreach ($avatar_list as $cat => $null) 44 { 45 if (!empty($avatar_list[$cat])) 46 { 47 $template->assign_block_vars('avatar_local_cats', array( 48 'NAME' => $cat, 49 'SELECTED' => ($cat == $category), 50 )); 51 } 52 53 if ($cat != $category) 54 { 55 unset($avatar_list[$cat]); 56 } 57 } 58 59 if (!empty($avatar_list[$category])) 60 { 61 $template->assign_vars(array( 62 'AVATAR_LOCAL_SHOW' => true, 63 )); 64 65 $table_cols = isset($row['avatar_gallery_cols']) ? $row['avatar_gallery_cols'] : 4; 66 $row_count = $col_count = $avatar_pos = 0; 67 $avatar_count = sizeof($avatar_list[$category]); 68 69 reset($avatar_list[$category]); 70 71 while ($avatar_pos < $avatar_count) 72 { 73 $img = current($avatar_list[$category]); 74 next($avatar_list[$category]); 75 76 if ($col_count == 0) 77 { 78 ++$row_count; 79 $template->assign_block_vars('avatar_local_row', array( 80 )); 81 } 82 83 $template->assign_block_vars('avatar_local_row.avatar_local_col', array( 84 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], 85 'AVATAR_NAME' => $img['name'], 86 'AVATAR_FILE' => $img['filename'], 87 'CHECKED' => $img['file'] === $row['avatar'], 88 )); 89 90 $template->assign_block_vars('avatar_local_row.avatar_local_option', array( 91 'AVATAR_FILE' => $img['filename'], 92 'S_OPTIONS_AVATAR' => $img['filename'], 93 'CHECKED' => $img['file'] === $row['avatar'], 94 )); 95 96 $col_count = ($col_count + 1) % $table_cols; 97 98 ++$avatar_pos; 99 } 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 if (function_exists('getimagesize')) 178 { 179 $dims = getimagesize($file_path . '/' . $image); 180 } 181 else 182 { 183 $dims = array(0, 0); 184 } 185 $cat = ($path == $file_path) ? $user->lang['NO_AVATAR_CATEGORY'] : str_replace("$path/", '', $file_path); 186 $avatar_list[$cat][$image] = array( 187 'file' => ($cat != $user->lang['NO_AVATAR_CATEGORY']) ? str_replace('%2F', '/', rawurlencode($cat)) . '/' . rawurlencode($image) : rawurlencode($image), 188 'filename' => rawurlencode($image), 189 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), 190 'width' => $dims[0], 191 'height' => $dims[1], 192 ); 193 } 194 } 195 ksort($avatar_list); 196 197 if ($this->cache != null) 198 { 199 $this->cache->put('_avatar_local_list', $avatar_list, 86400); 200 } 201 } 202 203 return $avatar_list; 204 } 205 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |