Enhance Readme.
[project/devel.git] / devel.pages.inc
1 <?php
2
3 // Menu callback that shows menu item.
4 function devel_menu_item() {
5 $item = menu_get_item($_GET['path']);
6 return kdevel_print_object($item);
7 }
8
9 /**
10 * Returns a list of all currently defined user functions in the current
11 * request lifecycle, with links their documentation.
12 */
13 function devel_function_reference() {
14 $functions = get_defined_functions();
15 $version = devel_get_core_version(VERSION);
16 $ufunctions = $functions['user'];
17 sort($ufunctions);
18 $api = variable_get('devel_api_url', 'api.drupal.org');
19 foreach ($ufunctions as $function) {
20 $links[] = l($function, "http://$api/api/$version/function/$function");
21 }
22 return theme('item_list', array('items' => $links));
23 }
24
25 /**
26 * Menu callback; clears all caches, then redirects to the previous page.
27 */
28 function devel_cache_clear() {
29 drupal_flush_all_caches();
30
31 drupal_set_message('Cache cleared.');
32
33 drupal_goto();
34 }
35
36 // A menu callback. Called by the AJAX link in query log.
37 function devel_querylog_explain($request_id, $qid) {
38 if (!is_numeric($request_id)) {
39 return MENU_ACCESS_DENIED;
40 }
41
42 $path = "temporary://devel_querylog/$request_id.txt";
43 $path = file_stream_wrapper_uri_normalize($path);
44 $queries = json_decode(file_get_contents($path));
45 $query = $queries[$qid];
46 $result = db_query('EXPLAIN ' . $query->query, (array)$query->args)->fetchAllAssoc('table');
47 $i = 1;
48 foreach ($result as $row) {
49 $row = (array)$row;
50 if ($i == 1) {
51 $header = array_keys($row);
52 }
53 $rows[] = array_values($row);
54 $i++;
55 }
56 // Print and return nothing thus avoiding page wrapper.
57 $output = theme('table', array('header' => $header, 'rows' => $rows));
58 print $output;
59 $GLOBALS['devel_shutdown'] = FALSE;
60 }
61
62 // A menu callback. Called by the AJAX link in query log.
63 function devel_querylog_arguments($request_id, $qid) {
64 if (!is_numeric($request_id)) {
65 return MENU_ACCESS_DENIED;
66 }
67
68 $path = "temporary://devel_querylog/$request_id.txt";
69 $path = file_stream_wrapper_uri_normalize($path);
70 $queries = json_decode(file_get_contents($path));
71 $query = $queries[$qid];
72 $conn = Database::getConnection();
73 $quoted = array();
74 foreach ((array)$query->args as $key => $val) {
75 $quoted[$key] = $conn->quote($val);
76 }
77 $output = strtr($query->query, $quoted);
78
79 // print and return nothing thus avoiding page wrapper.
80 print $output;
81 $GLOBALS['devel_shutdown'] = FALSE;
82 }
83
84 /**
85 * Menu callback; clear the database, resetting the menu to factory defaults.
86 */
87 function devel_menu_rebuild() {
88 menu_rebuild();
89 drupal_set_message(t('The menu router has been rebuilt.'));
90 drupal_goto();
91 }
92
93 /**
94 * Display a dropdown of installed modules with the option to reinstall them.
95 */
96 function devel_reinstall($form, &$form_state) {
97 $output = '';
98 $modules = module_list();
99 sort($modules);
100 $options = drupal_map_assoc($modules);
101 $form['list'] = array(
102 '#type' => 'checkboxes',
103 '#options' => $options,
104 '#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>.'),
105 );
106 $form['submit'] = array(
107 '#value' => t('Reinstall'),
108 '#type' => 'submit',
109 );
110 return $form;
111 }
112
113 /**
114 * Process reinstall menu form submissions.
115 */
116 function devel_reinstall_submit($form, &$form_state) {
117 // require_once './includes/install.inc';
118 $modules = array_filter($form_state['values']['list']);
119 module_disable($modules, FALSE);
120 drupal_uninstall_modules($modules);
121 module_enable($modules, FALSE);
122 drupal_set_message(t('Uninstalled and installed: %names.', array('%names' => implode(', ', $modules))));
123 }
124
125 // Menu callback.
126 function devel_theme_registry() {
127 drupal_theme_initialize();
128 $hooks = theme_get_registry();
129 ksort($hooks);
130 return kprint_r($hooks, TRUE);
131 }
132
133 // Menu callback. $entity_type argument not currently used in the UI.
134 function devel_entity_info_page($entity_type = NULL) {
135 $info = entity_get_info($entity_type);
136 ksort($info);
137 return kprint_r($info, TRUE);
138 }
139
140 // Menu callback.
141 function devel_field_info_page() {
142 $info = field_info_fields();
143 $output = kprint_r($info, TRUE, t('Fields'));
144 $info = field_info_instances();
145 $output .= kprint_r($info, TRUE, t('Instances'));
146 $info = field_info_bundles();
147 $output .= kprint_r($info, TRUE, t('Bundles'));
148 return $output;
149 }
150
151 /**
152 * Menu callback; display all variables.
153 */
154 function devel_variable_page() {
155 // We return our own $page so as to avoid blocks.
156 $output = drupal_get_form('devel_variable_form');
157 drupal_set_page_content($output);
158 $page = element_info('page');
159 return $page;
160 }
161
162 function devel_variable_form() {
163 $header = array(
164 'name' => array('data' => t('Name'), 'field' => 'name', 'sort' => 'asc'),
165 'value' => array('data' => t('Value'), 'field' => 'value'),
166 'length' => array('data' => t('Length'), 'field' => 'length'),
167 'edit' => array('data' => t('Operations')),
168 );
169 // TODO: we could get variables out of $conf but that would include hard coded ones too. ideally i would highlight overrridden/hard coded variables
170 $query = db_select('variable', 'v')->extend('TableSort');
171 $query->fields('v', array('name', 'value'));
172 switch (db_driver()) {
173 case 'mssql':
174 $query->addExpression("COL_LENGTH('{variable}', 'value')", 'length');
175 break;
176 case 'pgsql':
177 $query->addExpression("CONVERT(LENGTH(v.value), INTEGER)", 'length');
178 break;
179 default:
180 $query->addExpression("CONVERT(LENGTH(v.value), UNSIGNED INTEGER)", 'length');
181 break;
182 }
183 $result = $query
184 ->orderByHeader($header)
185 ->execute();
186
187 foreach ($result as $row) {
188 // $variables[$row->name] = '';
189 $options[$row->name]['name'] = check_plain($row->name);
190 if (merits_krumo($row->value)) {
191 $value = krumo_ob(variable_get($row->name, NULL));
192 }
193 else {
194 if (drupal_strlen($row->value) > 70) {
195 $value = check_plain(drupal_substr($row->value, 0, 65)) .'...';
196 }
197 else {
198 $value = check_plain($row->value);
199 }
200 }
201 $options[$row->name]['value'] = $value;
202 $options[$row->name]['length'] = $row->length;
203 $options[$row->name]['edit'] = l(t('Edit'), "devel/variable/edit/$row->name");
204 }
205 $form['variables'] = array(
206 '#type' => 'tableselect',
207 '#header' => $header,
208 '#options' => $options,
209 '#empty' => t('No variables.'),
210 );
211 $form['submit'] = array(
212 '#type' => 'submit',
213 '#value' => t('Delete'),
214 );
215
216 // krumo($form);
217 return $form;
218 }
219
220 function devel_variable_form_submit($form, &$form_state) {
221 $deletes = array_filter($form_state['values']['variables']);
222 array_walk($deletes, 'variable_del');
223 if (count($deletes)) {
224 drupal_set_message(format_plural(count($deletes), 'One variable deleted.', '@count variables deleted.'));
225 }
226 }
227
228 function devel_variable_edit($form, &$form_state, $name) {
229 $value = variable_get($name, 'not found');
230 $form['name'] = array(
231 '#type' => 'value',
232 '#value' => $name
233 );
234 $form['value'] = array(
235 '#type' => 'item',
236 '#title' => t('Old value'),
237 '#markup' => dpr($value, TRUE),
238 );
239 if (is_string($value) || is_numeric($value)) {
240 $form['new'] = array(
241 '#type' => 'textarea',
242 '#title' => t('New value'),
243 '#default_value' => $value
244 );
245 $form['submit'] = array(
246 '#type' => 'submit',
247 '#value' => t('Submit'),
248 );
249 }
250 else {
251 $api = variable_get('devel_api_url', 'api.drupal.org');
252 $form['new'] = array(
253 '#type' => 'item',
254 '#title' => t('New value'),
255 '#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"))
256 );
257 }
258 drupal_set_title($name);
259 return $form;
260 }
261
262 function devel_variable_edit_submit($form, &$form_state) {
263 variable_set($form_state['values']['name'], $form_state['values']['new']);
264 drupal_set_message(t('Saved new value for %name.', array('%name' => $form_state['values']['name'])));
265 'devel/variable';
266 }
267
268 /**
269 * Menu callback: display the session.
270 */
271 function devel_session() {
272 global $user;
273 $output = kprint_r($_SESSION, TRUE);
274 $headers = array(t('Session name'), t('Session ID'));
275 $output .= theme('table', array('headers' => $headers, 'rows' => array(array(session_name(), session_id()))));
276 return $output;
277 }
278
279 /**
280 * Menu callback; prints the loaded structure of the current node/user.
281 */
282 function devel_load_object($type, $object, $name = NULL) {
283 $name = isset($name) ? $name : $type;
284 return kdevel_print_object($object, '$'. $name .'->');
285 }
286
287 /**
288 * Menu callback; prints the render structure of the current object (currently node or user).
289 */
290 function devel_render_object($type, $object, $name = NULL) {
291 $name = isset($name) ? $name : $type;
292 $function = $type . '_view';
293 $build = $function($object);
294 return kdevel_print_object($build, '$'. $name .'->');
295 }
296
297 function devel_elements_page() {
298 return kdevel_print_object(module_invoke_all('element_info'));
299 }
300
301 function devel_phpinfo() {
302 print phpinfo();
303 drupal_exit();
304 }