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 /modules/gallery | |
| parent | 07f654c8d9918608c8229404585874ce5aba7ab2 (diff) | |
| parent | a9eb995dd2b64667c300c6193656b6cdfeb4e2a5 (diff) | |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/gallery')
| -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 | 
7 files changed, 122 insertions, 26 deletions
| 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"> | 
