From 0a5d54cc9b4ece668ba59d41a281c147874f3c5c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 16 Nov 2012 17:19:04 +0100 Subject: [feature/avatars] Shorten avatar driver's class name The addition of "core_" that was used until now would require additional avatar drivers (e.g. in extensions) to also include that in their class name which would be incorrect. PHPBB3-10018 --- phpBB/includes/avatar/driver/core/gravatar.php | 140 ------------------ phpBB/includes/avatar/driver/core/local.php | 190 ------------------------- phpBB/includes/avatar/driver/core/remote.php | 163 --------------------- phpBB/includes/avatar/driver/core/upload.php | 147 ------------------- phpBB/includes/avatar/driver/driver.php | 4 +- phpBB/includes/avatar/driver/gravatar.php | 140 ++++++++++++++++++ phpBB/includes/avatar/driver/local.php | 190 +++++++++++++++++++++++++ phpBB/includes/avatar/driver/remote.php | 163 +++++++++++++++++++++ phpBB/includes/avatar/driver/upload.php | 147 +++++++++++++++++++ phpBB/includes/avatar/manager.php | 6 +- 10 files changed, 645 insertions(+), 645 deletions(-) delete mode 100644 phpBB/includes/avatar/driver/core/gravatar.php delete mode 100644 phpBB/includes/avatar/driver/core/local.php delete mode 100644 phpBB/includes/avatar/driver/core/remote.php delete mode 100644 phpBB/includes/avatar/driver/core/upload.php create mode 100644 phpBB/includes/avatar/driver/gravatar.php create mode 100644 phpBB/includes/avatar/driver/local.php create mode 100644 phpBB/includes/avatar/driver/remote.php create mode 100644 phpBB/includes/avatar/driver/upload.php (limited to 'phpBB/includes/avatar') diff --git a/phpBB/includes/avatar/driver/core/gravatar.php b/phpBB/includes/avatar/driver/core/gravatar.php deleted file mode 100644 index 34aa0fa27f..0000000000 --- a/phpBB/includes/avatar/driver/core/gravatar.php +++ /dev/null @@ -1,140 +0,0 @@ -config['allow_avatar_gravatar']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function get_custom_html($row, $ignore_config = false, $alt = '') - { - $html = ''; - return $html; - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - $template->assign_vars(array( - 'AV_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), - 'AV_GRAVATAR_HEIGHT' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), - 'AV_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '', - )); - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - $email = $this->request->variable('av_gravatar_email', ''); - $width = $this->request->variable('av_gravatar_width', 0); - $height = $this->request->variable('av_gravatar_height', 0); - - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); - - $error = array_merge($error, validate_data(array( - 'email' => $email, - ), array( - 'email' => array( - array('string', false, 6, 60), - array('email')), - ))); - - if (!empty($error)) - { - return false; - } - - // Make sure getimagesize works... - if (function_exists('getimagesize')) - { - // build URL - // @todo: add https support - $url = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($email))); - - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - return false; - } - - if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - $width = ($width && $height) ? $width : $image_data[0]; - $height = ($width && $height) ? $height : $image_data[1]; - } - - if ($width <= 0 || $height <= 0) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - return array( - 'avatar' => $email, - 'avatar_width' => $width, - 'avatar_height' => $height, - ); - } -} diff --git a/phpBB/includes/avatar/driver/core/local.php b/phpBB/includes/avatar/driver/core/local.php deleted file mode 100644 index a8ed8ad130..0000000000 --- a/phpBB/includes/avatar/driver/core/local.php +++ /dev/null @@ -1,190 +0,0 @@ -config['allow_avatar_local']) - { - return array( - 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('av_local_cat', ''); - - $categories = array_keys($avatar_list); - - foreach ($categories as $cat) - { - if (!empty($avatar_list[$cat])) - { - $template->assign_block_vars('av_local_cats', array( - 'NAME' => $cat, - 'SELECTED' => ($cat == $category), - )); - } - } - - if (!empty($avatar_list[$category])) - { - $template->assign_vars(array( - 'AV_LOCAL_SHOW' => true, - )); - - $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; - $row_count = $col_count = $av_pos = 0; - $av_count = sizeof($avatar_list[$category]); - - reset($avatar_list[$category]); - - while ($av_pos < $av_count) - { - $img = current($avatar_list[$category]); - next($avatar_list[$category]); - - if ($col_count == 0) - { - ++$row_count; - $template->assign_block_vars('av_local_row', array( - )); - } - - $template->assign_block_vars('av_local_row.av_local_col', array( - 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], - 'AVATAR_NAME' => $img['name'], - 'AVATAR_FILE' => $img['filename'], - )); - - $col_count = ($col_count + 1) % $table_cols; - - ++$av_pos; - } - } - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - $avatar_list = $this->get_avatar_list(); - $category = $this->request->variable('av_local_cat', ''); - - $file = $this->request->variable('av_local_file', ''); - if (!isset($avatar_list[$category][urldecode($file)])) - { - $error[] = 'AVATAR_URL_NOT_FOUND'; - return false; - } - - return array( - 'avatar' => $category . '/' . $file, - 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], - 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], - ); - } - - /** - * @TODO - */ - private function get_avatar_list() - { - $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); - - if (!$avatar_list) - { - $avatar_list = array(); - $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; - - $dh = @opendir($path); - - if ($dh) - { - while (($cat = readdir($dh)) !== false) - { - if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) - { - if ($ch = @opendir("$path/$cat")) - { - while (($image = readdir($ch)) !== false) - { - // Match all images in the gallery folder - if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) - { - if (function_exists('getimagesize')) - { - $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); - } - else - { - $dims = array(0, 0); - } - $avatar_list[$cat][$image] = array( - 'file' => rawurlencode($cat) . '/' . rawurlencode($image), - 'filename' => rawurlencode($image), - 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), - 'width' => $dims[0], - 'height' => $dims[1], - ); - } - } - @closedir($ch); - } - } - } - @closedir($dh); - } - - @ksort($avatar_list); - - if ($this->cache != null) - { - $this->cache->put('av_local_list', $avatar_list); - } - } - - return $avatar_list; - } -} diff --git a/phpBB/includes/avatar/driver/core/remote.php b/phpBB/includes/avatar/driver/core/remote.php deleted file mode 100644 index 8b315b80a8..0000000000 --- a/phpBB/includes/avatar/driver/core/remote.php +++ /dev/null @@ -1,163 +0,0 @@ -config['allow_avatar_remote']) - { - return array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - $template->assign_vars(array( - 'AV_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), - 'AV_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), - 'AV_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '', - )); - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - $url = $this->request->variable('av_remote_url', ''); - $width = $this->request->variable('av_remote_width', 0); - $height = $this->request->variable('av_remote_height', 0); - - if (!preg_match('#^(http|https|ftp)://#i', $url)) - { - $url = 'http://' . $url; - } - - require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); - - $error = array_merge($error, validate_data(array( - 'url' => $url, - ), array( - 'url' => array('string', true, 5, 255), - ))); - - if (!empty($error)) - { - return false; - } - - // Check if this url looks alright - // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible - if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) - { - $error[] = 'AVATAR_URL_INVALID'; - return false; - } - - // Make sure getimagesize works... - if (function_exists('getimagesize')) - { - if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - return false; - } - - if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - $width = ($width && $height) ? $width : $image_data[0]; - $height = ($width && $height) ? $height : $image_data[1]; - } - - if ($width <= 0 || $height <= 0) - { - $error[] = 'AVATAR_NO_SIZE'; - return false; - } - - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); - $types = fileupload::image_types(); - $extension = strtolower(filespec::get_extension($url)); - - if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) - { - if (!isset($types[$image_data[2]])) - { - $error[] = 'UNABLE_GET_IMAGE_SIZE'; - } - else - { - $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); - } - - return false; - } - - if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) - { - if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) - { - $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); - return false; - } - } - - if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) - { - if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) - { - $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); - return false; - } - } - - return array( - 'avatar' => $url, - 'avatar_width' => $width, - 'avatar_height' => $height, - ); - } -} diff --git a/phpBB/includes/avatar/driver/core/upload.php b/phpBB/includes/avatar/driver/core/upload.php deleted file mode 100644 index 1ad1133bff..0000000000 --- a/phpBB/includes/avatar/driver/core/upload.php +++ /dev/null @@ -1,147 +0,0 @@ -config['allow_avatar_upload']) - { - return array( - 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - } - else - { - return array( - 'src' => '', - 'width' => 0, - 'height' => 0, - ); - } - } - - /** - * @inheritdoc - */ - public function prepare_form($template, $row, &$error) - { - if (!$this->can_upload()) - { - return false; - } - - $template->assign_vars(array( - 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, - 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], - )); - - return true; - } - - /** - * @inheritdoc - */ - public function process_form($template, $row, &$error) - { - if (!$this->can_upload()) - { - return false; - } - - include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); - - $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); - - $url = $this->request->variable('av_upload_url', ''); - - if (!empty($_FILES['av_upload_file']['name'])) - { - $file = $upload->form_upload('av_upload_file'); - } - else - { - $file = $upload->remote_upload($url); - } - - $prefix = $this->config['avatar_salt'] . '_'; - $file->clean_filename('avatar', $prefix, $row['id']); - - $destination = $this->config['avatar_path']; - - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } - - // Move file and overwrite any existing image - $file->move_file($destination, true); - - if (sizeof($file->error)) - { - $file->remove(); - $error = array_merge($error, $file->error); - return false; - } - - return array( - 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), - 'avatar_width' => $file->get('width'), - 'avatar_height' => $file->get('height'), - ); - } - - /** - * @inheritdoc - */ - public function delete($row) - { - $ext = substr(strrchr($row['avatar'], '.'), 1); - $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext; - - if (file_exists($filename)) - { - @unlink($filename); - } - - return true; - } - - /** - * @TODO - */ - private function can_upload() - { - return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); - } -} diff --git a/phpBB/includes/avatar/driver/driver.php b/phpBB/includes/avatar/driver/driver.php index cce0a8db0f..9a213ce730 100644 --- a/phpBB/includes/avatar/driver/driver.php +++ b/phpBB/includes/avatar/driver/driver.php @@ -147,7 +147,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface **/ public function is_enabled() { - $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); return $this->config["allow_avatar_$driver"]; } @@ -157,7 +157,7 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface **/ public function get_template_name() { - $driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this)); + $driver = preg_replace('#^phpbb_avatar_driver_#', '', get_class($this)); $template = "ucp_avatar_options_$driver.html"; return $template; diff --git a/phpBB/includes/avatar/driver/gravatar.php b/phpBB/includes/avatar/driver/gravatar.php new file mode 100644 index 0000000000..0ac7d71bef --- /dev/null +++ b/phpBB/includes/avatar/driver/gravatar.php @@ -0,0 +1,140 @@ +config['allow_avatar_gravatar']) + { + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function get_custom_html($row, $ignore_config = false, $alt = '') + { + $html = ''; + return $html; + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + $template->assign_vars(array( + 'AV_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_GRAVATAR_HEIGHT' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), + 'AV_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '', + )); + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + $email = $this->request->variable('av_gravatar_email', ''); + $width = $this->request->variable('av_gravatar_width', 0); + $height = $this->request->variable('av_gravatar_height', 0); + + require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); + + $error = array_merge($error, validate_data(array( + 'email' => $email, + ), array( + 'email' => array( + array('string', false, 6, 60), + array('email')), + ))); + + if (!empty($error)) + { + return false; + } + + // Make sure getimagesize works... + if (function_exists('getimagesize')) + { + // build URL + // @todo: add https support + $url = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($email))); + + if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + return false; + } + + if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + $width = ($width && $height) ? $width : $image_data[0]; + $height = ($width && $height) ? $height : $image_data[1]; + } + + if ($width <= 0 || $height <= 0) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + return array( + 'avatar' => $email, + 'avatar_width' => $width, + 'avatar_height' => $height, + ); + } +} diff --git a/phpBB/includes/avatar/driver/local.php b/phpBB/includes/avatar/driver/local.php new file mode 100644 index 0000000000..e4648381c2 --- /dev/null +++ b/phpBB/includes/avatar/driver/local.php @@ -0,0 +1,190 @@ +config['allow_avatar_local']) + { + return array( + 'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = $this->request->variable('av_local_cat', ''); + + $categories = array_keys($avatar_list); + + foreach ($categories as $cat) + { + if (!empty($avatar_list[$cat])) + { + $template->assign_block_vars('av_local_cats', array( + 'NAME' => $cat, + 'SELECTED' => ($cat == $category), + )); + } + } + + if (!empty($avatar_list[$category])) + { + $template->assign_vars(array( + 'AV_LOCAL_SHOW' => true, + )); + + $table_cols = isset($row['av_gallery_cols']) ? $row['av_gallery_cols'] : 4; + $row_count = $col_count = $av_pos = 0; + $av_count = sizeof($avatar_list[$category]); + + reset($avatar_list[$category]); + + while ($av_pos < $av_count) + { + $img = current($avatar_list[$category]); + next($avatar_list[$category]); + + if ($col_count == 0) + { + ++$row_count; + $template->assign_block_vars('av_local_row', array( + )); + } + + $template->assign_block_vars('av_local_row.av_local_col', array( + 'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $img['file'], + 'AVATAR_NAME' => $img['name'], + 'AVATAR_FILE' => $img['filename'], + )); + + $col_count = ($col_count + 1) % $table_cols; + + ++$av_pos; + } + } + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + $avatar_list = $this->get_avatar_list(); + $category = $this->request->variable('av_local_cat', ''); + + $file = $this->request->variable('av_local_file', ''); + if (!isset($avatar_list[$category][urldecode($file)])) + { + $error[] = 'AVATAR_URL_NOT_FOUND'; + return false; + } + + return array( + 'avatar' => $category . '/' . $file, + 'avatar_width' => $avatar_list[$category][urldecode($file)]['width'], + 'avatar_height' => $avatar_list[$category][urldecode($file)]['height'], + ); + } + + /** + * @TODO + */ + private function get_avatar_list() + { + $avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list'); + + if (!$avatar_list) + { + $avatar_list = array(); + $path = $this->phpbb_root_path . $this->config['avatar_gallery_path']; + + $dh = @opendir($path); + + if ($dh) + { + while (($cat = readdir($dh)) !== false) + { + if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat")) + { + if ($ch = @opendir("$path/$cat")) + { + while (($image = readdir($ch)) !== false) + { + // Match all images in the gallery folder + if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image)) + { + if (function_exists('getimagesize')) + { + $dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image); + } + else + { + $dims = array(0, 0); + } + $avatar_list[$cat][$image] = array( + 'file' => rawurlencode($cat) . '/' . rawurlencode($image), + 'filename' => rawurlencode($image), + 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))), + 'width' => $dims[0], + 'height' => $dims[1], + ); + } + } + @closedir($ch); + } + } + } + @closedir($dh); + } + + @ksort($avatar_list); + + if ($this->cache != null) + { + $this->cache->put('av_local_list', $avatar_list); + } + } + + return $avatar_list; + } +} diff --git a/phpBB/includes/avatar/driver/remote.php b/phpBB/includes/avatar/driver/remote.php new file mode 100644 index 0000000000..fbe158d200 --- /dev/null +++ b/phpBB/includes/avatar/driver/remote.php @@ -0,0 +1,163 @@ +config['allow_avatar_remote']) + { + return array( + 'src' => $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + $template->assign_vars(array( + 'AV_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), + 'AV_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '', + )); + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + $url = $this->request->variable('av_remote_url', ''); + $width = $this->request->variable('av_remote_width', 0); + $height = $this->request->variable('av_remote_height', 0); + + if (!preg_match('#^(http|https|ftp)://#i', $url)) + { + $url = 'http://' . $url; + } + + require_once($this->phpbb_root_path . 'includes/functions_user' . $this->phpEx); + + $error = array_merge($error, validate_data(array( + 'url' => $url, + ), array( + 'url' => array('string', true, 5, 255), + ))); + + if (!empty($error)) + { + return false; + } + + // Check if this url looks alright + // This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible + if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $url)) + { + $error[] = 'AVATAR_URL_INVALID'; + return false; + } + + // Make sure getimagesize works... + if (function_exists('getimagesize')) + { + if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false)) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + return false; + } + + if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0)) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + $width = ($width && $height) ? $width : $image_data[0]; + $height = ($width && $height) ? $height : $image_data[1]; + } + + if ($width <= 0 || $height <= 0) + { + $error[] = 'AVATAR_NO_SIZE'; + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); + $types = fileupload::image_types(); + $extension = strtolower(filespec::get_extension($url)); + + if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) + { + if (!isset($types[$image_data[2]])) + { + $error[] = 'UNABLE_GET_IMAGE_SIZE'; + } + else + { + $error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension); + } + + return false; + } + + if ($this->config['avatar_max_width'] || $this->config['avatar_max_height']) + { + if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height']) + { + $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); + return false; + } + } + + if ($this->config['avatar_min_width'] || $this->config['avatar_min_height']) + { + if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height']) + { + $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height); + return false; + } + } + + return array( + 'avatar' => $url, + 'avatar_width' => $width, + 'avatar_height' => $height, + ); + } +} diff --git a/phpBB/includes/avatar/driver/upload.php b/phpBB/includes/avatar/driver/upload.php new file mode 100644 index 0000000000..a86cc44d2f --- /dev/null +++ b/phpBB/includes/avatar/driver/upload.php @@ -0,0 +1,147 @@ +config['allow_avatar_upload']) + { + return array( + 'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'], + 'width' => $row['avatar_width'], + 'height' => $row['avatar_height'], + ); + } + else + { + return array( + 'src' => '', + 'width' => 0, + 'height' => 0, + ); + } + } + + /** + * @inheritdoc + */ + public function prepare_form($template, $row, &$error) + { + if (!$this->can_upload()) + { + return false; + } + + $template->assign_vars(array( + 'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false, + 'AV_UPLOAD_SIZE' => $this->config['avatar_filesize'], + )); + + return true; + } + + /** + * @inheritdoc + */ + public function process_form($template, $row, &$error) + { + if (!$this->can_upload()) + { + return false; + } + + include_once($this->phpbb_root_path . 'includes/functions_upload' . $this->phpEx); + + $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); + + $url = $this->request->variable('av_upload_url', ''); + + if (!empty($_FILES['av_upload_file']['name'])) + { + $file = $upload->form_upload('av_upload_file'); + } + else + { + $file = $upload->remote_upload($url); + } + + $prefix = $this->config['avatar_salt'] . '_'; + $file->clean_filename('avatar', $prefix, $row['id']); + + $destination = $this->config['avatar_path']; + + // Adjust destination path (no trailing slash) + if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') + { + $destination = substr($destination, 0, -1); + } + + $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); + if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) + { + $destination = ''; + } + + // Move file and overwrite any existing image + $file->move_file($destination, true); + + if (sizeof($file->error)) + { + $file->remove(); + $error = array_merge($error, $file->error); + return false; + } + + return array( + 'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'), + 'avatar_width' => $file->get('width'), + 'avatar_height' => $file->get('height'), + ); + } + + /** + * @inheritdoc + */ + public function delete($row) + { + $ext = substr(strrchr($row['avatar'], '.'), 1); + $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext; + + if (file_exists($filename)) + { + @unlink($filename); + } + + return true; + } + + /** + * @TODO + */ + private function can_upload() + { + return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); + } +} diff --git a/phpBB/includes/avatar/manager.php b/phpBB/includes/avatar/manager.php index 4256188f0a..546cdcdc05 100644 --- a/phpBB/includes/avatar/manager.php +++ b/phpBB/includes/avatar/manager.php @@ -57,13 +57,13 @@ class phpbb_avatar_manager switch ($avatar_type) { case AVATAR_GALLERY: - $avatar_type = 'avatar.driver.core.local'; + $avatar_type = 'avatar.driver.local'; break; case AVATAR_UPLOAD: - $avatar_type = 'avatar.driver.core.upload'; + $avatar_type = 'avatar.driver.upload'; break; case AVATAR_REMOTE: - $avatar_type = 'avatar.driver.core.remote'; + $avatar_type = 'avatar.driver.remote'; break; } -- cgit v1.2.1