diff --git a/3.0/modules/albumpassword/controllers/admin_albumpassword.php b/3.0/modules/albumpassword/controllers/admin_albumpassword.php new file mode 100644 index 00000000..425f9ed9 --- /dev/null +++ b/3.0/modules/albumpassword/controllers/admin_albumpassword.php @@ -0,0 +1,69 @@ +content = new View("admin_albumpassword.html"); + + // Generate a form for controlling the admin section. + $view->content->albumpassword_form = $this->_get_admin_form(); + + // Display the page. + print $view; + } + + private function _get_admin_form() { + // Make a new form for changing admin settings for this module. + $form = new Forge("admin/albumpassword/saveprefs", "", "post", + array("id" => "g-album-password-admin-form")); + + // Should protected items be hidden, or completely in-accessable? + $albumpassword_group = $form->group("album_password_group"); + $albumpassword_group->checkbox("hideonly") + ->label("Only hide protected albums?") + ->checked(module::get_var("albumpassword", "hideonly")); + + // Add a save button to the form. + $albumpassword_group->submit("save_settings")->value(t("Save")); + + // Return the newly generated form. + return $form; + } + + public function saveprefs() { + // Save user specified preferences. + + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + // Retrieve submitted form data. + if (Input::instance()->post("hideonly") == false) { + module::set_var("albumpassword", "hideonly", false); + } else { + module::set_var("albumpassword", "hideonly", true); + } + // Display a success message and redirect back to the TagsMap admin page. + message::success(t("Your settings have been saved.")); + url::redirect("admin/albumpassword"); + } +} diff --git a/3.0/modules/albumpassword/controllers/albumpassword.php b/3.0/modules/albumpassword/controllers/albumpassword.php index b014b749..01080fc2 100644 --- a/3.0/modules/albumpassword/controllers/albumpassword.php +++ b/3.0/modules/albumpassword/controllers/albumpassword.php @@ -84,7 +84,7 @@ class albumpassword_Controller extends Controller { // Display a success message and close the dialog. message::success(t("Password saved.")); - json::reply(array("result" => "success")); + print "\n\n\n\n\n"; } public function logout() { @@ -112,10 +112,10 @@ class albumpassword_Controller extends Controller { // If not, close the dialog and display a rejected message. cookie::set("g3_albumpassword", $album_password); message::success(t("Password Accepted.")); - json::reply(array("result" => "success")); + print "\n\n\n\n\n"; } else { message::error(t("Password Rejected.")); - json::reply(array("result" => "success")); + print "\n\n\n\n\n"; } } @@ -129,7 +129,7 @@ class albumpassword_Controller extends Controller { $assignpassword_group->input("assignpassword_password") ->id('assignpassword_password') ->label(t("Password:")); - $form->submit("save_password")->value(t("Save")); + $assignpassword_group->submit("save_password")->value(t("Save")); // Return the newly generated form. return $form; @@ -139,12 +139,14 @@ class albumpassword_Controller extends Controller { // Generate a form for allowing visitors to enter in their passwords. $form = new Forge("albumpassword/checkpassword", "", "post", array("id" => "g-login-password-form")); + $assignpassword_group = $form->group("Enter Password") ->label(t("Enter Password:")); - $assignpassword_group->input("albumpassword_password") + $assignpassword_group->password("albumpassword_password") ->id('albumpassword_password') ->label(t("Password:")); - $form->submit("login_password")->value(t("Login")); + + $assignpassword_group->submit("")->value(t("Login")); // Return the newly generated form. return $form; diff --git a/3.0/modules/albumpassword/helpers/MY_access.php b/3.0/modules/albumpassword/helpers/MY_access.php new file mode 100644 index 00000000..faf6c1c0 --- /dev/null +++ b/3.0/modules/albumpassword/helpers/MY_access.php @@ -0,0 +1,58 @@ +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(); + if ($existing_password->loaded()) { + if ((cookie::get("g3_albumpassword") != $existing_password->password) && + (identity::active_user()->id != $album_item->owner_id)) { + throw new Kohana_404_Exception(); + } + } + } while ($album_item->parent_id > 0); + } + } +} diff --git a/3.0/modules/albumpassword/helpers/MY_item.php b/3.0/modules/albumpassword/helpers/MY_item.php index 3e09a64d..79dd3afc 100644 --- a/3.0/modules/albumpassword/helpers/MY_item.php +++ b/3.0/modules/albumpassword/helpers/MY_item.php @@ -20,32 +20,19 @@ class item extends item_Core { static function viewable($model) { - // Hide the contents of a password protected album, - // Unless the current user is an admin, or the albums owner. + // Hide password protected albums until the correct password is entered, + // unless the current user is an admin, or the albums owner. $model = item_Core::viewable($model); - $album_item = ORM::factory("item")->where("id", "=", $model->id)->find(); - // Figure out if the user can access this album. - $deny_access = false; - $existing_password = ORM::factory("items_albumpassword")->where("album_id", "=", $model->id)->find(); - if ($existing_password->loaded()) { - if ((cookie::get("g3_albumpassword") != $existing_password->password) && - (identity::active_user()->id != $album_item->owner_id)) - $deny_access = true; - } - - // set access::DENY if necessary. - if ($deny_access == true) { - $view_restrictions = array(); - if (!identity::active_user()->admin) { - foreach (identity::group_ids_for_active_user() as $id) { - $view_restrictions[] = array("items.view_$id", "=", access::DENY); - } - } - } - if (count($view_restrictions)) { - $model->and_open()->merge_or_where($view_restrictions)->close(); + // If the user is an admin, don't hide anything anything. + // 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(); } return $model; diff --git a/3.0/modules/albumpassword/helpers/albumpassword_event.php b/3.0/modules/albumpassword/helpers/albumpassword_event.php index dd83c4d9..c5ead56a 100644 --- a/3.0/modules/albumpassword/helpers/albumpassword_event.php +++ b/3.0/modules/albumpassword/helpers/albumpassword_event.php @@ -80,7 +80,7 @@ class albumpassword_event_Core { ->label(t("Remove password")) ->css_id("g-album-password-remove") ->url(url::site("albumpassword/remove/" . $item->id))); - } else { + } elseif ($item->id != 1) { $menu->get("options_menu") ->append(Menu::factory("dialog") ->id("albumpassword_assign") @@ -101,4 +101,13 @@ class albumpassword_event_Core { db::build()->delete("items_albumpassword")->where("album_id", "=", $item->id)->execute(); } } + + static function admin_menu($menu, $theme) { + // Add a link to the Album Password admin page to the Content menu. + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("albumpassword") + ->label(t("Album Password Settings")) + ->url(url::site("admin/albumpassword"))); + } } diff --git a/3.0/modules/albumpassword/helpers/albumpassword_installer.php b/3.0/modules/albumpassword/helpers/albumpassword_installer.php index e59faffb..1fd20d89 100644 --- a/3.0/modules/albumpassword/helpers/albumpassword_installer.php +++ b/3.0/modules/albumpassword/helpers/albumpassword_installer.php @@ -28,9 +28,19 @@ class albumpassword_installer { 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", 1); + module::set_version("albumpassword", 2); + } + + 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); } static function uninstall() { diff --git a/3.0/modules/albumpassword/module.info b/3.0/modules/albumpassword/module.info index 6acdc1dd..cd1262f4 100644 --- a/3.0/modules/albumpassword/module.info +++ b/3.0/modules/albumpassword/module.info @@ -1,3 +1,3 @@ name = "Album Password" description = "Restrict access to individual albums." -version = 1 +version = 2 diff --git a/3.0/modules/albumpassword/views/admin_albumpassword.html.php b/3.0/modules/albumpassword/views/admin_albumpassword.html.php new file mode 100644 index 00000000..05e46454 --- /dev/null +++ b/3.0/modules/albumpassword/views/admin_albumpassword.html.php @@ -0,0 +1,9 @@ + +

+ +

+
+
+

+ +
diff --git a/3.0/modules/albumpassword/views/assignpassword.html.php b/3.0/modules/albumpassword/views/assignpassword.html.php index 14cd2767..c1a60b8d 100644 --- a/3.0/modules/albumpassword/views/assignpassword.html.php +++ b/3.0/modules/albumpassword/views/assignpassword.html.php @@ -1,20 +1,3 @@ -