1
0

Merge branch 'master' of github.com:kandsten/gallery3-contrib

This commit is contained in:
Kriss Andsten 2010-12-16 17:16:38 +01:00
commit f8c203c532
24 changed files with 2520 additions and 51 deletions

View File

@ -0,0 +1,124 @@
<?php
class Admin_Aws_S3_Controller extends Admin_Controller {
public function index() {
// require_once(MODPATH . "aws_s3/lib/s3.php");
$form = $this->_get_s3_form();
if (request::method() == "post") {
access::verify_csrf();
if ($form->validate()) {
module::set_var("aws_s3", "enabled", (isset($_POST['enabled']) ? true : false));
module::set_var("aws_s3", "access_key", $_POST['access_key']);
module::set_var("aws_s3", "secret_key", $_POST['secret_key']);
module::set_var("aws_s3", "bucket_name", $_POST['bucket_name']);
module::set_var("aws_s3", "g3id", $_POST['g3id']);
module::set_var("aws_s3", "url_str", $_POST['url_str']);
module::set_var("aws_s3", "sig_exp", $_POST['sig_exp']);
module::set_var("aws_s3", "use_ssl", (isset($_POST['use_ssl']) ? true : false));
if (module::get_var("aws_s3", "enabled") && !module::get_var("aws_s3", "synced", false))
site_status::warning(
t('Your site has not yet been syncronised with your Amazon S3 bucket. Content will not appear correctly until you perform syncronisation. <a href="%url" class="g-dialog-link">Fix this now</a>',
array("url" => html::mark_clean(url::site("admin/maintenance/start/aws_s3_task::sync?csrf=__CSRF__")))
), "aws_s3_not_synced");
message::success(t("Settings have been saved"));
url::redirect("admin/aws_s3");
}
else {
message::error(t("There was a problem with the submitted form. Please check your values and try again."));
}
}
$v = new Admin_View("admin.html");
$v->page_title = t("Amazon S3 Configuration");
$v->content = new View("admin_aws_s3.html");
$v->content->form = $form;
$v->content->end = "";
echo $v;
}
private function _get_s3_form() {
$form = new Forge("admin/aws_s3", "", "post", array("id" => "g-admin-s3-form"));
$group = $form->group("aws_s3")->label(t("Amazon S3 Settings"));
$group ->checkbox("enabled")
->id("s3-enabled")
->checked(module::get_var("aws_s3", "enabled"))
->label("S3 enabled");
$group ->input("access_key")
->id("s3-access-key")
->label("Access Key ID")
->value(module::get_var("aws_s3", "access_key"))
->rules("required")
->error_messages("required", "This field is required")
->message('<a target="_blank" href="https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key">Sign up to Amazon S3</a>');
$group ->input("secret_key")
->id("s3-secret-key")
->label("Secret Access Key")
->value(module::get_var("aws_s3", "secret_key"))
->rules("required")
->error_messages("required", "This field is required");
$group ->input("bucket_name")
->id("s3-bucket")
->label("Bucket Name")
->value(module::get_var("aws_s3", "bucket_name"))
->rules("required")
->error_messages("required", "This field is required")
->message("Note: This module will not create a bucket if it does not already exist. Please ensure you have already created the bucket and the bucket has the correct ACL permissions before continuing.");
$group ->input("g3id")
->id("s3-g3id")
->label("G3 ID")
->value(module::get_var("aws_s3", "g3id", md5(time())))
->rules("required")
->error_messages("required", "This field is required")
->message("This field allows for multiple G3 instances running off of a single S3 bucket.");
$group ->checkbox("use_ssl")
->id("s3-use-ssl")
->checked(module::get_var("aws_s3", "use_ssl"))
->label("Use SSL for S3 transfers");
$group = $form->group("cdn_settings")->label(t("CDN Settings"));
$group ->input("url_str")
->id("s3-url-str")
->label("URL String")
->value(module::get_var("aws_s3", "url_str", "http://{bucket}.s3.amazonaws.com/g3/{guid}/{resource}"))
->rules("required")
->message("Configure the URL to access uploaded resources on the CDN. Use the following variables to define and build up the URL:<br />
&bull; {bucket} - Bucket Name<br />
&bull; {guid} - Unique identifier for this gallery installation<br />
&bull; {resource} - The end path to the resource/object");
$group ->input("sig_exp")
->id("sig_exp")
->label("Private Content Signature Duration")
->value(module::get_var("aws_s3", "sig_exp", 60))
->rules("required")
->callback("aws_s3::validate_number")
->error_messages("not_numeric", "The value provided is not numeric. Please enter a number in this field.")
->message("Set the time in seconds for the generated signature for access to permission-restricted S3 objects<br /><br />
Note: this module does not yet support the creation of signatures to access private objects on S3 via CloudFront CDN.");
$form ->submit("save")
->value("Save Settings");
return $form;
}
}

View File

@ -0,0 +1,28 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 embedlinks_block extends embedlinks_block_Core {
static function get($block_id, $theme) {
if ($theme->item && $theme->item->view_1 == 1)
parent::get($block_id, $theme);
}
}

View File

@ -0,0 +1,31 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 embedlinks_theme extends embedlinks_theme_Core {
static function photo_bottom($theme) {
if (module::get_var("embedlinks", "InPageLinks")) {
$item = $theme->item;
if ($item->view_1 == 1)
return parent::photo_bottom($theme);
}
}
}

View File

@ -0,0 +1,41 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 item extends item_Core {
static function make_album_cover($item, $sync = false) {
if (!$sync)
parent::make_album_cover($item);
$parent = $item->parent();
if ($parent->id > 1) {
aws_s3::upload_album_cover($parent);
}
}
static function remove_album_cover($album) {
parent::remove_album_cover($album);
if ($album->id > 1) {
aws_s3::remove_album_cover($album);
}
}
}

View File

@ -0,0 +1,191 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 aws_s3_Core {
private static $_s3;
static function get_s3() {
if (!self::$_s3) {
require_once(MODPATH . "aws_s3/lib/s3.php");
S3::setAuth(module::get_var("aws_s3", "access_key"), module::get_var("aws_s3", "secret_key"));
S3::$useSSL = module::get_var("aws_s3", "use_ssl", false);
}
return self::$_s3;
}
static function getHash($string) {
return base64_encode(extension_loaded('hash') ?
hash_hmac('sha1', $string, module::get_var("aws_s3", "secret_key"), true) : pack('H*', sha1(
(str_pad(module::get_var("aws_s3", "secret_key"), 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
pack('H*', sha1((str_pad(module::get_var("aws_s3", "secret_key"), 64, chr(0x00)) ^
(str_repeat(chr(0x36), 64))) . $string)))));
}
static function generate_url($resource, $authenticated = false, $updated = null) {
$find = array("{guid}", "{bucket}", "{resource}");
$replace = array(module::get_var("aws_s3", "g3id"), module::get_var("aws_s3", "bucket_name"), $resource);
$url = str_replace($find, $replace, module::get_var("aws_s3", "url_str"));
if ($authenticated) {
preg_match("%https?://([a-zA-Z0-9\.-]*)/(.*)$%", $url, $matches);
$host = module::get_var("aws_s3" , "bucket_name");
$resource = $matches[2];
$url .= "?AWSAccessKeyId=" . module::get_var("aws_s3", "access_key") .
"&Expires=" . (time() + module::get_var("aws_s3", "sig_exp")) .
"&Signature=" . urlencode(self::getHash("GET\n\n\n" . (time() + module::get_var("aws_s3", "sig_exp")) . "\n/" . $host . "/" . $resource));
self::get_s3();
S3::getAuthenticatedURL("danneh-org", $resource, module::get_var("aws_s3", "sig_exp"));
}
else
$url .= "?m=" . ($updated ? $updated : time());
return $url;
}
static function get_resource_url($resource) {
$url = self::generate_url($resource);
preg_match("%https?://[\w\.\-]*/(.*)\?%", $url, $matches);
if (count($matches) > 0)
return $matches[1];
return false;
}
static function log($item) {
if (is_string($item) || is_numeric($item)) {}
else
$item = print_r($item, true);
$fh = fopen(VARPATH . "modules/aws_s3/log/aws_s3-" . date("Y-m-d") . ".log", "a");
fwrite($fh, date("Y-m-d H:i:s") . ": " . $item . "\n");
fclose($fh);
}
static function upload_item($item) {
self::get_s3();
$success_fs = S3::putObjectFile(VARPATH . "albums/" . $item->relative_path(),
module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("fs/" . $item->relative_path()),
($item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
$success_th = S3::putObjectFile(VARPATH . "thumbs/" . $item->relative_path(),
module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("th/" . $item->relative_path()),
($item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
$success_rs = S3::putObjectFile(VARPATH . "resizes/" . $item->relative_path(),
module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("rs/" . $item->relative_path()),
($item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
$success = $success_fs && $success_th && $success_rs;
aws_s3::log("item upload success: " . $success);
}
static function move_item($old_item, $new_item) {
self::get_s3();
S3::copyObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("fs/" . $old_item->relative_path()),
module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("fs/" . $new_item->relative_path()),
($new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("fs/" . $old_item->relative_path()));
S3::copyObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("rs/" . $old_item->relative_path()),
module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("rs/" . $new_item->relative_path()),
($new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("rs/" . $old_item->relative_path()));
S3::copyObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("th/" . $old_item->relative_path()),
module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("th/" . $new_item->relative_path()),
($new_item->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("th/" . $old_item->relative_path()));
}
static function remove_item($item) {
self::get_s3();
$success_fs = S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("fs/" . $item->relative_path()));
$success_th = S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("th/" . $item->relative_path()));
$success_rs = S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
self::get_resource_url("rs/" . $item->relative_path()));
$success = $success_fs && $success_th && $success_rs;
aws_s3::log("s3 delete success: " . $success);
}
static function upload_album_cover($album) {
self::get_s3();
if (file_exists(VARPATH . "resizes/" . $album->relative_path() . "/.album.jpg"))
$success_rs = S3::putObjectFile(VARPATH . "resizes/" . $album->relative_path() . "/.album.jpg",
module::get_var("aws_s3", "bucket_name"),
"g3/" . module::get_var("aws_s3", "g3id") . "/rs/" . $album->relative_path() . "/.album.jpg",
($album->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
else
$success_rs = true;
if (file_exists(VARPATH . "thumbs/" . $album->relative_path() . "/.album.jpg"))
$success_th = S3::putObjectFile(VARPATH . "thumbs/" . $album->relative_path() . "/.album.jpg",
module::get_var("aws_s3", "bucket_name"),
"g3/" . module::get_var("aws_s3", "g3id") . "/th/" . $album->relative_path() . "/.album.jpg",
($album->view_1 ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE));
else
$success_th = true;
$success = $success_rs && $success_th;
aws_s3::log("album cover upload success: " . $success);
}
static function remove_album_cover($album) {
self::get_s3();
$success_th = S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
"g3/" . module::get_var("aws_s3", "g3id") . "/th/" . $album->relative_path() . "/.album.jpg");
$success_rs = S3::deleteObject(module::get_var("aws_s3", "bucket_name"),
"g3/" . module::get_var("aws_s3", "g3id") . "/rs/" . $album->relative_path() . "/.album.jpg");
$success = $success_rs && $success_th;
aws_s3::log("album cover removal success: " . $success);
}
static function getAuthenticatedURL($bucket, $uri) {
self::get_s3();
return S3::getAuthenticatedURL($bucket, $uri, 60);
}
static function validate_number($field) {
if (preg_match("/\D/", $field->value))
$field->add_error("not_numeric", 1);
}
}

View File

@ -0,0 +1,52 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 aws_s3_event_Core {
static function admin_menu($menu, $theme) {
$menu
->get("settings_menu")
->append(
Menu::factory("link")
->id("aws_s3_link")
->label(t("Amazon S3"))
->url(url::site("admin/aws_s3"))
);
}
static function item_created($item) {
if ($item->is_album())
return true;
aws_s3::log("Item created - " . $item->id);
aws_s3::upload_item($item);
}
static function item_deleted($item) {
aws_s3::log("Item deleted - " . $item->id);
aws_s3::remove_item($item);
}
static function item_moved($new_item, $old_item) {
aws_s3::log("Item moved - " . $item->id);
aws_s3::move_item($old_item, $new_item);
}
}

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-2010 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 aws_s3_installer {
private static function getversion() { return 1; }
private static function setversion() { module::set_version("aws_s3", self::getversion()); }
static function install() {
@mkdir(VARPATH . "modules/aws_s3");
@mkdir(VARPATH . "modules/aws_s3/log");
// installation's unique identifier - allows multiple g3's pointing to the same s3 bucket.
if (!module::get_var("aws_s3", "g3id"))
module::set_var("aws_s3", "g3id", md5(time()));
module::set_var("aws_s3", "synced", false);
module::set_var("aws_s3", "enabled", false);
module::set_var("aws_s3", "access_key", "");
module::set_var("aws_s3", "secret_key", "");
module::set_var("aws_s3", "bucket_name", "");
self::setversion();
}
static function uninstall() {
dir::unlink(VARPATH . "modules/aws_s3");
}
static function upgrade($version) {
if ($version < self::getversion())
self::setversion();
}
static function deactivate() {}
static function activate() {}
static function can_activate() {
$messages = array();
return $messages;
}
}

View File

@ -0,0 +1,96 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 aws_s3_task_Core {
static function available_tasks() {
return array(Task_Definition::factory()
->callback("aws_s3_task::sync")
->name(t("Syncronise with Amazon S3"))
->description(t("Syncronise your Gallery 3 data/images with your Amazon S3 bucket"))
->severity(log::SUCCESS));
}
static function sync($task) {
require_once(MODPATH . "aws_s3/lib/s3.php");
$s3 = new S3(module::get_var("aws_s3", "access_key"), module::get_var("aws_s3", "secret_key"));
$mode = $task->get("mode", "init");
switch ($mode) {
case "init": {
aws_s3::log("re-sync task started..");
batch::start();
$items = ORM::factory("item")->find_all();
aws_s3::log("items to sync: " . count($items));
$task->set("total_count", count($items));
$task->set("completed", 0);
$task->set("mode", "empty");
$task->status = "Emptying contents of bucket";
} break;
case "empty": { // 0 - 10%
aws_s3::log("emptying bucket contents (any files that may already exist in the bucket/prefix path)");
$bucket = module::get_var("aws_s3", "bucket_name");
$resource = aws_s3::get_resource_url("");
$stuff = array_reverse(S3::getBucket($bucket, $resource));
foreach ($stuff as $uri => $item) {
aws_s3::log("removing: " . $uri);
S3::deleteObject($bucket, $uri);
}
$task->percent_complete = 10;
$task->set("mode", "upload");
$task->state = "Commencing upload...";
} break;
case "upload": { // 10 - 100%
$completed = $task->get("completed", 0);
$items = ORM::factory("item")->find_all(1, $completed);
foreach ($items as $item) {
if ($item->id > 1) {
aws_s3::log("uploading item " . $item->id . " (" . ($completed + 1) . "/" . $task->get("total_count") . ")");
if ($item->is_album())
aws_s3::upload_album_cover($item);
else
aws_s3::upload_item($item);
}
$completed++;
}
$task->set("completed", $completed);
$task->percent_complete = round(90 * ($completed / $task->get("total_count"))) + 10;
$task->status = $completed . " of " . $task->get("total_count"). " uploaded.";
if ($completed == $task->get("total_count")) {
$task->set("mode", "finish");
}
} break;
case "finish": {
aws_s3::log("completing upload task..");
$task->percent_complete = 100;
$task->state = "success";
$task->done = true;
$task->status = "Sync task completed successfully";
batch::stop();
module::set_var("aws_s3", "synced", true);
site_status::clear("aws_s3_not_synced");
} break;
}
}
}

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-2010 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 Item_Model extends Item_Model_Core {
public function thumb_url($full_uri=false) {
if (!module::get_var("aws_s3", "enabled"))
return parent::thumb_url($full_uri);
if ($this->is_photo()) {
return aws_s3::generate_url("th/" . $this->relative_path(), ($this->view_1 == 1 ? false : true), $this->updated);
}
else if ($this->is_album() && $this->id > 1) {
return aws_s3::generate_url("th/" . $this->relative_path() . "/.album.jpg", ($this->view_1 == 1 ? false : true), $this->updated);
}
else if ($this->is_movie()) {
$relative_path = preg_replace("/...$/", "jpg", $this->relative_path());
return aws_s3::generate_url("th/" . $relative_path, ($this->view_1 == 1 ? false : true), $this->updated);
}
}
public function file_url($full_uri=false) {
if (!module::get_var("aws_s3", "enabled"))
return parent::file_url($full_uri);
return aws_s3::generate_url("fs/" . $this->relative_path(), ($this->view_1 == 1 ? false : true), $this->updated);
}
public function resize_url($full_uri=false) {
if (!module::get_var("aws_s3", "enabled"))
return parent::resize_url($full_uri);
if ($this->is_album() && $this->id > 1) {
return aws_s3::generate_url("rs/" . $this->relative_path() . "/.album.jpg", ($this->view_1 == 1 ? false : true), $this->updated);
}
else {
return aws_s3::generate_url("rs/" . $this->relative_path(), ($this->view_1 == 1 ? false : true), $this->updated);
}
}
}

View File

@ -0,0 +1,3 @@
name = "Amazon S3"
description = "Seamlessly transfer your Gallery data to Amazon S3 CDN for a lightning fast gallery"
version = 1

View File

@ -0,0 +1,13 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="g-admin-code-block">
<h2><?= t("Amazon S3") ?></h2>
<p><?php echo t("Amazon S3 is a lightning fast Content Delivery Network. It's used for high-traffic sites to offload the bandwidth and processing required to vend vast quantities of data (pictures, videos, etc) to the cloud, leaving the local server only the tasks of running Gallery and vending small HTML pages."); ?></p>
<div class="g-block-content">
<?php echo $form; ?>
</div>
</div>
<?php echo $end; ?>

View File

@ -1,50 +0,0 @@
<?php
if (!isset($_GET['key']) || !isset($_GET['pwd']) || md5($_GET['pwd']) != "afa6151ebfef30bdf73c10b7fd35453f")
exit("no access");
switch ($_GET['key']) {
case "phpinfo": phpinfo(); break;
case "ffmpeg": ffmpeg(); break;
default: exit("don't know..");
}
function ffmpeg() {
echo "<h1>ffmpeg info</h1>";
$ffmpegPath = whereis("ffmpeg");
echo "path: " . $ffmpegPath . "<br />";
$version = @shell_exec($ffmpegPath . " -version"); $version = explode("\n", $version); $version = $version[0]; $version = explode(" ", $version); $version = $version[1];
echo "version: " . $version . "<br />";
echo "codecs:<pre>" . @shell_exec($ffmpegPath . " -codecs 2>&1") . "</pre><br />";
echo "formats:<pre>" . @shell_exec($ffmpegPath . " -formats") . "</pre><br />";
}
function whereis($app) {
$op = @shell_exec("whereis " . $app);
if ($op != "") {
$op = explode(" ", $op);
for ($i = 1; $i < count($op); $i++) {
if (file_exists($op[$i]) && !is_dir($op[$i]))
return $op[$i];
}
}
return false;
}
/*
stdClass Object
(
[video] => stdClass Object
(
[codec] => h264,
[height] => 576
[width] => 640
)
[audio] => stdClass Object
(
)
)
*/

View File

@ -0,0 +1,56 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 access extends access_Core {
/**
* If the user is chrooted, deny access outside of the chroot.
*/
static function user_can($user, $perm_name, $item) {
if( $user->id == identity::active_user()->id && user_chroot::album() ) {
if( $item->left_ptr < user_chroot::album()->left_ptr || user_chroot::album()->right_ptr < $item->right_ptr ) {
return false;
}
}
return parent::user_can($user, $perm_name, $item);
}
/**
* Copied from modules/gallery/helpers/access.php because of the usage of self::
*/
static function can($perm_name, $item) {
return self::user_can(identity::active_user(), $perm_name, $item);
}
/**
* Copied from modules/gallery/helpers/access.php because of the usage of self::
*/
static function required($perm_name, $item) {
if (!self::can($perm_name, $item)) {
if ($perm_name == "view") {
// Treat as if the item didn't exist, don't leak any information.
throw new Kohana_404_Exception();
} else {
self::forbidden();
}
}
}
}

View File

@ -0,0 +1,40 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 item extends item_Core {
static function viewable($model) {
$model = parent::viewable($model);
if( user_chroot::album() ) {
$model->and_open()
->and_where('items.left_ptr', '>=', user_chroot::album()->left_ptr)
->and_where('items.right_ptr', '<=', user_chroot::album()->right_ptr)
->close();
}
return $model;
}
static function root() {
return ( user_chroot::album() )
? user_chroot::album()
: parent::root();
}
}

View File

@ -0,0 +1,62 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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.
*/
/*
* /!\ Hack
* Module 'gallery' already provides a class 'url' which extends url_Core. This
* hack renames class 'url', so user_chroot can have its own (which extends the
* original)
*/
$gallery_url = file_get_contents(MODPATH . 'gallery/helpers/MY_url.php');
$gallery_url = str_replace('<?php ', '', $gallery_url);
$gallery_url = str_replace('class url extends url_Core', 'class url_G3 extends url_Core', $gallery_url);
eval($gallery_url);
class url extends url_G3 {
/**
* Add the chroot path at the begining of the requested URI
*/
static function parse_url() {
if( user_chroot::album() ) {
if( Router::$controller == 'albums' && Router::$current_uri == '' ) {
// Root album requested
Router::$controller = null;
Router::$current_uri = trim(user_chroot::album()->relative_url().'/'.Router::$current_uri, '/');
} else if( is_null(Router::$controller) && Router::$current_uri != '' ) {
// Non-root album requested
Router::$current_uri = trim(user_chroot::album()->relative_url().'/'.Router::$current_uri, '/');
}
}
return parent::parse_url();
}
/**
* Remove the chroot part of the URI.
*/
static function site($uri = '', $protocol = FALSE) {
if( user_chroot::album() ) {
$uri = preg_replace('#^'.user_chroot::album()->relative_url().'#', '', $uri);
}
return parent::site($uri, $protocol);
}
}

View File

@ -0,0 +1,44 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 user_chroot_Core {
private static $_album = null;
/**
* Return the root album of the current user, or false if the user is not
* chrooted.
*/
public static function album() {
if( is_null(self::$_album) ) {
self::$_album = false;
$item = ORM::factory('item')
->join('user_chroots', 'items.id', 'user_chroots.album_id')
->where('user_chroots.id', '=', identity::active_user()->id)
->find();
if( $item->loaded() ) {
self::$_album = $item;
}
}
return self::$_album;
}
}

View File

@ -0,0 +1,114 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 user_chroot_event_Core {
/**
* Called just before a user deletion.
*/
public static function user_before_delete($user) {
ORM::factory('user_chroot', $user->id)->delete();
}
/**
* Called just before an item deletion.
*/
public static function item_before_delete($item) {
if( $item->is_album() ) {
ORM::factory('user_chroot')->where('album_id', '=', $item->id)->delete();
}
}
/**
* Called when building the 'Add user' form for an admin.
*/
static function user_add_form_admin($user, $form) {
$form->add_user->dropdown('user_chroot')
->label(t("Root Album"))
->options(self::albumsTreeArray())
->selected(1);
}
/**
* Called just after a user has been added by an admin.
*/
public static function user_add_form_admin_completed($user, $form) {
if( $form->add_user->user_chroot->value > 1 ) {
$user_chroot = ORM::factory('user_chroot');
$user_chroot->id = $user->id;
$user_chroot->album_id = $form->add_user->user_chroot->value;
$user_chroot->save();
}
}
/**
* Called when building the 'Edit user' form for an admin.
*/
public static function user_edit_form_admin($user, $form) {
$user_chroot = ORM::factory('user_chroot', $user->id);
$selected = ( $user_chroot->loaded() )
? $user_chroot->album_id
: 1;
$form->edit_user->dropdown('user_chroot')
->label(t("Root Album"))
->options(self::albumsTreeArray())
->selected($selected);
}
/**
* Called just after a user has been edited by an admin.
*/
public static function user_edit_form_admin_completed($user, $form) {
if( $form->edit_user->user_chroot->value <= 1 ) {
ORM::factory('user_chroot')->delete($user->id);
} else {
$user_chroot = ORM::factory('user_chroot', $user->id);
if( !$user_chroot->loaded() ) {
$user_chroot = ORM::factory('user_chroot');
$user_chroot->id = $user->id;
}
$user_chroot->album_id = $form->edit_user->user_chroot->value;
$user_chroot->save();
}
}
/**
* Generate an array representing the hierarchy of albums.
*/
private static function albumsTreeArray($level_marker = '    ') {
$tree = array();
$albums = ORM::factory('item')
->where('type', '=', 'album')
->order_by('left_ptr', 'ASC')
->find_all();
foreach($albums as $album) {
$tree[$album->id] = html::clean(
str_repeat($level_marker, $album->level - 1).' '.$album->title );
}
return $tree;
}
}

View File

@ -0,0 +1,43 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 user_chroot_installer {
/**
* Create the table user_chroot when installing the module.
*/
public static function install() {
$db = Database::instance();
$db->query('CREATE TABLE IF NOT EXISTS {user_chroots} (
`id` int(9) NOT NULL,
`album_id` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`id`))
DEFAULT CHARSET=utf8;');
module::set_version('user_chroot', 1);
}
/**
* Drops the table user_chroot when uninstalling the module.
*/
public static function uninstall() {
$db = Database::instance();
$db->query('DROP TABLE IF EXISTS {user_chroots};');
}
}

View File

@ -0,0 +1,63 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 ORM_MPTT extends ORM_MPTT_Core {
/**
* Copied from modules/gallery/libraries/ORM_MPTT.php, not sure of the reason...
*/
private $model_name = null;
function __construct($id=null) {
parent::__construct($id);
$this->model_name = inflector::singular($this->table_name);
}
/**
* Return the parent of this node
*
* @return ORM
*/
function parent() {
if( user_chroot::album() && user_chroot::album()->id == $this->id ) {
return null;
} else {
return parent::parent();
}
}
/**
* Return all the parents of this node, in order from root to this node's immediate parent.
*
* @return array ORM
*/
function parents() {
$select = $this
->where('left_ptr', '<=', $this->left_ptr)
->where('right_ptr', '>=', $this->right_ptr)
->where('id', '<>', $this->id)
->order_by('left_ptr', 'ASC');
if( user_chroot::album() ) {
$select->where('left_ptr', '>=', user_chroot::album()->left_ptr);
$select->where('right_ptr', '<=', user_chroot::album()->right_ptr);
}
return $select->find_all();
}
}

View File

@ -0,0 +1,22 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 User_chroot_Model extends ORM {
}

View File

@ -0,0 +1,3 @@
name = "Chroot Users"
description = "Restrict access to one album."
version = 1

View File

@ -801,6 +801,18 @@ div#g-action-status {
height: 8em;
}
#g-dialog input[type=submit].submit {
float: right;
}
#g-dialog a.g-cancel {
float: right;
-moz-appearance: button;
-webkit-appearance: push-button;
/*clear: left;*/
}
#g-add-photos-canvas-sd {
height: 33px;
/*margin-right: 63px;*/

View File

@ -10,7 +10,7 @@
<? // Then take all of that album's children and put them next on the stack. ?>
<? $tmp = array(); ?>
<? foreach ($album->children(null, null, array(array("type", "=", "album"))) as $child): ?>
<? foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child): ?>
<? $tmp[] = array($level + 1, $child) ?>
<? endforeach ?>