PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/developers/classes/ElggInspector.php

https://github.com/fragilbert/Elgg
PHP | 275 lines | 165 code | 50 blank | 60 comment | 10 complexity | f2aeb432eb364ab3cb6fdd228e6b67db MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Inspect Elgg variables
  4. *
  5. */
  6. class ElggInspector {
  7. /**
  8. * Get Elgg event information
  9. *
  10. * returns [event,type] => array(handlers)
  11. */
  12. public function getEvents() {
  13. $tree = array();
  14. $events = _elgg_services()->events->getAllHandlers();
  15. foreach ($events as $event => $types) {
  16. foreach ($types as $type => $handlers) {
  17. $tree[$event . ',' . $type] = array_values($handlers);
  18. }
  19. }
  20. ksort($tree);
  21. return $tree;
  22. }
  23. /**
  24. * Get Elgg plugin hooks information
  25. *
  26. * returns [hook,type] => array(handlers)
  27. */
  28. public function getPluginHooks() {
  29. $tree = array();
  30. $hooks = _elgg_services()->hooks->getAllHandlers();
  31. foreach ($hooks as $hook => $types) {
  32. foreach ($types as $type => $handlers) {
  33. $tree[$hook . ',' . $type] = array_values($handlers);
  34. }
  35. }
  36. ksort($tree);
  37. return $tree;
  38. }
  39. /**
  40. * Get Elgg view information
  41. *
  42. * returns [view] => array(view location and extensions)
  43. */
  44. public function getViews() {
  45. global $CONFIG;
  46. $coreViews = $this->recurseFileTree($CONFIG->viewpath . "default/");
  47. // remove base path and php extension
  48. array_walk($coreViews, create_function('&$v,$k', 'global $CONFIG; $v = substr($v, strlen($CONFIG->viewpath . "default/"), -4);'));
  49. // setup views array before adding extensions and plugin views
  50. $views = array();
  51. foreach ($coreViews as $view) {
  52. $views[$view] = array($CONFIG->viewpath . "default/" . $view . ".php");
  53. }
  54. // add plugins and handle overrides
  55. foreach ($CONFIG->views->locations['default'] as $view => $location) {
  56. $views[$view] = array($location . $view . ".php");
  57. }
  58. // now extensions
  59. foreach ($CONFIG->views->extensions as $view => $extensions) {
  60. $view_list = array();
  61. foreach ($extensions as $priority => $ext_view) {
  62. if (isset($views[$ext_view])) {
  63. $view_list[] = $views[$ext_view][0];
  64. }
  65. }
  66. if (count($view_list) > 0) {
  67. $views[$view] = $view_list;
  68. }
  69. }
  70. ksort($views);
  71. return $views;
  72. }
  73. /**
  74. * Get Elgg widget information
  75. *
  76. * returns [widget] => array(name, contexts)
  77. */
  78. public function getWidgets() {
  79. global $CONFIG;
  80. $tree = array();
  81. foreach ($CONFIG->widgets->handlers as $handler => $handler_obj) {
  82. $tree[$handler] = array($handler_obj->name, implode(',', array_values($handler_obj->context)));
  83. }
  84. ksort($tree);
  85. return $tree;
  86. }
  87. /**
  88. * Get Elgg actions information
  89. *
  90. * returns [action] => array(file, public, admin)
  91. */
  92. public function getActions() {
  93. global $CONFIG;
  94. $tree = array();
  95. foreach ($CONFIG->actions as $action => $info) {
  96. $tree[$action] = array($info['file'], ($info['public']) ? 'public' : 'logged in only', ($info['admin']) ? 'admin only' : 'non-admin');
  97. }
  98. ksort($tree);
  99. return $tree;
  100. }
  101. /**
  102. * Get simplecache information
  103. *
  104. * returns [views]
  105. */
  106. public function getSimpleCache() {
  107. global $CONFIG;
  108. $tree = array();
  109. foreach ($CONFIG->views->simplecache as $view) {
  110. $tree[$view] = "";
  111. }
  112. ksort($tree);
  113. return $tree;
  114. }
  115. /**
  116. * Get Elgg web services API methods
  117. *
  118. * returns [method] => array(function, parameters, call_method, api auth, user auth)
  119. */
  120. public function getWebServices() {
  121. global $API_METHODS;
  122. $tree = array();
  123. foreach ($API_METHODS as $method => $info) {
  124. $params = implode(', ', array_keys($info['parameters']));
  125. if (!$params) {
  126. $params = 'none';
  127. }
  128. $tree[$method] = array(
  129. $info['function'],
  130. "params: $params",
  131. $info['call_method'],
  132. ($info['require_api_auth']) ? 'API authentication required' : 'No API authentication required',
  133. ($info['require_user_auth']) ? 'User authentication required' : 'No user authentication required',
  134. );
  135. }
  136. ksort($tree);
  137. return $tree;
  138. }
  139. /**
  140. * Get information about registered menus
  141. *
  142. * @returns array 'Menu Name' => array('Item Name' => array('Link Text', 'Href', 'Section', 'Parent', 'Priority'))
  143. *
  144. */
  145. public function getMenus() {
  146. $menus = elgg_get_config('menus');
  147. // get JIT menu items
  148. // note that 'river' is absent from this list - hooks attempt to get object/subject entities cause problems
  149. $jit_menus = array('annotation', 'entity', 'longtext', 'owner_block', 'user_hover', 'widget');
  150. // create generic ElggEntity, ElggAnnotation, ElggUser, ElggWidget
  151. $annotation = new ElggAnnotation();
  152. $annotation->id = 999;
  153. $annotation->name = 'generic_comment';
  154. $annotation->value = 'testvalue';
  155. $entity = new ElggObject();
  156. $entity->guid = 999;
  157. $entity->subtype = 'blog';
  158. $entity->title = 'test entity';
  159. $entity->access_id = ACCESS_PUBLIC;
  160. $user = new ElggUser();
  161. $user->guid = 999;
  162. $user->name = "Test User";
  163. $user->username = 'test_user';
  164. $widget = new ElggWidget();
  165. $widget->guid = 999;
  166. $widget->title = 'test widget';
  167. // call plugin hooks
  168. foreach($jit_menus as $type){
  169. $params = array('entity' => $entity, 'annotation' => $annotation, 'user' => $user);
  170. switch($type){
  171. case 'user_hover':
  172. $params['entity'] = $user;
  173. break;
  174. case 'widget':
  175. $params['entity'] = $widget;
  176. break;
  177. default:
  178. break;
  179. }
  180. $menus[$type] = elgg_trigger_plugin_hook('register', 'menu:'.$type, $params, array());
  181. }
  182. // put the menus in tree form for inspection
  183. $tree = array();
  184. foreach($menus as $menu_name => $attributes){
  185. foreach($attributes as $item){
  186. $name = $item->getName();
  187. $text = $item->getText();
  188. $href = $item->getHref();
  189. $section = $item->getSection();
  190. $parent = $item->getParentName();
  191. $tree[$menu_name][$name] = array(
  192. "Text: $text",
  193. "Href: $href",
  194. "Section: $section",
  195. "Parent: $parent"
  196. );
  197. }
  198. }
  199. ksort($tree);
  200. return $tree;
  201. }
  202. /**
  203. * Create array of all php files in directory and subdirectories
  204. *
  205. * @param $dir full path to directory to begin search
  206. * @return array of every php file in $dir or below in file tree
  207. */
  208. protected function recurseFileTree($dir) {
  209. $view_list = array();
  210. $handle = opendir($dir);
  211. while ($file = readdir($handle)) {
  212. if ($file[0] == '.') {
  213. } else if (is_dir($dir . $file)) {
  214. $view_list = array_merge($view_list, $this->recurseFileTree($dir . $file. "/"));
  215. } else {
  216. $extension = strrchr(trim($file, "/"), '.');
  217. if ($extension === ".php") {
  218. $view_list[] = $dir . $file;
  219. }
  220. }
  221. }
  222. closedir($handle);
  223. return $view_list;
  224. }
  225. }