/[drupal]/contributions/modules/sitedoc/sitedoc.module
ViewVC logotype

Contents of /contributions/modules/sitedoc/sitedoc.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.48 - (show annotations) (download) (as text)
Mon Mar 10 14:35:00 2008 UTC (20 months, 2 weeks ago) by nancyw
Branch: MAIN
CVS Tags: DRUPAL-5--1-7, HEAD
Branch point for: DRUPAL-5
Changes since 1.47: +37 -25 lines
File MIME type: text/x-php
Improved default filter format checks.
Added destination to come back from settings & cron.
1 <?php
2 // $Id: sitedoc.module,v 1.47 2008/03/10 04:13:31 nancyw Exp $
3
4 /**
5 * Implementation of hook_help().
6 */
7 function sitedoc_help($path, $arg=array()) {
8 switch ($path) {
9 case 'admin/help#sitedoc':
10 $output = '<p>'. t('The sitedoc module allows a site admin to gather extensive information about their site. It may be printed or archived for configuration/change management purposes. It may also be used to add "fancy" and up-to-date information to other site documentation, such as a succession plan.') .'</p>';
11 break;
12
13 case 'admin/settings/sitedoc/archive':
14 $output = '<p>'. t('The Site Documentation module may be run via Cron and the output HTML file archived to disk for future review. The options chosen on the main settings page will govern the data collected and reported.') .'</p>';
15 break;
16
17 case 'admin/settings/sitedoc':
18 $output = '<p>'. t("The Site Documentation module's data collection and output is governed by these settings. Indented options are in effect only if the parent item is selected.") .'</p>';
19 }
20 return $output;
21 }
22
23 /**
24 * Implementation of hook_perm().
25 */
26 function sitedoc_perm() {
27 return array('view site documentation');
28 }
29
30 /**
31 * Implementation of hook_menu().
32 *
33 * Add a menu item to the Administer >> Site building menu for displaying the sitedoc.
34 * Add a menu item to the Administer >> Site configuration menu for the sitedoc settings.
35 * Add a menu callback item to the Administer >> Site building menu for displaying node access lists.
36 * Add a menu callback item to the menu for displaying taxonomy term counts.
37 * Add a menu callback item to the menu for displaying phpinfo.
38 */
39 function sitedoc_menu($may_cache) {
40 $items = array();
41
42 if ($may_cache) {
43 drupal_add_css(drupal_get_path('module', 'sitedoc') .'/sitedoc.css');
44 $items[] = array(
45 'path' => 'admin/build/sitedoc',
46 'title' => t('Site documentation'),
47 'description' => t('Show site documentation'),
48 'callback' => 'sitedoc_list',
49 'access' => user_access('view site documentation'),
50 );
51 $items[] = array(
52 'path' => 'admin/settings/sitedoc',
53 'title' => t('Site documentation'),
54 'description' => t('Set how Site Documentation works'),
55 'callback' => 'sitedoc_settings_page',
56 'access' => user_access('view site documentation'),
57 );
58 $items[] = array(
59 'path' => 'admin/settings/sitedoc/report',
60 'title' => t('Report'),
61 'description' => t('Report settings'),
62 'callback' => 'drupal_get_form',
63 'callback arguments' => array('sitedoc_settings_form'),
64 'access' => user_access('view site documentation'),
65 'type' => MENU_DEFAULT_LOCAL_TASK,
66 );
67 $items[] = array(
68 'path' => 'admin/settings/sitedoc/archive',
69 'title' => t('Archive'),
70 'access' => user_access('view site documentation'),
71 'callback' => 'drupal_get_form',
72 'callback arguments' => array('sitedoc_archive_form'),
73 'description' => t('Set how Site Documentation archive works'),
74 'weight' => 2,
75 'type' => MENU_LOCAL_TASK,
76 );
77 }
78 else {
79 $items[] = array(
80 'path' => 'admin/build/sitedoc_node_access_view',
81 'title' => t('Site documentation node access list'),
82 'description' => t('Do not use'),
83 'callback' => 'sitedoc_node_access_view',
84 'callback arguments' => array(arg(3)),
85 'access' => user_access('view site documentation'),
86 'type' => MENU_CALLBACK,
87 );
88 $items[] = array('path' => 'sitedoc/vocabulary',
89 'title' => t('Site Documentation Term Count by Type'),
90 'callback' => 'sitedoc_term_count_by_type',
91 // 'callback arguments' => array(arg(2)),
92 'access' => user_access('access content'),
93 'type' => MENU_CALLBACK
94 );
95 $items[] = array('path' => 'sitedoc/phpinfo',
96 'title' => t('Site Documentation PHP Information'),
97 'callback' => 'sitedoc_phpinfo',
98 'access' => user_access('view site documentation'),
99 'type' => MENU_CALLBACK
100 );
101 $items[] = array('path' => 'sitedoc/table',
102 'title' => t('Table Contents'),
103 'callback' => 'sitedoc_show_table',
104 'access' => user_access('access content'),
105 'type' => MENU_CALLBACK
106 );
107 }
108 return $items;
109 }
110
111 /**
112 * Implementation of hook_enable().
113 *
114 * Set the default parameters. This is an easy way to reset the deaults - disable and re-enable.
115 *
116 * Parameters: None.
117 *
118 * Return: None.
119 */
120 function sitedoc_enable() {
121 $sitedoc_settings = array(
122 'drupal_section' => TRUE,
123 'kill_cron' => 0, /* kill long-running cron */
124 'table_section' => TRUE,
125 'show_indexes' => FALSE, /* use SHOW INDEX on the tables */
126 'optimize_tables' => FALSE, /* use OPTIMIZE to release overhead */
127 'sequences_section' => FALSE, /* not on because not much interest */
128 'node_section' => FALSE, /* not on because of expense */
129 'include_comment_count' => FALSE, /* comment count on nodes */
130 'include_node_access' => FALSE, /* node access summary */
131 'node_show_size' => 99999, /* show nodes exceeding x KB */
132 'node_max_size' => 50, /* warn if nodes exceeding x KB */
133 'module_section' => TRUE,
134 'module_suppress' => FALSE, /* exclude disabled modules */
135 'module_sort_order' => 0, /* package, project, module */
136 'content_section' => TRUE,
137 'vocabulary_section' => TRUE,
138 'orphan_term_node' => FALSE, /* not on to allow control */
139 'delete_orphan_term_nodes' => FALSE, /* do not delete orphans */
140 'theme_section' => TRUE,
141 'variables_section' => FALSE, /* not on because of expense */
142 'block_section' => TRUE,
143 'block_warn' => TRUE, /* warn on missing theme */
144 'block_delete' => FALSE, /* delete those orphan blocks */
145 'roles_section' => TRUE,
146 'role_users' => TRUE, /* list users in roles */
147 'role_perms_list' => FALSE, /* do role permissions as stream */
148 'contacts_section' => TRUE,
149 'profile_fields_section' => FALSE, /* not on because of interest */
150 'url_alias_section' => FALSE, /* not on because of expense */
151 'input_format_section' => FALSE, /* not on because probably not wanted */
152 // Archive options
153 'archive_frequency' => 0, /* don't run */
154 'archive_directory' => 'sitedoc', /* archive directory within file setting */
155 );
156 variable_set('sitedoc_settings', $sitedoc_settings);
157 }
158
159 /********************************/
160 /** Main settings function **/
161 /********************************/
162 function sitedoc_settings_page() {
163 return drupal_get_form('sitedoc_settings_form');
164 }
165
166 function sitedoc_settings_form() {
167 drupal_add_css(drupal_get_path('module', 'sitedoc') .'/sitedoc.css');
168 $sitedoc_settings = variable_get('sitedoc_settings', array());
169
170 // Sections Fieldset
171 $form['sections'] = array(
172 '#type' => 'fieldset',
173 '#title' => t('Show Sections'),
174 '#weight' => -5,
175 '#collapsible' => FALSE,
176 '#collapsed' => FALSE,
177 '#prefix' => '<div class="sitedoc_sections_block">',
178 '#suffix' => '',
179 );
180
181 $form['sections']['drupal_section'] = array(
182 '#type' => 'checkbox',
183 '#title' => t('Include Basic Drupal information?'),
184 '#prefix' => '<div class="sitedoc_sections">',
185 // '#suffix' => '</div>',
186 '#default_value' => $sitedoc_settings['drupal_section'],
187 );
188
189 $kill_time = drupal_map_assoc(array(0, 1800, 3600, 7200, 10800, 14400, 18000, 21600, 32400, 43200, 86400, 172800), 'format_interval');
190 $kill_time['0'] = t('Never');
191 $form['sections']['kill_cron'] = array(
192 '#type' => 'select',
193 '#options' => $kill_time,
194 '#title' => t('Delete Cron variables after'),
195 '#prefix' => '<div class="sitedoc_options">',
196 '#suffix' => '</div></div>',
197 '#default_value' => $sitedoc_settings['kill_cron'],
198 );
199
200 $form['sections']['table_section'] = array(
201 '#type' => 'checkbox',
202 '#title' => t('Include Table Summary?'),
203 '#prefix' => '<div class="sitedoc_sections">',
204 // '#suffix' => '</div>',
205 '#default_value' => $sitedoc_settings['table_section'],
206 );
207
208 $form['sections']['show_indexes'] = array(
209 '#type' => 'checkbox',
210 '#title' => t('Show indexes?'),
211 '#prefix' => '<div class="sitedoc_options">',
212 '#suffix' => '</div>',
213 '#default_value' => $sitedoc_settings['show_indexes'],
214 );
215
216 $form['sections']['optimize_tables'] = array(
217 '#type' => 'checkbox',
218 '#title' => t('Release overhead?'),
219 '#prefix' => '<div class="sitedoc_options">',
220 '#suffix' => '</div></div>',
221 '#description' => t('(SQL intensive - uses OPTIMIZE)'),
222 '#default_value' => $sitedoc_settings['optimize_tables'],
223 );
224
225 // Postgres databases don't use the sequences table (and D6 probably won't either)
226 if ($GLOBALS['db_type'] == 'postgres') {
227 // Force it off and skip the form field
228 $sitedoc_settings['sequences_section'] = FALSE;
229 }
230 else {
231 $form['sections']['sequences_section'] = array(
232 '#type' => 'checkbox',
233 '#title' => t('Include Sequences Summary?'),
234 '#prefix' => '<div class="sitedoc_sections">',
235 '#suffix' => '</div>',
236 '#default_value' => $sitedoc_settings['sequences_section'],
237 );
238 }
239
240 $form['sections']['node_section'] = array(
241 '#type' => 'checkbox',
242 '#title' => t('Include Node Summary?'),
243 '#prefix' => '<div class="sitedoc_sections">',
244 // '#suffix' => '</div>',
245 '#description' => t('(SQL intensive)'),
246 '#default_value' => $sitedoc_settings['node_section'],
247 );
248
249 $form['sections']['node_show_size'] = array(
250 '#type' => 'textfield',
251 '#title' => t('Show nodes exceeding (KB)'),
252 '#prefix' => '<div class="sitedoc_options">',
253 '#suffix' => '</div>',
254 '#default_value' => $sitedoc_settings['node_show_size'],
255 '#size' => 8,
256 '#maxlength' => 7,
257 );
258
259 $form['sections']['node_max_size'] = array(
260 '#type' => 'textfield',
261 '#title' => t('Warn if nodes exceed (KB)'),
262 '#prefix' => '<div class="sitedoc_options">',
263 '#suffix' => '</div>',
264 '#default_value' => $sitedoc_settings['node_max_size'],
265 '#size' => 8,
266 '#maxlength' => 7,
267 );
268
269 $form['sections']['include_node_access'] = array(
270 '#type' => 'checkbox',
271 '#title' => t('Include node access summary?'),
272 '#prefix' => '<div class="sitedoc_options">',
273 '#suffix' => '</div>',
274 '#default_value' => $sitedoc_settings['include_node_access'],
275 );
276
277 $form['sections']['include_comment_count'] = array(
278 '#type' => 'checkbox',
279 '#title' => t('Include comment count on nodes?'),
280 '#prefix' => '<div class="sitedoc_options">',
281 '#suffix' => '</div></div>',
282 '#default_value' => $sitedoc_settings['include_comment_count'],
283 );
284
285 $form['sections']['variables_section'] = array(
286 '#type' => 'checkbox',
287 '#title' => t('Include System Variables?'),
288 '#prefix' => '<div class="sitedoc_sections">',
289 '#suffix' => '</div>',
290 '#description' => t('(CPU intensive)'),
291 '#default_value' => $sitedoc_settings['variables_section'],
292 );
293
294 $form['sections']['module_section'] = array(
295 '#type' => 'checkbox',
296 '#title' => t('Include Module summary?'),
297 '#prefix' => '<div class="sitedoc_sections">',
298 // '#suffix' => '</div>',
299 '#default_value' => $sitedoc_settings['module_section'],
300 );
301
302 $form['sections']['module_suppress'] = array(
303 '#type' => 'checkbox',
304 '#title' => t('Exclude disabled modules?'),
305 '#prefix' => '<div class="sitedoc_options">',
306 '#suffix' => '</div>',
307 '#default_value' => $sitedoc_settings['module_suppress'],
308 );
309
310 $module_sort_order = array(
311 0 => 'package, project, module',
312 1 => 'path, module',
313 );
314
315 $form['sections']['module_sort_order'] = array(
316 '#type' => 'radios',
317 '#title' => t('List sort order'),
318 '#options' => $module_sort_order,
319 '#prefix' => '<div class="sitedoc_options">',
320 '#suffix' => '</div></div>',
321 '#default_value' => $sitedoc_settings['module_sort_order'],
322 );
323
324 $form['sections']['content_section'] = array(
325 '#type' => 'checkbox',
326 '#title' => t('Include Content Type summary?'),
327 '#prefix' => '<div class="sitedoc_sections">',
328 '#suffix' => '</div>',
329 '#default_value' => $sitedoc_settings['content_section'],
330 );
331
332 if (module_exists('taxonomy')) {
333 $form['sections']['vocabulary_section'] = array(
334 '#type' => 'checkbox',
335 '#title' => t('Include Vocabulary summary?'),
336 '#prefix' => '<div class="sitedoc_sections">',
337 '#description' => t('(may be CPU and SQL intensive)'),
338 '#default_value' => $sitedoc_settings['vocabulary_section'],
339 );
340
341 $form['sections']['orphan_term_node'] = array(
342 '#type' => 'checkbox',
343 '#title' => t('Check for orphan Term_nodes?'),
344 '#prefix' => '<div class="sitedoc_options">',
345 '#suffix' => '</div>',
346 '#description' => t('(may be SQL intensive)'),
347 '#default_value' => $sitedoc_settings['orphan_term_node'],
348 );
349
350 $form['sections']['delete_orphan_term_nodes'] = array(
351 '#type' => 'checkbox',
352 '#title' => t('Delete orphan term nodes?'),
353 '#prefix' => '<div class="sitedoc_options">',
354 '#suffix' => '</div></div>',
355 '#default_value' => $sitedoc_settings['delete_orphan_term_nodes'],
356 );
357 } /* end if taxo exists */
358
359 $form['sections']['theme_section'] = array(
360 '#type' => 'checkbox',
361 '#title' => t('Include Themes and Theme Engines?'),
362 '#prefix' => '<div class="sitedoc_sections">',
363 '#suffix' => '</div>',
364 '#default_value' => $sitedoc_settings['theme_section'],
365 );
366
367 $form['sections']['block_section'] = array(
368 '#type' => 'checkbox',
369 '#title' => t('Include Blocks and Boxes?'),
370 '#prefix' => '<div class="sitedoc_sections">',
371 '#default_value' => $sitedoc_settings['block_section'],
372 );
373
374 $form['sections']['block_warn'] = array(
375 '#type' => 'checkbox',
376 '#title' => t('Warn on missing theme for blocks?'),
377 '#prefix' => '<div class="sitedoc_options">',
378 '#suffix' => '</div>',
379 '#description' => t('This allows the module to display a warning message if a block exists for a missing theme.'),
380 '#default_value' => $sitedoc_settings['block_warn'],
381 );
382
383 $form['sections']['block_delete'] = array(
384 '#type' => 'checkbox',
385 '#title' => t('Delete the orphan blocks?'),
386 '#prefix' => '<div class="sitedoc_options">',
387 '#suffix' => '</div></div>',
388 '#description' => t('Delete the blocks with a missing theme.'),
389 '#default_value' => $sitedoc_settings['block_delete'],
390 );
391
392 $form['sections']['roles_section'] = array(
393 '#type' => 'checkbox',
394 '#title' => t('Include Roles and Permissions?'),
395 '#prefix' => '<div class="sitedoc_sections">',
396 '#default_value' => $sitedoc_settings['roles_section'],
397 );
398
399 $form['sections']['role_users'] = array(
400 '#type' => 'checkbox',
401 '#title' => t('Show list of users for each role?'),
402 '#prefix' => '<div class="sitedoc_options">',
403 '#suffix' => '</div>',
404 '#description' => t('Displays the list of users assigned the role.'),
405 '#default_value' => $sitedoc_settings['role_users'],
406 );
407
408 $form['sections']['role_perms_list'] = array(
409 '#type' => 'checkbox',
410 '#title' => t('Show role permissions as a list?'),
411 '#prefix' => '<div class="sitedoc_options">',
412 '#suffix' => '</div></div>',
413 '#description' => t('If not chosen, the roles will be shown as a stream.'),
414 '#default_value' => $sitedoc_settings['role_perms_list'],
415 );
416
417 if (module_exists('contact')) {
418 $form['sections']['contacts_section'] = array(
419 '#type' => 'checkbox',
420 '#title' => t('Include Contacts?'),
421 '#prefix' => '<div class="sitedoc_sections">',
422 '#suffix' => '</div>',
423 '#default_value' => $sitedoc_settings['contacts_section'],
424 );
425 }
426
427 if (module_exists('profile')) {
428 $form['sections']['profile_fields_section'] = array(
429 '#type' => 'checkbox',
430 '#title' => t('Include Profile Fields?'),
431 '#prefix' => '<div class="sitedoc_sections">',
432 '#suffix' => '</div>',
433 '#default_value' => $sitedoc_settings['profile_fields_section'],
434 );
435 }
436
437 if (module_exists('path')) {
438 $form['sections']['url_alias_section'] = array(
439 '#type' => 'checkbox',
440 '#title' => t('Include URL Aliases?'),
441 '#prefix' => '<div class="sitedoc_sections">',
442 '#suffix' => '</div>',
443 '#description' => t('(SQL intensive)'),
444 '#default_value' => $sitedoc_settings['url_alias_section'],
445 );
446 }
447
448 $form['sections']['input_format_section'] = array(
449 '#type' => 'checkbox',
450 '#title' => t('Include Input Formats and Filters?'),
451 '#prefix' => '<div class="sitedoc_sections">',
452 '#suffix' => '</div>',
453 '#default_value' => $sitedoc_settings['input_format_section'],
454 );
455
456 // Update Button
457 $form['submit'] = array(
458 '#type' => 'submit',
459 '#value' => t('Save configuration'),
460 '#weight' => 5,
461 '#prefix' => '</div><div class="clear-block"></div>'
462 );
463
464 return $form;
465 }
466
467 /**
468 * Save the settings values.
469 */
470 function sitedoc_settings_form_submit($form_id, $form_values) {
471 // update the settings array and save it
472 $settings = variable_get('sitedoc_settings', array());
473
474 $settings['drupal_section'] = $form_values['drupal_section'];
475 $settings['kill_cron'] = $form_values['kill_cron'];
476 $settings['table_section'] = $form_values['table_section'];
477 $settings['show_indexes'] = $form_values['show_indexes'];
478 $settings['optimize_tables'] = $form_values['optimize_tables'];
479 $settings['sequences_section'] = $form_values['sequences_section'];
480 $settings['node_section'] = $form_values['node_section'];
481 $settings['include_comment_count'] = $form_values['include_comment_count'];
482 $settings['include_node_access'] = $form_values['include_node_access'];
483 $settings['node_show_size'] = $form_values['node_show_size'];
484 $settings['node_max_size'] = $form_values['node_max_size'];
485 $settings['module_section'] = $form_values['module_section'];
486 $settings['module_suppress'] = $form_values['module_suppress'];
487 $settings['module_sort_order'] = $form_values['module_sort_order'];
488 $settings['content_section'] = $form_values['content_section'];
489 $settings['vocabulary_section'] = $form_values['vocabulary_section'];
490 $settings['orphan_term_node'] = $form_values['orphan_term_node'];
491 $settings['delete_orphan_term_nodes'] = $form_values['delete_orphan_term_nodes'];
492 $settings['theme_section'] = $form_values['theme_section'];
493 $settings['variables_section'] = $form_values['variables_section'];
494 $settings['block_section'] = $form_values['block_section'];
495 $settings['block_warn'] = $form_values['block_warn'];
496 $settings['block_delete'] = $form_values['block_delete'];
497 $settings['roles_section'] = $form_values['roles_section'];
498 $settings['role_users'] = $form_values['role_users'];
499 $settings['role_perms_list'] = $form_values['role_perms_list'];
500 $settings['contacts_section'] = $form_values['contacts_section'];
501 $settings['profile_fields_section'] = $form_values['profile_fields_section'];
502 $settings['url_alias_section'] = $form_values['url_alias_section'];
503 $settings['input_format_section'] = $form_values['input_format_section'];
504
505 variable_set('sitedoc_settings', $settings);
506
507 drupal_set_message(t('Configuration has been updated. ') . l(t('Run now'), 'admin/build/sitedoc'), 'status');
508 }
509
510 function sitedoc_archive_form($form_values=NULL) {
511 drupal_add_css(drupal_get_path('module', 'sitedoc') .'/sitedoc.css');
512 $sitedoc_settings = variable_get('sitedoc_settings', array());
513
514 $save_time = drupal_map_assoc(array(0, 3600, 7200, 14400, 21600, 43200, 86400, 172800, 259200, 604800), 'format_interval');
515 $save_time['0'] = t('Never');
516 $save_time['999999'] = t('Always');
517
518 $form['archive_frequency'] = array(
519 '#type' => 'select',
520 '#options' => $save_time,
521 '#title' => t('Archive frequency'),
522 '#prefix' => '<div class="sitedoc_archive">',
523 '#suffix' => '</div>',
524 '#default_value' => $sitedoc_settings['archive_frequency'],
525 '#description' => t('The Site Documentation module will run at the next scheduled Cron run after this period has elapsed. A zero value suppresses creation of an archive. "Always" means a file will be created every time Cron runs.'),
526 );
527
528 $form['archive_directory'] = array(
529 '#type' => 'textfield',
530 '#title' => t('Archive directory'),
531 '#prefix' => '<div class="sitedoc_archive">',
532 '#suffix' => '</div>',
533 '#default_value' => $sitedoc_settings['archive_directory'],
534 '#description' => t('This is directory within \'!filepath\' where the Site Documentation module will place the archive file. The current date will be appended to the file name.', array('!filepath' => variable_get('file_directory_path', 'files'))),
535 );
536
537 // Add the Buttons
538 $form['save'] = array(
539 '#type' => 'submit',
540 '#value' => t('Save configuration'),
541 '#weight' => 5,
542 '#prefix' => '</div><div class="clear-block"></div>'
543 );
544
545 // If $form_values exists, then we've been here before (submitted), so now add a "run cron" button.
546 if (isset($form_values)) {
547 $form['cron'] = array(
548 '#type' => 'submit',
549 '#value' => t('Run Cron Now'),
550 '#weight' => 6,
551 );
552 }
553
554 // These allow us to add on the Cron button.
555 $form['#multistep'] = TRUE;
556 $form['#redirect'] = FALSE;
557
558 return $form;
559 }
560
561 /**
562 * Validate the submission.
563 */
564 function sitedoc_archive_form_validate($form_id, $form_values) {
565 $archive_path = variable_get('file_directory_path', 'files') .'/'. $form_values['archive_directory'];
566 if (!file_check_directory($archive_path, TRUE, 'archive_directory')) {
567 form_set_error('archive_directory', t('The archive path could not be found or could not be created.'));
568 } // end path not found
569 }
570
571 /**
572 * Save the settings values.
573 */
574 function sitedoc_archive_form_submit($form_id, $form_values) {
575 switch ($form_values['op']) {
576 case t('Run Cron Now'):
577 drupal_goto('admin/logs/status/run-cron');
578 break;
579
580 case t('Save configuration'):
581 // update the settings array and save it
582 $sitedoc_settings = variable_get('sitedoc_settings', array());
583 $sitedoc_settings['archive_frequency'] = $form_values['archive_frequency'];
584 $sitedoc_settings['archive_directory'] = $form_values['archive_directory'];
585
586 variable_set('sitedoc_settings', $sitedoc_settings);
587
588 drupal_set_message(t('Configuration has been updated. ') . l(t('Run now'), 'admin/build/sitedoc'), 'status');
589 }
590 }
591
592 /***********************/
593 /** main function **/
594 /***********************/
595 function sitedoc_list() {
596 // Retrieve the settings and check if they have been settings page.
597 $sitedoc_settings = variable_get('sitedoc_settings', array());
598 if ($sitedoc_settings == array()) {
599 return t('It appears that you have not been to "administer >> site configuration" to set the Site Documentation settings. ') . l(t('Click here to do so.'), 'admin/settings/sitedoc');
600 }
601
602 // Insert a wrapper division and a link back to the settings page.
603 $output = '<div class="site-documentation">'. l(t('Change settings.'), 'admin/settings/sitedoc') .'<br/><br/>';
604
605 // Get basic Drupal info.
606 if ($sitedoc_settings['drupal_section']) {
607 $output .= '<div class="sitedoc_drupal">';
608 $fieldset = array(
609 '#title' => t('Drupal Section'),
610 '#collapsible' => TRUE,
611 '#collapsed' => FALSE,
612 '#value' => sitedoc_drupal($sitedoc_settings['kill_cron']),
613 );
614 $output .= theme('fieldset', $fieldset);
615 $output .= "</div>\n";
616 }
617
618 // Get database info.
619 if ($sitedoc_settings['table_section']) {
620 $output .= '<div class="sitedoc_database_overview">';
621 $fieldset = array(
622 '#title' => t('Table Section'),
623 '#collapsible' => TRUE,
624 '#collapsed' => FALSE,
625 '#value' => sitedoc_database_overview($sitedoc_settings['optimize_tables'], $sitedoc_settings['show_indexes']),
626 );
627 $output .= theme('fieldset', $fieldset);
628 $output .= "</div>\n";
629 }
630
631 // Get info from the sequences table (last used item number).
632 if ($sitedoc_settings['sequences_section']) {
633 $output .= '<div class="sitedoc_sequences">';
634 $fieldset = array(
635 '#title' => t('Sequences Section'),
636 '#collapsible' => TRUE,
637 '#collapsed' => FALSE,
638 '#value' => sitedoc_sequences(),
639 );
640 $output .= theme('fieldset', $fieldset);
641 $output .= "</div>\n";
642 }
643
644 // Get summary of all nodes (this is VERY expensive!).
645 if ($sitedoc_settings['node_section']) {
646 $output .= '<div class="sitedoc_node_summary">';
647 $fieldset = array(
648 '#title' => t('Node Summary'),
649 '#collapsible' => TRUE,
650 '#collapsed' => FALSE,
651 '#value' => sitedoc_node_summary($sitedoc_settings['include_comment_count'], $sitedoc_settings['node_show_size'], $sitedoc_settings['node_max_size']),
652 );
653 $output .= theme('fieldset', $fieldset);
654 $output .= "</div>\n";
655
656 // Get node access summary (this is expensive!).
657 // Runs only if the node summary section is selected.
658 if ($sitedoc_settings['include_node_access']) {
659 $output .= '<div class="sitedoc_node_access">';
660 $fieldset = array(
661 '#title' => t('Node Access'),
662 '#collapsible' => TRUE,
663 '#collapsed' => FALSE,
664 '#value' => sitedoc_node_access(),
665 );
666 $output .= theme('fieldset', $fieldset);
667 $output .= "</div>\n";
668 } // end access summary
669 } // end node summary
670
671 // Get content type info from node module along with workflow options from system variables.
672 if ($sitedoc_settings['content_section']) {
673 $output .= '<div class="sitedoc_content_types">';
674 $fieldset = array(
675 '#title' => t('Content Types'),
676 '#collapsible' => TRUE,
677 '#collapsed' => FALSE,
678 '#value' => sitedoc_content_types(),
679 );
680 $output .= theme('fieldset', $fieldset);
681 $output .= "</div>\n";
682 }
683
684 // Get modules from the System module functions.
685 if ($sitedoc_settings['module_section']) {
686 $output .= '<div class="sitedoc_modules">';
687 $fieldset = array(
688 '#title' => t('Modules'),
689 '#collapsible' => TRUE,
690 '#collapsed' => FALSE,
691 '#value' => sitedoc_get_modules($sitedoc_settings['module_suppress'], $sitedoc_settings['module_sort_order']),
692 );
693 $output .= theme('fieldset', $fieldset);
694 $output .= "</div>\n";
695 }
696
697 // Get themes and theme_engines from the System table.
698 if ($sitedoc_settings['theme_section']) { /* controls themes and theme engines */
699 $output .= '<div class="sitedoc_themes">';
700 $fieldset = array(
701 '#title' => t('Themes'),
702 '#collapsible' => TRUE,
703 '#collapsed' => FALSE,
704 '#value' => sitedoc_get_system('theme'),
705 );
706 $output .= theme('fieldset', $fieldset);
707 $output .= "</div>\n";
708
709 $output .= '<div class="sitedoc_theme_engines">';
710 $fieldset = array(
711 '#title' => t('Theme Engines'),
712 '#collapsible' => TRUE,
713 '#collapsed' => TRUE,
714 '#value' => sitedoc_get_system('theme_engine'),
715 );
716 $output .= theme('fieldset', $fieldset);
717 $output .= "</div>\n";
718 }
719
720 // Get vocabularies and their definitions.
721 if ($sitedoc_settings['vocabulary_section']) {
722 $output .= '<div class="sitedoc_vocabularies">';
723 $fieldset = array(
724 '#title' => t('Vocabularies'),
725 '#collapsible' => TRUE,
726 '#collapsed' => FALSE,
727 '#value' => sitedoc_get_vocabularies(),
728 );
729 $output .= theme('fieldset', $fieldset);
730
731 // do we want to check for orphans in the Term_node table?
732 if ($sitedoc_settings['orphan_term_node']) {
733 $orphans = sitedoc_check_orphan_term_node($sitedoc_settings['delete_orphan_term_nodes']);
734 $fieldset = array(
735 '#title' => t('Orphan Term_nodes'),
736 '#collapsible' => TRUE,
737 '#collapsed' => ($orphans == '<p>'. t('No orphan term_nodes found.') .'</p>'),
738 '#value' => $orphans,
739 );
740 $output .= theme('fieldset', $fieldset);
741 }
742 $output .= "</div>\n";
743 }
744
745 // Get system variable info from cache.
746 if ($sitedoc_settings['variables_section']) {
747 $output .= '<div class="sitedoc_variables">';
748 $fieldset = array(
749 '#title' => t('Variables'),
750 '#collapsible' => TRUE,
751 '#collapsed' => FALSE,
752 '#value' => sitedoc_get_variables(),
753 );
754 $output .= theme('fieldset', $fieldset);
755 $output .= "</div>\n";
756 }
757
758 // Get blocks info from Blocks table.
759 if ($sitedoc_settings['block_section']) { /* controls block and boxes */
760 $output .= '<div class="sitedoc_blocks">';
761 // use the setting to decide on a warning for missing themes
762 $fieldset = array(
763 '#title' => t('Blocks'),
764 '#collapsible' => TRUE,
765 '#collapsed' => FALSE,
766 '#value' => sitedoc_get_blocks($sitedoc_settings['block_warn'], $sitedoc_settings['block_delete']),
767 );
768 $output .= theme('fieldset', $fieldset);
769 $output .= "</div>\n";
770
771 // Get boxes (custom blocks) info from Boxes table.
772 // Runs only if the blocks section is selected.
773 $output .= '<div class="sitedoc_boxes">';
774 $boxes = sitedoc_get_boxes($sitedoc_settings['block_warn'], $sitedoc_settings['block_delete']);
775 $fieldset = array(
776 '#title' => t('Custom Blocks (Boxes)'),
777 '#collapsible' => TRUE,
778 '#collapsed' => FALSE,
779 '#value' => $boxes ? $boxes : ('<p>'. t('No boxes found.') .'</p>'),
780 );
781 $output .= theme('fieldset', $fieldset);
782 $output .= "</div>\n";
783 }
784
785 // Get roles info from Roles table (how can we get a description of the roles?).
786 if ($sitedoc_settings['roles_section']) {
787 $output .= '<div class="sitedoc_roles">';
788 $rpt .= sitedoc_get_roles($sitedoc_settings['role_perms_list'], $sitedoc_settings['role_users']);
789 $fieldset = array(
790 '#title' => t('Roles'),
791 '#collapsible' => TRUE,
792 '#collapsed' => FALSE,
793 '#value' => $rpt ? $rpt : (t('No roles found.') .' <img src="/misc/watchdog-error.png" width="17" height="17">'),
794 );
795 $output .= theme('fieldset', $fieldset);
796 $output .= "</div>\n";
797 }
798
799 // Get contacts info from Contacts table.
800 if ($sitedoc_settings['contacts_section']) {
801 $output .= '<div class="sitedoc_contacts">';
802 $rpt = sitedoc_get_contacts();
803 $fieldset = array(
804 '#title' => t('Contacts'),
805 '#collapsible' => TRUE,
806 '#collapsed' => FALSE,
807 '#value' => $rpt ? $rpt : t('No contacts found.'),
808 );
809 $output .= theme('fieldset', $fieldset);
810 $output .= "</div>\n";
811 }
812
813 // Get info from Profile_fields table.
814 if ($sitedoc_settings['profile_fields_section']) {
815 $output .= '<div class="sitedoc_profile_fields">';
816 $rpt = sitedoc_profile_fields();
817 $fieldset = array(
818 '#title' => t('Profile Fields'),
819 '#collapsible' => TRUE,
820 '#collapsed' => FALSE,
821 '#value' => $rpt ? $rpt : ('<p>'. t('No profile fields found.') .'</p>'),
822 );
823 $output .= theme('fieldset', $fieldset);
824 $output .= "</div>\n";
825 }
826
827 // Get info from URL Alias table and cross-check it.
828 if ($sitedoc_settings['url_alias_section']) {
829 $output .= '<div class="sitedoc_url_alias">';
830 $rpt = sitedoc_url_alias();
831 $fieldset = array(
832 '#title' => t('URL Aliases'),
833 '#collapsible' => TRUE,
834 '#collapsed' => FALSE,
835 '#value' => $rpt ? $rpt : t('No aliases found.'),
836 );
837 $output .= theme('fieldset', $fieldset);
838 $output .= "</div>\n";
839 }
840
841 $output .= "</div>\n";
842
843 // Get info from Filter and Filter_format tables.
844 if ($sitedoc_settings['input_format_section']) {
845 $output .= '<div class="sitedoc_input_format">';
846 $fieldset = array(
847 '#title' => t('Input Formats and Filters'),
848 '#collapsible' => TRUE,
849 '#collapsed' => FALSE,
850 '#value' => sitedoc_filters(),
851 );
852 $output .= theme('fieldset', $fieldset);
853 $output .= "</div>\n";
854 }
855
856 $output .= "</div>\n";
857 return $output;
858
859 }
860 /**
861 * Implementation of hook_cron
862 *
863 * Runs the report and saves it to disk.
864 */
865 function sitedoc_cron() {
866 // Get the module settings and verify they've been set.
867 $sitedoc_settings = variable_get('sitedoc_settings', array());
868 if ($sitedoc_settings == array()) {
869 watchdog('Site Doc', t('It appears that you have not been to "administer >> site configuration" to set the Site Documentation settings.'), WATCHDOG_ERROR);
870 }
871
872 // If set up for manual run, then just quit now.
873 $frequency = $sitedoc_settings['archive_frequency'];
874 if ($frequency == 0) {
875 return;
876 }
877
878 // If set up for debugging, then -1 will let us run every time.
879 if ($frequency == '999999') {
880 $frequency = -1;
881 }
882
883 // Determine if it's time to make another run.
884 $how_long = time() - $sitedoc_settings['archive_last_run'];
885
886 if ($how_long > $frequency) { /* longer than how long between saves? */
887 // Get the file path and append a file name.
888 $filename = variable_get('file_directory_path', 'files') .'/'
889 . $sitedoc_settings['archive_directory'] .'/sitedoc_'. date('Ymd_Hi') .'.html';
890 $path = $filename;
891 // make sure we can write to it
892 $writable = fopen($path, 'w');
893 if ($writable == FALSE) {
894 watchdog('Site Doc', t('Cannot write "!file" to archive directory.', array('!file' => $filename)), WATCHDOG_ERROR);
895 return;
896 }
897
898 // Call the main list, format the output as a full page (without blocks),
899 // change all the relative paths to full paths, fix the page title.
900 $output = theme('page', sitedoc_list(), FALSE);
901 global $base_url;
902 $output = str_replace('@import "/', '@import "'. $base_url .'/', $output);
903 $output = str_replace('src="/', 'src="'. $base_url .'/', $output);
904 $output = str_replace('<title>Run cron', '<title>Site Documentation', $output);
905
906 // Save the file and write a message indicating whether it worked.
907 $saved_as = fwrite($writable, $output);
908 if ($saved_as === 0) {
909 watchdog('Site Doc', t('Documentation file save failed.'), WATCHDOG_ERROR);
910 }
911 else {
912 watchdog('Site Doc', t('Documentation file saved as !name', array('!name' => $filename)), WATCHDOG_NOTICE);
913 }
914 fclose($writable);
915
916 // update last run time
917 $sitedoc_settings['archive_last_run'] = time();
918 variable_set('sitedoc_settings', $sitedoc_settings);
919
920 } /* end if how long */
921 }
922
923 /****************************/
924 /** Callable functions **/
925 /****************************/
926
927 /**
928 * Produce the basic system overview.
929 *
930 * Parameters:
931 * TRUE/FALSE - whether to fix Cron stall problem if detected.
932 *
933 * Return: HTML string.
934 */
935 function sitedoc_drupal($kill_cron=0) {
936 global $base_url;
937 $dest = drupal_get_destination();
938 $_abled = array(t('Disabled'), t('Enabled'));
939 $_bool = array(t('False'), t('True'));
940 $_noyes = array(t('No'), t('Yes'));
941
942 $header = array(t('Item'), t('Value'), t('Operation'));
943 $setting = t('Settings');
944 $rows = array();
945
946 $rows[] = array(t('Site Name'), variable_get('site_name', 'none'), l($setting, 'admin/settings/site-information', array(), $dest));
947 $rows[] = array(t('Version'), VERSION, NULL);
948 $rows[] = array(t('Configuration file'), conf_path() .'/settings.php', NULL);
949 $rows[] = array(t('Install profile'), variable_get('install_profile', 'default'), NULL);
950 $rows[] = array(t('Base URL'), $base_url, NULL);
951
952 $cache = variable_get('cache', 0);
953 $cache_type = array(t('Disabled'), t('Normal'), t('Agressive'));
954 $rows[] = array(t('Cache'), $cache_type[$cache], l($setting, 'admin/settings/performance', array(), $dest));
955 $rows[] = array(t('Minimum cache lifetime'), format_interval(variable_get('cache_lifetme', 0), 1), l($setting, 'admin/settings/performance', array(), $dest));
956 $rows[] = array(t('CSS preprocess'), variable_get('preprocess_css', FALSE) ? t('Enabled') : t('Disabled'), l($setting, 'admin/settings/performance', array(), $dest));
957
958 $clean_urls = variable_get('clean_url', FALSE);
959 $rows[] = array(t('Clean URLS'), $_abled[$clean_urls], l($setting, 'admin/settings/clean-urls', array(), $dest));
960
961 $cron_last = variable_get('cron_last', NULL);
962 $cron_when = isset($cron_last) ? t('Last run !time ago', array('!time' => format_interval(time() - $cron_last))) : t('Not run yet');
963 // If it last ran more than an hour ago, add "Run now" link.
964 if (time() - $cron_last > 3600) {
965 $cron_op .= l(t('Run now'), 'admin/logs/status/run-cron', array(), $dest);
966 }
967 else {
968 $cron_op = NULL;
969 }
970 $cron_semaphore = variable_get('cron_semaphore', NULL); /* is it running now? */
971 if (isset($cron_semaphore)) {
972 $how_long = time() - $cron_semaphore; /* how long it's been running (secs) */
973 $cron_when .= ' - '. t('Running for !time', array('!time' => format_interval($how_long)))
974 .'<img src="/misc/watchdog-warning.png" width="17" height="17">';
975 if ($kill_cron) {
976 if ($kill_cron <= $how_long) {
977 variable_del('cron_semaphore'); /* turn off "cron started" flag */
978 variable_del('cron_last'); /** I don't think this is actually needed **/
979 } /* end if how long */
980 } /* end if kill_cron */
981 } /* end if semaphore */
982 $rows[] = array(t('Cron'), $cron_when, $cron_op);
983
984 if (module_exists('search')) {
985 $rows[] = array(t('Search Cron limit'), variable_get("search_cron_limit", null), l($setting, 'admin/settings/search', array(), $dest));
986 $remaining = 0;
987 $total = 0;
988 foreach (module_list() as $module) {
989 if (module_hook($module, 'search')) {
990 $status = module_invoke($module, 'search', 'status');
991 $remaining += $status['remaining'];
992 $total += $status['total'];
993 }
994 }
995 $count = format_plural($remaining, 'There is 1 item left to index.', 'There are @count items left to index.');
996 $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) .'%';
997 $status = t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) .' '. $count;
998 $link = l($setting, 'admin/settings/search', array(), $dest);
999 if ($remaining) {
1000 $link .= ', '. l(t('Run Cron'), 'admin/logs/status/run-cron', array(), $dest);
1001 }
1002 $rows[] = array(t('Search status'), $status, $link);
1003 }
1004
1005 $rows[] = array(t('Anonymous'), variable_get('anonymous', 'anonymous'), l($setting, 'admin/settings/site-information', array(), $dest));
1006 $rows[] = array(t('File directory'), variable_get('file_directory_path', 'files/'), l($setting, 'admin/settings/file-system', array(), $dest));
1007
1008 if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
1009 $downloads = t('Public');
1010 $download_op = NULL;
1011 }
1012 else {
1013 $downloads = t('Private') .'<img src="/misc/watchdog-warning.png" width="17" height="17">';
1014 $download_op = l($setting, 'admin/settings/file-system', array(), $dest);
1015 }
1016
1017 $rows[] = array(t('Download method'), $downloads, $download_op);
1018
1019 // Is the menu choice restricted?
1020 $menu_restrict = variable_get('menu_parent_items', NULL);
1021 // "Show all menus" is Zero. Unless the setting has been changed it won't be present (NULL)
1022 if ($menu_restrict) {
1023 $menu_msg = t('Restricted') .' ('. $menu_restrict .') <img src="/misc/watchdog-warning.png" width="17" height="17">';
1024 }
1025 else {
1026 $menu_msg = t('Show all menus') .'<img src="/misc/watchdog-ok.png" width="17" height="17">';
1027 }
1028 $rows[] = array(t('Content menu links'), $menu_msg, l($setting, 'admin/build/menu/settings', array(), $dest));
1029
1030 $rows[] = array(t('Default theme'), variable_get('theme_default', 'standard'), l($setting, 'admin/build/themes', array(), $dest));
1031
1032 $teaser_len = variable_get('teaser_length', 300);
1033 $rows[] = array(t('Teaser length'), $teaser_len ? $teaser_len : t('unlimited'), l($setting, 'admin/content/node-settings', array(), $dest));
1034
1035 // Get default filter and then look up its name.
1036 $filter = $filter_default = variable_get('filter_default_format', 0);
1037 if ($filter_default == 0) {
1038 $filter = 1;
1039 }
1040 $filter_name = db_fetch_object(db_query_range("SELECT f.name FROM {filter_formats} f WHERE f.format='%d'", $filter, 0, 1));
1041 if ($filter_default == 1) {
1042 $filter_warn = NULL;
1043 $filter_op = NULL;
1044 }
1045 else {
1046 $filter_warn = ' <em>('. t('not set') .')</em><img src="/misc/watchdog-warning.png" width="17" height="17"> ';
1047 $filter_op = l($setting, 'admin/settings/filters', array(), $dest);
1048 }
1049 $rows[] = array(t('Default filter format'), $filter_name->name . $filter_warn, $filter_op);
1050
1051 $rows[] = array(t('Operating system'), php_uname