diff options
author | Cash Costello <cash.costello@gmail.com> | 2011-07-06 03:55:10 -0700 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2011-07-06 03:55:10 -0700 |
commit | e4ad206bfd288463a37cfd4f86e6f343e3a35f77 (patch) | |
tree | 6a7c84a815467fc34d7ce266b682f7816427f50d /mod/developers/classes | |
parent | d15c4bdf3388b7eca709bd81c522ac1ebf087f0a (diff) | |
parent | b3382a41496bee4b66bc69421b9612bedfb77913 (diff) | |
download | elgg-e4ad206bfd288463a37cfd4f86e6f343e3a35f77.tar.gz elgg-e4ad206bfd288463a37cfd4f86e6f343e3a35f77.tar.bz2 |
Merge pull request #54 from cash/dev-tools
Fixes #3564 Adds the inspection tool and logging to the web page
Diffstat (limited to 'mod/developers/classes')
-rw-r--r-- | mod/developers/classes/ElggInspector.php | 201 | ||||
-rw-r--r-- | mod/developers/classes/ElggLogCache.php | 44 |
2 files changed, 245 insertions, 0 deletions
diff --git a/mod/developers/classes/ElggInspector.php b/mod/developers/classes/ElggInspector.php new file mode 100644 index 000000000..e83fc6b81 --- /dev/null +++ b/mod/developers/classes/ElggInspector.php @@ -0,0 +1,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; + } + +} diff --git a/mod/developers/classes/ElggLogCache.php b/mod/developers/classes/ElggLogCache.php new file mode 100644 index 000000000..5bd4bce28 --- /dev/null +++ b/mod/developers/classes/ElggLogCache.php @@ -0,0 +1,44 @@ +<?php +/** + * Cache logging information for later display + * + */ + +class ElggLogCache { + protected $cache; + + public function __construct() { + $this->cache = array(); + } + + /** + * Insert into cache + * + * @param mixed $data The log data to cache + */ + public function insert($data) { + $this->cache[] = $data; + } + + /** + * Insert into cache from plugin hook + * + * @param string $hook + * @param string $type + * @param bool $result + * @param array $params Must have the data at $params['msg'] + */ + public function insertDump($hook, $type, $result, $params) { + $this->insert($params['msg']); + return false; + } + + /** + * Get the cache + * + * @return array + */ + public function get() { + return $this->cache; + } +} |