]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
improved the upgrade system and moved albums to use an ordered list for images
authorCash Costello <cash.costello@gmail.com>
Sat, 31 Jul 2010 19:22:47 +0000 (19:22 +0000)
committerCash Costello <cash.costello@gmail.com>
Sat, 31 Jul 2010 19:22:47 +0000 (19:22 +0000)
13 files changed:
actions/admin/upgrade.php [new file with mode: 0644]
actions/upgrade.php [deleted file]
actions/upload.php
lib/album.php
start.php
upgrades/2009082901.php [new file with mode: 0644]
upgrades/2010073101.php [new file with mode: 0644]
version.php [new file with mode: 0644]
views/default/object/album.php
views/default/object/image.php
views/default/tidypics/admin/settings.php
views/default/tidypics/admin/upgrade.php [new file with mode: 0644]
views/default/tidypics/forms/settings.php

diff --git a/actions/admin/upgrade.php b/actions/admin/upgrade.php
new file mode 100644 (file)
index 0000000..9c4aef1
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Tidypics upgrade action
+ */
+require_once "{$CONFIG->pluginspath}tidypics/version.php";
+
+$local_version = get_plugin_setting('version', 'tidypics');
+
+if ($version <= $local_version) {
+       register_error('No upgrade required');
+       forward($_SERVER['HTTP_REFERER']);
+}
+
+$base_dir = $CONFIG->pluginspath . 'tidypics/upgrades';
+
+// taken from engine/lib/version.php
+if ($handle = opendir($base_dir)) {
+       $upgrades = array();
+
+       while ($updatefile = readdir($handle)) {
+               // Look for upgrades and add to upgrades list
+               if (!is_dir("$base_dir/$updatefile")) {
+                       if (preg_match('/^([0-9]{10})\.(php)$/', $updatefile, $matches)) {
+                               $plugin_version = (int) $matches[1];
+                               if ($plugin_version > $local_version) {
+                                       $upgrades[] = "$base_dir/$updatefile";
+                               }
+                       }
+               }
+       }
+
+       // Sort and execute
+       asort($upgrades);
+
+       if (sizeof($upgrades) > 0) {
+               foreach ($upgrades as $upgrade) {
+                       include($upgrade);
+               }
+       }
+}
+
+set_plugin_setting('version', $version, 'tidypics');
+
+system_message("Tidypics has been upgraded");
+
+forward($_SERVER['HTTP_REFERER']);
diff --git a/actions/upgrade.php b/actions/upgrade.php
deleted file mode 100644 (file)
index 596b90a..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-/********************************************
- *
- * Upgrade from Tidypics 1.5 to 1.6
- *
- *********************************************/
-
-include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php";
-
-admin_gatekeeper();
-
-$result = true;
-
-// add image class
-$id = get_subtype_id("object", "image"); 
-if ($id != 0) {
-       $table = $CONFIG->dbprefix . 'entity_subtypes';
-       $result = update_data("UPDATE {$table} set class='TidypicsImage' where id={$id}");
-       if (!result) {
-               register_error(elgg_echo('tidypics:upgrade:failed'));
-               forward($_SERVER['HTTP_REFERER']);
-       }
-}
-
-// add album class
-$id = get_subtype_id("object", "album"); 
-if ($id != 0) {
-       $table = $CONFIG->dbprefix . 'entity_subtypes';
-       $result = update_data("UPDATE {$table} set class='TidypicsAlbum' where id={$id}");
-       if (!result) {
-               register_error(elgg_echo('tidypics:upgrade:failed'));
-               forward($_SERVER['HTTP_REFERER']);
-       }
-}
-
-system_message(elgg_echo('tidypics:upgrade:success'));
-
-forward($_SERVER['HTTP_REFERER']);
index b1eb4efe13848d3ae40fb314ee0d2c22064868e5..88b0007063dd5d2c27db2a25059bda9b95fce12c 100644 (file)
@@ -244,6 +244,10 @@ if (count($uploaded_images) && $img_river_view == "1") {
 // update image repo size
 create_metadata($album->container_guid, "image_repo_size", $image_repo_size, 'integer', $album->container_guid);
 
+if (count($uploaded_images) > 0) {
+       $album->prependImageList($uploaded_images);
+}
+
 // plugins can register to be told when a Tidypics album has had images added
 trigger_elgg_event('upload', 'tp_album', $album);
 
index 1eaabd3ba4c3feb116d4173950f1fbda62d52c3c..87bb715f42292dd80a2e5d5bb8167f333febaa13 100644 (file)
@@ -17,12 +17,61 @@ class TidypicsAlbum extends ElggObject {
                parent::__construct($guid);
        }
 
+       /**
+        * Get an array of image objects
+        *
+        * @param int $limit
+        * @param int $offset
+        * @return array
+        */
+       public function getImages($limit, $offset=0) {
+               $imageList = $this->getImageList();
+               if ($offset > count($imageList)) {
+                       return array();
+               }
+
+               $imageList = array_slice($imageList, $offset, $limit);
+               
+               $images = array();
+               foreach ($imageList as $guid) {
+                       $images[] = get_entity($guid);
+               }
+               return $images;
+       }
+
+       /**
+        * View a list of images
+        *
+        * @param int $limit
+        * @param int $offset
+        * @return string
+        */
+       public function viewImages($limit, $offset=0) {
+               $images = $this->getImages($limit, $offset);
+               if (count($images) == 0) {
+                       return '';
+               }
+
+               $count = $this->getSize();
+
+               return elgg_view_entity_list($images, $count, $offset, $limit, FALSE, FALSE, TRUE);
+       }
+
+       /**
+        * Get the number of photos in the album
+        *
+        * @return int
+        */
+       public function getSize() {
+               return count($this->getImageList());
+       }
+
        /**
         * Returns an order list of image guids
         * 
         * @return array
         */
-       public function getOrderedImageList() {
+       public function getImageList() {
                $listString = $this->orderedImages;
                if (!$listString) {
                        return array();
@@ -36,7 +85,7 @@ class TidypicsAlbum extends ElggObject {
         *
         * @param array $list An indexed array of image guids 
         */
-       public function setOrderedImageList($list) {
+       public function setImageList($list) {
                $listString = serialize($list);
                $this->orderedImages = $listString;
        }
@@ -46,9 +95,47 @@ class TidypicsAlbum extends ElggObject {
         *
         * @param array $list An indexed array of image guids
         */
-       public function prependOrderedImageList($list) {
-               $currentList = $this->getOrderedImageList();
+       public function prependImageList($list) {
+               $currentList = $this->getImageList();
                $list = array_merge($list, $currentList);
-               $this->setOrderedImageList($list);
+               $this->setImageList($list);
+       }
+
+       /**
+        * Get the GUID of the image before the current one
+        *
+        * @param int $currentGuid
+        * @return int
+        */
+       public function getPreviousImageGuid($currentGuid) {
+               $imageList = $this->getImageList();
+               $key = array_search($currentGuid, $imageList);
+               if ($key === FALSE) {
+                       return 0;
+               }
+               $key--;
+               if ($key < 0) {
+                       return 0;
+               }
+               return $imageList[$key];
+       }
+
+       /**
+        * Get the GUID of the image after the current one
+        *
+        * @param int $currentGuid
+        * @return int
+        */
+       public function getNextImageGuid($currentGuid) {
+               $imageList = $this->getImageList();
+               $key = array_search($currentGuid, $imageList);
+               if ($key === FALSE) {
+                       return 0;
+               }
+               $key++;
+               if ($key >= count($imageList)) {
+                       return 0;
+               }
+               return $imageList[$key];
        }
 }
index 8589be9fba9770eec087be77b06477d30175fd86..52d56d77aacb5ca1f000a512bcf3abec9695bed3 100644 (file)
--- a/start.php
+++ b/start.php
@@ -461,3 +461,4 @@ register_action("tidypics/edit_multi", false, $CONFIG->pluginspath. "tidypics/ac
 register_action("tidypics/addtag", true, $CONFIG->pluginspath . "tidypics/actions/addtag.php");
 register_action("tidypics/deletetag", true, $CONFIG->pluginspath . "tidypics/actions/deletetag.php");
 register_action("tidypics/flickrSetup", true, $CONFIG->pluginspath . "tidypics/actions/flickrSetup.php");
+register_action("tidypics/admin/upgrade", true, $CONFIG->pluginspath . "tidypics/actions/admin/upgrade.php", true);
diff --git a/upgrades/2009082901.php b/upgrades/2009082901.php
new file mode 100644 (file)
index 0000000..dfbdf79
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+/********************************************
+ *
+ * Upgrade from Tidypics 1.5 to 1.6
+ *
+ *********************************************/
+
+global $CONFIG;
+
+// add image class
+$id = get_subtype_id("object", "image");
+if ($id != 0) {
+       $table = $CONFIG->dbprefix . 'entity_subtypes';
+       $result = update_data("UPDATE {$table} set class='TidypicsImage' where id={$id}");
+       if (!$result) {
+               register_error('unable to update tidypics image class');
+       }
+}
+
+// add album class
+$id = get_subtype_id("object", "album");
+if ($id != 0) {
+       $table = $CONFIG->dbprefix . 'entity_subtypes';
+       $result = update_data("UPDATE {$table} set class='TidypicsAlbum' where id={$id}");
+       if (!$result) {
+               register_error('unable to update tidypics album class');
+       }
+}
diff --git a/upgrades/2010073101.php b/upgrades/2010073101.php
new file mode 100644 (file)
index 0000000..20fd331
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Populate image lists for current photo albums
+ */
+
+$album_subtype_id = get_subtype_id('object', 'album');
+
+global $DB_QUERY_CACHE, $DB_PROFILE, $ENTITY_CACHE, $CONFIG;
+$album_guids = mysql_query("SELECT guid FROM {$CONFIG->dbprefix}entities WHERE subtype = $album_subtype_id");
+while ($guid_obj = mysql_fetch_object($album_guids)) {
+       $DB_QUERY_CACHE = $DB_PROFILE = $ENTITY_CACHE = array();
+
+       $album = get_entity($guid_obj->guid);
+       $images = get_entities("object", "image", $album->guid, '', 9999);
+       $image_list = array();
+       foreach ($images as $image) {
+               $image_list[] = $image->guid;
+       }
+
+       $album->prependImageList($image_list);
+}
+
diff --git a/version.php b/version.php
new file mode 100644 (file)
index 0000000..557ea5d
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+
+/**
+ * Version of this plugin.
+ * Used for the upgrade system.
+ */
+
+$version = 2010073101;
index 0db0d3e49dbe097c13b59ba0636d0e28fbdd1732..b87bef44405a32b1094a2a23188d8d96b079309b 100644 (file)
@@ -106,24 +106,11 @@ if (get_context() == "search") {
 <?php
        echo '<div id="tidypics_desc">' . autop($desc) . '</div>';
 
-       $images = get_entities("object", "image", $album_guid, '', 999);
-
-       //build array for back | next links
-       $_SESSION['image_sort'] = array();
-
-       if (is_array($images)) {
-               foreach ($images as $image) {
-                       array_push($_SESSION['image_sort'], $image->guid);
-               }
-
-               // display the simple image views. Uses 'object/image' view
-               echo list_entities("object", "image", $album_guid, 24, false);
-
-               $num_images = count($images);
-       } else {
-               echo '<div class="tidypics_info">' . elgg_echo('image:none') . '</div>';
-               $num_images = 0;
-       }
+       $offset = (int)get_input('offset', 0);
+       echo $album->viewImages(8, $offset);
+       //      echo '<div class="tidypics_info">' . elgg_echo('image:none') . '</div>';
+       //      $num_images = 0;
+       //}
 
 ?>
        <div class="clearfloat"></div>
@@ -137,7 +124,7 @@ if (get_context() == "search") {
        }
 ?>
        <?php echo elgg_echo('album:by');?> <b><a href="<?php echo $vars['url'] ;?>pg/profile/<?php echo $owner->username; ?>"><?php echo $owner->name; ?></a></b>  <?php echo $friendlytime; ?><br>
-       <?php echo elgg_echo('image:total');?> <b><?php echo $num_images; ?></b><br>
+       <?php echo elgg_echo('image:total');?> <b><?php echo $album->getSize(); ?></b><br>
 <?php
        $categories = elgg_view('categories/view',$vars);
        if (!empty($categories)) {
index cd53120dee88a2591244778b37c1ecb44c5e56b0..da3e257a1e09cd63b571edae776481607a83b63e 100644 (file)
@@ -94,32 +94,18 @@ if (get_context() == "search") {
                // Build back and next links
                $back = '';
                $next = '';
-
                $album = get_entity($image->container_guid);
+               $back_guid = $album->getPreviousImageGuid($image->guid);
+               $next_guid = $album->getNextImageGuid($image->guid);
 
-               $current = array_search($image_guid, $_SESSION['image_sort']);
-
-               if (!$current) {  // means we are no longer using the correct album array
-
-                       //rebuild the array
-                       $count = get_entities("object","image", $album->guid, '', 999);
-                       $_SESSION['image_sort'] = array();
-
-                       foreach ($count as $img) {
-                               array_push($_SESSION['image_sort'], $img->guid);
-                       }
-
-                       if ($_SESSION['image_sort']) {
-                               $current = array_search($image_guid, $_SESSION['image_sort']);
-                       }
-               }
-
-               if ($current != 0) {
-                       $back = '<a href="' .$vars['url'] . 'pg/photos/view/' . $_SESSION['image_sort'][$current-1] . '">&laquo; ' . elgg_echo('image:back') . '</a>';
+               if ($back_guid != 0) {
+                       $text = elgg_echo('image:back');
+                       $back = "<a href=\"{$vars['url']}pg/photos/view/$back_guid\">&laquo; $text</a>";
                }
 
-               if (sizeof($_SESSION['image_sort']) > $current + 1) {
-                       $next = '<a href="' . $vars['url'] . 'pg/photos/view/' . $_SESSION['image_sort'][$current+1] . '">' . elgg_echo('image:next') . ' &raquo;</a>';
+               if ($next_guid != 0) {
+                       $text = elgg_echo('image:next');
+                       $next = "<a href=\"{$vars['url']}pg/photos/view/$next_guid\">$text &raquo;</a>";
                }
 
 ?>
index 60c34b64eaac8ad261a6db5ee3b8319210c89c4b..6dace18300e7b3929b4bf54a515f826b8bb3da85 100644 (file)
@@ -7,8 +7,7 @@ echo elgg_view('output/longtext', array('value' => elgg_echo("tidypics:admin:ins
 <?php
 echo elgg_view('tidypics/admin/upgrade');
 
-global $CONFIG;
-$url = $CONFIG->wwwroot . 'mod/tidypics/pages/server_analysis.php';
+$url = "{$vars['url']}mod/tidypics/pages/server_analysis.php";
 $text = elgg_echo('tidypics:settings:server:analysis');
 
 echo "<a href=\"$url\">$text</a>";
diff --git a/views/default/tidypics/admin/upgrade.php b/views/default/tidypics/admin/upgrade.php
new file mode 100644 (file)
index 0000000..5a21aa1
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+require_once "{$CONFIG->pluginspath}tidypics/version.php";
+
+$upgrade_url = "{$vars['url']}action/tidypics/admin/upgrade";
+//$upgrade_url = elgg_add_action_tokens_to_url($upgrade_url);
+
+// determine whether an upgrade is required
+$local_version = get_plugin_setting('version', 'tidypics');
+if ($local_version === FALSE) {
+       // no version set so either new install or really old one
+       if (!get_subtype_class('object', 'image') || !get_subtype_class('object', 'album')) {
+               $local_version = 0;
+       } else {
+               set_plugin_setting('version', $local_version, 'tidypics');
+               $local_version = $version;
+       }
+} elseif ($local_version == '1.62') {
+       $local_version = 2010010101;
+       set_plugin_setting('version', $local_version, 'tidypics');
+}
+if ($local_version == $version) {
+       // no upgrade required
+       return TRUE;
+}
+
+echo elgg_view('output/url', array(    'text' => 'Upgrade',
+                                                                       'href' => $upgrade_url,
+                                                                       'is_action' => TRUE));
+echo '<br />';
\ No newline at end of file
index e7d05adcc27ea0ed5d411f53654bb8e6014ca5d7..c102b044e8a84369c57c556eb6f6ce890ac5bb8e 100644 (file)
@@ -10,12 +10,6 @@ $action = $vars['url'] . 'action/tidypics/settings';
 $plugin = find_plugin_settings('tidypics');
 
 
-// bootstrap the plugin version here for now
-if (!$plugin->version) {
-       set_plugin_setting('version', 1.62, 'tidypics');
-}
-
-
 // Main settings
 $form_body = '<h3>' . elgg_echo('tidypics:settings:heading:main') . '</h3>';