blob: ffa531e16b2c3207aa93160b282c601ec923a630 (
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
79
80
81
82
83
84
|
<?php
/**
* Subgroups helper functions
*
* @package ElggSubgroups
*/
/**
* Gives the list of the group subgroups
*
* @param ElggGroup $group
* @return array
*/
function get_subgroups($group, $options = array()){
if($group instanceof ElggGroup){
$options['type'] = 'group';
$options['container_guid'] = $group->guid;
return elgg_get_entities($options);
} else {
return false;
}
}
function list_subgroups($group, $options = array()){
if($group instanceof ElggGroup){
$defaults = array(
'full_view' => false,
'pagination' => true,
);
$options = array_merge($defaults, $options);
$options['type'] = 'group';
$options['container_guid'] = $group->guid;
elgg_push_context('subgroups');
$list = elgg_list_entities($options);
elgg_pop_context();
return $list;
} else {
return "";
}
}
function subgroups_group_url_matches($url){
$url = parse_url($url);
$pattern1 = "/groups\/profile\/(?P<group_guid>\d+)/";
$pattern2 = "/g\/(?P<group_alias>[^\/]+)/";
$matches1 = array();
$matches2 = array();
preg_match($pattern1, $url['path'], $matches1);
preg_match($pattern2, $url['path'], $matches2);
if(!empty($matches1) || !empty($matches2)) {
return array_merge($matches1, $matches2);
} else {
return false;
}
}
function subgroups_get_group_from_url($group_url){
$matches = subgroups_group_url_matches($group_url);
$group_guid = $matches['group_guid'];
$group_alias = $matches['group_alias'];
$group = get_entity($group_guid);
if(!$group && elgg_is_active_plugin('group_alias')) {
$group = get_group_from_group_alias($group_alias);
}
if($group && $group->getURL() == $group_url){
return $group;
} else {
return false;
}
}
|