'devel/cache/clear', 'title' => t('empty cache'), 'callback' => 'devel_cache_clear', 'access' => user_access('access devel information')); $items[] = array('path' => 'devel/variable', 'title' => t('variable viewer'), 'callback' => 'devel_variable', 'access' => user_access('access devel information')); $items[] = array('path' => 'devel/switch', 'title' => t('switch user'), 'callback' => 'devel_switch_user', 'access' => user_access('switch users'), 'type' => MENU_CALLBACK); } return $items; } /** * Switch from original user to another user and back. * * Note: taken from mailhandler.module * * Note: You first need to run mailhandler_switch_user without * argument to store the current user. Call mailhandler_switch_user * without argument to set the user back to the original user. * * @param $uid The user ID to switch to * */ function devel_switch_user($uid = NULL) { global $user; static $orig_user = array(); if (isset($uid)) { $user = user_load(array('uid' => $uid)); } // retrieve the initial user, can be called multiple times else if (count($orig_user)) { $user = array_shift($orig_user); array_unshift($orig_user, $user); } // store the initial user else { $orig_user[] = $user; } drupal_goto(); } /** * Implementation of hook_block(). */ function devel_block($op = 'list', $delta = 0) { if ($op == 'list') { $blocks[0]['info'] = t('Switch user'); return $blocks; } else if ($op == 'view') { $links = array(); if (user_access('switch users')) { $users = db_query('SELECT uid, name FROM {users} WHERE uid > 0'); while ($user = db_fetch_object($users)) { $links[] = l(check_plain($user->name), 'devel/switch/'. $user->uid , array(), drupal_get_destination()); } $block['subject'] = t('Switch user'); $block['content'] = theme('item_list', $links); } return $block; } } function devel_variable() { global$conf; print theme('page', dprint_r($conf)); } function devel_timer() { global $timer; list($usec, $sec) = explode(' ', microtime()); $stop = (float)$usec + (float)$sec; $diff = round(($stop - $timer) * 1000, 2); return t(' Page execution time was %time ms.', array('%time' => $diff)); } /** * Implementation of hook_exit(). Displays developer information in the footer. * * We can't move this to hook_footer() since this must run after * drupal_page_footer() in order to work for cached pages. */ function devel_exit($destination = NULL) { global $queries, $memory_init; if (isset($destination)) { // The page we are leaving is a drupal_goto(). Present a redirection page // so that the developer can see the intermediate query log. if (user_access('access devel information') && variable_get('devel_redirect_page', 0)) { $output = t('
The user is being redirected to %destination.
', array('%destination' => "$destination")); print theme('page', $output); // Don't allow the automatic redirect to happen. drupal_page_footer(); exit(); } else { // Make sure not to print anything before the automatic redirect. return; } } if (function_exists('drupal_get_headers') && strstr(drupal_get_headers(), 'xml')) { $is_xml = TRUE; }; if (user_access('access devel information') && !$is_xml) { // try not to break the xml pages // Query log off, timer on if (!variable_get('dev_query', 0) && variable_get('dev_timer', 0)) { $output = '$str"; } } /** * Pretty-print a variable such as an array or object to the browser. * Displays only for users with proper permissions. */ function dprint_r($arr) { if (user_access('access devel information')) { print '
';
print_r($arr);
print '';
}
}
/**
* Print the function call stack. This works even without xdebug installed.
*/
function ddebug_backtrace() {
if (user_access('access devel information')) {
dprint_r(debug_backtrace());
}
}
/**
* Implementation of hook_help().
*/
function devel_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Development helper functions');
}
}
/**
* Implementation of hook_settings().
*/
function devel_settings() {
$output = form_select(t('Display Page Timer'), 'dev_timer', variable_get('dev_timer', 0), array(t('Disabled'), t('Enabled')), t('Display page execution time in the query log box.'));
$output .= form_select(t('Display query log'), 'dev_query', variable_get('dev_query', 0), array(t('Disabled'), t('Enabled')), t('Display a log of the database queries needed to generate the current page, the and the execution time for each. Also, a queries which are repeated during a single page view are summed in the # column, and printed in red since they are candidates for caching.'));
$output .= form_select(t('Display memory usage'), 'dev_mem', variable_get('dev_mem', 0), array(t('Disabled'), t('Enabled')), t('Display how much memory is used to generate the current page. This will show memory usage when devel_init() is called and when devel_exit() is called. PHP must have been compiled with the --enable-memory_limit configuration option for this feature to work.'));
$output .= form_textfield(t('Query execution threshhold'), 'devel_execution', variable_get('devel_execution', 5), 4, 4, t('Enter an integer in milliseconds. Any query which takes longer than this many milliseconds will be highlighted in the query log. This indicates a possibliy inefficient query, or a candidate for caching.'));
$output .= form_select(t('Display redirection page'), 'devel_redirect_page', variable_get('devel_redirect_page', 0), array(t('Disabled'), t('Enabled')), t('When a module executes drupal_goto(), the query log and other developer information is lost. Enabling this setting presents an intermediate page to developers so that the log can be examined before continuing to the destination page.'));
return $output;
}
/**
* Implementation of hook_perm().
*/
function devel_perm() {
return array('access devel information', 'switch users');
}
?>