summaryrefslogtreecommitdiff
path: root/modules/watermark
diff options
context:
space:
mode:
Diffstat (limited to 'modules/watermark')
-rw-r--r--modules/watermark/controllers/admin_watermarks.php137
-rw-r--r--modules/watermark/helpers/watermark.php23
-rw-r--r--modules/watermark/js/watermark.js125
-rw-r--r--modules/watermark/models/watermark.php21
-rw-r--r--modules/watermark/views/admin_watermarks.html.php41
-rw-r--r--modules/watermark/views/watermark_position.html.php16
6 files changed, 126 insertions, 237 deletions
diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php
index fa17ba8c..7a8eb217 100644
--- a/modules/watermark/controllers/admin_watermarks.php
+++ b/modules/watermark/controllers/admin_watermarks.php
@@ -19,81 +19,102 @@
*/
class Admin_Watermarks_Controller extends Admin_Controller {
public function index() {
- $form = watermark::get_watermark_form();
- if (request::method() == "post" && $form->validate()) {
- $file = $_POST["file"];
- $pathinfo = pathinfo($file);
- $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', $pathinfo["basename"]);
- if (ORM::factory("watermark")->where("name", $name)->count_all() > 0) {
- message::error(_("There is already a watermark with that name"));
- } else if (!($image_info = getimagesize($file))) {
- message::warning(_("An error occurred while saving this watermark"));
- } else {
- if (empty($pathinfo["extension"])) {
- $name .= "." . image_type_to_extension($image_info[2]);
- }
- if (!rename($file, VARPATH . "modules/watermark/$name")) {
- message::warning(_("An error occurred while saving this watermark"));
- } else {
- $watermark = ORM::factory("watermark");
- $watermark->name = $name;
- $watermark->width = $image_info[0];
- $watermark->height = $image_info[1];
- $watermark->mime_type = $image_info["mime"];
- $watermark->save();
-
- message::success(_("Watermark saved"));
- url::redirect("admin/watermarks");
- }
- }
- @unlink($file);
- }
+ $name = module::get_var("watermark", "name");
$view = new Admin_View("admin.html");
$view->content = new View("admin_watermarks.html");
- $view->content->watermarks = ORM::factory("watermark")->find_all();
- $view->content->form = watermark::get_watermark_form();
+ if ($name) {
+ $view->content->name = $name;
+ $view->content->url = url::file("var/modules/watermark/$name");
+ $view->content->width = $name;
+ $view->content->height = $name;
+ }
print $view;
}
- public function edit($watermark_id) {
+ public function form_add() {
+ print watermark::get_add_form();
}
- public function delete($watermark_id) {
+ public function form_edit() {
+ print watermark::get_edit_form();
}
- public function get_form($user_id) {
- try {
- $path = module::get_var("watermark", "watermark_image_path");
- $view = new View("watermark_position.html");
+ public function edit() {
+ $form = watermark::get_edit_form();
+ if ($form->validate()) {
+ module::set_var("watermark", "position", $form->edit_watermark->position->value);
+ print json_encode(
+ array("result" => "success",
+ "location" => url::site("admin/watermarks")));
+ } else {
+ print json_encode(
+ array("result" => "error",
+ "form" => $form->__toString()));
+ }
+ }
- if (empty($path)) {
- // @todo need to do something when there is no watermark
- }
+ public function form_delete() {
+ print watermark::get_delete_form();
+ }
+
+ public function delete() {
+ $form = watermark::get_delete_form();
+ if ($form->validate()) {
+ if ($name = module::get_var("watermark", "name")) {
+ @unlink(VARPATH . "modules/watermark/$name");
- $photo = ORM::factory("item")
- ->where("type", "photo")
- ->find_all(1, 0)->current();
+ 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");
- // @todo determine what to do if water mark is not set
- // @todo calculate the view sizes
- $view->sample_image = $photo->resize_url();
- $scaleWidth = $photo->resize_width / $photo->width;
- $scaleHeight = $photo->resize_height / $photo->height;
- $scale = $scaleHeight < $scaleWidth ? $scaleHeight : $scaleWidth;
+ log::success("watermark", _("Deleted watermark"));
+ message::success(_("Watermark deleted"));
+ }
+ print json_encode(
+ array("result" => "success",
+ "location" => url::site("admin/watermarks")));
+ } else {
+ print json_encode(
+ array("result" => "error",
+ "form" => $form->__toString()));
+ }
+ }
- $imageinfo = getimagesize(VARPATH . $path);
+ public function upload() {
+ $form = watermark::get_add_form();
+ if ($form->validate()) {
+ $file = $_POST["file"];
+ $pathinfo = pathinfo($file);
+ // Forge prefixes files with "uploadfile-xxxxxxx" for uniqueness
+ $name = preg_replace("/uploadfile-[^-]+-(.*)/", '$1', $pathinfo["basename"]);
- $view->watermark_height = $imageinfo[1] * $scale;
- $view->watermark_width = $imageinfo[0] * $scale;
- $view->watermark_image = url::abs_file("var/" . $path);
+ if (!($image_info = getimagesize($file)) ||
+ !in_array($image_info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
+ message::error(_("Unable to identify this image file"));
+ @unlink($file);
+ return;
+ }
- $current_position = module::get_var("watermark", "watermark_position");
- $view->watermark_position_form = watermark::get_watermark_postion_form($current_position);
+ rename($file, VARPATH . "modules/watermark/$name");
+ module::set_var("watermark", "name", $name);
+ module::set_var("watermark", "width", $image_info[0]);
+ module::set_var("watermark", "height", $image_info[1]);
+ module::set_var("watermark", "mime_type", $image_info["mime"]);
+ module::set_var("watermark", "position", $form->add_watermark->position->value);
+ message::success(_("Watermark saved"));
+ url::redirect("admin/watermarks");
+ @unlink($file);
- print $view;
- } catch (Exception $e) {
- print $e;
+ print json_encode(
+ array("result" => "success",
+ "location" => url::site("admin/watermarks")));
+ } else {
+ print json_encode(
+ array("result" => "error",
+ "form" => $form->__toString()));
}
}
} \ No newline at end of file
diff --git a/modules/watermark/helpers/watermark.php b/modules/watermark/helpers/watermark.php
index 6d8da35a..c17bf0ab 100644
--- a/modules/watermark/helpers/watermark.php
+++ b/modules/watermark/helpers/watermark.php
@@ -18,22 +18,35 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class watermark_Core {
- public static function get_watermark_form() {
- $form = new Forge("admin/watermarks", "", "post");
+ public static function get_add_form() {
+ $form = new Forge("admin/watermarks/upload", "", "post");
$group = $form->group("add_watermark")->label(_("Upload Watermark"));
$group->upload("file")->label(_("Watermark"))->rules("allow[jpg,png,gif]|size[1MB]|required");
+ $group->dropdown("position")->label(_("Watermark Position"))
+ ->options(array("northwest", "north", "northeast",
+ "west", "center", "east",
+ "southwest", "south", "southeast"))
+ ->selected("8");
$group->submit(_("Upload"));
return $form;
}
- public static function get_watermark_position_form($position="southeast") {
- $form = new Forge("admin/watermark/position", "", "post");
- $group = $form->group("watermark_position")->label(_("Update Position"));
+ public static function get_edit_form() {
+ $form = new Forge("admin/watermarks/edit", "", "post");
+ $group = $form->group("edit_watermark")->label(_("Edit Watermark"));
$group->dropdown("position")->label(_("Watermark Position"))
->options(array("northwest", "north", "northeast",
"west", "center", "east",
"southwest", "south", "southeast"))
->selected("8");
+ $group->submit(_("Modify"));
+ return $form;
+ }
+
+ public static function get_delete_form() {
+ $form = new Forge("admin/watermarks/delete", "", "post");
+ $group = $form->group("delete_watermark")->label(_("Delete Watermark"));
+ $group->submit(_("Delete"));
return $form;
}
} \ No newline at end of file
diff --git a/modules/watermark/js/watermark.js b/modules/watermark/js/watermark.js
deleted file mode 100644
index d90cdb80..00000000
--- a/modules/watermark/js/watermark.js
+++ /dev/null
@@ -1,125 +0,0 @@
-$("gUploadWatermarkForm").ready(function() {
- ajaxify_watermark_add_form();
-});
-
-function ajaxify_watermark_add_form() {
- $("#gUploadWatermarkForm").ajaxForm({
- complete:function(xhr, statusText) {
- $("#gUploadWatermarkForm").replaceWith(xhr.responseText);
- ajaxify_watermark_add_form();
- }
- });
-}
-
-var locations = {
- areas: {},
- names: ["northwest", "north", "northeast",
- "west", "center", "east",
- "southwest", "south", "southeast"],
- nameIndex: function(name) {
- for (var row=0; row < 3; row++) {
- for (var col=0; col < 3; col++) {
- var index = row * 3 + col;
- if (this.names[index] == name) {
- return index;
- }
- }
- }
- },
- getArea: function(x, y) {
- for (var row=0; row < 3; row++) {
- for (var col=0; col < 3; col++) {
- var name = this.names[row * 3 + col];
- var area = this.areas[name];
- var check = area.top <= y && y < area.bottom && area.left <= x && x < area.right;
- if (check) {
- return name;
- }
- }
- }
- },
- getDimension: function (area) {
- return this.areas[area];
- }
-};
-
-
-
-locations.areas["northeast"] = {};
-locations.areas["north"] = {};
-locations.areas["northwest"] = {};
-locations.areas["east"] = {};
-locations.areas["center"] = {};
-locations.areas["west"] = {};
-locations.areas["southeast"] = {};
-locations.areas["south"] = {};
-locations.areas["southwest"] = {};
-
-function calculateAreas(target) {
- var cell_height = $(target).attr("offsetHeight") / 3;
- var cell_width = $(target).attr("offsetWidth") / 3;
-
- var top = $(target).attr("offsetTop");
- for (var row=0; row < 3; row++) {
- var left = $(target).attr("offsetLeft");
- for (var col=0; col < 3; col++) {
- var name = locations.names[row * 3 + col];
- locations.areas[name] = {
- top: top,
- left: left,
- right: left + cell_width,
- bottom: top + cell_height};
- left += cell_width;
- }
- top += cell_height;
- }
-}
-
-function watermark_dialog_initialize() {
- // Adjust the size of the dialog to accomodate the image content
- var container = $("#gDialog").parent().parent();
- var container_height = $(container).attr("offsetHeight");
- var container_width = $(container).attr("offsetWidth");
-
- var new_height = $("#gDialog").attr("offsetHeight") +
- container.find("div.ui-dialog-titlebar").attr("offsetHeight") +
- container.find("div.ui-dialog-buttonpane").attr("offsetHeight");
- var height = Math.max(new_height, container_height);
- var width = Math.max($("#gDialog").attr("offsetWidth"), container_width);
- container.css("height", height + "px");
- container.css("width", width + "px");
- container.css("top", ((document.height - height) / 2) + "px");
- container.css("left", ((document.width - width) / 2) + "px");
-
- $("#gTargetImage").droppable({
- accept: "div",
- greedy: true,
- hoverClass: "droppable-hover",
- drop: function(ev, ui) {
- var areaname = locations.getArea(ui.position.left, ui.position.top);
- positionWatermark(areaname);
- $("#position").val(locations.nameIndex(areaname));
- }
- });
-
- $("#gWaterMark").draggable({
- helper: 'clone',
- containment: "#gTargetImage",
- opacity: .6
- });
-
- $("#position").change(function() {
- positionWatermark($("option:selected", this).text());
- });
-
- calculateAreas($("#gTargetImage"));
- var dropdown = $("#position");
- positionWatermark($("option:selected", dropdown).text());
-}
-
-function positionWatermark(area) {
- var region = locations.getDimension(area);
-
- $("#gWaterMark").css("top", region.top + "px");
- $("#gWaterMark").css("left", region.left + "px");
-}
diff --git a/modules/watermark/models/watermark.php b/modules/watermark/models/watermark.php
deleted file mode 100644
index b03ce0b7..00000000
--- a/modules/watermark/models/watermark.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2008 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_Model extends ORM {
-} \ No newline at end of file
diff --git a/modules/watermark/views/admin_watermarks.html.php b/modules/watermark/views/admin_watermarks.html.php
index 06cb086f..adeba0ef 100644
--- a/modules/watermark/views/admin_watermarks.html.php
+++ b/modules/watermark/views/admin_watermarks.html.php
@@ -1,14 +1,31 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
-<ul class="gWatermarks">
- <? foreach ($watermarks as $watermark): ?>
- <li>
- <img <?= photo::img_dimensions($watermark->width, $watermark->height, 72) ?>
- src="<?= url::file("var/modules/watermark/$watermark->name") ?>">
+<div id="#gWatermarks">
+ <h1> <?= _("Watermarks") ?> </h1>
+ <p>
+ <?= _("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>
- <a href="<?= url::site("admin/watermarks/edit/$watermark->id") ?>" class="gDialogLink"><?= _("edit") ?></a>
- <a href="<?= url::site("admin/watermarks/delete/$watermark->id") ?>"><?= _("delete") ?></a>
- </li>
- <? endforeach ?>
-</ul>
-
-<?= $form ?>
+ <? if (empty($name)): ?>
+ <a href="<?= url::site("admin/watermarks/form_add") ?>"
+ title="<?= _("Add Watermark") ?>"
+ class="gDialogLink"><?= _("Upload a watermark") ?></a>
+ <? else: ?>
+ <h2> <?= _("Active Watermark") ?> </h2>
+ <p>
+ <?= _("Note that changing this watermark will rebuild all of your thumbnails and resized images.") ?>
+ </p>
+ <p>
+ <div class="image">
+ <img width="<?= $width ?>" height="<? $height ?>" src="<?= $url ?>"/>
+ </div>
+ <div class="controls">
+ <a href="<?= url::site("admin/watermarks/form_edit") ?>"
+ title="<?= _("Edit Watermark") ?>"
+ class="gDialogLink"><?= _("edit") ?></a>
+ <a href="<?= url::site("admin/watermarks/form_delete") ?>"
+ title="<?= _("Delete Watermark") ?>"
+ class="gDialogLink"><?= _("delete") ?></a>
+ </div>
+ </p>
+ <? endif ?>
+</div>
diff --git a/modules/watermark/views/watermark_position.html.php b/modules/watermark/views/watermark_position.html.php
deleted file mode 100644
index 6a8b1d71..00000000
--- a/modules/watermark/views/watermark_position.html.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<? defined("SYSPATH") or die("No direct script access."); ?>
-<script type="text/javascript">
- $("#gDialog").ready(watermark_dialog_initialize);
-</script>
-<div id="gWatermarkAdmin">
- <div id="gTarget">
- <img id="gTargetImage" src="<?= $sample_image ?>"></img>
- <div id="gWaterMark" style="float:none;z-index:1005;position:absolute;top:100px">
- <img id ="gWaterMarkImage" src="<?= $watermark_image ?>"
- width="<?= $watermark_width ?>" height="<?= $watermark_height ?>" />
- </div>
- </div>
- <div id="gWatermarkPostionForm" >
- <?= $watermark_position_form ?>
- </div>
-</div>