/
start.php
executable file
·152 lines (126 loc) · 3.95 KB
/
start.php
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Elgg welcome plugin start
*
* @author Gerard Kanters
* @author Wouter van Os
* @author Juho Jaakkola
*
* @website https://www.centillien.com
*
* @copyright Centillien 2016
*/
elgg_register_event_handler('init', 'system', 'welcome_init');
/**
* Initialize the plugin
*/
function welcome_init()
{
if (elgg_is_admin_logged_in()) {
elgg_unregister_plugin_hook_handler('validate', 'input', 'htmlawed_filter_tags');
}
elgg_register_page_handler('welcome', 'welcome_page_handler');
elgg_register_plugin_hook_handler('forward', 'system', 'welcome_forward_hook', 600);
//Register action path for email change
$action_path = dirname(__FILE__) . '/actions';
elgg_register_action('welcome/change_user_email', "$action_path/change_user_email.php", 'public');
elgg_register_ajax_view('welcome/change_email');
//Support for walled garden
elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'welcome_public_pages');
}
/**
* Directs user to welcome page after successful registration
*
* @param string $hook_name 'forward'
* @param string $type 'system'
* @param string $return The url that user is being forwarded to
* @param array $params Hook parameters
*
* @return string $forward_url The new forward url
*/
function welcome_forward_hook($hook_name, $type, $return, $params)
{
$current = current_page_url();
// Check whether user is being forwarded from the registration action
if (strpos($current, 'action/register') === false) {
return $return;
}
$username = get_input('username');
// User validation by email has disabled the user so we need to
// explicitly include hidden entities in the database query
$hidden_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$user = get_user_by_username($username);
// Set hidden entity status back to normal
access_show_hidden_entities($hidden_status);
if (!$user) {
// User does not exist meaning that registration failed
return $return;
}
// Pass on the user GUID in the url so the welcome page can access the user
$welcome_url = elgg_normalize_url('welcome/' . $user->guid);
return $welcome_url;
}
/**
* Handle requests to /welcome/
*
* @param array $page Page segments
*
* @return boolean
*/
function welcome_page_handler($page)
{
// User validation by email has disabled the user so we need to
// explicitly include hidden entities in the database query
$hidden_status = access_get_show_hidden_status();
access_show_hidden_entities(true);
$user = get_user($page[0]);
// Set hidden entity status back to normal
access_show_hidden_entities($hidden_status);
if (!$user) {
forward();
}
set_input('guid', $user->guid);
$base = elgg_get_plugins_path() . 'welcome/pages/';
switch ($page[0]) {
default:
include $base . '/welcome.php';
break;
}
return true;
}
/**
* Extend public pages for walled garden
*
* @param string $hook_name 'public_pages'
* @param string $entity 'walled_garden'
* @param array $return_value Array of public pages
* @param array $params Hook parameters
*
* @return array
*/
function welcome_public_pages($hook_name, $entity, $return, $params)
{
$return[] = "welcome/*"; // for backwards compatibility
$return[] = 'welcome\/[0-9]+';
return $return;
}
/**
* Validate a e-mail adress on it's domain, check
* if an MX records exists for that domain.
*
* @param string $email E-mail address to validate
*
* @return bool
*/
function checkEmail($email)
{
// Get domain from e-mailadres
list(,$domain) = explode('@', $email);
// Check if MX record exists for domain
if (!checkdnsrr($domain, 'MX')) {
return false;
} else {
return true;
}
}