]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
album creation and editing is working
authorcash <cash.costello@gmail.com>
Sat, 19 Nov 2011 23:43:35 +0000 (18:43 -0500)
committercash <cash.costello@gmail.com>
Sat, 19 Nov 2011 23:43:35 +0000 (18:43 -0500)
17 files changed:
actions/addalbum.php [deleted file]
actions/photos/album/save.php [new file with mode: 0644]
classes/TidypicsAlbum.php
languages/en.php
lib/tidypics.php
pages/edit.php [deleted file]
pages/newalbum.php [deleted file]
pages/photos/album/add.php [new file with mode: 0644]
pages/photos/album/edit.php [new file with mode: 0644]
pages/photos/album/view.php
pages/photos/image/upload.php [moved from pages/upload.php with 100% similarity]
start.php
views/default/forms/photos/admin/settings.php [moved from views/default/forms/tidypics/admin/settings.php with 100% similarity]
views/default/forms/photos/ajax_upload.php [moved from views/default/forms/tidypics/ajax_upload.php with 100% similarity]
views/default/forms/photos/album/save.php [new file with mode: 0644]
views/default/forms/photos/basic_upload.php [moved from views/default/forms/tidypics/basic_upload.php with 100% similarity]
views/default/tidypics/forms/edit.php [deleted file]

diff --git a/actions/addalbum.php b/actions/addalbum.php
deleted file mode 100644 (file)
index 8ddcca1..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * Tidypics Add New Album Action
- *
- */
-
-// Make sure we're logged in 
-gatekeeper();
-
-// Get input data
-$title = get_input('tidypicstitle');
-$body = get_input('tidypicsbody');
-$tags = get_input('tidypicstags');
-$access = get_input('access_id');
-$container_guid = get_input('container_guid', get_loggedin_userid());
-
-// Cache to the session
-$_SESSION['tidypicstitle'] = $title;
-$_SESSION['tidypicsbody'] = $body;
-$_SESSION['tidypicstags'] = $tags;
-
-
-if (empty($title)) {
-       register_error(elgg_echo("album:blank"));
-       forward($_SERVER['HTTP_REFERER']);
-}
-
-$album = new TidypicsAlbum();
-
-$album->container_guid = $container_guid;
-$album->owner_guid = get_loggedin_userid();
-$album->access_id = $access;
-$album->title = $title;
-$album->description = $body;
-if ($tags) {
-       $album->tags = string_to_tag_array($tags);
-}
-$album->new_album = TP_NEW_ALBUM;
-
-if (!$album->save()) {
-       register_error(elgg_echo("album:error"));
-       forward(get_input('forward_url', $_SERVER['HTTP_REFERER']));
-}
-
-mkdir(tp_get_img_dir() . $album->guid, 0755, true);
-
-system_message(elgg_echo("album:created"));
-
-// Remove the album post cache
-unset($_SESSION['tidypicstitle']);
-unset($_SESSION['tidypicsbody']);
-unset($_SESSION['tidypicstags']);
-
-// plugins can register to be told when a new Tidypics album has been created
-trigger_elgg_event('add', 'tp_album', $album);
-
-forward("pg/photos/upload/" . $album->guid);
diff --git a/actions/photos/album/save.php b/actions/photos/album/save.php
new file mode 100644 (file)
index 0000000..cc71816
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Save album action
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+
+// Get input data
+$title = get_input('title');
+$description = get_input('description');
+$tags = get_input('tags');
+$access_id = get_input('access_id');
+$container_guid = get_input('container_guid', elgg_get_logged_in_user_guid());
+$guid = get_input('guid');
+
+elgg_make_sticky_form('tidypics');
+
+if (empty($title)) {
+       register_error(elgg_echo("album:blank"));
+       forward(REFERER);
+}
+
+if ($guid) {
+       $album = get_entity($guid);
+} else {
+       $album = new TidypicsAlbum();
+}
+
+$album->container_guid = $container_guid;
+$album->owner_guid = elgg_get_logged_in_user_guid();
+$album->access_id = $access_id;
+$album->title = $title;
+$album->description = $description;
+if ($tags) {
+       $album->tags = string_to_tag_array($tags);
+}
+
+if (!$album->save()) {
+       register_error(elgg_echo("album:error"));
+       forward(REFERER);
+}
+
+elgg_clear_sticky_form('tidypics');
+
+system_message(elgg_echo("album:created"));
+forward($album->getURL());
index 1fbdb8ad8170085824aba9837fe96b6db44a2ab8..75a01841031a1b8cf388a7142522171aa7ca9a21 100644 (file)
@@ -18,12 +18,23 @@ class TidypicsAlbum extends ElggObject {
        }
 
        /**
-        * Get the title of the photo album
-        * 
-        * @return string
+        * Save an album
+        *
+        * @return bool
         */
