summaryrefslogtreecommitdiff
path: root/modules/user/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user/helpers')
-rw-r--r--modules/user/helpers/group.php1
-rw-r--r--modules/user/helpers/user.php43
-rw-r--r--modules/user/helpers/user_event.php26
-rw-r--r--modules/user/helpers/user_installer.php6
-rw-r--r--modules/user/helpers/user_menu.php28
-rw-r--r--modules/user/helpers/user_theme.php33
6 files changed, 89 insertions, 48 deletions
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index 1dace840..04e6efd6 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -39,7 +39,6 @@ class group_Core {
$group->name = $name;
$group->save();
- module::event("group_created", $group);
return $group;
}
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index a59588f8..b9162b92 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -34,13 +34,16 @@ class user_Core {
->matches($group->password);
$group->input("email")->label(t("Email"))->id("gEmail")->value($user->email);
$group->input("url")->label(t("URL"))->id("gUrl")->value($user->url);
- $group->submit("")->value(t("Save"));
$form->add_rules_from($user);
+
+ module::event("user_edit_form", $user, $form);
+ $group->submit("")->value(t("Save"));
return $form;
}
static function get_edit_form_admin($user) {
- $form = new Forge("admin/users/edit_user/$user->id", "", "post", array("id" => "gEditUserForm"));
+ $form = new Forge(
+ "admin/users/edit_user/$user->id", "", "post", array("id" => "gEditUserForm"));
$group = $form->group("edit_user")->label(t("Edit User"));
$group->input("name")->label(t("Username"))->id("gUsername")->value($user->name);
$group->inputs["name"]->error_messages(
@@ -53,9 +56,11 @@ class user_Core {
$group->input("email")->label(t("Email"))->id("gEmail")->value($user->email);
$group->input("url")->label(t("URL"))->id("gUrl")->value($user->url);
$group->checkbox("admin")->label(t("Admin"))->id("gAdmin")->checked($user->admin);
- $group->submit("")->value(t("Modify User"));
$form->add_rules_from($user);
$form->edit_user->password->rules("-required");
+
+ module::event("user_edit_form_admin", $user, $form);
+ $group->submit("")->value(t("Modify User"));
return $form;
}
@@ -72,14 +77,19 @@ class user_Core {
$group->input("url")->label(t("URL"))->id("gUrl");
self::_add_locale_dropdown($group);
$group->checkbox("admin")->label(t("Admin"))->id("gAdmin");
- $group->submit("")->value(t("Add User"));
$user = ORM::factory("user");
$form->add_rules_from($user);
+
+ module::event("user_add_form_admin", $user, $form);
+ $group->submit("")->value(t("Add User"));
return $form;
}
private static function _add_locale_dropdown(&$form, $user=null) {
- $locales = locale::installed();
+ $locales = locales::installed();
+ foreach ($locales as $locale => $display_name) {
+ $locales[$locale] = SafeString::of_safe_html($display_name);
+ }
if (count($locales) > 1) {
// Put "none" at the first position in the array
$locales = array_merge(array("" => t("« none »")), $locales);
@@ -152,7 +162,12 @@ class user_Core {
*/
static function active() {
// @todo (maybe) cache this object so we're not always doing session lookups.
- $user = Session::instance()->get("user", self::guest());
+ $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 = user::guest();
+ }
return $user;
}
@@ -202,7 +217,6 @@ class user_Core {
$user->add(group::registered_users());
$user->save();
- module::event("user_created", $user);
return $user;
}
@@ -325,4 +339,19 @@ class user_Core {
}
return $salt . md5($salt . $password);
}
+
+ static function cookie_locale() {
+ $cookie_data = Input::instance()->cookie("g_locale");
+ $locale = null;
+ if ($cookie_data) {
+ if (preg_match("/^([a-z]{2,3}(?:_[A-Z]{2})?)$/", trim($cookie_data), $matches)) {
+ $requested_locale = $matches[1];
+ $installed_locales = locales::installed();
+ if (isset($installed_locales[$requested_locale])) {
+ $locale = $requested_locale;
+ }
+ }
+ }
+ return $locale;
+ }
} \ No newline at end of file
diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php
index 6515fbfb..ede4e515 100644
--- a/modules/user/helpers/user_event.php
+++ b/modules/user/helpers/user_event.php
@@ -23,10 +23,30 @@ class user_event_Core {
*/
static function gallery_ready() {
user::load_user();
+ self::set_request_locale();
+ }
+
+ static function admin_menu($menu, $theme) {
+ $menu->add_after("appearance_menu",
+ Menu::factory("link")
+ ->id("users_groups")
+ ->label(t("Users/Groups"))
+ ->url(url::site("admin/users")));
+ }
- $locale = user::active()->locale;
- if (!empty($locale)) {
- // TODO(andy_st): Check session data as well.
+ static function set_request_locale() {
+ // 1. Check the session specific preference (cookie)
+ $locale = user::cookie_locale();
+ // 2. Check the user's preference
+ if (!$locale) {
+ $locale = user::active()->locale;
+ }
+ // 3. Check the browser's / OS' preference
+ if (!$locale) {
+ $locale = locales::locale_from_http_request();
+ }
+ // If we have any preference, override the site's default locale
+ if ($locale) {
I18n::instance()->locale($locale);
}
}
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index 1959d038..8ef4f13d 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -36,7 +36,7 @@ class user_installer {
PRIMARY KEY (`id`),
UNIQUE KEY(`hash`),
UNIQUE KEY(`name`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups} (
`id` int(9) NOT NULL auto_increment,
@@ -44,14 +44,14 @@ class user_installer {
`special` BOOLEAN default 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups_users} (
`group_id` int(9) NOT NULL,
`user_id` int(9) NOT NULL,
PRIMARY KEY (`group_id`, `user_id`),
UNIQUE KEY(`user_id`, `group_id`))
- ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ DEFAULT CHARSET=utf8;");
$everybody = group::create("Everybody");
$everybody->special = true;
diff --git a/modules/user/helpers/user_menu.php b/modules/user/helpers/user_menu.php
deleted file mode 100644
index 05e401f9..00000000
--- a/modules/user/helpers/user_menu.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class user_menu_Core {
- static function admin($menu, $theme) {
- $menu->add_after("appearance_menu",
- Menu::factory("link")
- ->id("users_groups")
- ->label(t("Users/Groups"))
- ->url(url::site("admin/users")));
- }
-}
diff --git a/modules/user/helpers/user_theme.php b/modules/user/helpers/user_theme.php
index ad9d4c63..098d87fd 100644
--- a/modules/user/helpers/user_theme.php
+++ b/modules/user/helpers/user_theme.php
@@ -18,15 +18,36 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_theme_Core {
+ static function head($theme) {
+ if (count(locales::installed())) {
+ // Needed by the languages block
+ $theme->script("jquery.cookie.js");
+ }
+ return "";
+ }
+
static function header_top($theme) {
- $view = new View("login.html");
- $view->user = user::active();
- return $view->render();
+ if ($theme->page_type != "login") {
+ $view = new View("login.html");
+ $view->user = user::active();
+ return $view->render();
+ }
}
- static function admin_head($theme) {
- if (strpos(Router::$current_uri, "admin/users") !== false) {
- $theme->script("lib/gallery.panel.js");
+ static function sidebar_blocks($theme) {
+ $locales = locales::installed();
+ foreach ($locales as $locale => $display_name) {
+ $locales[$locale] = SafeString::of_safe_html($display_name);
+ }
+ if (count($locales) > 1) {
+ $block = new Block();
+ $block->css_id = "gUserLanguageBlock";
+ $block->title = t("Language Preference");
+ $block->content = new View("user_languages_block.html");
+ $block->content->installed_locales =
+ array_merge(array("" => t("« none »")), $locales);
+ $block->content->selected = (string) user::cookie_locale();
+ return $block;
}
}
}