XOOPS  2.6.0
GravatarsProvider.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
14 
27 {
37  private static function getGravatar($email)
38  {
39  $s = 80; // Size in pixels, defaults to 80px [ 1 - 2048 ]
40  $d = 'mm'; // Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
41  $r = 'g'; // Maximum rating (inclusive) [ g | pg | r | x ]
42  if ($helper = Xoops\Module\Helper::getHelper('gravatars')) {
43  $v = $helper->getConfig('pixel_size');
44  $s = (empty($v)) ? $s : $v;
45  $v = $helper->getConfig('default_imageset');
46  $d = (empty($v)) ? $d : $v;
47  $d = ($d=='default') ? '' : $d; // preferences does not like empty string
48  $v = $helper->getConfig('max_rating');
49  $r = (empty($v)) ? $r : $v;
50  }
51 
52  $scheme = \Xoops\Core\HttpRequest::getInstance()->getScheme();
53  if ($scheme == 'https') {
54  $url = 'https://secure.gravatar.com/avatar/';
55  } else {
56  $url = 'http://www.gravatar.com/avatar/';
57  }
58  $url .= md5(strtolower(trim($email)));
59  $url .= "?s=$s&d=$d&r=$r";
60 
61  return $url;
62  }
63 
71  private function getUserById($uid)
72  {
73  $user = \Xoops::getInstance()->getHandlerMember()->getUser((int) $uid);
74  return (is_object($user)) ? $user : null;
75  }
76 
83  public function getName()
84  {
85  return 'gravatars';
86  }
87 
93  public function getDescription()
94  {
95  return 'Use gravatar.com for system avatars.';
96  }
97 
108  public function getAvatarUrl($response, $userinfo)
109  {
110  $noInfo = true;
111  if (is_object($userinfo)) {
112  if (is_a($userinfo, 'XoopsUser')) {
113  $email = $userinfo->getVar('email', 'e');
114  $response->setValue(self::getGravatar($email));
115  $noInfo = false;
116  }
117  } elseif (is_array($userinfo)) {
118  if (!empty($userinfo['email'])) {
119  $response->setValue(self::getGravatar($userinfo['email']));
120  $noInfo = false;
121  }
122  } elseif (is_scalar($userinfo)) {
123  $user = $this->getUserById((int) $userinfo);
124  if (is_object($user) && is_a($user, 'XoopsUser')) {
125  $email = $user->getVar('email', 'e');
126  $response->setValue(self::getGravatar($email));
127  $noInfo = false;
128  }
129  }
130  if ($noInfo) {
131  $response->setSuccess(false)->addErrorMessage('User info is invalid');
132  }
133  }
134 
143  public function getAvatarEditUrl($response, \XoopsUser $userinfo)
144  {
145  $noInfo = true;
146 
147  if (is_object($userinfo)) {
148  if (is_a($userinfo, 'XoopsUser')) {
149  $email = $userinfo->getVar('email', 'e');
150  $link = 'http://www.gravatar.com/' . md5(strtolower(trim($email)));
151  $response->setValue($link);
152  $noInfo = false;
153  }
154  }
155  if ($noInfo) {
156  $response->setSuccess(false)->addErrorMessage('User info is invalid');
157  }
158  }
159 }
getAvatarEditUrl($response,\XoopsUser $userinfo)
static getInstance()
Definition: Xoops.php:160
$user
Definition: checklogin.php:47
$link
Definition: userinfo.php:84
getVar($key, $format= 's')
if(!$xoops->isUser()) $uid
Definition: index.php:31
static getGravatar($email)
$helper
$url
Definition: register.php:72
if($xoops->isUser()&&$isAdmin) $response
Definition: userinfo.php:83
getAvatarUrl($response, $userinfo)
$email
Definition: lostpass.php:32