-       public function getTitle() {
-               return $this->title;
+       public function save() {
+
+               if (!isset($this->new_album)) {
+                       $this->new_album = true;
+               }
+
+               if (!parent::save()) {
+                       return false;
+               }
+               
+               mkdir(tp_get_img_dir() . $this->guid, 0755, true);
+
+               return true;
        }
 
        /**
@@ -39,6 +50,15 @@ class TidypicsAlbum extends ElggObject {
                return parent::delete();
        }
 
+       /**
+        * Get the title of the photo album
+        *
+        * @return string
+        */
+       public function getTitle() {
+               return $this->title;
+       }
+
        /**
         * Get an array of image objects
         *
index d6d934c20da5f7c8146ecdbbf8c47e03c88493bc..63d4632c601e95f9c8306737e61fdda2324b1bb6 100644 (file)
@@ -206,7 +206,7 @@ The photo can be viewed here: %s",
                        'album:none' => "No albums have been created yet.",
                        'album:uploadfailed' => "Sorry; we could not save your album.",
                        'album:deletefailed' => "Your album could not be deleted.",
-                       'album:blank' => "Please give this album a title and description.",
+                       'album:blank' => "Please give this album a title.",
                        'tidypics:upgrade:failed' => "The upgrade of Tidypics failed", 
 );
 
index 8fcfc22c97183d5b4a0b5a9bd55250c134552263..7eedb246d1adab23dc8f781ac2d22b8b41cf00a0 100644 (file)
@@ -59,6 +59,37 @@ function tp_get_img_dir() {
        return $file->getFilenameOnFilestore() . 'image/';
 }
 
+function tidypics_prepare_form_vars($entity = null) {
+       // input names => defaults
+       $values = array(
+               'title' => '',
+               'description' => '',
+               'access_id' => ACCESS_DEFAULT,
+               'tags' => '',
+               'container_guid' => elgg_get_page_owner_guid(),
+               'guid' => null,
+               'entity' => $entity,
+       );
+
+       if ($entity) {
+               foreach (array_keys($values) as $field) {
+                       if (isset($entity->$field)) {
+                               $values[$field] = $entity->$field;
+                       }
+               }
+       }
+
+       if (elgg_is_sticky_form('tidypics')) {
+               $sticky_values = elgg_get_sticky_values('tidypics');
+               foreach ($sticky_values as $key => $value) {
+                       $values[$key] = $value;
+               }
+       }
+
+       elgg_clear_sticky_form('tidypics');
+
+       return $values;
+}
 
 
 /*********************************************************************
diff --git a/pages/edit.php b/pages/edit.php
deleted file mode 100644 (file)
index 06d3dd9..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * Tidypics Edit for Albums and Single Photos
- *
- */
-
-include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php";
-
-// make sure the user is logged_in
-gatekeeper(); 
-
-set_context('photos');
-$guid = (int) get_input('guid');
-
-if (!$entity = get_entity($guid)) {
-       forward();
-}
-
-if (!$entity->canEdit()) {
-       forward();
-}
-
-$subtype = $entity->getSubtype();
-
-if ($subtype == 'album') {
-       $title = elgg_echo('album:edit');
-
-       if ($container = $entity->container_guid) {
-               set_page_owner($container);
-       }
-
-} else if ($subtype == 'image') {
-       $title = elgg_echo('image:edit');
-
-       if ($container = get_entity($entity->container_guid)->container_guid) {
-               set_page_owner($container);
-       }
-
-} else {
-       forward();
-}
-
-$page_owner = page_owner_entity();
-if ($page_owner instanceof ElggGroup) {
-       add_submenu_item(       sprintf(elgg_echo('album:group'),$page_owner->name),
-                       $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username);
-}
-
-
-$area2 .= elgg_view_title($title);
-$area2 .= elgg_view('tidypics/forms/edit', array('entity' => $entity, 'subtype' => $subtype));
-$body = elgg_view_layout('two_column_left_sidebar', $area1, $area2);
-
-page_draw($title, $body);
diff --git a/pages/newalbum.php b/pages/newalbum.php
deleted file mode 100644 (file)
index 5351162..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-/**
- * Tidypics Create New Album Page
- *
- */
-
-// Load Elgg engine
-include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php";
-
-// must be logged in to create a new album
-gatekeeper();
-
-// Get the current page's owner        
-$page_owner = page_owner_entity();
-if ($page_owner === false || is_null($page_owner)) {
-       $page_owner = get_loggedin_user();
-       set_page_owner($page_owner->guid);
-}
-
-if ($page_owner instanceof ElggGroup) {
-       add_submenu_item(sprintf(elgg_echo('album:group'), $page_owner->name),
-                       $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username);
-}
-
-$area2 = elgg_view_title(elgg_echo('album:add'));
-$area2 .= elgg_view("tidypics/forms/edit");
-
-// Display page
-page_draw(elgg_echo('album:add'),elgg_view_layout("two_column_left_sidebar", '', $area2));
diff --git a/pages/photos/album/add.php b/pages/photos/album/add.php
new file mode 100644 (file)
index 0000000..d34d391
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Create new album page
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+$owner = elgg_get_page_owner_entity();
+
+gatekeeper();
+group_gatekeeper();
+
+$title = elgg_echo('photos:add');
+
+// set up breadcrumbs
+elgg_push_breadcrumb(elgg_echo('photos'), "photos/all");
+if (elgg_instanceof($owner, 'user')) {
+       elgg_push_breadcrumb($owner->name, "photos/owner/$owner->username");
+} else {
+       elgg_push_breadcrumb($owner->name, "photos/group/$owner->guid/all");
+}
+elgg_push_breadcrumb($title);
+
+$vars = tidypics_prepare_form_vars();
+$content = elgg_view_form('photos/album/save', array('method' => 'post'), $vars);
+
+$body = elgg_view_layout('content', array(
+       'content' => $content,
+       'title' => $title,
+       'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/pages/photos/album/edit.php b/pages/photos/album/edit.php
new file mode 100644 (file)
index 0000000..6fff50b
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Edit an album
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+$guid = (int) get_input('guid');
+
+if (!$entity = get_entity($guid)) {
+       // @todo either deleted or do not have access
+       forward('photos/all');
+}
+
+if (!$entity->canEdit()) {
+       // @todo cannot change it
+       forward('photos/all');
+}
+
+elgg_set_page_owner_guid($entity->getContainerGUID());
+$owner = elgg_get_page_owner_entity();
+
+gatekeeper(); 
+group_gatekeeper();
+
+$title = elgg_echo('album:edit');
+
+// set up breadcrumbs
+elgg_push_breadcrumb(elgg_echo('photos'), "photos/all");
+if (elgg_instanceof($owner, 'user')) {
+       elgg_push_breadcrumb($owner->name, "photos/owner/$owner->username");
+} else {
+       elgg_push_breadcrumb($owner->name, "photos/group/$owner->guid/all");
+}
+elgg_push_breadcrumb($title);
+
+$vars = tidypics_prepare_form_vars($entity);
+$content = elgg_view_form('photos/album/save', array('method' => 'post'), $vars);
+
+$body = elgg_view_layout('content', array(
+       'content' => $content,
+       'title' => $title,
+       'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
index adb5a1b51e06e7847752de42d7cf1f6ba53c3aa7..aafcf14bc043e5f007a75ffb22b23c83b7af1bc4 100644 (file)
@@ -12,7 +12,8 @@ group_gatekeeper();
 $album_guid = (int) get_input('guid');
 $album = get_entity($album_guid);
 if (!$album) {
-       
+       // @todo album deleted or don't have access
+       forward('photos/all');
 }
 
 elgg_set_page_owner_guid($album->getContainerGUID());
index ae52e7098d6c84d40d8d6b0c54f0893e7d24f005..95378992481652cce0b8c5ea71cb59cb0c391a72 100644 (file)
--- a/start.php
+++ b/start.php
@@ -83,11 +83,11 @@ function tidypics_init() {
        register_plugin_hook('forward', 'system', 'tidypics_ajax_session_handler');
 
        // Register actions
-       $base_dir = $CONFIG->pluginspath . "tidypics/actions";
+       $base_dir = $CONFIG->pluginspath . "tidypics/actions/photos";
+       elgg_register_action("photos/album/save", "$base_dir/album/save.php");
        register_action("tidypics/upload", false, "$base_dir/upload.php");
        register_action("tidypics/ajax_upload", true, "$base_dir/ajax_upload.php");
        register_action("tidypics/ajax_upload_complete", true, "$base_dir/ajax_upload_complete.php");
-       register_action("tidypics/addalbum", false, "$base_dir/addalbum.php");
        register_action("tidypics/sortalbum", false, "$base_dir/sortalbum.php");
        register_action("tidypics/edit", false, "$base_dir/edit.php");
        register_action("tidypics/delete", false, "$base_dir/delete.php");
@@ -247,22 +247,21 @@ function tidypics_mostviewed_submenus() {
 }
 
 /**
- * tidypics page handler
+ * Tidypics page handler
  *
  * @param array $page Array of url segments
  */
 function tidypics_page_handler($page) {
 
-       global $CONFIG;
-
        if (!isset($page[0])) {
                return false;
        }
 
+       $base = elgg_get_plugins_path() . 'tidypics/pages/photos';
        switch($page[0]) {
                case "all": // all site albums
                case "world":
-                       include($CONFIG->pluginspath . "tidypics/pages/photos/all.php");
+                       require "$base/all.php";
                        break;
 
                case "owned":  // albums owned by container entity
@@ -270,28 +269,43 @@ function tidypics_page_handler($page) {
                        if (isset($page[1])) {
                                set_input('username', $page[1]);
                        }
-                       include($CONFIG->pluginspath . "tidypics/pages/photos/owner.php");
+                       require "$base/owner.php";
                        break;
 
                case "friends": // albums of friends
                        if (isset($page[1])) {
                                set_input('username', $page[1]);
                        }
-                       include($CONFIG->pluginspath . "tidypics/pages/photos/friends.php");
+                       require "$base/friends.php";
                        break;
 
-               case "view": //view an image individually
+               case "album": // view an album individually
                        if (isset($page[1])) {
                                set_input('guid', $page[1]);
                        }
-                       include($CONFIG->pluginspath . "tidypics/pages/viewimage.php");
+                       require "$base/album/view.php";
                        break;
 
-               case "album": //view an album individually
+               case "new":  // create new album
+               case "add":
                        if (isset($page[1])) {
                                set_input('guid', $page[1]);
                        }
-                       include($CONFIG->pluginspath . "tidypics/pages/photos/album/view.php");
+                       require "$base/album/add.php";
+                       break;
+
+               case "edit": //edit image or album
+                       set_input('guid', $page[1]);
+                       $entity = get_entity($page[1]);
+                       switch ($entity->getSubtype()) {
+                               case 'album':
+                                       require "$base/album/edit.php";
+                                       break;
+                               default:
+                                       echo 'not album';
+                                       exit;
+                                       return false;
+                       }
                        break;
 
                case "sort": //sort a photo album
@@ -301,14 +315,13 @@ function tidypics_page_handler($page) {
                        include($CONFIG->pluginspath . "tidypics/pages/sortalbum.php");
                        break;
 
-               case "new":  //create new album
-               case "add":
+               case "view": //view an image individually
                        if (isset($page[1])) {
-                               set_input('username', $page[1]);
+                               set_input('guid', $page[1]);
                        }
-                       include($CONFIG->pluginspath . "tidypics/pages/newalbum.php");
+                       include($CONFIG->pluginspath . "tidypics/pages/viewimage.php");
                        break;
-
+               
                case "upload": //upload images to album
                        if (isset($page[1])) {
                                set_input('album_guid', $page[1]);
@@ -316,14 +329,7 @@ function tidypics_page_handler($page) {
                        if (isset($page[2])) {
                                set_input('uploader', 'basic');
                        }
-                       include($CONFIG->pluginspath . "tidypics/pages/upload.php");
-                       break;
-
-               case "edit": //edit image or album
-                       if (isset($page[1])) {
-                               set_input('guid', $page[1]);
-                       }
-                       include($CONFIG->pluginspath . "tidypics/pages/edit.php");
+                       include($CONFIG->pluginspath . "tidypics/pages/photos/image/upload.php");
                        break;
 
                case "batch": //update titles and descriptions
diff --git a/views/default/forms/photos/album/save.php b/views/default/forms/photos/album/save.php
new file mode 100644 (file)
index 0000000..8a1202c
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Save album form body
+ *
+ * @author Cash Costello
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
+ */
+
+$title = elgg_extract('title', $vars, '');
+$description = elgg_extract('description', $vars, '');
+$tags = elgg_extract('tags', $vars, '');
+$access_id = elgg_extract('access_id', $vars, get_default_access());
+$container_guid = elgg_extract('container_guid', $vars, elgg_get_page_owner_guid());
+$guid = elgg_extract('guid', $vars, 0);
+
+?>
+
+<div>
+       <label><?php echo elgg_echo('album:title'); ?></label>
+       <?php echo elgg_view('input/text', array('name' => 'title', 'value' => $title)); ?>
+</div>
+<div>
+       <label><?php echo elgg_echo('album:desc'); ?></label>
+       <?php echo elgg_view('input/longtext', array('name' => 'description', 'value' => $description)); ?>
+</div>
+<div>
+       <label><?php echo elgg_echo('tags'); ?></label>
+       <?php echo elgg_view('input/tags', array('name' => 'tags', 'value' => $tags)); ?>
+</div>
+<?php
+
+$categories = elgg_view('input/categories', $vars);
+if ($categories) {
+       echo $categories;
+}
+
+?>
+<div>
+       <label><?php echo elgg_echo('access'); ?></label>
+       <?php echo elgg_view('input/access', array('name' => 'access_id', 'value' => $access_id)); ?>
+</div>
+<div class="elgg-foot">
+<?php
+echo elgg_view('input/hidden', array('name' => 'guid', 'value' => $guid));
+echo elgg_view('input/hidden', array('name' => 'container_guid', 'value' => $container_guid));
+echo elgg_view('input/submit', array('value' => elgg_echo('save')));
+?>
+</div>
diff --git a/views/default/tidypics/forms/edit.php b/views/default/tidypics/forms/edit.php
deleted file mode 100644 (file)
index 8e2bd9b..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-<?php
-/**
- * Tidypics images edit/add form
- *  This form is used to:
- *     - create albums
- *     - edit albums
- *     - edit images
- */
-
-//set stuff if we are editing existing album or image
-if (isset($vars['entity'])) {
-       $action = "tidypics/edit";
-       $title = $vars['entity']->title;
-       $body = $vars['entity']->description;
-       $tags = $vars['entity']->tags;
-       $access_id = $vars['entity']->access_id;
-       $subtype = $vars['subtype'];
-
-       // if nothing is sent, create new, but only new albums are sent here
-       // new images are sent to upload.php
-} else {
-       $action = "tidypics/addalbum";
-       $tags = "";
-       $title = "";
-       $body = "";
-       $access_id = ACCESS_DEFAULT;
-       $subtype = 'album';
-
-       $title = $_SESSION['tidypicstitle'];
-       $body = $_SESSION['tidypicsbody'];
-       $tags = $_SESSION['tidypicstags'];
-
-       unset($_SESSION['tidypicstitle']);
-       unset($_SESSION['tidypicsbody']);
-       unset($_SESSION['tidypicstags']);
-}
-
-// group or individual 
-$container_guid = page_owner();
-
-?>
-<div class="contentWrapper">
-       <form action="<?php echo $vars['url']; ?>action/<?php echo $action; ?>" method="post">
-               <p>
-                       <label><?php echo elgg_echo('album:title'); ?></label>
-                       <?php  echo elgg_view("input/text", array("internalname" => "tidypicstitle", "value" => $title,));  ?>
-               </p>
-               <?php
-               if ($subtype == 'album') {
-                       ?>
-               <p>
-                       <label><?php echo elgg_echo('album:desc'); ?></label>
-                               <?php  echo elgg_view("input/longtext",array("internalname" => "tidypicsbody","value" => $body,)); ?>
-               </p>
-                       <?php
-               } else {
-                       ?>
-               <p>
-                       <label><?php echo elgg_echo('caption'); ?></label>
-                               <?php  echo elgg_view("input/longtext",array("internalname" => "tidypicsbody","value" => $body,"class" => 'tidypics_caption_input')); ?>
-               </p>
-                       <?php
-               }
-               ?>
-               <p>
-                       <label><?php echo elgg_echo("tags"); ?></label>
-                       <?php  echo elgg_view("input/tags", array( "internalname" => "tidypicstags","value" => $tags,));  ?>
-               </p>
-
-               <?php
-               if ($subtype == 'image') {
-                       $container_guid = $vars['entity']->container_guid;
-
-                       // should this image be the cover for the album - only ask for non-cover photos
-                       // determine if it is already the cover
-                       $img_guid = $vars['entity']->guid;
-                       $album = get_entity($container_guid);
-                       $cover_guid = $album->getCoverImageGuid();
-
-                       if ($cover_guid != $img_guid) {
-
-                               ?>
-               <p>
-                                       <?php                   echo elgg_view('input/checkboxes', array('internalname' => "cover",
-                                       'options' => array(elgg_echo("album:cover")),
-                                       ));
-                                       ?>
-               </p>
-                               <?php
-                       }
-
-               } else {
-                       // album so display access control
-
-                       $categories = elgg_view('categories',$vars);
-                       if (!empty($categories)) {
-                               ?>
-               <p>
-                                       <?php echo $categories; ?>
-               </p>
-
-                               <?php
-                       }
-                       ?>
-               <p>
-                       <label><?php echo elgg_echo('access'); ?></label>
-                               <?php echo elgg_view('input/access', array('internalname' => 'access_id','value' => $access_id)); ?>
-               </p>
-
-                       <?php
-               }
-
-               if (isset($vars['entity'])) {
-                       ?>
-               <input type="hidden" name="guid" value="<?php echo $vars['entity']->getGUID(); ?>" />
-                       <?php
-               }
-
-               echo elgg_view('input/securitytoken');
-               ?>
-               <input type="hidden" name="container_guid" value="<?php echo $container_guid; ?>" />
-               <input type="hidden" name="subtype" value="<?php echo $subtype; ?>" />
-               <p><input type="submit" name="submit" value="<?php echo elgg_echo('save'); ?>" /></p>
-       </form>
-</div>
\ No newline at end of file