From 00eacd659f27df9c13246c510057c4f42c8866a2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 15 Oct 2009 14:37:57 -0700 Subject: Start simplifying the interface by moving the static methods from user.php and group.php. Tried creating a identity helper, but the helper identity.php was confused with the library Identity.php. So got around this by making the methods on Identity static and calling the instance within the static methods. Also temporarily moved the user.php and group.php back into the user module. --- modules/server_add/helpers/server_add_event.php | 2 +- modules/server_add/helpers/server_add_theme.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/server_add/helpers') diff --git a/modules/server_add/helpers/server_add_event.php b/modules/server_add/helpers/server_add_event.php index 4db83f74..76357871 100644 --- a/modules/server_add/helpers/server_add_event.php +++ b/modules/server_add/helpers/server_add_event.php @@ -30,7 +30,7 @@ class server_add_event_Core { $item = $theme->item(); $paths = unserialize(module::get_var("server_add", "authorized_paths")); - if ($item && user::active()->admin && $item->is_album() && !empty($paths) && + if ($item && Identity::active()->admin && $item->is_album() && !empty($paths) && is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path())) { $menu->get("add_menu") ->append(Menu::factory("dialog") diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index 2ba2e167..cecb90b4 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -19,7 +19,7 @@ */ class server_add_theme_Core { static function head($theme) { - if (user::active()->admin) { + if (Identity::active()->admin) { $theme->script("server_add.js"); } } -- cgit v1.2.3 From 78ee4193b70329c8e0929efd18c22324dd2ad8e0 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 16 Oct 2009 10:06:58 -0700 Subject: Remove all non Identity API methods from Identity.php. Created an MY_Session class to provide the user state changes in the session and a login.php helper that has the login form. --- modules/comment/controllers/comments.php | 8 +- modules/comment/helpers/comment.php | 2 +- modules/comment/tests/Comment_Model_Test.php | 2 +- modules/gallery/controllers/admin.php | 2 +- modules/gallery/controllers/albums.php | 6 +- modules/gallery/controllers/l10n_client.php | 4 +- modules/gallery/controllers/login.php | 13 ++- modules/gallery/controllers/logout.php | 13 ++- modules/gallery/controllers/permissions.php | 2 +- modules/gallery/controllers/upgrader.php | 4 +- modules/gallery/controllers/welcome_message.php | 4 +- modules/gallery/helpers/access.php | 2 +- modules/gallery/helpers/gallery.php | 2 +- modules/gallery/helpers/gallery_event.php | 6 +- modules/gallery/helpers/gallery_theme.php | 2 +- modules/gallery/helpers/item.php | 4 +- modules/gallery/helpers/locales.php | 2 +- modules/gallery/helpers/log.php | 2 +- modules/gallery/helpers/login.php | 31 ++++++ modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/helpers/site_status.php | 2 +- modules/gallery/helpers/task.php | 2 +- modules/gallery/libraries/Admin_View.php | 4 +- modules/gallery/libraries/Identity.php | 107 --------------------- modules/gallery/libraries/MY_Session.php | 84 ++++++++++++++++ modules/gallery/libraries/Theme_View.php | 6 +- modules/gallery/tests/Access_Helper_Test.php | 8 +- modules/gallery/tests/Item_Helper_Test.php | 2 +- modules/gallery/tests/Photos_Controller_Test.php | 2 +- modules/gallery/views/kohana_error_page.php | 2 +- modules/gallery/views/maintenance.html.php | 2 +- modules/notification/helpers/notification.php | 8 +- .../notification/helpers/notification_event.php | 2 +- modules/search/helpers/search.php | 4 +- modules/server_add/controllers/server_add.php | 4 +- modules/server_add/helpers/server_add_event.php | 2 +- modules/server_add/helpers/server_add_theme.php | 2 +- modules/user/controllers/admin_users.php | 6 +- modules/user/controllers/users.php | 4 +- modules/user/views/admin_users.html.php | 2 +- 41 files changed, 194 insertions(+), 176 deletions(-) create mode 100644 modules/gallery/helpers/login.php create mode 100644 modules/gallery/libraries/MY_Session.php (limited to 'modules/server_add/helpers') diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 84d6ca47..c0658cc1 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -65,7 +65,7 @@ class Comments_Controller extends REST_Controller { $form = comment::get_add_form($item); $valid = $form->validate(); if ($valid) { - if (Identity::active()->guest && !$form->add_comment->inputs["name"]->value) { + if (Session::active_user()->guest && !$form->add_comment->inputs["name"]->value) { $form->add_comment->inputs["name"]->add_error("missing", 1); $valid = false; } @@ -78,13 +78,13 @@ class Comments_Controller extends REST_Controller { if ($valid) { $comment = comment::create( - $item, Identity::active(), + $item, Session::active_user(), $form->add_comment->text->value, $form->add_comment->inputs["name"]->value, $form->add_comment->email->value, $form->add_comment->url->value); - $active = Identity::active(); + $active = Session::active_user(); if ($active->guest) { $form->add_comment->inputs["name"]->value(""); $form->add_comment->email->value(""); @@ -192,7 +192,7 @@ class Comments_Controller extends REST_Controller { * @see REST_Controller::form_edit($resource) */ public function _form_edit($comment) { - if (!Identity::active()->admin) { + if (!Session::active_user()->admin) { access::forbidden(); } print comment::get_edit_form($comment); diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 38d65db6..e741266d 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -75,7 +75,7 @@ class comment_Core { module::event("comment_add_form", $form); $group->submit("")->value(t("Add")); - $active = Identity::active(); + $active = Session::active_user(); if (!$active->guest) { $group->inputs["name"]->value($active->full_name)->disabled("disabled"); $group->email->value($active->email)->disabled("disabled"); diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php index 76de2a34..84532a96 100644 --- a/modules/comment/tests/Comment_Model_Test.php +++ b/modules/comment/tests/Comment_Model_Test.php @@ -23,7 +23,7 @@ class Comment_Model_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $album = album::create($root, rand(), rand(), rand()); $comment = comment::create($album, Identity::guest(), "text", "name", "email", "url"); - Identity::set_active(Identity::guest()); + Session::set_active_user(Identity::guest()); // We can see the comment when permissions are granted on the album access::allow(Identity::everybody(), "view", $album); diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 8a4181a6..24eebe7d 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -21,7 +21,7 @@ class Admin_Controller extends Controller { private $theme; public function __construct($theme=null) { - if (!(Identity::active()->admin)) { + if (!(Session::active_user()->admin)) { access::forbidden(); } diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index fdf06ec0..055ff22b 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -29,7 +29,7 @@ class Albums_Controller extends Items_Controller { $view = new Theme_View("page.html", "login"); $view->page_title = t("Log in to Gallery"); $view->content = new View("login_ajax.html"); - $view->content->form = Identity::get_login_form("login/auth_html"); + $view->content->form = login::get_login_form("login/auth_html"); print $view; return; } else { @@ -111,7 +111,7 @@ class Albums_Controller extends Items_Controller { $this->input->post("name"), $this->input->post("title", $this->input->post("name")), $this->input->post("description"), - Identity::active()->id, + Session::active_user()->id, $this->input->post("slug")); log::success("content", "Created an album", @@ -146,7 +146,7 @@ class Albums_Controller extends Items_Controller { $_FILES["file"]["name"], $this->input->post("title", $this->input->post("name")), $this->input->post("description"), - Identity::active()->id); + Session::active_user()->id); log::success("content", "Added a photo", html::anchor("photos/$photo->id", "view photo")); message::success(t("Added photo %photo_title", diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index b3929c5d..2ab73102 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -20,7 +20,7 @@ class L10n_Client_Controller extends Controller { public function save() { access::verify_csrf(); - if (!Identity::active()->admin) { + if (!Session::active_user()->admin) { access::forbidden(); } @@ -85,7 +85,7 @@ class L10n_Client_Controller extends Controller { public function toggle_l10n_mode() { access::verify_csrf(); - if (!Identity::active()->admin) { + if (!Session::active_user()->admin) { access::forbidden(); } diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index c8b771ca..96a97a1d 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -21,7 +21,7 @@ class Login_Controller extends Controller { public function ajax() { $view = new View("login_ajax.html"); - $view->form = Identity::get_login_form("login/auth_ajax"); + $view->form = login::get_login_form("login/auth_ajax"); print $view; } @@ -40,7 +40,7 @@ class Login_Controller extends Controller { } public function html() { - print Identity::get_login_form("login/auth_html"); + print login::get_login_form("login/auth_html"); } public function auth_html() { @@ -54,7 +54,7 @@ class Login_Controller extends Controller { } } private function _auth($url) { - $form = Identity::get_login_form($url); + $form = login::get_login_form($url); $valid = $form->validate(); if ($valid) { $user = Identity::lookup_user_by_name($form->login->inputs["name"]->value); @@ -69,7 +69,12 @@ class Login_Controller extends Controller { } if ($valid) { - Identity::login($user); + if (Identity::is_writable()) { + $user->login_count += 1; + $user->last_login = time(); + $user->save(); + } + Session::set_active_user($user); log::info("user", t("User %name logged in", array("name" => $user->name))); } diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 6841b870..058860fa 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -19,10 +19,15 @@ */ class Logout_Controller extends Controller { public function index() { - //access::verify_csrf(); - - $user = Identity::active(); - Identity::logout(); + $user = Session::active_user(); + if (!$user->guest) { + try { + Session::instance()->destroy(); + } catch (Exception $e) { + Kohana::log("error", $e); + } + module::event("user_logout", $user); + } log::info("user", t("User %name logged out", array("name" => $user->name)), html::anchor("user/$user->id", html::clean($user->name))); if ($continue_url = $this->input->get("continue")) { diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 6b1e926f..7a06c3d3 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -74,7 +74,7 @@ class Permissions_Controller extends Controller { // If the active user just took away their own edit permissions, give it back. if ($perm->name == "edit") { - if (!access::user_can(Identity::active(), "edit", $item)) { + if (!access::user_can(Session::active_user(), "edit", $item)) { access::allow($group, $perm->name, $item); } } diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php index f6ca4c8a..e0c5d340 100644 --- a/modules/gallery/controllers/upgrader.php +++ b/modules/gallery/controllers/upgrader.php @@ -40,7 +40,7 @@ class Upgrader_Controller extends Controller { } $view = new View("upgrader.html"); - $view->can_upgrade = Identity::active()->admin || $session->get("can_upgrade"); + $view->can_upgrade = Session::active_user()->admin || $session->get("can_upgrade"); $view->upgrade_token = $upgrade_token; $view->available = module::available(); $view->done = ($available_upgrades == 0); @@ -52,7 +52,7 @@ class Upgrader_Controller extends Controller { // @todo this may screw up some module installers, but we don't have a better answer at // this time. $_SERVER["HTTP_HOST"] = "example.com"; - } else if (!Identity::active()->admin && !Session::instance()->get("can_upgrade", false)) { + } else if (!Session::active_user()->admin && !Session::instance()->get("can_upgrade", false)) { access::forbidden(); } diff --git a/modules/gallery/controllers/welcome_message.php b/modules/gallery/controllers/welcome_message.php index c093b67d..cfdc3976 100644 --- a/modules/gallery/controllers/welcome_message.php +++ b/modules/gallery/controllers/welcome_message.php @@ -19,12 +19,12 @@ */ class Welcome_Message_Controller extends Controller { public function index() { - if (!Identity::active()->admin) { + if (!Session::active_user()->admin) { url::redirect(item::root()->abs_url()); } $v = new View("welcome_message.html"); - $v->user = Identity::active(); + $v->user = Session::active_user(); print $v; } } diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 0e0e749e..21f4de81 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -79,7 +79,7 @@ class access_Core { * @return boolean */ static function can($perm_name, $item) { - return self::user_can(Identity::active(), $perm_name, $item); + return self::user_can(Session::active_user(), $perm_name, $item); } /** diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index e1fa2a7c..18bb2609 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -27,7 +27,7 @@ class gallery_Core { static function maintenance_mode() { $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); - if (Router::$controller != "login" && !empty($maintenance_mode) && !Identity::active()->admin) { + if (Router::$controller != "login" && !empty($maintenance_mode) && !Session::active_user()->admin) { Router::$controller = "maintenance"; Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php"; Router::$method = "index"; diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index abead9e3..a6aa0657 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -24,10 +24,10 @@ class gallery_event_Core { */ static function gallery_ready() { // Call Identity::instance() now to force the load of the user interface classes. - // Identity::load_user will attempt to load the active user from the session and needs + // Session::load_user will attempt to load the active user from the session and needs // the user definition class, which can't be reached by Kohana's heiracrchical lookup. Identity::instance(); - Identity::load_user(); + Session::load_user(); locales::set_request_locale(); } @@ -139,7 +139,7 @@ class gallery_event_Core { } } - if (Identity::active()->admin) { + if (Session::active_user()->admin) { $menu->append($admin_menu = Menu::factory("submenu") ->id("admin_menu") ->label(t("Admin"))); diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index cc46a88a..d21cb124 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -54,7 +54,7 @@ class gallery_theme_Core { static function header_top($theme) { if ($theme->page_type != "login") { $view = new View("login.html"); - $view->user = Identity::active(); + $view->user = Session::active_user(); return $view->render(); } } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index bce83bb3..3d36a324 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -158,8 +158,8 @@ class item_Core { */ static function viewable($model) { $view_restrictions = array(); - if (!Identity::active()->admin) { - foreach (Identity::group_ids_for_active_user() as $id) { + if (!Session::active_user()->admin) { + foreach (Session::group_ids_for_active_user() as $id) { // Separate the first restriction from the rest to make it easier for us to formulate // our where clause below if (empty($view_restrictions)) { diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index 2dfc7f21..f80fce03 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -141,7 +141,7 @@ class locales_Core { $locale = self::cookie_locale(); // 2. Check the user's preference if (!$locale) { - $locale = Identity::active()->locale; + $locale = Session::active_user()->locale; } // 3. Check the browser's / OS' preference if (!$locale) { diff --git a/modules/gallery/helpers/log.php b/modules/gallery/helpers/log.php index 512723dd..d1b34e3a 100644 --- a/modules/gallery/helpers/log.php +++ b/modules/gallery/helpers/log.php @@ -80,7 +80,7 @@ class log_Core { $log->url = substr(url::abs_current(true), 0, 255); $log->referer = request::referrer(null); $log->timestamp = time(); - $log->user_id = Identity::active()->id; + $log->user_id = Session::active_user()->id; $log->save(); } diff --git a/modules/gallery/helpers/login.php b/modules/gallery/helpers/login.php new file mode 100644 index 00000000..d44153ad --- /dev/null +++ b/modules/gallery/helpers/login.php @@ -0,0 +1,31 @@ + "g-login-form")); + $form->set_attr('class', "g-narrow"); + $group = $form->group("login")->label(t("Login")); + $group->input("name")->label(t("Username"))->id("g-username")->class(null); + $group->password("password")->label(t("Password"))->id("g-password")->class(null); + $group->inputs["name"]->error_messages("invalid_login", t("Invalid name or password")); + $group->submit("")->value(t("Login")); + return $form; + } +} \ No newline at end of file diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index bc0efa01..9541f20e 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -77,7 +77,7 @@ class movie_Core { $movie->title = $title; $movie->description = $description; $movie->name = $name; - $movie->owner_id = $owner_id ? $owner_id : Identity::active()->id; + $movie->owner_id = $owner_id ? $owner_id : Session::active_user()->id; $movie->width = $movie_info[0]; $movie->height = $movie_info[1]; $movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv"; diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index ad23e322..203862cd 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -76,7 +76,7 @@ class photo_Core { $photo->title = $title; $photo->description = $description; $photo->name = $name; - $photo->owner_id = $owner_id ? $owner_id : Identity::active()->id; + $photo->owner_id = $owner_id ? $owner_id : Session::active_user()->id; $photo->width = $image_info[0]; $photo->height = $image_info[1]; $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index 3f7ff19d..06b29fda 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -95,7 +95,7 @@ class site_status_Core { * @return html text */ static function get() { - if (!Identity::active()->admin) { + if (!Session::active_user()->admin) { return; } $buf = array(); diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index 4735c36c..f84fd10e 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -42,7 +42,7 @@ class task_Core { $task->percent_complete = 0; $task->status = ""; $task->state = "started"; - $task->owner_id = Identity::active()->id; + $task->owner_id = Session::active_user()->id; $task->context = serialize($context); $task->save(); diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index b1bb4ada..74a08c77 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -36,12 +36,12 @@ class Admin_View_Core extends Gallery_View { parent::__construct($name); $this->theme_name = module::get_var("gallery", "active_admin_theme"); - if (Identity::active()->admin) { + if (Session::active_user()->admin) { $this->theme_name = Input::instance()->get("theme", $this->theme_name); } $this->sidebar = ""; $this->set_global("theme", $this); - $this->set_global("user", Identity::active()); + $this->set_global("user", Session::active_user()); } public function admin_menu() { diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php index fb553de6..f844cf8f 100644 --- a/modules/gallery/libraries/Identity.php +++ b/modules/gallery/libraries/Identity.php @@ -194,111 +194,4 @@ class Identity_Core { static function get_user_list($ids) { return self::instance()->driver->get_user_list($ids); } - - static function get_login_form($url) { - $form = new Forge($url, "", "post", array("id" => "g-login-form")); - $form->set_attr('class', "g-narrow"); - $group = $form->group("login")->label(t("Login")); - $group->input("name")->label(t("Username"))->id("g-username")->class(null); - $group->password("password")->label(t("Password"))->id("g-password")->class(null); - $group->inputs["name"]->error_messages("invalid_login", t("Invalid name or password")); - $group->submit("")->value(t("Login")); - return $form; - } - - /** - * Return the active user. If there's no active user, return the guest user. - * - * @return User_Model - */ - static function active() { - // @todo (maybe) cache this object so we're not always doing session lookups. - $user = Session::instance()->get("user", null); - if (!isset($user)) { - // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary - // work. - $user = self::guest(); - } - return $user; - } - - /** - * Change the active user. - * - * @return User_Model - */ - static function set_active($user) { - $session = Session::instance(); - $session->set("user", $user); - $session->delete("group_ids"); - self::load_user(); - } - - /** - * Return the array of group ids this user belongs to - * - * @return array - */ - static function group_ids_for_active_user() { - return Session::instance()->get("group_ids", array(1)); - } - - /** - * Make sure that we have a session and group_ids cached in the session. This is one - * of the first calls to reference the user so call the Identity::instance to load the - * driver classes. - */ - static function load_user() { - $session = Session::instance(); - if (!($user = $session->get("user"))) { - $session->set("user", $user = self::guest()); - } - - // The installer cannot set a user into the session, so it just sets an id which we should - // upconvert into a user. - // @todo set the user name into the session instead of 2 and then use it to get the user object - if ($user === 2) { - $user = self::lookup_user_by_name("admin"); - self::login($user); - $session->set("user", $user); - } - - if (!$session->get("group_ids")) { - $ids = array(); - foreach ($user->groups as $group) { - $ids[] = $group->id; - } - $session->set("group_ids", $ids); - } - } - - /** - * Log in as a given user. - * @param object $user the user object. - */ - static function login($user) { - // @todo make this an interface call - $user->login_count += 1; - $user->last_login = time(); - $user->save(); - - self::set_active($user); - module::event("user_login", $user); - } - - /** - * Log out the active user and destroy the session. - * @param object $user the user object. - */ - static function logout() { - $user = self::active(); - if (!$user->guest) { - try { - Session::instance()->destroy(); - } catch (Exception $e) { - Kohana::log("error", $e); - } - module::event("user_logout", $user); - } - } } // End Identity diff --git a/modules/gallery/libraries/MY_Session.php b/modules/gallery/libraries/MY_Session.php new file mode 100644 index 00000000..6394c0fb --- /dev/null +++ b/modules/gallery/libraries/MY_Session.php @@ -0,0 +1,84 @@ +get("user"))) { + $session->set("user", $user = Identity::guest()); + } + + // The installer cannot set a user into the session, so it just sets an id which we should + // upconvert into a user. + // @todo set the user name into the session instead of 2 and then use it to get the user object + if ($user === 2) { + $user = Instance::lookup_user_by_name("admin"); + self::set_active_user($user); + $session->set("user", $user); + } + + if (!$session->get("group_ids")) { + $ids = array(); + foreach ($user->groups as $group) { + $ids[] = $group->id; + } + $session->set("group_ids", $ids); + } + } + + /** + * Return the array of group ids this user belongs to + * + * @return array + */ + static function group_ids_for_active_user() { + return self::instance()->get("group_ids", array(1)); + } + + /** + * Return the active user. If there's no active user, return the guest user. + * + * @return User_Definition + */ + static function active_user() { + // @todo (maybe) cache this object so we're not always doing session lookups. + $user = self::instance()->get("user", null); + if (!isset($user)) { + // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary + // work. + $user = Identity::guest(); + } + return $user; + } + + /** + * Change the active user. + * @param User_Definition $user + */ + static function set_active_user($user) { + $session = Session::instance(); + $session->set("user", $user); + $session->delete("group_ids"); + self::load_user(); + } +} \ No newline at end of file diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 4e87f4fb..2fdc7531 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -37,13 +37,13 @@ class Theme_View_Core extends Gallery_View { parent::__construct($name); $this->theme_name = module::get_var("gallery", "active_site_theme"); - if (Identity::active()->admin) { + if (Session::active_user()->admin) { $this->theme_name = Input::instance()->get("theme", $this->theme_name); } $this->item = null; $this->tag = null; $this->set_global("theme", $this); - $this->set_global("user", Identity::active()); + $this->set_global("user", Session::active_user()); $this->set_global("page_type", $page_type); $this->set_global("page_title", null); if ($page_type == "album") { @@ -158,7 +158,7 @@ class Theme_View_Core extends Gallery_View { */ public function sidebar_blocks() { $sidebar = block_manager::get_html("site.sidebar", $this); - if (empty($sidebar) && Identity::active()->admin) { + if (empty($sidebar) && Session::active_user()->admin) { $sidebar = new View("no_sidebar.html"); } return $sidebar; diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 4904887a..b3b5ed30 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -45,7 +45,7 @@ class Access_Helper_Test extends Unit_Test_Case { } public function setup() { - Identity::set_active(Identity::guest()); + Session::set_active_user(Identity::guest()); } public function groups_and_permissions_are_bound_to_columns_test() { @@ -295,7 +295,7 @@ class Access_Helper_Test extends Unit_Test_Case { $user->remove($group); } $user->save(); - Identity::set_active($user); + Session::set_active_user($user); // This user can't edit anything $root = ORM::factory("item", 1); @@ -308,7 +308,7 @@ class Access_Helper_Test extends Unit_Test_Case { access::allow($group, "edit", $root); $user = Identity::lookup_user($user->id); // reload() does not flush related columns - Identity::set_active($user); + Session::set_active_user($user); // And verify that the user can edit. $this->assert_true(access::can("edit", $root)); @@ -363,7 +363,7 @@ class Access_Helper_Test extends Unit_Test_Case { } public function moved_items_inherit_new_permissions_test() { - Identity::set_active(Identity::lookup_user_by_name("admin")); + Session::set_active_user(Identity::lookup_user_by_name("admin")); $root = ORM::factory("item", 1); $public_album = album::create($root, rand(), "public album"); diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index d4cfebba..fc01db91 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -23,7 +23,7 @@ class Item_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $album = album::create($root, rand(), rand(), rand()); $item = self::_create_random_item($album); - Identity::set_active(Identity::guest()); + Session::set_active_user(Identity::guest()); // We can see the item when permissions are granted access::allow(Identity::everybody(), "view", $album); diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index 3f99e037..cdb4ae4f 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -31,7 +31,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $photo = photo::create( $root, MODPATH . "gallery/tests/test.jpg", "test.jpeg", - "test", "test", Identity::active(), "slug"); + "test", "test", Session::active_user(), "slug"); $orig_name = $photo->name; $_POST["filename"] = "test.jpeg"; diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php index bca29298..0256fabb 100644 --- a/modules/gallery/views/kohana_error_page.php +++ b/modules/gallery/views/kohana_error_page.php @@ -57,7 +57,7 @@ <?= t("Something went wrong!") ?> - + admin ?>

