diff options
Diffstat (limited to 'modules/watermark')
| -rw-r--r-- | modules/watermark/controllers/admin_watermarks.php | 158 | ||||
| -rw-r--r-- | modules/watermark/helpers/watermark.php | 82 | ||||
| -rw-r--r-- | modules/watermark/helpers/watermark_event.php | 29 | ||||
| -rw-r--r-- | modules/watermark/helpers/watermark_installer.php | 42 | ||||
| -rw-r--r-- | modules/watermark/module.info | 7 | ||||
| -rw-r--r-- | modules/watermark/views/admin_watermarks.html.php | 39 |
6 files changed, 357 insertions, 0 deletions
diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php new file mode 100644 index 0000000..222279e --- /dev/null +++ b/modules/watermark/controllers/admin_watermarks.php @@ -0,0 +1,158 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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_Watermarks_Controller extends Admin_Controller { + public function index() { + $name = module::get_var("watermark", "name"); + + $view = new Admin_View("admin.html"); + $view->page_title = t("Watermarks"); + $view->content = new View("admin_watermarks.html"); + if ($name) { + $view->content->name = module::get_var("watermark", "name"); + $view->content->url = url::file("var/modules/watermark/$name"); + $view->content->width = module::get_var("watermark", "width"); + $view->content->height = module::get_var("watermark", "height"); + $view->content->position = module::get_var("watermark", "position"); + } + print $view; + } + + public function form_edit() { + print watermark::get_edit_form(); + } + + public function edit() { + access::verify_csrf(); + + $form = watermark::get_edit_form(); + if ($form->validate()) { + module::set_var("watermark", "position", $form->edit_watermark->position->value); + module::set_var("watermark", "transparency", $form->edit_watermark->transparency->value); + $this->_update_graphics_rules(); + + log::success("watermark", t("Watermark changed")); + message::success(t("Watermark changed")); + json::reply( + array("result" => "success", + "location" => url::site("admin/watermarks"))); + } else { + json::reply(array("result" => "error", "html" => (string)$form)); + } + } + + public function form_delete() { + print watermark::get_delete_form(); + } + + public function delete() { + access::verify_csrf(); + + $form = watermark::get_delete_form(); + if ($form->validate()) { + if ($name = basename(module::get_var("watermark", "name"))) { + system::delete_later(VARPATH . "modules/watermark/$name"); + + module::clear_var("watermark", "name"); + module::clear_var("watermark", "width"); + module::clear_var("watermark", "height"); + module::clear_var("watermark", "mime_type"); + module::clear_var("watermark", "position"); + $this->_update_graphics_rules(); + + log::success("watermark", t("Watermark deleted")); + message::success(t("Watermark deleted")); + } + json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); + } else { + json::reply(array("result" => "error", "html" => (string)$form)); + } + } + + public function form_add() { + print watermark::get_add_form(); + } + + public function add() { + access::verify_csrf(); + + $form = watermark::get_add_form(); + // For TEST_MODE, we want to simulate a file upload. Because this is not a true upload, Forge's + // validation logic will correctly reject it. So, we skip validation when we're running tests. + if (TEST_MODE || $form->validate()) { + $file = $_POST["file"]; + // Forge prefixes files with "uploadfile-xxxxxxx" for uniqueness + $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', basename($file)); + + try { + list ($width, $height, $mime_type, $extension) = photo::get_file_metadata($file); + // Sanitize filename, which ensures a valid extension. This renaming prevents the issues + // addressed in ticket #1855, where an image that looked valid (header said jpg) with a + // php extension was previously accepted without changing its extension. + $name = legal_file::sanitize_filename($name, $extension, "photo"); + } catch (Exception $e) { + message::error(t("Invalid or unidentifiable image file")); + system::delete_later($file); + return; + } + + rename($file, VARPATH . "modules/watermark/$name"); + module::set_var("watermark", "name", $name); + module::set_var("watermark", "width", $width); + module::set_var("watermark", "height", $height); + module::set_var("watermark", "mime_type", $mime_type); + module::set_var("watermark", "position", $form->add_watermark->position->value); + module::set_var("watermark", "transparency", $form->add_watermark->transparency->value); + $this->_update_graphics_rules(); + system::delete_later($file); + + message::success(t("Watermark saved")); + log::success("watermark", t("Watermark saved")); + json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); + } else { + // rawurlencode the results because the JS code that uploads the file buffers it in an + // iframe which entitizes the HTML and makes it difficult for the JS to process. If we url + // encode it now, it passes through cleanly. See ticket #797. + json::reply(array("result" => "error", "html" => rawurlencode((string)$form))); + } + + // Override the application/json mime type. The dialog based HTML uploader uses an iframe to + // buffer the reply, and on some browsers (Firefox 3.6) it does not know what to do with the + // JSON that it gets back so it puts up a dialog asking the user what to do with it. So force + // the encoding type back to HTML for the iframe. + // See: http://jquery.malsup.com/form/#file-upload + header("Content-Type: text/html; charset=" . Kohana::CHARSET); + } + + private function _update_graphics_rules() { + graphics::remove_rules("watermark"); + if ($name = module::get_var("watermark", "name")) { + foreach (array("thumb", "resize") as $target) { + graphics::add_rule( + "watermark", $target, "gallery_graphics::composite", + array("file" => VARPATH . "modules/watermark/$name", + "width" => module::get_var("watermark", "width"), + "height" => module::get_var("watermark", "height"), + "position" => module::get_var("watermark", "position"), + "transparency" => 101 - module::get_var("watermark", "transparency")), + 1000); + } + } + } +}
\ No newline at end of file diff --git a/modules/watermark/helpers/watermark.php b/modules/watermark/helpers/watermark.php new file mode 100644 index 0000000..3357c14 --- /dev/null +++ b/modules/watermark/helpers/watermark.php @@ -0,0 +1,82 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 watermark_Core { + static function get_add_form() { + for ($i = 1; $i <= 100; $i++) { + $range[$i] = "$i%"; + } + + $form = new Forge("admin/watermarks/add", "", "post", array("id" => "g-add-watermark-form")); + $group = $form->group("add_watermark")->label(t("Upload watermark")); + $group->upload("file")->label(t("Watermark"))->rules("allow[jpg,png,gif]|size[1MB]|required") + ->error_messages("required", "You must select a watermark") + ->error_messages("invalid_type", "The watermark must be a JPG, GIF or PNG") + ->error_messages("max_size", "The watermark is too big (1 MB max)"); + $group->dropdown("position")->label(t("Watermark position")) + ->options(self::positions()) + ->selected("southeast"); + $group->dropdown("transparency")->label(t("Transparency (100% = completely transparent)")) + ->options($range) + ->selected(1); + $group->submit("")->value(t("Upload")); + return $form; + } + + static function get_edit_form() { + for ($i = 1; $i <= 100; $i++) { + $range[$i] = "$i%"; + } + + $form = new Forge("admin/watermarks/edit", "", "post", array("id" => "g-edit-watermark-form")); + $group = $form->group("edit_watermark")->label(t("Edit Watermark")); + $group->dropdown("position")->label(t("Watermark Position")) + ->options(self::positions()) + ->selected(module::get_var("watermark", "position")); + $group->dropdown("transparency")->label(t("Transparency (100% = completely transparent)")) + ->options($range) + ->selected(module::get_var("watermark", "transparency")); + $group->submit("")->value(t("Save")); + return $form; + } + + static function get_delete_form() { + $form = new Forge("admin/watermarks/delete", "", "post", array("id" => "g-delete-watermark-form")); + $group = $form->group("delete_watermark")->label(t("Really delete Watermark?")); + $group->submit("")->value(t("Delete")); + return $form; + } + + static function positions() { + return array("northwest" => t("Northwest"), + "north" => t("North"), + "northeast" => t("Northeast"), + "west" => t("West"), + "center" => t("Center"), + "east" => t("East"), + "southwest" => t("Southwest"), + "south" => t("South"), + "southeast" => t("Southeast")); + } + + static function position($key) { + $positions = self::positions(); + return $positions[$key]; + } +}
\ No newline at end of file diff --git a/modules/watermark/helpers/watermark_event.php b/modules/watermark/helpers/watermark_event.php new file mode 100644 index 0000000..7547515 --- /dev/null +++ b/modules/watermark/helpers/watermark_event.php @@ -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-2013 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 watermark_event_Core { + static function admin_menu($menu, $theme) { + $menu->get("content_menu") + ->append( + Menu::factory("link") + ->id("watermarks") + ->label(t("Watermarks")) + ->url(url::site("admin/watermarks"))); + } +} diff --git a/modules/watermark/helpers/watermark_installer.php b/modules/watermark/helpers/watermark_installer.php new file mode 100644 index 0000000..1333891 --- /dev/null +++ b/modules/watermark/helpers/watermark_installer.php @@ -0,0 +1,42 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2013 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 watermark_installer { + static function install() { + $db = Database::instance(); + $db->query("CREATE TABLE IF NOT EXISTS {watermarks} ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(32) NOT NULL, + `width` int(9) NOT NULL, + `height` int(9) NOT NULL, + `active` boolean default 0, + `position` boolean default 0, + `mime_type` varchar(64) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + DEFAULT CHARSET=utf8;"); + + @mkdir(VARPATH . "modules/watermark"); + } + + static function uninstall() { + Database::instance()->query("DROP TABLE {watermarks}"); + dir::unlink(VARPATH . "modules/watermark"); + } +} diff --git a/modules/watermark/module.info b/modules/watermark/module.info new file mode 100644 index 0000000..e5003cd --- /dev/null +++ b/modules/watermark/module.info @@ -0,0 +1,7 @@ +name = "Watermarks" +description = "Allows users to watermark their photos" +version = 2 +author_name = "Gallery Team" +author_url = "http://codex.galleryproject.org/Gallery:Team" +info_url = "http://codex.galleryproject.org/Gallery3:Modules:watermark" +discuss_url = "http://galleryproject.org/forum_module_watermark" diff --git a/modules/watermark/views/admin_watermarks.html.php b/modules/watermark/views/admin_watermarks.html.php new file mode 100644 index 0000000..fc634b8 --- /dev/null +++ b/modules/watermark/views/admin_watermarks.html.php @@ -0,0 +1,39 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<div class="g-block"> + <h1> <?= t("Watermarks") ?> </h1> + <p> + <?= t("You can have one watermark for your Gallery. This watermark will be applied to all thumbnails and resized images, but it will not be applied to your full size images. To make sure that your guests can only see watermarked images, you should restrict access to your full size images.") ?> + </p> + + <div class="g-block-content"> + <? if (empty($name)): ?> + <a href="<?= url::site("admin/watermarks/form_add") ?>" + title="<?= t("Upload a watermark")->for_html_attr() ?>" + class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"><span class="ui-icon ui-icon-document-b"></span><?= t("Upload a watermark") ?></a> + <? else: ?> + <h2> <?= t("Active watermark") ?> </h2> + <p> + <?= t("Note that changing this watermark will require you to rebuild all of your thumbnails and resized images.") ?> + </p> + <div> + <div class="g-photo"> + <img width="<?= $width ?>" height="<?= $height ?>" src="<?= $url ?>" /> + <p> + <?= t("Position: %position", array("position" => watermark::position($position))) ?> + </p> + <p> + <?= t("Transparency: %transparency%", array("transparency" => module::get_var("watermark", "transparency"))) ?> + </p> + </div> + <div class="controls"> + <a href="<?= url::site("admin/watermarks/form_edit") ?>" + title="<?= t("Edit watermark")->for_html_attr() ?>" + class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"><span class="ui-icon ui-icon-pencil"></span><?= t("edit") ?></a> + <a href="<?= url::site("admin/watermarks/form_delete") ?>" + title="<?= t("Delete watermark")->for_html_attr() ?>" + class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"><span class="ui-icon ui-icon-trash"></span><?= t("delete") ?></a> + </div> + </div> + <? endif ?> + </div> +</div> |
