aboutsummaryrefslogtreecommitdiff
path: root/mod/landing/start.php
blob: 05ccac9fb41f4caa6591fdcb8e7c60e86981fa1c (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
 * Landing Page Plugin for Elgg 1.8
 *
 * @author: hellekin <hellekin@lorea.org>
 * @copyright: 2012 Lorea Faeries <federation@lorea.org>
 * @license: GNU Affero General Public License version 3 or later
 * @package: ElggLanding
 */

elgg_register_event_handler('init', 'system', 'landing_init');

function landing_init() {
	// Register Tests
	elgg_register_plugin_hook_handler('unit_test', 'system', 'landing_test');

	// Register CSS
	elgg_extend_view('css', 'landing/css');

	// Register Login Event Handler
	elgg_register_event_handler('login', 'user', 'landing_login_handler');

}

/**
 * Test the plugin
 */
function landing_test($hook, $type, $value, $params) {
	$value[] = 'landing/test/landing_test.php';
	return $value;
}

/**
 * Redirect user to chosen landing page upon login
 */
function landing_login_handler($event, $type, $user) {
	global $forward_url;

	if (empty($forward_url)) {
		$forward_url = landing_page_url();
	}

	return NULL;
}

function landing_page_url() {

	$user = elgg_get_logged_in_user_entity();
	if (!($user instanceof ElggUser)) {
		return '';
	}

	$mode = get_plugin_usersetting('landing_mode', $user->guid, 'landing');

	switch($mode) {
	case 'profile':
		if (elgg_is_active_plugin('profile')) {
			$forward_url = "/profile/{$user->username}";
		} else {
			$forward_url = "/view/{$user->guid}";
		}
		break;
	case 'custom':
		$forward_url = get_plugin_usersetting('landing_url', $user->guid, 'landing');
		break;
	case 'dashboard':
		if (elgg_is_active_plugin('dashboard')) {
			$forward_url = '/dashboard';
			break;
		}
	case 'default':
	default:
		$forward_url = '';
		break;
	}

	return $forward_url;
}