admin.devel.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Devel admin block.
  4. */
  5. function admin_block_devel() {
  6. if (module_exists('devel') && (user_access('access devel information') || user_access('switch users') || user_access('execute php code'))) {
  7. drupal_add_css(drupal_get_path('module', 'admin') . '/includes/admin.devel.css');
  8. drupal_add_js(drupal_get_path('module', 'admin') . '/includes/admin.devel.js');
  9. return array('subject' => t('Devel'), 'content' => drupal_get_form('admin_block_devel_form'));
  10. }
  11. }
  12. /**
  13. * Devel admin block form.
  14. */
  15. function admin_block_devel_form($form, $form_state) {
  16. $panes = array();
  17. if (user_access('access devel information')) {
  18. $panes['performance'] = admin_devel_performance_form();
  19. }
  20. if (user_access('switch users')) {
  21. $panes['switch_user'] = array(
  22. '#title' => t('Switch user'),
  23. 'list' => array('#markup' => theme('links', array(
  24. 'links' => devel_switch_user_list(),
  25. 'attributes' => array('class' => 'links clearfix'),
  26. ))),
  27. 'user' => devel_switch_user_form(),
  28. );
  29. $panes['switch_user']['user']['#submit'] = array('devel_switch_user_form_submit');
  30. }
  31. if (user_access('execute php code')) {
  32. $panes['execute'] = devel_execute_form() + array('#title' => t('Execute PHP'));
  33. $panes['execute']['op']['#submit'] = array('devel_execute_form_submit');
  34. }
  35. if (user_access('access devel information')) {
  36. $panes['menu'] = menu_tree_output(menu_tree_all_data('devel'));
  37. $panes['menu']['#title'] = t('Other tools');
  38. }
  39. if (!empty($panes)) {
  40. $panes['#type'] = 'admin_panes';
  41. return array('panes' => $panes);
  42. }
  43. return array();
  44. }
  45. /**
  46. * Performance "form". Actually renders placeholders that are populated post-exit via javascript.
  47. */
  48. function admin_devel_performance_form() {
  49. $items = array();
  50. if (variable_get('dev_timer', 0) && !variable_get('devel_query_display', FALSE)) {
  51. $items[] = array(
  52. 'data' => "<div class='dev-info'></div>",
  53. 'class' => array('dev-timer'),
  54. );
  55. }
  56. if (variable_get('dev_mem', FALSE) && function_exists('memory_get_usage')) {
  57. $items[] = array(
  58. 'data' => "<div class='dev-info'></div>",
  59. 'class' => array('dev-memory-usage'),
  60. );
  61. }
  62. if (variable_get('devel_query_display', FALSE)) {
  63. $show = "<input type='button' class='form-submit dev-querylog-show' value='" . t('Show querylog') . "'/>";
  64. $hide = "<input type='button' class='form-submit dev-querylog-hide' value='" . t('Hide querylog') . "'/>";
  65. $items[] = array(
  66. 'data' => "<div class='dev-info'></div>{$show}{$hide}",
  67. 'class' => array('dev-query'),
  68. );
  69. }
  70. if ($items) {
  71. return array(
  72. '#title' => t('Performance'),
  73. '#markup' => theme('item_list', array('items' => $items)),
  74. );
  75. }
  76. }