diff --git a/modules/gallery/views/maintenance.html.php b/modules/gallery/views/maintenance.html.php index dc8925b4..0aeaaec2 100644 --- a/modules/gallery/views/maintenance.html.php +++ b/modules/gallery/views/maintenance.html.php @@ -43,7 +43,7 @@

- + diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 2e22eeae..64eed8dc 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -20,7 +20,7 @@ class notification { static function get_subscription($item_id, $user=null) { if (empty($user)) { - $user = Identity::active(); + $user = Session::active_user(); } return ORM::factory("subscription") @@ -31,7 +31,7 @@ class notification { static function is_watching($item, $user=null) { if (empty($user)) { - $user = Identity::active(); + $user = Session::active_user(); } return ORM::factory("subscription") @@ -44,7 +44,7 @@ class notification { static function add_watch($item, $user=null) { if ($item->is_album()) { if (empty($user)) { - $user = Identity::active(); + $user = Session::active_user(); } $subscription = ORM::factory("subscription"); $subscription->item_id = $item->id; @@ -56,7 +56,7 @@ class notification { static function remove_watch($item, $user=null) { if ($item->is_album()) { if (empty($user)) { - $user = Identity::active(); + $user = Session::active_user(); } $subscription = ORM::factory("subscription") diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index d519bdc4..f0530cd9 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -95,7 +95,7 @@ class notification_event_Core { } static function site_menu($menu, $theme) { - if (!Identity::active()->guest) { + if (!Session::active_user()->guest) { $item = $theme->item(); if ($item && $item->is_album() && access::can("view", $item)) { diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 86107714..8b14cfa9 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -22,8 +22,8 @@ class search_Core { $db = Database::instance(); $q = $db->escape_str($q); - if (!Identity::active()->admin) { - foreach (Identity::group_ids_for_active_user() as $id) { + if (!Session::active_user()->admin) { + foreach (Session::group_ids_for_active_user() as $id) { $fields[] = "`view_$id` = TRUE"; // access::ALLOW } $access_sql = "AND (" . join(" AND ", $fields) . ")"; diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 701c89fd..428065f6 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -103,7 +103,7 @@ class Server_Add_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded || $task->owner_id != Identity::active()->id) { + if (!$task->loaded || $task->owner_id != Session::active_user()->id) { access::forbidden(); } @@ -207,7 +207,7 @@ class Server_Add_Controller extends Admin_Controller { $task->set("mode", "done"); } - $owner_id = Identity::active()->id; + $owner_id = Session::active_user()->id; foreach ($entries as $entry) { if (microtime(true) - $start > 0.5) { break; diff --git a/modules/server_add/helpers/server_add_event.php b/modules/server_add/helpers/server_add_event.php index 76357871..8f8b0016 100644 --- a/modules/server_add/helpers/server_add_event.php +++ b/modules/server_add/helpers/server_add_event.php @@ -30,7 +30,7 @@ class server_add_event_Core { $item = $theme->item(); $paths = unserialize(module::get_var("server_add", "authorized_paths")); - if ($item && Identity::active()->admin && $item->is_album() && !empty($paths) && + if ($item && Session::active_user()->admin && $item->is_album() && !empty($paths) && is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path())) { $menu->get("add_menu") ->append(Menu::factory("dialog") diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index cecb90b4..44681d36 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -19,7 +19,7 @@ */ class server_add_theme_Core { static function head($theme) { - if (Identity::active()->admin) { + if (Session::active_user()->admin) { $theme->script("server_add.js"); } } diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index fed872a5..258de843 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -69,7 +69,7 @@ class Admin_Users_Controller extends Admin_Controller { public function delete_user($id) { access::verify_csrf(); - if ($id == Identity::active()->id || $id == user::guest()->id) { + if ($id == Session::active_user()->id || $id == user::guest()->id) { access::forbidden(); } @@ -136,7 +136,7 @@ class Admin_Users_Controller extends Admin_Controller { } // An admin can change the admin status for any user but themselves - if ($user->id != Identity::active()->id) { + if ($user->id != Session::active_user()->id) { $user->admin = $form->edit_user->admin->checked; } $user->save(); @@ -158,7 +158,7 @@ class Admin_Users_Controller extends Admin_Controller { $form = $this->_get_user_edit_form_admin($user); // Don't allow the user to control their own admin bit, else you can lock yourself out - if ($user->id == Identity::active()->id) { + if ($user->id == Session::active_user()->id) { $form->edit_user->admin->disabled(1); } print $form; diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index ebce1d8d..0ccf3e2a 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -21,7 +21,7 @@ class Users_Controller extends Controller { public function update($id) { $user = user::lookup($id); - if ($user->guest || $user->id != Identity::active()->id) { + if ($user->guest || $user->id != Session::active_user()->id) { access::forbidden(); } @@ -59,7 +59,7 @@ class Users_Controller extends Controller { public function form_edit($id) { $user = user::lookup($id); - if ($user->guest || $user->id != Identity::active()->id) { + if ($user->guest || $user->id != Session::active_user()->id) { access::forbidden(); } diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index 400686cc..899e0b68 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -90,7 +90,7 @@ - id != $user->id && !$user->guest): ?> + id != $user->id && !$user->guest): ?> id") ?>" class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> -- cgit v1.2.3 From 3c936d661a088fb43b47eb5b208958180e8f65eb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 22 Oct 2009 13:09:20 -0700 Subject: Change the name of identity library from Identity to IdentityProvider. Create a helper class called identity to simplify call the Identity Provider. Move the contents of MY_Session.php to the new helper class and remove the MY_Session class --- modules/akismet/tests/Akismet_Helper_Test.php | 2 +- modules/comment/controllers/comments.php | 8 +- modules/comment/helpers/comment.php | 2 +- modules/comment/models/comment.php | 2 +- modules/comment/tests/Comment_Event_Test.php | 2 +- modules/comment/tests/Comment_Helper_Test.php | 4 +- modules/comment/tests/Comment_Model_Test.php | 8 +- modules/digibug/controllers/digibug.php | 2 +- modules/digibug/tests/Digibug_Controller_Test.php | 4 +- modules/g2_import/helpers/g2_import.php | 16 +- modules/gallery/controllers/admin.php | 2 +- modules/gallery/controllers/admin_identity.php | 10 +- modules/gallery/controllers/albums.php | 4 +- modules/gallery/controllers/l10n_client.php | 4 +- modules/gallery/controllers/login.php | 8 +- modules/gallery/controllers/logout.php | 2 +- modules/gallery/controllers/permissions.php | 6 +- modules/gallery/controllers/upgrader.php | 4 +- modules/gallery/controllers/welcome_message.php | 4 +- modules/gallery/helpers/access.php | 4 +- modules/gallery/helpers/gallery.php | 2 +- modules/gallery/helpers/gallery_event.php | 10 +- modules/gallery/helpers/gallery_installer.php | 2 +- modules/gallery/helpers/gallery_theme.php | 2 +- modules/gallery/helpers/identity.php | 225 +++++++++++++++++++++ modules/gallery/helpers/item.php | 4 +- modules/gallery/helpers/locales.php | 2 +- modules/gallery/helpers/log.php | 2 +- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/helpers/site_status.php | 2 +- modules/gallery/helpers/task.php | 2 +- modules/gallery/libraries/Admin_View.php | 4 +- modules/gallery/libraries/Identity.php | 222 -------------------- modules/gallery/libraries/IdentityProvider.php | 200 ++++++++++++++++++ modules/gallery/libraries/MY_Session.php | 93 --------- modules/gallery/libraries/Theme_View.php | 6 +- modules/gallery/libraries/drivers/Identity.php | 123 ----------- .../gallery/libraries/drivers/IdentityProvider.php | 123 +++++++++++ modules/gallery/models/item.php | 2 +- modules/gallery/models/log.php | 2 +- modules/gallery/models/task.php | 2 +- modules/gallery/tests/Access_Helper_Test.php | 144 ++++++------- modules/gallery/tests/Albums_Controller_Test.php | 4 +- modules/gallery/tests/Item_Helper_Test.php | 6 +- modules/gallery/tests/Photos_Controller_Test.php | 6 +- modules/gallery/views/kohana_error_page.php | 2 +- modules/gallery/views/login.html.php | 2 +- modules/gallery/views/login_ajax.html.php | 2 +- modules/notification/helpers/notification.php | 10 +- .../notification/helpers/notification_event.php | 2 +- modules/search/helpers/search.php | 4 +- modules/server_add/controllers/server_add.php | 4 +- modules/server_add/helpers/server_add_event.php | 2 +- modules/server_add/helpers/server_add_theme.php | 2 +- modules/user/controllers/admin_users.php | 6 +- modules/user/controllers/password.php | 2 +- modules/user/controllers/users.php | 4 +- modules/user/helpers/group.php | 18 +- .../user/libraries/drivers/Identity/Gallery.php | 150 -------------- .../libraries/drivers/IdentityProvider/Gallery.php | 150 ++++++++++++++ modules/user/views/admin_users.html.php | 2 +- 62 files changed, 885 insertions(+), 769 deletions(-) create mode 100644 modules/gallery/helpers/identity.php delete mode 100644 modules/gallery/libraries/Identity.php create mode 100644 modules/gallery/libraries/IdentityProvider.php delete mode 100644 modules/gallery/libraries/MY_Session.php delete mode 100644 modules/gallery/libraries/drivers/Identity.php create mode 100644 modules/gallery/libraries/drivers/IdentityProvider.php delete mode 100644 modules/user/libraries/drivers/Identity/Gallery.php create mode 100644 modules/user/libraries/drivers/IdentityProvider/Gallery.php (limited to 'modules/server_add/helpers') diff --git a/modules/akismet/tests/Akismet_Helper_Test.php b/modules/akismet/tests/Akismet_Helper_Test.php index 6788e7a3..745b455c 100644 --- a/modules/akismet/tests/Akismet_Helper_Test.php +++ b/modules/akismet/tests/Akismet_Helper_Test.php @@ -26,7 +26,7 @@ class Akismet_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $this->_comment = comment::create( - $root, Identity::guest(), "This is a comment", + $root, identity::guest(), "This is a comment", "John Doe", "john@gallery2.org", "http://gallery2.org"); foreach ($this->_comment->list_fields("comments") as $name => $field) { if (strpos($name, "server_") === 0) { diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index c0658cc1..09b9c607 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -65,7 +65,7 @@ class Comments_Controller extends REST_Controller { $form = comment::get_add_form($item); $valid = $form->validate(); if ($valid) { - if (Session::active_user()->guest && !$form->add_comment->inputs["name"]->value) { + if (identity::active_user()->guest && !$form->add_comment->inputs["name"]->value) { $form->add_comment->inputs["name"]->add_error("missing", 1); $valid = false; } @@ -78,13 +78,13 @@ class Comments_Controller extends REST_Controller { if ($valid) { $comment = comment::create( - $item, Session::active_user(), + $item, identity::active_user(), $form->add_comment->text->value, $form->add_comment->inputs["name"]->value, $form->add_comment->email->value, $form->add_comment->url->value); - $active = Session::active_user(); + $active = identity::active_user(); if ($active->guest) { $form->add_comment->inputs["name"]->value(""); $form->add_comment->email->value(""); @@ -192,7 +192,7 @@ class Comments_Controller extends REST_Controller { * @see REST_Controller::form_edit($resource) */ public function _form_edit($comment) { - if (!Session::active_user()->admin) { + if (!identity::active_user()->admin) { access::forbidden(); } print comment::get_edit_form($comment); diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index e741266d..53d58afa 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -75,7 +75,7 @@ class comment_Core { module::event("comment_add_form", $form); $group->submit("")->value(t("Add")); - $active = Session::active_user(); + $active = identity::active_user(); if (!$active->guest) { $group->inputs["name"]->value($active->full_name)->disabled("disabled"); $group->email->value($active->email)->disabled("disabled"); diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 5e29e778..bb9b8833 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -23,7 +23,7 @@ class Comment_Model extends ORM { } function author() { - return Identity::lookup_user($this->author_id); + return identity::lookup_user($this->author_id); } function author_name() { diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php index eb301893..f650cabf 100644 --- a/modules/comment/tests/Comment_Event_Test.php +++ b/modules/comment/tests/Comment_Event_Test.php @@ -22,7 +22,7 @@ class Comment_Event_Test extends Unit_Test_Case { $rand = rand(); $album = album::create(ORM::factory("item", 1), "test_$rand", "test_$rand"); $comment = comment::create( - $album, Identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand"); + $album, identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand"); $album->delete(); diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php index e8ab7c79..c635c3b7 100644 --- a/modules/comment/tests/Comment_Helper_Test.php +++ b/modules/comment/tests/Comment_Helper_Test.php @@ -48,7 +48,7 @@ class Comment_Helper_Test extends Unit_Test_Case { $rand = rand(); $root = ORM::factory("item", 1); $comment = comment::create( - $root, Identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand"); + $root, identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand"); $this->assert_equal("name_$rand", $comment->author_name()); $this->assert_equal("email_$rand", $comment->author_email()); @@ -77,7 +77,7 @@ class Comment_Helper_Test extends Unit_Test_Case { public function create_comment_for_user_test() { $rand = rand(); $root = ORM::factory("item", 1); - $admin = Identity::lookup_user(2); + $admin = identity::lookup_user(2); $comment = comment::create( $root, $admin, "text_$rand", "name_$rand", "email_$rand", "url_$rand"); diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php index 84532a96..de19648d 100644 --- a/modules/comment/tests/Comment_Model_Test.php +++ b/modules/comment/tests/Comment_Model_Test.php @@ -22,17 +22,17 @@ class Comment_Model_Test extends Unit_Test_Case { public function cant_view_comments_for_unviewable_items_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), rand(), rand()); - $comment = comment::create($album, Identity::guest(), "text", "name", "email", "url"); - Session::set_active_user(Identity::guest()); + $comment = comment::create($album, identity::guest(), "text", "name", "email", "url"); + identity::set_active_user(identity::guest()); // We can see the comment when permissions are granted on the album - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_equal( 1, ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all()); // We can't see the comment when permissions are denied on the album - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all()); diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index 8ea83601..1bb2691b 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -23,7 +23,7 @@ class Digibug_Controller extends Controller { $item = ORM::factory("item", $id); access::required("view", $item); - if (access::group_can(Identity::everybody(), "view_full", $item)) { + if (access::group_can(identity::everybody(), "view_full", $item)) { $full_url = $item->file_url(true); $thumb_url = $item->thumb_url(true); } else { diff --git a/modules/digibug/tests/Digibug_Controller_Test.php b/modules/digibug/tests/Digibug_Controller_Test.php index 19f57972..a56d58bb 100644 --- a/modules/digibug/tests/Digibug_Controller_Test.php +++ b/modules/digibug/tests/Digibug_Controller_Test.php @@ -35,8 +35,8 @@ class Digibug_Controller_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $this->_album = album::create($root, rand(), "test album"); - access::deny(Identity::everybody(), "view_full", $this->_album); - access::deny(Identity::registered_users(), "view_full", $this->_album); + access::deny(identity::everybody(), "view_full", $this->_album); + access::deny(identity::registered_users(), "view_full", $this->_album); $rand = rand(); $this->_item = photo::create($this->_album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index d24aab93..f55e7f32 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -230,16 +230,16 @@ class g2_import_Core { switch ($g2_group->getGroupType()) { case GROUP_NORMAL: try { - $group = Identity::create_group($g2_group->getGroupName()); + $group = identity::create_group($g2_group->getGroupName()); } catch (Exception $e) { // @todo For now we assume this is a "duplicate group" exception - $group = Identity::lookup_user_by_name($g2_group->getGroupname()); + $group = identity::lookup_user_by_name($g2_group->getGroupname()); } $message = t("Group '%name' was imported", array("name" => $g2_group->getGroupname())); break; case GROUP_ALL_USERS: - $group = Identity::registered_users(); + $group = identity::registered_users(); $message = t("Group 'Registered' was converted to '%name'", array("name" => $group->name)); break; @@ -248,7 +248,7 @@ class g2_import_Core { break; // This is not a group in G3 case GROUP_EVERYBODY: - $group = Identity::everybody(); + $group = identity::everybody(); $message = t("Group 'Everybody' was converted to '%name'", array("name" => $group->name)); break; } @@ -270,7 +270,7 @@ class g2_import_Core { } if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) { - self::set_map($g2_user_id, Identity::guest()->id); + self::set_map($g2_user_id, identity::guest()->id); return t("Skipping Anonymous User"); } @@ -285,11 +285,11 @@ class g2_import_Core { $g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId())); try { - $user = Identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), ""); + $user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), ""); $message = t("Created user: '%name'.", array("name" => $user->name)); } catch (Exception $e) { // @todo For now we assume this is a "duplicate user" exception - $user = Identity::lookup_user_by_name($g2_user->getUsername()); + $user = identity::lookup_user_by_name($g2_user->getUsername()); $message = t("Loaded existing user: '%name'.", array("name" => $user->name)); } @@ -301,7 +301,7 @@ class g2_import_Core { $user->admin = true; $message .= t("\n\tAdded 'admin' flag to user"); } else { - $group = Identity::lookup_group(self::map($g2_group_id)); + $group = identity::lookup_group(self::map($g2_group_id)); $user->add($group); $message .= t("\n\tAdded user to group '%group'.", array("group" => $group->name)); } diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 24eebe7d..98cac557 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -21,7 +21,7 @@ class Admin_Controller extends Controller { private $theme; public function __construct($theme=null) { - if (!(Session::active_user()->admin)) { + if (!(identity::active_user()->admin)) { access::forbidden(); } diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index 9d756a5c..d06132ff 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -21,7 +21,7 @@ class Admin_Identity_Controller extends Admin_Controller { public function index() { $view = new Admin_View("admin.html"); $view->content = new View("admin_identity.html"); - $view->content->available = Identity::providers(); + $view->content->available = identity::providers(); $view->content->active = module::get_var("gallery", "identity_provider", "user"); print $view; } @@ -39,7 +39,7 @@ class Admin_Identity_Controller extends Admin_Controller { access::verify_csrf(); $active_provider = module::get_var("gallery", "identity_provider", "user"); - $providers = Identity::providers(); + $providers = identity::providers(); $new_provider = $this->input->post("provider"); @@ -47,13 +47,13 @@ class Admin_Identity_Controller extends Admin_Controller { module::event("pre_identity_change", $active_provider, $new_provider); - Identity::deactivate(); + identity::deactivate(); // Switch authentication module::set_var("gallery", "identity_provider", $new_provider); - Identity::reset(); + identity::reset(); - Identity::activate(); + identity::activate(); // @todo this type of collation is questionable from an i18n perspective message::success(t("Changed to %description", diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index fabf67ce..24ceb0c9 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -111,7 +111,7 @@ class Albums_Controller extends Items_Controller { $this->input->post("name"), $this->input->post("title", $this->input->post("name")), $this->input->post("description"), - Session::active_user()->id, + identity::active_user()->id, $this->input->post("slug")); log::success("content", "Created an album", @@ -146,7 +146,7 @@ class Albums_Controller extends Items_Controller { $_FILES["file"]["name"], $this->input->post("title", $this->input->post("name")), $this->input->post("description"), - Session::active_user()->id); + identity::active_user()->id); log::success("content", "Added a photo", html::anchor("photos/$photo->id", "view photo")); message::success(t("Added photo %photo_title", diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php index 2ab73102..6db67d3b 100644 --- a/modules/gallery/controllers/l10n_client.php +++ b/modules/gallery/controllers/l10n_client.php @@ -20,7 +20,7 @@ class L10n_Client_Controller extends Controller { public function save() { access::verify_csrf(); - if (!Session::active_user()->admin) { + if (!identity::active_user()->admin) { access::forbidden(); } @@ -85,7 +85,7 @@ class L10n_Client_Controller extends Controller { public function toggle_l10n_mode() { access::verify_csrf(); - if (!Session::active_user()->admin) { + if (!identity::active_user()->admin) { access::forbidden(); } diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index 4c83d647..86e2b0a4 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -58,8 +58,8 @@ class Login_Controller extends Controller { $form = login::get_login_form($url); $valid = $form->validate(); if ($valid) { - $user = Identity::lookup_user_by_name($form->login->inputs["name"]->value); - if (empty($user) || !Identity::is_correct_password($user, $form->login->password->value)) { + $user = identity::lookup_user_by_name($form->login->inputs["name"]->value); + if (empty($user) || !identity::is_correct_password($user, $form->login->password->value)) { log::warning( "user", t("Failed login for %name", @@ -70,12 +70,12 @@ class Login_Controller extends Controller { } if ($valid) { - if (Identity::is_writable()) { + if (identity::is_writable()) { $user->login_count += 1; $user->last_login = time(); $user->save(); } - Session::set_active_user($user); + identity::set_active_user($user); log::info("user", t("User %name logged in", array("name" => $user->name))); } diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 058860fa..1b0364fd 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -19,7 +19,7 @@ */ class Logout_Controller extends Controller { public function index() { - $user = Session::active_user(); + $user = identity::active_user(); if (!$user->guest) { try { Session::instance()->destroy(); diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 58c5b816..99943fbb 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -51,7 +51,7 @@ class Permissions_Controller extends Controller { function change($command, $group_id, $perm_id, $item_id) { access::verify_csrf(); - $group = Identity::lookup_group($group_id); + $group = identity::lookup_group($group_id); $perm = ORM::factory("permission", $perm_id); $item = ORM::factory("item", $item_id); access::required("view", $item); @@ -74,7 +74,7 @@ class Permissions_Controller extends Controller { // If the active user just took away their own edit permissions, give it back. if ($perm->name == "edit") { - if (!access::user_can(Session::active_user(), "edit", $item)) { + if (!access::user_can(identity::active_user(), "edit", $item)) { access::allow($group, $perm->name, $item); } } @@ -84,7 +84,7 @@ class Permissions_Controller extends Controller { private function _get_form($item) { $view = new View("permissions_form.html"); $view->item = $item; - $view->groups = Identity::groups(); + $view->groups = identity::groups(); $view->permissions = ORM::factory("permission")->find_all(); return $view; } diff --git a/modules/gallery/controllers/upgrader.php b/modules/gallery/controllers/upgrader.php index e0c5d340..1aa607ef 100644 --- a/modules/gallery/controllers/upgrader.php +++ b/modules/gallery/controllers/upgrader.php @@ -40,7 +40,7 @@ class Upgrader_Controller extends Controller { } $view = new View("upgrader.html"); - $view->can_upgrade = Session::active_user()->admin || $session->get("can_upgrade"); + $view->can_upgrade = identity::active_user()->admin || $session->get("can_upgrade"); $view->upgrade_token = $upgrade_token; $view->available = module::available(); $view->done = ($available_upgrades == 0); @@ -52,7 +52,7 @@ class Upgrader_Controller extends Controller { // @todo this may screw up some module installers, but we don't have a better answer at // this time. $_SERVER["HTTP_HOST"] = "example.com"; - } else if (!Session::active_user()->admin && !Session::instance()->get("can_upgrade", false)) { + } else if (!identity::active_user()->admin && !Session::instance()->get("can_upgrade", false)) { access::forbidden(); } diff --git a/modules/gallery/controllers/welcome_message.php b/modules/gallery/controllers/welcome_message.php index cfdc3976..af0d6997 100644 --- a/modules/gallery/controllers/welcome_message.php +++ b/modules/gallery/controllers/welcome_message.php @@ -19,12 +19,12 @@ */ class Welcome_Message_Controller extends Controller { public function index() { - if (!Session::active_user()->admin) { + if (!identity::active_user()->admin) { url::redirect(item::root()->abs_url()); } $v = new View("welcome_message.html"); - $v->user = Session::active_user(); + $v->user = identity::active_user(); print $v; } } diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 4e7491e3..a3abbe2e 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -79,7 +79,7 @@ class access_Core { * @return boolean */ static function can($perm_name, $item) { - return self::user_can(Session::active_user(), $perm_name, $item); + return self::user_can(identity::active_user(), $perm_name, $item); } /** @@ -423,7 +423,7 @@ class access_Core { // This is ok at packaging time, so work around it. $config = module::get_var("gallery", "identity_provider"); if (!empty($config)) { - return Identity::groups(); + return identity::groups(); } else { return array(); } diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 18bb2609..84f8a7fb 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -27,7 +27,7 @@ class gallery_Core { static function maintenance_mode() { $maintenance_mode = Kohana::config("core.maintenance_mode", false, false); - if (Router::$controller != "login" && !empty($maintenance_mode) && !Session::active_user()->admin) { + if (Router::$controller != "login" && !empty($maintenance_mode) && !identity::active_user()->admin) { Router::$controller = "maintenance"; Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php"; Router::$method = "index"; diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 95be4813..b6afa2c8 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -23,11 +23,7 @@ class gallery_event_Core { * Initialization. */ static function gallery_ready() { - // Call Identity::instance() now to force the load of the user interface classes. - // Session::load_user will attempt to load the active user from the session and needs - // the user definition class, which can't be reached by Kohana's heiracrchical lookup. - Identity::instance(); - Session::load_user(); + identity::load_user(); locales::set_request_locale(); } @@ -139,7 +135,7 @@ class gallery_event_Core { } } - if (Session::active_user()->admin) { + if (identity::active_user()->admin) { $menu->append($admin_menu = Menu::factory("submenu") ->id("admin_menu") ->label(t("Admin"))); @@ -191,7 +187,7 @@ class gallery_event_Core { ->id("sidebar") ->label(t("Manage Sidebar")) ->url(url::site("admin/sidebar")))); - if (count(Identity::providers()) > 1) { + if (count(identity::providers()) > 1) { $menu ->append(Menu::factory("submenu") ->id("identity_menu") diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 10e796fd..9c19eaed 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -317,7 +317,7 @@ class gallery_installer { } if ($version == 7) { - $groups = Identity::groups(); + $groups = identity::groups(); $permissions = ORM::factory("permission")->find_all(); foreach($groups as $group) { foreach($permissions as $permission) { diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index d21cb124..5f3eb2a9 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -54,7 +54,7 @@ class gallery_theme_Core { static function header_top($theme) { if ($theme->page_type != "login") { $view = new View("login.html"); - $view->user = Session::active_user(); + $view->user = identity::active_user(); return $view->render(); } } diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php new file mode 100644 index 00000000..cf84c8a9 --- /dev/null +++ b/modules/gallery/helpers/identity.php @@ -0,0 +1,225 @@ + $module) { + if (file_exists(MODPATH . "{$module_name}/config/identity.php")) { + $drivers->$module_name = $module->description; + } + } + self::$available = $drivers; + } + return self::$available; + } + + /** + * Make sure that we have a session and group_ids cached in the session. + */ + static function load_user() { + //try { + // Call IdentityProvider::instance() now to force the load of the user interface classes. + // We are about to load the active user from the session and which needs the user definition + // class, which can't be reached by Kohana's heiracrchical lookup. + IdentityProvider::instance(); + + $session = Session::instance(); + if (!($user = $session->get("user"))) { + self::set_active_user($user = self::guest()); + } + + // The installer cannot set a user into the session, so it just sets an id which we should + // upconvert into a user. + // @todo set the user name into the session instead of 2 and then use it to get the user object + if ($user === 2) { + $user = IdentityProvider::instance()->lookup_user_by_name("admin"); + self::set_active_user($user); + $session->set("user", $user); + } + + if (!$session->get("group_ids")) { + $ids = array(); + foreach ($user->groups as $group) { + $ids[] = $group->id; + } + $session->set("group_ids", $ids); + } + //} catch (Exception $e) { + //try { + //Session::instance()->destroy(); + //} catch (Exception $e) { + // We don't care if there was a problem destroying the session. + //} + //url::redirect(item::root()->abs_url()); + //} + } + + /** + * Return the array of group ids this user belongs to + * + * @return array + */ + static function group_ids_for_active_user() { + return Session::instance()->get("group_ids", array(1)); + } + + /** + * Return the active user. If there's no active user, return the guest user. + * + * @return User_Definition + */ + static function active_user() { + // @todo (maybe) cache this object so we're not always doing session lookups. + $user = Session::instance()->get("user", null); + if (!isset($user)) { + // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary + // work. + $user = identity::guest(); + } + return $user; + } + + /** + * Change the active user. + * @param User_Definition $user + */ + static function set_active_user($user) { + $session = Session::instance(); + $session->set("user", $user); + $session->delete("group_ids"); + self::load_user(); + } + + /** + * Determine if if the current driver supports updates. + * + * @return boolean true if the driver supports updates; false if read only + */ + static function is_writable() { + return IdentityProvider::instance()->is_writable(); + } + + /** + * @see IdentityProvider_Driver::activate. + */ + static function activate() { + IdentityProvider::instance()->activate(); + } + + /** + * @see IdentityProvider_Driver::deactivate. + */ + static function deactivate() { + IdentityProvider::instance()->deactivate(); + } + + /** + * @see IdentityProvider_Driver::guest. + */ + static function guest() { + return IdentityProvider::instance()->guest(); + } + + /** + * @see IdentityProvider_Driver::create_user. + */ + static function create_user($name, $full_name, $password) { + return IdentityProvider::instance()->create_user($name, $full_name, $password); + } + + /** + * @see IdentityProvider_Driver::is_correct_password. + */ + static function is_correct_password($user, $password) { + return IdentityProvider::instance()->is_correct_password($user, $password); + } + + /** + * @see IdentityProvider_Driver::lookup_user. + */ + static function lookup_user($id) { + return IdentityProvider::instance()->lookup_user($id); + } + + /** + * @see IdentityProvider_Driver::lookup_user_by_name. + */ + static function lookup_user_by_name($name) { + return IdentityProvider::instance()->lookup_user_by_name($name); + } + + /** + * @see IdentityProvider_Driver::create_group. + */ + static function create_group($name) { + return IdentityProvider::instance()->create_group($name); + } + + /** + * @see IdentityProvider_Driver::everybody. + */ + static function everybody() { + return IdentityProvider::instance()->everybody(); + } + + /** + * @see IdentityProvider_Driver::registered_users. + */ + static function registered_users() { + return IdentityProvider::instance()->everybody(); + } + + /** + * @see IdentityProvider_Driver::lookup_group. + */ + static function lookup_group($id) { + return IdentityProvider::instance()->lookup_group($id); + } + + /** + * @see IdentityProvider_Driver::lookup_group_by_name. + */ + static function lookup_group_by_name($name) { + return IdentityProvider::instance()->lookup_group_by_name($name); + } + + /** + * @see IdentityProvider_Driver::get_user_list. + */ + static function get_user_list($ids) { + return IdentityProvider::instance()->get_user_list($ids); + } + + /** + * @see IdentityProvider_Driver::groups. + */ + static function groups() { + return IdentityProvider::instance()->groups(); + } +} \ No newline at end of file diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 3d36a324..b3b6d0bb 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -158,8 +158,8 @@ class item_Core { */ static function viewable($model) { $view_restrictions = array(); - if (!Session::active_user()->admin) { - foreach (Session::group_ids_for_active_user() as $id) { + if (!identity::active_user()->admin) { + foreach (identity::group_ids_for_active_user() as $id) { // Separate the first restriction from the rest to make it easier for us to formulate // our where clause below if (empty($view_restrictions)) { diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php index f80fce03..c2a606cd 100644 --- a/modules/gallery/helpers/locales.php +++ b/modules/gallery/helpers/locales.php @@ -141,7 +141,7 @@ class locales_Core { $locale = self::cookie_locale(); // 2. Check the user's preference if (!$locale) { - $locale = Session::active_user()->locale; + $locale = identity::active_user()->locale; } // 3. Check the browser's / OS' preference if (!$locale) { diff --git a/modules/gallery/helpers/log.php b/modules/gallery/helpers/log.php index d1b34e3a..184b0b97 100644 --- a/modules/gallery/helpers/log.php +++ b/modules/gallery/helpers/log.php @@ -80,7 +80,7 @@ class log_Core { $log->url = substr(url::abs_current(true), 0, 255); $log->referer = request::referrer(null); $log->timestamp = time(); - $log->user_id = Session::active_user()->id; + $log->user_id = identity::active_user()->id; $log->save(); } diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 9541f20e..6dac0803 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -77,7 +77,7 @@ class movie_Core { $movie->title = $title; $movie->description = $description; $movie->name = $name; - $movie->owner_id = $owner_id ? $owner_id : Session::active_user()->id; + $movie->owner_id = $owner_id ? $owner_id : identity::active_user()->id; $movie->width = $movie_info[0]; $movie->height = $movie_info[1]; $movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv"; diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 193293e8..01cf5278 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -76,7 +76,7 @@ class photo_Core { $photo->title = $title; $photo->description = $description; $photo->name = $name; - $photo->owner_id = $owner_id ? $owner_id : Session::active_user()->id; + $photo->owner_id = $owner_id ? $owner_id : identity::active_user()->id; $photo->width = $image_info[0]; $photo->height = $image_info[1]; $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index 06b29fda..2b090776 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -95,7 +95,7 @@ class site_status_Core { * @return html text */ static function get() { - if (!Session::active_user()->admin) { + if (!identity::active_user()->admin) { return; } $buf = array(); diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index f84fd10e..dac5f9d3 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -42,7 +42,7 @@ class task_Core { $task->percent_complete = 0; $task->status = ""; $task->state = "started"; - $task->owner_id = Session::active_user()->id; + $task->owner_id = identity::active_user()->id; $task->context = serialize($context); $task->save(); diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 74a08c77..6eedec0d 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -36,12 +36,12 @@ class Admin_View_Core extends Gallery_View { parent::__construct($name); $this->theme_name = module::get_var("gallery", "active_admin_theme"); - if (Session::active_user()->admin) { + if (identity::active_user()->admin) { $this->theme_name = Input::instance()->get("theme", $this->theme_name); } $this->sidebar = ""; $this->set_global("theme", $this); - $this->set_global("user", Session::active_user()); + $this->set_global("user", identity::active_user()); } public function admin_menu() { diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php deleted file mode 100644 index 1dd5d23b..00000000 --- a/modules/gallery/libraries/Identity.php +++ /dev/null @@ -1,222 +0,0 @@ -config = Kohana::config("identity.".$config)) === NULL) { - throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $config"); - } - - // Set driver name - $driver = "Identity_".ucfirst($this->config["driver"])."_Driver"; - - // Load the driver - if ( ! Kohana::auto_load($driver)) { - throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], - get_class($this)); - } - - // Initialize the driver - $this->driver = new $driver($this->config["params"]); - - // Validate the driver - if ( !($this->driver instanceof Identity_Driver)) { - throw new Kohana_Exception("core.driver_implements", $this->config["driver"], - get_class($this), "Identity_Driver"); - } - - Kohana::log("debug", "Identity Library initialized"); - } - - /** - * Return a list of installed Identity Drivers. - * - * @return boolean true if the driver supports updates; false if read only - */ - static function providers() { - if (empty(self::$active)) { - $drivers = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (module::active() as $module) { - $module_name = $module->name; - if (file_exists(MODPATH . "{$module->name}/config/identity.php") && - ($info = module::info($module_name))) { - $drivers->$module_name = $info->description; - } - } - self::$active = $drivers; - } - return self::$active; - } - - /** - * @see Identity_Driver::activate. - */ - static function activate() { - self::instance()->driver->activate(); - } - - /** - * @see Identity_Driver::deactivate. - */ - static function deactivate() { - self::instance()->driver->deactivate(); - } - - /** - * Determine if if the current driver supports updates. - * - * @return boolean true if the driver supports updates; false if read only - */ - static function is_writable() { - return !empty(self::instance()->config["allow_updates"]); - } - - /** - * @see Identity_Driver::guest. - */ - static function guest() { - return self::instance()->driver->guest(); - } - - /** - * @see Identity_Driver::create_user. - */ - static function create_user($name, $full_name, $password) { - return self::instance()->driver->create_user($name, $full_name, $password); - } - - /** - * @see Identity_Driver::is_correct_password. - */ - static function is_correct_password($user, $password) { - return self::instance()->driver->is_correct_password($user, $password); - } - - /** - * @see Identity_Driver::lookup_user. - */ - static function lookup_user($id) { - return self::instance()->driver->lookup_user($id); - } - - /** - * @see Identity_Driver::lookup_user_by_name. - */ - static function lookup_user_by_name($name) { - return self::instance()->driver->lookup_user_by_name($name); - } - - /** - * @see Identity_Driver::create_group. - */ - static function create_group($name) { - return self::instance()->driver->create_group($name); - } - - /** - * @see Identity_Driver::everybody. - */ - static function everybody() { - return self::instance()->driver->everybody(); - } - - /** - * @see Identity_Driver::registered_users. - */ - static function registered_users() { - return self::instance()->driver->everybody(); - } - - /** - * @see Identity_Driver::lookup_group. - */ - static function lookup_group($id) { - return self::instance()->driver->lookup_group($id); - } - - /** - * @see Identity_Driver::lookup_group_by_name. - */ - static function lookup_group_by_name($name) { - return self::instance()->driver->lookup_group_by_name($name); - } - - /** - * @see Identity_Driver::get_user_list. - */ - static function get_user_list($ids) { - return self::instance()->driver->get_user_list($ids); - } - - /** - * @see Identity_Driver::groups. - */ - static function groups() { - return self::instance()->driver->groups(); - } -} // End Identity diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php new file mode 100644 index 00000000..512f28eb --- /dev/null +++ b/modules/gallery/libraries/IdentityProvider.php @@ -0,0 +1,200 @@ +config = Kohana::config("identity.".$config)) === NULL) { + throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $config"); + } + + // Set driver name + $driver = "IdentityProvider_".ucfirst($this->config["driver"])."_Driver"; + + // Load the driver + if ( ! Kohana::auto_load($driver)) { + throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], + get_class($this)); + } + + // Initialize the driver + $this->driver = new $driver($this->config["params"]); + + // Validate the driver + if ( !($this->driver instanceof IdentityProvider_Driver)) { + throw new Kohana_Exception("core.driver_implements", $this->config["driver"], + get_class($this), "IdentityProvider_Driver"); + } + + Kohana::log("debug", "Identity Library initialized"); + } + + /** + * Determine if if the current driver supports updates. + * + * @return boolean true if the driver supports updates; false if read only + */ + public function is_writable() { + return !empty($this->config["allow_updates"]); + } + + /** + * @see IdentityProvider_Driver::activate. + */ + public function activate() { + $this->driver->activate(); + } + + /** + * @see IdentityProvider_Driver::deactivate. + */ + public function deactivate() { + $this->driver->deactivate(); + } + + /** + * @see IdentityProvider_Driver::guest. + */ + public function guest() { + return $this->driver->guest(); + } + + /** + * @see IdentityProvider_Driver::create_user. + */ + public function create_user($name, $full_name, $password) { + return $this->driver->create_user($name, $full_name, $password); + } + + /** + * @see IdentityProvider_Driver::is_correct_password. + */ + public function is_correct_password($user, $password) { + return $this->driver->is_correct_password($user, $password); + } + + /** + * @see IdentityProvider_Driver::lookup_user. + */ + public function lookup_user($id) { + return $this->driver->lookup_user($id); + } + + /** + * @see IdentityProvider_Driver::lookup_user_by_name. + */ + public function lookup_user_by_name($name) { + return $this->driver->lookup_user_by_name($name); + } + + /** + * @see IdentityProvider_Driver::create_group. + */ + public function create_group($name) { + return $this->driver->create_group($name); + } + + /** + * @see IdentityProvider_Driver::everybody. + */ + public function everybody() { + return $this->driver->everybody(); + } + + /** + * @see IdentityProvider_Driver::registered_users. + */ + public function registered_users() { + return $this->driver->everybody(); + } + + /** + * @see IdentityProvider_Driver::lookup_group. + */ + public function lookup_group($id) { + return $this->driver->lookup_group($id); + } + + /** + * @see IdentityProvider_Driver::lookup_group_by_name. + */ + public function lookup_group_by_name($name) { + return $this->driver->lookup_group_by_name($name); + } + + /** + * @see IdentityProvider_Driver::get_user_list. + */ + public function get_user_list($ids) { + return $this->driver->get_user_list($ids); + } + + /** + * @see IdentityProvider_Driver::groups. + */ + public function groups() { + return $this->driver->groups(); + } +} // End Identity diff --git a/modules/gallery/libraries/MY_Session.php b/modules/gallery/libraries/MY_Session.php deleted file mode 100644 index 1a3ae801..00000000 --- a/modules/gallery/libraries/MY_Session.php +++ /dev/null @@ -1,93 +0,0 @@ -get("user"))) { - $session->set("user", $user = Identity::guest()); - } - - // The installer cannot set a user into the session, so it just sets an id which we should - // upconvert into a user. - // @todo set the user name into the session instead of 2 and then use it to get the user object - if ($user === 2) { - $user = Instance::lookup_user_by_name("admin"); - self::set_active_user($user); - $session->set("user", $user); - } - - if (!$session->get("group_ids")) { - $ids = array(); - foreach ($user->groups as $group) { - $ids[] = $group->id; - } - $session->set("group_ids", $ids); - } - } catch (Exception $e) { - try { - Session::instance()->destroy(); - } catch (Exception $e) { - // We don't care if there was a problem destroying the session. - } - url::redirect(item::root()->abs_url()); - } - } - - /** - * Return the array of group ids this user belongs to - * - * @return array - */ - static function group_ids_for_active_user() { - return self::instance()->get("group_ids", array(1)); - } - - /** - * Return the active user. If there's no active user, return the guest user. - * - * @return User_Definition - */ - static function active_user() { - // @todo (maybe) cache this object so we're not always doing session lookups. - $user = self::instance()->get("user", null); - if (!isset($user)) { - // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary - // work. - $user = Identity::guest(); - } - return $user; - } - - /** - * Change the active user. - * @param User_Definition $user - */ - static function set_active_user($user) { - $session = Session::instance(); - $session->set("user", $user); - $session->delete("group_ids"); - self::load_user(); - } -} \ No newline at end of file diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 2fdc7531..68ec325f 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -37,13 +37,13 @@ class Theme_View_Core extends Gallery_View { parent::__construct($name); $this->theme_name = module::get_var("gallery", "active_site_theme"); - if (Session::active_user()->admin) { + if (identity::active_user()->admin) { $this->theme_name = Input::instance()->get("theme", $this->theme_name); } $this->item = null; $this->tag = null; $this->set_global("theme", $this); - $this->set_global("user", Session::active_user()); + $this->set_global("user", identity::active_user()); $this->set_global("page_type", $page_type); $this->set_global("page_title", null); if ($page_type == "album") { @@ -158,7 +158,7 @@ class Theme_View_Core extends Gallery_View { */ public function sidebar_blocks() { $sidebar = block_manager::get_html("site.sidebar", $this); - if (empty($sidebar) && Session::active_user()->admin) { + if (empty($sidebar) && identity::active_user()->admin) { $sidebar = new View("no_sidebar.html"); } return $sidebar; diff --git a/modules/gallery/libraries/drivers/Identity.php b/modules/gallery/libraries/drivers/Identity.php deleted file mode 100644 index 39b2a9c7..00000000 --- a/modules/gallery/libraries/drivers/Identity.php +++ /dev/null @@ -1,123 +0,0 @@ -owner_id); + return identity::lookup_user($this->owner_id); } catch (Exception $e) { return null; } diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php index 1d639857..4f6b8c4b 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -26,7 +26,7 @@ class Log_Model extends ORM { // This relationship depends on an outside module, which may not be present so handle // failures gracefully. try { - return Identity::lookup_user($this->user_id); + return identity::lookup_user($this->user_id); } catch (Exception $e) { return null; } diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 548e5f9c..f40be492 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -46,7 +46,7 @@ class Task_Model extends ORM { } public function owner() { - return Identity::lookup_user($this->owner_id); + return identity::lookup_user($this->owner_id); } /** diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index dac431a7..e9e5cb26 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -22,7 +22,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function teardown() { try { - $group = Identity::lookup_group_by_name("access_test"); + $group = identity::lookup_group_by_name("access_test"); if (!empty($group)) { $group->delete(); } @@ -33,7 +33,7 @@ class Access_Helper_Test extends Unit_Test_Case { } catch (Exception $e) { } try { - $user = Identity::lookup_user_by_name("access_test"); + $user = identity::lookup_user_by_name("access_test"); if (!empty($user)) { $user->delete(); } @@ -41,16 +41,16 @@ class Access_Helper_Test extends Unit_Test_Case { // Reset some permissions that we mangle below $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", $root); } public function setup() { - Session::set_active_user(Identity::guest()); + identity::set_active_user(identity::guest()); } public function groups_and_permissions_are_bound_to_columns_test() { access::register_permission("access_test", "Access Test"); - $group = Identity::create_group("access_test"); + $group = identity::create_group("access_test"); // We have a new column for this perm / group combo $fields = Database::instance()->list_fields("access_caches"); @@ -65,17 +65,17 @@ class Access_Helper_Test extends Unit_Test_Case { } public function user_can_access_test() { - $access_test = Identity::create_group("access_test"); + $access_test = identity::create_group("access_test"); $root = ORM::factory("item", 1); access::allow($access_test, "view", $root); $item = album::create($root, rand(), "test album"); - access::deny(Identity::everybody(), "view", $item); - access::deny(Identity::registered_users(), "view", $item); + access::deny(identity::everybody(), "view", $item); + access::deny(identity::registered_users(), "view", $item); - $user = Identity::create_user("access_test", "Access Test", ""); + $user = identity::create_user("access_test", "Access Test", ""); foreach ($user->groups as $group) { $user->remove($group); } @@ -89,10 +89,10 @@ class Access_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $item = album::create($root, rand(), "test album"); - access::deny(Identity::everybody(), "view", $item); - access::deny(Identity::registered_users(), "view", $item); + access::deny(identity::everybody(), "view", $item); + access::deny(identity::registered_users(), "view", $item); - $user = Identity::create_user("access_test", "Access Test", ""); + $user = identity::create_user("access_test", "Access Test", ""); foreach ($user->groups as $group) { $user->remove($group); } @@ -121,11 +121,11 @@ class Access_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", ""); - $this->assert_true($photo->__get("view_" . Identity::everybody()->id)); + $this->assert_true($photo->__get("view_" . identity::everybody()->id)); } public function can_allow_deny_and_reset_intent_test() { @@ -134,23 +134,23 @@ class Access_Helper_Test extends Unit_Test_Case { $intent = ORM::factory("access_intent")->where("item_id", $album)->find(); // Allow - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_same(access::ALLOW, $intent->reload()->view_1); // Deny - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_same( access::DENY, ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); // Allow again. If the initial value was allow, then the first Allow clause above may not // have actually changed any values. - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_same( access::ALLOW, ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); - access::reset(Identity::everybody(), "view", $album); + access::reset(identity::everybody(), "view", $album); $this->assert_same( null, ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); @@ -158,7 +158,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function cant_reset_root_item_test() { try { - access::reset(Identity::everybody(), "view", ORM::factory("item", 1)); + access::reset(identity::everybody(), "view", ORM::factory("item", 1)); } catch (Exception $e) { return; } @@ -167,17 +167,17 @@ class Access_Helper_Test extends Unit_Test_Case { public function can_view_item_test() { $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "view", $root); - $this->assert_true(access::group_can(Identity::everybody(), "view", $root)); + access::allow(identity::everybody(), "view", $root); + $this->assert_true(access::group_can(identity::everybody(), "view", $root)); } public function can_always_fails_on_unloaded_items_test() { $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "view", $root); - $this->assert_true(access::group_can(Identity::everybody(), "view", $root)); + access::allow(identity::everybody(), "view", $root); + $this->assert_true(access::group_can(identity::everybody(), "view", $root)); $bogus = ORM::factory("item", -1); - $this->assert_false(access::group_can(Identity::everybody(), "view", $bogus)); + $this->assert_false(access::group_can(identity::everybody(), "view", $bogus)); } public function cant_view_child_of_hidden_parent_test() { @@ -185,21 +185,21 @@ class Access_Helper_Test extends Unit_Test_Case { $album = album::create($root, rand(), "test album"); $root->reload(); - access::deny(Identity::everybody(), "view", $root); - access::reset(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $root); + access::reset(identity::everybody(), "view", $album); $album->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album)); } public function view_permissions_propagate_down_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - access::allow(Identity::everybody(), "view", $root); - access::reset(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $root); + access::reset(identity::everybody(), "view", $album); $album->reload(); - $this->assert_true(access::group_can(Identity::everybody(), "view", $album)); + $this->assert_true(access::group_can(identity::everybody(), "view", $album)); } public function can_toggle_view_permissions_propagate_down_test() { @@ -214,18 +214,18 @@ class Access_Helper_Test extends Unit_Test_Case { $album3->reload(); $album4->reload(); - access::allow(Identity::everybody(), "view", $root); - access::deny(Identity::everybody(), "view", $album1); - access::reset(Identity::everybody(), "view", $album2); - access::reset(Identity::everybody(), "view", $album3); - access::reset(Identity::everybody(), "view", $album4); + access::allow(identity::everybody(), "view", $root); + access::deny(identity::everybody(), "view", $album1); + access::reset(identity::everybody(), "view", $album2); + access::reset(identity::everybody(), "view", $album3); + access::reset(identity::everybody(), "view", $album4); $album4->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album4)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album4)); - access::allow(Identity::everybody(), "view", $album1); + access::allow(identity::everybody(), "view", $album1); $album4->reload(); - $this->assert_true(access::group_can(Identity::everybody(), "view", $album4)); + $this->assert_true(access::group_can(identity::everybody(), "view", $album4)); } public function revoked_view_permissions_cant_be_allowed_lower_down_test() { @@ -234,29 +234,29 @@ class Access_Helper_Test extends Unit_Test_Case { $album2 = album::create($album1, rand(), "test album"); $root->reload(); - access::deny(Identity::everybody(), "view", $root); - access::allow(Identity::everybody(), "view", $album2); + access::deny(identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", $album2); $album1->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album1)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album1)); $album2->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album2)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album2)); } public function can_edit_item_test() { $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "edit", $root); - $this->assert_true(access::group_can(Identity::everybody(), "edit", $root)); + access::allow(identity::everybody(), "edit", $root); + $this->assert_true(access::group_can(identity::everybody(), "edit", $root)); } public function non_view_permissions_propagate_down_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - access::allow(Identity::everybody(), "edit", $root); - access::reset(Identity::everybody(), "edit", $album); - $this->assert_true(access::group_can(Identity::everybody(), "edit", $album)); + access::allow(identity::everybody(), "edit", $root); + access::reset(identity::everybody(), "edit", $album); + $this->assert_true(access::group_can(identity::everybody(), "edit", $album)); } public function non_view_permissions_can_be_revoked_lower_down_test() { @@ -276,36 +276,36 @@ class Access_Helper_Test extends Unit_Test_Case { $outer->reload(); $inner->reload(); - access::allow(Identity::everybody(), "edit", $root); - access::deny(Identity::everybody(), "edit", $outer); - access::allow(Identity::everybody(), "edit", $inner); + access::allow(identity::everybody(), "edit", $root); + access::deny(identity::everybody(), "edit", $outer); + access::allow(identity::everybody(), "edit", $inner); // Outer album is not editable, inner one is. - $this->assert_false(access::group_can(Identity::everybody(), "edit", $outer_photo)); - $this->assert_true(access::group_can(Identity::everybody(), "edit", $inner_photo)); + $this->assert_false(access::group_can(identity::everybody(), "edit", $outer_photo)); + $this->assert_true(access::group_can(identity::everybody(), "edit", $inner_photo)); } public function i_can_edit_test() { // Create a new user that belongs to no groups - $user = Identity::create_user("access_test", "Access Test", ""); + $user = identity::create_user("access_test", "Access Test", ""); foreach ($user->groups as $group) { $user->remove($group); } $user->save(); - Session::set_active_user($user); + identity::set_active_user($user); // This user can't edit anything $root = ORM::factory("item", 1); $this->assert_false(access::can("edit", $root)); // Now add them to a group that has edit permission - $group = Identity::create_group("access_test"); + $group = identity::create_group("access_test"); $group->add($user); $group->save(); access::allow($group, "edit", $root); - $user = Identity::lookup_user($user->id); // reload() does not flush related columns - Session::set_active_user($user); + $user = identity::lookup_user($user->id); // reload() does not flush related columns + identity::set_active_user($user); // And verify that the user can edit. $this->assert_true(access::can("edit", $root)); @@ -317,16 +317,16 @@ class Access_Helper_Test extends Unit_Test_Case { $this->assert_false(file_exists($album->file_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); - access::reset(Identity::everybody(), "view", $album); + access::reset(identity::everybody(), "view", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); } @@ -338,44 +338,44 @@ class Access_Helper_Test extends Unit_Test_Case { $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view_full", $album); + access::deny(identity::everybody(), "view_full", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::allow(Identity::everybody(), "view_full", $album); + access::allow(identity::everybody(), "view_full", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view_full", $album); + access::deny(identity::everybody(), "view_full", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::reset(Identity::everybody(), "view_full", $album); + access::reset(identity::everybody(), "view_full", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); } public function moved_items_inherit_new_permissions_test() { - Session::set_active_user(Identity::lookup_user_by_name("admin")); + identity::set_active_user(identity::lookup_user_by_name("admin")); $root = ORM::factory("item", 1); $public_album = album::create($root, rand(), "public album"); $public_photo = photo::create($public_album, MODPATH . "gallery/images/gallery.png", "", ""); - access::allow(Identity::everybody(), "view", $public_album); + access::allow(identity::everybody(), "view", $public_album); $root->reload(); // Account for MPTT changes $private_album = album::create($root, rand(), "private album"); - access::deny(Identity::everybody(), "view", $private_album); + access::deny(identity::everybody(), "view", $private_album); $private_photo = photo::create($private_album, MODPATH . "gallery/images/gallery.png", "", ""); // Make sure that we now have a public photo and private photo. - $this->assert_true(access::group_can(Identity::everybody(), "view", $public_photo)); - $this->assert_false(access::group_can(Identity::everybody(), "view", $private_photo)); + $this->assert_true(access::group_can(identity::everybody(), "view", $public_photo)); + $this->assert_false(access::group_can(identity::everybody(), "view", $private_photo)); // Swap the photos item::move($public_photo, $private_album); @@ -391,7 +391,7 @@ class Access_Helper_Test extends Unit_Test_Case { $public_photo->reload(); // Make sure that the public_photo is now private, and the private_photo is now public. - $this->assert_false(access::group_can(Identity::everybody(), "view", $public_photo)); - $this->assert_true(access::group_can(Identity::everybody(), "view", $private_photo)); + $this->assert_false(access::group_can(identity::everybody(), "view", $public_photo)); + $this->assert_true(access::group_can(identity::everybody(), "view", $private_photo)); } } diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php index fa46d924..b85b5258 100644 --- a/modules/gallery/tests/Albums_Controller_Test.php +++ b/modules/gallery/tests/Albums_Controller_Test.php @@ -45,7 +45,7 @@ class Albums_Controller_Test extends Unit_Test_Case { $_POST["csrf"] = access::csrf_token(); $_POST["slug"] = "new_name"; $_POST["_method"] = "put"; - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); ob_start(); $controller->_update($this->_album); @@ -69,7 +69,7 @@ class Albums_Controller_Test extends Unit_Test_Case { $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); try { $controller->_update($this->_album); diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index fc01db91..a364423a 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -23,16 +23,16 @@ class Item_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $album = album::create($root, rand(), rand(), rand()); $item = self::_create_random_item($album); - Session::set_active_user(Identity::guest()); + identity::set_active_user(identity::guest()); // We can see the item when permissions are granted - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_equal( 1, ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); // We can't see the item when permissions are denied - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index 59c3f78a..2e5d7fe3 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -31,7 +31,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $photo = photo::create( $root, MODPATH . "gallery/tests/test.jpg", "test.jpeg", - "test", "test", Session::active_user()->id, "slug"); + "test", "test", identity::active_user()->id, "slug"); $orig_name = $photo->name; $_POST["filename"] = "test.jpeg"; @@ -40,7 +40,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $_POST["description"] = "new description"; $_POST["slug"] = "new-slug"; $_POST["csrf"] = access::csrf_token(); - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); ob_start(); $controller->_update($photo); @@ -64,7 +64,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); try { $controller->_update($photo); diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php index 0256fabb..0d8801e5 100644 --- a/modules/gallery/views/kohana_error_page.php +++ b/modules/gallery/views/kohana_error_page.php @@ -57,7 +57,7 @@ <?= t("Something went wrong!") ?> - + admin ?>

diff --git a/modules/gallery/views/login.html.php b/modules/gallery/views/login.html.php index 6695d564..961f44fa 100644 --- a/modules/gallery/views/login.html.php +++ b/modules/gallery/views/login.html.php @@ -8,7 +8,7 @@
  • - + html::mark_clean( 'id}") . '" title="' . t("Edit Your Profile")->for_html_attr() . diff --git a/modules/gallery/views/login_ajax.html.php b/modules/gallery/views/login_ajax.html.php index 6ed40571..a9a9ef11 100644 --- a/modules/gallery/views/login_ajax.html.php +++ b/modules/gallery/views/login_ajax.html.php @@ -36,7 +36,7 @@
  • - +
  • diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 080f154b..9a40b0b9 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -20,7 +20,7 @@ class notification { static function get_subscription($item_id, $user=null) { if (empty($user)) { - $user = Session::active_user(); + $user = identity::active_user(); } return ORM::factory("subscription") @@ -31,7 +31,7 @@ class notification { static function is_watching($item, $user=null) { if (empty($user)) { - $user = Session::active_user(); + $user = identity::active_user(); } return ORM::factory("subscription") @@ -44,7 +44,7 @@ class notification { static function add_watch($item, $user=null) { if ($item->is_album()) { if (empty($user)) { - $user = Session::active_user(); + $user = identity::active_user(); } $subscription = ORM::factory("subscription"); $subscription->item_id = $item->id; @@ -56,7 +56,7 @@ class notification { static function remove_watch($item, $user=null) { if ($item->is_album()) { if (empty($user)) { - $user = Session::active_user(); + $user = identity::active_user(); } $subscription = ORM::factory("subscription") @@ -81,7 +81,7 @@ class notification { if (empty($subscriber_ids)) { return array(); } - $users = Identity::get_user_list($subscriber_ids); + $users = identity::get_user_list($subscriber_ids); $subscribers = array(); foreach ($users as $user) { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index f0530cd9..3a369155 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -95,7 +95,7 @@ class notification_event_Core { } static function site_menu($menu, $theme) { - if (!Session::active_user()->guest) { + if (!identity::active_user()->guest) { $item = $theme->item(); if ($item && $item->is_album() && access::can("view", $item)) { diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 8b14cfa9..f9da9a16 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -22,8 +22,8 @@ class search_Core { $db = Database::instance(); $q = $db->escape_str($q); - if (!Session::active_user()->admin) { - foreach (Session::group_ids_for_active_user() as $id) { + if (!identity::active_user()->admin) { + foreach (identity::group_ids_for_active_user() as $id) { $fields[] = "`view_$id` = TRUE"; // access::ALLOW } $access_sql = "AND (" . join(" AND ", $fields) . ")"; diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 428065f6..53a3d091 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -103,7 +103,7 @@ class Server_Add_Controller extends Admin_Controller { access::verify_csrf(); $task = ORM::factory("task", $task_id); - if (!$task->loaded || $task->owner_id != Session::active_user()->id) { + if (!$task->loaded || $task->owner_id != identity::active_user()->id) { access::forbidden(); } @@ -207,7 +207,7 @@ class Server_Add_Controller extends Admin_Controller { $task->set("mode", "done"); } - $owner_id = Session::active_user()->id; + $owner_id = identity::active_user()->id; foreach ($entries as $entry) { if (microtime(true) - $start > 0.5) { break; diff --git a/modules/server_add/helpers/server_add_event.php b/modules/server_add/helpers/server_add_event.php index 8f8b0016..1d883a71 100644 --- a/modules/server_add/helpers/server_add_event.php +++ b/modules/server_add/helpers/server_add_event.php @@ -30,7 +30,7 @@ class server_add_event_Core { $item = $theme->item(); $paths = unserialize(module::get_var("server_add", "authorized_paths")); - if ($item && Session::active_user()->admin && $item->is_album() && !empty($paths) && + if ($item && identity::active_user()->admin && $item->is_album() && !empty($paths) && is_writable($item->is_album() ? $item->file_path() : $item->parent()->file_path())) { $menu->get("add_menu") ->append(Menu::factory("dialog") diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index 44681d36..9da8969a 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -19,7 +19,7 @@ */ class server_add_theme_Core { static function head($theme) { - if (Session::active_user()->admin) { + if (identity::active_user()->admin) { $theme->script("server_add.js"); } } diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 258de843..8b96ebd2 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -69,7 +69,7 @@ class Admin_Users_Controller extends Admin_Controller { public function delete_user($id) { access::verify_csrf(); - if ($id == Session::active_user()->id || $id == user::guest()->id) { + if ($id == identity::active_user()->id || $id == user::guest()->id) { access::forbidden(); } @@ -136,7 +136,7 @@ class Admin_Users_Controller extends Admin_Controller { } // An admin can change the admin status for any user but themselves - if ($user->id != Session::active_user()->id) { + if ($user->id != identity::active_user()->id) { $user->admin = $form->edit_user->admin->checked; } $user->save(); @@ -158,7 +158,7 @@ class Admin_Users_Controller extends Admin_Controller { $form = $this->_get_user_edit_form_admin($user); // Don't allow the user to control their own admin bit, else you can lock yourself out - if ($user->id == Session::active_user()->id) { + if ($user->id == identity::active_user()->id) { $form->edit_user->admin->disabled(1); } print $form; diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index a8f1c5ca..6bef1a17 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -46,7 +46,7 @@ class Password_Controller extends Controller { $valid = $form->validate(); if ($valid) { - $user = Identity::lookup_user_by_name($form->reset->inputs["name"]->value); + $user = identity::lookup_user_by_name($form->reset->inputs["name"]->value); if (!$user->loaded || empty($user->email)) { $form->reset->inputs["name"]->add_error("no_email", 1); $valid = false; diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index 0ccf3e2a..dee54f63 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -21,7 +21,7 @@ class Users_Controller extends Controller { public function update($id) { $user = user::lookup($id); - if ($user->guest || $user->id != Session::active_user()->id) { + if ($user->guest || $user->id != identity::active_user()->id) { access::forbidden(); } @@ -59,7 +59,7 @@ class Users_Controller extends Controller { public function form_edit($id) { $user = user::lookup($id); - if ($user->guest || $user->id != Session::active_user()->id) { + if ($user->guest || $user->id != identity::active_user()->id) { access::forbidden(); } diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 8ad52564..567b2ee4 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -25,7 +25,10 @@ */ class group_Core { /** - * @see Identity_Driver::create. + * Create a new group. + * + * @param string $name + * @return Group_Definition the group object */ static function create($name) { $group = ORM::factory("group")->where("name", $name)->find(); @@ -39,14 +42,18 @@ class group_Core { } /** - * @see Identity_Driver::everbody. + * The group of all possible visitors. This includes the guest user. + * + * @return Group_Definition the group object */ static function everybody() { return model_cache::get("group", 1); } /** - * @see Identity_Driver::registered_users. + * The group of all logged-in visitors. This does not include guest users. + * + * @return Group_Definition the group object */ static function registered_users() { return model_cache::get("group", 2); @@ -71,7 +78,10 @@ class group_Core { } /** - * @see Identity_Driver::get_group_list. + * Search the groups by the field and value. + * @param string $field_name column to look up the user by + * @param string $value value to match + * @return Group_Definition the group object, or null if the name was invalid. */ static function lookup_by_field($field_name, $value) { try { diff --git a/modules/user/libraries/drivers/Identity/Gallery.php b/modules/user/libraries/drivers/Identity/Gallery.php deleted file mode 100644 index 36f37543..00000000 --- a/modules/user/libraries/drivers/Identity/Gallery.php +++ /dev/null @@ -1,150 +0,0 @@ -password; - - // Try phpass first, since that's what we generate. - if (strlen($valid) == 34) { - require_once(MODPATH . "user/lib/PasswordHash.php"); - $hashGenerator = new PasswordHash(10, true); - return $hashGenerator->CheckPassword($password, $valid); - } - - $salt = substr($valid, 0, 4); - // Support both old (G1 thru 1.4.0; G2 thru alpha-4) and new password schemes: - $guess = (strlen($valid) == 32) ? md5($password) : ($salt . md5($salt . $password)); - if (!strcmp($guess, $valid)) { - return true; - } - - // Passwords with <&"> created by G2 prior to 2.1 were hashed with entities - $sanitizedPassword = html::specialchars($password, false); - $guess = (strlen($valid) == 32) ? md5($sanitizedPassword) - : ($salt . md5($salt . $sanitizedPassword)); - if (!strcmp($guess, $valid)) { - return true; - } - - return false; - } - - /** - * @see Identity_Driver::lookup_user. - */ - public function lookup_user($id) { - return user::lookup_by_field("id", $id); - } - - /** - * @see Identity_Driver::lookup_user_by_name. - */ - public function lookup_user_by_name($name) { - return user::lookup_by_field("name", $name); - } - - /** - * @see Identity_Driver::create_group. - */ - public function create_group($name) { - return group::create($name); - } - - /** - * @see Identity_Driver::everybody. - */ - public function everybody() { - return group::everybody(); - } - - /** - * @see Identity_Driver::registered_users. - */ - public function registered_users() { - return group::registered_users(); - } - - /** - * @see Identity_Driver::lookup_group. - */ - public function lookup_group($id) { - return group::lookup_by_field("id", $id); - } - - /** - * @see Identity_Driver::lookup_group_by_name. - */ - public function lookup_group_by_name($name) { - return group::lookup_by_field("name", $name); - } - - /** - * @see Identity_Driver::get_user_list. - */ - public function get_user_list($ids) { - return ORM::factory("user") - ->in("id", $ids) - ->find_all() - ->as_array(); - } - - /** - * @see Identity_Driver::groups. - */ - public function groups() { - return ORM::factory("group")->find_all(); - } - -} // End Identity Gallery Driver - diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php new file mode 100644 index 00000000..5941abb7 --- /dev/null +++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php @@ -0,0 +1,150 @@ +password; + + // Try phpass first, since that's what we generate. + if (strlen($valid) == 34) { + require_once(MODPATH . "user/lib/PasswordHash.php"); + $hashGenerator = new PasswordHash(10, true); + return $hashGenerator->CheckPassword($password, $valid); + } + + $salt = substr($valid, 0, 4); + // Support both old (G1 thru 1.4.0; G2 thru alpha-4) and new password schemes: + $guess = (strlen($valid) == 32) ? md5($password) : ($salt . md5($salt . $password)); + if (!strcmp($guess, $valid)) { + return true; + } + + // Passwords with <&"> created by G2 prior to 2.1 were hashed with entities + $sanitizedPassword = html::specialchars($password, false); + $guess = (strlen($valid) == 32) ? md5($sanitizedPassword) + : ($salt . md5($salt . $sanitizedPassword)); + if (!strcmp($guess, $valid)) { + return true; + } + + return false; + } + + /** + * @see IdentityProvider_Driver::lookup_user. + */ + public function lookup_user($id) { + return user::lookup_by_field("id", $id); + } + + /** + * @see IdentityProvider_Driver::lookup_user_by_name. + */ + public function lookup_user_by_name($name) { + return user::lookup_by_field("name", $name); + } + + /** + * @see IdentityProvider_Driver::create_group. + */ + public function create_group($name) { + return group::create($name); + } + + /** + * @see IdentityProvider_Driver::everybody. + */ + public function everybody() { + return group::everybody(); + } + + /** + * @see IdentityProvider_Driver::registered_users. + */ + public function registered_users() { + return group::registered_users(); + } + + /** + * @see IdentityProvider_Driver::lookup_group. + */ + public function lookup_group($id) { + return group::lookup_by_field("id", $id); + } + + /** + * @see IdentityProvider_Driver::lookup_group_by_name. + */ + public function lookup_group_by_name($name) { + return group::lookup_by_field("name", $name); + } + + /** + * @see IdentityProvider_Driver::get_user_list. + */ + public function get_user_list($ids) { + return ORM::factory("user") + ->in("id", $ids) + ->find_all() + ->as_array(); + } + + /** + * @see IdentityProvider_Driver::groups. + */ + public function groups() { + return ORM::factory("group")->find_all(); + } + +} // End Identity Gallery Driver + diff --git a/modules/user/views/admin_users.html.php b/modules/user/views/admin_users.html.php index ee8d413c..fed92c5e 100644 --- a/modules/user/views/admin_users.html.php +++ b/modules/user/views/admin_users.html.php @@ -91,7 +91,7 @@ open_text="" class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left"> - id != $user->id && !$user->guest): ?> + id != $user->id && !$user->guest): ?> id") ?>" class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> -- cgit v1.2.3 From e3f90a889d5bb4cb1214445bbf5be8c9815d8733 Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Fri, 23 Oct 2009 22:24:06 -0600 Subject: Adjust order of items on server_add admin page. Restore autocomplete to the add form. Created a server_add.css file. --- .../server_add/controllers/admin_server_add.php | 4 +-- modules/server_add/css/server_add.css | 38 ++++++++++++++++++++++ modules/server_add/helpers/server_add_theme.php | 2 ++ modules/server_add/js/admin.js | 2 +- modules/server_add/views/admin_server_add.html.php | 15 ++++----- themes/night_wind/css/screen.css | 33 ------------------- themes/wind/css/screen.css | 33 ------------------- 7 files changed, 50 insertions(+), 77 deletions(-) create mode 100644 modules/server_add/css/server_add.css (limited to 'modules/server_add/helpers') diff --git a/modules/server_add/controllers/admin_server_add.php b/modules/server_add/controllers/admin_server_add.php index cb71e1f1..f32bb834 100644 --- a/modules/server_add/controllers/admin_server_add.php +++ b/modules/server_add/controllers/admin_server_add.php @@ -83,9 +83,9 @@ class Admin_Server_Add_Controller extends Admin_Controller { private function _get_admin_form() { $form = new Forge("admin/server_add/add_path", "", "post", - array("id" => "g-server-add-admin-form", "class" => "g-short-form g-wide")); + array("id" => "g-server-add-admin-form", "class" => "g-short-form")); $add_path = $form->group("add_path"); - $add_path->input("path")->label(t("Path"))->rules("required") + $add_path->input("path")->label(t("Path"))->rules("required")->id("g-path") ->error_messages("not_readable", t("This directory is not readable by the webserver")) ->error_messages("is_symlink", t("Symbolic links are not allowed")); $add_path->submit("add")->value(t("Add Path")); diff --git a/modules/server_add/css/server_add.css b/modules/server_add/css/server_add.css new file mode 100644 index 00000000..36746ab5 --- /dev/null +++ b/modules/server_add/css/server_add.css @@ -0,0 +1,38 @@ +#g-server-add button { + margin-bottom: .5em; +} + +#g-server-add-tree { + cursor: pointer; + padding-left: 4px; + width: 95%; +} + +#g-server-add-tree li { + padding: 0; + float: none; +} + +#g-server-add-tree span.selected { + background: #ddd; +} + +#g-server-add-tree { + border: 1px solid #ccc; + height: 20em; + overflow: auto; + margin-bottom: .5em; + padding: .5em; +} + +#g-server-add ul ul li { + padding-left: 1.2em; +} + +#g-server-add-paths li .ui-icon { + margin-top: .4em; +} + +#g-server-add-admin-form .textbox { + width: 400px; +} diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index 2ba2e167..0410c9fe 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -20,6 +20,7 @@ class server_add_theme_Core { static function head($theme) { if (user::active()->admin) { + $theme->css("server_add.css"); $theme->script("server_add.js"); } } @@ -27,6 +28,7 @@ class server_add_theme_Core { static function admin_head($theme) { $head = array(); if (strpos(Router::$current_uri, "admin/server_add") !== false) { + $theme->css("server_add.css"); $theme->css("jquery.autocomplete.css"); $base = url::site("__ARGS__"); $csrf = access::csrf_token(); diff --git a/modules/server_add/js/admin.js b/modules/server_add/js/admin.js index edbddf33..9d7bd181 100644 --- a/modules/server_add/js/admin.js +++ b/modules/server_add/js/admin.js @@ -3,6 +3,6 @@ * */ $("document").ready(function() { - $("#g-server-add-admin input:text").autocomplete( + $("#g-path").autocomplete( base_url.replace("__ARGS__", "admin/server_add/autocomplete"), {max: 256}); }); diff --git a/modules/server_add/views/admin_server_add.html.php b/modules/server_add/views/admin_server_add.html.php index eae767af..33fd81f3 100644 --- a/modules/server_add/views/admin_server_add.html.php +++ b/modules/server_add/views/admin_server_add.html.php @@ -2,21 +2,20 @@

    +

    - style="display: none;"> +
      +
    • -
    - -
    diff --git a/themes/night_wind/css/screen.css b/themes/night_wind/css/screen.css index dfc94b6d..b95cfc72 100644 --- a/themes/night_wind/css/screen.css +++ b/themes/night_wind/css/screen.css @@ -714,39 +714,6 @@ li.g-error select { background: #999; } -/* Server Add */ - -#g-server-add button { - margin-bottom: .5em; -} - -#g-server-add-tree { - cursor: pointer; - padding-left: 4px; - width: 95%; -} - -#g-server-add-tree li { - padding: 0; - float: none; -} - -#g-server-add-tree span.selected { - background: #ddd; -} - -#g-server-add-tree { - border: 1px solid #ccc; - height: 20em; - overflow: auto; - margin-bottom: .5em; - padding: .5em; -} - -#g-server-add ul ul li { - padding-left: 1.2em; -} - /* Permissions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #g-edit-permissions-form { diff --git a/themes/wind/css/screen.css b/themes/wind/css/screen.css index ef2f1510..84b8b090 100644 --- a/themes/wind/css/screen.css +++ b/themes/wind/css/screen.css @@ -513,39 +513,6 @@ td { background: #999; } -/* Server Add */ - -#g-server-add button { - margin-bottom: .5em; -} - -#g-server-add-tree { - cursor: pointer; - padding-left: 4px; - width: 95%; -} - -#g-server-add-tree li { - padding: 0; - float: none; -} - -#g-server-add-tree span.selected { - background: #ddd; -} - -#g-server-add-tree { - border: 1px solid #ccc; - height: 20em; - overflow: auto; - margin-bottom: .5em; - padding: .5em; -} - -#g-server-add ul ul li { - padding-left: 1.2em; -} - /* Permissions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #g-edit-permissions-form { -- cgit v1.2.3 From 7ea13b3869dee33804606a17488bb1cd26759bdb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 28 Oct 2009 12:15:52 -0700 Subject: Normalize capitalization ticket #596 --- modules/akismet/views/admin_akismet.html.php | 4 ++-- modules/comment/helpers/comment_block.php | 4 ++-- modules/comment/helpers/comment_rss.php | 2 +- modules/comment/views/admin_comments.html.php | 12 +++++----- modules/exif/views/exif_dialog.html.php | 2 +- modules/exif/views/exif_sidebar.html.php | 2 +- modules/g2_import/helpers/g2_import.php | 2 +- modules/g2_import/views/admin_g2_import.html.php | 2 +- modules/gallery/controllers/admin_languages.php | 2 +- modules/gallery/helpers/gallery_block.php | 26 +++++++++++----------- modules/gallery/helpers/gallery_installer.php | 4 ++-- modules/gallery/helpers/gallery_rss.php | 4 ++-- .../gallery/views/admin_advanced_settings.html.php | 4 ++-- .../gallery/views/admin_block_platform.html.php | 2 +- modules/gallery/views/admin_graphics.html.php | 6 ++--- modules/gallery/views/admin_graphics_none.html.php | 2 +- modules/gallery/views/admin_identity.html.php | 2 +- modules/gallery/views/admin_languages.html.php | 4 ++-- modules/gallery/views/admin_maintenance.html.php | 12 +++++----- modules/gallery/views/admin_sidebar.html.php | 6 ++--- modules/gallery/views/admin_themes.html.php | 4 ++-- modules/gallery/views/l10n_client.html.php | 6 ++--- modules/gallery/views/login.html.php | 2 +- modules/gallery/views/login_ajax.html.php | 4 ++-- modules/gallery/views/maintenance.html.php | 4 ++-- modules/gallery/views/simple_uploader.html.php | 4 ++-- modules/gallery/views/upgrader.html.php | 2 +- modules/gallery/views/welcome_message.html.php | 4 ++-- modules/image_block/helpers/image_block_block.php | 4 ++-- modules/info/helpers/info_block.php | 2 +- .../notification/views/comment_published.html.php | 4 ++-- modules/notification/views/item_updated.html.php | 4 ++-- modules/recaptcha/views/admin_recaptcha.html.php | 6 ++--- modules/rss/helpers/rss_block.php | 4 ++-- modules/search/views/search.html.php | 2 +- modules/server_add/helpers/server_add_event.php | 2 +- modules/server_add/views/admin_server_add.html.php | 6 ++--- modules/tag/helpers/tag_block.php | 4 ++-- modules/user/views/admin_users.html.php | 14 ++++++------ modules/user/views/admin_users_group.html.php | 8 +++---- modules/user/views/reset_password.html.php | 4 ++-- modules/watermark/views/admin_watermarks.html.php | 6 ++--- themes/admin_wind/views/admin.html.php | 6 ++--- themes/admin_wind/views/pager.html.php | 16 ++++++------- themes/night_wind/views/movie.html.php | 8 +++---- themes/night_wind/views/pager.html.php | 16 ++++++------- themes/wind/views/movie.html.php | 8 +++---- themes/wind/views/pager.html.php | 16 ++++++------- 48 files changed, 137 insertions(+), 137 deletions(-) (limited to 'modules/server_add/helpers') diff --git a/modules/akismet/views/admin_akismet.html.php b/modules/akismet/views/admin_akismet.html.php index d273be5b..399053d8 100644 --- a/modules/akismet/views/admin_akismet.html.php +++ b/modules/akismet/views/admin_akismet.html.php @@ -1,6 +1,6 @@
    -

    +

    Wordpress.com API Key, which is also free. Your comments will be automatically relayed to Akismet.com where they'll be scanned for spam. Spam messages will be flagged accordingly and hidden from your vistors until you approve or delete them.", array("api_key_url" => "http://wordpress.com/api-keys", @@ -9,7 +9,7 @@

    - +
    diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php index c00c6c51..7cd5d429 100644 --- a/modules/comment/helpers/comment_block.php +++ b/modules/comment/helpers/comment_block.php @@ -19,7 +19,7 @@ */ class comment_block_Core { static function get_admin_list() { - return array("recent_comments" => t("Recent Comments")); + return array("recent_comments" => t("Recent comments")); } static function get($block_id) { @@ -27,7 +27,7 @@ class comment_block_Core { switch ($block_id) { case "recent_comments": $block->css_id = "g-recent-comments"; - $block->title = t("Recent Comments"); + $block->title = t("Recent comments"); $block->content = new View("admin_block_recent_comments.html"); $block->content->comments = ORM::factory("comment")->orderby("created", "DESC")->limit(5)->find_all(); diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 4424981d..3692a30d 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -61,7 +61,7 @@ class comment_rss_Core { $feed->max_pages = ceil($comments->count_all() / $limit); $feed->title = htmlspecialchars(t("Recent Comments")); $feed->uri = url::abs_site("albums/" . (empty($id) ? "1" : $id)); - $feed->description = t("Recent Comments"); + $feed->description = t("Recent comments"); return $feed; } diff --git a/modules/comment/views/admin_comments.html.php b/modules/comment/views/admin_comments.html.php index 82e071a8..f0f5ab1c 100644 --- a/modules/comment/views/admin_comments.html.php +++ b/modules/comment/views/admin_comments.html.php @@ -35,7 +35,7 @@
    -

    +

    @@ -46,13 +46,13 @@

    - + - + - + - +

    @@ -196,6 +196,6 @@
    - +
    diff --git a/modules/exif/views/exif_dialog.html.php b/modules/exif/views/exif_dialog.html.php index b50eea1d..22744e2d 100644 --- a/modules/exif/views/exif_dialog.html.php +++ b/modules/exif/views/exif_dialog.html.php @@ -4,7 +4,7 @@ .g-odd { background: #bdd2ff; } .g-even { background: #dfeffc; } -

    +

    diff --git a/modules/exif/views/exif_sidebar.html.php b/modules/exif/views/exif_sidebar.html.php index 04f72b02..8af2eb12 100644 --- a/modules/exif/views/exif_sidebar.html.php +++ b/modules/exif/views/exif_sidebar.html.php @@ -1,5 +1,5 @@ -id}") ?>" title="for_html_attr() ?>" +id}") ?>" title="for_html_attr() ?>" class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"> diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index f55e7f32..248f8017 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -271,7 +271,7 @@ class g2_import_Core { if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) { self::set_map($g2_user_id, identity::guest()->id); - return t("Skipping Anonymous User"); + return t("Skipping anonymous user"); } $g2_admin_group_id = diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php index e1443aa7..b2665a5f 100644 --- a/modules/g2_import/views/admin_g2_import.html.php +++ b/modules/g2_import/views/admin_g2_import.html.php @@ -1,6 +1,6 @@
    -

    +

    diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php index ccc631c7..27537c7f 100644 --- a/modules/gallery/controllers/admin_languages.php +++ b/modules/gallery/controllers/admin_languages.php @@ -115,7 +115,7 @@ class Admin_Languages_Controller extends Admin_Controller { ? t("This is a unique key that will allow you to send translations to the remote server. To get your API key go to %server-link.", array("server-link" => html::mark_clean(html::anchor($server_link)))) - : t("API Key")) + : t("API key")) ->value($api_key) ->error_messages("invalid", t("The API key you provided is invalid.")); $group->submit("save")->value(t("Save settings")); diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 6c08d39a..0052affc 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -21,15 +21,15 @@ class gallery_block_Core { static function get_admin_list() { return array( "welcome" => t("Welcome to Gallery 3!"), - "photo_stream" => t("Photo Stream"), - "log_entries" => t("Log Entries"), - "stats" => t("Gallery Stats"), - "platform_info" => t("Platform Information"), - "project_news" => t("Gallery Project News")); + "photo_stream" => t("Photo stream"), + "log_entries" => t("Log entries"), + "stats" => t("Gallery stats"), + "platform_info" => t("Platform information"), + "project_news" => t("Gallery project news")); } static function get_site_list() { - return array("language" => t("Language Preference")); + return array("language" => t("Language preference")); } static function get($block_id) { @@ -43,7 +43,7 @@ class gallery_block_Core { case "photo_stream": $block->css_id = "g-photo-stream"; - $block->title = t("Photo Stream"); + $block->title = t("Photo stream"); $block->content = new View("admin_block_photo_stream.html"); $block->content->photos = ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10); @@ -51,7 +51,7 @@ class gallery_block_Core { case "log_entries": $block->css_id = "g-log-entries"; - $block->title = t("Log Entries"); + $block->title = t("Log entries"); $block->content = new View("admin_block_log_entries.html"); $block->content->entries = ORM::factory("log") ->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5); @@ -59,7 +59,7 @@ class gallery_block_Core { case "stats": $block->css_id = "g-stats"; - $block->title = t("Gallery Stats"); + $block->title = t("Gallery stats"); $block->content = new View("admin_block_stats.html"); $block->content->album_count = ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all(); @@ -68,7 +68,7 @@ class gallery_block_Core { case "platform_info": $block->css_id = "g-platform"; - $block->title = t("Platform Information"); + $block->title = t("Platform information"); $block->content = new View("admin_block_platform.html"); if (is_readable("/proc/loadavg")) { $block->content->load_average = @@ -80,14 +80,14 @@ class gallery_block_Core { case "project_news": $block->css_id = "g-project-news"; - $block->title = t("Gallery Project News"); + $block->title = t("Gallery project news"); $block->content = new View("admin_block_news.html"); $block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3); break; case "block_adder": $block->css_id = "g-block-adder"; - $block->title = t("Dashboard Content"); + $block->title = t("Dashboard content"); $block->content = self::get_add_block_form(); break; @@ -99,7 +99,7 @@ class gallery_block_Core { } $block = new Block(); $block->css_id = "g-user-language-block"; - $block->title = t("Language Preference"); + $block->title = t("Language preference"); $block->content = new View("user_languages_block.html"); $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales); diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 01a213c8..5daf1016 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -199,12 +199,12 @@ class gallery_installer { } access::register_permission("view", "View"); - access::register_permission("view_full", "View Full Size"); + access::register_permission("view_full", "View full size"); access::register_permission("edit", "Edit"); access::register_permission("add", "Add"); // Mark for translation (must be the same strings as used above) - t("View Full Size"); + t("View full size"); t("View"); t("Edit"); t("Add"); diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index feeab88a..155edfb5 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -39,8 +39,8 @@ class gallery_rss_Core { ->orderby("created", "DESC"); $feed->max_pages = ceil($all_children->find_all()->count() / $limit); - $feed->title = t("Recent Updates"); - $feed->description = t("Recent Updates"); + $feed->title = t("Recent updates"); + $feed->description = t("Recent updates"); return $feed; case "album": diff --git a/modules/gallery/views/admin_advanced_settings.html.php b/modules/gallery/views/admin_advanced_settings.html.php index e3ae5f58..32fbc2c3 100644 --- a/modules/gallery/views/admin_advanced_settings.html.php +++ b/modules/gallery/views/admin_advanced_settings.html.php @@ -1,10 +1,10 @@
    -

    +

    - +
    diff --git a/modules/gallery/views/admin_block_platform.html.php b/modules/gallery/views/admin_block_platform.html.php index f27b9e7a..b1b8a2f9 100644 --- a/modules/gallery/views/admin_block_platform.html.php +++ b/modules/gallery/views/admin_block_platform.html.php @@ -4,7 +4,7 @@ php_uname("n"))) ?>
  • - php_uname("s"), "version" => php_uname("r"))) ?> + php_uname("s"), "version" => php_uname("r"))) ?>
  • function_exists("apache_get_version") ? apache_get_version() : t("Unknown"))) ?> diff --git a/modules/gallery/views/admin_graphics.html.php b/modules/gallery/views/admin_graphics.html.php index 0f4c0dd8..3a48e087 100644 --- a/modules/gallery/views/admin_graphics.html.php +++ b/modules/gallery/views/admin_graphics.html.php @@ -13,13 +13,13 @@
    -

    +

    -

    +

    @@ -27,7 +27,7 @@
    -

    +

    $tk->$id, "is_active" => false)) ?> diff --git a/modules/gallery/views/admin_graphics_none.html.php b/modules/gallery/views/admin_graphics_none.html.php index 3ac6b4fb..e0fc4170 100644 --- a/modules/gallery/views/admin_graphics_none.html.php +++ b/modules/gallery/views/admin_graphics_none.html.php @@ -1,7 +1,7 @@
    -

    +

    diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php index 358860cf..9a34dcc4 100644 --- a/modules/gallery/views/admin_identity.html.php +++ b/modules/gallery/views/admin_identity.html.php @@ -34,7 +34,7 @@
    -

    +

    diff --git a/modules/gallery/views/admin_languages.html.php b/modules/gallery/views/admin_languages.html.php index 311672de..908cc892 100644 --- a/modules/gallery/views/admin_languages.html.php +++ b/modules/gallery/views/admin_languages.html.php @@ -26,7 +26,7 @@
    -

    +

    @@ -107,6 +107,6 @@
    - +
    diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index 73a4bef8..107b35cc 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -1,13 +1,13 @@
    -

    +

    -

    +

  • @@ -43,11 +43,11 @@ count()): ?>
    -

    +

    - + @@ -116,11 +116,11 @@ count()): ?>
    -

    +

    - + diff --git a/modules/gallery/views/admin_sidebar.html.php b/modules/gallery/views/admin_sidebar.html.php index 7c97270c..b394aa19 100644 --- a/modules/gallery/views/admin_sidebar.html.php +++ b/modules/gallery/views/admin_sidebar.html.php @@ -36,7 +36,7 @@
    -

    +

    @@ -44,7 +44,7 @@
    ">
    -

    +

      @@ -52,7 +52,7 @@
    -

    +

      diff --git a/modules/gallery/views/admin_themes.html.php b/modules/gallery/views/admin_themes.html.php index dda18265..d14e8bd4 100644 --- a/modules/gallery/views/admin_themes.html.php +++ b/modules/gallery/views/admin_themes.html.php @@ -8,7 +8,7 @@
      -

      +

      @@ -89,6 +89,6 @@
    - +
    \ No newline at end of file diff --git a/modules/gallery/views/l10n_client.html.php b/modules/gallery/views/l10n_client.html.php index f4da52dc..9d14bbb2 100644 --- a/modules/gallery/views/l10n_client.html.php +++ b/modules/gallery/views/l10n_client.html.php @@ -6,9 +6,9 @@ for_html_attr() ?>" href="">X -

    +

    get('show_all_l10n_messages')): ?> - "> + ">

    @@ -73,7 +73,7 @@

    diff --git a/modules/gallery/views/welcome_message.html.php b/modules/gallery/views/welcome_message.html.php index 4acdb156..b50163fa 100644 --- a/modules/gallery/views/welcome_message.html.php +++ b/modules/gallery/views/welcome_message.html.php @@ -16,10 +16,10 @@

    id}") ?>" - title="for_html_attr() ?>" + title="for_html_attr() ?>" id="g-after-install-change-password-link" class="g-button ui-state-default ui-corners-all"> - +

    -

    +

    @@ -54,7 +54,7 @@ -

    +

    @@ -87,17 +87,17 @@ @@ -115,7 +115,7 @@

    - +

    diff --git a/modules/user/views/admin_users_group.html.php b/modules/user/views/admin_users_group.html.php index db3645a0..e44cbddd 100644 --- a/modules/user/views/admin_users_group.html.php +++ b/modules/user/views/admin_users_group.html.php @@ -5,11 +5,11 @@ id") ?>" title=" $group->name))->for_html_attr() ?>" class="g-dialog-link g-button ui-state-default ui-corner-all"> - + for_html_attr() ?>" class="g-dialog-link g-button ui-state-disabled ui-corner-all ui-icon-left"> - + @@ -23,7 +23,7 @@ class="g-button ui-state-default ui-corner-all ui-icon-left" title=" $user->name, "group" => $group->name))->for_html_attr() ?>"> - + @@ -32,7 +32,7 @@

    - +

    diff --git a/modules/user/views/reset_password.html.php b/modules/user/views/reset_password.html.php index 92ca4917..3afca881 100644 --- a/modules/user/views/reset_password.html.php +++ b/modules/user/views/reset_password.html.php @@ -1,10 +1,10 @@ - <?= t("Password Reset Request") ?> + <?= t("Password reset request") ?> -

    +

    $user->full_name ? $user->full_name : $user->name)) ?>

    diff --git a/modules/watermark/views/admin_watermarks.html.php b/modules/watermark/views/admin_watermarks.html.php index af38cb41..fc634b82 100644 --- a/modules/watermark/views/admin_watermarks.html.php +++ b/modules/watermark/views/admin_watermarks.html.php @@ -11,7 +11,7 @@ title="for_html_attr() ?>" class="g-dialog-link g-button ui-icon-left ui-state-default ui-corner-all"> -

    +

    @@ -27,10 +27,10 @@
    diff --git a/themes/admin_wind/views/admin.html.php b/themes/admin_wind/views/admin.html.php index ef1aa1d2..e554b817 100644 --- a/themes/admin_wind/views/admin.html.php +++ b/themes/admin_wind/views/admin.html.php @@ -4,7 +4,7 @@ - <?= t("Admin Dashboard") ?> + <?= t("Admin dashboard") ?>" type="image/x-icon" /> css("yui/reset-fonts-grids.css") ?> @@ -23,7 +23,7 @@ script("gallery.common.js") ?> script("gallery.ajax.js") ?> script("gallery.dialog.js") ?> @@ -48,7 +48,7 @@ html::mark_clean( 'id}") . - '" title="' . t("Edit Your Profile")->for_html_attr() . + '" title="' . t("Edit your profile")->for_html_attr() . '" id="g-user-profile-link" class="g-dialog-link">' . html::clean($user->display_name()) . ''))) ?> diff --git a/themes/admin_wind/views/pager.html.php b/themes/admin_wind/views/pager.html.php index 555a4950..e4fbd5d5 100644 --- a/themes/admin_wind/views/pager.html.php +++ b/themes/admin_wind/views/pager.html.php @@ -11,34 +11,34 @@
  • - + - + - + - +
  • - + - + - + - +
  • diff --git a/themes/night_wind/views/movie.html.php b/themes/night_wind/views/movie.html.php index 17b519ba..9254c7fe 100644 --- a/themes/night_wind/views/movie.html.php +++ b/themes/night_wind/views/movie.html.php @@ -6,20 +6,20 @@
  • - + - +
  • $position, "total" => $sibling_count)) ?>
  • - + - +
  • diff --git a/themes/night_wind/views/pager.html.php b/themes/night_wind/views/pager.html.php index 337d658f..ba325d03 100644 --- a/themes/night_wind/views/pager.html.php +++ b/themes/night_wind/views/pager.html.php @@ -11,34 +11,34 @@
  • - + - + - + - +
  • - + - + - + - +
  • diff --git a/themes/wind/views/movie.html.php b/themes/wind/views/movie.html.php index 17b519ba..9254c7fe 100644 --- a/themes/wind/views/movie.html.php +++ b/themes/wind/views/movie.html.php @@ -6,20 +6,20 @@
  • - + - +
  • $position, "total" => $sibling_count)) ?>
  • - + - +
  • diff --git a/themes/wind/views/pager.html.php b/themes/wind/views/pager.html.php index 337d658f..ba325d03 100644 --- a/themes/wind/views/pager.html.php +++ b/themes/wind/views/pager.html.php @@ -11,34 +11,34 @@
  • - + - + - + - +
  • - + - + - + - +
  • -- cgit v1.2.3 From 03b4b2749825778e1fb436944e0e1225686f7705 Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Fri, 30 Oct 2009 00:14:57 -0600 Subject: Add type attribute to rest of our script tags. --- modules/gallery/views/movieplayer.html.php | 2 +- modules/gallery/views/welcome_message.html.php | 2 +- modules/server_add/helpers/server_add_theme.php | 2 +- themes/night_wind/views/photo.html.php | 2 +- themes/wind/views/photo.html.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/server_add/helpers') diff --git a/modules/gallery/views/movieplayer.html.php b/modules/gallery/views/movieplayer.html.php index e9783eb8..f7af8d93 100644 --- a/modules/gallery/views/movieplayer.html.php +++ b/modules/gallery/views/movieplayer.html.php @@ -1,6 +1,6 @@ file_url(true), "", $attrs) ?> -

    diff --git a/modules/server_add/helpers/server_add_theme.php b/modules/server_add/helpers/server_add_theme.php index e213779c..84f28df2 100644 --- a/modules/server_add/helpers/server_add_theme.php +++ b/modules/server_add/helpers/server_add_theme.php @@ -32,7 +32,7 @@ class server_add_theme_Core { $theme->css("jquery.autocomplete.css"); $base = url::site("__ARGS__"); $csrf = access::csrf_token(); - $head[] = ""; + $head[] = ""; $theme->script("jquery.autocomplete.js"); $theme->script("admin.js"); diff --git a/themes/night_wind/views/photo.html.php b/themes/night_wind/views/photo.html.php index b33e2afa..e1231f65 100644 --- a/themes/night_wind/views/photo.html.php +++ b/themes/night_wind/views/photo.html.php @@ -2,7 +2,7 @@ item())): ?> -
    id") ?>" - open_text="" + open_text="" class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left"> - + id != $user->id && !$user->guest): ?> id") ?>" class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> - + for_html_attr() ?>" class="g-button ui-state-disabled ui-corner-all ui-icon-left"> - +