Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gallery/gallery3
Browse files Browse the repository at this point in the history
  • Loading branch information
ckieffer committed Sep 28, 2009
2 parents 6cd8679 + ab5e680 commit bb74d2f
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 113 deletions.
14 changes: 7 additions & 7 deletions installer/install.sql
Expand Up @@ -88,8 +88,8 @@ CREATE TABLE {graphics_rules} (
PRIMARY KEY (`id`)
) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','resize',100,'thumb');
INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:480;s:6:\"master\";i:2;}','gallery','resize',100,'resize');
INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'thumb');
INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:480;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'resize');
DROP TABLE IF EXISTS {groups};
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
Expand Down Expand Up @@ -228,7 +228,7 @@ CREATE TABLE {modules} (
UNIQUE KEY `name` (`name`)
) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO {modules} VALUES (1,1,'gallery',12);
INSERT INTO {modules} VALUES (1,1,'gallery',14);
INSERT INTO {modules} VALUES (2,1,'user',1);
INSERT INTO {modules} VALUES (3,1,'comment',2);
INSERT INTO {modules} VALUES (4,1,'organize',1);
Expand Down Expand Up @@ -331,8 +331,8 @@ CREATE TABLE {themes} (
UNIQUE KEY `name` (`name`)
) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO {themes} VALUES (1,'default',1);
INSERT INTO {themes} VALUES (2,'admin_default',1);
INSERT INTO {themes} VALUES (1,'wind',1);
INSERT INTO {themes} VALUES (2,'admin_wind',1);
DROP TABLE IF EXISTS {users};
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
Expand Down Expand Up @@ -368,8 +368,8 @@ CREATE TABLE {vars} (
UNIQUE KEY `module_name` (`module_name`,`name`)
) AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','default');
INSERT INTO {vars} VALUES (2,'gallery','active_admin_theme','admin_default');
INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','wind');
INSERT INTO {vars} VALUES (2,'gallery','active_admin_theme','admin_wind');
INSERT INTO {vars} VALUES (3,'gallery','page_size','9');
INSERT INTO {vars} VALUES (4,'gallery','thumb_size','200');
INSERT INTO {vars} VALUES (5,'gallery','resize_size','640');
Expand Down
8 changes: 4 additions & 4 deletions modules/gallery/controllers/admin_theme_options.php
Expand Up @@ -35,9 +35,9 @@ public function save() {
$thumb_size = $form->edit_theme->thumb_size->value;
$thumb_dirty = false;
if (module::get_var("gallery", "thumb_size") != $thumb_size) {
graphics::remove_rule("gallery", "thumb", "resize");
graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize");
graphics::add_rule(
"gallery", "thumb", "resize",
"gallery", "thumb", "gallery_graphics::resize",
array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO),
100);
module::set_var("gallery", "thumb_size", $thumb_size);
Expand All @@ -46,9 +46,9 @@ public function save() {
$resize_size = $form->edit_theme->resize_size->value;
$resize_dirty = false;
if (module::get_var("gallery", "resize_size") != $resize_size) {
graphics::remove_rule("gallery", "resize", "resize");
graphics::remove_rule("gallery", "resize", "gallery_graphics::resize");
graphics::add_rule(
"gallery", "resize", "resize",
"gallery", "resize", "gallery_graphics::resize",
array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO),
100);
module::set_var("gallery", "resize_size", $resize_size);
Expand Down
55 changes: 55 additions & 0 deletions modules/gallery/helpers/gallery_graphics.php
Expand Up @@ -51,4 +51,59 @@ static function resize($input_file, $output_file, $options) {

module::event("graphics_resize_completed", $input_file, $output_file, $options);
}

/**
* Overlay an image on top of the input file.
*
* Valid options are: file, mime_type, position, transparency_percent, padding
*
* Valid positions: northwest, north, northeast,
* west, center, east,
* southwest, south, southeast
*
* padding is in pixels
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function composite($input_file, $output_file, $options) {
try {
graphics::init_toolkit();

module::event("graphics_composite", $input_file, $output_file, $options);

list ($width, $height) = getimagesize($input_file);
list ($w_width, $w_height) = getimagesize($options["file"]);

$pad = isset($options["padding"]) ? $options["padding"] : 10;
$top = $pad;
$left = $pad;
$y_center = max($height / 2 - $w_height / 2, $pad);
$x_center = max($width / 2 - $w_width / 2, $pad);
$bottom = max($height - $w_height - $pad, $pad);
$right = max($width - $w_width - $pad, $pad);

switch ($options["position"]) {
case "northwest": $x = $left; $y = $top; break;
case "north": $x = $x_center; $y = $top; break;
case "northeast": $x = $right; $y = $top; break;
case "west": $x = $left; $y = $y_center; break;
case "center": $x = $x_center; $y = $y_center; break;
case "east": $x = $right; $y = $y_center; break;
case "southwest": $x = $left; $y = $bottom; break;
case "south": $x = $x_center; $y = $bottom; break;
case "southeast": $x = $right; $y = $bottom; break;
}

Image::factory($input_file)
->composite($options["file"], $x, $y, $options["transparency"])
->quality(module::get_var("gallery", "image_quality"))
->save($output_file);

module::event("graphics_composite_completed", $input_file, $output_file, $options);
} catch (ErrorException $e) {
Kohana::log("error", $e->get_message());
}
}
}
15 changes: 11 additions & 4 deletions modules/gallery/helpers/gallery_installer.php
Expand Up @@ -235,16 +235,16 @@ static function install() {

// Add rules for generating our thumbnails and resizes
graphics::add_rule(
"gallery", "thumb", "resize",
"gallery", "thumb", "gallery_graphics::resize",
array("width" => 200, "height" => 200, "master" => Image::AUTO),
100);
graphics::add_rule(
"gallery", "resize", "resize",
"gallery", "resize", "gallery_graphics::resize",
array("width" => 640, "height" => 480, "master" => Image::AUTO),
100);

// Instantiate default themes (site and admin)
foreach (array("default", "admin_default") as $theme_name) {
foreach (array("wind", "admin_wind") as $theme_name) {
$theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"),
ArrayObject::ARRAY_AS_PROPS);
$theme = ORM::factory("theme");
Expand All @@ -268,7 +268,7 @@ static function install() {
module::set_var("gallery", "show_credits", 1);
// @todo this string needs to be picked up by l10n_scanner
module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
module::set_version("gallery", 13);
module::set_version("gallery", 14);
}

static function upgrade($version) {
Expand Down Expand Up @@ -375,6 +375,13 @@ static function upgrade($version) {
module::set_version("gallery", $version = 13);
}

if ($version == 13) {
// Add rules for generating our thumbnails and resizes
Database::instance()->query("update g3_graphics_rules g
set operation=concat(\"gallery_graphics::\", g.operation);");
module::set_version("gallery", $version = 14);
}

}

static function uninstall() {
Expand Down
8 changes: 5 additions & 3 deletions modules/gallery/helpers/gallery_task.php
Expand Up @@ -48,11 +48,13 @@ static function rebuild_dirty_images($task) {
$errors = array();
try {
$result = graphics::find_dirty_images_query();
$total_count = $task->get("total_count", -1);
if ($total_count < 0) {
$total_count = $result->count();
$total_count = $task->get("total_count", $result->count());
$mode = $task->get("mode", "init");
if ($mode == "init") {
$task->set("total_count", $total_count);
$task->get("mode", "process");
}

$completed = $task->get("completed", 0);
$ignored = $task->get("ignored", array());

Expand Down
30 changes: 21 additions & 9 deletions modules/gallery/helpers/graphics.php
Expand Up @@ -19,14 +19,15 @@
*/
class graphics_Core {
private static $init;
private static $_rules_cache = array();

/**
* Add a new graphics rule.
*
* 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
Expand All @@ -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)
*/
Expand All @@ -56,7 +57,7 @@ static function add_rule($module_name, $target, $operation, $args, $priority) {
* 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")
Expand Down Expand Up @@ -146,13 +147,9 @@ static function generate($item) {
$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;
}
}
Expand Down Expand Up @@ -180,6 +177,21 @@ static function generate($item) {
}
}

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
*
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/module.info
@@ -1,3 +1,3 @@
name = "Gallery 3"
description = "Gallery core application"
version = 13
version = 14
16 changes: 8 additions & 8 deletions modules/gallery/views/simple_uploader.html.php
Expand Up @@ -32,15 +32,15 @@
</ul>

<div id="g-uploadqueue-infobar">
<?= t("Upload Queue") ?>
<?= t("Upload Queue") ?>
<span id="g-uploadstatus"></span>
<a id="g-cancelupload" title="<?= t("Cancel all the pending uploads")->for_html_attr() ?>" onclick="swfu.cancelQueue();"><?= t("cancel") ?></a>
</div>
<div id="gAddPhotosCanvas" style="text-align: center;">
<div id="gAddPhotosQueue"></div>
<div id="gEditPhotosQueue"></div>
</div>
<span id="gChooseFilesButtonPlaceholder"></span>
<span id="gChooseFilesButtonPlaceholder"></span>

<!-- Proxy the done request back to our form, since its been ajaxified -->
<button class="ui-state-default ui-corner-all" onclick="$('#gAddPhotosForm').submit()">
Expand Down Expand Up @@ -72,7 +72,7 @@
button_text: <?= json_encode('<span class="swfUploadFont">' . t("Select photos...") . '</span>') ?>,
button_text_style: ".swfUploadFont { color: #2E6E9E; font-size: 16px; font-family: Lucida Grande,Lucida Sans,Arial,sans-serif; font-weight: bold; }",
button_text_left_padding: 30,
button_text_right_padding: 30,
button_text_right_padding: 30,
button_text_top_padding: 10,

// The event handler functions are defined in handlers.js
Expand Down Expand Up @@ -164,11 +164,11 @@ function upload_start(file) {
fp.title.html(file.name);
fp.set_status("uploading", <?= t("Uploading...")->for_js() ?>);
$("#gAddPhotosCanvas").scrollTo(fp.box, 1000);
// move file select button
$("#SWFUpload_0").css({'left': '0', 'top': '0'});
swfu.setButtonText(<?= json_encode('<span class="swfUploadFont">' . t("Select more photos...") . '</span>') ?>);

// move file select button
$("#SWFUpload_0").css({'left': '0', 'top': '0'});
swfu.setButtonText(<?= json_encode('<span class="swfUploadFont">' . t("Select more photos...") . '</span>') ?>);

return true;
// @todo add cancel button to call this.cancelUpload(file.id)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/watermark/controllers/admin_watermarks.php
Expand Up @@ -138,7 +138,7 @@ private function _update_graphics_rules() {
if ($name = module::get_var("watermark", "name")) {
foreach (array("thumb", "resize") as $target) {
graphics::add_rule(
"watermark", $target, "composite",
"watermark", $target, "gallery_graphics::composite",
array("file" => VARPATH . "modules/watermark/$name",
"width" => module::get_var("watermark", "width"),
"height" => module::get_var("watermark", "height"),
Expand Down
75 changes: 0 additions & 75 deletions modules/watermark/helpers/watermark_graphics.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/watermark/module.info
@@ -1,3 +1,3 @@
name = "Watermarks"
description = "Allows users to watermark their photos"
version = 1
version = 2

0 comments on commit bb74d2f

Please sign in to comment.