diff options
-rw-r--r-- | actions/admin/upgrade.php | 46 | ||||
-rw-r--r-- | actions/upgrade.php | 39 | ||||
-rw-r--r-- | actions/upload.php | 4 | ||||
-rw-r--r-- | lib/album.php | 97 | ||||
-rw-r--r-- | start.php | 1 | ||||
-rw-r--r-- | upgrades/2009082901.php | 29 | ||||
-rw-r--r-- | upgrades/2010073101.php | 22 | ||||
-rw-r--r-- | version.php | 8 | ||||
-rw-r--r-- | views/default/object/album.php | 25 | ||||
-rw-r--r-- | views/default/object/image.php | 30 | ||||
-rw-r--r-- | views/default/tidypics/admin/settings.php | 3 | ||||
-rw-r--r-- | views/default/tidypics/admin/upgrade.php | 30 | ||||
-rw-r--r-- | views/default/tidypics/forms/settings.php | 6 |
13 files changed, 247 insertions, 93 deletions
diff --git a/actions/admin/upgrade.php b/actions/admin/upgrade.php new file mode 100644 index 000000000..9c4aef1cf --- /dev/null +++ b/actions/admin/upgrade.php @@ -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 index 596b90a22..000000000 --- a/actions/upgrade.php +++ /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']); diff --git a/actions/upload.php b/actions/upload.php index b1eb4efe1..88b000706 100644 --- a/actions/upload.php +++ b/actions/upload.php @@ -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); diff --git a/lib/album.php b/lib/album.php index 1eaabd3ba..87bb715f4 100644 --- a/lib/album.php +++ b/lib/album.php @@ -18,11 +18,60 @@ class TidypicsAlbum extends ElggObject { } /** + * 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]; } } @@ -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 index 000000000..dfbdf79f4 --- /dev/null +++ b/upgrades/2009082901.php @@ -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 index 000000000..20fd33144 --- /dev/null +++ b/upgrades/2010073101.php @@ -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 index 000000000..557ea5d1c --- /dev/null +++ b/version.php @@ -0,0 +1,8 @@ +<?php + +/** + * Version of this plugin. + * Used for the upgrade system. + */ + +$version = 2010073101; diff --git a/views/default/object/album.php b/views/default/object/album.php index 0db0d3e49..b87bef444 100644 --- a/views/default/object/album.php +++ b/views/default/object/album.php @@ -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)) { diff --git a/views/default/object/image.php b/views/default/object/image.php index cd53120de..da3e257a1 100644 --- a/views/default/object/image.php +++ b/views/default/object/image.php @@ -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] . '">« ' . elgg_echo('image:back') . '</a>'; + if ($back_guid != 0) { + $text = elgg_echo('image:back'); + $back = "<a href=\"{$vars['url']}pg/photos/view/$back_guid\">« $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') . ' »</a>'; + if ($next_guid != 0) { + $text = elgg_echo('image:next'); + $next = "<a href=\"{$vars['url']}pg/photos/view/$next_guid\">$text »</a>"; } ?> diff --git a/views/default/tidypics/admin/settings.php b/views/default/tidypics/admin/settings.php index 60c34b64e..6dace1830 100644 --- a/views/default/tidypics/admin/settings.php +++ b/views/default/tidypics/admin/settings.php @@ -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 index 000000000..5a21aa136 --- /dev/null +++ b/views/default/tidypics/admin/upgrade.php @@ -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 diff --git a/views/default/tidypics/forms/settings.php b/views/default/tidypics/forms/settings.php index e7d05adcc..c102b044e 100644 --- a/views/default/tidypics/forms/settings.php +++ b/views/default/tidypics/forms/settings.php @@ -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>'; |