-
Notifications
You must be signed in to change notification settings - Fork 1
/
loginlogout.module
65 lines (59 loc) · 1.83 KB
/
loginlogout.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* Implementation of hook_user()
*
*/
function loginlogout_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'logout':
if (!$_REQUEST['destination']) break;
global $user ;
$user_temp = $user;
$user = user_load(0);
$item = menu_get_item($_REQUEST['destination']);
if (!$item['access']) $_REQUEST['destination'] = '';
$user = $user_temp;
break;
}
}
/*
* Implementation of hook_init()
*
*/
function loginlogout_init() {
$path = drupal_get_path('module', 'loginlogout');
drupal_add_js($path .'/loginlogout.js');
$settings = array('loginlogout' => array(
'destination' => drupal_get_destination(),
));
$settings['loginlogout']['urls'] = array(
url('user/login') => url('user/login', array('query'=>drupal_get_destination())),
url('logout') => url('logout', array('query'=>drupal_get_destination())),
);
if (!user_is_logged_in()) { // fixme
$settings['loginlogout']['urls'][url('user')] = url('user', array('query'=>drupal_get_destination()));
}
$paths = variable_get('loginlogout_additional_urls','');
if (!is_array($paths)) $paths = explode("\n",$paths);
foreach($paths as $path) {
$url = url(trim($path));
if ($url) $settings['loginlogout']['urls'][$url] = url($path, array('query'=>drupal_get_destination()));
}
drupal_add_js($settings ,'setting');
}
/*
* Implementation of hook_menu()
*
*/
function loginlogout_menu() {
$items['admin/settings/loginlogout'] = array(
'title' => 'Login logout settings',
'description' => 'Configure login logout settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('loginlogout_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'loginlogout.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}