XOOPS  2.6.0
AvatarsProvider.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 {
28  protected $xoops_url;
29  protected $xoops_upload_url;
30 
31  public function __construct()
32  {
33  $this->xoops_url = \XoopsBaseConfig::get('url');
34  $this->xoops_upload_url = \XoopsBaseConfig::get('uploads-url');
35  }
36 
43  public function getName()
44  {
45  return 'avatars';
46  }
47 
53  public function getDescription()
54  {
55  return 'Traditional XOOPS avatars.';
56  }
57 
65  private function getUserById($uid)
66  {
67  $user = \Xoops::getInstance()->getHandlerMember()->getUser((int) $uid);
68  return (is_object($user)) ? $user : null;
69  }
70 
80  public function getAvatarUrl($response, $userinfo)
81  {
82  $noInfo = true;
83  if (is_object($userinfo)) {
84  if (is_a($userinfo, 'XoopsUser')) {
85  if ($userinfo->getVar('user_avatar')
86  && 'blank.gif' != $userinfo->getVar('user_avatar')
87  ) {
88  $response->setValue($this->xoops_upload_url . "/" . $userinfo->getVar('user_avatar'));
89  }
90  $noInfo = false;
91  }
92  } elseif (is_array($userinfo)) {
93  if (!empty($userinfo['user_avatar']) && $userinfo['user_avatar'] != 'blank.gif') {
94  $response->setValue($this->xoops_upload_url . "/" . $userinfo['user_avatar']);
95  $noInfo = false;
96  }
97  } elseif (is_scalar($userinfo)) {
98  $user = $this->getUserById((int) $userinfo);
99  if (is_object($user) && is_a($user, 'XoopsUser')) {
100  if ($user->getVar('user_avatar')
101  && 'blank.gif' != $user->getVar('user_avatar')
102  ) {
103  $response->setValue($this->xoops_upload_url . "/" . $user->getVar('user_avatar'));
104  }
105  $noInfo = false;
106  }
107  }
108  if ($noInfo) {
109  $response->setSuccess(false)->addErrorMessage('User info is invalid');
110  }
111  }
112 
121  public function getAvatarEditUrl($response, \XoopsUser $userinfo)
122  {
123  $noInfo = true;
124  if (is_a($userinfo, 'XoopsUser')) {
125  $link = $this->xoops_url . '/modules/avatars/editavatar.php';
126  $response->setValue($link);
127  $noInfo = false;
128  }
129  if ($noInfo) {
130  $response->setSuccess(false)->addErrorMessage('User info is invalid');
131  }
132  }
133 }
static getInstance()
Definition: Xoops.php:160
getAvatarUrl($response, $userinfo)
$user
Definition: checklogin.php:47
getAvatarEditUrl($response,\XoopsUser $userinfo)
$link
Definition: userinfo.php:84
static get($name)
if(!$xoops->isUser()) $uid
Definition: index.php:31
if($xoops->isUser()&&$isAdmin) $response
Definition: userinfo.php:83