'. t('This is a list of defined user functions that generated this current request lifecycle. Click on a function name to view its documention.') .'

'; case 'devel/session': return '

'. t('Here are the contents of your $_SESSION variable.') .'

'; case 'devel/variable': $api = variable_get('devel_api_url', 'api.drupal.org'); return '

'. t('This is a list of the variables and their values currently stored in variables table and the $conf array of your settings.php file. These variables are usually accessed with variable_get() and variable_set(). Variables that are too long can slow down your pages.', array('@variable-get-doc' => "http://$api/api/HEAD/function/variable_get", '@variable-set-doc' => "http://$api/api/HEAD/function/variable_set")) .'

'; } } /** * Implementationation of hook_menu(). */ function devel_menu() { $items = array(); // Note: we can't dynamically append destination to querystring. Do so at theme layer. Fix in D7? $items['devel/cache/clear'] = array( 'title' => 'Empty cache', 'page callback' => 'devel_cache_clear', 'description' => 'Clear the CSS cache and all database cache tables which store page, node, theme and variable caches.', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/reference'] = array( 'title' => 'Function reference', 'description' => 'View a list of currently defined user functions with documentation links.', 'page callback' => 'devel_function_reference', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/reinstall'] = array( 'title' => 'Reinstall modules', 'page callback' => 'drupal_get_form', 'page arguments' => array('devel_reinstall'), 'description' => 'Run hook_uninstall() and then hook_install() for a given module.', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/devel_themer'] = array( 'title callback' => 'devel_menu_title_theme_developer', 'title arguments' => array(NULL), 'title' => 'foo', 'description' => 'Quickly enable or disable theme developer module. Useful for removing HTML cruft added by that module.', 'page callback' => 'devel_devel_themer_toggle', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/source'] = array( 'title' => 'Display the PHP code of any file in your Drupal installation', 'page callback' => 'devel_display_source', 'access arguments' => array('display source code'), 'type' => MENU_CALLBACK, 'menu_name' => 'devel', ); $items['devel/menu/reset'] = array( 'title' => 'Rebuild menus', 'description' => 'Rebuild menu based on hook_menu() and revert any custom changes. All menu items return to their default settings.', 'page callback' => 'drupal_get_form', 'page arguments' => array('devel_menu_rebuild'), 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/variable'] = array( 'title' => 'Variable editor', 'description' => 'Edit and delete site variables.', 'page callback' => 'devel_variable_page', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); // we don't want the abbreviated version provided by status report $items['devel/phpinfo'] = array( 'title' => 'PHPinfo()', 'description' => 'View your server\'s PHP configuration', 'page callback' => 'devel_phpinfo', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/php'] = array( 'title' => 'Execute PHP Code', 'description' => 'Execute some PHP code', 'page callback' => 'drupal_get_form', 'page arguments' => array('devel_execute_form'), 'access arguments' => array('execute php code'), 'menu_name' => 'devel', ); $items['devel/theme/registry'] = array( 'title' => 'Theme registry', 'description' => 'View a list of available theme functions across the whole site.', 'page callback' => 'devel_theme_registry', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/field/info'] = array( 'title' => 'Field info', 'description' => 'View fields information across the whole site.', 'page callback' => 'devel_field_info_page', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/elements'] = array( 'title' => 'Hook_elements()', 'description' => 'View the active form/render elements for this site.', 'page callback' => 'devel_elements_page', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/variable/edit/%'] = array( 'title' => 'Variable editor', 'page callback' => 'drupal_get_form', 'page arguments' => array('devel_variable_edit', 3), 'access arguments' => array('access devel information'), 'type' => MENU_CALLBACK, 'menu_name' => 'devel', ); $items['devel/session'] = array( 'title' => 'Session viewer', 'description' => 'List the contents of $_SESSION.', 'page callback' => 'devel_session', 'access arguments' => array('access devel information'), 'menu_name' => 'devel', ); $items['devel/switch'] = array( 'title' => 'Switch user', 'page callback' => 'devel_switch_user', 'access arguments' => array('switch users'), 'type' => MENU_CALLBACK, 'menu_name' => 'devel', ); $items['devel/run-cron'] = array( 'title' => 'Run cron', 'page callback' => 'system_run_cron', 'access arguments' => array('administer site configuration'), 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'), 'menu_name' => 'devel', ); $items['admin/config/development/devel'] = array( 'title' => 'Devel settings', 'description' => 'Helper functions, pages, and blocks to assist Drupal developers. The devel blocks can be managed via the block administration page.', 'page callback' => 'drupal_get_form', 'page arguments' => array('devel_admin_settings'), 'access arguments' => array('administer site configuration'), 'menu_name' => 'devel', ); $items['node/%node/devel/load'] = array( 'title' => 'Dev load', 'page callback' => 'devel_load_object', 'page arguments' => array(1, 'node'), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['node/%node/devel/render'] = array( 'title' => 'Dev render', 'page callback' => 'devel_render_object', 'page arguments' => array('node', 1), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['comment/%comment/devel/load'] = array( 'title' => 'Dev load', 'page callback' => 'devel_load_object', 'page arguments' => array(1, 'comment'), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['comment/%comment/devel/render'] = array( 'title' => 'Dev render', 'page callback' => 'devel_render_object', 'page arguments' => array('comment', 1), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['user/%user/devel/load'] = array( 'title' => 'Dev load', 'page callback' => 'devel_load_object', 'page arguments' => array(1, 'user'), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['user/%user/devel/render'] = array( 'title' => 'Dev render', 'page callback' => 'devel_render_object', 'page arguments' => array('user', 1), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['taxonomy/term/%taxonomy_term/devel/load'] = array( 'title' => 'Dev load', 'page callback' => 'devel_load_object', 'page arguments' => array(2, 'term'), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); $items['taxonomy/term/%taxonomy_term/devel/render'] = array( 'title' => 'Dev render', 'page callback' => 'devel_render_term', 'page arguments' => array(2), 'access callback' => 'user_access', 'access arguments' => array('access devel information'), 'type' => MENU_LOCAL_TASK, 'weight' => 100, ); return $items; } function devel_menu_need_destination() { return array('devel/cache/clear', 'devel/devel_themer', 'devel/reinstall', 'devel/menu/reset', 'admin/og/og', 'devel/variable', 'admin/reports/status/run-cron'); } /** * An implementation of hook_menu_link_alter(). Flag this link as needing alter at display time. * This is more robust that setting alter in hook_menu(). See devel_translated_menu_link_alter(). * **/ function devel_menu_link_alter(&$item) { if (in_array($item['link_path'], devel_menu_need_destination())) { $item['options']['alter'] = TRUE; } } /** * An implementation of hook_translated_menu_item_alter(). Append dynamic * querystring 'destination' to several of our own menu items. * **/ function devel_translated_menu_link_alter(&$item) { if (in_array($item['href'], devel_menu_need_destination())) { $item['localized_options']['query'] = drupal_get_destination(); } } function devel_menu_title_theme_developer() { if (module_exists('devel_themer')) { return t('Disable Theme developer'); } else { return t('Enable Theme developer'); } } function devel_devel_themer_toggle() { if (module_exists('devel_themer')) { module_disable(array('devel_themer')); } else { // Sanity check in case the devel_themer schema is not installed. include_once('./includes/install.inc'); if (drupal_get_schema_versions('devel_themer') == FALSE) { drupal_install_modules(array('devel_themer')); } else { module_enable(array('devel_themer')); } } drupal_theme_rebuild(); menu_rebuild(); drupal_goto(); } /** * Implementation of hook_theme() */ function devel_theme() { // &$cache, $type, $theme, $path return array( 'devel_querylog' => array( 'arguments' => array('header' => array(), 'rows' => array()), ), 'devel_querylog_row' => array( 'arguments' => array('row' => array()), ), ); } /** * Page callback to display syntax hilighted source code * * note: the path for this function is received via $_GET['path'] * example http://www.example.com/devel/source?file=modules/node/node.module * * @param $standalone * Set to FALSE to place the code inside a Drupal page. Otherwise code displays on its own. */ function devel_display_source($standalone = TRUE) { $path = $_GET['file']; // take out the nasties $path = str_replace('../', '', $path); $output = devel_highlight_file($path, $standalone); if ($output) { if ($standalone) { print $output; exit(); } return $output; } else { drupal_set_message(t('Invalid file path'), 'error'); drupal_not_found(); } } /** * Return PHP highlighted file * * @param $path * path to the file * *warning* there is NO VALIDATION in this function * Beware of paths such as '../../../../../etc/apache/httpd.conf' * * @param $standalone * should the returned HTML be wrapped in a full page or will it be output by Drupal? */ function devel_highlight_file($path = NULL, $standalone = FALSE) { if (file_exists($path)) { $source = highlight_file($path, TRUE); // add anchor links before all functions // with doxygen // $source = preg_replace('!(\/\*\*.*?\*\/.*?)(.*?)<\/span>!', ' $0', $source); //$source = preg_replace('!(\/\*\*.*?\*\/).*?function.*?#0000BB">(.*?)<\/span>!', ' $0', $source); if ($standalone) { $source = <<$path $source EOT; } return $source; } else { return FALSE; } } /** * Implementation of hook_init(). */ function devel_init() { if (!devel_silent()) { if (user_access('access devel information')) { devel_set_handler(variable_get('devel_error_handler', DEVEL_ERROR_HANDLER_STANDARD)); // We want to include the class early so that anyone may call krumo() as needed. See http://krumo.sourceforge.net/ has_krumo(); // See http://www.firephp.org/. // Support Libraries API - http://drupal.org/project/libraries if (module_exists('libraries')) { $path = libraries_get_path('FirePHPCore') . '/lib/FirePHPCore/fb.php'; } else { $path = './'. drupal_get_path('module', 'devel') .'/FirePHPCore/lib/FirePHPCore/fb.php'; } if (file_exists($path)) { include_once $path; } // Add CSS for query log if should be displayed. if (variable_get('devel_query_display', 0)) { drupal_add_css(drupal_get_path('module', 'devel') .'/devel.css'); } } } if (variable_get('devel_rebuild_theme_registry', FALSE)) { drupal_theme_rebuild(); if (flood_is_allowed('devel_rebuild_registry_warning', 1)) { flood_register_event('devel_rebuild_registry_warning'); if (!devel_silent() && user_access('access devel information')) { drupal_set_message(t('The theme registry is being rebuilt on every request. Remember to turn off this feature on production websites.', array("!url" => url('admin/config/development/devel')))); } } } } // return boolean. no need for cache here. function has_krumo() { // see README.txt or just download from http://krumo.sourceforge.net/ @include_once './'. drupal_get_path('module', 'devel') .'/krumo/class.krumo.php'; if (function_exists('krumo') && php_sapi_name() != 'cli') { return TRUE; } else { return FALSE; } } /** * Decide whether or not to print a debug variable using krumo(). * * @param $input * @return boolean */ function merits_krumo($input) { return (is_object($input) || is_array($input)) && has_krumo() && variable_get('devel_krumo_skin', '') != 'disabled'; } /** * Calls the http://www.firephp.org/ fb() function if it is found. * * @return void */ function dfb() { if (function_exists('fb') && user_access('access devel information')) { $args = func_get_args(); call_user_func_array('fb', $args); } } function devel_set_handler($handler) { switch ($handler) { case DEVEL_ERROR_HANDLER_STANDARD: // do nothing break; case DEVEL_ERROR_HANDLER_BACKTRACE: if (has_krumo()) { set_error_handler('backtrace_error_handler'); } break; case DEVEL_ERROR_HANDLER_NONE: restore_error_handler(); break; } } function devel_silent() { // isset($_GET['q']) is needed on IIS when calling the front page. q is not set. // Don't interfere with private files/images. return devel_verify_cli() || strpos($_SERVER['HTTP_USER_AGENT'], 'ApacheBench') !== FALSE || !empty($_REQUEST['XDEBUG_PROFILE']) || isset($GLOBALS['devel_shutdown']) || strstr($_SERVER['PHP_SELF'], 'update.php') || (isset($_GET['q']) && ( in_array($_GET['q'], array('upload/js', 'admin/content/node-settings/rebuild')) || substr($_GET['q'], 0, strlen('system/files')) == 'system/files' || substr($_GET['q'], 0, strlen('batch')) == 'batch') ); } /** * Implementation of hook_boot(). Runs even for cached pages. */ function devel_boot() { if (!devel_silent()) { devel_start(); } } // Kickoff our tricks. Put here all code which must run for cached pages too. Called from both devel_boot() and devel_init(). function devel_start() { if (variable_get('dev_mem', 0)) { global $memory_init; $memory_init = memory_get_usage(); } if (devel_query_enabled()) { //TODO: How best to include this? @include_once DRUPAL_ROOT . '/includes/database/log.inc'; Database::startLog('devel');; } if (devel_code_coverage_enabled()) { xdebug_start_code_coverage(); } // We need user_access() in the shutdown function. make sure it gets loaded. // Also prime the drupal_get_filename() static with user.module's location to // avoid a stray query. drupal_get_filename('module', 'user', 'modules/user/user.module'); drupal_load('module', 'user'); register_shutdown_function('devel_shutdown'); } function backtrace_error_handler($errno, $message, $filename, $line) { // Don't respond to the error if it was suppressed with a '@' if (error_reporting() == 0) return; if ($errno & (E_ALL ^ E_NOTICE)) { // We can't use the PHP E_* constants here as not all versions of PHP have all // the constants defined, so for consistency, we just use the numeric equivelant. $types = array( 1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning', 4096 => 'recoverable error', 8192 => 'deprecated', 16384 => 'user deprecated', ); $entry = $types[$errno] .': '. $message .' in '. $filename .' on line '. $line .'.'; if (variable_get('error_level', 1) == 1) { $backtrace = debug_backtrace(); foreach ($backtrace as $call) { $nicetrace[$call['function']] = $call; } krumo($nicetrace); } watchdog('php', '%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line), WATCHDOG_ERROR); } } /** * Implement hook_permission(). */ function devel_permission() { return array( 'access devel information' => array( 'description' => t('View developer output like variable printouts, query log, etc.'), 'title' => t('Access developer information'), ), 'execute php code' => array( 'title' => t('Execute PHP code'), 'description' => t('Run arbitrary PHP from a block. Danger!'), ), 'switch users' => array( 'title' => t('Switch users'), 'description' => t('Become any user on the site with just a click. Danger!'), ), 'display source code' => array( 'title' => t('Display source code'), 'description' => t('View the site\'s php source code. Danger!'), ), ); } function devel_block_info() { $blocks['execute_php'] = array( 'info' => t('Execute PHP'), 'cache' => DRUPAL_NO_CACHE, ); $blocks['switch_user'] = array( 'info' => t('Switch user'), 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } /** * Implementation of hook_block_configure(). */ function devel_block_configure($delta) { if ($delta == 'switch_user') { $form['devel_switch_user_list_size'] = array( '#type' => 'textfield', '#title' => t('Number of users to display in the list'), '#default_value' => variable_get('devel_switch_user_list_size', 10), '#size' => '3', '#maxlength' => '4', ); return $form; } } function devel_block_save($delta, $edit = array()) { if ($delta == 'switch_user') { variable_set('devel_switch_user_list_size', $edit['devel_switch_user_list_size']); } } function devel_block_view($delta) { $block = array(); switch ($delta) { case 'switch_user': $block = devel_block_switch_user(); break; case 'execute_php': if (user_access('execute php code')) { $block['subject'] = t('Execute PHP'); $block['content'] = drupal_get_form('devel_execute_form'); } break; } return $block; } function devel_block_switch_user() { $links = devel_switch_user_list(); if (!empty($links)) { $block['subject'] = t('Switch user'); $build['devel_links'] = array('#theme' => 'links', '#links' => $links); $build['devel_form'] = drupal_get_form('devel_switch_user_form'); $block['content'] = $build; return $block; } } function devel_switch_user_list() { $links = array(); if (user_access('switch users')) { $list_size = variable_get('devel_switch_user_list_size', 10); $dest = drupal_get_destination(); // Try to find at least $list_size users that can switch. $roles = user_roles(1, 'switch users'); if (isset($roles[2])) { // If authenticated users have this permission, just grab // the last $list_size users, since there won't be records in // {user_roles} and every user on the system can switch. $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u WHERE u.uid > 0 ORDER BY u.access DESC", 0, $list_size); } else { $where = array('u.uid = 1'); if (count($roles)) { $where[] = 'r.rid IN ('. implode(',', array_keys($roles)) .')'; } $where_sql = implode(' OR ', $where); $users = db_query_range("SELECT DISTINCT u.uid, u.name, u.access FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, $list_size); } foreach ($users as $user) { $links[$user->uid] = array( 'title' => theme('placeholder', $user->name), 'href' => 'devel/switch/'. $user->name, 'query' => $dest, 'attributes' => array('title' => t('This user can switch back.')), 'html' => TRUE, ); } $num_links = count($links); if ($num_links < $list_size) { // If we don't have enough, add distinct uids until we hit $list_size. $users = db_query_range('SELECT uid, name, access FROM {users} WHERE uid > 0 AND uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, $list_size - $num_links); foreach ($users as $user) { if (count($links) >= $list_size) { break; } $links[$user->uid] = array( 'title' => $user->name ? $user->name : 'anon', 'href' => 'devel/switch/'. $user->name, 'query' => $dest, 'attributes' => array('title' => t('Caution: this user will be unable switch back.')), ); } } } return $links; } function devel_phpinfo() { print phpinfo(); exit; } function devel_switch_user_form() { $form['username'] = array( '#type' => 'textfield', '#description' => t('Enter username'), '#autocomplete_path' => 'user/autocomplete', '#maxlength' => USERNAME_MAX_LENGTH, '#size' => 16, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Switch'), ); return $form; } function devel_doc_function_form() { $version = devel_get_core_version(VERSION); $form['function'] = array( '#type' => 'textfield', '#description' => t('Enter function name for api lookup'), '#size' => 16, '#maxlength' => 255, ); $form['version'] = array('#type' => 'value', '#value' => $version); $form['submit_button'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } function devel_doc_function_form_submit($form, &$form_state) { $version = $form_state['values']['version']; $function = $form_state['values']['function']; $api = variable_get('devel_api_url', 'api.drupal.org'); $form_state['redirect'] = "http://$api/api/$version/function/$function"; } function devel_switch_user_form_validate($form, &$form_state) { if (!$account = user_load_by_name($form_state['values']['username'])) { form_set_error('username', t('Username not found')); } } function devel_switch_user_form_submit($form, &$form_state) { $form_state['redirect'] = 'devel/switch/'. $form_state['values']['username']; } /** * TODO: I switched params as per http://drupal.org/node/144132#form-alter but needs work still * Implementation of hook_form_alter(). */ function devel_form_alter(&$form, $form_state, $form_id, $key_in = NULL) { if (user_access('access devel information') && variable_get('devel_form_weights', 0)) { $children = element_children($form); if (empty($children)) { if (isset($form['#type']) && !in_array($form['#type'], array('value', 'hidden'))) { if (!isset($form['#title'])) { $form['#title'] = ''; } $form['#title'] .= " (key=$key_in, weight=". (isset($form['#weight']) ? $form['#weight'] : 0) .')'; } } else { foreach (element_children($form) as $key) { // We need to add the weight to fieldsets. if (element_children($form[$key])) { // Which are a container of others. if (!isset($form[$key]['#title'])) { $form[$key]['#title'] = ''; } $form[$key]['#title'] .= " (key=$key, weight=". (isset($form[$key]['#weight']) ? $form[$key]['#weight'] : 0) .')'; } devel_form_alter($form[$key], $form_state, $form_id, $key); } } } } // An implementation of hook_exit(). function devel_exit($destination = NULL) { global $user; if (isset($destination) && !devel_silent()) { // The page we are leaving is a drupal_goto(). Present a redirection page // so that the developer can see the intermediate query log. // We don't want to load user module here, so keep function_exists() call. if (isset($user) && function_exists('user_access') && user_access('access devel information') && variable_get('devel_redirect_page', 0)) { $output = t_safe('

The user is being redirected to @destination.

', array('@destination' => $destination)); drupal_set_page_content($output); $page = element_info('page'); print drupal_render_page($page); // Don't allow the automatic redirect to happen. drupal_page_footer(); exit(); } else { $GLOBALS['devel_redirecting'] = TRUE; } } } /** * See devel_start() which registers this function as a shutdown function. */ function devel_shutdown() { // Register the real shutdown function so it runs later than other shutdown functions. register_shutdown_function('devel_shutdown_real'); } // Borrowed from drush. function devel_verify_cli() { if (php_sapi_name() == 'cgi') { return (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0); } return (php_sapi_name() == 'cli'); } function devel_page_alter($page) { if (variable_get('devel_page_alter', FALSE) && user_access('access devel information')) { dpm($page, 'page'); } } /** * See devel_shutdown() which registers this function as a shutdown function. Displays developer information in the footer. */ function devel_shutdown_real() { global $memory_init, $user; $output = $txt = ''; // Set $GLOBALS['devel_shutdown'] = FALSE in order to supress the // devel footer for a page. Not necessary if your page outputs any // of the Content-type http headers tested below (e.g. text/xml, // text/javascript, etc). This is is advised where applicable. if (!isset($GLOBALS['devel_shutdown']) && !isset($GLOBALS['devel_redirecting'])) { // Try not to break non html pages. if (function_exists('drupal_get_header')) { if ($headers = drupal_get_header()) { $formats = array('xml', 'javascript', 'json', 'plain', 'image', 'application', 'csv', 'x-comma-separated-values'); foreach ($formats as $format) { if (strstr($headers['content-type'], $format)) { return; } } } } if (isset($user) && user_access('access devel information')) { if (devel_query_enabled()) { $output .= devel_shutdown_query(); } if (variable_get('dev_mem', FALSE)) { $memory_shutdown = memory_get_usage(); $args = array('@memory_boot' => round($memory_init / 1024 / 1024, 2), '@memory_shutdown' => round($memory_shutdown / 1024 / 1024, 2), '@memory_peak' => round(memory_get_peak_usage(TRUE) / 1024 / 1024, 2)); $msg = '

Memory usage:

Memory used at: devel_boot()=@memory_boot MB, devel_shutdown()=@memory_shutdown MB, PHP peak usage=@memory_peak MB.
'; // theme() may not be available. not t() either. $output .= t_safe($msg, $args); } // Code coverage reporting. if (devel_code_coverage_enabled()) { $mode = variable_get('devel_code_coverage', FALSE); $coverage = xdebug_get_code_coverage(); if ($mode == 1) { $output .= dpr(array_keys($coverage), TRUE); } else { $output .= dpr($coverage, TRUE); } } } if ($output) { // TODO: gzip this text if we are sending a gzip page. see drupal_page_header(). // For some reason, this is not actually printing for cached pages even though it gets executed // and $output looks good. print $output; } } } function devel_shutdown_query() { $output = ''; $queries = Database::getLog('devel', 'default'); list($counts, $query_summary) = devel_query_summary($queries); // Query log off, timer on. if (!variable_get('devel_query_display', 0) && variable_get('dev_timer', 0)) { $output .= '
'. devel_timer() .' '. $query_summary. '
'; } // Query log on. $sum = 0; if (variable_get('devel_query_display', FALSE)) { $output .= '
'; $output .= $query_summary; // calling theme() during shutdown is very bad if registry gets rebuilt like when making a change on admin/build/modules // so we check for presence of theme registry before calling theme() if (function_exists('theme_get_registry') && theme_get_registry()) { $txt = t_safe(' Queries taking longer than @threshold ms and queries executed more than once, are highlighted.', array('@threshold' => variable_get('devel_execution', 5))); if (variable_get('dev_timer', 0)) { $txt .= devel_timer(); } $output .= $txt; $output .= '
'; $output .= devel_query_table($queries, $counts); } else { $output .= $txt . '' . dprint_r($queries, TRUE); } } return $output; } function devel_query_enabled() { return method_exists('Database', 'getLog') && variable_get('dev_query', FALSE); } function devel_code_coverage_enabled() { return function_exists('xdebug_get_code_coverage') && variable_get('devel_code_coverage', FALSE); } function devel_query_summary($queries) { if (variable_get('dev_query', FALSE) && is_array($queries)) { $sum = 0; foreach ($queries as $query) { $text[] = $query['query']; $sum += $query['time']; } $counts = array_count_values($text); return array($counts, t_safe('Executed @queries queries in @time milliseconds.', array('@queries' => count($queries), '@time' => round($sum * 1000, 2)))); } } function t_safe($string, $args) { // get_t caused problems here with theme registry after changing on admin/build/modules. the theme_get_registry call is needed. if (function_exists('t') && function_exists('theme_get_registry')) { theme_get_registry(); return t($string, $args); } else { strtr($string, $args); } } /** * Returns a list of all currently defined user functions in the current * request lifecycle, with links their documentation. */ function devel_function_reference() { $functions = get_defined_functions(); $version = devel_get_core_version(VERSION); $ufunctions = $functions['user']; sort($ufunctions); $api = variable_get('devel_api_url', 'api.drupal.org'); foreach ($ufunctions as $function) { $links[] = l($function, "http://$api/api/$version/function/$function"); } return theme('item_list', $links); } function devel_get_core_version($version) { $version_parts = explode('.', $version); // Map from 4.7.10 -> 4.7 if ($version_parts[0] < 5) { return $version_parts[0] .'.'. $version_parts[1]; } // Map from 5.5 -> 5 or 6.0-beta2 -> 6 else { return $version_parts[0]; } } // See http://drupal.org/node/126098 function devel_is_compatible_optimizer() { ob_start(); phpinfo(); $info = ob_get_contents(); ob_end_clean(); // Match the Zend Optimizer version in the phpinfo information $found = preg_match('/Zend Optimizer v([0-9])\.([0-9])\.([0-9])/', $info, $matches); if ($matches) { $major = $matches[1]; $minor = $matches[2]; $build = $matches[3]; if ($major >= 3) { if ($minor >= 3) { return TRUE; } elseif ($minor == 2 && $build >= 8) { return TRUE; } else { return FALSE; } } else { return FALSE; } } else { return TRUE; } } function devel_admin_settings() { $form['queries'] = array('#type' => 'fieldset', '#title' => t('Query log')); $description = t("Collect query info. If disabled, no query log functionality will work."); if (!devel_is_compatible_optimizer()) { $description = t('You must disable or upgrade the php Zend Optimizer extension in order to enable this feature. The minimum required version is 3.2.8. Earlier versions of Zend Optimizer are horribly buggy and segfault your Apache ... ', array('!url' => url('http://drupal.org/node/126098'))) . $description; } $form['queries']['dev_query'] = array('#type' => 'checkbox', '#title' => t('Collect query info'), '#default_value' => variable_get('dev_query', 0), '#disabled' => !devel_is_compatible_optimizer() ? TRUE : FALSE, '#description' => $description, ); $form['queries']['devel_query_display'] = array('#type' => 'checkbox', '#title' => t('Display query log'), '#default_value' => variable_get('devel_query_display', 0), '#description' => t('Display a log of the database queries needed to generate the current page, and the execution time for each. Also, queries which are repeated during a single page view are summed in the # column, and printed in red since they are candidates for caching.')); $form['queries']['devel_query_sort'] = array('#type' => 'radios', '#title' => t('Sort query log'), '#default_value' => variable_get('devel_query_sort', DEVEL_QUERY_SORT_BY_SOURCE), '#options' => array(t('by source'), t('by duration')), '#description' => t('The query table can be sorted in the order that the queries were executed or by descending duration.'), ); $form['queries']['devel_execution'] = array('#type' => 'textfield', '#title' => t('Slow query highlighting'), '#default_value' => variable_get('devel_execution', 5), '#size' => 4, '#maxlength' => 4, '#description' => 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 possibly inefficient query, or a candidate for caching.'), ); $form['devel_api_url'] = array('#type' => 'textfield', '#title' => t('API Site'), '#default_value' => variable_get('devel_api_url', 'api.drupal.org'), '#description' => t('The base URL for your developer documentation links. You might change this if you run api.module locally.', array('!url' => url('http://drupal.org/project/api')))); $form['dev_timer'] = array('#type' => 'checkbox', '#title' => t('Display page timer'), '#default_value' => variable_get('dev_timer', 0), '#description' => t('Display page execution time in the query log box.'), ); $form['dev_mem'] = array('#type' => 'checkbox', '#title' => t('Display memory usage'), '#default_value' => variable_get('dev_mem', 0), '#description' => 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.'), ); $form['devel_code_coverage'] = array( '#type' => 'radios', '#title' => t('Code Coverage'), '#disabled' => !function_exists('xdebug_start_code_coverage'), '#default_value' => variable_get('devel_code_coverage', 0), '#options' => array(t('Disabled'), t('Files only'), 'Files and lines'), '#description' => t('Show the files (and optionally the lines in those files) which were loaded by PHP to fulfill this request. In general, fewer files is better since parsing files costs significant performance. Requires xdebug.'), ); $form['devel_redirect_page'] = array('#type' => 'checkbox', '#title' => t('Display redirection page'), '#default_value' => variable_get('devel_redirect_page', 0), '#description' => 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.'), ); $form['devel_form_weights'] = array('#type' => 'checkbox', '#title' => t('Display form element keys and weights'), '#default_value' => variable_get('devel_form_weights', 0), '#description' => t('Form element names are needed for performing themeing or altering a form. Their weights determine the position of the element. Enabling this setting will show these keys and weights beside each form item.'), ); $form['devel_page_alter'] = array('#type' => 'checkbox', '#title' => t('Display $page array'), '#default_value' => variable_get('devel_page_alter', FALSE), '#description' => t('Display $page array from hook_page_alter() in the messages area of each page.'), ); $form['devel_error_handler'] = array('#type' => 'radios', '#title' => t('Error handler'), '#default_value' => variable_get('devel_error_handler', DEVEL_ERROR_HANDLER_STANDARD), '#options' => array(DEVEL_ERROR_HANDLER_NONE => t('None'), DEVEL_ERROR_HANDLER_STANDARD => t('Standard drupal')), '#description' => t('Choose an error handler for your site. Backtrace prints nice debug information when an error is noticed, and you choose to show errors on screen. Backtrace requires the krumo library. None is a good option when stepping through the site in your debugger.', array('@krumo' => url('http://krumo.sourceforge.net'), '@choose' => url('admin/settings/error-reporting'))), ); if (has_krumo()) { $form['devel_error_handler']['#options'][DEVEL_ERROR_HANDLER_BACKTRACE] = t('Backtrace'); } $options = drupal_map_assoc(array('default', 'blue', 'green', 'orange', 'schablon.com', 'disabled')); $form['devel_krumo_skin'] = array( '#type' => 'radios', '#title' => t('Krumo display'), '#description' => t('Select a skin for your debug messages or select disabled to display object and array output in standard PHP format.'), '#options' => $options, '#default_value' => variable_get('devel_krumo_skin', 'default'), ); $form['devel_rebuild_theme_registry'] = array( '#type' => 'checkbox', '#title' => t('Rebuild the theme registry on every page load'), '#description' => t('While creating new templates and theme_ overrides the theme registry needs to be rebuilt.'), '#default_value' => variable_get('devel_rebuild_theme_registry', FALSE), ); return system_settings_form($form); } /** * Menu callback; clears all caches, then redirects to the previous page. */ function devel_cache_clear() { // If you used to implement our own cache clear hook, implement hook_flush_caches instead. See drupal_flush_all_caches() drupal_flush_all_caches(); drupal_set_message('Cache cleared.'); drupal_goto(); } /** * Generates the execute block form. */ function devel_execute_form() { $form['code'] = array( '#type' => 'textarea', '#title' => t('PHP code to execute'), '#description' => t('Enter some code. Do not use <?php ?> tags.') ); $form['op'] = array('#type' => 'submit', '#value' => t('Execute')); $form['#redirect'] = FALSE; $form['#skip_duplicate_check'] = TRUE; return $form; } /** * Process PHP execute form submissions. */ function devel_execute_form_submit($form, &$form_state) { ob_start(); print eval($form_state['values']['code']); dsm(ob_get_clean()); } /** * Menu callback; clear the database, resetting the menu to factory defaults. */ function devel_menu_rebuild() { menu_rebuild(); drupal_set_message(t('The menu router has been rebuilt.')); drupal_goto(); } /** * Display a dropdown of installed modules with the option to reinstall them. */ function devel_reinstall($form, &$form_state) { $output = ''; $modules = module_list(); sort($modules); $options = drupal_map_assoc($modules); $form['list'] = array( '#type' => 'checkboxes', '#options' => $options, '#description' => t('Uninstall and then install the selected modules. hook_uninstall() and hook_install() will be executed and the schema version number will be set to the most recent update number. You may have to manually clear out any existing tables first if the module doesn\'t implement hook_uninstall().'), ); $form['submit'] = array( '#value' => t('Reinstall'), '#type' => 'submit', ); if (empty($form_state['post'])) { drupal_set_message(t('Warning - will delete your module tables and variables.'), 'error'); } return $form; } /** * Process reinstall menu form submissions. */ function devel_reinstall_submit($form, &$form_state) { require_once './includes/install.inc'; $modules = array_filter($form_state['values']['list']); foreach ($modules as $module) { module_load_install($module); $versions = drupal_get_schema_versions($module); drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED); module_invoke($module, 'uninstall'); _drupal_install_module($module); module_invoke($module, 'enable'); drupal_get_schema(NULL, TRUE); drupal_set_message(t('Uninstalled and installed the %name module.', array('%name' => $module))); } } // Menu callback. function devel_theme_registry() { drupal_theme_initialize(); $hooks = theme_get_registry(); ksort($hooks); return kprint_r($hooks, TRUE); } // Menu callback. function devel_field_info_page() { $info = field_info_fields(); return kprint_r($info, TRUE); } /** * Menu callback; display all variables. */ function devel_variable_page() { // We return our own $page so as to avoid blocks. $output = drupal_get_form('devel_variable_form'); drupal_set_page_content($output); $page = element_info('page'); return $page; } function devel_variable_form() { $header = array( 'name' => array('data' => t('Name'), 'field' => 'name', 'sort' => 'asc'), 'value' => array('data' => t('Value'), 'field' => 'value'), 'length' => array('data' => t('Length'), 'field' => 'length'), 'edit' => array('data' => t('Operations')), ); // TODO: we could get variables out of $conf but that would include hard coded ones too. ideally i would highlight overrridden/hard coded variables $query = db_select('variable', 'v')->extend('TableSort'); $query->fields('v', array('name', 'value')); switch (db_driver()) { case 'mssql': $query->addExpression("COL_LENGTH('{variable}', 'value')", 'length'); break; default: $query->addExpression("CONVERT(LENGTH(v.value), UNSIGNED INTEGER)", 'length'); break; } $result = $query ->orderByHeader($header) ->execute(); foreach ($result as $row) { // $variables[$row->name] = ''; $options[$row->name]['name'] = check_plain($row->name); if (merits_krumo($row->value)) { $value = krumo_ob(variable_get($row->name, NULL)); } else { if (drupal_strlen($row->value) > 70) { $value = check_plain(drupal_substr($row->value, 0, 65)) .'...'; } else { $value = check_plain($row->value); } } $options[$row->name]['value'] = $value; $options[$row->name]['length'] = $row->length; $options[$row->name]['edit'] = l(t('edit'), "devel/variable/edit/$row->name"); } $form['variables'] = array( '#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => t('No variables.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Delete'), ); // krumo($form); return $form; } function devel_variable_form_submit($form, &$form_state) { $deletes = array_filter($form_state['values']['variables']); array_walk($deletes, 'variable_del'); drupal_set_message(format_plural(count($deletes), 'One variable deleted.', '@count variables deleted.')); } function devel_variable_edit($form, &$form_state, $name) { $value = variable_get($name, 'not found'); $form['name'] = array( '#type' => 'value', '#value' => $name ); $form['value'] = array( '#type' => 'item', '#title' => t('Old value'), '#markup' => dpr($value, TRUE), ); if (is_string($value) || is_numeric($value)) { $form['new'] = array( '#type' => 'textarea', '#title' => t('New value'), '#default_value' => $value ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); } else { $api = variable_get('devel_api_url', 'api.drupal.org'); $form['new'] = array( '#type' => 'item', '#title' => t('New value'), '#value' => t('Sorry, complex variable types may not be edited yet. Use the Execute PHP block and the variable_set() function.', array('@variable-set-doc' => "http://$api/api/HEAD/function/variable_set")) ); } drupal_set_title($name); return $form; } function devel_variable_edit_submit($form, &$form_state) { variable_set($form_state['values']['name'], $form_state['values']['new']); drupal_set_message(t('Saved new value for %name.', array('%name' => $form_state['values']['name']))); 'devel/variable'; } /** * Menu callback: display the session. */ function devel_session() { global $user; $output = kprint_r($_SESSION, TRUE); $headers = array(t('Session name'), t('Session ID')); $output .= theme('table', $headers, array(array(session_name(), session_id()))); return $output; } /** * Switch from original user to another user and back. * We don't call session_save_session() because we really want to change users. Usually unsafe! * * @param $name The username to switch to. */ function devel_switch_user($name = NULL) { global $user; static $orig_user = array(); if (isset($name)) { $user = user_load_by_name($name); } // Retrieve the initial user. Can be called multiple times. elseif (count($orig_user)) { $user = array_shift($orig_user); array_unshift($orig_user, $user); } // Store the initial user. else { $orig_user[] = $user; } drupal_goto(); } /** * Menu callback; prints the loaded structure of the current node/user. */ function devel_load_object($object, $name = NULL) { $title = isset($object->title) ? $object->title : $object->name; drupal_set_title($title); return kdevel_print_object($object, '$'. $name .'->'); } /** * Menu callback; prints the render structure of the a term. */ function devel_render_term($term) { $build = array(); $build += field_attach_view('taxonomy_term', $term); if (!empty($term->description)) { $build['term_description'] = array( '#markup' => filter_xss_admin($term->description), '#weight' => -1, '#prefix' => '
', '#suffix' => '
', ); } return kdevel_print_object($build, '$term->'); } /** * Menu callback; prints the render structure of the current object (currently node or user). */ function devel_render_object($type, $object) { $output = ''; $title = isset($object->title) ? $object->title : $object->name; // not sure why menu system doesn't give us a reasonable title here. drupal_set_title($title); $function = $type .'_build_content'; $content = $function($object); return kdevel_print_object($content, '$'. $type .'->'); } function devel_elements_page() { return kdevel_print_object(module_invoke_all('elements')); } /** * Print an object or array using either Krumo (if installed) or devel_print_object() * * @param $object * array or object to print * @param $prefix * prefixing for output items */ function kdevel_print_object($object, $prefix = NULL) { return has_krumo() ? krumo_ob($object) : devel_print_object($object, $prefix); } // Save krumo htlm using output buffering. function krumo_ob($object) { ob_start(); krumo($object); $output = ob_get_contents(); ob_end_clean(); return $output; } /** * Display an object or array * * @param $object * the object or array * @param $prefix * prefix for the output items (example "$node->", "$user->", "$") * @param $header * set to FALSE to suppress the output of the h3 */ function devel_print_object($object, $prefix = NULL, $header = TRUE) { drupal_add_css(drupal_get_path('module', 'devel') .'/devel.css'); $output = '
'; if ($header) { $output .= '

