From ae5ad0a65508725871159ffb6a068fcb2084aad7 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 2 Jul 2011 11:36:53 -0400 Subject: added the inspect tool to developers tool plugin --- mod/developers/classes/ElggInspector.php | 201 +++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 mod/developers/classes/ElggInspector.php (limited to 'mod/developers/classes') 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 @@ + 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; + } + +} -- cgit v1.2.3 From c4a53af23533d44383a87b5180b15e1a01a0e18a Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 2 Jul 2011 12:07:27 -0400 Subject: added logging to the web page footer --- engine/classes/ElggPlugin.php | 10 ++--- mod/developers/actions/developers/settings.php | 3 ++ mod/developers/classes/ElggLogCache.php | 43 ++++++++++++++++++++++ mod/developers/languages/en.php | 5 +++ mod/developers/start.php | 8 ++++ .../views/default/admin/developers/settings.php | 7 ++++ mod/developers/views/default/developers/css.php | 6 +++ mod/developers/views/default/developers/log.php | 16 ++++++++ 8 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 mod/developers/classes/ElggLogCache.php create mode 100644 mod/developers/views/default/developers/log.php (limited to 'mod/developers/classes') diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 95a7362e2..e46ac4273 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -700,6 +700,11 @@ class ElggPlugin extends ElggObject { // return false; // } + // include classes + if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) { + $this->registerClasses(); + } + // include start file if ($flags & ELGG_PLUGIN_INCLUDE_START) { $this->includeFile('start.php'); @@ -715,11 +720,6 @@ class ElggPlugin extends ElggObject { $this->registerLanguages(); } - // include classes - if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) { - $this->registerClasses(); - } - return true; } diff --git a/mod/developers/actions/developers/settings.php b/mod/developers/actions/developers/settings.php index d8be34866..9fa96fa91 100644 --- a/mod/developers/actions/developers/settings.php +++ b/mod/developers/actions/developers/settings.php @@ -18,6 +18,7 @@ if (get_input('view_path_cache')) { } elgg_set_plugin_setting('display_errors', get_input('display_errors'), 'developers'); +elgg_set_plugin_setting('screen_log', get_input('screen_log'), 'developers'); $debug = get_input('debug_level'); if ($debug) { @@ -26,4 +27,6 @@ if ($debug) { unset_config('debug', $site->getGUID()); } +system_message(elgg_echo('developers:settings:success')); + forward(REFERER); diff --git a/mod/developers/classes/ElggLogCache.php b/mod/developers/classes/ElggLogCache.php new file mode 100644 index 000000000..19df598d7 --- /dev/null +++ b/mod/developers/classes/ElggLogCache.php @@ -0,0 +1,43 @@ +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']); + } + + /** + * Get the cache + * + * @return array + */ + public function get() { + return $this->cache; + } +} diff --git a/mod/developers/languages/en.php b/mod/developers/languages/en.php index dc763765c..053eed04f 100644 --- a/mod/developers/languages/en.php +++ b/mod/developers/languages/en.php @@ -21,6 +21,8 @@ $english = array( 'developers:help:debug_level' => "This controls the amount of information logged. See elgg_log() for more information.", 'developers:label:display_errors' => 'Display fatal PHP errors', 'developers:help:display_errors' => "By default, Elgg's .htaccess file supresses the display of fatal errors.", + 'developers:label:screen_log' => "Log to the screen", + 'developers:help:screen_log' => "This displays elgg_log() and elgg_dump() output on the web page.", 'developers:debug:off' => 'Off', 'developers:debug:error' => 'Error', @@ -41,6 +43,9 @@ $english = array( 'theme_preview:modules' => 'Modules', 'theme_preview:navigation' => 'Navigation', 'theme_preview:typography' => 'Typography', + + // status messages + 'developers:settings:success' => 'Settings saved', ); add_translation('en', $english); diff --git a/mod/developers/start.php b/mod/developers/start.php index a53b7eec4..23b82d9db 100644 --- a/mod/developers/start.php +++ b/mod/developers/start.php @@ -12,6 +12,7 @@ function developers_init() { elgg_register_event_handler('pagesetup', 'system', 'developers_setup_menu'); elgg_extend_view('css/admin', 'developers/css'); + elgg_extend_view('css/elgg', 'developers/css'); elgg_register_page_handler('theme_preview', 'developers_theme_preview_controller'); @@ -32,6 +33,13 @@ function developers_process_settings() { } else { ini_set('display_errors', 0); } + + if (elgg_get_plugin_setting('screen_log', 'developers') == 1) { + $cache = new ElggLogCache(); + elgg_set_config('log_cache', $cache); + elgg_register_plugin_hook_handler('debug', 'log', array($cache, 'insertDump')); + elgg_extend_view('page/elements/foot', 'developers/log'); + } } function developers_setup_menu() { diff --git a/mod/developers/views/default/admin/developers/settings.php b/mod/developers/views/default/admin/developers/settings.php index 705ad00c6..3843c2c30 100644 --- a/mod/developers/views/default/admin/developers/settings.php +++ b/mod/developers/views/default/admin/developers/settings.php @@ -8,6 +8,7 @@ $sections = array( 'view_path_cache' => 'checkbox', 'display_errors' => 'checkbox', 'debug_level' => 'pulldown', + 'screen_log' => 'checkbox', ); $data = array( @@ -39,6 +40,12 @@ $data = array( 'NOTICE' => elgg_echo('developers:debug:notice'), ), ), + + 'screen_log' => array( + 'type' => 'checkbox', + 'value' => 1, + 'checked' => elgg_get_plugin_setting('screen_log', 'developers') == 1, + ), ); $form_vars = array('id' => 'developer-settings-form'); diff --git a/mod/developers/views/default/developers/css.php b/mod/developers/views/default/developers/css.php index 3aa226d0a..4690945a9 100644 --- a/mod/developers/views/default/developers/css.php +++ b/mod/developers/views/default/developers/css.php @@ -15,3 +15,9 @@ .elgg-page .jstree-default.jstree-focused { background-color: transparent; } +.developers-log { + background-color: #EBF5FF; + border: 1px solid #999; + color: #666; + padding: 20px; +} diff --git a/mod/developers/views/default/developers/log.php b/mod/developers/views/default/developers/log.php new file mode 100644 index 000000000..eca2b4b67 --- /dev/null +++ b/mod/developers/views/default/developers/log.php @@ -0,0 +1,16 @@ +get(); + +echo '
'; +foreach ($items as $item) { + echo '
';
+	print_r($item);
+	echo '
'; +} + +echo '
'; \ No newline at end of file -- cgit v1.2.3 From c7e9b59e95b34c0d850e0b53c90a7b9f04ed4d2b Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 2 Jul 2011 19:27:50 -0400 Subject: returning false to stop elgg_dump() from also displaying the debugging information to the screen --- mod/developers/classes/ElggLogCache.php | 1 + 1 file changed, 1 insertion(+) (limited to 'mod/developers/classes') diff --git a/mod/developers/classes/ElggLogCache.php b/mod/developers/classes/ElggLogCache.php index 19df598d7..5bd4bce28 100644 --- a/mod/developers/classes/ElggLogCache.php +++ b/mod/developers/classes/ElggLogCache.php @@ -30,6 +30,7 @@ class ElggLogCache { */ public function insertDump($hook, $type, $result, $params) { $this->insert($params['msg']); + return false; } /** -- cgit v1.2.3