]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/GNUsocialPhotos/actions/photoupload.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / GNUsocialPhotos / actions / photoupload.php
index 28405bc58fcc4f6f522191de3e9d4f438f1b2613..a8874ea13b17a3da215e41c652d5ee005549ec46 100644 (file)
@@ -36,14 +36,14 @@ class PhotouploadAction extends Action
 {
     var $user = null;
 
-    function prepare($args)
+    function prepare(array $args=array())
     {
         parent::prepare($args);
         $this->user = common_current_user();
         return true;
     }
 
-    function handle($args)
+    function handle(array $args=array())
     {
         parent::handle($args);
         if($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -63,6 +63,12 @@ class PhotouploadAction extends Action
         if(empty($this->user)) {
             $this->element('p', array(), 'You are not logged in.');
         } else {
+            //showForm() data
+            if(!empty($this->msg)) {
+                $class = ($this->success) ? 'success' : 'error';
+                $this->element('p', array('class' => $class), $this->msg);
+            }
+
             $this->elementStart('form', array('enctype' => 'multipart/form-data',
                                               'method' => 'post',
                                               'action' => common_local_url('photoupload')));
@@ -101,6 +107,18 @@ class PhotouploadAction extends Action
             $this->elementEnd('ul');
             $this->submit('create', _('Create'));
             $this->elementEnd('form');
+
+            //Delete an album
+            $this->element('h3', array(), _("Delete an album"));
+            $this->elementStart('form', array('method' => 'post',
+                                              'action' =>common_local_url('photoupload')));
+            $this->elementStart('ul', 'form_data');
+            $this->elementStart('li');
+            $this->dropdown('album', _("Album"), $this->albumList(), _("The album in which to place this photo"), false);
+            $this->elementEnd('li');
+            $this->elementEnd('ul');
+            $this->submit('deletealbum', _('Delete'));
+            $this->elementEnd('form');
             
         }
     }
@@ -138,6 +156,9 @@ class PhotouploadAction extends Action
         if ($this->arg('create')) {
             $this->createAlbum();
         }
+        if ($this->arg('deletealbum')) {
+            $this->deleteAlbum();
+        }
     }
 
     function showForm($msg, $success=false)
@@ -193,8 +214,7 @@ class PhotouploadAction extends Action
         $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
         $profile_id = $cur->id;
        
-        // TODO: proper multiple album support 
-        $album = GNUsocialPhotoAlbum::staticGet('album_id', $this->trimmed('album'));
+        $album = GNUsocialPhotoAlbum::getKV('album_id', $this->trimmed('album'));
         if ($album->profile_id != $profile_id) {
             $this->showForm(_('Error: This is not your album!'));
             return;
@@ -214,4 +234,26 @@ class PhotouploadAction extends Action
        
         GNUsocialPhotoAlbum::newAlbum($cur->id, $album_name, $album_description);
     }
+
+    function deleteAlbum()
+    {
+        $cur = common_current_user();
+        if(empty($cur)) return;
+        
+        $album_id = $this->trimmed('album');
+        $album = GNUsocialPhotoAlbum::getKV('album_id', $album_id);
+        if (empty($album)) {
+            $this->showForm(_('This album does not exist or has been deleted.'));
+            return;
+        }
+        //Check if the album has any photos in it before deleting
+        $photos = GNUsocialPhoto::getKV('album_id', $album_id);
+        if(empty($photos)) {
+            $album->delete();
+            $this->showForm(_('Album deleted'), true);
+        }
+        else {
+            $this->showForm(_('Cannot delete album when there are photos in it!'), false);
+        }
+    }
 }