summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gallery.dialog.js2
-rw-r--r--modules/comment/helpers/comment.php2
-rw-r--r--modules/comment/helpers/comment_event.php21
-rw-r--r--modules/gallery/controllers/admin_identity.php8
-rw-r--r--modules/gallery/controllers/albums.php2
-rw-r--r--modules/gallery/controllers/login.php15
-rw-r--r--modules/gallery/controllers/logout.php12
-rw-r--r--modules/gallery/helpers/auth.php (renamed from modules/gallery/helpers/login.php)29
-rw-r--r--modules/gallery/helpers/gallery_event.php27
-rw-r--r--modules/gallery/helpers/gallery_installer.php2
-rw-r--r--modules/gallery/helpers/graphics.php5
-rw-r--r--modules/gallery/helpers/movie.php5
-rw-r--r--modules/gallery/libraries/IdentityProvider.php6
-rw-r--r--modules/gallery/models/log.php1
-rw-r--r--modules/gallery/views/admin_identity.html.php6
-rw-r--r--modules/gallery/views/maintenance.html.php2
-rw-r--r--modules/notification/helpers/notification_event.php8
-rw-r--r--modules/recaptcha/helpers/recaptcha_event.php4
-rw-r--r--modules/user/controllers/admin_users.php22
-rw-r--r--modules/user/helpers/user_event.php14
-rw-r--r--modules/user/helpers/user_installer.php14
21 files changed, 133 insertions, 74 deletions
diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js
index a3715929..3587108c 100644
--- a/lib/gallery.dialog.js
+++ b/lib/gallery.dialog.js
@@ -115,6 +115,8 @@
success: function(data) {
if (data.form) {
$("#g-dialog form").replaceWith(data.form);
+ $("#g-dialog form :submit").removeClass("ui-state-disabled")
+ .attr("disabled", null);
self._ajaxify_dialog();
self.form_loaded(null, $("#g-dialog form"));
if (typeof data.reset == 'function') {
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 2b651118..35685d8c 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -72,7 +72,7 @@ class comment_Core {
$group->input("url") ->label(t("Website (hidden)"))->id("g-url");
$group->textarea("text")->label(t("Comment")) ->id("g-text");
$group->hidden("item_id")->value($item->id);
- module::event("recaptcha_add", $group);
+ module::event("comment_add_form", $form);
$group->submit("")->value(t("Add"))->class("ui-state-default ui-corner-all");
$active = identity::active_user();
diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php
index 2199eb7f..ddf72e3c 100644
--- a/modules/comment/helpers/comment_event.php
+++ b/modules/comment/helpers/comment_event.php
@@ -22,6 +22,27 @@ class comment_event_Core {
Database::instance()->delete("comments", array("item_id" => $item->id));
}
+ static function user_deleted($user) {
+ $guest = identity::guest();
+ Database::instance()
+ ->query("UPDATE {comments}
+ SET author_id = {$guest->id},
+ guest_email = NULL,
+ guest_name = 'guest',
+ guest_url = NULL
+ WHERE author_id = {$user->id}");
+ }
+
+ static function identity_provider_changed($old_provider, $new_provider) {
+ $guest = identity::guest();
+ Database::instance()
+ ->query("UPDATE {comments}
+ SET author_id = {$guest->id},
+ guest_email = NULL,
+ guest_name = 'guest',
+ guest_url = null");
+ }
+
static function admin_menu($menu, $theme) {
$menu->get("content_menu")
->append(Menu::factory("link")
diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php
index 520b1966..acf71665 100644
--- a/modules/gallery/controllers/admin_identity.php
+++ b/modules/gallery/controllers/admin_identity.php
@@ -40,15 +40,11 @@ class Admin_Identity_Controller extends Admin_Controller {
$active_provider = module::get_var("gallery", "identity_provider", "user");
$providers = identity::providers();
-
$new_provider = $this->input->post("provider");
if ($new_provider != $active_provider) {
- module::event("identity_before_change", $active_provider, $new_provider);
-
module::deactivate($active_provider);
- module::uninstall($active_provider);
// Switch authentication
identity::reset();
@@ -57,6 +53,10 @@ class Admin_Identity_Controller extends Admin_Controller {
module::install($new_provider);
module::activate($new_provider);
+ module::event("identity_provider_changed", $active_provider, $new_provider);
+
+ module::uninstall($active_provider);
+
message::success(t("Changed to %description",
array("description" => $providers->$new_provider)));
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index d393422e..a430b14d 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 = login::get_form("login/auth_html");
+ $view->content->form = auth::get_login_form("login/auth_html");
print $view;
return;
} else {
diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php
index 3978b64f..75ee6b9c 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 = login::get_form("login/auth_ajax");
+ $view->form = auth::get_login_form("login/auth_ajax");
print $view;
}
@@ -40,7 +40,7 @@ class Login_Controller extends Controller {
}
public function html() {
- print login::get_form("login/auth_html");
+ print auth::get_login_form("login/auth_html");
}
public function auth_html() {
@@ -55,7 +55,7 @@ class Login_Controller extends Controller {
}
private function _auth($url) {
- $form = login::get_form($url);
+ $form = auth::get_login_form($url);
$valid = $form->validate();
if ($valid) {
$user = identity::lookup_user_by_name($form->login->inputs["name"]->value);
@@ -70,14 +70,7 @@ class Login_Controller extends Controller {
}
if ($valid) {
- if (identity::is_writable()) {
- $user->login_count += 1;
- $user->last_login = time();
- $user->save();
- }
- identity::set_active_user($user);
- log::info("user", t("User %name logged in", array("name" => $user->name)));
- module::event("user_login", $user);
+ auth::login($user);
}
// Either way, regenerate the session id to avoid session trapping
diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php
index 1b0364fd..2b93655d 100644
--- a/modules/gallery/controllers/logout.php
+++ b/modules/gallery/controllers/logout.php
@@ -19,17 +19,7 @@
*/
class Logout_Controller extends Controller {
public function index() {
- $user = identity::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)));
+ auth::logout();
if ($continue_url = $this->input->get("continue")) {
$item = url::get_item_from_uri($continue_url);
if (access::can("view", $item)) {
diff --git a/modules/gallery/helpers/login.php b/modules/gallery/helpers/auth.php
index cb961604..9c69cecd 100644
--- a/modules/gallery/helpers/login.php
+++ b/modules/gallery/helpers/auth.php
@@ -17,8 +17,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class login_Core {
- static function get_form($url) {
+class auth_Core {
+ 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"));
@@ -28,4 +28,29 @@ class login_Core {
$group->submit("")->value(t("Login"));
return $form;
}
+
+ static function login($user) {
+ if (identity::is_writable()) {
+ $user->login_count += 1;
+ $user->last_login = time();
+ $user->save();
+ }
+ identity::set_active_user($user);
+ log::info("user", t("User %name logged in", array("name" => $user->name)));
+ module::event("user_login", $user);
+ }
+
+ static function logout() {
+ $user = identity::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)));
+ }
} \ No newline at end of file
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 87dee356..582e3267 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -28,6 +28,20 @@ class gallery_event_Core {
locales::set_request_locale();
}
+ static function user_deleted($user) {
+ $admin = identity::admin_user();
+ $db = Database::instance();
+ $db->query("UPDATE {tasks} SET owner_id = {$admin->id} where owner_id = {$user->id}");
+ $db->query("UPDATE {items} SET owner_id = {$admin->id} where owner_id = {$user->id}");
+ }
+
+ static function identity_provider_changed($old_provider, $new_provider) {
+ $admin = identity::admin_user();
+ $db = Database::instance();
+ $db->query("UPDATE {tasks} SET owner_id = {$admin->id}");
+ $db->query("UPDATE {items} SET owner_id = {$admin->id}");
+ }
+
static function group_created($group) {
access::add_group($group);
}
@@ -165,7 +179,11 @@ class gallery_event_Core {
->append(Menu::factory("link")
->id("advanced")
->label(t("Advanced"))
- ->url(url::site("admin/advanced_settings"))))
+ ->url(url::site("admin/advanced_settings")))
+ ->append(Menu::factory("link")
+ ->id("identity_drivers")
+ ->label(t("Identity drivers"))
+ ->url(url::site("admin/identity"))))
->append(Menu::factory("link")
->id("modules")
->label(t("Modules"))
@@ -189,13 +207,6 @@ class gallery_event_Core {
->label(t("Manage sidebar"))
->url(url::site("admin/sidebar"))))
->append(Menu::factory("submenu")
- ->id("identity_menu")
- ->label(t("Identity management"))
- ->append(Menu::factory("link")
- ->id("identity_drivers")
- ->label(t("Identity drivers"))
- ->url(url::site("admin/identity"))))
- ->append(Menu::factory("submenu")
->id("statistics_menu")
->label(t("Statistics")))
->append(Menu::factory("link")
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 5daf1016..2eb02546 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -253,8 +253,6 @@ class gallery_installer {
$theme->save();
}
- module::set_var("gallery", "identity_provider", "user");
-
block_manager::add("dashboard_sidebar", "gallery", "block_adder");
block_manager::add("dashboard_sidebar", "gallery", "stats");
block_manager::add("dashboard_sidebar", "gallery", "platform_info");
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index 1063c073..d6a2f00c 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -278,7 +278,10 @@ class graphics_Core {
$toolkits->graphicsmagick->installed = false;
$toolkits->graphicsmagick->error = t("GraphicsMagick requires the <b>exec</b> function");
} else {
- putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin");
+ $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null);
+
+ putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") .
+ ":/usr/local/bin:/opt/local/bin:/opt/bin");
// @todo: consider refactoring the two segments below into a loop since they are so
// similar.
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index 6dac0803..e84e8ea6 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -190,7 +190,10 @@ class movie_Core {
static function find_ffmpeg() {
if (!$ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) {
- putenv("PATH=" . getenv("PATH") . ":/usr/local/bin:/opt/local/bin:/opt/bin");
+ $graphics_path = module::get_var("gallery", "graphics_toolkit_path", null);
+
+ putenv("PATH=" . getenv("PATH") . (empty($graphics_path) ? "" : ":$graphics_path") .
+ ":/usr/local/bin:/opt/local/bin:/opt/bin");
if (function_exists("exec")) {
$ffmpeg_path = exec("which ffmpeg");
}
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index aa519bd3..e213ae97 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -62,8 +62,10 @@ class IdentityProvider_Core {
*
* @return void
*/
- public function __construct() {
- $config = module::get_var("gallery", "identity_provider", "user");
+ public function __construct($config=null) {
+ if (empty($config)) {
+ $config = module::get_var("gallery", "identity_provider", "user");
+ }
// Test the config group name
if (($this->config = Kohana::config("identity." . $config)) === NULL) {
diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php
index 4f6b8c4b..c816a4a7 100644
--- a/modules/gallery/models/log.php
+++ b/modules/gallery/models/log.php
@@ -28,6 +28,7 @@ class Log_Model extends ORM {
try {
return identity::lookup_user($this->user_id);
} catch (Exception $e) {
+ Kohana::log("alert", "Unable to load user with id $this->user_id");
return null;
}
} else {
diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php
index 9a34dcc4..70fe401f 100644
--- a/modules/gallery/views/admin_identity.html.php
+++ b/modules/gallery/views/admin_identity.html.php
@@ -12,7 +12,7 @@
bgiframe: true,
title: <?= t("Confirm identity provider change")->for_js() ?>,
resizable: false,
- height:165,
+ height:180,
modal: true,
overlay: {
backgroundColor: '#000',
@@ -20,10 +20,10 @@
},
buttons: {
"Continue": function() {
- $("##g-dialog form").submit();
+ $("#g-dialog form").submit();
},
Cancel: function() {
- $(this).dialog('close');
+ $(this).dialog('destroy').remove();
}
}
});
diff --git a/modules/gallery/views/maintenance.html.php b/modules/gallery/views/maintenance.html.php
index 2fdc40a3..6351b6ab 100644
--- a/modules/gallery/views/maintenance.html.php
+++ b/modules/gallery/views/maintenance.html.php
@@ -43,7 +43,7 @@
<p>
<?= t("This site is currently only accessible by site administrators.") ?>
</p>
- <?= login::get_form("login/auth_html") ?>
+ <?= auth::get_login_form("login/auth_html") ?>
</body>
</html>
diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php
index 3a369155..b82e4f0f 100644
--- a/modules/notification/helpers/notification_event.php
+++ b/modules/notification/helpers/notification_event.php
@@ -52,6 +52,14 @@ class notification_event_Core {
}
}
+ static function user_deleted($user) {
+ Database::instance()->query("DELETE FROM {subscriptions} where user_id = {$user->id}");
+ }
+
+ static function identity_provider_changed($old_provider, $new_provider) {
+ Database::instance()->query("DELETE FROM {subscriptions}");
+ }
+
static function comment_created($comment) {
try {
if ($comment->state == "published") {
diff --git a/modules/recaptcha/helpers/recaptcha_event.php b/modules/recaptcha/helpers/recaptcha_event.php
index d3e5bca6..feedced4 100644
--- a/modules/recaptcha/helpers/recaptcha_event.php
+++ b/modules/recaptcha/helpers/recaptcha_event.php
@@ -18,9 +18,9 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class recaptcha_event_Core {
- static function recaptcha_add($form) {
+ static function comment_add_form($form) {
if (module::get_var("recaptcha", "public_key")) {
- $form->recaptcha("recaptcha")->label("")->id("g-recaptcha");
+ $form->add_comment->recaptcha("recaptcha")->label("")->id("g-recaptcha");
}
}
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php
index a7db6179..54541e90 100644
--- a/modules/user/controllers/admin_users.php
+++ b/modules/user/controllers/admin_users.php
@@ -36,9 +36,7 @@ class Admin_Users_Controller extends Admin_Controller {
$form = $this->_get_user_add_form_admin();
$valid = $form->validate();
$name = $form->add_user->inputs["name"]->value;
- $user_exists_data = (object)array("name" => $name);
- module::event("check_username_exists", $user_exists_data);
- if ($user_exists_data->exists) {
+ if ($user = user::lookup_by_name($name)) {
$form->add_user->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
@@ -300,14 +298,14 @@ class Admin_Users_Controller extends Admin_Controller {
static function _get_user_edit_form_admin($user) {
$form = new Forge(
"admin/users/edit_user/$user->id", "", "post", array("id" => "g-edit-user-form"));
- $group = $form->group("edit_user")->label(t("Edit User"));
+ $group = $form->group("edit_user")->label(t("Edit user"));
$group->input("name")->label(t("Username"))->id("g-username")->value($user->name);
$group->inputs["name"]->error_messages(
"in_use", t("There is already a user with that username"));
- $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name);
+ $group->input("full_name")->label(t("Full name"))->id("g-fullname")->value($user->full_name);
self::_add_locale_dropdown($group, $user);
$group->password("password")->label(t("Password"))->id("g-password");
- $group->password("password2")->label(t("Confirm Password"))->id("g-password2")
+ $group->password("password2")->label(t("Confirm password"))->id("g-password2")
->matches($group->password);
$group->input("email")->label(t("Email"))->id("g-email")->value($user->email);
$group->input("url")->label(t("URL"))->id("g-url")->value($user->url);
@@ -324,12 +322,12 @@ class Admin_Users_Controller extends Admin_Controller {
static function _get_user_add_form_admin() {
$form = new Forge("admin/users/add_user", "", "post", array("id" => "g-add-user-form"));
- $group = $form->group("add_user")->label(t("Add User"));
+ $group = $form->group("add_user")->label(t("Add user"));
$group->input("name")->label(t("Username"))->id("g-username")
->error_messages("in_use", t("There is already a user with that username"));
- $group->input("full_name")->label(t("Full Name"))->id("g-fullname");
+ $group->input("full_name")->label(t("Full name"))->id("g-fullname");
$group->password("password")->label(t("Password"))->id("g-password");
- $group->password("password2")->label(t("Confirm Password"))->id("g-password2")
+ $group->password("password2")->label(t("Confirm password"))->id("g-password2")
->matches($group->password);
$group->input("email")->label(t("Email"))->id("g-email");
$group->input("url")->label(t("URL"))->id("g-url");
@@ -374,7 +372,7 @@ class Admin_Users_Controller extends Admin_Controller {
/* Group Form Definitions */
private function _get_group_edit_form_admin($group) {
$form = new Forge("admin/users/edit_group/$group->id", "", "post", array("id" => "g-edit-group-form"));
- $form_group = $form->group("edit_group")->label(t("Edit Group"));
+ $form_group = $form->group("edit_group")->label(t("Edit group"));
$form_group->input("name")->label(t("Name"))->id("g-name")->value($group->name);
$form_group->inputs["name"]->error_messages(
"in_use", t("There is already a group with that name"));
@@ -386,11 +384,11 @@ class Admin_Users_Controller extends Admin_Controller {
private function _get_group_add_form_admin() {
$form = new Forge("admin/users/add_group", "", "post", array("id" => "g-add-group-form"));
$form->set_attr('class', "g-one-quarter");
- $form_group = $form->group("add_group")->label(t("Add Group"));
+ $form_group = $form->group("add_group")->label(t("Add group"));
$form_group->input("name")->label(t("Name"))->id("g-name");
$form_group->inputs["name"]->error_messages(
"in_use", t("There is already a group with that name"));
- $form_group->submit("")->value(t("Add Group"));
+ $form_group->submit("")->value(t("Add group"));
$form->add_rules_from(ORM::factory("group"));
return $form;
}
diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php
index e3dbacb7..cf91812e 100644
--- a/modules/user/helpers/user_event.php
+++ b/modules/user/helpers/user_event.php
@@ -20,17 +20,11 @@
class user_event_Core {
static function admin_menu($menu, $theme) {
- $menu->get("identity_menu")
- ->append(Menu::factory("link")
- ->id("users_groups")
- ->label(t("Users/Groups"))
- ->url(url::site("admin/users")));
+ $menu->add_after("appearance_menu", Menu::factory("link")
+ ->id("users_groups")
+ ->label(t("Users/Groups"))
+ ->url(url::site("admin/users")));
return $menu;
}
-
- static function check_username_exists($data) {
- $user = user::lookup_by_name($data->name);
- $data->exists |= $user ? true : false;
- }
}
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index 9aad4130..0cba502f 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -70,8 +70,18 @@ class user_installer {
$admin->admin = true;
$admin->save();
- // Let the admin own everything
- $db->query("update {items} set owner_id = {$admin->id}");
+ $current_provider = module::get_var("gallery", "identity_provider");
+ if (empty($current_provider)) {
+ // If there is no provider defined then we are doing an initial install
+ // so we need to set the provider and make the administrator own everything
+ // If the installer is called and there is an identity provider, then we
+ // are switching identity providers and and the event handlers will do the
+ // right things
+ module::set_var("gallery", "identity_provider", "user");
+
+ // Let the admin own everything
+ $db->query("update {items} set owner_id = {$admin->id}");
+ }
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);