From a62e9fec656fa2e21f8ceeb06cfba343cc1565b2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 14 Apr 2011 11:47:20 -0400 Subject: [PATCH] remove avatar saving from GravatarPlugin --- plugins/Gravatar/GravatarPlugin.php | 164 +--------------------------- 1 file changed, 1 insertion(+), 163 deletions(-) diff --git a/plugins/Gravatar/GravatarPlugin.php b/plugins/Gravatar/GravatarPlugin.php index ea91d11e78..bdb73f3433 100644 --- a/plugins/Gravatar/GravatarPlugin.php +++ b/plugins/Gravatar/GravatarPlugin.php @@ -1,7 +1,7 @@ hasGravatar($user->id); - - if($hasGravatar) { - return false; - } - } - - function onEndAvatarFormData($action) - { - $user = common_current_user(); - $hasGravatar = $this->hasGravatar($user->id); - - if(!empty($user->email) && !$hasGravatar) { //and not gravatar already set - $action->elementStart('form', array('method' => 'post', - 'id' => 'form_settings_gravatar_add', - 'class' => 'form_settings', - 'action' => - common_local_url('avatarsettings'))); - $action->elementStart('fieldset', array('id' => 'settings_gravatar_add')); - // TRANS: Fieldset legend. Gravatar is an avatar service. - $action->element('legend', null, _m('Set Gravatar')); - $action->hidden('token', common_session_token()); - $action->element('p', 'form_guide', - // TRANS: Form guide. Gravatar is an avatar service. - _m('If you want to use your Gravatar image, click "Add".')); - $action->element('input', array('type' => 'submit', - 'id' => 'settings_gravatar_add_action-submit', - 'name' => 'add', - 'class' => 'submit', - // TRANS: Button text to add a Gravatar. Gravatar is an avatar service. - 'value' => _m('BUTTON','Add'))); - $action->elementEnd('fieldset'); - $action->elementEnd('form'); - } elseif($hasGravatar) { - $action->elementStart('form', array('method' => 'post', - 'id' => 'form_settings_gravatar_remove', - 'class' => 'form_settings', - 'action' => - common_local_url('avatarsettings'))); - $action->elementStart('fieldset', array('id' => 'settings_gravatar_remove')); - // TRANS: Fieldset legend. Gravatar is an avatar service. - $action->element('legend', null, _m('Remove Gravatar')); - $action->hidden('token', common_session_token()); - $action->element('p', 'form_guide', - // TRANS: Form guide. Gravatar is an avatar service. - _m('If you want to remove your Gravatar image, click "Remove".')); - $action->element('input', array('type' => 'submit', - 'id' => 'settings_gravatar_remove_action-submit', - 'name' => 'remove', - 'class' => 'submit', - // TRANS: Button text to remove a Gravatar. Gravatar is an avatar service. - 'value' => _m('Remove'))); - $action->elementEnd('fieldset'); - $action->elementEnd('form'); - } else { - $action->element('p', 'form_guide', - // TRANS: Form guide. Gravatar is an avatar service. - _m('To use a Gravatar first enter in an email address.')); - } - } - - function onStartAvatarSaveForm($action) - { - if ($action->arg('add')) { - $result = $this->gravatar_save(); - - if($result['success']===true) { - common_broadcast_profile(common_current_user()->getProfile()); - } - - $action->showForm($result['message'], $result['success']); - - return false; - } else if ($action->arg('remove')) { - $result = $this->gravatar_remove(); - - if($result['success']===true) { - common_broadcast_profile(common_current_user()->getProfile()); - } - - $action->showForm($result['message'], $result['success']); - - return false; - } else { - return true; - } - } - - function hasGravatar($id) { - $avatar = new Avatar(); - $avatar->profile_id = $id; - if ($avatar->find()) { - while ($avatar->fetch()) { - if($avatar->filename == null) { - return true; - } - } - } - return false; - } - - function gravatar_save() - { - $cur = common_current_user(); - - if(empty($cur->email)) { - // TRANS: Message displayed when no e-mail address was set when saving Gravatar setting. Gravatar is an avatar service. - return array('message' => _m('You do not have an email address set in your profile.'), - 'success' => false); - } - //Get rid of previous Avatar - $this->gravatar_remove(); - - foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { - $gravatar = new Avatar(); - $gravatar->profile_id = $cur->id; - $gravatar->width = $size; - $gravatar->height = $size; - $gravatar->original = false; //No file, so no original - $gravatar->mediatype = 'img';//XXX: Unsure what to put here - //$gravatar->filename = null;//No filename. Remote - $gravatar->url = $this->gravatar_url($cur->email, $size); - $gravatar->created = DB_DataObject_Cast::dateTime(); # current time - - if (!$gravatar->insert()) { - // TRANS: Message displayed when saving Gravatar setting fails. Gravatar is an avatar service. - return array('message' => _m('Failed to save Gravatar to the database.'), - 'success' => false); - } - } - // TRANS: Message displayed when Gravatar was added. Gravatar is an avatar service. - return array('message' => _m('Gravatar added.'), - 'success' => true); - } - - function gravatar_remove() - { - $user = common_current_user(); - $profile = $user->getProfile(); - - $avatar = $profile->getOriginalAvatar(); - if($avatar) $avatar->delete(); - $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); - if($avatar) $avatar->delete(); - $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); - if($avatar) $avatar->delete(); - $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); - if($avatar) $avatar->delete(); - - // TRANS: Message displayed when Gravatar was removed. Gravatar is an avatar service. - return array('message' => _m('Gravatar removed.'), - 'success' => true); - } - function onEndProfileGetAvatar($profile, $size, &$avatar) { if (empty($avatar)) { -- 2.39.5