diff options
-rw-r--r-- | actions/addalbum.php | 57 | ||||
-rw-r--r-- | actions/photos/album/save.php | 48 | ||||
-rw-r--r-- | classes/TidypicsAlbum.php | 30 | ||||
-rw-r--r-- | languages/en.php | 2 | ||||
-rw-r--r-- | lib/tidypics.php | 31 | ||||
-rw-r--r-- | pages/edit.php | 54 | ||||
-rw-r--r-- | pages/newalbum.php | 30 | ||||
-rw-r--r-- | pages/photos/album/add.php | 34 | ||||
-rw-r--r-- | pages/photos/album/edit.php | 47 | ||||
-rw-r--r-- | pages/photos/album/view.php | 3 | ||||
-rw-r--r-- | pages/photos/image/upload.php (renamed from pages/upload.php) | 0 | ||||
-rw-r--r-- | start.php | 56 | ||||
-rw-r--r-- | views/default/forms/photos/admin/settings.php (renamed from views/default/forms/tidypics/admin/settings.php) | 0 | ||||
-rw-r--r-- | views/default/forms/photos/ajax_upload.php (renamed from views/default/forms/tidypics/ajax_upload.php) | 0 | ||||
-rw-r--r-- | views/default/forms/photos/album/save.php | 48 | ||||
-rw-r--r-- | views/default/forms/photos/basic_upload.php (renamed from views/default/forms/tidypics/basic_upload.php) | 0 | ||||
-rw-r--r-- | views/default/tidypics/forms/edit.php | 125 |
17 files changed, 267 insertions, 298 deletions
diff --git a/actions/addalbum.php b/actions/addalbum.php deleted file mode 100644 index 8ddcca131..000000000 --- a/actions/addalbum.php +++ /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 index 000000000..cc7181678 --- /dev/null +++ b/actions/photos/album/save.php @@ -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()); diff --git a/classes/TidypicsAlbum.php b/classes/TidypicsAlbum.php index 1fbdb8ad8..75a018410 100644 --- a/classes/TidypicsAlbum.php +++ b/classes/TidypicsAlbum.php @@ -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; } /** @@ -40,6 +51,15 @@ class TidypicsAlbum extends ElggObject { } /** + * Get the title of the photo album + * + * @return string + */ + public function getTitle() { + return $this->title; + } + + /** * Get an array of image objects * * @param int $limit diff --git a/languages/en.php b/languages/en.php index d6d934c20..63d4632c6 100644 --- a/languages/en.php +++ b/languages/en.php @@ -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", ); diff --git a/lib/tidypics.php b/lib/tidypics.php index 8fcfc22c9..7eedb246d 100644 --- a/lib/tidypics.php +++ b/lib/tidypics.php @@ -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 index 06d3dd9c4..000000000 --- a/pages/edit.php +++ /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 index 535116237..000000000 --- a/pages/newalbum.php +++ /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 index 000000000..d34d39177 --- /dev/null +++ b/pages/photos/album/add.php @@ -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 index 000000000..6fff50b29 --- /dev/null +++ b/pages/photos/album/edit.php @@ -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); diff --git a/pages/photos/album/view.php b/pages/photos/album/view.php index adb5a1b51..aafcf14bc 100644 --- a/pages/photos/album/view.php +++ b/pages/photos/album/view.php @@ -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()); diff --git a/pages/upload.php b/pages/photos/image/upload.php index 6580c6f52..6580c6f52 100644 --- a/pages/upload.php +++ b/pages/photos/image/upload.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/tidypics/admin/settings.php b/views/default/forms/photos/admin/settings.php index 06b3f4cb9..06b3f4cb9 100644 --- a/views/default/forms/tidypics/admin/settings.php +++ b/views/default/forms/photos/admin/settings.php diff --git a/views/default/forms/tidypics/ajax_upload.php b/views/default/forms/photos/ajax_upload.php index a1d13e80b..a1d13e80b 100644 --- a/views/default/forms/tidypics/ajax_upload.php +++ b/views/default/forms/photos/ajax_upload.php diff --git a/views/default/forms/photos/album/save.php b/views/default/forms/photos/album/save.php new file mode 100644 index 000000000..8a1202c07 --- /dev/null +++ b/views/default/forms/photos/album/save.php @@ -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/forms/tidypics/basic_upload.php b/views/default/forms/photos/basic_upload.php index 55ab854a4..55ab854a4 100644 --- a/views/default/forms/tidypics/basic_upload.php +++ b/views/default/forms/photos/basic_upload.php diff --git a/views/default/tidypics/forms/edit.php b/views/default/tidypics/forms/edit.php deleted file mode 100644 index 8e2bd9bcc..000000000 --- a/views/default/tidypics/forms/edit.php +++ /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 |