ElggInspector.php 6.8 KB

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