3 use wcf\data\user\avatar\Gravatar
;
4 use wcf\data\user\avatar\UserAvatarAction
;
5 use wcf\data\user\UserAction
;
6 use wcf\system\exception\PermissionDeniedException
;
7 use wcf\system\exception\UserInputException
;
8 use wcf\system\menu\user\UserMenu
;
12 * Shows the avatar edit form.
15 * @copyright 2001-2014 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package com.woltlab.wcf
19 * @category Community Framework
21 class AvatarEditForm
extends AbstractForm
{
23 * @see \wcf\page\AbstractPage::$enableTracking
25 public $enableTracking = true;
28 * @see \wcf\page\AbstractPage::$loginRequired
30 public $loginRequired = true;
33 * @see \wcf\page\AbstractPage::$templateName
35 public $templateName = 'avatarEdit';
41 public $avatarType = 'none';
44 * @see \wcf\form\IForm::readFormParameters()
46 public function readFormParameters() {
47 parent
::readFormParameters();
49 if (isset($_POST['avatarType'])) $this->avatarType
= $_POST['avatarType'];
53 * @see \wcf\form\IForm::validate()
55 public function validate() {
58 if (WCF
::getUser()->disableAvatar
) throw new PermissionDeniedException();
60 if ($this->avatarType
!= 'custom' && $this->avatarType
!= 'gravatar') $this->avatarType
= 'none';
62 switch ($this->avatarType
) {
64 if (!WCF
::getUser()->avatarID
) {
65 throw new UserInputException('custom');
70 if (!MODULE_GRAVATAR
) {
71 $this->avatarType
= 'none';
76 if (!Gravatar
::test(WCF
::getUser()->email
)) {
77 throw new UserInputException('gravatar', 'notFound');
84 * @see \wcf\form\IForm::save()
86 public function save() {
89 if ($this->avatarType
!= 'custom') {
90 // delete custom avatar
91 if (WCF
::getUser()->avatarID
) {
92 $action = new UserAvatarAction(array(WCF
::getUser()->avatarID
), 'delete');
93 $action->executeAction();
98 switch ($this->avatarType
) {
102 'enableGravatar' => 0
108 'enableGravatar' => 0
115 'enableGravatar' => 1
119 $this->objectAction
= new UserAction(array(WCF
::getUser()), 'update', array(
120 'data' => array_merge($this->additionalFields
, $data)
122 $this->objectAction
->executeAction();
124 // reset gravatar cache
125 if ($this->avatarType
== 'gravatar') {
126 $pattern = WCF_DIR
. sprintf(Gravatar
::GRAVATAR_CACHE_LOCATION
, md5(mb_strtolower(WCF
::getUser()->email
)), '*');
127 $files = glob($pattern);
128 if (!empty($files)) {
129 foreach ($files as $file) {
136 WCF
::getTPL()->assign('success', true);
140 * @see \wcf\page\IPage::readData()
142 public function readData() {
146 if (WCF
::getUser()->avatarID
) $this->avatarType
= 'custom';
147 else if (MODULE_GRAVATAR
&& WCF
::getUser()->enableGravatar
) $this->avatarType
= 'gravatar';
152 * @see \wcf\page\IPage::assignVariables()
154 public function assignVariables() {
155 parent
::assignVariables();
157 WCF
::getTPL()->assign(array(
158 'avatarType' => $this->avatarType
163 * @see \wcf\page\IPage::show()
165 public function show() {
167 UserMenu
::getInstance()->setActiveMenuItem('wcf.user.menu.profile.avatar');