diff options
author | Chad Kieffer <ckieffer@gmail.com> | 2011-04-23 15:02:29 -0400 |
---|---|---|
committer | Chad Kieffer <ckieffer@gmail.com> | 2011-04-23 15:02:29 -0400 |
commit | 268f9425d918d14e1839b3e22203a8869093f3f0 (patch) | |
tree | 3a0676e1fa0b158262e9ae8f0faef0474998b061 | |
parent | 07f654c8d9918608c8229404585874ce5aba7ab2 (diff) | |
parent | a9eb995dd2b64667c300c6193656b6cdfeb4e2a5 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
-rw-r--r-- | .build_number | 2 | ||||
-rw-r--r-- | modules/gallery/css/gallery.css | 6 | ||||
-rw-r--r-- | modules/gallery/helpers/MY_num.php | 14 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 25 | ||||
-rw-r--r-- | modules/gallery/helpers/graphics.php | 21 | ||||
-rw-r--r-- | modules/gallery/libraries/Form_Uploadify.php | 14 | ||||
-rw-r--r-- | modules/gallery/tests/Num_Helper_Test.php | 32 | ||||
-rw-r--r-- | modules/gallery/views/form_uploadify.html.php | 36 | ||||
-rw-r--r-- | modules/server_add/js/server_add.js | 125 | ||||
-rw-r--r-- | modules/tag/helpers/tag.php | 1 |
10 files changed, 249 insertions, 27 deletions
diff --git a/.build_number b/.build_number index 05667d5e..c0d876e3 100644 --- a/.build_number +++ b/.build_number @@ -3,4 +3,4 @@ ; process. You don't need to edit it. In fact.. ; ; DO NOT EDIT THIS FILE BY HAND! -build_number=103 +build_number=109 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_block.php b/modules/gallery/helpers/gallery_block.php index 0ba7c936..49d16246 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -82,9 +82,13 @@ class gallery_block_Core { break; case "block_adder": - $block->css_id = "g-block-adder"; - $block->title = t("Dashboard content"); - $block->content = gallery_block::get_add_block_form(); + if ($form = gallery_block::get_add_block_form()) { + $block->css_id = "g-block-adder"; + $block->title = t("Dashboard content"); + $block->content = $form; + } else { + $block = ""; + } break; case "language": @@ -118,11 +122,22 @@ class gallery_block_Core { } static function get_add_block_form() { + $available_blocks = block_manager::get_available_admin_blocks(); + + $active = array(); + foreach (array_merge(block_manager::get_active("dashboard_sidebar"), + block_manager::get_active("dashboard_center")) as $b) { + unset($available_blocks[implode(":", $b)]); + } + + if (!$available_blocks) { + return; + } + $form = new Forge("admin/dashboard/add_block", "", "post", array("id" => "g-add-dashboard-block-form")); $group = $form->group("add_block")->label(t("Add Block")); - $group->dropdown("id")->label(t("Available Blocks")) - ->options(block_manager::get_available_admin_blocks()); + $group->dropdown("id")->label(t("Available blocks"))->options($available_blocks); $group->submit("center")->value(t("Add to center")); $group->submit("sidebar")->value(t("Add to sidebar")); return $form; diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 04501132..8d8853b0 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -316,7 +316,7 @@ class graphics_Core { // ImageMagick & GraphicsMagick $magick_kits = array( "imagemagick" => array( - "name" => "ImageMagick", "binary" => "convert", "version" => "convert -v", + "name" => "ImageMagick", "binary" => "convert", "version" => "convert -version", "version_regex" => "/Version: \S+ (\S+)/"), "graphicsmagick" => array( "name" => "GraphicsMagick", "binary" => "gm", "version" => "gm version", @@ -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/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/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"> diff --git a/modules/server_add/js/server_add.js b/modules/server_add/js/server_add.js new file mode 100644 index 00000000..02dda4c0 --- /dev/null +++ b/modules/server_add/js/server_add.js @@ -0,0 +1,125 @@ +(function($) { + $.widget("ui.gallery_server_add", { + _init: function() { + var self = this; + $("#g-server-add-add-button", this.element).click(function(event) { + event.preventDefault(); + $(".g-progress-bar", this.element). + progressbar(). + progressbar("value", 0); + $("#g-server-add-progress", this.element).slideDown("fast", function() { self.start_add(); }); + }); + $("#g-server-add-pause-button", this.element).click(function(event) { + self.pause = true; + $("#g-server-add-pause-button", this.element).hide(); + $("#g-server-add-continue-button", this.element).show(); + }); + $("#g-server-add-continue-button", this.element).click(function(event) { + self.pause = false; + $("#g-server-add-pause-button", this.element).show(); + $("#g-server-add-continue-button", this.element).hide(); + self.run_add(); + }); + $("#g-server-add-close-button", this.element).click(function(event) { + $("#g-dialog").dialog("close"); + window.location.reload(); + }); + $("#g-server-add-tree span.g-directory", this.element).dblclick(function(event) { + self.open_dir(event); + }); + $("#g-server-add-tree span.g-file, #g-server-add-tree span.g-directory", this.element).click(function(event) { + self.select_file(event); + }); + $("#g-server-add-tree span.g-directory", this.element).dblclick(function(event) { + self.open_dir(event); + }); + $("#g-dialog").bind("dialogclose", function(event, ui) { + window.location.reload(); + }); + }, + + taskURL: null, + pause: false, + + start_add: function() { + var self = this; + var paths = []; + $.each($("span.selected", self.element), function () { + paths.push($(this).attr("ref")); + }); + + $("#g-server-add-add-button", this.element).hide(); + $("#g-server-add-pause-button", this.element).show(); + + $.ajax({ + url: START_URL, + type: "POST", + async: false, + data: { "paths[]": paths }, + dataType: "json", + success: function(data, textStatus) { + $("#g-status").html(data.status); + $(".g-progress-bar", self.element).progressbar("value", data.percent_complete); + self.taskURL = data.url; + setTimeout(function() { self.run_add(); }, 25); + } + }); + return false; + }, + + run_add: function () { + var self = this; + $.ajax({ + url: self.taskURL, + async: false, + dataType: "json", + success: function(data, textStatus) { + $("#g-status").html(data.status); + $(".g-progress-bar", self.element).progressbar("value", data.percent_complete); + if (data.done) { + $("#g-server-add-progress", this.element).slideUp(); + $("#g-server-add-add-button", this.element).show(); + $("#g-server-add-pause-button", this.element).hide(); + $("#g-server-add-continue-button", this.element).hide(); + } else { + if (!self.pause) { + setTimeout(function() { self.run_add(); }, 25); + } + } + } + }); + }, + + /** + * Load a new directory + */ + open_dir: function(event) { + var self = this; + var path = $(event.target).attr("ref"); + $.ajax({ + url: GET_CHILDREN_URL.replace("__PATH__", path), + success: function(data, textStatus) { + $("#g-server-add-tree", self.element).html(data); + $("#g-server-add-tree span.g-directory", self.element).dblclick(function(event) { + self.open_dir(event); + }); + $("#g-server-add-tree span.g-file, #g-server-add-tree span.g-directory", this.element).click(function(event) { + self.select_file(event); + }); + } + }); + }, + + /** + * Manage file selection state. + */ + select_file: function (event) { + $(event.target).toggleClass("selected"); + if ($("#g-server-add span.selected").length) { + $("#g-server-add-add-button").enable(true).removeClass("ui-state-disabled"); + } else { + $("#g-server-add-add-button").enable(false).addClass("ui-state-disabled"); + } + } + }); +})(jQuery); diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 733215b3..c21104ee 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -48,6 +48,7 @@ class tag_Core { * @return ORM_Iterator of Tag_Model in descending tag count order */ static function popular_tags($count) { + $count = max($count, 1); return ORM::factory("tag") ->order_by("count", "DESC") ->limit($count) |