]> 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 84caf474754aebf2bc4110f4d6e79dabe4f3f872..a8874ea13b17a3da215e41c652d5ee005549ec46 100644 (file)
@@ -22,6 +22,8 @@
  * @category  Widget
  * @package   GNU Social
  * @author    Ian Denhardt <ian@zenhack.net>
+ * @author    Sean Corbett <sean@gnu.org>
+ * @author    Max Shinn    <trombonechamp@gmail.com>
  * @copyright 2010 Free Software Foundation, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  */
@@ -34,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') {
@@ -57,17 +59,67 @@ class PhotouploadAction extends Action
 
     function showContent()
     {
+        //Upload a photo
         if(empty($this->user)) {
             $this->element('p', array(), 'You are not logged in.');
         } else {
-            $this->elementStart('form', array('enctype' => 'mutlipart/form-data',
+            //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')));
+            $this->elementStart('ul', 'form_data');
+            $this->elementStart('li');
             $this->element('input', array('name' => 'photofile',
                                           'type' => 'file',
                                           'id' => 'photofile'));
+            $this->elementEnd('li');
+            //$this->element('br');
+            $this->elementStart('li');
+            $this->input('phototitle', _("Title"), null, _("The title of the photo. (Optional)"));
+            $this->elementEnd('li');
+            $this->elementStart('li');
+            $this->textarea('photo_description', _("Description"), null, _("A description of the photo. (Optional)"));
+            $this->elementEnd('li');
+            $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('upload', _('Upload'));
             $this->elementEnd('form');
+            $this->element('br');
+
+            //Create a new album
+            $this->element('h3', array(), _("Create a new album"));
+            $this->elementStart('form', array('method' => 'post',
+                                              'action' =>common_local_url('photoupload')));
+            $this->elementStart('ul', 'form_data');
+            $this->elementStart('li');
+            $this->input('album_name', _("Title"), null, _("The title of the album."));
+            $this->elementEnd('li');
+            $this->elementStart('li');
+            $this->textarea('album_description', _("Description"), null, _("A description of the album. (Optional)"));
+            $this->elementEnd('li');
+            $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');
+            
         }
     }
 
@@ -98,22 +150,43 @@ class PhotouploadAction extends Action
             return;
         } */
 
-        if($this->arg('upload')) {
+        if ($this->arg('upload')) {
             $this->uploadPhoto();
         }
+        if ($this->arg('create')) {
+            $this->createAlbum();
+        }
+        if ($this->arg('deletealbum')) {
+            $this->deleteAlbum();
+        }
     }
 
     function showForm($msg, $success=false)
-    { 
+    {
         $this->msg = $msg;
         $this->success = $success;
 
 //        $this->showPage();
     }
 
+    function albumList() 
+    {
+        $cur = common_current_user();
+        $album = new GNUsocialPhotoAlbum();
+        $album->user_id = $cur->id;
+
+        $albumlist = array();
+        if (!$album->find()) {
+            GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default');
+        }
+        while ($album->fetch()) {
+            $albumlist[$album->album_id] = $album->album_name;
+        }
+        return $albumlist;
+    }
+
     function uploadPhoto()
     {
-        common_log(LOG_INFO, 'Is this function even getting called?');
         $cur = common_current_user();
         if(empty($cur)) {
             return;
@@ -129,6 +202,9 @@ class PhotouploadAction extends Action
             return;
         }
 
+        $title = $this->trimmed('phototitle');
+        $photo_description = $this->trimmed('photo_description');
+
         common_log(LOG_INFO, 'upload path : ' . $imagefile->filepath);
 
         $filename = $cur->nickname . '-' . common_timestamp() . sha1_file($imagefile->filepath) .  image_type_to_extension($imagefile->type);
@@ -137,8 +213,47 @@ class PhotouploadAction extends Action
         $uri = 'http://' . common_config('site', 'server') . '/file/' . $filename;
         $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename;
         $profile_id = $cur->id;
-               //scorbett: the second arg below should be set to the album ID
-        GNUsocialPhoto::saveNew($profile_id, 0, $thumb_uri, $uri, 'web');
+       
+        $album = GNUsocialPhotoAlbum::getKV('album_id', $this->trimmed('album'));
+        if ($album->profile_id != $profile_id) {
+            $this->showForm(_('Error: This is not your album!'));
+            return;
+        }
+        GNUsocialPhoto::saveNew($profile_id, $album->album_id, $thumb_uri, $uri, 'web', false, $title, $photo_description);
+    }
+
+    function createAlbum()
+    {
+        $cur = common_current_user();
+        if(empty($cur)) {
+            return;
+        }
+
+        $album_name = $this->trimmed('album_name');
+        $album_description = $this->trimmed('album_description');
+       
+        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);
+        }
+    }
 }