]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/avatarsettings.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / actions / avatarsettings.php
index 3f50ca24cd4faf167365897255432703a8e19727..f38a44a24a3e782dc20b588005a6d39ac09c47b4 100644 (file)
@@ -145,6 +145,7 @@ class AvatarsettingsAction extends AccountSettingsAction
                                         'height' => AVATAR_PROFILE_SIZE,
                                         'alt' => $user->nickname));
             $this->elementEnd('div');
+            $this->submit('delete', _('Delete'));
             $this->elementEnd('li');
         }
 
@@ -200,7 +201,7 @@ class AvatarsettingsAction extends AccountSettingsAction
                                   'class' => 'avatar_view'));
         $this->element('h2', null, _("Original"));
         $this->elementStart('div', array('id'=>'avatar_original_view'));
-        $this->element('img', array('src' => common_avatar_url($this->filedata['filename']),
+        $this->element('img', array('src' => Avatar::url($this->filedata['filename']),
                                     'width' => $this->filedata['width'],
                                     'height' => $this->filedata['height'],
                                     'alt' => $user->nickname));
@@ -212,7 +213,7 @@ class AvatarsettingsAction extends AccountSettingsAction
                                   'class' => 'avatar_view'));
         $this->element('h2', null, _("Preview"));
         $this->elementStart('div', array('id'=>'avatar_preview_view'));
-        $this->element('img', array('src' => common_avatar_url($this->filedata['filename']),
+        $this->element('img', array('src' => Avatar::url($this->filedata['filename']),
                                     'width' => AVATAR_PROFILE_SIZE,
                                     'height' => AVATAR_PROFILE_SIZE,
                                     'alt' => $user->nickname));
@@ -256,6 +257,8 @@ class AvatarsettingsAction extends AccountSettingsAction
             $this->uploadAvatar();
         } else if ($this->arg('crop')) {
             $this->cropAvatar();
+        } else if ($this->arg('delete')) {
+            $this->deleteAvatar();
         } else {
             $this->showForm(_('Unexpected form submission.'));
         }
@@ -281,12 +284,12 @@ class AvatarsettingsAction extends AccountSettingsAction
 
         $cur = common_current_user();
 
-        $filename = common_avatar_filename($cur->id,
-                                           image_type_to_extension($imagefile->type),
-                                           null,
-                                           'tmp'.common_timestamp());
+        $filename = Avatar::filename($cur->id,
+                                     image_type_to_extension($imagefile->type),
+                                     null,
+                                     'tmp'.common_timestamp());
 
-        $filepath = common_avatar_path($filename);
+        $filepath = Avatar::path($filename);
 
         move_uploaded_file($imagefile->filepath, $filepath);
 
@@ -344,6 +347,29 @@ class AvatarsettingsAction extends AccountSettingsAction
             $this->showForm(_('Failed updating avatar.'));
         }
     }
+    
+    /**
+     * Get rid of the current avatar.
+     *
+     * @return void
+     */
+    
+    function deleteAvatar()
+    {
+        $user = common_current_user();
+        $profile = $user->getProfile();
+        
+        $avatar = $profile->getOriginalAvatar();
+        $avatar->delete();
+        $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+        $avatar->delete();
+        $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+        $avatar->delete();
+        $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
+        $avatar->delete();
+
+        $this->showForm(_('Avatar deleted.'), true);
+    }
 
     /**
      * Add the jCrop stylesheet