From b91702665a2ad555a172d09429d9beaac7ba88a7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 13 Nov 2012 20:06:44 +0100 Subject: [PATCH] [feature/avatars] Add barebone gravatar driver PHPBB3-10018 --- .../includes/avatar/driver/core/gravatar.php | 148 ++++++++++++++++++ .../template/ucp_avatar_options_gravatar.html | 11 ++ 2 files changed, 159 insertions(+) create mode 100644 phpBB/includes/avatar/driver/core/gravatar.php create mode 100644 phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html diff --git a/phpBB/includes/avatar/driver/core/gravatar.php b/phpBB/includes/avatar/driver/core/gravatar.php new file mode 100644 index 0000000000..a9e4d6c491 --- /dev/null +++ b/phpBB/includes/avatar/driver/core/gravatar.php @@ -0,0 +1,148 @@ +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'] == __CLASS__ || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $this->request->variable('av_local_width', 0), + 'AV_GRAVATAR_HEIGHT' => (($row['avatar_type'] == __CLASS__ || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $this->request->variable('av_local_width', 0), + 'AV_GRAVATAR_EMAIL' => (($row['avatar_type'] == __CLASS__ || $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); + var_dump($width, $height); + + /* + if (!preg_match('#^(http|https|ftp)://#i', $email)) + { + $url = 'http://' . $url; + }*/ + // @todo: check if we need to check emails + + 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/styles/prosilver/template/ucp_avatar_options_gravatar.html b/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html new file mode 100644 index 0000000000..c0bae47162 --- /dev/null +++ b/phpBB/styles/prosilver/template/ucp_avatar_options_gravatar.html @@ -0,0 +1,11 @@ +
+

{L_EMAIL_GRAVATAR_AVATAR_EXPLAIN}
+
+
+
+

{L_GRAVATAR_AVATAR_EXPLAIN}
+
+ ×  + +
+