5 * Page callback to display syntax hilighted source code
7 * note: the path for this function is received via $_GET['path']
8 * example http://www.example.com/devel/source?file=modules/node/node.module
11 * Set to FALSE to place the code inside a Drupal page. Otherwise code displays on its own.
13 function devel_display_source($standalone = TRUE
) {
14 $path = $_GET['file'];
15 // take out the nasties
16 $path = str_replace('../', '', $path);
17 $output = devel_highlight_file($path, $standalone);
26 drupal_set_message(t('Invalid file path'), 'error');
32 * Return PHP highlighted file
36 * *warning* there is NO VALIDATION in this function
37 * Beware of paths such as '../../../../../etc/apache/httpd.conf'
40 * should the returned HTML be wrapped in a full <html> page or will it be output by Drupal?
42 function devel_highlight_file($path = NULL
, $standalone = FALSE
) {
43 if (file_exists($path)) {
44 $source = highlight_file($path, TRUE
);
45 // add anchor links before all functions
47 // $source = preg_replace('!(\/\*\*.*?\*\/.*?)<br.*?function.*?#0000BB">(.*?)<\/span>!', '<a id="$2"></a> $0', $source);
48 //$source = preg_replace('!(\/\*\*.*?\*\/).*?function.*?#0000BB">(.*?)<\/span>!', '<a id="$2"></a> $0', $source);
51 <head
><title
>$path</title
></head
>
62 // Menu callback that shows menu item.
63 function devel_menu_item() {
64 $item = menu_get_item($_GET['path']);
65 return kdevel_print_object($item);
69 * Returns a list of all currently defined user functions in the current
70 * request lifecycle, with links their documentation.
72 function devel_function_reference() {
73 $functions = get_defined_functions();
74 $version = devel_get_core_version(VERSION
);
75 $ufunctions = $functions['user'];
77 $api = variable_get('devel_api_url', 'api.drupal.org');
78 foreach ($ufunctions as
$function) {
79 $links[] = l($function, "http://$api/api/$version/function/$function");
81 return theme('item_list', array('items' => $links));
85 * Menu callback; clears all caches, then redirects to the previous page.
87 function devel_cache_clear() {
88 drupal_flush_all_caches();
90 drupal_set_message('Cache cleared.');
95 // A menu callback. Called by the AJAX link in query log.
96 function devel_querylog_explain($request_id, $qid) {
97 if (!is_numeric($request_id)) {
98 return MENU_ACCESS_DENIED
;
101 $path = "temporary://devel_querylog/$request_id.txt";
102 $path = file_stream_wrapper_uri_normalize($path);
103 $queries = json_decode(file_get_contents($path));
104 $query = $queries[$qid];
105 $result = db_query('EXPLAIN ' .
$query->query
, (array)$query->args
)->fetchAllAssoc('table');
107 foreach ($result as
$row) {
110 $header = array_keys($row);
112 $rows[] = array_values($row);
115 // Print and return nothing thus avoiding page wrapper.
116 $output = theme('table', array('header' => $header, 'rows' => $rows));
118 $GLOBALS['devel_shutdown'] = FALSE
;
121 // A menu callback. Called by the AJAX link in query log.
122 function devel_querylog_arguments($request_id, $qid) {
123 if (!is_numeric($request_id)) {
124 return MENU_ACCESS_DENIED
;
127 $path = "temporary://devel_querylog/$request_id.txt";
128 $path = file_stream_wrapper_uri_normalize($path);
129 $queries = json_decode(file_get_contents($path));
130 $query = $queries[$qid];
131 $conn = Database
::getConnection();
133 foreach ((array)$query->args as
$key => $val) {
134 $quoted[$key] = $conn->quote($val);
136 $output = strtr($query->query
, $quoted);
138 // print and return nothing thus avoiding page wrapper.
140 $GLOBALS['devel_shutdown'] = FALSE
;
144 * Menu callback; clear the database, resetting the menu to factory defaults.
146 function devel_menu_rebuild() {
148 drupal_set_message(t('The menu router has been rebuilt.'));
153 * Display a dropdown of installed modules with the option to reinstall them.
155 function devel_reinstall($form, &$form_state) {
157 $modules = module_list();
159 $options = drupal_map_assoc($modules);
160 $form['list'] = array(
161 '#type' => 'checkboxes',
162 '#options' => $options,
163 '#description' => t('Uninstall and then install the selected modules. <code>hook_uninstall()</code> and <code>hook_install()</code> 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 <code>hook_uninstall()</code>.'),
165 $form['submit'] = array(
166 '#value' => t('Reinstall'),
173 * Process reinstall menu form submissions.
175 function devel_reinstall_submit($form, &$form_state) {
176 // require_once './includes/install.inc';
177 $modules = array_filter($form_state['values']['list']);
178 module_disable($modules, FALSE
);
179 drupal_uninstall_modules($modules);
180 module_enable($modules, FALSE
);
181 drupal_set_message(t('Uninstalled and installed: %names.', array('%names' => implode(', ', $modules))));
185 function devel_theme_registry() {
186 drupal_theme_initialize();
187 $hooks = theme_get_registry();
189 return kprint_r($hooks, TRUE
);
192 // Menu callback. $entity_type argument not currently used in the UI.
193 function devel_entity_info_page($entity_type = NULL
) {
194 $info = entity_get_info($entity_type);
196 return kprint_r($info, TRUE
);
200 function devel_field_info_page() {
201 $info = field_info_fields();
202 $output = kprint_r($info, TRUE
, t('Fields'));
203 $info = field_info_instances();
204 $output .
= kprint_r($info, TRUE
, t('Instances'));
205 $info = field_info_bundles();
206 $output .
= kprint_r($info, TRUE
, t('Bundles'));
211 * Menu callback; display all variables.
213 function devel_variable_page() {
214 // We return our own $page so as to avoid blocks.
215 $output = drupal_get_form('devel_variable_form');
216 drupal_set_page_content($output);
217 $page = element_info('page');
221 function devel_variable_form() {
223 'name' => array('data' => t('Name'), 'field' => 'name', 'sort' => 'asc'),
224 'value' => array('data' => t('Value'), 'field' => 'value'),
225 'length' => array('data' => t('Length'), 'field' => 'length'),
226 'edit' => array('data' => t('Operations')),
228 // TODO: we could get variables out of $conf but that would include hard coded ones too. ideally i would highlight overrridden/hard coded variables
229 $query = db_select('variable', 'v')->extend('TableSort');
230 $query->fields('v', array('name', 'value'));
231 switch (db_driver()) {
233 $query->addExpression("COL_LENGTH('{variable}', 'value')", 'length');
236 $query->addExpression("CONVERT(LENGTH(v.value), UNSIGNED INTEGER)", 'length');
240 ->orderByHeader($header)
243 foreach ($result as
$row) {
244 // $variables[$row->name] = '';
245 $options[$row->name
]['name'] = check_plain($row->name
);
246 if (merits_krumo($row->value
)) {
247 $value = krumo_ob(variable_get($row->name
, NULL
));
250 if (drupal_strlen($row->value
) > 70) {
251 $value = check_plain(drupal_substr($row->value
, 0, 65)) .
'...';
254 $value = check_plain($row->value
);
257 $options[$row->name
]['value'] = $value;
258 $options[$row->name
]['length'] = $row->length
;
259 $options[$row->name
]['edit'] = l(t('Edit'), "devel/variable/edit/$row->name");
261 $form['variables'] = array(
262 '#type' => 'tableselect',
263 '#header' => $header,
264 '#options' => $options,
265 '#empty' => t('No variables.'),
267 $form['submit'] = array(
269 '#value' => t('Delete'),
276 function devel_variable_form_submit($form, &$form_state) {
277 $deletes = array_filter($form_state['values']['variables']);
278 array_walk($deletes, 'variable_del');
279 if (count($deletes)) {
280 drupal_set_message(format_plural(count($deletes), 'One variable deleted.', '@count variables deleted.'));
284 function devel_variable_edit($form, &$form_state, $name) {
285 $value = variable_get($name, 'not found');
286 $form['name'] = array(
290 $form['value'] = array(
292 '#title' => t('Old value'),
293 '#markup' => dpr($value, TRUE
),
295 if (is_string($value) || is_numeric($value)) {
296 $form['new'] = array(
297 '#type' => 'textarea',
298 '#title' => t('New value'),
299 '#default_value' => $value
301 $form['submit'] = array(
303 '#value' => t('Submit'),
307 $api = variable_get('devel_api_url', 'api.drupal.org');
308 $form['new'] = array(
310 '#title' => t('New value'),
311 '#value' => t('Sorry, complex variable types may not be edited yet. Use the <em>Execute PHP</em> block and the <a href="@variable-set-doc">variable_set()</a> function.', array('@variable-set-doc' => "http://$api/api/HEAD/function/variable_set"))
314 drupal_set_title($name);
318 function devel_variable_edit_submit($form, &$form_state) {
319 variable_set($form_state['values']['name'], $form_state['values']['new']);
320 drupal_set_message(t('Saved new value for %name.', array('%name' => $form_state['values']['name'])));
325 * Menu callback: display the session.
327 function devel_session() {
329 $output = kprint_r($_SESSION, TRUE
);
330 $headers = array(t('Session name'), t('Session ID'));
331 $output .
= theme('table', array('headers' => $headers, 'rows' => array(array(session_name(), session_id()))));
336 * Menu callback; prints the render structure of a term.
338 function devel_render_term($term) {
340 $build += field_attach_view('taxonomy_term', $term);
341 if (!empty($term->description
)) {
342 $build['term_description'] = array(
343 '#markup' => filter_xss_admin($term->description
),
345 '#prefix' => '<div class="taxonomy-term-description">',
346 '#suffix' => '</div>',
349 return kdevel_print_object($build, '$term->');
353 * Menu callback; prints the loaded structure of the current node/user.
355 function devel_load_object($object, $name = NULL
) {
356 $title = isset($object->title
) ?
$object->title
: $object->name
;
357 drupal_set_title($title);
358 return kdevel_print_object($object, '$'.
$name .
'->');
362 * Menu callback; prints the render structure of the current object (currently node or user).
364 function devel_render_object($type, $object) {
366 $title = isset($object->title
) ?
$object->title
: $object->name
;
367 // not sure why menu system doesn't give us a reasonable title here.
368 drupal_set_title($title);
369 $function = $type .
'_build_content';
371 return kdevel_print_object($object->content
, '$'.
$type .
'->');
374 function devel_elements_page() {
375 return kdevel_print_object(module_invoke_all('element_info'));
378 function devel_phpinfo() {