]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
added editing of images
authorCash Costello <cash.costello@gmail.com>
Wed, 23 Nov 2011 21:50:04 +0000 (16:50 -0500)
committerCash Costello <cash.costello@gmail.com>
Wed, 23 Nov 2011 21:50:04 +0000 (16:50 -0500)
13 files changed:
actions/photos/image/save.php [new file with mode: 0644]
classes/TidypicsAlbum.php
classes/TidypicsImage.php
languages/en.php
lib/resize.php
lib/upload.php
pages/photos/album/edit.php
pages/photos/all.php
pages/photos/friends.php
pages/photos/image/edit.php [new file with mode: 0644]
pages/photos/owner.php
start.php
views/default/forms/photos/image/save.php [new file with mode: 0644]

diff --git a/actions/photos/image/save.php b/actions/photos/image/save.php
new file mode 100644 (file)
index 0000000..535ae8b
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Save image 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');
+$guid = get_input('guid');
+
+elgg_make_sticky_form('tidypics');
+
+if (empty($title)) {
+       register_error(elgg_echo("album:blank"));
+       forward(REFERER);
+}
+
+$image = get_entity($guid);
+
+$image->access_id = $access_id;
+$image->title = $title;
+$image->description = $description;
+if ($tags) {
+       $image->tags = string_to_tag_array($tags);
+}
+
+if (!$image->save()) {
+       register_error(elgg_echo("image:error"));
+       forward(REFERER);
+}
+
+elgg_clear_sticky_form('tidypics');
+
+system_message(elgg_echo("image:saved"));
+forward($image->getURL());
index f1fd20669a093272b65d2f7dcfa2dfb5d2211700..f85b66d7256b8bfddd4f9767d20b5d40821c9e82 100644 (file)
@@ -71,6 +71,17 @@ class TidypicsAlbum extends ElggObject {
                return $this->title;
        }
 
+       /**
+        * Get the URL for this album
+        * 
+        * @return string
+        */
+       public function getURL() {
+               $title = elgg_get_friendly_title($this->getTitle());
+               $url = "photos/album/$this->guid/$title";
+               return elgg_normalize_url($url);
+       }
+
        /**
         * Get an array of image objects
         *
index c604d869edd5bf28016360d6cd2cc639593eec13..926bc386b07eedb196bc747c3e30024f521adcb4 100644 (file)
@@ -9,8 +9,8 @@
 
 
 class TidypicsImage extends ElggFile {
-       protected function initialise_attributes() {
-               parent::initialise_attributes();
+       protected function initializeAttributes() {
+               parent::initializeAttributes();
 
                $this->attributes['subtype'] = "image";
        }
@@ -51,6 +51,17 @@ class TidypicsImage extends ElggFile {
                return $this->title;
        }
 
+       /**
+        * Get the URL for the web page of this image
+        * 
+        * @return string
+        */
+       public function getURL() {
+               $title = elgg_get_friendly_title($this->getTitle());
+               $url = "photos/image/$this->guid/$title";
+               return elgg_normalize_url($url);
+       }
+
        /**
         * Get the src URL for the image
         * 
@@ -312,7 +323,7 @@ class TidypicsImage extends ElggFile {
         * @param $viewer_guid the guid of the viewer (0 if not logged in)
         * @return array with number of views, number of unique viewers, and number of views for this viewer
         */
