+++ /dev/null
-<?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);
--- /dev/null
+<?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());
}
/**
- * 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;
}
/**
return parent::delete();
}
+ /**
+ * Get the title of the photo album
+ *
+ * @return string
+ */
+ public function getTitle() {
+ return $this->title;
+ }
+
/**
* Get an array of image objects
*
'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",
);
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;
+}
/*********************************************************************
+++ /dev/null
-<?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);
+++ /dev/null
-<?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));
--- /dev/null
+<?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);
--- /dev/null
+<?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);
$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());
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");
}
/**
- * 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
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
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]);
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
--- /dev/null
+<?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>
+++ /dev/null
-<?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