Merge branch 'master' of git://github.com/gallery/gallery3-contrib.git
This commit is contained in:
commit
cb0255150b
|
@ -49,9 +49,12 @@ class albumpassword_Controller extends Controller {
|
|||
access::required("view", $item);
|
||||
access::required("edit", $item);
|
||||
|
||||
// Check for and delete the password.
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $id)->find();
|
||||
if ($existing_password->loaded()) {
|
||||
// Check for and delete the password and any cached ids assigned to it.
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $id)->find_all();
|
||||
if (count($existing_password) > 0) {
|
||||
foreach ($existing_password as $one_password) {
|
||||
db::build()->delete("albumpassword_idcaches")->where("password_id", "=", $one_password->id)->execute();
|
||||
}
|
||||
db::build()->delete("items_albumpasswords")->where("album_id", "=", $id)->execute();
|
||||
message::success(t("Password Removed."));
|
||||
}
|
||||
|
@ -70,9 +73,12 @@ class albumpassword_Controller extends Controller {
|
|||
$album_id = Input::instance()->post("item_id");
|
||||
$album_password = Input::instance()->post("assignpassword_password");
|
||||
|
||||
// Check for, and remove, any existing passwords.
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $album_id)->find();
|
||||
if ($existing_password->loaded()) {
|
||||
// Check for, and remove, any existing passwords and cached ids.
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $album_id)->find_all();
|
||||
if (count($existing_password) > 0) {
|
||||
foreach ($existing_password as $one_password) {
|
||||
db::build()->delete("albumpassword_idcaches")->where("password_id", "=", $one_password->id)->execute();
|
||||
}
|
||||
db::build()->delete("items_albumpasswords")->where("album_id", "=", $album_id)->execute();
|
||||
}
|
||||
|
||||
|
@ -82,6 +88,25 @@ class albumpassword_Controller extends Controller {
|
|||
$new_password->password = $album_password;
|
||||
$new_password->save();
|
||||
|
||||
// Add the album to the id cache.
|
||||
$cached_album = ORM::factory("albumpassword_idcache");
|
||||
$cached_album->password_id = $new_password->id;
|
||||
$cached_album->item_id = $album_id;
|
||||
$cached_album->save();
|
||||
|
||||
// Check for any sub-items within the album, add all of them to the id cache.
|
||||
$items = ORM::factory("item", $album_id)
|
||||
->viewable()
|
||||
->descendants();
|
||||
if (count($items) > 0) {
|
||||
foreach ($items as $one_item) {
|
||||
$cached_item = ORM::factory("albumpassword_idcache");
|
||||
$cached_item->password_id = $new_password->id;
|
||||
$cached_item->item_id = $one_item->id;
|
||||
$cached_item->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Display a success message and close the dialog.
|
||||
message::success(t("Password saved."));
|
||||
print "<html>\n<body>\n<script type=\"text/javascript\">\n$(\"#g-dialog\").dialog(\"close\");\nwindow.location.reload();\n</script>\n</body>\n</html>\n";
|
||||
|
|
|
@ -21,38 +21,29 @@
|
|||
class access extends access_Core {
|
||||
static function required($perm_name, $item) {
|
||||
// Original code from the required function in modules/gallery/helpers/access.php.
|
||||
if (!self::can($perm_name, $item)) {
|
||||
if (!access::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();
|
||||
access::forbidden();
|
||||
}
|
||||
|
||||
// Begin rWatcher modifications.
|
||||
// Throw a 404 error when a user attempts to access a protected item,
|
||||
// unless the password has been provided, or the user is the item's owner.
|
||||
// unless the password has been provided, or the user is the item's owner.
|
||||
} elseif (module::get_var("albumpassword", "hideonly") == false) {
|
||||
$album_item = "";
|
||||
do {
|
||||
if ($album_item == "") {
|
||||
if ($item->is_album()) {
|
||||
$album_item = $item;
|
||||
} else {
|
||||
$album_item = $item->parent();
|
||||
}
|
||||
} else {
|
||||
$album_item = $album_item->parent();
|
||||
}
|
||||
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $album_item->id)->find();
|
||||
$item_protected = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
|
||||
if (count($item_protected) > 0) {
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("id", "=", $item_protected[0]->password_id)->find();
|
||||
if ($existing_password->loaded()) {
|
||||
if ((cookie::get("g3_albumpassword") != $existing_password->password) &&
|
||||
(identity::active_user()->id != $album_item->owner_id)) {
|
||||
(identity::active_user()->id != $item->owner_id) &&
|
||||
(!identity::active_user()->admin)) {
|
||||
throw new Kohana_404_Exception();
|
||||
}
|
||||
}
|
||||
} while ($album_item->parent_id > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,21 @@ class item extends item_Core {
|
|||
// If not, hide whatever is restricted by an album password
|
||||
// that the current user is not the owner of.
|
||||
if (!identity::active_user()->admin) {
|
||||
$model->and_open()->join("items_albumpasswords", "items.id", "items_albumpasswords.album_id", "LEFT OUTER")
|
||||
->and_where("items_albumpasswords.album_id", "IS", NULL)
|
||||
->or_where("items_albumpasswords.password", "=", cookie::get("g3_albumpassword"))
|
||||
->or_where("items.owner_id", "=", identity::active_user()->id)->close();
|
||||
|
||||
// Display items that are not in idcaches.
|
||||
$model->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER")
|
||||
->and_where("albumpassword_idcaches.item_id", "IS", NULL);
|
||||
|
||||
// ... Unless their password id corresponds with a valid password.
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("password", "=", cookie::get("g3_albumpassword"))->find_all();
|
||||
if (count($existing_password) > 0) {
|
||||
foreach ($existing_password as $one_password) {
|
||||
$model->or_where("albumpassword_idcaches.password_id", "=", $one_password->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Or the current user is the owner of the item.
|
||||
$model->or_where("items.owner_id", "=", identity::active_user()->id)->close();
|
||||
}
|
||||
|
||||
return $model;
|
||||
|
|
|
@ -81,24 +81,61 @@ class albumpassword_event_Core {
|
|||
->css_id("g-album-password-remove")
|
||||
->url(url::site("albumpassword/remove/" . $item->id)));
|
||||
} elseif ($item->id != 1) {
|
||||
$menu->get("options_menu")
|
||||
->append(Menu::factory("dialog")
|
||||
->id("albumpassword_assign")
|
||||
->label(t("Assign password"))
|
||||
->css_id("g-album-password-assign")
|
||||
->url(url::site("albumpassword/assign/" . $item->id)));
|
||||
$passworded_subitems = ORM::factory("item", $item->id)
|
||||
->and_open()->join("albumpassword_idcaches", "items.id", "albumpassword_idcaches.item_id", "LEFT OUTER")
|
||||
->where("albumpassword_idcaches.item_id", "IS NOT", NULL)->close()
|
||||
->descendants();
|
||||
|
||||
$existing_cacheditem = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->id)->order_by("cache_id")->find_all();
|
||||
if ((count($existing_cacheditem) == 0) && count($passworded_subitems) == 0) {
|
||||
$menu->get("options_menu")
|
||||
->append(Menu::factory("dialog")
|
||||
->id("albumpassword_assign")
|
||||
->label(t("Assign password"))
|
||||
->css_id("g-album-password-assign")
|
||||
->url(url::site("albumpassword/assign/" . $item->id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function item_deleted($item) {
|
||||
// If an album is deleted, remove any associated passwords.
|
||||
$existingPasswords = ORM::factory("items_albumpassword")
|
||||
->where("album_id", "=", $item->id)
|
||||
->find_all();
|
||||
if (count($existingPasswords) > 0) {
|
||||
db::build()->delete("items_albumpassword")->where("album_id", "=", $item->id)->execute();
|
||||
// Check for and delete the password and any cached ids assigned to it.
|
||||
$existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $item->id)->find_all();
|
||||
if (count($existing_password) > 0) {
|
||||
foreach ($existing_password as $one_password) {
|
||||
db::build()->delete("albumpassword_idcaches")->where("password_id", "=", $one_password->id)->execute();
|
||||
}
|
||||
db::build()->delete("items_albumpasswords")->where("album_id", "=", $item->id)->execute();
|
||||
message::success(t("Password Removed."));
|
||||
} else {
|
||||
db::build()->delete("albumpassword_idcaches")->where("item_id", "=", $item->id)->execute();
|
||||
}
|
||||
}
|
||||
|
||||
static function item_created($item) {
|
||||
// Check for any already existing password on parent album(s), if found, generate cache data for the new item.
|
||||
$existing_password = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->parent_id)->order_by("cache_id")->find_all();
|
||||
if (count($existing_password) > 0) {
|
||||
$new_cachedid = ORM::factory("albumpassword_idcache");
|
||||
$new_cachedid->password_id = $existing_password[0]->password_id;
|
||||
$new_cachedid->item_id = $item->id;
|
||||
$new_cachedid->save();
|
||||
}
|
||||
}
|
||||
|
||||
static function item_moved($item, $old_parent) {
|
||||
// Delete any existing cache data.
|
||||
db::build()->delete("albumpassword_idcaches")->where("item_id", "=", $item->id)->execute();
|
||||
|
||||
// Check for a password on the new parent, generate cache data if necessary.
|
||||
$existing_password = ORM::factory("albumpassword_idcache")->where("item_id", "=", $item->parent_id)->order_by("cache_id")->find_all();
|
||||
if (count($existing_password) > 0) {
|
||||
$new_cachedid = ORM::factory("albumpassword_idcache");
|
||||
$new_cachedid->password_id = $existing_password[0]->password_id;
|
||||
$new_cachedid->item_id = $item->id;
|
||||
$new_cachedid->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,25 +28,45 @@ class albumpassword_installer {
|
|||
PRIMARY KEY (`id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
|
||||
// Create a table to store a list of all protected items in.
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {albumpassword_idcaches} (
|
||||
`cache_id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`cache_id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
|
||||
// Set the default value for this module's behavior.
|
||||
module::set_var("albumpassword", "hideonly", true);
|
||||
|
||||
// Set the module's version number.
|
||||
module::set_version("albumpassword", 2);
|
||||
module::set_version("albumpassword", 3);
|
||||
}
|
||||
|
||||
static function upgrade($version) {
|
||||
// Set the default value for this module's behavior.
|
||||
module::set_var("albumpassword", "hideonly", true);
|
||||
|
||||
// Set the module's version number.
|
||||
module::set_version("albumpassword", 2);
|
||||
$db = Database::instance();
|
||||
if ($version == 1) {
|
||||
// Set the default value for this module's behavior.
|
||||
module::set_var("albumpassword", "hideonly", true);
|
||||
module::set_version("albumpassword", $version = 2);
|
||||
}
|
||||
if ($version == 2) {
|
||||
// Create a table to store a list of all protected items in.
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {albumpassword_idcaches} (
|
||||
`cache_id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`cache_id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
module::set_version("albumpassword", $version = 3);
|
||||
}
|
||||
}
|
||||
|
||||
static function uninstall() {
|
||||
// Delete the password table before uninstalling.
|
||||
$db = Database::instance();
|
||||
$db->query("DROP TABLE IF EXISTS {items_albumpassword};");
|
||||
$db->query("DROP TABLE IF EXISTS {items_albumpasswords};");
|
||||
$db->query("DROP TABLE IF EXISTS {albumpassword_idcaches};");
|
||||
module::delete("albumpassword");
|
||||
}
|
||||
}
|
||||
|
|
138
3.0/modules/albumpassword/helpers/albumpassword_task.php
Normal file
138
3.0/modules/albumpassword/helpers/albumpassword_task.php
Normal file
|
@ -0,0 +1,138 @@
|
|||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2011 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 albumpassword_task_Core {
|
||||
static function available_tasks() {
|
||||
// Check for any albums listed in albumpasswords but not idcaches.
|
||||
// If found, set the severity for this task to warning, as there's
|
||||
// obviously something missing from idcaches.
|
||||
$bad_albums = ORM::factory("items_albumpassword")
|
||||
->join("albumpassword_idcaches", "items_albumpasswords.id", "albumpassword_idcaches.password_id", "LEFT OUTER")
|
||||
->and_where("albumpassword_idcaches.password_id", "IS", NULL)->count_all();
|
||||
|
||||
return array(Task_Definition::factory()
|
||||
->callback("albumpassword_task::update_idcaches")
|
||||
->name(t("Rebuild Album Password ID Caches DB"))
|
||||
->description(t("Logs the contents of all protected albums into the db."))
|
||||
->severity($bad_albums ? log::WARNING : log::SUCCESS));
|
||||
}
|
||||
|
||||
static function update_idcaches($task) {
|
||||
// Populate the idcaches table with the contents of all protected albums.
|
||||
|
||||
$start = microtime(true);
|
||||
$total = $task->get("total");
|
||||
$existing_passwords = ORM::factory("items_albumpassword")->find_all();
|
||||
// If this is the first time this function has been run,
|
||||
// delete and re-create the idcaches table, and set up
|
||||
// some initial variables.
|
||||
if (empty($total)) {
|
||||
// Delete the idcache table and make a new one.
|
||||
$db = Database::instance();
|
||||
$db->query("DROP TABLE IF EXISTS {albumpassword_idcaches};");
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {albumpassword_idcaches} (
|
||||
`cache_id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`cache_id`))
|
||||
DEFAULT CHARSET=utf8;");
|
||||
|
||||
// Set the initial values for all variables.
|
||||
$task->set("total", count($existing_passwords));
|
||||
$total = $task->get("total");
|
||||
$task->set("last_album_counter", 0);
|
||||
$task->set("last_id", 0);
|
||||
$task->set("completed_albums", 0);
|
||||
$task->set("completed_items", 0);
|
||||
$task->set("total_items", 0);
|
||||
}
|
||||
|
||||
// Retrieve the values for variables from the last time this
|
||||
// function was run.
|
||||
$last_album_counter = $task->get("last_album_counter");
|
||||
$completed_albums = $task->get("completed_albums");
|
||||
$completed_items = $task->get("completed_items");
|
||||
$total_items = $task->get("total_items");
|
||||
$last_id = $task->get("last_id");
|
||||
|
||||
// If completed_items is 0, then we're just starting to process this
|
||||
// album. Add the album to idcaches before adding it's contents.
|
||||
if ($completed_items == 0) {
|
||||
// Add the album to the id cache.
|
||||
$cached_album = ORM::factory("albumpassword_idcache");
|
||||
$cached_album->password_id = $existing_passwords[$last_album_counter]->id;
|
||||
$cached_album->item_id = $existing_passwords[$last_album_counter]->album_id;
|
||||
$cached_album->save();
|
||||
|
||||
// Set total_items to the number of items in this album.
|
||||
$total_items = ORM::factory("item", $existing_passwords[$last_album_counter]->album_id)
|
||||
->descendants_count();
|
||||
$task->set("total_items", $total_items);
|
||||
}
|
||||
|
||||
// Add each item in the album to idcaches.
|
||||
foreach (ORM::factory("item", $existing_passwords[$last_album_counter]->album_id)
|
||||
->where("id", ">", $last_id)
|
||||
->order_by("id")
|
||||
->descendants(100) as $item) {
|
||||
|
||||
$cached_item = ORM::factory("albumpassword_idcache");
|
||||
$cached_item->password_id =$existing_passwords[$last_album_counter]->id;
|
||||
$cached_item->item_id = $item->id;
|
||||
$cached_item->save();
|
||||
|
||||
$last_id = $item->id;
|
||||
$completed_items++;
|
||||
|
||||
// Set a time limit so the script doesn't time out.
|
||||
if (microtime(true) - $start > 1.5) {
|
||||
break;
|
||||
}
|
||||
} // end foreach
|
||||
|
||||
// If completed_items equals total_items, then we've
|
||||
// processed everything in the current album.
|
||||
// Increase variables and set everything up for the
|
||||
// next album.
|
||||
if ($completed_items == $total_items) {
|
||||
$completed_items = 0;
|
||||
$last_album_counter++;
|
||||
$completed_albums++;
|
||||
$last_id = 0;
|
||||
}
|
||||
|
||||
// Store the current values of the variables for the next
|
||||
// time this function is called.
|
||||
$task->set("last_album_counter", $last_album_counter);
|
||||
$task->set("last_id", $last_id);
|
||||
$task->set("completed_albums", $completed_albums);
|
||||
$task->set("completed_items", $completed_items);
|
||||
|
||||
// Display the number of albums that have been completed before exiting.
|
||||
if ($total == $completed_albums) {
|
||||
$task->done = true;
|
||||
$task->state = "success";
|
||||
$task->percent_complete = 100;
|
||||
$task->status = t("Scanning Protected Album $completed_albums of $total");
|
||||
} else {
|
||||
$task->percent_complete = round(100 * $completed / $total);
|
||||
$task->status = t("Scanning Protected Album $completed_albums of $total -- $completed_items / $total_items files");
|
||||
}
|
||||
}
|
||||
}
|
21
3.0/modules/albumpassword/models/albumpassword_idcache.php
Normal file
21
3.0/modules/albumpassword/models/albumpassword_idcache.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-2011 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 Albumpassword_Idcache_Model extends ORM {
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
name = "Album Password"
|
||||
description = "Restrict access to individual albums."
|
||||
version = 2
|
||||
version = 3
|
||||
|
|
|
@ -32,7 +32,7 @@ class EXIF_GPS_Controller extends Controller {
|
|||
->order_by("exif_coordinates.latitude", "ASC")
|
||||
->descendants();
|
||||
$curr_album = ORM::factory("item")->where("id", "=", $type_id)->find_all();
|
||||
$map_title = $curr_album[0]->name;
|
||||
$map_title = $curr_album[0]->title;
|
||||
} elseif ($map_type == "user") {
|
||||
// Generate an array of all items uploaded by the current user that
|
||||
// have exif gps coordinates and order by latitude (to group items
|
||||
|
|
|
@ -50,16 +50,18 @@ class exif_gps_task_Core {
|
|||
$completed = $task->get("completed");
|
||||
|
||||
// Generate an array of the next 100 photos to check.
|
||||
$all_photos = ORM::factory("item")
|
||||
->where("id", ">", $last_id)
|
||||
->where("type", "=", "photo")
|
||||
->find_all(100);
|
||||
//$all_photos = ORM::factory("item")
|
||||
// ->where("id", ">", $last_id)
|
||||
// ->where("type", "=", "photo")
|
||||
// ->order_by("id")
|
||||
// ->find_all(100);
|
||||
|
||||
// Check each photo in the array to see if it already has exif gps data associated with it.
|
||||
// If it doesn't, attempt to extract gps coordinates.
|
||||
foreach (ORM::factory("item")
|
||||
->where("id", ">", $last_id)
|
||||
->where("type", "=", "photo")
|
||||
->order_by("id")
|
||||
->find_all(100) as $item) {
|
||||
|
||||
$record = ORM::factory("exif_coordinate")->where("item_id", "=", $item->id)->find();
|
||||
|
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user