-       public function getViews($viewer_guid) {
+       public function getViewCount($viewer_guid) {
                $views = get_annotations($this->getGUID(), "object", "image", "tp_view", "", 0, 99999);
                if ($views) {
                        $total_views = count($views);
index 58055039c7b2b41a53dc18dc34594ef596f00b58..96b63c170bb579d3ed6be0734819ec26a86de3c9 100644 (file)
@@ -53,6 +53,7 @@ $english = array(
                        'tidypics:nophotosingroup' => 'This groups does not have any photos yet',
                        'tidypics:upgrade' => 'Upgrade',
                        'tidypics:sort' => 'Sorting the %s album',
+                       'tidypics:none' => 'No photo albums',
                        
                //settings
                        'tidypics:settings' => 'Settings',
index 857d0ba1cc93dffc8f5eb8a16a864f6e2c051e93..78b5290e6199e38c7472d11926f48d96a7cbe170 100644 (file)
@@ -19,11 +19,11 @@ include dirname(__FILE__) . "/watermark.php";
 function tp_create_gd_thumbnails($file, $prefix, $filestorename) {
        global $CONFIG;
 
-       $image_sizes = get_plugin_setting('image_sizes', 'tidypics');
+       $image_sizes = elgg_get_plugin_setting('image_sizes', 'tidypics');
        if (!$image_sizes) {
                // move this out of library
                register_error(elgg_echo('tidypics:nosettings'));
-               forward($_SERVER['HTTP_REFERER']);
+               forward(REFERER);
                return FALSE;
        }
        $image_sizes = unserialize($image_sizes);
@@ -38,8 +38,8 @@ function tp_create_gd_thumbnails($file, $prefix, $filestorename) {
        $rtn_code = tp_gd_resize(       $file->getFilenameOnFilestore(),
                                                                $thumbname,
                                                                FALSE,
-                                                               $image_sizes['thumb_image_width'],
-                                                               $image_sizes['thumb_image_height'],
+                                                               $image_sizes['tiny_image_width'],
+                                                               $image_sizes['tiny_image_height'],
                                                                TRUE);
        if (!$rtn_code) {
                return FALSE;
@@ -209,8 +209,8 @@ function tp_create_imagick_thumbnails($file, $prefix, $filestorename) {
        $thumbname = $thumb->getFilenameOnFilestore();
        $rtn_code = tp_imagick_resize(  $file->getFilenameOnFilestore(),
                                                                        $thumbname,
-                                                                       $image_sizes['thumb_image_width'],
-                                                                       $image_sizes['thumb_image_height'],
+                                                                       $image_sizes['tiny_image_width'],
+                                                                       $image_sizes['tiny_image_height'],
                                                                        TRUE);
        if (!$rtn_code) {
                return FALSE;
@@ -335,8 +335,8 @@ function tp_create_im_cmdline_thumbnails($file, $prefix, $filestorename) {
        $thumbname = $thumb->getFilenameOnFilestore();
        $rtn_code = tp_im_cmdline_resize(       $file->getFilenameOnFilestore(),
                                                                                $thumbname,
-                                                                               $image_sizes['thumb_image_width'],
-                                                                               $image_sizes['thumb_image_height'],
+                                                                               $image_sizes['tiny_image_width'],
+                                                                               $image_sizes['tiny_image_height'],
                                                                                TRUE);
        if (!$rtn_code) {
                return FALSE;
index 30540dced2df11826b0d033f43ed8547be2c4dda..0b034517c495c5e3c7bc4ff22d809c00d20d3f40 100644 (file)
@@ -82,7 +82,7 @@ function tp_upload_memory_check($image_lib, $num_pixels) {
  * @return bool false = too large
  */
 function tp_upload_check_max_size($image_size) {
-       $max_file_size = (float) get_plugin_setting('maxfilesize','tidypics');
+       $max_file_size = (float) elgg_get_plugin_setting('maxfilesize', 'tidypics');
        if (!$max_file_size) {
                // default to 5 MB if not set
                $max_file_size = 5;
@@ -103,7 +103,7 @@ function tp_upload_check_quota($image_size, $owner_guid) {
        static $quota;
        
        if (!isset($quota)) {
-               $quota = get_plugin_setting('quota','tidypics');
+               $quota = elgg_get_plugin_setting('quota', 'tidypics');
                $quota = 1024 * 1024 * $quota;
        }
 
index 6fff50b29ae017d064fffcca996adf69b7922ffa..7efb05ce11fc9636769d14b2f8b2b418815d1ce7 100644 (file)
@@ -33,6 +33,7 @@ if (elgg_instanceof($owner, 'user')) {
 } else {
        elgg_push_breadcrumb($owner->name, "photos/group/$owner->guid/all");
 }
+elgg_push_breadcrumb($entity->getTitle(), $entity->getURL());
 elgg_push_breadcrumb($title);
 
 $vars = tidypics_prepare_form_vars($entity);
index edda65ce0ef094d6f6c78eb93cbbfe6f6976fb0f..aef7f11c6a76d61fff4ddd813e928e4682085a50 100644 (file)
@@ -10,7 +10,6 @@ elgg_push_breadcrumb(elgg_echo('photos'));
 
 $num_albums = 16;
 
-elgg_push_context('tidypics:main');
 $offset = (int)get_input('offset', 0);
 $content = elgg_list_entities(array(
        'type' => 'object',
@@ -21,7 +20,9 @@ $content = elgg_list_entities(array(
        'list_type_toggle' => false,
        'gallery_class' => 'tidypics-gallery',
 ));
-elgg_pop_context();
+if (!$content) {
+       $content = elgg_echo('tidypics:none');
+}
 
 $title = elgg_echo('album:all');
 
index b7b6178c5e70338efa1eabb2dc7001e40b3e5bb0..e6ac49cc6ae6d924904942894bdf34a1e095e432 100644 (file)
@@ -17,10 +17,11 @@ $title = elgg_echo('album:friends');
 
 $num_albums = 16;
 
-elgg_push_context('tidypics:main');
 set_input('list_type', 'gallery');
 $content = list_user_friends_objects($owner->guid, 'album', $num_albums, false);
-elgg_pop_context();
+if (!$content) {
+       $content = elgg_echo('tidypics:none');
+}
 
 elgg_register_title_button();
 
diff --git a/pages/photos/image/edit.php b/pages/photos/image/edit.php
new file mode 100644 (file)
index 0000000..76c1381
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Edit an image
+ *
+ * @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($entity->getContainerEntity()->getURL());
+}
+
+$album = $entity->getContainerEntity();
+if (!$album) {
+
+}
+
+elgg_set_page_owner_guid($album->getContainerGUID());
+$owner = elgg_get_page_owner_entity();
+
+gatekeeper();
+group_gatekeeper();
+
+$title = elgg_echo('image: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($album->getTitle(), $album->getURL());
+elgg_push_breadcrumb($entity->getTitle(), $entity->getURL());
+elgg_push_breadcrumb($title);
+
+$vars = tidypics_prepare_form_vars($entity);
+$content = elgg_view_form('photos/image/save', array('method' => 'post'), $vars);
+
+$body = elgg_view_layout('content', array(
+       'content' => $content,
+       'title' => $title,
+       'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
index 214cd2e37248c78d5dc508a3c4734cc92454609a..506cb569bb814f0519c2582e398b69027f6fcaef 100644 (file)
@@ -10,7 +10,6 @@ group_gatekeeper();
 
 $owner = elgg_get_page_owner_entity();
 
-//set the title
 $title = elgg_echo('album:user', array($owner->name));
 
 // set up breadcrumbs
@@ -20,7 +19,6 @@ elgg_push_breadcrumb($owner->name);
 
 $num_albums = 16;
 
-elgg_push_context('tidypics:main');
 $content = elgg_list_entities(array(
        'type' => 'object',
        'subtype' => 'album',
@@ -31,7 +29,9 @@ $content = elgg_list_entities(array(
        'list_type_toggle' => false,
        'gallery_class' => 'tidypics-gallery',
 ));
-elgg_pop_context();
+if (!$content) {
+       $content = elgg_echo('tidypics:none');
+}
 
 elgg_register_title_button();
 
index 056c1739a89d104f3e87ee50f5ede814d8cae0ac..1c548b90b5003b852a4b0028b9a8dba40bf9e586 100644 (file)
--- a/start.php
+++ b/start.php
@@ -23,6 +23,9 @@ function tidypics_init() {
                'text' => elgg_echo('photos'),
        ));
 
+       // Register a page handler so we can have nice URLs
+       elgg_register_page_handler('photos', 'tidypics_page_handler');
+
        // Extend CSS
        elgg_extend_view('css/elgg', 'tidypics/css');
        elgg_extend_view('css/admin', 'tidypics/css');
@@ -33,6 +36,13 @@ function tidypics_init() {
        // Add admin menu item
        elgg_register_admin_menu_item('configure', 'tidypics', 'settings');
 
+       // Register for search
+       elgg_register_entity_type('object', 'image');
+       elgg_register_entity_type('object', 'album');
+
+       // Register for the entity menu
+       elgg_register_plugin_hook_handler('register', 'menu:entity', 'tidypics_entity_menu_setup');
+
 /*
        // Extend hover-over and profile menu
        elgg_extend_view('profile/menu/links','tidypics/hover_menu');
@@ -44,8 +54,6 @@ function tidypics_init() {
        elgg_extend_view('extensions/xmlns', 'extensions/tidypics/xmlns');
        elgg_extend_view('extensions/channel', 'extensions/tidypics/channel');
 
-       // Register a page handler so we can have nice URLs
-       elgg_register_page_handler('photos', 'tidypics_page_handler');
 
        // register for menus
        //register_elgg_event_handler('pagesetup', 'system', 'tidypics_submenus');
@@ -59,14 +67,6 @@ function tidypics_init() {
        register_entity_url_handler('tidypics_image_url', 'object', 'image');
        register_entity_url_handler('tidypics_album_url', 'object', 'album');
 
-       // add the class files for image and album
-       add_subtype("object", "image", "TidypicsImage");
-       add_subtype("object", "album", "TidypicsAlbum");
-
-       // Register entity type
-       register_entity_type('object','image');
-       register_entity_type('object','album');
-
        add_group_tool_option('photos', elgg_echo('tidypics:enablephotos'), true);
 
        if (get_plugin_setting('grp_perm_override', 'tidypics') != "disabled") {
@@ -88,21 +88,22 @@ function tidypics_init() {
        elgg_register_action("photos/album/save", "$base_dir/album/save.php");
        elgg_register_action("photos/delete", "$base_dir/delete.php");
        elgg_register_action("photos/image/upload", "$base_dir/image/upload.php");
+       elgg_register_action("photos/image/save", "$base_dir/image/save.php");
        elgg_register_action("photos/batch/edit", "$base_dir/batch/edit.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/sortalbum", false, "$base_dir/sortalbum.php");
-       register_action("tidypics/edit", false, "$base_dir/edit.php");
-       register_action("tidypics/addtag", false, "$base_dir/addtag.php");
-       register_action("tidypics/deletetag", false, "$base_dir/deletetag.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/sortalbum", false, "$base_dir/sortalbum.php");
+       //register_action("tidypics/edit", false, "$base_dir/edit.php");
+       //register_action("tidypics/addtag", false, "$base_dir/addtag.php");
+       //register_action("tidypics/deletetag", false, "$base_dir/deletetag.php");
 
        elgg_register_action("photos/admin/settings", "$base_dir/admin/settings.php", 'admin');
-       register_action("tidypics/admin/upgrade", false, "$base_dir/admin/upgrade.php", true);
+       //register_action("tidypics/admin/upgrade", false, "$base_dir/admin/upgrade.php", true);
 
        // Register libraries
        $base_dir = elgg_get_plugins_path() . 'tidypics/lib';
-       elgg_register_library('tidypics:upload', "$base/upload.php");
-       elgg_register_library('tidypics:resize', "$base/resize.php");
+       elgg_register_library('tidypics:upload', "$base_dir/upload.php");
+       elgg_register_library('tidypics:resize', "$base_dir/resize.php");
 }
 
 /**
@@ -264,7 +265,7 @@ function tidypics_page_handler($page) {
        }
 
        $base = elgg_get_plugins_path() . 'tidypics/pages/photos';
-       switch($page[0]) {
+       switch ($page[0]) {
                case "all": // all site albums
                case "world":
                        require "$base/all.php";
@@ -301,6 +302,9 @@ function tidypics_page_handler($page) {
                                case 'album':
                                        require "$base/album/edit.php";
                                        break;
+                               case 'image':
+                                       require "$base/image/edit.php";
+                                       break;
                                case 'tidypics_batch':
                                        require "$base/batch/edit.php";
                                        break;
@@ -414,6 +418,36 @@ function tidypics_owner_block_menu($hook, $type, $return, $params) {
        return $return;
 }
 
+/**
+ * Add particular blog links/info to entity menu
+ */
+function tidypics_entity_menu_setup($hook, $type, $return, $params) {
+       if (elgg_in_context('widgets')) {
+               return $return;
+       }
+
+       $entity = $params['entity'];
+       $handler = elgg_extract('handler', $params, false);
+       if ($handler != 'photos') {
+               return $return;
+       }
+
+       if (elgg_instanceof($entity, 'object', 'image')) {
+               if (elgg_get_plugin_setting('view_count', 'tidypics')) {
+                       $status_text = '27 views';
+                       $options = array(
+                               'name' => 'published_status',
+                               'text' => "<span>$status_text</span>",
+                               'href' => false,
+                               'priority' => 90,
+                       );
+                       $return[] = ElggMenuItem::factory($options);
+               }
+       }
+
+       return $return;
+}
+
 /**
  * Override permissions for group albums and images
  *
diff --git a/views/default/forms/photos/image/save.php b/views/default/forms/photos/image/save.php
new file mode 100644 (file)
index 0000000..47a0864
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Save image 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>