1
0

forgot to add these files to the previous commit... oops.

This commit is contained in:
shadlaws 2012-12-12 22:59:46 +01:00
parent ab0265b1c4
commit 7e19410003
19 changed files with 1904 additions and 0 deletions

View File

@ -0,0 +1,163 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 Admin_Image_Optimizer_Controller extends Admin_Controller {
public function index() {
// print screen from new form
$form = $this->_get_admin_form();
$this->_print_screen($form);
}
public function save() {
access::verify_csrf();
$form = $this->_get_admin_form();
if ($form->validate()) {
foreach (array('jpg', 'png', 'gif') as $type) {
module::set_var("image_optimizer", "path_".$type, $form->paths->{"path_".$type}->value);
module::set_var("image_optimizer", "optlevel_thumb_".$type, $form->thumb->{"optlevel_thumb_".$type}->value);
module::set_var("image_optimizer", "optlevel_resize_".$type, $form->resize->{"optlevel_resize_".$type}->value);
}
module::set_var("image_optimizer", "rotate_jpg", ($form->rotate->rotate_jpg->value == 1));
foreach (array('thumb', 'resize') as $target) {
module::set_var("image_optimizer", "convert_".$target."_gif", $form->$target->{"convert_".$target."_gif"}->value);
module::set_var("image_optimizer", "convert_".$target."_png", $form->$target->{"convert_".$target."_png"}->value);
module::set_var("image_optimizer", "metastrip_".$target, ($form->$target->{"metastrip_".$target}->value == 1));
module::set_var("image_optimizer", "progressive_".$target, ($form->$target->{"progressive_".$target}->value == 1));
// deal with enable changes
$enable_old = module::get_var("image_optimizer", "enable_".$target);
$enable_new = ($form->$target->{"enable_".$target}->value == 1);
if ($enable_new && !$enable_old) {
image_optimizer::add_image_optimizer_rule($target);
module::set_var("image_optimizer", "enable_".$target, true);
} elseif (!$enable_new && $enable_old) {
image_optimizer::remove_image_optimizer_rule($target);
module::set_var("image_optimizer", "enable_".$target, false);
}
// deal with update mode changes
$update_mode_old = module::get_var("image_optimizer", "update_mode_".$target);
$update_mode_new = ($form->$target->{"update_mode_".$target}->value == 1);
if ($update_mode_new && !$update_mode_old) {
image_optimizer::activate_update_mode($target);
} elseif (!$update_mode_new && $update_mode_old) {
image_optimizer::deactivate_update_mode($target);
}
// dirty images if needed
if ($form->$target->{"rebuild_".$target}->value == 1) {
image_optimizer::dirty($target);
}
}
// all done; redirect with message
message::success(t("Image optimizer settings updated successfully"));
url::redirect("admin/image_optimizer");
}
// not valid - print screen from existing form
$this->_print_screen($form);
}
private function _print_screen($form) {
// this part is a bit of a hack, but Forge doesn't seem to allow set_attr() for groups.
$form = $form->render();
$form = preg_replace("/<fieldset>/","<fieldset class=\"g-image-optimizer-admin-form-top\">",$form,2);
$form = preg_replace("/<fieldset>/","<fieldset class=\"g-image-optimizer-admin-form-left\">",$form,1);
$form = preg_replace("/<fieldset>/","<fieldset class=\"g-image-optimizer-admin-form-right\">",$form,1);
// make and print view
$view = new Admin_View("admin.html");
$view->page_title = t("Image optimizer settings");
$view->content = new View("admin_image_optimizer.html");
$view->content->form = $form;
// get module parameters
foreach (array('jpg', 'png', 'gif') as $type) {
$view->content->{"installed_path_".$type} = image_optimizer::tool_installed_path($type);
$view->content->{"version_".$type} = image_optimizer::tool_version($type);
}
print $view;
}
private function _get_admin_form() {
$form = new Forge("admin/image_optimizer/save", "", "post", array("id" => "g-image-optimizer-admin-form"));
$group_paths = $form->group("paths")->label(t("Toolkit paths"))->set_attr("id","g-image-optimizer-admin-form-paths");
foreach (array('jpg', 'png', 'gif') as $type) {
$path = strval(module::get_var("image_optimizer", "path_".$type, null));
$group_paths->input("path_".$type)
->label(t("Path for")." ".image_optimizer::tool_name($type)." (".t("no symlinks, default")." ".MODPATH."image_optimizer/lib/".image_optimizer::tool_name($type).")")
->value($path);
}
$group_rotate = $form->group("rotate")->label(t("Full-size image rotation"))->set_attr("id","g-image-optimizer-admin-form-rotate");
$group_rotate->checkbox("rotate_jpg")
->label(t("Override default toolkit and use")." ".image_optimizer::tool_name('jpg')." ".t("for rotation"))
->checked(module::get_var("image_optimizer", "rotate_jpg", null));
foreach (array('thumb', 'resize') as $target) {
${'group_'.$target} = $form->group($target)->label(ucfirst($target)." ".t("images optimization"))->set_attr("id","g-image-optimizer-admin-form-".$target);
${'group_'.$target}->checkbox("enable_".$target)
->label(t("Enable optimization"))
->checked(module::get_var("image_optimizer", "enable_".$target, null));
${'group_'.$target}->checkbox("update_mode_".$target)
->label(t("Enable update mode - deactivates all other graphics rules to allow fast optimization on existing images; MUST deactivate this after initial rebuild!"))
->checked(module::get_var("image_optimizer", "update_mode_".$target, null));
${'group_'.$target}->checkbox("rebuild_".$target)
->label(t("Mark all existing images for rebuild - afterward, go to Maintenace | Rebuild Images"))
->checked(false); // always set as false
${'group_'.$target}->dropdown("convert_".$target."_png")
->label(t("PNG conversion"))
->options(array(0=>t("none"),
"jpg"=>("JPG ".t("(not lossless)"))))
->selected(module::get_var("image_optimizer", "convert_".$target."_png", null));
${'group_'.$target}->dropdown("convert_".$target."_gif")
->label(t("GIF conversion"))
->options(array(0=>t("none"),
"jpg"=>("JPG ".t("(not lossless)")),
"png"=>("PNG ".t("(lossless)"))))
->selected(module::get_var("image_optimizer", "convert_".$target."_gif", null));
${'group_'.$target}->dropdown("optlevel_".$target."_jpg")
->label(t("JPG compression optimization (default: enabled)"))
->options(array(0=>t("disabled"),
1=>t("enabled")))
->selected(module::get_var("image_optimizer", "optlevel_".$target."_jpg", null));
${'group_'.$target}->dropdown("optlevel_".$target."_png")
->label(t("PNG compression optimization (default: level 2)"))
->options(array(0=>t("disabled"),
1=>t("level 1: 1 trial"),
2=>t("level 2: 8 trials"),
3=>t("level 3: 16 trials"),
4=>t("level 4: 24 trials"),
5=>t("level 5: 48 trials"),
6=>t("level 6: 120 trials"),
7=>t("level 7: 240 trials")))
->selected(module::get_var("image_optimizer", "optlevel_".$target."_png", null));
${'group_'.$target}->dropdown("optlevel_".$target."_gif")
->label(t("GIF compression optimization (default: enabled)"))
->options(array(0=>t("disabled"),
1=>t("enabled")))
->selected(module::get_var("image_optimizer", "optlevel_".$target."_gif", null));
${'group_'.$target}->checkbox("metastrip_".$target)
->label(t("Remove all meta data"))
->checked(module::get_var("image_optimizer", "metastrip_".$target, null));
${'group_'.$target}->checkbox("progressive_".$target)
->label(t("Make images progressive/interlaced"))
->checked(module::get_var("image_optimizer", "progressive_".$target, null));
}
$form->submit("")->value(t("Save"));
return $form;
}
}

