Merge remote branch 'upstream/master'
This commit is contained in:
commit
6f388efc03
121
3.0/modules/author/helpers/author.php
Normal file
121
3.0/modules/author/helpers/author.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the API for handling exif data.
|
||||
*/
|
||||
class author_Core {
|
||||
static function fix($item) {
|
||||
if ($item->is_album()) { return false; }
|
||||
|
||||
$mime = $item->mime_type;
|
||||
if ($mime == 'image/jpeg' || $mime == 'image/png' || $mime == 'image/gif') {}
|
||||
else { return false; }
|
||||
|
||||
$owner = ORM::factory("user")->where("id", "=", $item->owner_id)->find();
|
||||
$user_name = $owner->full_name;
|
||||
|
||||
$exiv = module::get_var('author', 'exiv_path');
|
||||
$version = module::get_var('author', 'exiv_version');
|
||||
|
||||
/*
|
||||
Debian stable ships with exiv2 0.16 at the time of writing. You get
|
||||
roughly the same output out of the utility as with 0.20, but you have
|
||||
to invoke it several times.
|
||||
|
||||
The real threshhold for this might be somewhere between 0.16 and 0.20,
|
||||
but the 0.16 way of doing things is forward compatible.
|
||||
*/
|
||||
$exivData = array();
|
||||
if ($version < 0.20) {
|
||||
exec("$exiv -p x " . escapeshellarg($item->file_path()), $exivData);
|
||||
exec("$exiv -p i " . escapeshellarg($item->file_path()), $exivData);
|
||||
exec("$exiv -p t " . escapeshellarg($item->file_path()), $exivData);
|
||||
} else {
|
||||
exec("$exiv -p a " . escapeshellarg($item->file_path()), $exivData);
|
||||
}
|
||||
|
||||
$has = array();
|
||||
$mod = array();
|
||||
foreach ($exivData as $line)
|
||||
{
|
||||
$tokens = preg_split('/\s+/', $line, 4);
|
||||
$has[ $tokens[0] ] = $tokens[3];
|
||||
}
|
||||
|
||||
$candidates = array(
|
||||
$has['Xmp.dc.creator'],
|
||||
$has['Iptc.Application2.Byline'],
|
||||
$has['Exif.Image.Artist'],
|
||||
$user_name,
|
||||
'Unknown');
|
||||
|
||||
foreach ($candidates as $cand) {
|
||||
if ($cand != '') { $byline = $cand; break; }
|
||||
}
|
||||
|
||||
if (!array_key_exists('Exif.Image.Artist', $has)) { $mod['Exif.Image.Artist'] = $byline; }
|
||||
if (!array_key_exists('Iptc.Application2.Byline', $has)) { $mod['Iptc.Application2.Byline'] = $byline; }
|
||||
|
||||
/* Apply the credit block */
|
||||
$credit = module::get_var("author", "credit");
|
||||
if ($credit != '') {
|
||||
$mod['Iptc.Application2.Credit'] = $credit;
|
||||
}
|
||||
|
||||
/*
|
||||
Older versions doesn't support XMP writing.
|
||||
*/
|
||||
if ($version >= 0.20) {
|
||||
if (!array_key_exists('Xmp.dc.creator', $has)) { $mod['Xmp.dc.creator'] = $byline; }
|
||||
|
||||
/* Apply our own image terms URL */
|
||||
$terms = module::get_var("author", "usage_terms");
|
||||
if ($terms != '') {
|
||||
$mod['Xmp.xmpRights.UsageTerms'] = 'http://wiki.sverok.se/wiki/Bildbank-Bilder';
|
||||
}
|
||||
}
|
||||
|
||||
$line = $exiv . ' ';
|
||||
foreach ($mod as $key => $value) {
|
||||
$line .= "-M \"set $key " . escapeshellarg($value) . "\" ";
|
||||
}
|
||||
|
||||
$files = array(
|
||||
$item->file_path(),
|
||||
$item->thumb_path(),
|
||||
$item->resize_path()
|
||||
);
|
||||
|
||||
foreach ($files as $file) {
|
||||
system("$line " . escapeshellarg($file));
|
||||
}
|
||||
|
||||
$record = ORM::factory("author_record")->where("item_id", "=", $item->id)->find();
|
||||
if (!$record->loaded()) {
|
||||
$record->item_id = $item->id;
|
||||
}
|
||||
$record->author = $byline;
|
||||
$record->dirty = 0;
|
||||
$record->save();
|
||||
return $byline;
|
||||
}
|
||||
|
||||
}
|
48
3.0/modules/author/helpers/author_block.php
Normal file
48
3.0/modules/author/helpers/author_block.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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 author_block_Core {
|
||||
static function get_site_list() {
|
||||
return array("author" => t("Author"));
|
||||
}
|
||||
|
||||
static function get($block_id, $theme) {
|
||||
$item = $theme->item;
|
||||
if ($block_id != 'author' || $item->is_album() ) {
|
||||
return '';
|
||||
}
|
||||
$record = db::build()
|
||||
->select("author")
|
||||
->from("author_records")
|
||||
->where("item_id", "=", $item->id)
|
||||
->execute()
|
||||
->current();
|
||||
|
||||
$byline = $record->author;
|
||||
if ($byline == '') {
|
||||
$byline = author::fix($item);
|
||||
}
|
||||
|
||||
$block = new Block();
|
||||
$block->content = new View("author_block.html");
|
||||
$block->content->author = $byline;
|
||||
|
||||
return $block;
|
||||
}
|
||||
}
|
32
3.0/modules/author/helpers/author_event.php
Normal file
32
3.0/modules/author/helpers/author_event.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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 author_event_Core
|
||||
{
|
||||
static function item_created($item) {
|
||||
$byline = author::fix($item);
|
||||
}
|
||||
|
||||
static function item_deleted($item) {
|
||||
db::build()
|
||||
->delete("author_records")
|
||||
->where("item_id", "=", $item->id)
|
||||
->execute();
|
||||
}
|
||||
}
|
64
3.0/modules/author/helpers/author_installer.php
Normal file
64
3.0/modules/author/helpers/author_installer.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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 author_installer {
|
||||
static function install() {
|
||||
$db = Database::instance();
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {author_records} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`item_id` INTEGER(9) NOT NULL,
|
||||
`author` TEXT,
|
||||
`dirty` BOOLEAN default 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY(`item_id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
module::set_version("author", 1);
|
||||
module::set_var("author", "usage_terms", '');
|
||||
module::set_var("author", "credit", '');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static function activate() {
|
||||
gallery::set_path_env(
|
||||
array(
|
||||
getenv("PATH"),
|
||||
module::get_var("gallery", "extra_binary_paths")
|
||||
));
|
||||
|
||||
$exiv = exec('which exiv2');
|
||||
if ($exiv == '') {
|
||||
# Proper warning
|
||||
}
|
||||
else {
|
||||
module::set_var("author", "exiv_path", $exiv);
|
||||
$out = array();
|
||||
exec("$exiv -V", $out);
|
||||
$parts = split(' ', $out[0]);
|
||||
module::set_var("author", "exiv_version", $parts[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static function deactivate() {
|
||||
}
|
||||
|
||||
static function uninstall() {
|
||||
Database::instance()->query("DROP TABLE IF EXISTS {author_records};");
|
||||
}
|
||||
}
|
21
3.0/modules/author/models/author_record.php
Normal file
21
3.0/modules/author/models/author_record.php
Normal file
@ -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-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 Author_Record_Model extends ORM {
|
||||
}
|
3
3.0/modules/author/module.info
Normal file
3
3.0/modules/author/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = "Author"
|
||||
description = "Allows for the display and modification of the Author/Photographer/Byline data in photos."
|
||||
version = 2
|
6
3.0/modules/author/views/author_block.html.php
Normal file
6
3.0/modules/author/views/author_block.html.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
|
||||
<div class="g-author-block">
|
||||
<?= t('Credit') ?>: <?= html::clean($author) ?>
|
||||
</div>
|
||||
|
56
3.0/modules/user_chroot/helpers/MY_access.php
Normal file
56
3.0/modules/user_chroot/helpers/MY_access.php
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
3.0/modules/user_chroot/helpers/MY_item.php
Normal file
40
3.0/modules/user_chroot/helpers/MY_item.php
Normal 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();
|
||||
}
|
||||
}
|
62
3.0/modules/user_chroot/helpers/MY_url.php
Normal file
62
3.0/modules/user_chroot/helpers/MY_url.php
Normal 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);
|
||||
}
|
||||
}
|
44
3.0/modules/user_chroot/helpers/user_chroot.php
Normal file
44
3.0/modules/user_chroot/helpers/user_chroot.php
Normal 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;
|
||||
}
|
||||
}
|
114
3.0/modules/user_chroot/helpers/user_chroot_event.php
Normal file
114
3.0/modules/user_chroot/helpers/user_chroot_event.php
Normal 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;
|
||||
}
|
||||
}
|
43
3.0/modules/user_chroot/helpers/user_chroot_installer.php
Normal file
43
3.0/modules/user_chroot/helpers/user_chroot_installer.php
Normal 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};');
|
||||
}
|
||||
}
|
63
3.0/modules/user_chroot/libraries/MY_ORM_MPTT.php
Normal file
63
3.0/modules/user_chroot/libraries/MY_ORM_MPTT.php
Normal 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();
|
||||
}
|
||||
}
|
22
3.0/modules/user_chroot/models/user_chroot.php
Normal file
22
3.0/modules/user_chroot/models/user_chroot.php
Normal 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 {
|
||||
}
|
3
3.0/modules/user_chroot/module.info
Normal file
3
3.0/modules/user_chroot/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = "Chroot Users"
|
||||
description = "Restrict access to one album."
|
||||
version = 1
|
@ -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;*/
|
||||
|
@ -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 ?>
|
||||
|
||||
|
Reference in New Issue
Block a user