Create a new table to track all protected files.
This commit is contained in:
parent
1cd2de2154
commit
d8c6b1f4cf
@ -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)->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,27 +81,64 @@ 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)->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)->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)->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 admin_menu($menu, $theme) {
|
||||
// Add a link to the Album Password admin page to the Content menu.
|
||||
$menu->get("settings_menu")
|
||||
|
@ -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} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`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} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`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");
|
||||
}
|
||||
}
|
||||
|
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
|
||||
|
@ -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)->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,27 +81,64 @@ 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)->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)->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)->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 admin_menu($menu, $theme) {
|
||||
// Add a link to the Album Password admin page to the Content menu.
|
||||
$menu->get("settings_menu")
|
||||
|
@ -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} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`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} (
|
||||
`id` int(9) NOT NULL auto_increment,
|
||||
`password_id` int(9) NOT NULL,
|
||||
`item_id` int(9) NOT NULL,
|
||||
PRIMARY KEY (`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");
|
||||
}
|
||||
}
|
||||
|
21
3.1/modules/albumpassword/models/albumpassword_idcache.php
Normal file
21
3.1/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
|
||||
|
Reference in New Issue
Block a user