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
|
<?php
/**
* Inspect Elgg variables
*
*/
class ElggInspector {
/**
* Get Elgg event information
*
* returns [event,type] => array(handlers)
*/
public function getEvents() {
global $CONFIG;
$tree = array();
foreach ($CONFIG->events as $event => $types) {
foreach ($types as $type => $handlers) {
$tree[$event . ',' . $type] = array_values($handlers);
}
}
ksort($tree);
return $tree;
}
/**
* Get Elgg plugin hooks information
*
* returns [hook,type] => array(handlers)
*/
public function getPluginHooks() {
global $CONFIG;
$tree = array();
foreach ($CONFIG->hooks as $hook => $types) {
foreach ($types as $type => $handlers) {
$tree[$hook . ',' . $type] = array_values($handlers);
}
}
ksort($tree);
return $tree;
}
/**
* Get Elgg view information
*
* returns [view] => array(view location and extensions)
*/
public function getViews() {
global $CONFIG;
$coreViews = $this->recurseFileTree($CONFIG->viewpath . "default/");
// remove base path and php extension
array_walk($coreViews, create_function('&$v,$k', 'global $CONFIG; $v = substr($v, strlen($CONFIG->viewpath . "default/"), -4);'));
// setup views array before adding extensions and plugin views
$views = array();
foreach ($coreViews as $view) {
$views[$view] = array($CONFIG->viewpath . "default/" . $view . ".php");
}
// add plugins and handle overrides
foreach ($CONFIG->views->locations['default'] as $view => $location) {
$views[$view] = array($location . $view . ".php");
}
// now extensions
foreach ($CONFIG->views->extensions as $view => $extensions) {
$view_list = array();
foreach ($extensions as $priority => $ext_view) {
if (isset($views[$ext_view])) {
$view_list[] = $views[$ext_view][0];
}
}
if (count($view_list) > 0) {
$views[$view] = $view_list;
}
}
ksort($views);
return $views;
}
/**
* Get Elgg widget information
*
* returns [widget] => array(name, contexts)
*/
public function getWidgets() {
global $CONFIG;
$tree = array();
foreach ($CONFIG->widgets->handlers as $handler => $handler_obj) {
$tree[$handler] = array($handler_obj->name, implode(',', array_values($handler_obj->context)));
}
ksort($tree);
return $tree;
}
/**
* Get Elgg actions information
*
* returns [action] => array(file, public, admin)
*/
public function getActions() {
global $CONFIG;
$tree = array();
foreach ($CONFIG->actions as $action => $info) {
$tree[$action] = array($info['file'], ($info['public']) ? 'public' : 'logged in only', ($info['admin']) ? 'admin only' : 'non-admin');
}
ksort($tree);
return $tree;
}
/**
* Get simplecache information
*
* returns [views]
*/
public function getSimpleCache() {
global $CONFIG;
$tree = array();
foreach ($CONFIG->views->simplecache as $view) {
$tree[$view] = "";
}
ksort($tree);
return $tree;
}
/**
* Get Elgg web services API methods
*
* returns [method] => array(function, parameters, call_method, api auth, user auth)
*/
public function getWebServices() {
global $API_METHODS;
$tree = array();
foreach ($API_METHODS as $method => $info) {
$params = implode(', ', array_keys($info['parameters']));
if (!$params) {
$params = 'none';
}
$tree[$method] = array(
$info['function'],
"params: $params",
$info['call_method'],
($info['require_api_auth']) ? 'API authentication required' : 'No API authentication required',
($info['require_user_auth']) ? 'User authentication required' : 'No user authentication required',
);
}
ksort($tree);
return $tree;
}
/**
* Create array of all php files in directory and subdirectories
*
* @param $dir full path to directory to begin search
* @return array of every php file in $dir or below in file tree
*/
protected function recurseFileTree($dir) {
$view_list = array();
$handle = opendir($dir);
while ($file = readdir($handle)) {
if ($file[0] == '.') {
} else if (is_dir($dir . $file)) {
$view_list = array_merge($view_list, $this->recurseFileTree($dir . $file. "/"));
} else {
$extension = strrchr(trim($file, "/"), '.');
if ($extension === ".php") {
$view_list[] = $dir . $file;
}
}
}
closedir($handle);
return $view_list;
}
}
|