|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AU\ActivityTabs; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Pagesetup |
|
7
|
|
|
* |
|
8
|
|
|
* @return type |
|
9
|
|
|
*/ |
|
10
|
|
|
function pagesetup() { |
|
11
|
|
|
if (!elgg_is_logged_in()) { |
|
12
|
|
|
return; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
if (!elgg_in_context('activity') && !elgg_in_context('activity_tabs')) { |
|
16
|
|
|
return; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
$dbprefix = elgg_get_config('dbprefix'); |
|
20
|
|
|
$priority = 500; |
|
21
|
|
|
|
|
22
|
|
|
$user = elgg_get_logged_in_user_entity(); |
|
23
|
|
|
$filter_context = get_input('filter_context', false); |
|
24
|
|
|
|
|
25
|
|
|
$plugin = elgg_get_plugin_from_id(PLUGIN_ID); |
|
26
|
|
|
if (!$plugin) { |
|
27
|
|
|
// dunno how this could be possible |
|
28
|
|
|
return true; |
|
29
|
|
|
} |
|
30
|
|
|
$all_settings = $plugin->getAllUserSettings($user->guid); |
|
31
|
|
|
|
|
32
|
|
|
$tabs = array( |
|
33
|
|
|
'group' => array(), |
|
34
|
|
|
'collection' => array(), |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
if (!empty($all_settings)) { |
|
38
|
|
|
foreach ($all_settings as $name => $value) { |
|
39
|
|
|
list($type, $id, $opt) = explode('_', $name); |
|
40
|
|
|
if ($type !== 'group' && $type !== 'collection') { |
|
41
|
|
|
continue; |
|
42
|
|
|
} |
|
43
|
|
|
if (!$opt) { |
|
44
|
|
|
$opt = 'enabled'; |
|
45
|
|
|
} |
|
46
|
|
|
$tabs[$type][$id][$opt] = $value; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$collection_ids = array(); |
|
51
|
|
|
foreach ($tabs['collection'] as $id => $opts) { |
|
52
|
|
|
$enabled = elgg_extract('enabled', $opts); |
|
53
|
|
|
if ($enabled == 'yes') { |
|
54
|
|
|
$collection_ids[] = (int) $id; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$group_ids = array(); |
|
59
|
|
|
foreach ($tabs['group'] as $id => $opts) { |
|
60
|
|
|
$enabled = elgg_extract('enabled', $opts); |
|
61
|
|
|
if ($enabled == 'yes') { |
|
62
|
|
|
$group_ids[] = (int) $id; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
View Code Duplication |
if (!empty($collection_ids)) { |
|
67
|
|
|
$collection_ids_in = implode(',', $collection_ids); |
|
68
|
|
|
$query = "SELECT * FROM {$dbprefix}access_collections |
|
69
|
|
|
WHERE owner_guid = {$user->guid} AND id IN ($collection_ids_in) AND name NOT LIKE 'Group:%'"; |
|
70
|
|
|
$collections = get_data($query); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
View Code Duplication |
if (!empty($collections)) { |
|
74
|
|
|
|
|
75
|
|
|
// iterate through collections and add tabs as necessary |
|
76
|
|
|
foreach ($collections as $collection) { |
|
77
|
|
|
// we need to create a tab |
|
78
|
|
|
$tab = array( |
|
79
|
|
|
'name' => "collection:$collection->id", |
|
80
|
|
|
'text' => $collection->name, |
|
81
|
|
|
'href' => "activity_tabs/collection/{$collection->id}/" . elgg_get_friendly_title($collection->name), |
|
82
|
|
|
'selected' => $filter_context == 'collection_' . $collection->id, |
|
83
|
|
|
'priority' => $priority + (int) $tabs['collection']["$collection->id"]['priority'], |
|
84
|
|
|
); |
|
85
|
|
|
elgg_register_menu_item('filter', $tab); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
if (!empty($group_ids)) { |
|
90
|
|
|
$group_ids_in = implode(',', $group_ids); |
|
91
|
|
|
$query = "SELECT * FROM {$dbprefix}groups_entity ge |
|
92
|
|
|
JOIN {$dbprefix}entity_relationships er ON er.guid_two = ge.guid |
|
93
|
|
|
WHERE er.guid_one = {$user->guid} AND ge.guid IN ($group_ids_in)"; |
|
94
|
|
|
$groups = get_data($query); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
View Code Duplication |
if (!empty($groups)) { |
|
98
|
|
|
foreach ($groups as $group) { |
|
99
|
|
|
$tab = array( |
|
100
|
|
|
'name' => "group:$group->guid", |
|
101
|
|
|
'text' => $group->name, |
|
102
|
|
|
'href' => "activity_tabs/group/{$group->guid}/" . elgg_get_friendly_title($group->name), |
|
103
|
|
|
'selected' => $filter_context == 'group_' . $group->guid, |
|
104
|
|
|
'priority' => $priority + (int) $tabs['group']["$group->guid"]['priority'], |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
elgg_register_menu_item('filter', $tab); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if( strpos(elgg_get_site_entity()->name, 'collab') == false ){ |
|
|
|
|
|
|
111
|
|
|
$tab = array( |
|
112
|
|
|
'name' => "mydept:$user->department", |
|
113
|
|
|
'text' => elgg_echo('activity_tabs:mydepartment'), |
|
114
|
|
|
'href' => "activity_tabs/mydept/", |
|
115
|
|
|
'selected' => $filter_context == 'mydept_', |
|
116
|
|
|
'priority' => $priority + (int) $tabs['dept']["$user->department"]['priority'], |
|
117
|
|
|
); |
|
118
|
|
|
elgg_register_menu_item('filter', $tab); |
|
119
|
|
|
|
|
120
|
|
|
$tab = array( |
|
121
|
|
|
'name' => "otherdept:$user->department", |
|
122
|
|
|
'text' => elgg_echo('activity_tabs:otherdepartments'), |
|
123
|
|
|
'href' => "activity_tabs/otherdept/", |
|
124
|
|
|
'selected' => $filter_context == 'otherdept_', |
|
125
|
|
|
'priority' => $priority + (int) $tabs['otherdept']["$user->department"]['priority'], |
|
126
|
|
|
); |
|
127
|
|
|
elgg_register_menu_item('filter', $tab); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
// register menu item for configuring tabs |
|
131
|
|
|
$link = array( |
|
132
|
|
|
'name' => 'configure_activity_tabs', |
|
133
|
|
|
'text' => elgg_echo('activity_tabs:configure'), |
|
134
|
|
|
'href' => 'settings/plugins/' . $user->username, |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
elgg_register_menu_item('page', $link); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Run-once upgrades |
|
142
|
|
|
* @return boolean |
|
143
|
|
|
*/ |
|
144
|
|
|
function upgrades() { |
|
145
|
|
|
if (!elgg_is_admin_logged_in()) { |
|
146
|
|
|
return true; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
require_once __DIR__ . '/upgrades.php'; |
|
150
|
|
|
run_function_once(__NAMESPACE__ . '\\upgrade20151017'); |
|
151
|
|
|
} |
|
152
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: