]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Updating uploaded photos
authorMax Shinn <trombonechamp@gmail.com>
Tue, 28 Dec 2010 16:40:58 +0000 (10:40 -0600)
committerMax Shinn <trombonechamp@gmail.com>
Tue, 28 Dec 2010 16:40:58 +0000 (10:40 -0600)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/editphoto.php [new file with mode: 0644]
plugins/GNUsocialPhotos/actions/photo.php
plugins/GNUsocialPhotos/actions/photos.php

index a3aed95c0cefd2ac1511a2758f6ed22b5e8749b5..499d376fcce5f5e26beabf61f11bd09206fc0ede 100644 (file)
@@ -56,6 +56,10 @@ class GNUsocialPhotosPlugin extends Plugin
             include_once $dir . '/lib/photolib.php';
             include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
             break;
+        case 'EditphotoAction':
+            include_once $dir . '/lib/photolib.php';
+            include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
+            break;
         default:
             break;
         }
@@ -89,6 +93,7 @@ class GNUsocialPhotosPlugin extends Plugin
         $m->connect(':nickname/photos/:albumid', array('action' => 'photos'));
         $m->connect('main/uploadphoto', array('action' => 'photoupload'));
         $m->connect('photo/:photoid', array('action' => 'photo'));
+        $m->connect('editphoto/:photoid', array('action' => 'editphoto'));
         return true;
     }
 
diff --git a/plugins/GNUsocialPhotos/actions/editphoto.php b/plugins/GNUsocialPhotos/actions/editphoto.php
new file mode 100644 (file)
index 0000000..d7f60e6
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+/**
+ * GNU Social
+ * Copyright (C) 2010, Free Software Foundation, Inc.
+ *
+ * PHP version 5
+ *
+ * LICENCE:
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @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
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+class EditphotoAction extends Action
+{
+    var $user = null;
+
+    function prepare($args)
+    {
+        parent::prepare($args);
+        $args = $this->returnToArgs();
+        $this->user = common_current_user();
+        $this->photoid = $args[1]['photoid'];
+        $this->photo = GNUsocialPhoto::staticGet('id', $this->photoid);
+        return true;
+    }
+
+    function handle($args)
+    {
+        parent::handle($args);
+        if($_SERVER['REQUEST_METHOD'] == 'POST') {
+            $this->handlePost();
+        }
+        $this->showPage();
+    }
+
+    function title()
+    {
+        return _m('Upload Photos');
+    }
+
+    function showContent()
+    {
+        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');            
+        }
+    }
+
+    function handlePost()
+    {
+
+        common_log(LOG_INFO, 'handlPost()!');
+
+        if ($this->arg('update')) {
+            $this->updatePhoto();
+        }
+    }
+
+    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 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'));
+        if ($album->profile_id != $profile_id) {
+            $this->showForm(_('Error: This is not your album!'));
+            return;
+        }
+        $this->photo->album_id = $album->album_id;
+        if ($this->photo->validate())
+            $this->photo->update();
+        else {
+            $this->showForm(_('Error: The photo data is not valid.'));
+            return;
+        }
+        $this->showForm(_('Success!'));
+
+    }
+
+}
index e9d87b32d7d03606ae51c9e5ed1d06e57f0a1f10..f6ec06358638fbf294062afcdc6c323bfa9a59e8 100644 (file)
@@ -90,6 +90,15 @@ class PhotoAction extends Action
         $this->elementStart('a', array('href' => $this->photo->uri));
         $this->element('img', array('src' => $this->photo->uri));
         $this->elementEnd('a');
+
+        //Image "toolbar"
+        $cur = common_current_user();
+        if($this->photo->profile_id == $cur->profile_id) {
+            $this->elementStart('div', array('id' => 'image_toolbar'));
+            $this->element('a', array('href' => '/editphoto/' . $this->photo->id), 'Edit');
+            $this->elementEnd('div');
+        }
+
         $this->element('p', array(), $this->photo->photo_description);
         //This is a hack to hide the top-level comment
         $this->element('style', array(), "#notice-{$this->photo->notice_id} div { display: none } #notice-{$this->photo->notice_id} ol li div { display: inline }");
index d1136008506ea70fdd344004eb0f87f95e0ffea5..5b750a6501ac1227ef0f7683cedbdba7caf85b3d 100644 (file)
@@ -86,10 +86,10 @@ class PhotosAction extends Action
 
         $this->elementStart('div', array('class' => 'galleryheader'));
         $this->element('a', array('href' => '#',
-                                  'onclick' => 'increasePhotoSize()'), '+');
+                                  'onclick' => 'return increasePhotoSize()'), '+');
         $this->raw(' | ');
         $this->element('a', array('href' => '#',
-                                  'onclick' => 'decreasePhotoSize()'), '-');
+                                  'onclick' => 'return decreasePhotoSize()'), '-');
         $this->elementEnd('div');
 
         while ($album->fetch()) {
@@ -127,10 +127,10 @@ class PhotosAction extends Action
             $this->raw(' | ');
         }
         $this->element('a', array('href' => '#',
-                                  'onclick' => 'increasePhotoSize()'), '+');
+                                  'onclick' => 'return increasePhotoSize()'), '+');
         $this->raw(' | ');
         $this->element('a', array('href' => '#',
-                                  'onclick' => 'decreasePhotoSize()'), '-');
+                                  'onclick' => 'return decreasePhotoSize()'), '-');
         $this->elementEnd('div');