-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.php
More file actions
284 lines (247 loc) · 7.86 KB
/
Copy pathstart.php
File metadata and controls
284 lines (247 loc) · 7.86 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/*
* The lunch plugin is responsible for:
* 1. Lunch entity
* 2. Topic entity
* 3. School entity (extends Group)
*
*/
function lunch_init() {
/**
* Shared libraries, CSS and JS
*/
elgg_register_library('elgg:lunch', elgg_get_plugins_path() . 'lunch/lib/lunch.php');
elgg_register_library('elgg:lunch:api', elgg_get_plugins_path() . 'lunch/lib/api.php');
elgg_register_css('fullcalendar', "/mod/lunch/vendors/fullcalendar/fullcalendar.css");
elgg_register_js('fullcalendar', "/mod/lunch/vendors/fullcalendar/fullcalendar.js");
elgg_load_library('elgg:lunch:api');
/**
* Action registrations
*/
elgg_register_action("lunch/save", elgg_get_plugins_path() . "lunch/actions/lunch/save.php");
elgg_register_action("lunch/delete", elgg_get_plugins_path() . "lunch/actions/lunch/delete.php");
elgg_register_action("topic/save", elgg_get_plugins_path() . "lunch/actions/topic/save.php");
/**
* Page handlers
*/
elgg_register_page_handler('lunch', 'lunch_page_handler');
elgg_register_page_handler('topic', 'topic_page_handler');
elgg_register_page_handler('map', 'map_page_handler');
elgg_register_page_handler('calendar', 'calendar_page_handler');
elgg_register_page_handler('howto', 'howto_page_handler');
elgg_register_page_handler('activity', 'activity_page_handler');
/**
* Plugin hook handlers
*/
elgg_register_plugin_hook_handler('index', 'system', 'lunch_index'); // Override index
elgg_register_plugin_hook_handler('login', 'lunch', 'lunch_index'); // Override login
elgg_register_plugin_hook_handler('profile:fields', 'group', 'lunch_school_profile_fields', 1);
elgg_register_plugin_hook_handler('action', 'groups/edit', 'lunch_address_hook');
elgg_register_plugin_hook_handler('register', 'user', 'lunch_register_hook');
elgg_register_plugin_hook_handler('prepare', 'menu:page', 'menu_hook_handler', 1000);
elgg_register_plugin_hook_handler('prepare', 'menu:extras', 'menu_hook_handler', 1000);
elgg_register_plugin_hook_handler('prepare', 'menu:site', 'menu_hook_handler', 1000);
elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'gravatar_hook_handler', 900); // Gravatar support
elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'public_pages_hook_handler'); // Make some pages public
/**
* Menu registration
*/
elgg_register_menu_item('site', array('name' => 'howto', 'text' => 'How-to', 'href' => '/howto'));
elgg_register_menu_item('site', array('name' => 'schools', 'text' => 'Schools', 'href' => '/map'));
elgg_register_menu_item('site', array('name' => 'calendar', 'text' => 'Calendar', 'href' => '/calendar'));
elgg_register_menu_item('site', array('name' => 'topics', 'text' => 'Topics', 'href' => '/topic'));
/**
* Event Handlers
*/
elgg_register_event_handler('delete', 'all', 'lunch_delete_handler');
/**
* Extend views
*/
elgg_extend_view('groups/tool_latest', 'lunch/group_module');
elgg_extend_view('css/elgg', 'lunch/css');
/**
* Group customizations
*/
remove_group_tool_option('activity');
remove_group_tool_option('forum');
}
/*
* Plugin hook handlers
*/
function lunch_school_profile_fields($hook, $type, $fields, $params) {
return array(
'street' => 'text',
'city' => 'text',
'geocode' => 'hidden',
// 'briefdescription' => 'text',
'description' => 'longtext',
// 'interests' => 'tags',
'activity_enable' => 'hidden',
'forum_enable' => 'hidden',
);
}
// Converts school address to geocode using Google API
function lunch_address_hook($hook, $type, $fields, $params) {
elgg_load_library('elgg:lunch');
$street = urlencode(get_input('street'));
$city = urlencode(get_input('city'));
$json = lunch_geocode($street . ',+' . $city);
set_input('geocode', $json['results'][0]['geometry']['location']);
set_input('activity_enable', 'no');
set_input('forum_enable', 'no');
return true;
}
// Sets username to guid
function lunch_register_hook($hook, $type, $fields, $params) {
// Set username to guid
$guid = $params['user']->getGUID();
$user = get_entity($guid);
$user->__set("username", $guid);
// Set graduation metadata
$graduation = (int) get_input('graduation');
$user->graduation = graduation;
return true;
}
/**
* Delete Event
* TODO: Basic recycle bin
*/
function lunch_delete_handler($event, $type, $params) {
switch($type) {
case 'group':
// Delete if admin
if (elgg_is_admin_logged_in ()) {
return true;
}
// Otherwise, disable
$group = get_entity($params->getGUID());
$group->disable();
return false;
}
return true;
}
/*
* Page Handlers
*
*/
function lunch_page_handler($segments) {
switch ($segments[0]) {
case 'add':
include elgg_get_plugins_path() . 'lunch/pages/lunch/add.php';
break;
case 'all':
default:
include elgg_get_plugins_path() . 'lunch/pages/lunch/all.php';
break;
}
return true;
}
function topic_page_handler($segments) {
switch ($segments[0]) {
case 'icon':
include elgg_get_plugins_path() . 'lunch/pages/topic/icon.php';
break;
case 'add':
include elgg_get_plugins_path() . 'lunch/pages/topic/add.php';
break;
case 'view':
include elgg_get_plugins_path() . 'lunch/pages/topic/view.php';
break;
case 'all':
default:
include elgg_get_plugins_path() . 'lunch/pages/topic/all.php';
break;
}
return true;
}
function map_page_handler($segments) {
include elgg_get_plugins_path() . 'lunch/pages/map/index.php';
return true;
}
function calendar_page_handler($segments) {
include elgg_get_plugins_path() . 'lunch/pages/calendar/index.php';
return true;
}
function howto_page_handler($segments) {
include elgg_get_plugins_path() . 'lunch/pages/howto/index.php';
return true;
}
function activity_page_handler($segments) {
include elgg_get_plugins_path() . 'lunch/pages/activity/index.php';
return true;
}
/**
* add menu item to owner block
*/
function lunch_gatekeeper($redirect = true) {
elgg_load_library('elgg:lunch');
if (!is_lunch_moderator()) {
register_error("You must be a moderator to view that page.");
if ($redirect) {
forward(REFERER); // REFERER is a global variable that defines the previous page
} else {
return false;
}
}
return true;
}
/*
* Removes menu items from other plugins
*/
function menu_hook_handler($hook, $type, $items, $params) {
// Move all items out of 'more' array
$items['default'] = array_merge($items['default'], $items['more']);
unset($items['more']);
foreach ($items['default'] as $key => $item) {
switch ($item->getName()) {
case 'groups:all':
case 'groups:member':
case 'groups:owned':
case 'groups:user:invites':
case 'rss':
case 'activity':
case 'blog':
case 'groups':
case 'more':
unset($items['default'][$key]);
break;
}
}
return $items;
}
/**
* Add Gravatar to user icons
*/
function gravatar_hook_handler($hook, $type, $url, $params) {
// check if user already has an icon
if (!$params['entity']->icontime) {
$icon_sizes = elgg_get_config('icon_sizes');
$size = $params['size'];
if (!in_array($size, array_keys($icon_sizes))) {
$size = 'small';
}
// avatars must be square
$size = $icon_sizes[$size]['w'];
$hash = md5($params['entity']->email);
return "https://secure.gravatar.com/avatar/$hash.jpg?d=mm&s=$size";
}
}
/**
* Extend the public pages range
*
*/
function public_pages_hook_handler($hook, $handler, $return, $params){
// These pages will be public!
$pages = array(
'mod/lunch/vendors/fullcalendar/.*', // Contains calendar javascript
'calendar', // Calendar menubar
'index', // Homepage
'map', // Map menubar
'topic', // Topics menubar
'howto', // Howto menu bar
'groupicon/.*', // School logos
);
return array_merge($pages, $return);
}
elgg_register_event_handler('init', 'system', 'lunch_init');
?>