mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-08-07 15:40:41 -04:00
Allow the site admin to upload watermark images. Can't do much with them yet.
This commit is contained in:
@@ -114,7 +114,7 @@ class core_installer {
|
||||
UNIQUE KEY(`module_id`, `name`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
|
||||
foreach (array("albums", "resizes", "thumbs", "uploads") as $dir) {
|
||||
foreach (array("albums", "resizes", "thumbs", "uploads", "modules") as $dir) {
|
||||
@mkdir(VARPATH . $dir);
|
||||
}
|
||||
|
||||
@@ -156,5 +156,6 @@ class core_installer {
|
||||
system("/bin/rm -rf " . VARPATH . "resizes");
|
||||
system("/bin/rm -rf " . VARPATH . "thumbs");
|
||||
system("/bin/rm -rf " . VARPATH . "uploads");
|
||||
system("/bin/rm -rf " . VARPATH . "modules");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,31 +18,44 @@
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class Admin_Watermarks_Controller extends Admin_Controller {
|
||||
public function load() {
|
||||
public function index() {
|
||||
$form = watermark::get_watermark_form();
|
||||
Kohana::log("debug", print_r($form, 1));
|
||||
if ($form->validate()) {
|
||||
$file = $_POST["file"];
|
||||
Kohana::log("debug", $file);
|
||||
|
||||
$pathinfo = pathinfo($file);
|
||||
$watermark_target = $pathinfo["basename"];
|
||||
if (copy($file, VARPATH . $watermark_target)) {
|
||||
module::set_var("watermark", "watermark_image_path", $watermark_target);
|
||||
unlink($file);
|
||||
$form->success = _("Watermark saved");
|
||||
} else {
|
||||
// @todo set and error message
|
||||
if (request::method() == "post" && $form->validate()) {
|
||||
$file = $_POST["file"];
|
||||
$pathinfo = pathinfo($file);
|
||||
$name = $pathinfo["basename"];
|
||||
if (ORM::factory("watermark")->where("name", $name)->count_all() > 0) {
|
||||
message::add(_("There is already a watermark with that name"), log::WARNING);
|
||||
} else if (!($image_info = getimagesize($file))) {
|
||||
message::add(_("An error occurred while saving this watermark"), log::WARNING);
|
||||
} else {
|
||||
if (empty($pathinfo["extension"])) {
|
||||
$name .= "." . image_type_to_extension($image_info[2]);
|
||||
}
|
||||
if (!rename($file, VARPATH . "modules/watermark/$name")) {
|
||||
message::add(_("An error occurred while saving this watermark"), log::WARNING);
|
||||
} 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::add(_("Watermark saved"));
|
||||
url::redirect("admin/watermarks");
|
||||
}
|
||||
}
|
||||
@unlink($file);
|
||||
}
|
||||
|
||||
print $form;
|
||||
$view = new View("admin_watermarks.html");
|
||||
$view->watermarks = ORM::factory("watermark")->find_all();
|
||||
$view->form = watermark::get_watermark_form();
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function get_form($user_id) {
|
||||
try {
|
||||
// @todo check for admin user
|
||||
|
||||
$path = module::get_var("watermark", "watermark_image_path");
|
||||
$view = new View("watermark_position.html");
|
||||
|
||||
@@ -55,7 +68,7 @@ class Admin_Watermarks_Controller extends Admin_Controller {
|
||||
->find_all(1, 0)->current();
|
||||
|
||||
// @todo determine what to do if water mark is not set
|
||||
// @todo caclulate the view sizes
|
||||
// @todo calculate the view sizes
|
||||
$view->sample_image = $photo->resize_url();
|
||||
$scaleWidth = $photo->resize_width / $photo->width;
|
||||
$scaleHeight = $photo->resize_height / $photo->height;
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
*/
|
||||
class watermark_Core {
|
||||
public static function get_watermark_form() {
|
||||
$form = new Forge("admin/watermark/load", "", "post",
|
||||
array("id" => "gUploadWatermarkForm", "enctype" => "multipart/form-data"));
|
||||
$form = new Forge("admin/watermarks", "", "post");
|
||||
$group = $form->group("add_watermark")->label(_("Upload Watermark"));
|
||||
$group->upload("file")->label(_("Watermark"))->rules("allow[jpg,png,gif],size[1M]");
|
||||
$group->upload("file")->label(_("Watermark"))->rules("allow[jpg,png,gif]|size[1MB]|required");
|
||||
$group->submit(_("Upload"));
|
||||
return $form;
|
||||
}
|
||||
|
||||
public static function get_watermark_postion_form($position="southeast") {
|
||||
public static function get_watermark_position_form($position="southeast") {
|
||||
$form = new Forge("admin/watermark/position", "", "post");
|
||||
$group = $form->group("watermark_position")->label(_("Update Position"));
|
||||
$group->dropdown("position")->label(_("Watermark Position"))
|
||||
|
||||
@@ -22,13 +22,25 @@ class watermark_installer {
|
||||
$db = Database::instance();
|
||||
$version = module::get_version("watermark");
|
||||
if ($version == 0) {
|
||||
$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,
|
||||
`mime_type` varchar(64) default NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY(`name`))
|
||||
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
|
||||
module::set_version("watermark", 1);
|
||||
module::set_var("watermark", "watermark_image_path", "");
|
||||
module::set_var("watermark", "watermark_position", "southeast");
|
||||
@mkdir(VARPATH . "modules/watermark");
|
||||
}
|
||||
}
|
||||
|
||||
public static function uninstall() {
|
||||
module::delete("watermark");
|
||||
Database::instance()->query("DROP TABLE `watermarks`");
|
||||
dir::unlink(VARPATH . "modules/watermark");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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 {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<? 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") ?>">
|
||||
</li>
|
||||
<? endforeach ?>
|
||||
</ul>
|
||||
|
||||
<?= $form ?>
|
||||
Reference in New Issue
Block a user