summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/admin_modules.php6
-rw-r--r--modules/gallery/css/gallery.css6
-rw-r--r--modules/gallery/helpers/MY_num.php14
-rw-r--r--modules/gallery/helpers/gallery_installer.php13
-rw-r--r--modules/gallery/helpers/graphics.php19
-rw-r--r--modules/gallery/helpers/module.php2
-rw-r--r--modules/gallery/libraries/Form_Uploadify.php14
-rw-r--r--modules/gallery/module.info2
-rw-r--r--modules/gallery/tests/Num_Helper_Test.php32
-rw-r--r--modules/gallery/views/form_uploadify.html.php36
10 files changed, 113 insertions, 31 deletions
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index 787785ea..b712d14f 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -19,6 +19,9 @@
*/
class Admin_Modules_Controller extends Admin_Controller {
public function index() {
+ // If modules need upgrading, this will get recreated in module::available()
+ site_status::clear("upgrade_now");
+
$view = new Admin_View("admin.html");
$view->page_title = t("Modules");
$view->content = new View("admin_modules.html");
@@ -103,9 +106,6 @@ class Admin_Modules_Controller extends Admin_Controller {
module::event("module_change", $changes);
- // If modules need upgrading, this will get recreated
- site_status::clear("upgrade_now");
-
// @todo this type of collation is questionable from an i18n perspective
if ($activated_names) {
message::success(t("Activated: %names", array("names" => join(", ", $activated_names))));
diff --git a/modules/gallery/css/gallery.css b/modules/gallery/css/gallery.css
index 275a3d7d..97d09454 100644
--- a/modules/gallery/css/gallery.css
+++ b/modules/gallery/css/gallery.css
@@ -29,12 +29,12 @@
#g-add-photos-canvas object,
#g-add-photos-button {
- left: 137px;
- margin: .5em 0;
+ left: 93px;
+ margin: .5em 0;
padding: .4em 1em;
position: absolute;
top: 0;
- width: 175px;
+ width: auto;
}
#g-add-photos-canvas object {
diff --git a/modules/gallery/helpers/MY_num.php b/modules/gallery/helpers/MY_num.php
index 9787044c..842a2ee3 100644
--- a/modules/gallery/helpers/MY_num.php
+++ b/modules/gallery/helpers/MY_num.php
@@ -37,4 +37,18 @@ class num extends num_Core {
return $val;
}
+
+ /**
+ * Convert a size value as accepted by PHP's shorthand to bytes.
+ * ref: http://us2.php.net/manual/en/function.ini-get.php
+ * ref: http://us2.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
+ */
+ static function convert_to_human_readable($num) {
+ foreach (array("G" => 1e9, "M" => 1e6, "K" => 1e3) as $k => $v) {
+ if ($num > $v) {
+ $num = round($num / $v) . $k;
+ }
+ }
+ return $num;
+ }
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 83c5ed71..7a9af402 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -311,9 +311,9 @@ class gallery_installer {
module::set_var("gallery", "email_header_separator", serialize("\n"));
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_var("gallery", "timezone", Kohana::config("locale.timezone"));
+ module::set_var("gallery", "timezone", null);
- module::set_version("gallery", 48);
+ module::set_version("gallery", 49);
}
static function upgrade($version) {
@@ -685,11 +685,12 @@ class gallery_installer {
module::set_version("gallery", $version = 47);
}
- if ($version == 47) {
+ if ($version == 47 || $version == 48) {
// Add configuration variable to set timezone. Defaults to the currently
- // used timezone (from PHP configuration).
- module::set_var("gallery", "timezone", Kohana::config("locale.timezone"));
- module::set_version("gallery", $version = 48);
+ // used timezone (from PHP configuration). Note that in v48 we werew
+ // setting this value incorrectly, so we're going to stomp this value for v49.
+ module::set_var("gallery", "timezone", null);
+ module::set_version("gallery", $version = 49);
}
}
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index f374f9da..8d8853b0 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -423,4 +423,23 @@ class graphics_Core {
return true;
}
+
+ /**
+ * Return the max file size that this graphics toolkit can handle.
+ */
+ static function max_filesize() {
+ if (module::get_var("gallery", "graphics_toolkit") == "gd") {
+ $memory_limit = trim(ini_get("memory_limit"));
+ $memory_limit_bytes = num::convert_to_bytes($memory_limit);
+
+ // GD expands images in memory and uses 4 bytes of RAM for every byte
+ // in the file.
+ $max_filesize = $memory_limit_bytes / 4;
+ $max_filesize_human_readable = num::convert_to_human_readable($max_filesize);
+ return array($max_filesize, $max_filesize_human_readable);
+ }
+
+ // Some arbitrarily large size
+ return array(1000000000, "1G");
+ }
}
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 37f7f68a..4b7d4a5f 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -101,7 +101,7 @@ class module_Core {
$m->locked = false;
if ($m->active && $m->version != $m->code_version) {
- site_status::warning(t("Some of your modules are out of date. <a href=\"%upgrader_url\">Upgrade now!</a>", array("upgrader_url" => url::site("upgrader"))), "upgrade_now");
+ site_status::warning(t("Some of your modules are out of date. <a href=\"%upgrader_url\">Upgrade now!</a>", array("upgrader_url" => url::abs_site("upgrader"))), "upgrade_now");
}
}
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index 27ab9684..3e35e380 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -48,6 +48,20 @@ class Form_Uploadify_Core extends Form_Input {
$v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
$v->movies_allowed = (bool) movie::find_ffmpeg();
$v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
+
+ list ($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize();
+
+ $upload_max_filesize = trim(ini_get("upload_max_filesize"));
+ $upload_max_filesize_bytes = num::convert_to_bytes($upload_max_filesize);
+
+ if ($upload_max_filesize_bytes < $toolkit_max_filesize_bytes) {
+ $v->size_limit_bytes = $upload_max_filesize_bytes;
+ $v->size_limit = $upload_max_filesize;
+ } else {
+ $v->size_limit_bytes = $toolkit_max_filesize_bytes;
+ $v->size_limit = $toolkit_max_filesize;
+ }
+
return $v;
}
diff --git a/modules/gallery/module.info b/modules/gallery/module.info
index 807d08fd..74c0658f 100644
--- a/modules/gallery/module.info
+++ b/modules/gallery/module.info
@@ -1,3 +1,3 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 48
+version = 49
diff --git a/modules/gallery/tests/Num_Helper_Test.php b/modules/gallery/tests/Num_Helper_Test.php
new file mode 100644
index 00000000..a22f9359
--- /dev/null
+++ b/modules/gallery/tests/Num_Helper_Test.php
@@ -0,0 +1,32 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2011 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 Num_Helper_Test extends Gallery_Unit_Test_Case {
+ public function convert_to_bytes_test() {
+ $this->assert_equal(5 * 1024, num::convert_to_bytes("5K"));
+ $this->assert_equal(3 * 1024*1024, num::convert_to_bytes("3M"));
+ $this->assert_equal(4 * 1024*1024*1024, num::convert_to_bytes("4G"));
+ }
+
+ public function convert_to_human_readable_test() {
+ $this->assert_equal("6K", num::convert_to_human_readable(5615));
+ $this->assert_equal("1M", num::convert_to_human_readable(1205615));
+ $this->assert_equal("3G", num::convert_to_human_readable(3091205615));
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php
index 77b6d493..83dfcc68 100644
--- a/modules/gallery/views/form_uploadify.html.php
+++ b/modules/gallery/views/form_uploadify.html.php
@@ -32,6 +32,7 @@
fileDesc: <?= t("Photos and movies")->for_js() ?>,
cancelImg: "<?= url::file("lib/uploadify/cancel.png") ?>",
simUploadLimit: <?= $simultaneous_upload_limit ?>,
+ sizeLimit: <?= $size_limit_bytes ?>,
wmode: "transparent",
hideButton: true, /* should be true */
auto: true,
@@ -66,26 +67,30 @@
return true;
},
onError: function(event, queueID, fileObj, errorObj) {
- var msg = " - ";
if (errorObj.type == "HTTP") {
if (errorObj.info == "500") {
- msg += <?= t("Unable to process this file")->for_js() ?>;
- // Server error - check server logs
+ error_msg = <?= t("Unable to process this photo")->for_js() ?>;
} else if (errorObj.info == "404") {
- msg += <?= t("The upload script was not found.")->for_js() ?>;
- // Server script not found
+ error_msg = <?= t("The upload script was not found")->for_js() ?>;
+ } else if (errorObj.info == "400") {
+ error_msg = <?= t("This photo is too large (max is %size bytes)",
+ array("size" => $size_limit))->for_js() ?>;
} else {
- // Server Error: status: errorObj.info
- msg += (<?= t("Server error: __INFO__")->for_js() ?>.replace("__INFO__", errorObj.info));
+ msg += (<?= t("Server error: __INFO__ (__TYPE__)")->for_js() ?>
+ .replace("__INFO__", errorObj.info)
+ .replace("__TYPE__", errorObj.type));
}
} else if (errorObj.type == "File Size") {
- var sizelimit = $("#g-uploadify").uploadifySettings(sizeLimit);
- msg += fileObj.name+' '+errorObj.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB';
+ error_msg = <?= t("This photo is too large (max is %size bytes)",
+ array("size" => $size_limit))->for_js() ?>;
} else {
- msg += (<?= t("Server error: __INFO__ (__TYPE__)")->for_js() ?>
- .replace("__INFO__", errorObj.info)
- .replace("__TYPE__", errorObj.type));
+ error_msg = <?= t("Server error: __INFO__ (__TYPE__)")->for_js() ?>
+ .replace("__INFO__", errorObj.info)
+ .replace("__TYPE__", errorObj.type);
}
+ msg = " - <a target=\"_blank\" href=\"http://codex.gallery2.org/Gallery3:Troubleshooting:Uploading\">" +
+ error_msg + "</a>";
+
$("#g-add-photos-status ul").append(
"<li id=\"q" + queueID + "\" class=\"g-error\">" + fileObj.name + msg + "</li>");
$("#g-uploadify").uploadifyCancel(queueID);
@@ -131,10 +136,7 @@
<? endif ?>
<div>
- <p>
- <?= t("Photos will be uploaded to album: ") ?>
- </p>
- <ul class="g-breadcrumbs ui-helper-clearfix">
+ <ul class="g-breadcrumbs">
<? foreach ($album->parents() as $i => $parent): ?>
<li<? if ($i == 0) print " class=\"g-first\"" ?>> <?= html::clean($parent->title) ?> </li>
<? endforeach ?>
@@ -143,7 +145,7 @@
</div>
<div id="g-add-photos-canvas">
- <button id="g-add-photos-button" class="g-button ui-state-default ui-corner-all" href="#"><?= t("Select photos...") ?></button>
+ <button id="g-add-photos-button" class="g-button ui-state-default ui-corner-all" href="#"><?= t("Select photos (%size max per file)...", array("size" => $size_limit)) ?></button>
<span id="g-uploadify"></span>
</div>
<div id="g-add-photos-status">