Taxonomy generate form text improvements.
[project/devel.git] / devel.pages.inc
CommitLineData
61b651a0 1<?php
2//$Id$
3
4/**
5 * Page callback to display syntax hilighted source code
6 *
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
9 *
10 * @param $standalone
11 * Set to FALSE to place the code inside a Drupal page. Otherwise code displays on its own.
12 */
13function 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);
18 if ($output) {
19 if ($standalone) {
20 print $output;
21 drupal_exit();
22 }
23 return $output;
24 }
25 else {
26 drupal_set_message(t('Invalid file path'), 'error');
27 drupal_not_found();
28 }
29}
30
31/**
32 * Return PHP highlighted file
33 *
34 * @param $path
35 * path to the file
36 * *warning* there is NO VALIDATION in this function
37 * Beware of paths such as '../../../../../etc/apache/httpd.conf'
38 *
39 * @param $standalone
40 * should the returned HTML be wrapped in a full <html> page or will it be output by Drupal?
41 */
42function 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
46 // with doxygen
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);
49 if ($standalone) {
50 $source = <<<EOT
51<head><title>$path</title></head>
52<body>$source</body>
53EOT;
54 }
55 return $source;
56 }
57 else {
58 return FALSE;
59 }
60}
61
62// Menu callback that shows menu item.
63function devel_menu_item() {
64 $item = menu_get_item($_GET['path']);
65 return kdevel_print_object($item);
66}
67
68/**
69 * Returns a list of all currently defined user functions in the current
70 * request lifecycle, with links their documentation.
71 */
72function devel_function_reference() {
73 $functions = get_defined_functions();
74 $version = devel_get_core_version(VERSION);
75 $ufunctions = $functions['user'];
76 sort($ufunctions);
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");
80 }
81 return theme('item_list', array('items' => $links));
82}
83
84/**
85 * Menu callback; clears all caches, then redirects to the previous page.
86 */
87function devel_cache_clear() {
88 drupal_flush_all_caches();
89
90 drupal_set_message('Cache cleared.');
91
92 drupal_goto();
93}
94
95// A menu callback. Called by the AJAX link in query log.
96function devel_querylog_explain($request_id, $qid) {
97 if (!is_numeric($request_id)) {
98 return MENU_ACCESS_DENIED;
99 }
100
101 $path = "temporary://devel_querylog/$request_id.txt";
102 $path = file_stream_wrapper_uri_normalize($path);
103 $queries = unserialize(file_get_contents($path));
104 $query = $queries[$qid];
105 $result = db_query('EXPLAIN ' . $query['query'], $query['args'])->fetchAllAssoc('table');
106 $i = 1;
107 foreach ($result as $row) {
108 $row = (array)$row;
109 if ($i == 1) {
110 $header = array_keys($row);
111 }
112 $rows[] = array_values($row);
113 $i++;
114 }
115 // Print and return nothing thus avoiding page wrapper.
116 $output = theme('table', array('header' => $header, 'rows' => $rows));
117 print $output;
118 $GLOBALS['devel_shutdown'] = FALSE;
119}
120
121// A menu callback. Called by the AJAX link in query log.
122function devel_querylog_arguments($request_id, $qid) {
123 if (!is_numeric($request_id)) {
124 return MENU_ACCESS_DENIED;
125 }
126
127 $path = "temporary://devel_querylog/$request_id.txt";
128 $path = file_stream_wrapper_uri_normalize($path);
129 $queries = unserialize(file_get_contents($path));
130 $query = $queries[$qid];
131 $conn = Database::getConnection();
132 $quoted = array();
133 foreach ((array)$query['args'] as $key => $val) {
134 $quoted[$key] = $conn->quote($val);
135 }
136 $output = strtr($query['query'], $quoted);
137
138 // print and return nothing thus avoiding page wrapper.
139 print $output;
140 $GLOBALS['devel_shutdown'] = FALSE;
141}
142
143/**
144 * Menu callback; clear the database, resetting the menu to factory defaults.
145 */
146function devel_menu_rebuild() {
147 menu_rebuild();
148 drupal_set_message(t('The menu router has been rebuilt.'));
149 drupal_goto();
150}
151
152/**
153 * Display a dropdown of installed modules with the option to reinstall them.
154 */
155function devel_reinstall($form, &$form_state) {
156 $output = '';
157 $modules = module_list();
158 sort($modules);
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>.'),
164 );
165 $form['submit'] = array(
166 '#value' => t('Reinstall'),
167 '#type' => 'submit',
168 );
169 return $form;
170}
171
172/**
173 * Process reinstall menu form submissions.
174 */
175function 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))));
182}
183
184// Menu callback.
185function devel_theme_registry() {
186 drupal_theme_initialize();
187 $hooks = theme_get_registry();
188 ksort($hooks);
189 return kprint_r($hooks, TRUE);
190}
191
192// Menu callback.
193function devel_field_info_page() {
194 $info = field_info_fields();
195 return kprint_r($info, TRUE);
196}
197
198/**
199 * Menu callback; display all variables.
200 */
201function devel_variable_page() {
202 // We return our own $page so as to avoid blocks.
203 $output = drupal_get_form('devel_variable_form');
204 drupal_set_page_content($output);
205 $page = element_info('page');
206 return $page;
207}
208
209function devel_variable_form() {
210 $header = array(
211 'name' => array('data' => t('Name'), 'field' => 'name', 'sort' => 'asc'),
212 'value' => array('data' => t('Value'), 'field' => 'value'),
213 'length' => array('data' => t('Length'), 'field' => 'length'),
214 'edit' => array('data' => t('Operations')),
215 );
216 // TODO: we could get variables out of $conf but that would include hard coded ones too. ideally i would highlight overrridden/hard coded variables
217 $query = db_select('variable', 'v')->extend('TableSort');
218 $query->fields('v', array('name', 'value'));
219 switch (db_driver()) {
220 case 'mssql':
221 $query->addExpression("COL_LENGTH('{variable}', 'value')", 'length');
222 break;
223 default:
224 $query->addExpression("CONVERT(LENGTH(v.value), UNSIGNED INTEGER)", 'length');
225 break;
226 }
227 $result = $query
228 ->orderByHeader($header)
229 ->execute();
230
231 foreach ($result as $row) {
232 // $variables[$row->name] = '';
233 $options[$row->name]['name'] = check_plain($row->name);
234 if (merits_krumo($row->value)) {
235 $value = krumo_ob(variable_get($row->name, NULL));
236 }
237 else {
238 if (drupal_strlen($row->value) > 70) {
239 $value = check_plain(drupal_substr($row->value, 0, 65)) .'...';
240 }
241 else {
242 $value = check_plain($row->value);
243 }
244 }
245 $options[$row->name]['value'] = $value;
246 $options[$row->name]['length'] = $row->length;
247 $options[$row->name]['edit'] = l(t('Edit'), "devel/variable/edit/$row->name");
248 }
249 $form['variables'] = array(
250 '#type' => 'tableselect',
251 '#header' => $header,
252 '#options' => $options,
253 '#empty' => t('No variables.'),
254 );
255 $form['submit'] = array(
256 '#type' => 'submit',
257 '#value' => t('Delete'),
258 );
259
260 // krumo($form);
261 return $form;
262}
263
264function devel_variable_form_submit($form, &$form_state) {
265 $deletes = array_filter($form_state['values']['variables']);
266 array_walk($deletes, 'variable_del');
267 drupal_set_message(format_plural(count($deletes), 'One variable deleted.', '@count variables deleted.'));
268}
269
270function devel_variable_edit($form, &$form_state, $name) {
271 $value = variable_get($name, 'not found');
272 $form['name'] = array(
273 '#type' => 'value',
274 '#value' => $name
275 );
276 $form['value'] = array(
277 '#type' => 'item',
278 '#title' => t('Old value'),
279 '#markup' => dpr($value, TRUE),
280 );
281 if (is_string($value) || is_numeric($value)) {
282 $form['new'] = array(
283 '#type' => 'textarea',
284 '#title' => t('New value'),
285 '#default_value' => $value
286 );
287 $form['submit'] = array(
288 '#type' => 'submit',
289 '#value' => t('Submit'),
290 );
291 }
292 else {
293 $api = variable_get('devel_api_url', 'api.drupal.org');
294 $form['new'] = array(
295 '#type' => 'item',
296 '#title' => t('New value'),
297 '#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"))
298 );
299 }
300 drupal_set_title($name);
301 return $form;
302}
303
304function devel_variable_edit_submit($form, &$form_state) {
305 variable_set($form_state['values']['name'], $form_state['values']['new']);
306 drupal_set_message(t('Saved new value for %name.', array('%name' => $form_state['values']['name'])));
307 'devel/variable';
308}
309
310/**
311 * Menu callback: display the session.
312 */
313function devel_session() {
314 global $user;
315 $output = kprint_r($_SESSION, TRUE);
316 $headers = array(t('Session name'), t('Session ID'));
317 $output .= theme('table', array('headers' => $headers, 'rows' => array(array(session_name(), session_id()))));
318 return $output;
319}
320
321/**
322 * Menu callback; prints the render structure of a term.
323 */
324function devel_render_term($term) {
325 $build = array();
326 $build += field_attach_view('taxonomy_term', $term);
327 if (!empty($term->description)) {
328 $build['term_description'] = array(
329 '#markup' => filter_xss_admin($term->description),
330 '#weight' => -1,
331 '#prefix' => '<div class="taxonomy-term-description">',
332 '#suffix' => '</div>',
333 );
334 }
335 return kdevel_print_object($build, '$term->');
336}
337
338/**
410b980f 339 * Menu callback; prints the loaded structure of the current node/user.
340 */
341function devel_load_object($object, $name = NULL) {
342 $title = isset($object->title) ? $object->title : $object->name;
343 drupal_set_title($title);
344 return kdevel_print_object($object, '$'. $name .'->');
345}
346
347/**
61b651a0 348 * Menu callback; prints the render structure of the current object (currently node or user).
349 */
350function devel_render_object($type, $object) {
351 $output = '';
352 $title = isset($object->title) ? $object->title : $object->name;
353 // not sure why menu system doesn't give us a reasonable title here.
354 drupal_set_title($title);
355 $function = $type .'_build_content';
356 $function($object);
357 return kdevel_print_object($object->content, '$'. $type .'->');
358}
359
360function devel_elements_page() {
361 return kdevel_print_object(module_invoke_all('element_info'));
362}
ff9a744a 363
364function devel_phpinfo() {
365 print phpinfo();
366 drupal_exit();
367}