summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/gallery_block.php12
-rw-r--r--modules/gallery/helpers/gallery_installer.php16
-rw-r--r--modules/gallery/helpers/upgrade_checker.php91
3 files changed, 117 insertions, 2 deletions
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index 1d92d66d..2189a710 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -25,7 +25,9 @@ class gallery_block_Core {
"log_entries" => t("Log entries"),
"stats" => t("Gallery stats"),
"platform_info" => t("Platform information"),
- "project_news" => t("Gallery project news"));
+ "project_news" => t("Gallery project news"),
+ "upgrade_checker" => t("Check for Gallery upgrades")
+ );
}
static function get_site_list() {
@@ -101,6 +103,14 @@ class gallery_block_Core {
$block = "";
}
break;
+
+ case "upgrade_checker":
+ $block = new Block();
+ $block->css_id = "g-upgrade-available-block";
+ $block->title = t("Check for Gallery upgrades");
+ $block->content = new View("upgrade_checker_block.html");
+ $block->content->version_info = upgrade_checker::version_info();
+ $block->content->auto_check_enabled = upgrade_checker::auto_check_enabled();
}
return $block;
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 92e5b7b8..1ffe9bae 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -259,6 +259,7 @@ class gallery_installer {
module::set_var("gallery", "default_locale", "en_US");
module::set_var("gallery", "image_quality", 75);
module::set_var("gallery", "image_sharpen", 15);
+ module::set_var("gallery", "upgrade_checker_auto_enabled", true);
// Add rules for generating our thumbnails and resizes
graphics::add_rule(
@@ -285,6 +286,7 @@ class gallery_installer {
block_manager::add("dashboard_sidebar", "gallery", "platform_info");
block_manager::add("dashboard_sidebar", "gallery", "project_news");
block_manager::add("dashboard_center", "gallery", "welcome");
+ block_manager::add("dashboard_center", "gallery", "upgrade_checker");
block_manager::add("dashboard_center", "gallery", "photo_stream");
block_manager::add("dashboard_center", "gallery", "log_entries");
@@ -309,7 +311,7 @@ class gallery_installer {
module::set_var("gallery", "show_user_profiles_to", "registered_users");
module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
- module::set_version("gallery", 45);
+ module::set_version("gallery", 46);
}
static function upgrade($version) {
@@ -663,6 +665,18 @@ class gallery_installer {
$db->query("ALTER TABLE {messages} CHANGE `value` `value` text default NULL");
module::set_version("gallery", $version = 45);
}
+
+ if ($version == 45) {
+ // Splice the upgrade_checker block into the admin dashboard at the top
+ // of the page, but under the welcome block if it's in the first position.
+ $blocks = block_manager::get_active("dashboard_center");
+ $index = count($blocks) && current($blocks) == array("gallery", "welcome") ? 1 : 0;
+ array_splice($blocks, $index, 0, array(random::int() => array("gallery", "upgrade_checker")));
+ block_manager::set_active("dashboard_center", $blocks);
+
+ module::set_var("gallery", "upgrade_checker_auto_enabled", true);
+ module::set_version("gallery", $version = 46);
+ }
}
static function uninstall() {
diff --git a/modules/gallery/helpers/upgrade_checker.php b/modules/gallery/helpers/upgrade_checker.php
new file mode 100644
index 00000000..9311cf4a
--- /dev/null
+++ b/modules/gallery/helpers/upgrade_checker.php
@@ -0,0 +1,91 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2010 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class upgrade_checker_Core {
+ const CHECK_URL = "http://gallery.menalto.com/versioncheck/gallery3";
+
+ static function version_info() {
+ return unserialize(Cache::instance()->get("upgrade_checker_version_info"));
+ }
+
+ static function auto_check_enabled() {
+ return (bool)module::get_var("gallery", "upgrade_checker_auto_enabled");
+ }
+
+ static function fetch_version_info() {
+ $result = new stdClass();
+ try {
+ list ($status, $headers, $body) = remote::do_request(upgrade_checker::CHECK_URL);
+ if ($status == "HTTP/1.1 200 OK") {
+ $result->status = "success";
+ foreach (explode("\n", $body) as $line) {
+ if ($line) {
+ list($key, $val) = explode("=", $line, 2);
+ $result->data[$key] = $val;
+ }
+ }
+ } else {
+ $result->status = "error";
+ }
+ } catch (Exception $e) {
+ Kohana_Log::add("error",
+ sprintf("%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(),
+ $e->getLine(), $e->getTraceAsString()));
+ }
+ $result->timestamp = time();
+ Cache::instance()->set("upgrade_checker_version_info", serialize($result), null, 86400 * 365);
+ }
+
+ static function check_for_upgrade() {
+ $version_info = upgrade_checker::version_info();
+ $upgrade_available = false;
+ if ($version_info) {
+ if (gallery::RELEASE_CHANNEL == "release") {
+ if (version_compare($version_info->data["release_version"], gallery::VERSION, ">")) {
+ site_status::warning(
+ t("A newer version of Gallery is available! <a href=\"%upgrade-url\">Upgrade now</a> to version %version or <a href=\"%hide-url\">wait until later</a>.",
+ array("version" => $version_info->data["release_version"],
+ "upgrade-url" => $version_info->data["release_upgrade_url"],
+ "hide-url" => url::site("admin/upgrade_checker/remind_me_later?csrf=__CSRF__"))),
+ "upgrade_checker");
+ $upgrade_available = true;
+ }
+ } else {
+ $branch = gallery::RELEASE_BRANCH;
+ if (isset($version_info->data["{$branch}_build_number"]) &&
+ version_compare($version_info->data["{$branch}_build_number"],
+ gallery::build_number(), ">")) {
+ site_status::warning(
+ t("A newer version of Gallery is available! <a href=\"%upgrade-url\">Upgrade now</a> to version %version (build %build on branch %branch) or <a href=\"%hide-url\">wait until later</a>.",
+ array("version" => $version_info->data["{$branch}_version"],
+ "upgrade-url" => $version_info->data["{$branch}_upgrade_url"],
+ "build" => $version_info->data["{$branch}_build_number"],
+ "branch" => $branch,
+ "hide-url" => url::site("admin/upgrade_checker/remind_me_later?csrf=__CSRF__"))),
+ "upgrade_checker");
+ $upgrade_available = true;
+ }
+ }
+ }
+
+ if (!$upgrade_available) {
+ site_status::clear("upgrade_checker");
+ }
+ }
+}