1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Groups function library |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* List all groups |
8
|
|
|
*/ |
9
|
|
|
function groups_handle_all_page() { |
|
|
|
|
10
|
|
|
|
11
|
|
|
// all groups doesn't get link to self |
12
|
|
|
elgg_pop_breadcrumb(); |
13
|
|
|
elgg_push_breadcrumb(elgg_echo('groups')); |
14
|
|
|
|
15
|
|
|
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) { |
16
|
|
|
elgg_register_title_button(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
$selected_tab = get_input('filter', 'newest'); |
20
|
|
|
|
21
|
|
|
switch ($selected_tab) { |
22
|
|
|
case 'popular': |
23
|
|
|
$content = elgg_list_entities_from_relationship_count(array( |
24
|
|
|
'type' => 'group', |
25
|
|
|
'relationship' => 'member', |
26
|
|
|
'inverse_relationship' => false, |
27
|
|
|
'full_view' => false, |
28
|
|
|
'no_results' => elgg_echo('groups:none'), |
29
|
|
|
)); |
30
|
|
|
break; |
31
|
|
|
case 'discussion': |
32
|
|
|
$content = elgg_list_entities(array( |
33
|
|
|
'type' => 'object', |
34
|
|
|
'subtype' => 'groupforumtopic', |
35
|
|
|
'order_by' => 'e.last_action desc', |
36
|
|
|
'limit' => 40, |
37
|
|
|
'full_view' => false, |
38
|
|
|
'no_results' => elgg_echo('discussion:none'), |
39
|
|
|
'distinct' => false, |
40
|
|
|
'preload_containers' => true, |
41
|
|
|
)); |
42
|
|
|
break; |
43
|
|
|
case 'featured': |
44
|
|
|
$content = elgg_list_entities_from_metadata(array( |
45
|
|
|
'type' => 'group', |
46
|
|
|
'metadata_name' => 'featured_group', |
47
|
|
|
'metadata_value' => 'yes', |
48
|
|
|
'full_view' => false, |
49
|
|
|
)); |
50
|
|
|
if (!$content) { |
51
|
|
|
$content = elgg_echo('groups:nofeatured'); |
52
|
|
|
} |
53
|
|
|
break; |
54
|
|
|
case 'newest': |
55
|
|
View Code Duplication |
default: |
56
|
|
|
$content = elgg_list_entities(array( |
57
|
|
|
'type' => 'group', |
58
|
|
|
'full_view' => false, |
59
|
|
|
'no_results' => elgg_echo('groups:none'), |
60
|
|
|
'distinct' => false, |
61
|
|
|
)); |
62
|
|
|
break; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$filter = elgg_view('groups/group_sort_menu', array('selected' => $selected_tab)); |
66
|
|
|
|
67
|
|
|
$sidebar = elgg_view('groups/sidebar/find'); |
68
|
|
|
$sidebar .= elgg_view('groups/sidebar/featured'); |
69
|
|
|
|
70
|
|
|
$params = array( |
71
|
|
|
'content' => $content, |
72
|
|
|
'sidebar' => $sidebar, |
73
|
|
|
'filter' => $filter, |
74
|
|
|
); |
75
|
|
|
$body = elgg_view_layout('content', $params); |
76
|
|
|
|
77
|
|
|
echo elgg_view_page(elgg_echo('groups:all'), $body); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
function groups_search_page() { |
|
|
|
|
81
|
|
|
elgg_push_breadcrumb(elgg_echo('search')); |
82
|
|
|
|
83
|
|
|
$tag = get_input("tag"); |
84
|
|
|
$display_query = _elgg_get_display_query($tag); |
85
|
|
|
$title = elgg_echo('groups:search:title', array($display_query)); |
86
|
|
|
|
87
|
|
|
// groups plugin saves tags as "interests" - see groups_fields_setup() in start.php |
88
|
|
|
$params = array( |
89
|
|
|
'metadata_name' => 'interests', |
90
|
|
|
'metadata_value' => $tag, |
91
|
|
|
'type' => 'group', |
92
|
|
|
'full_view' => false, |
93
|
|
|
'no_results' => elgg_echo('groups:search:none'), |
94
|
|
|
); |
95
|
|
|
$content = elgg_list_entities_from_metadata($params); |
96
|
|
|
|
97
|
|
|
$sidebar = elgg_view('groups/sidebar/find'); |
98
|
|
|
$sidebar .= elgg_view('groups/sidebar/featured'); |
99
|
|
|
|
100
|
|
|
$params = array( |
101
|
|
|
'content' => $content, |
102
|
|
|
'sidebar' => $sidebar, |
103
|
|
|
'filter' => false, |
104
|
|
|
'title' => $title, |
105
|
|
|
); |
106
|
|
|
$body = elgg_view_layout('content', $params); |
107
|
|
|
|
108
|
|
|
echo elgg_view_page($title, $body); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* List owned groups |
113
|
|
|
*/ |
114
|
|
View Code Duplication |
function groups_handle_owned_page() { |
|
|
|
|
115
|
|
|
|
116
|
|
|
$page_owner = elgg_get_page_owner_entity(); |
117
|
|
|
|
118
|
|
|
if ($page_owner->guid == elgg_get_logged_in_user_guid()) { |
119
|
|
|
$title = elgg_echo('groups:owned'); |
120
|
|
|
} else { |
121
|
|
|
$title = elgg_echo('groups:owned:user', array($page_owner->name)); |
122
|
|
|
} |
123
|
|
|
elgg_push_breadcrumb($title); |
124
|
|
|
|
125
|
|
|
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) { |
126
|
|
|
elgg_register_title_button(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$dbprefix = elgg_get_config('dbprefix'); |
130
|
|
|
$content = elgg_list_entities(array( |
131
|
|
|
'type' => 'group', |
132
|
|
|
'owner_guid' => elgg_get_page_owner_guid(), |
133
|
|
|
'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"), |
134
|
|
|
'order_by' => 'ge.name ASC', |
135
|
|
|
'full_view' => false, |
136
|
|
|
'no_results' => elgg_echo('groups:none'), |
137
|
|
|
'distinct' => false, |
138
|
|
|
)); |
139
|
|
|
|
140
|
|
|
$params = array( |
141
|
|
|
'content' => $content, |
142
|
|
|
'title' => $title, |
143
|
|
|
'filter' => '', |
144
|
|
|
); |
145
|
|
|
$body = elgg_view_layout('content', $params); |
146
|
|
|
|
147
|
|
|
echo elgg_view_page($title, $body); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* List groups the user is memober of |
152
|
|
|
*/ |
153
|
|
View Code Duplication |
function groups_handle_mine_page() { |
|
|
|
|
154
|
|
|
|
155
|
|
|
$page_owner = elgg_get_page_owner_entity(); |
156
|
|
|
|
157
|
|
|
if ($page_owner->guid == elgg_get_logged_in_user_guid()) { |
158
|
|
|
$title = elgg_echo('groups:yours'); |
159
|
|
|
} else { |
160
|
|
|
$title = elgg_echo('groups:user', array($page_owner->name)); |
161
|
|
|
} |
162
|
|
|
elgg_push_breadcrumb($title); |
163
|
|
|
|
164
|
|
|
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) { |
165
|
|
|
elgg_register_title_button(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$dbprefix = elgg_get_config('dbprefix'); |
169
|
|
|
|
170
|
|
|
$content = elgg_list_entities_from_relationship(array( |
171
|
|
|
'type' => 'group', |
172
|
|
|
'relationship' => 'member', |
173
|
|
|
'relationship_guid' => elgg_get_page_owner_guid(), |
174
|
|
|
'inverse_relationship' => false, |
175
|
|
|
'full_view' => false, |
176
|
|
|
'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"), |
177
|
|
|
'order_by' => 'ge.name ASC', |
178
|
|
|
'no_results' => elgg_echo('groups:none'), |
179
|
|
|
)); |
180
|
|
|
|
181
|
|
|
$params = array( |
182
|
|
|
'content' => $content, |
183
|
|
|
'title' => $title, |
184
|
|
|
'filter' => '', |
185
|
|
|
); |
186
|
|
|
$body = elgg_view_layout('content', $params); |
187
|
|
|
|
188
|
|
|
echo elgg_view_page($title, $body); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Create or edit a group |
193
|
|
|
* |
194
|
|
|
* @param string $page |
195
|
|
|
* @param int $guid |
196
|
|
|
*/ |
197
|
|
View Code Duplication |
function groups_handle_edit_page($page, $guid = 0) { |
|
|
|
|
198
|
|
|
elgg_gatekeeper(); |
199
|
|
|
|
200
|
|
|
elgg_require_js('elgg/groups/edit'); |
201
|
|
|
|
202
|
|
|
if ($page == 'add') { |
203
|
|
|
elgg_set_page_owner_guid(elgg_get_logged_in_user_guid()); |
204
|
|
|
$title = elgg_echo('groups:add'); |
205
|
|
|
elgg_push_breadcrumb($title); |
206
|
|
|
if (elgg_get_plugin_setting('limited_groups', 'groups') != 'yes' || elgg_is_admin_logged_in()) { |
207
|
|
|
$content = elgg_view('groups/edit'); |
208
|
|
|
} else { |
209
|
|
|
$content = elgg_echo('groups:cantcreate'); |
210
|
|
|
} |
211
|
|
|
} else { |
212
|
|
|
$title = elgg_echo("groups:edit"); |
213
|
|
|
$group = get_entity($guid); |
214
|
|
|
|
215
|
|
|
if (elgg_instanceof($group, 'group') && $group->canEdit()) { |
216
|
|
|
elgg_set_page_owner_guid($group->getGUID()); |
217
|
|
|
elgg_push_breadcrumb($group->name, $group->getURL()); |
218
|
|
|
elgg_push_breadcrumb($title); |
219
|
|
|
$content = elgg_view("groups/edit", array('entity' => $group)); |
220
|
|
|
} else { |
221
|
|
|
$content = elgg_echo('groups:noaccess'); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$params = array( |
226
|
|
|
'content' => $content, |
227
|
|
|
'title' => $title, |
228
|
|
|
'filter' => '', |
229
|
|
|
); |
230
|
|
|
$body = elgg_view_layout('content', $params); |
231
|
|
|
|
232
|
|
|
echo elgg_view_page($title, $body); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Group invitations for a user |
237
|
|
|
*/ |
238
|
|
View Code Duplication |
function groups_handle_invitations_page() { |
|
|
|
|
239
|
|
|
elgg_gatekeeper(); |
240
|
|
|
|
241
|
|
|
$username = get_input('username'); |
242
|
|
|
if ($username) { |
243
|
|
|
$user = get_user_by_username($username); |
244
|
|
|
elgg_set_page_owner_guid($user->guid); |
245
|
|
|
} else { |
246
|
|
|
$user = elgg_get_logged_in_user_entity(); |
247
|
|
|
elgg_set_page_owner_guid($user->guid); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if (!$user || !$user->canEdit()) { |
251
|
|
|
register_error(elgg_echo('noaccess')); |
252
|
|
|
forward(''); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$title = elgg_echo('groups:invitations'); |
256
|
|
|
elgg_push_breadcrumb($title); |
257
|
|
|
|
258
|
|
|
$content = elgg_view('groups/invitationrequests'); |
259
|
|
|
|
260
|
|
|
$params = array( |
261
|
|
|
'content' => $content, |
262
|
|
|
'title' => $title, |
263
|
|
|
'filter' => '', |
264
|
|
|
); |
265
|
|
|
$body = elgg_view_layout('content', $params); |
266
|
|
|
|
267
|
|
|
echo elgg_view_page($title, $body); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Group profile page |
272
|
|
|
* |
273
|
|
|
* @param int $guid Group entity GUID |
274
|
|
|
*/ |
275
|
|
View Code Duplication |
function groups_handle_profile_page($guid) { |
|
|
|
|
276
|
|
|
elgg_set_page_owner_guid($guid); |
277
|
|
|
|
278
|
|
|
// turn this into a core function |
279
|
|
|
global $autofeed; |
280
|
|
|
$autofeed = true; |
281
|
|
|
|
282
|
|
|
elgg_push_context('group_profile'); |
283
|
|
|
|
284
|
|
|
elgg_entity_gatekeeper($guid, 'group'); |
285
|
|
|
|
286
|
|
|
$group = get_entity($guid); |
287
|
|
|
|
288
|
|
|
elgg_push_breadcrumb($group->name); |
289
|
|
|
|
290
|
|
|
groups_register_profile_buttons($group); |
|
|
|
|
291
|
|
|
|
292
|
|
|
$content = elgg_view('groups/profile/layout', array('entity' => $group)); |
293
|
|
|
$sidebar = ''; |
294
|
|
|
|
295
|
|
|
if (elgg_group_gatekeeper(false)) { |
296
|
|
|
if (elgg_is_active_plugin('search')) { |
297
|
|
|
$sidebar .= elgg_view('groups/sidebar/search', array('entity' => $group)); |
298
|
|
|
} |
299
|
|
|
$sidebar .= elgg_view('groups/sidebar/members', array('entity' => $group)); |
300
|
|
|
|
301
|
|
|
$subscribed = false; |
302
|
|
|
if (elgg_is_active_plugin('notifications')) { |
303
|
|
|
$NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal(); |
304
|
|
|
foreach ($NOTIFICATION_HANDLERS as $method => $foo) { |
305
|
|
|
$relationship = check_entity_relationship(elgg_get_logged_in_user_guid(), |
306
|
|
|
'notify' . $method, $guid); |
307
|
|
|
|
308
|
|
|
if ($relationship) { |
309
|
|
|
$subscribed = true; |
310
|
|
|
break; |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
$sidebar .= elgg_view('groups/sidebar/my_status', array( |
316
|
|
|
'entity' => $group, |
317
|
|
|
'subscribed' => $subscribed |
318
|
|
|
)); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
$params = array( |
322
|
|
|
'content' => $content, |
323
|
|
|
'sidebar' => $sidebar, |
324
|
|
|
'title' => $group->name, |
325
|
|
|
); |
326
|
|
|
$body = elgg_view_layout('one_sidebar', $params); |
327
|
|
|
|
328
|
|
|
echo elgg_view_page($group->name, $body); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Group activity page |
333
|
|
|
* |
334
|
|
|
* @param int $guid Group entity GUID |
335
|
|
|
*/ |
336
|
|
View Code Duplication |
function groups_handle_activity_page($guid) { |
|
|
|
|
337
|
|
|
|
338
|
|
|
elgg_entity_gatekeeper($guid, 'group'); |
339
|
|
|
|
340
|
|
|
elgg_set_page_owner_guid($guid); |
341
|
|
|
|
342
|
|
|
elgg_group_gatekeeper(); |
343
|
|
|
|
344
|
|
|
$group = get_entity($guid); |
345
|
|
|
|
346
|
|
|
$title = elgg_echo('groups:activity'); |
347
|
|
|
|
348
|
|
|
elgg_push_breadcrumb($group->name, $group->getURL()); |
349
|
|
|
elgg_push_breadcrumb($title); |
350
|
|
|
|
351
|
|
|
$db_prefix = elgg_get_config('dbprefix'); |
352
|
|
|
|
353
|
|
|
$content = elgg_list_river(array( |
354
|
|
|
'joins' => array( |
355
|
|
|
"JOIN {$db_prefix}entities e1 ON e1.guid = rv.object_guid", |
356
|
|
|
"LEFT JOIN {$db_prefix}entities e2 ON e2.guid = rv.target_guid", |
357
|
|
|
), |
358
|
|
|
'wheres' => array( |
359
|
|
|
"(e1.container_guid = $group->guid OR e2.container_guid = $group->guid)", |
360
|
|
|
), |
361
|
|
|
'no_results' => elgg_echo('groups:activity:none'), |
362
|
|
|
)); |
363
|
|
|
|
364
|
|
|
$params = array( |
365
|
|
|
'content' => $content, |
366
|
|
|
'title' => $title, |
367
|
|
|
'filter' => '', |
368
|
|
|
); |
369
|
|
|
$body = elgg_view_layout('content', $params); |
370
|
|
|
|
371
|
|
|
echo elgg_view_page($title, $body); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Group members page |
376
|
|
|
* |
377
|
|
|
* @param int $guid Group entity GUID |
378
|
|
|
*/ |
379
|
|
|
function groups_handle_members_page($guid) { |
|
|
|
|
380
|
|
|
|
381
|
|
|
elgg_entity_gatekeeper($guid, 'group'); |
382
|
|
|
|
383
|
|
|
$group = get_entity($guid); |
384
|
|
|
|
385
|
|
|
elgg_set_page_owner_guid($guid); |
386
|
|
|
|
387
|
|
|
elgg_group_gatekeeper(); |
388
|
|
|
|
389
|
|
|
$title = elgg_echo('groups:members:title', array($group->name)); |
390
|
|
|
|
391
|
|
|
elgg_push_breadcrumb($group->name, $group->getURL()); |
392
|
|
|
elgg_push_breadcrumb(elgg_echo('groups:members')); |
393
|
|
|
|
394
|
|
|
$db_prefix = elgg_get_config('dbprefix'); |
395
|
|
|
$content = elgg_list_entities_from_relationship(array( |
396
|
|
|
'relationship' => 'member', |
397
|
|
|
'relationship_guid' => $group->guid, |
398
|
|
|
'inverse_relationship' => true, |
399
|
|
|
'type' => 'user', |
400
|
|
|
'limit' => (int)get_input('limit', max(20, elgg_get_config('default_limit')), false), |
401
|
|
|
'joins' => array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid"), |
402
|
|
|
'order_by' => 'u.name ASC', |
403
|
|
|
)); |
404
|
|
|
|
405
|
|
|
$params = array( |
406
|
|
|
'content' => $content, |
407
|
|
|
'title' => $title . 'TESTING', |
408
|
|
|
'filter' => '', |
409
|
|
|
); |
410
|
|
|
$body = elgg_view_layout('content', $params); |
411
|
|
|
|
412
|
|
|
echo elgg_view_page($title, $body); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Invite users to a group |
417
|
|
|
* |
418
|
|
|
* @param int $guid Group entity GUID |
419
|
|
|
*/ |
420
|
|
View Code Duplication |
function groups_handle_invite_page($guid) { |
|
|
|
|
421
|
|
|
elgg_gatekeeper(); |
422
|
|
|
|
423
|
|
|
elgg_set_page_owner_guid($guid); |
424
|
|
|
|
425
|
|
|
$title = elgg_echo('groups:invite:title'); |
426
|
|
|
|
427
|
|
|
$group = get_entity($guid); |
428
|
|
|
if (!elgg_instanceof($group, 'group') || !$group->canEdit()) { |
429
|
|
|
register_error(elgg_echo('groups:noaccess')); |
430
|
|
|
forward(REFERER); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
$content = elgg_view_form('groups/invite', array( |
434
|
|
|
'id' => 'invite_to_group', |
435
|
|
|
'class' => 'elgg-form-alt mtm', |
436
|
|
|
), array( |
437
|
|
|
'entity' => $group, |
438
|
|
|
)); |
439
|
|
|
|
440
|
|
|
elgg_push_breadcrumb($group->name, $group->getURL()); |
441
|
|
|
elgg_push_breadcrumb(elgg_echo('groups:invite')); |
442
|
|
|
|
443
|
|
|
$params = array( |
444
|
|
|
'content' => $content, |
445
|
|
|
'title' => $title, |
446
|
|
|
'filter' => '', |
447
|
|
|
); |
448
|
|
|
$body = elgg_view_layout('content', $params); |
449
|
|
|
|
450
|
|
|
echo elgg_view_page($title, $body); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Manage requests to join a group |
455
|
|
|
* |
456
|
|
|
* @param int $guid Group entity GUID |
457
|
|
|
*/ |
458
|
|
View Code Duplication |
function groups_handle_requests_page($guid) { |
|
|
|
|
459
|
|
|
|
460
|
|
|
elgg_gatekeeper(); |
461
|
|
|
|
462
|
|
|
elgg_set_page_owner_guid($guid); |
463
|
|
|
|
464
|
|
|
$group = get_entity($guid); |
465
|
|
|
if (!elgg_instanceof($group, 'group') || !$group->canEdit()) { |
466
|
|
|
register_error(elgg_echo('groups:noaccess')); |
467
|
|
|
forward(REFERER); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
$title = elgg_echo('groups:membershiprequests'); |
471
|
|
|
|
472
|
|
|
elgg_push_breadcrumb($group->name, $group->getURL()); |
473
|
|
|
elgg_push_breadcrumb($title); |
474
|
|
|
|
475
|
|
|
$requests = elgg_get_entities_from_relationship(array( |
476
|
|
|
'type' => 'user', |
477
|
|
|
'relationship' => 'membership_request', |
478
|
|
|
'relationship_guid' => $guid, |
479
|
|
|
'inverse_relationship' => true, |
480
|
|
|
'limit' => 0, |
481
|
|
|
)); |
482
|
|
|
$content = elgg_view('groups/membershiprequests', array( |
483
|
|
|
'requests' => $requests, |
484
|
|
|
'entity' => $group, |
485
|
|
|
)); |
486
|
|
|
|
487
|
|
|
$params = array( |
488
|
|
|
'content' => $content, |
489
|
|
|
'title' => $title, |
490
|
|
|
'filter' => '', |
491
|
|
|
); |
492
|
|
|
$body = elgg_view_layout('content', $params); |
493
|
|
|
|
494
|
|
|
echo elgg_view_page($title, $body); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Add an about page for widgets and such |
499
|
|
|
* |
500
|
|
|
* @param int $guid Group entity GUID |
501
|
|
|
*/ |
502
|
|
|
function groups_handle_about_page($guid) { |
503
|
|
|
|
504
|
|
|
$content = 'Im AN ABOUT PAGE!'; |
505
|
|
|
$title = 'ABOOOT THIS GROUP'; |
506
|
|
|
|
507
|
|
|
$params = array( |
508
|
|
|
'content' => $content, |
509
|
|
|
'title' => $title, |
510
|
|
|
); |
511
|
|
|
$body = elgg_view_layout('content', $params); |
512
|
|
|
|
513
|
|
|
echo elgg_view_page($title, $body); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* Registers the buttons for title area of the group profile page |
518
|
|
|
* |
519
|
|
|
* @param ElggGroup $group |
520
|
|
|
*/ |
521
|
|
View Code Duplication |
function groups_register_profile_buttons($group) { |
|
|
|
|
522
|
|
|
|
523
|
|
|
$actions = array(); |
524
|
|
|
|
525
|
|
|
// group owners |
526
|
|
|
if ($group->canEdit()) { |
527
|
|
|
// edit and invite |
528
|
|
|
$url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}"; |
529
|
|
|
$actions[$url] = 'groups:edit'; |
530
|
|
|
$url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}"; |
531
|
|
|
$actions[$url] = 'groups:invite'; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
// group members |
535
|
|
|
if ($group->isMember(elgg_get_logged_in_user_entity())) { |
536
|
|
|
if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) { |
537
|
|
|
// leave |
538
|
|
|
$url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}"; |
539
|
|
|
$url = elgg_add_action_tokens_to_url($url); |
540
|
|
|
$actions[$url] = 'groups:leave'; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
if( strpos(elgg_get_site_entity()->name, 'collab') !== false ){ |
544
|
|
|
$url = elgg_get_site_url() . "groups/stats/{$group->getGUID()}"; |
545
|
|
|
$actions[$url] = 'groups:stats'; |
546
|
|
|
} |
547
|
|
|
} elseif (elgg_is_logged_in()) { |
548
|
|
|
// join - admins can always join. |
549
|
|
|
$url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}"; |
550
|
|
|
$url = elgg_add_action_tokens_to_url($url); |
551
|
|
|
if ($group->isPublicMembership() || $group->canEdit()) { |
552
|
|
|
$actions[$url] = 'groups:join'; |
553
|
|
|
} else { |
554
|
|
|
// request membership |
555
|
|
|
$actions[$url] = 'groups:joinrequest'; |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
if ($actions) { |
|
|
|
|
560
|
|
|
foreach ($actions as $url => $text) { |
561
|
|
|
elgg_register_menu_item('title', array( |
562
|
|
|
'name' => $text, |
563
|
|
|
'href' => $url, |
564
|
|
|
'text' => elgg_echo($text), |
565
|
|
|
'link_class' => 'elgg-button elgg-button-action', |
566
|
|
|
)); |
567
|
|
|
} |
568
|
|
|
} |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Prepares variables for the group edit form view. |
573
|
|
|
* |
574
|
|
|
* @param mixed $group ElggGroup or null. If a group, uses values from the group. |
575
|
|
|
* @return array |
576
|
|
|
*/ |
577
|
|
View Code Duplication |
function groups_prepare_form_vars($group = null) { |
|
|
|
|
578
|
|
|
$values = array( |
579
|
|
|
'name' => '', |
580
|
|
|
'name2' => '', |
581
|
|
|
'membership' => ACCESS_PUBLIC, |
582
|
|
|
'vis' => ACCESS_PUBLIC, |
583
|
|
|
'guid' => null, |
584
|
|
|
'entity' => null, |
585
|
|
|
'owner_guid' => elgg_get_logged_in_user_guid(), |
586
|
|
|
'content_access_mode' => ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED |
587
|
|
|
); |
588
|
|
|
|
589
|
|
|
// handle customizable profile fields |
590
|
|
|
$fields = elgg_get_config('group'); |
591
|
|
|
|
592
|
|
|
if ($fields) { |
593
|
|
|
foreach ($fields as $name => $type) { |
594
|
|
|
$values[$name] = ''; |
595
|
|
|
} |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
// handle tool options |
599
|
|
|
$tools = elgg_get_config('group_tool_options'); |
600
|
|
|
if ($tools) { |
601
|
|
|
foreach ($tools as $group_option) { |
602
|
|
|
$option_name = $group_option->name . "_enable"; |
603
|
|
|
$values[$option_name] = $group_option->default_on ? 'yes' : 'no'; |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
// get current group settings |
608
|
|
|
if ($group) { |
609
|
|
|
foreach (array_keys($values) as $field) { |
610
|
|
|
if (isset($group->$field)) { |
611
|
|
|
$values[$field] = $group->$field; |
612
|
|
|
} |
613
|
|
|
} |
614
|
|
|
|
615
|
|
|
if ($group->access_id != ACCESS_PUBLIC && $group->access_id != ACCESS_LOGGED_IN) { |
616
|
|
|
// group only access - this is done to handle access not created when group is created |
617
|
|
|
$values['vis'] = ACCESS_PRIVATE; |
618
|
|
|
} else { |
619
|
|
|
$values['vis'] = $group->access_id; |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
// The content_access_mode was introduced in 1.9. This method must be |
623
|
|
|
// used for backwards compatibility with groups created before 1.9. |
624
|
|
|
$values['content_access_mode'] = $group->getContentAccessMode(); |
625
|
|
|
|
626
|
|
|
$values['entity'] = $group; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
// get any sticky form settings |
630
|
|
|
if (elgg_is_sticky_form('groups')) { |
631
|
|
|
$sticky_values = elgg_get_sticky_values('groups'); |
632
|
|
|
foreach ($sticky_values as $key => $value) { |
633
|
|
|
$values[$key] = $value; |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
elgg_clear_sticky_form('groups'); |
638
|
|
|
|
639
|
|
|
return $values; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* View stats for a group |
644
|
|
|
* |
645
|
|
|
* @param int $guid Group entity GUID |
646
|
|
|
*/ |
647
|
|
|
function groups_handle_stats_page($guid) { |
|
|
|
|
648
|
|
|
|
649
|
|
|
elgg_gatekeeper(); |
650
|
|
|
|
651
|
|
|
elgg_set_page_owner_guid($guid); |
652
|
|
|
|
653
|
|
|
$group = get_entity($guid); |
654
|
|
View Code Duplication |
if (!elgg_instanceof($group, 'group') || strpos(elgg_get_site_entity()->name, 'collab') == false) { |
|
|
|
|
655
|
|
|
register_error(elgg_echo('groups:noaccess')); |
656
|
|
|
forward(REFERER); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
$title = elgg_echo('groups:stats'); |
660
|
|
|
$lang = get_current_language(); |
661
|
|
|
|
662
|
|
|
elgg_push_breadcrumb(gc_explode_translation($group->name, $lang), $group->getURL()); |
663
|
|
|
elgg_push_breadcrumb($title); |
664
|
|
|
|
665
|
|
|
$content = ""; |
666
|
|
|
$data = ""; |
667
|
|
|
$dbprefix = elgg_get_config('dbprefix'); |
668
|
|
|
$query = "SELECT * FROM {$dbprefix}entity_relationships WHERE relationship = 'member' AND guid_two = '" . $guid . "'"; |
669
|
|
|
$groupsjoined = get_data($query); |
670
|
|
|
|
671
|
|
|
$data = array(); |
672
|
|
View Code Duplication |
foreach($groupsjoined as $key => $obj){ |
673
|
|
|
if ( $obj->time_created ){ |
674
|
|
|
$user = get_user($obj->guid_one); |
675
|
|
|
$data[] = array($obj->time_created, $user->username); |
676
|
|
|
} |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
ob_start(); ?> |
680
|
|
|
|
681
|
|
|
<script src="//code.highcharts.com/highcharts.js"></script> |
682
|
|
|
<script src="//code.highcharts.com/modules/exporting.js"></script> |
683
|
|
|
<script src="//code.highcharts.com/modules/data.js"></script> |
684
|
|
|
<script src="//code.highcharts.com/modules/drilldown.js"></script> |
685
|
|
|
<script src="//highcharts.github.io/export-csv/export-csv.js"></script> |
686
|
|
|
<script>var lang = '<?php echo get_current_language(); ?>';</script> |
687
|
|
|
<script>var siteUrl = '<?php echo elgg_get_site_url(); ?>';</script> |
688
|
|
|
<script>var data = $.parseJSON('<?php echo json_encode($data); ?>');</script> |
689
|
|
|
<script> |
690
|
|
|
Date.prototype.niceDate = function() { |
691
|
|
|
if(lang == "fr"){ |
692
|
|
|
var months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre']; |
693
|
|
|
var mm = this.getMonth(); |
694
|
|
|
var dd = this.getDate(); |
695
|
|
|
var yy = this.getFullYear(); |
696
|
|
|
return dd + ' ' + months[mm] + ' ' + yy; |
697
|
|
|
} else { |
698
|
|
|
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; |
699
|
|
|
var mm = this.getMonth(); |
700
|
|
|
var dd = this.getDate(); |
701
|
|
|
var yy = this.getFullYear(); |
702
|
|
|
return months[mm] + ' ' + dd + ', ' + yy; |
703
|
|
|
} |
704
|
|
|
}; |
705
|
|
|
|
706
|
|
|
String.prototype.capitalizeFirstLetter = function() { |
707
|
|
|
return this.charAt(0).toUpperCase() + this.slice(1); |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
function SortRegistrations(a, b){ |
711
|
|
|
return (a[0] - b[0]); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
function SortByCount(a, b){ |
715
|
|
|
return (b[1] - a[1]); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
function SortByName(a, b){ |
719
|
|
|
var one = (a.name != null) ? a.name.toLowerCase().replace(/é/g, 'e').replace(/è/g, 'e').replace(/î/g, 'i') : ""; |
720
|
|
|
var two = (b.name != null) ? b.name.toLowerCase().replace(/é/g, 'e').replace(/è/g, 'e').replace(/î/g, 'i') : ""; |
721
|
|
|
if(one < two) return -1; |
722
|
|
|
if(one > two) return 1; |
723
|
|
|
return 0; |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
function SortInstitutionByName(a, b){ |
727
|
|
|
var one = (a[0] != null) ? a[0].toLowerCase().replace(/é/g, 'e').replace(/è/g, 'e').replace(/î/g, 'i') : ""; |
728
|
|
|
var two = (b[0] != null) ? b[0].toLowerCase().replace(/é/g, 'e').replace(/è/g, 'e').replace(/î/g, 'i') : ""; |
729
|
|
|
if(one < two) return -1; |
730
|
|
|
if(one > two) return 1; |
731
|
|
|
return 0; |
732
|
|
|
} |
733
|
|
|
</script> |
734
|
|
|
<?php if(get_current_language() == "fr"): ?> |
735
|
|
|
<script> |
736
|
|
|
Highcharts.setOptions({ |
737
|
|
|
lang: { |
738
|
|
|
months: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'], |
739
|
|
|
weekdays: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'], |
740
|
|
|
shortMonths: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aout', 'Sept', 'Oct', 'Nov', 'Déc'], |
741
|
|
|
decimalPoint: ',', |
742
|
|
|
downloadPNG: 'Télécharger en image PNG', |
743
|
|
|
downloadJPEG: 'Télécharger en image JPEG', |
744
|
|
|
downloadPDF: 'Télécharger en document PDF', |
745
|
|
|
downloadSVG: 'Télécharger en document Vectoriel', |
746
|
|
|
exportButtonTitle: 'Export du graphique', |
747
|
|
|
loading: 'Chargement en cours...', |
748
|
|
|
printButtonTitle: 'Imprimer le graphique', |
749
|
|
|
resetZoom: 'Réinitialiser le zoom', |
750
|
|
|
resetZoomTitle: 'Réinitialiser le zoom au niveau 1:1', |
751
|
|
|
thousandsSep: ' ', |
752
|
|
|
decimalPoint: ',', |
753
|
|
|
printChart: 'Imprimer le graphique', |
754
|
|
|
downloadCSV: 'Télécharger en CSV', |
755
|
|
|
downloadXLS: 'Télécharger en XLS', |
756
|
|
|
viewData: 'Afficher la table des données' |
757
|
|
|
} |
758
|
|
|
}); |
759
|
|
|
</script> |
760
|
|
|
<?php endif; ?> |
761
|
|
|
<style> |
762
|
|
|
.chart { |
763
|
|
|
width: 100%; |
764
|
|
|
min-width: 100%; |
765
|
|
|
max-width: 100%; |
766
|
|
|
margin: 0 auto; |
767
|
|
|
} |
768
|
|
|
.chart .loading { |
769
|
|
|
padding-top: 10%; |
770
|
|
|
display: block; |
771
|
|
|
font-size: 2em; |
772
|
|
|
text-align: center; |
773
|
|
|
} |
774
|
|
|
@media (max-width: 480px) { |
775
|
|
|
.nav-tabs > li { |
776
|
|
|
float:none; |
777
|
|
|
} |
778
|
|
|
} |
779
|
|
|
</style> |
780
|
|
|
|
781
|
|
|
<div class="chart" id="groupsjoinedChart" style="min-height: 350px;"><span class="loading"><?php echo elgg_echo("gccollab_stats:loading"); ?></span></div> |
782
|
|
|
|
783
|
|
|
<script> |
784
|
|
|
$(function () { |
785
|
|
|
var dates = {}; |
786
|
|
|
var users = {}; |
787
|
|
|
var groupsjoined = []; |
788
|
|
|
$.each(data, function(key, value){ |
789
|
|
|
var date = new Date(value[0] * 1000); |
790
|
|
|
date.setHours(0, 0, 0, 0); |
791
|
|
|
var dateString = date.getTime(); |
792
|
|
|
dates[dateString] = (dates[dateString] ? dates[dateString] + 1 : 1); |
793
|
|
|
if( users[dateString] ){ |
794
|
|
|
users[dateString] = users[dateString] + value[1] + "<br>"; |
795
|
|
|
} else { |
796
|
|
|
users[dateString] = ""; |
797
|
|
|
users[dateString] = users[dateString] + value[1] + "<br>"; |
798
|
|
|
} |
799
|
|
|
}); |
800
|
|
|
$.each(dates, function(key, value){ |
801
|
|
|
key = parseInt(key); |
802
|
|
|
groupsjoined.push([key, value, new Date(key).niceDate(), users[key]]); |
803
|
|
|
}); |
804
|
|
|
groupsjoined.sort(); |
805
|
|
|
|
806
|
|
|
Highcharts.chart('groupsjoinedChart', { |
807
|
|
|
chart: { |
808
|
|
|
zoomType: 'x' |
809
|
|
|
}, |
810
|
|
|
title: { |
811
|
|
|
text: '<?php echo elgg_echo("gccollab_stats:usersjoined:title"); ?>' |
812
|
|
|
}, |
813
|
|
|
subtitle: { |
814
|
|
|
text: document.ontouchstart === undefined ? '<?php echo elgg_echo("gccollab_stats:zoommessage"); ?>' : '<?php echo elgg_echo("gccollab_stats:pinchmessage"); ?>' |
815
|
|
|
}, |
816
|
|
|
xAxis: { |
817
|
|
|
type: 'datetime' |
818
|
|
|
}, |
819
|
|
|
yAxis: { |
820
|
|
|
title: { |
821
|
|
|
text: '<?php echo elgg_echo("gccollab_stats:usersjoined:amount"); ?>' |
822
|
|
|
}, |
823
|
|
|
min: 0 |
824
|
|
|
}, |
825
|
|
|
legend: { |
826
|
|
|
enabled: false |
827
|
|
|
}, |
828
|
|
|
plotOptions: { |
829
|
|
|
area: { |
830
|
|
|
fillColor: { |
831
|
|
|
linearGradient: { |
832
|
|
|
x1: 0, |
833
|
|
|
y1: 0, |
834
|
|
|
x2: 0, |
835
|
|
|
y2: 1 |
836
|
|
|
}, |
837
|
|
|
stops: [ |
838
|
|
|
[0, Highcharts.getOptions().colors[0]], |
839
|
|
|
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] |
840
|
|
|
] |
841
|
|
|
}, |
842
|
|
|
marker: { |
843
|
|
|
radius: 2 |
844
|
|
|
}, |
845
|
|
|
lineWidth: 1, |
846
|
|
|
states: { |
847
|
|
|
hover: { |
848
|
|
|
lineWidth: 1 |
849
|
|
|
} |
850
|
|
|
}, |
851
|
|
|
threshold: null |
852
|
|
|
} |
853
|
|
|
}, |
854
|
|
|
tooltip: { |
855
|
|
|
formatter: function() { |
856
|
|
|
return '<b><?php echo elgg_echo("gccollab_stats:date"); ?></b> ' + groupsjoined[this.series.data.indexOf(this.point)][2] + '<br /><b><?php echo elgg_echo("gccollab_stats:total"); ?></b> ' + groupsjoined[this.series.data.indexOf(this.point)][1]+ '<br /><b><?php echo elgg_echo("gccollab_stats:users:title"); ?></b> ' + groupsjoined[this.series.data.indexOf(this.point)][3]; |
857
|
|
|
} |
858
|
|
|
}, |
859
|
|
|
series: [{ |
860
|
|
|
type: 'area', |
861
|
|
|
name: '<?php echo elgg_echo("gccollab_stats:groupsjoined:title"); ?>', |
862
|
|
|
data: groupsjoined |
863
|
|
|
}] |
864
|
|
|
}); |
865
|
|
|
}); |
866
|
|
|
</script> |
867
|
|
|
|
868
|
|
|
<?php |
869
|
|
|
|
870
|
|
|
$content = ob_get_clean(); |
871
|
|
|
|
872
|
|
|
$params = array( |
873
|
|
|
'content' => $content, |
874
|
|
|
'title' => $title, |
875
|
|
|
'filter' => '', |
876
|
|
|
); |
877
|
|
|
$body = elgg_view_layout('content', $params); |
878
|
|
|
$body = str_replace('col-md-8', 'col-md-12', $body); |
879
|
|
|
|
880
|
|
|
echo elgg_view_page($title, $body); |
881
|
|
|
} |
882
|
|
|
|
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.