'. t('Display of !type !obj', array('!type' => str_replace(array('$', '->'), '', $prefix), '!obj' => gettype($object))) .'

'; } $output .= _devel_print_object($object, $prefix); $output .= '
'; return $output; } /** * Recursive (and therefore magical) function goes through an array or object and * returns a nicely formatted listing of its contents. * * @param $obj * array or object to recurse through * @param $prefix * prefix for the output items (example "$node->", "$user->", "$") * @param $parents * used by recursion * @param $object * used by recursion * @return * fomatted html * * @todo * currently there are problems sending an array with a varname */ function _devel_print_object($obj, $prefix = NULL, $parents = NULL, $object = FALSE) { static $root_type, $out_format; // TODO: support objects with references. See http://drupal.org/node/234581. if (isset($obj->view)) { return; } if (!isset($root_type)) { $root_type = gettype($obj); if ($root_type == 'object') { $object = TRUE; } } if (is_object($obj)) { $obj = (array)$obj; } if (is_array($obj)) { $output = "
\n"; foreach ($obj as $field => $value) { if ($field == 'devel_flag_reference') { continue; } if (!is_null($parents)) { if ($object) { $field = $parents .'->'. $field; } else { if (is_int($field)) { $field = $parents .'['. $field .']'; } else { $field = $parents .'[\''. $field .'\']'; } } } $type = gettype($value); $show_summary = TRUE; $summary = NULL; if ($show_summary) { switch ($type) { case 'string' : case 'float' : case 'integer' : if (strlen($value) == 0) { $summary = t("{empty}"); } elseif (strlen($value) < 40) { $summary = htmlspecialchars($value); } else { $summary = format_plural(drupal_strlen($value), '1 character', '@count characters'); } break; case 'array' : case 'object' : $summary = format_plural(count((array)$value), '1 element', '@count elements'); break; case 'boolean' : $summary = $value ? t('TRUE') : t('FALSE'); break; } } if (!is_null($summary)) { $typesum = '('. $type .', '. $summary .')'; } else { $typesum = '('. $type .')'; } $output .= ''; $output .= "
{$prefix}{$field} $typesum
\n"; $output .= "
\n"; // Check for references. if (is_array($value) && isset($value['devel_flag_reference'])) { $value['devel_flag_reference'] = TRUE; } // Check for references to prevent errors from recursions. if (is_array($value) && isset($value['devel_flag_reference']) && !$value['devel_flag_reference']) { $value['devel_flag_reference'] = FALSE; $output .= _devel_print_object($value, $prefix, $field); } elseif (is_object($value)) { $value->devel_flag_reference = FALSE; $output .= _devel_print_object((array)$value, $prefix, $field, TRUE); } else { $value = is_bool($value) ? ($value ? 'TRUE' : 'FALSE') : $value; $output .= htmlspecialchars(print_r($value, TRUE)) ."\n"; } $output .= "
\n"; } $output .= "
\n"; } return $output; } /** * Adds a table at the bottom of the page cataloguing data on all the database queries that were made to * generate the page. */ function devel_query_table($queries, $counts) { $version = devel_get_core_version(VERSION); $header = array ('ms', '#', 'where', 'query', 'target'); $i = 0; $api = variable_get('devel_api_url', 'api.drupal.org'); foreach ($queries as $query) { $function = $query['caller']['function']; $count = isset($counts[$query['query']]) ? $counts[$query['query']] : 0; $diff = round($query['time'] * 1000, 2); if ($diff > variable_get('devel_execution', 5)) { $cell[$i][] = array ('data' => $diff, 'class' => 'marker'); } else { $cell[$i][] = $diff; } if ($count > 1) { $cell[$i][] = array ('data' => $count, 'class' => 'marker'); } else { $cell[$i][] = $count; } $cell[$i][] = l($function, "http://$api/api/$version/function/$function"); $cell[$i][] = check_plain($query['query']); $cell[$i][] = $query['target']; $i++; unset($diff, $count); } if (variable_get('devel_query_sort', DEVEL_QUERY_SORT_BY_SOURCE)) { usort($cell, '_devel_table_sort'); } return theme('devel_querylog', array('header' => $header, 'rows' => $cell)); } function theme_devel_querylog_row($row) { $i = 0; $output = ''; foreach ($row as $cell) { $i++; if (is_array($cell)) { $data = !empty($cell['data']) ? $cell['data'] : ''; unset($cell['data']); $attr = $cell; } else { $data = $cell; $attr = array(); } if (!empty($attr['class'])) { $attr['class'] .= " cell cell-$i"; } else { $attr['class'] = "cell cell-$i"; } $attr = drupal_attributes($attr); $output .= "
$data
"; } return $output; } function theme_devel_querylog($variables) { $header = $variables['header']; $rows = $variables['rows']; $output = ''; if (!empty($header)) { $output .= "
"; $output .= theme('devel_querylog_row', $header); $output .= "
"; } if (!empty($rows)) { $i = 0; foreach ($rows as $row) { $i++; $zebra = ($i % 2) == 0 ? 'even' : 'odd'; $output .= "
"; $output .= theme('devel_querylog_row', $row); $output .= "
"; } } return $output; } function _devel_table_sort($a, $b) { $a = is_array($a[0]) ? $a[0]['data'] : $a[0]; $b = is_array($b[0]) ? $b[0]['data'] : $b[0]; if ($a < $b) { return 1; } if ($a > $b) { return -1; } return 0; } /** * Displays page execution time at the bottom of the page. */ function devel_timer() { $time = timer_read('page'); return t_safe(' Page execution time was @time ms.', array('@time' => $time)); } // An alias for drupal_debug(). function dd($data, $label = NULL) { return drupal_debug($data, $label); } // Log any variable to a drupal_debug.log in the site's temp directory. // See http://drupal.org/node/314112 function drupal_debug($data, $label = NULL) { ob_start(); print_r($data); $string = ob_get_clean(); if ($label) { $out = $label .': '. $string; } else { $out = $string; } $out .= "\n"; // The temp directory does vary across multiple simpletest instances. $file = file_directory_path('temporary') . '/drupal_debug.txt'; if (file_put_contents($file, $out, FILE_APPEND) === FALSE) { drupal_set_message(t('The file could not be written.'), 'error'); return FALSE; } } /** * Prints the arguments passed into the current function */ function dargs($always = TRUE) { static $printed; if ($always || !$printed) { $bt = debug_backtrace(); print kdevel_print_object($bt[1]['args']); $printed = TRUE; } } /** * Print a variable to the 'message' area of the page. Uses drupal_set_message() */ function dpm($input, $name = NULL) { if (user_access('access devel information')) { $export = kprint_r($input, TRUE, $name); drupal_set_message($export); } } /** * Var_dump() a variable to the 'message' area of the page. Uses drupal_set_message() */ function dvm($input, $name = NULL) { if (user_access('access devel information')) { $export = dprint_r($input, TRUE, $name, 'var_dump', FALSE); drupal_set_message($export); } } // legacy function that was poorly named. use dpm() instead, since the 'p' maps to 'print_r' function dsm($input, $name = NULL) { dpm($input, $name); } /** * An alias for dprint_r(). Saves carpal tunnel syndrome. */ function dpr($input, $return = FALSE, $name = NULL) { return dprint_r($input, $return, $name); } /** * An alias for kprint_r(). Saves carpal tunnel syndrome. */ function kpr($input, $return = FALSE, $name = NULL) { return kprint_r($input, $return, $name); } /** * Like dpr, but uses var_dump() instead */ function dvr($input, $return = FALSE, $name = NULL) { return dprint_r($input, $return, $name, 'var_dump', FALSE); } function kprint_r($input, $return = FALSE, $name = NULL, $function = 'print_r') { // We do not want to krumo() strings and integers and such if (merits_krumo($input)) { if (user_access('access devel information')) { return $return ? (isset($name) ? $name .' => ' : '') . krumo_ob($input) : krumo($input); } } else { return dprint_r($input, $return, $name, $function); } } /** * Pretty-print a variable to the browser (no krumo). * Displays only for users with proper permissions. If * you want a string returned instead of a print, use the 2nd param. */ function dprint_r($input, $return = FALSE, $name = NULL, $function = 'print_r', $check= TRUE) { if (user_access('access devel information')) { if ($name) { $name .= ' => '; } ob_start(); $function($input); $output = ob_get_clean(); if ($check) { $output = check_plain($output); } if (count($input, COUNT_RECURSIVE) > DEVEL_MIN_TEXTAREA) { // don't use fapi here because sometimes fapi will not be loaded $printed_value = "'; } else { $printed_value = '
'. $name . $output .'
'; } if ($return) { return $printed_value; } else { print $printed_value; } } } /** * Print the function call stack. */ function ddebug_backtrace() { if (user_access('access devel information')) { $trace = debug_backtrace(); array_shift($trace); foreach ($trace as $key => $value) { $rich_trace[$value['function']] = $value; } if (has_krumo()) { print krumo($rich_trace); } else { dprint_r($rich_trace); } } } /* * migration related functions */ /** * Update node_comment_statistics table for nodes with comments. * TODO: if 2 comments have exact same timestamp, the function can get wrong uid and name fields. * Handles when comment timestamps have been manually set in admin * * @return void **/ function devel_rebuild_node_comment_statistics() { // Empty table db_delete('node_comment_statistics'); $sql = "INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) (SELECT nid, c.timestamp, name, uid, comment_count FROM {comments} c INNER JOIN (SELECT MAX(timestamp) AS timestamp, COUNT(*) AS comment_count FROM {comments} WHERE status=%d GROUP BY nid) AS c2 ON c.timestamp=c2.timestamp)"; db_query($sql, COMMENT_PUBLISHED); // Insert 0 count records into the node_comment_statistics for nodes that are missing. See comment_enable() db_query_temporary("SELECT n.nid, n.changed, n.uid FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE c.comment_count IS NULL", 'missing_nids'); db_query("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, n.uid, 0 FROM missing_nids n"); }