diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-09-27 15:24:51 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-09-27 15:24:51 -0700 |
commit | 467b74c3106558d1656301b9c73236417d4421ac (patch) | |
tree | 6f5364ef698847b04b231852bb9791010006af24 /modules/gallery/helpers/graphics.php | |
parent | 0ab73cd1adb2acac0f2b2f97acc8362083d9cdfa (diff) |
This path requires the upgrader to be run and applies the following changes:
* moves the composite method back into core
* requires that the operation be fully qualified i.e. gallery_graphics::resize
* caches the graphics rules on each request
Diffstat (limited to 'modules/gallery/helpers/graphics.php')
-rw-r--r-- | modules/gallery/helpers/graphics.php | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 6705652f..0e32022f 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -19,6 +19,7 @@ */ class graphics_Core { private static $init; + private static $_rules_cache = array(); /** * Add a new graphics rule. @@ -26,7 +27,7 @@ class graphics_Core { * Rules are applied to targets (thumbnails and resizes) in priority order. Rules are functions * in the graphics class. So for example, the following rule: * - * graphics::add_rule("gallery", "thumb", "resize", + * graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", * array("width" => 200, "height" => 200, "master" => Image::AUTO), 100); * * Specifies that "gallery" is adding a rule to resize thumbnails down to a max of 200px on @@ -35,7 +36,7 @@ class graphics_Core { * * @param string $module_name the module that added the rule * @param string $target the target for this operation ("thumb" or "resize") - * @param string $operation the name of the operation + * @param string $operation the name of the operation (<defining class>::method) * @param array $args arguments to the operation * @param integer $priority the priority for this rule (lower priorities are run first) */ @@ -56,7 +57,7 @@ class graphics_Core { * Remove any matching graphics rules * @param string $module_name the module that added the rule * @param string $target the target for this operation ("thumb" or "resize") - * @param string $operation the name of the operation + * @param string $operation the name of the operation(<defining class>::method) */ static function remove_rule($module_name, $target, $operation) { ORM::factory("graphics_rule") @@ -146,13 +147,9 @@ class graphics_Core { $working_file = $input_file; } - foreach (ORM::factory("graphics_rule") - ->where("target", $target) - ->where("active", true) - ->orderby("priority", "asc") - ->find_all() as $rule) { + foreach (self::_get_rules($target) as $rule) { $args = array($working_file, $output_file, unserialize($rule->args)); - call_user_func_array(array("{$rule->module_name}_graphics", $rule->operation), $args); + call_user_func_array($rule->operation, $args); $working_file = $output_file; } } @@ -180,6 +177,21 @@ class graphics_Core { } } + private static function _get_rules($target) { + if (empty(self::$_rules_cache[$target])) { + $rules = array(); + foreach (ORM::factory("graphics_rule") + ->where("target", $target) + ->where("active", true) + ->orderby("priority", "asc") + ->find_all() as $rule) { + $rules[] = (object)$rule->as_array(); + } + self::$_rules_cache[$target] = $rules; + } + return self::$_rules_cache[$target]; + } + /** * Rotate an image. Valid options are degrees * |