|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WET 4 Collab Theme plugin |
|
4
|
|
|
* |
|
5
|
|
|
* @package wet4Theme |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
elgg_register_event_handler('init', 'system', 'wet4_collab_theme_init'); |
|
9
|
|
|
|
|
10
|
|
|
function wet4_collab_theme_init() { |
|
11
|
|
|
|
|
12
|
|
|
// theme specific CSS |
|
13
|
|
|
elgg_extend_view('css/elgg', 'wet4_theme/css'); |
|
14
|
|
|
elgg_extend_view('css/elgg', 'wet4_theme/custom_css'); |
|
15
|
|
|
|
|
16
|
|
|
//message preview |
|
17
|
|
|
elgg_register_ajax_view("messages/message_preview"); |
|
18
|
|
|
|
|
19
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:user_menu', 'remove_custom_colleagues_menu_item', 1); |
|
20
|
|
|
elgg_register_event_handler('pagesetup', 'system', 'add_custom_colleagues_menu_item', 1000); |
|
21
|
|
|
|
|
22
|
|
|
elgg_unregister_plugin_hook_handler('usersettings:save', 'user', '_elgg_set_user_email'); |
|
23
|
|
|
elgg_register_plugin_hook_handler('usersettings:save', 'user', 'change_user_email'); |
|
24
|
|
|
|
|
25
|
|
|
elgg_define_js('moment', [ |
|
26
|
|
|
'src' => '/mod/wet4_collab/views/default/js/moment/moment.js', |
|
27
|
|
|
'deps' => array('jquery') |
|
28
|
|
|
]); |
|
29
|
|
|
|
|
30
|
|
|
elgg_unregister_js('elgg.full_calendar'); |
|
31
|
|
|
$calendar_js = elgg_get_simplecache_url('js', 'event_calendar/fullcalendar.min.js'); |
|
32
|
|
|
elgg_register_simplecache_view('js/event_calendar/fullcalendar.min.js'); |
|
33
|
|
|
elgg_register_js('elgg.full_calendar', $calendar_js); |
|
34
|
|
|
|
|
35
|
|
|
$calendar_css = elgg_get_simplecache_url('css', 'event_calendar/fullcalendar.min.css'); |
|
36
|
|
|
elgg_register_css('elgg.full_calendar', $calendar_css); |
|
37
|
|
|
|
|
38
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:site', 'remove_menu_item_handler_collab'); |
|
39
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
function remove_menu_item_handler_collab($hook, $type, $menu, $params){ |
|
43
|
|
|
foreach ($menu as $key => $item){ |
|
44
|
|
|
error_log($item->getName()); |
|
45
|
|
|
switch ($item->getName()){ |
|
46
|
|
|
case 'mission_main': |
|
47
|
|
|
unset($menu[$key]); |
|
48
|
|
|
break; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
return $menu; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function remove_custom_colleagues_menu_item($hook, $type, $return, $params) { |
|
55
|
|
|
// Remove Colleagues menu item |
|
56
|
|
|
foreach($return as $key => $item) { |
|
57
|
|
|
if ($item->getName() == 'Colleagues') { |
|
58
|
|
|
unset($return[$key]); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
return $return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function add_custom_colleagues_menu_item() { |
|
65
|
|
|
$user = elgg_get_logged_in_user_entity(); |
|
66
|
|
|
|
|
67
|
|
|
if( !empty($user) ){ |
|
68
|
|
|
$options = array( |
|
69
|
|
|
"type" => "user", |
|
70
|
|
|
"count" => true, |
|
71
|
|
|
"relationship" => "friendrequest", |
|
72
|
|
|
"relationship_guid" => $user->getGUID(), |
|
73
|
|
|
"inverse_relationship" => true |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$count = elgg_get_entities_from_relationship($options); |
|
77
|
|
|
|
|
78
|
|
|
$countTitle = " - "; |
|
79
|
|
|
$countBadge = ""; |
|
80
|
|
|
if( $count > 0 ){ |
|
81
|
|
|
//display 9+ instead of huge numbers in notif badge |
|
82
|
|
|
if( $count >= 10 ){ |
|
83
|
|
|
$countTitle .= '9+'; |
|
84
|
|
|
} else { |
|
85
|
|
|
$countTitle .= $count; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$countBadge = "<span class='notif-badge'>" . $count . "</span>"; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$params = array( |
|
92
|
|
|
"name" => "Colleaguess", |
|
93
|
|
|
"href" => "friends/" . $user->username, |
|
94
|
|
|
"text" => '<i class="fa fa-users mrgn-rght-sm mrgn-tp-sm fa-lg"></i>' . $countBadge, |
|
95
|
|
|
"title" => elgg_echo('userMenu:colleagues') . $countTitle . elgg_echo('friend_request') .'(s)', |
|
96
|
|
|
"class" => '', |
|
97
|
|
|
"item_class" => '', |
|
98
|
|
|
"priority" => '1' |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
elgg_register_menu_item("user_menu", $params); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
function change_user_email() { |
|
106
|
|
|
$email = get_input('email'); |
|
107
|
|
|
$user_guid = get_input('guid'); |
|
108
|
|
|
|
|
109
|
|
|
if ($user_guid) { |
|
110
|
|
|
$user = get_user($user_guid); |
|
111
|
|
|
} else { |
|
112
|
|
|
$user = elgg_get_logged_in_user_entity(); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if (!is_email_address($email)) { |
|
116
|
|
|
register_error(elgg_echo('email:save:fail')); |
|
117
|
|
|
return false; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
elgg_load_library('c_ext_lib'); |
|
121
|
|
|
$isValid = false; |
|
122
|
|
|
|
|
123
|
|
View Code Duplication |
if ($email) { |
|
124
|
|
|
// cyu - check if the email is in the list of exceptions |
|
125
|
|
|
$user_email = explode('@',$email); |
|
126
|
|
|
$list_of_domains = getExtension(); |
|
127
|
|
|
|
|
128
|
|
|
if( elgg_is_active_plugin('c_email_extensions') ){ |
|
129
|
|
|
// Checks against the domain manager list... |
|
130
|
|
|
$wildcard_query = "SELECT ext FROM email_extensions WHERE ext LIKE '%*%'"; |
|
131
|
|
|
$wildcard_emails = get_data($wildcard_query); |
|
132
|
|
|
|
|
133
|
|
|
if( $wildcard_emails ){ |
|
|
|
|
|
|
134
|
|
|
foreach($wildcard_emails as $wildcard){ |
|
135
|
|
|
$regex = str_replace(".", "\.", $wildcard->ext); |
|
136
|
|
|
$regex = str_replace("*", "[\w-.]+", $regex); |
|
137
|
|
|
$regex = "/^@" . $regex . "$/"; |
|
138
|
|
|
if(preg_match($regex, "@".$user_email[1]) || strtolower(str_replace("*.", "", $wildcard->ext)) == strtolower($user_email[1])){ |
|
139
|
|
|
$isValid = true; |
|
140
|
|
|
break; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
if( elgg_is_active_plugin('gcRegistration_invitation') ){ |
|
147
|
|
|
// Checks against the email invitation list... |
|
148
|
|
|
$invitation_query = "SELECT email FROM email_invitations WHERE email = '{$email}'"; |
|
149
|
|
|
$result = get_data($invitation_query); |
|
150
|
|
|
|
|
151
|
|
|
if( count($result) > 0 ) |
|
152
|
|
|
$isValid = true; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
if (count($list_of_domains) > 0) { |
|
156
|
|
|
while ($row = mysqli_fetch_array($list_of_domains)) { |
|
157
|
|
|
if (strtolower($row['ext']) === strtolower($user_email[1])) { |
|
158
|
|
|
$isValid = true; |
|
159
|
|
|
break; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
$error_message = elgg_echo('gcc_profile:error').elgg_echo('gcc_profile:notaccepted'); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
// cyu - check if domain is gc.ca |
|
166
|
|
|
if (!$isValid) { |
|
167
|
|
|
$govt_domain = explode('.',$user_email[1]); |
|
168
|
|
|
$govt_domain_len = count($govt_domain) - 1; |
|
169
|
|
|
|
|
170
|
|
|
if ($govt_domain[$govt_domain_len - 1].'.'.$govt_domain[$govt_domain_len] === 'gc.ca') { |
|
171
|
|
|
$isValid = true; |
|
172
|
|
|
} else { |
|
173
|
|
|
$isValid = false; |
|
174
|
|
|
$error_message = elgg_echo('gcc_profile:error').elgg_echo('gcc_profile:notaccepted'); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
if( !$isValid ){ |
|
180
|
|
|
if( elgg_is_active_plugin('b_extended_profile_collab') ){ |
|
181
|
|
|
prepare_email_change($user_guid, $email); |
|
182
|
|
|
} else { |
|
183
|
|
|
register_error($error_message); |
|
|
|
|
|
|
184
|
|
|
} |
|
185
|
|
|
} else { |
|
186
|
|
|
if ($user) { |
|
187
|
|
|
if (strcmp($email, $user->email) != 0) { |
|
188
|
|
|
if (!get_user_by_email($email)) { |
|
189
|
|
|
if ($user->email != $email) { |
|
190
|
|
|
|
|
191
|
|
|
$user->email = $email; |
|
192
|
|
|
if ($user->save()) { |
|
193
|
|
|
system_message(elgg_echo('email:save:success')); |
|
194
|
|
|
return true; |
|
195
|
|
|
} else { |
|
196
|
|
|
register_error(elgg_echo('email:save:fail')); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
} else { |
|
200
|
|
|
register_error(elgg_echo('registration:dupeemail')); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
} else { |
|
204
|
|
|
register_error(elgg_echo('email:save:fail')); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
return false; |
|
209
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.