]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/GNUsocialPhotos/actions/editphoto.php
Merge branch 'nightly' into singpolyma/gnu-social-events-saveObjectFromActivity
[quix0rs-gnu-social.git] / plugins / GNUsocialPhotos / actions / editphoto.php
index d7f60e675210304fd4ae3bd6e79b6e137da23040..35dac7bf3f6298d921d62f100ffdd8b7d6059e5b 100644 (file)
@@ -42,7 +42,7 @@ class EditphotoAction extends Action
         $args = $this->returnToArgs();
         $this->user = common_current_user();
         $this->photoid = $args[1]['photoid'];
-        $this->photo = GNUsocialPhoto::staticGet('id', $this->photoid);
+        $this->photo = GNUsocialPhoto::getKV('id', $this->photoid);
         return true;
     }
 
@@ -57,32 +57,58 @@ class EditphotoAction extends Action
 
     function title()
     {
-        return _m('Upload Photos');
+        if ($this->photo->title)
+            return _m('Edit photo - ' . $this->photo->title);
+        else
+            return _m('Edit photo');
     }
 
     function showContent()
     {
-        if($this->user->profile_id != $this->photo->profile_id) {
+
+        if ($this->photo->album_id == 0) {
+            $this->element('p', array(), _('This photo does not exist or was deleted.'));
+            return;
+        }
+
+        if ($this->user->profile_id != $this->photo->profile_id) {
             $this->element('p', array(), _('You are not authorized to edit this photo.'));
-        } else {
-            $this->element('img', array('src' => $this->photo->uri));
-            $this->elementStart('form', array('method' => 'post',
-                                              'action' => '/editphoto/' . $this->photo->id));
-            $this->elementStart('ul', 'form_data');
-            $this->elementStart('li');
-            $this->input('phototitle', _("Title"), $this->photo->title, _("The title of the photo. (Optional)"));
-            $this->elementEnd('li');
-            $this->elementStart('li');
-            $this->textarea('photo_description', _("Description"), $this->photo->photo_description, _("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->photo->album_id);
-            $this->elementEnd('li');
-            $this->elementEnd('ul');
-            $this->submit('update', _('Update'));
-            $this->elementEnd('form');
-            $this->element('br');            
+            return;
+        } 
+
+        //showForm() data
+        if(!empty($this->msg)) {
+            $class = ($this->success) ? 'success' : 'error';
+            $this->element('p', array('class' => $class), $this->msg);
         }
+
+        $this->element('img', array('src' => $this->photo->uri));
+        $this->elementStart('form', array('method' => 'post',
+                                          'action' => '/editphoto/' . $this->photo->id));
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        $this->input('phototitle', _("Title"), $this->photo->title, _("The title of the photo. (Optional)"));
+        $this->elementEnd('li');
+        $this->elementStart('li');
+        $this->textarea('photo_description', _("Description"), $this->photo->photo_description, _("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->photo->album_id);
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        $this->submit('update', _('Update'));
+        $this->elementEnd('form');
+        $this->element('br');            
+        $this->elementStart('form', array('method' => 'post',
+                                          'action' => '/editphoto/' . $this->photo->id));
+        $this->element('input', array('type' => 'submit',
+                                      'name' => 'delete',
+                                      'value' => _('Delete Photo'),
+                                      'id' => 'delete',
+                                      'class' => 'submit',
+                                      'onclick' => 'return confirm(\'Are you sure you would like to delete this photo?\')'));
+        $this->elementEnd('form');
+
     }
 
     function handlePost()
@@ -90,9 +116,22 @@ class EditphotoAction extends Action
 
         common_log(LOG_INFO, 'handlPost()!');
 
+        if ($this->photo->album_id == 0) {
+            $this->element('p', array(), _('This photo does not exist or was deleted.'));
+            return;
+        }
+
+        if ($this->user->profile_id != $this->photo->profile_id) {
+            $this->element('p', array(), _('You are not authorized to edit this photo.'));
+            return;
+        } 
+
         if ($this->arg('update')) {
             $this->updatePhoto();
         }
+        if ($this->arg('delete')) {
+            $this->deletePhoto();
+        }
     }
 
     function showForm($msg, $success=false)
@@ -122,16 +161,12 @@ class EditphotoAction extends Action
     function updatePhoto()
     {
         $cur = common_current_user();
-        if($this->user->profile_id != $this->photo->profile_id) {
-            return;
-        }
-
         $this->photo->title = $this->trimmed('phototitle');
         $this->photo->photo_description = $this->trimmed('photo_description');
 
         $profile_id = $cur->id;
        
-        $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;
@@ -143,8 +178,25 @@ class EditphotoAction extends Action
             $this->showForm(_('Error: The photo data is not valid.'));
             return;
         }
-        $this->showForm(_('Success!'));
+        common_redirect('/photo/' . $this->photo->id, '303');
+        // common_redirect exits
+    }
+
+    function deletePhoto()
+    {
+        //For redirection
+        $oldalbum = $this->album_id;
 
+        $notice = Notice::getKV('id', $this->photo->notice_id);
+
+        $this->photo->delete();
+        
+        if (Event::handle('StartDeleteOwnNotice', array($this->user, $notice))) {
+            $notice->deleteAs($this->scoped);
+            Event::handle('EndDeleteOwnNotice', array($this->user, $notice));
+        }
+       $this->showForm(_('Success!'));
+        common_redirect('/' . $this->user->nickname . '/photos/' . $oldalbum, '303');
     }
 
 }