View File

@ -0,0 +1,17 @@
#g-content fieldset {
display: block;
}
#g-content fieldset.g-image-optimizer-admin-form-top {
width: 80%;
clear: both;
}
#g-content fieldset.g-image-optimizer-admin-form-left {
width: 45%;
float: left;
clear: left;
margin-right: 2%
}
#g-content fieldset.g-image-optimizer-admin-form-right {
width: 45%;
clear: right;
}

View File

@ -0,0 +1,72 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 gallery_graphics extends gallery_graphics_Core {
// this is copied from modules/gallery/helpers/gallery_graphics.php
/**
* Rotate an image. Valid options are degrees
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function rotate($input_file, $output_file, $options) {
graphics::init_toolkit();
module::event("graphics_rotate", $input_file, $output_file, $options);
// BEGIN mod to original function
$image_info = getimagesize($input_file); // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG)
if (module::get_var("image_optimizer","rotate_jpg") || $image_info[2] == 2) {
// rotate_jpg enabled, the file is a jpg. get args
$path = module::get_var("image_optimizer", "path_jpg");
$exec_args = " -rotate ";
$exec_args .= $options["degrees"] > 0 ? $options["degrees"] : $options["degrees"]+360;
$exec_args .= " -copy all -optimize -outfile ";
// run it - from input_file to tmp_file
$tmp_file = image_optimizer::make_temp_name($output_file);
exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($input_file), $exec_output, $exec_status);
if ($exec_status || !filesize($tmp_file)) {
// either a blank/nonexistant file or an error - log an error and pass to normal function
Kohana_Log::add("error", "image_optimizer rotation failed on ".$output_file);
unlink($tmp_file);
} else {
// worked - move temp to output
rename($tmp_file, $output_file);
$status = true;
}
}
if (!$status) {
// we got here if we weren't supposed to use jpegtran or if jpegtran failed
// END mod to original function
Image::factory($input_file)
->quality(module::get_var("gallery", "image_quality"))
->rotate($options["degrees"])
->save($output_file);
// BEGIN mod to original function
}
// END mod to original function
module::event("graphics_rotate_completed", $input_file, $output_file, $options);
}
}

View File

@ -0,0 +1,343 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 image_optimizer_Core {
/**
* These functions deal with the toolkit installations
*/
// define the tool names
static function tool_name($type) {
$type = strtolower($type);
switch($type) {
case "jpg":
$tool = "jpegtran";
break;
case "png":
$tool = "optipng";
break;
case "gif":
$tool = "gifsicle";
break;
default:
$tool = "";
}
return $tool;
}
// find server-installed versions of the tools
static function tool_installed_path($type) {
$type = strtolower($type);
$path = exec('which '.image_optimizer::tool_name($type));
$path = is_file($path) ? $path : "(not found)";
return $path;
}
// return status of tool path and attempt to fix permissions if not executable
static function tool_status($type) {
$type = strtolower($type);
$path = module::get_var("image_optimizer","path_".$type);
if (is_file($path) && !is_link($path)) {
if (is_executable($path)) {
$status = true;
} else {
// try to fix its permissions. return false if it doesn't work.
$status = chmod($path,0755);
}
} else {
$status = false;
}
// set module variable
module::set_var("image_optimizer", "configstatus_".$type, $status);
return $status;
}
// return tool version as string
static function tool_version($type) {
$type = strtolower($type);
if (image_optimizer::tool_status($type)) {
switch($type) {
case "jpg":
$path = module::get_var("image_optimizer","path_".$type);
// jpegtran is weird as it doesn't have a version flag. so, we run in verbose mode with a fake file and catch stderr, which exec() can't do.
// this is sort of a hack, but since there's no clean way available...
$cmd = escapeshellcmd($path)." -verbose ".MODPATH."image_optimizer/this_file_does_not_exist.jpg";
$output = image_optimizer::get_pipe($cmd, 2);
$output = "Correctly configured! " . substr($output, 0, strpos($output, "\n"));
break;
case "png":
case "gif":
$path = module::get_var("image_optimizer","path_".$type);
exec(escapeshellcmd($path)." --version", $output);
$output = "Correctly configured! " . $output[0];
break;
default:
$output = t("Only jpg/png/gif supported");
}
} else {
$output = t("Invalid configuration");
}
return $output;
}
/**
* These functions supplement the rule functions in modules/gallery/helpers/graphics.php
* Note that all rule-changing functions in graphics.php trigger all images to be marked as dirty for rebuild, which we often want to avoid.
*/
// add image_optimizer rules without marking for dirty (based on add_rule)
static function add_image_optimizer_rule($target) {
// to prevent duplicates, remove any existing instances first
image_optimizer::remove_image_optimizer_rule($target);
// then add the new one
$rule = ORM::factory("graphics_rule");
$rule->module_name = "image_optimizer";
$rule->target = $target;
$rule->operation = 'image_optimizer::optimize';
$rule->priority = 999999999; // this MUST be larger than all others to be last
$rule->args = serialize($target); // this isn't typical for other graphics rules
$rule->active = true;
$rule->save();
}
// remove image_optimizer rules without marking for dirty (based on remove_rule)
static function remove_image_optimizer_rule($target) {
db::build()
->delete("graphics_rules")
->where("target", "=", $target)
->where("module_name", "=", "image_optimizer")
->execute();
}
// activate update mode - disactivates all currently-active rules except those of image_optimizer without marking for dirty
// sets update_mode_thumb/resize variable with serialized list of deactivated rule ids
static function activate_update_mode($target) {
// find all currently active non-image-optimizer rules
$rules = db::build()
->from("graphics_rules")
->select("id")
->where("active", "=", true)
->where("target", "=", $target)
->where("module_name", "!=", "image_optimizer")
->execute();
// use found rules to build ids array and deactivate rules
$ids = array();
foreach ($rules as $rule) {
$ids[] = $rule->id;
db::build()
->update("graphics_rules")
->where("id", "=", $rule->id)
->set("active", false) // deactivation!
->execute();
}
// set module variable as deactivated rule ids
module::set_var("image_optimizer", "update_mode_".$target, serialize($ids));
// display a warning that we're in update mode
site_status::warning(
t("Image optimizer is in thumb/resize update mode - remember to exit <a href=\"%url\">here</a> after rebuild!",
array("url" => html::mark_clean(url::site("admin/image_optimizer")))),
"image_optimizer_update_mode");
}
// deactivate update mode - re-activates rules marked in the update_mode_thumb/resize variable as previously deactivated
static function deactivate_update_mode($target) {
// get deactivated rule ids
$ids = unserialize(module::get_var("image_optimizer", "update_mode_".$target));
// activate them
foreach ($ids as $id) {
db::build()
->update("graphics_rules")
->where("id", "=", $id)
->set("active", true) // activation!
->execute();
}
// reset module variable
module::set_var("image_optimizer", "update_mode_".$target, false);
// clear update mode warning
if (!module::get_var("image_optimizer", "update_mode_thumb") && !module::get_var("image_optimizer", "update_mode_resize")) {
site_status::clear("image_optimizer_update_mode");
}
}
// mark all as dirty (in similar syntax to above)
static function dirty($target) {
graphics::mark_dirty($target == "thumb", $target == "resize");
}
/**
* the main optimize function
*
* the function arguments are the same format as other graphics rules. the only "option" is $target, hence why it's renamed in the function def.
*
* NOTE: unlike other graphics transformations, this only uses the output file! if it isn't already there, we don't do anything.
* among other things, this means that the original, full-size images are never touched.
*/
static function optimize($input_file, $output_file, $target, $item=null) {
// see if output file exists and is writable
if (is_writable($output_file)) {
// see if input is a supported file type. if not, return without doing anything.
$image_info = getimagesize($input_file); // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG)
switch ($image_info[2]) {
case 1:
$type_old = "gif";
$convert = module::get_var("image_optimizer", "convert_".$target."_gif");
break;
case 2:
$type_old = "jpg";
$convert = 0; // no conversion possible here...
break;
case 3:
$type_old = "png";
$convert = module::get_var("image_optimizer", "convert_".$target."_png");
break;
default:
// not a supported file type
return;
}
} else {
// file doesn't exist or isn't writable
return;
}
// set new file type
$type = $convert ? $convert : $type_old;
// convert image type (if applicable). this isn't necessarily lossless.
if ($convert) {
$output_file_new = legal_file::change_extension($output_file, $type);
// perform conversion using standard Gallery toolkit (GD/ImageMagick/GraphicsMagick)
// note: if input was a GIF, this will kill animation
$image = Image::factory($output_file)
->quality(module::get_var("gallery", "image_quality"))
->save($output_file_new);
// if filenames are different, move the new on top of the old
if ($output_file != $output_file_new) {
/**
* HACK ALERT! Gallery3 is still broken with regard to treating thumb/resizes with proper extensions. This doesn't try to fix that.
* Normal Gallery setup:
* photo thumb -> keep photo type, keep photo extension
* album thumb -> keep source photo thumb type, change extension to jpg (i.e. ".album.jpg" even for png/gif)
* Also, missing_photo.png is similarly altered...
*
* Anyway, to avoid many rewrites of core functions (and not-easily-reversible database changes), this module also forces the extension to stay the same.
* With image optimizer conversion:
* photo thumb -> change type, keep photo extension (i.e. "photo.png" photo becomes "photo.png" thumb even if type has changed)
* album thumb -> keep source photo thumb type, change extension to jpg (i.e. ".album.jpg" even for png/gif)
*/
rename($output_file_new, $output_file);
}
}
// get module variables
$configstatus = module::get_var("image_optimizer", "configstatus_".$type);
$path = module::get_var("image_optimizer", "path_".$type);
$opt = module::get_var("image_optimizer", "optlevel_".$target."_".$type);
$meta = module::get_var("image_optimizer", "metastrip_".$target);
$prog = module::get_var("image_optimizer", "progressive_".$target);
// make sure the toolkit is configured correctly and we want to use it - if not, return without doing anything.
if ($configstatus) {
if (!$prog && !$meta && !$opt) {
// nothing to do!
return;
}
} else {
// not configured correctly
return;
}
/**
* do the actual optimization
*/
// set parameters
switch ($type) {
case "jpg":
$exec_args = $opt ? " -optimize" : "";
$exec_args .= $meta ? " -copy none" : " -copy all";
$exec_args .= $prog ? " -progressive" : "";
$exec_args .= " -outfile ";
break;
case "png":
$exec_args = $opt ? " -o".$opt : "";
$exec_args .= $meta ? " -strip all" : "";
$exec_args .= $prog ? " -i 1" : "";
$exec_args .= " -quiet -out ";
break;
case "gif":
$exec_args = $opt ? " --optimize=3" : ""; // levels 1 and 2 don't really help us
$exec_args .= $meta ? " --no-comments --no-extensions --no-names" : " --same-comments --same-extensions --same-names";
$exec_args .= $prog ? " --interlace" : " --same-interlace";
$exec_args .= " --careful --output ";
break;
}
// run it - from output_file to tmp_file.
$tmp_file = image_optimizer::make_temp_name($output_file);
exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($output_file), $exec_output, $exec_status);
if ($exec_status || !filesize($tmp_file)) {
// either a blank/nonexistant file or an error - do nothing to the output, but log an error and delete the temp (if any)
Kohana_Log::add("error", "image_optimizer optimization failed on ".$output_file);
unlink($tmp_file);
} else {
// worked - move temp to output
rename($tmp_file, $output_file);
}
}
/**
* make a unique temporary filename. this bit is inspired/copied from
* the system/libraries/Image.php save function and the system/libraries/drivers/Image/ImageMagick.php process function
*/
static function make_temp_name($file) {
// Separate the directory and filename
$dir = pathinfo($file, PATHINFO_DIRNAME);
$file = pathinfo($file, PATHINFO_BASENAME);
// Normalize the path
$dir = str_replace('\\', '/', realpath($dir)).'/';
// Unique temporary filename
$tmp_file = $dir.'k2img--'.sha1(time().$dir.$file).substr($file, strrpos($file, '.'));
return $tmp_file;
}
/**
* get stdin, stdout, or stderr from shell command. php commands like exec() don't do this.
* this is only used to get jpegtran's version info in the admin screen.
*
* see http://stackoverflow.com/questions/2320608/php-stderr-after-exec
*/
static function get_pipe($cmd, $pipe) {
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w"), // stderr
);
$process = proc_open($cmd, $descriptorspec, $pipes);
$output = stream_get_contents($pipes[$pipe]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
return $output;
}
}

View File

@ -0,0 +1,29 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 image_optimizer_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(
Menu::factory("link")
->id("image_optimizer")
->label(t("Image optimizer"))
->url(url::site("admin/image_optimizer")));
}
}

View File

@ -0,0 +1,75 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2012 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 image_optimizer_installer {
static function install() {
$defaults = array('jpg' => '1', 'png' => '2', 'gif' => '1');
foreach ($defaults as $type => $optlevel) {
// set default path as the pre-compiled versions in the lib
module::set_var("image_optimizer", "path_".$type, MODPATH."image_optimizer/lib/".image_optimizer::tool_name($type));
// check config status (also sets configstatus_ variables and ensures that the permissions are set correctly)
image_optimizer::tool_status($type);
// set default optimization levels
module::set_var("image_optimizer", "optlevel_thumb_".$type, $optlevel);
module::set_var("image_optimizer", "optlevel_resize_".$type, $optlevel);
}
module::set_var("image_optimizer", "rotate_jpg", true);
module::set_var("image_optimizer", "enable_thumb", true);
module::set_var("image_optimizer", "enable_resize", true);
module::set_var("image_optimizer", "update_mode_thumb", false);
module::set_var("image_optimizer", "update_mode_resize", false);
module::set_var("image_optimizer", "metastrip_thumb", true);
module::set_var("image_optimizer", "convert_thumb_png", "jpg");
module::set_var("image_optimizer", "convert_resize_png", false);
module::set_var("image_optimizer", "convert_thumb_gif", "jpg");
module::set_var("image_optimizer", "convert_resize_gif", false);
module::set_var("image_optimizer", "metastrip_resize", false);
module::set_var("image_optimizer", "progressive_thumb", false);
module::set_var("image_optimizer", "progressive_resize", true);
module::set_version("image_optimizer", 1);
image_optimizer::add_image_optimizer_rule("thumb");
image_optimizer::add_image_optimizer_rule("resize");
}
static function activate() {
// add graphics rules if enabled
if (module::get_var("image_optimizer", "enable_thumb")) {
image_optimizer::add_image_optimizer_rule("thumb");
}
if (module::get_var("image_optimizer", "enable_resize")) {
image_optimizer::add_image_optimizer_rule("resize");
}
}
static function deactivate() {
// ensure that update modes are disabled
image_optimizer::deactivate_update_mode("thumb");
image_optimizer::deactivate_update_mode("resize");
// remove graphics rules
image_optimizer::remove_image_optimizer_rule("thumb");
image_optimizer::remove_image_optimizer_rule("resize");
}
static function uninstall() {
// deactivate
module::deactivate("image_optimizer");
// delete vars from database
module::clear_all_vars("image_optimizer");
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
name = Image Optimizer
description = "Use jpegtran, optipng, and gifsicle for lossless optimization and rotation."
version = 1
author_name = "Shad Laws"
author_url = ""
info_url = "http://codex.gallery2.org/Gallery3:Modules:image_optimizer"
discuss_url = "http://gallery.menalto.com/node/110262"

View File

@ -0,0 +1,51 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<style>
@import "<?= url::file("modules/image_optimizer/css/admin_image_optimizer.css"); ?>";
</style>
<div id="g-image-optimizer-admin">
<h2>
<?= t("Image optimizer settings") ?>
</h2>
<p>
<?= t("This module uses three underlying toolkits, all performing <b>lossless</b> transformations.")." ".
t("You can set the paths to each of the three toolkits below.")." ".
t("By default, this module uses it's own pre-compiled versions, included as libraries.")." ".
t("Additionally, your server may have copies installed elsewhere (see table below).") ?><br/>
<table>
<tr>
<td></td>
<td><b><?= t("Name and author") ?></b></td>
<td><b><?= t("Server-installed path") ?></b></td>
<td><b><?= t("Configuration status") ?></b></td>
</tr>
<tr>
<td>JPG</td>
<td><a href='http://jpegclub.org/droppatch.v09.tar.gz'>Jpegtran</a> <?= t("by") ?> <a href='http://jpegclub.org/jpegtran'>Jpegclub</a></td>
<td><?= $installed_path_jpg ?></td>
<td><?= $version_jpg ?></td>
</tr>
<tr>
<td>PNG</td>
<td><a href='http://shanebishop.net/uploads/optipng.tar.gz'>OptiPNG</a> <?= t("by") ?> <a href='http://optipng.sourceforge.net'>Cosmin Truta et al.</a></td>
<td><?= $installed_path_png ?></td>
<td><?= $version_png ?></td>
</tr>
<tr>
<td>GIF</td>
<td><a href='http://shanebishop.net/uploads/gifsicle.tar.gz'>GIFsicle</a> <?= t("by") ?> <a href='http://www.lcdf.org/gifsicle'>LCDF</a></td>
<td><?= $installed_path_gif ?></td>
<td><?= $version_gif ?></td>
</tr>
</table>
<?= t("This module was inspired by the WordPress module")." <a href='http://wordpress.org/extend/plugins/ewww-image-optimizer'>EWWW Image Optimizer</a> ".t("and the Gallery3 module")." <a href='http://codex.gallery2.org/Gallery3:Modules:jpegtran'>Jpegtran</a>." ?>
</p>
<p>
<b><?= t("Notes:") ?></b><br/>
<b>1. <?= t("Remove all meta data") ?></b>: <?= t("recommended for thumb images - 80% size reduction typical, which drastically changes page load speed") ?><br/>
<b>2. <?= t("Make images progressive/interlaced") ?></b>: <?= t("recommended for resize images - provides preview of photo during download") ?><br/>
<b>3. <?= t("Conversion") ?></b>: <?= t("recommended for thumb images - converting PNG/GIF to JPG can reduce the size by a huge amount, again helping page load speed") ?><br/>
<b>4. <?= t("Update mode") ?></b>: <?= t("used to speed up initial rebuild to optimize existing images by deactivating all other graphics rules - MUST ensure that no new images are created while this is enabled (use maintenance mode if needed), and MUST disable once initial rebuild is done.") ?><br/>
<b>5. <?= t("Windows / Linux") ?></b>: <?= t("the module's lib directory includes both Windows and Linux versions of the toolkits. For security reasons, Windows should not be used on production sites. Both versions are provided here to enable development copies to still run Windows without issue.") ?><br/>
</p>
<?= $form ?>
</div>

View File

@ -0,0 +1 @@
#g-register-form { width: 350px; }

View File

@ -0,0 +1,15 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<html>
<head>
<title><?= ($subject_prefix.$subject) ?></title>
</head>
<body>
<h2><?= $subject ?></h2>
<p>
<?= t("There's a new pending user registration from %name.<br/>You can access the site by <a href=\"%site_url\">clicking this link</a>, after which you can review and approve this request.",
array("name" => $user->full_name ? $user->full_name : $user->name,
"locale" => $locale,
"site_url" => html::mark_clean($admin_register_url))) ?>
</p>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
<?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 Form_Input extends Form_Input_Core {
/**
* Custom validation rule: numrange
* 0 args : returns error if not numeric
* 1 arg : returns error if not numeric OR if below min
* 2 args : returns error if not numeric OR if below min OR if above max
*/
protected function rule_numrange($min = null, $max = null) {
if (is_numeric($this->value)) {
if (!is_null($min) && ($this->value < $min)) {
// below min
$this->errors['numrange'] = true;
$this->error_messages['numrange'] = t('Value is below minimum of').' '.$min;
} elseif (!is_null($max) && ($this->value > $max)) {
// above max
$this->errors['numrange'] = true;
$this->error_messages['numrange'] = t('Value is above maximum of').' '.$max;;
}
} else {
// not numeric
$this->errors['numrange'] = true;
$this->error_messages['numrange'] = t('Value is not numeric');
}
}
/**
* Custom validation rule: color
* returns no error if string is formatted as #hhhhhh OR if string is empty
* to exclude the empty case, add "required" as another rule
*/
protected function rule_color() {
if (preg_match("/^#[0-9A-Fa-f]{6}$|^$/", $this->value) == 0) {
$this->errors['color'] = true;
$this->error_messages['color'] = t('Color is not in #hhhhhh format');
}
}
}

View File

@ -0,0 +1,59 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<!--[if lt IE 9]>
<?= html::script(gallery::find_file("js", "excanvas.compiled.js", false)) ?>
<![endif]-->
<script type="text/javascript">
// define flag variables if not already defined elsewhere
if (typeof(jQueryScriptFlag) == 'undefined') {
var jQueryScriptFlag = false;
};
if (typeof(jQueryTagCanvasScriptFlag) == 'undefined') {
var jQueryTagCanvasScriptFlag = false;
};
function initScripts() {
// load scripts if not already loaded
if (typeof(jQuery) == 'undefined') {
if (!jQueryScriptFlag) {
// load both scripts
jQueryScriptFlag = true;
jQueryTagCanvasScriptFlag = true;
document.write("<scr" + "ipt type=\"text/javascript\" src=\"<?= url::base(false).gallery::find_file("js", "jquery.js", false) ?>\"></scr" + "ipt>");
document.write("<scr" + "ipt type=\"text/javascript\" src=\"<?= url::base(false).gallery::find_file("js", "jquery.tagcanvas.mod.min.js", false) ?>\"></scr" + "ipt>");
};
setTimeout("initScripts()", 50);
} else if (typeof(jQuery().tagcanvas) == 'undefined') {
if (!jQueryTagCanvasScriptFlag) {
// load one script
jQueryTagCanvasScriptFlag = true;
document.write("<scr" + "ipt type=\"text/javascript\" src=\"<?= url::base(false).gallery::find_file("js", "jquery.tagcanvas.mod.min.js", false) ?>\"></scr" + "ipt>");
};
setTimeout("initScripts()", 50);
} else {
// libraries loaded - run actual code
function redraw() {
// set g-tag-cloud-html5-embed-canvas size
$("#g-tag-cloud-html5-embed-canvas").attr({
'width' : $("#g-tag-cloud-html5-embed").parent().width(),
'height': $("#g-tag-cloud-html5-embed").parent().height()
});
// start g-tag-cloud-html5-embed-canvas
if(!$('#g-tag-cloud-html5-embed-canvas').tagcanvas(<?= $options ?>,'g-tag-cloud-html5-embed-tags')) {
// something went wrong, hide the canvas container g-tag-cloud-html5-embed
$('#g-tag-cloud-html5-embed').hide();
};
};
// resize and redraw the canvas
$(document).ready(redraw);
$(window).resize(redraw);
};
};
initScripts();
</script>
<div id="g-tag-cloud-html5-embed">
<canvas id="g-tag-cloud-html5-embed-canvas">
<? echo t('Tag cloud loading...'); ?>
</canvas>
</div>
<div id="g-tag-cloud-html5-embed-tags" style="display: none">
<?= $cloud ?>
</div>