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

Contents of /contributions/modules/alternadmin/alternadmin.module

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


Revision 1.4 - (show annotations) (download) (as text)
Mon Jun 26 00:19:03 2006 UTC (3 years, 5 months ago) by merlinofchaos
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +14 -5 lines
File MIME type: text/x-php
More throttle fixes; integrate help onto modules page.
1 <?php
2 // $Id: alternadmin.module,v 1.3 2006/06/26 00:03:01 merlinofchaos Exp $
3
4 /**
5 * implementation of hook_help
6 */
7 function alternadmin_help($section = NULL) {
8 switch ($section) {
9 case 'admin/modules#description':
10 return t('This module provides an alternative administrative interface to Drupal. It actually replaces existing management screens and provides a hopefully easier interface.');
11 case 'alternadmin':
12 return t('This is the central point for administrative tasks. From here you can quickly get to screens that help you set up and administer your Drupal site. It can be easily reconfigured so that common tasks are more easily reached.');
13 }
14 }
15
16 /**
17 * implementation of hook_menu
18 */
19 function alternadmin_menu($may_cache) {
20 if ($may_cache) {
21 $items[] = array(
22 'path' => 'alternadmin',
23 'access' => user_access('administer site'),
24 'title' => t('administer site'),
25 'callback' => 'alternadmin_page',
26 'type' => MENU_NORMAL_ITEM,
27 );
28 $items[] = array(
29 'path' => 'alternadmin/settings',
30 'access' => user_access('administer site'),
31 'title' => t('site settings'),
32 'callback' => 'alternadmin_site_settings',
33 'type' => MENU_CALLBACK,
34 );
35 $items[] = array(
36 'path' => 'alternadmin/modules',
37 'access' => user_access('administer site'),
38 'title' => t('system modules'),
39 'callback' => 'alternadmin_modules_page',
40 'type' => MENU_CALLBACK,
41 );
42 }
43 return $items;
44 }
45
46 /**
47 * implementation of hook init -- this function forces the administrative
48 * UI into a default theme.
49 */
50 function alternadmin_init() {
51 global $custom_theme;
52
53 if (arg(0) == 'admin' && variable_get('alternadmin_admin_theme', NULL)) {
54 $custom_theme = variable_get('alternadmin_admin_theme', NULL);
55 }
56 else if (arg(0) == 'alternadmin') {
57 $custom_theme = variable_get('alternadmin_theme', 'bluemarine');
58 }
59 }
60
61 /**
62 * implementation of hook init -- this function forces the administrative
63 * UI into a default theme.
64 */
65 function alternadmin_settings() {
66 $themes = system_theme_data();
67 ksort($themes);
68 $options[0] = t('System Default');
69 foreach ($themes as $theme) {
70 $options[$theme->name] = $theme->name;
71 }
72
73 $form['alternadmin_theme'] = array(
74 '#type' => 'select',
75 '#options' => $options,
76 '#title' => t('Choose which theme AlternAdmin UI should display in'),
77 '#default_value' => variable_get('alternadmin_theme', 'bluemarine'),
78 );
79
80 $form['alternadmin_admin_theme'] = array(
81 '#type' => 'select',
82 '#options' => $options,
83 '#title' => t('Choose which theme normal Drupal Admin UI should display in'),
84 '#default_value' => variable_get('alternadmin_admin_theme', '0'),
85 );
86 return $form;
87 }
88
89 // --------------------------------------------------------------------------
90 // Adminstrative pages.
91
92 /**
93 * Top level page. This page constructs various blocks and places them
94 * on the page.
95 */
96 function alternadmin_page() {
97 alternadmin_set_head();
98 $blocks = module_invoke_all('administer_blocks');
99
100 // for now
101 foreach ($blocks as $block) {
102 $output .= theme('alternadmin_block', $block);
103 }
104
105 return $output;
106 }
107
108 // -------------------------------------------------------------------------
109 // system settings page
110
111 function alternadmin_site_settings($module = NULL) {
112 alternadmin_set_head();
113 if ($module) {
114 $form = module_invoke($module, 'settings');
115 $loc = array(
116 array(
117 'path' => 'alternadmin/modules/',
118 'title' => t('system modules'),
119 ),
120 array(
121 'path' => 'alternadmin/modules/' . $module,
122 'title' => $module,
123 ),
124 );
125 menu_set_location($loc);
126 $form['#submit'] = array(
127 'system_settings_form_submit' => array(),
128 'alternadmin_settings_submit' => array('alternadmin/modules'),
129 );
130 }
131 else {
132 $form = system_view_general();
133 $module = 'system';
134 $form['#submit'] = array(
135 'system_settings_form_submit' => array(),
136 'alternadmin_settings_submit' => array('alternadmin'),
137 );
138 }
139
140
141 foreach ($form as $id => $item) {
142 if ($item['#type'] == 'fieldset') {
143 $form[$id]['#type'] = 'alternadmin_tabpage';
144 }
145 }
146
147
148 $form = array_merge(array('tab-set-pref' => array('#value' => '<div class="tab-pane">')), $form);
149 $form['tab-set-post'] = array('#value' => '</div>');
150
151 return system_settings_form($module . '_settings_form', $form);
152 }
153
154 function alternadmin_settings_submit($form_id, $form_values, $where) {
155 return $where;
156 }
157 // -------------------------------------------------------------------------
158 // System modules page
159
160 /**
161 * Menu callback; displays a listing of all modules.
162 */
163 function alternadmin_modules_page() {
164 alternadmin_set_head();
165 // Get current list of modules
166 $files = system_listing('\.module$', 'modules', 'name', 0);
167
168 // Extract current files from database.
169 system_get_files_database($files, 'module');
170
171 ksort($files);
172
173 $order = array('modules' => array()); // ensure modules is first in list.
174
175 foreach ($files as $filename => $file) {
176 drupal_get_filename('module', $file->name, $file->filename);
177 drupal_load('module', $file->name);
178
179 // Discover the base module directory this lives in.
180 $working_name = dirname($file->filename);
181 $last_name = NULL;
182 while ($dir = basename($working_name)) {
183 if ($dir == 'modules') {
184 $group = isset($last_name) ? $last_name : $dir;
185 break;
186 }
187 $last_name = $dir;
188 $working_name = dirname($working_name);
189 }
190
191 if (!isset($order[$group])) {
192 $order[$group] = array();
193 }
194 $order[$group][] = $file->name;
195
196 $file->description = module_invoke($file->name, 'help', 'admin/modules#description');
197
198 $form['name'][$file->name] = array('#value' => $file->name);
199 $form['description'][$file->name] = array('#value' => $file->description);
200 $options[$file->name] = '';
201 if ($file->status) {
202 $status[] = $file->name;
203 }
204 if ($file->throttle) {
205 $throttle[] = $file->name;
206 }
207 $orig_status[$file->name] = $file->status;
208 $orig_throttle[$file->name] = $file->throttle;
209 // log the critical hooks implemented by this module
210 $bootstrap = 0;
211 foreach (bootstrap_hooks() as $hook) {
212 if (module_hook($file->name, $hook)) {
213 $bootstrap = 1;
214 break;
215 }
216 }
217
218 // Update the contents of the system table:
219 if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) {
220 db_query("UPDATE {system} SET description = '%s', name = '%s', bootstrap = %d, filename = '%s' WHERE filename = '%s'", $file->description, $file->name, $bootstrap, $file->filename, $file->old_filename);
221 }
222 else {
223 // This is a new module.
224 db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
225 }
226 }
227
228
229 // Handle status checkboxes, including overriding the generated
230 // checkboxes for required modules.
231 $form['status'] = array('#type' => 'checkboxes', '#default_value' => $status, '#options' => $options);
232 $required = array('block', 'filter', 'node', 'system', 'user', 'watchdog');
233 foreach ($required as $require) {
234 $form['status'][$require] = array('#type' => 'hidden', '#value' => 1, '#suffix' => t('required'));
235 }
236
237 /**
238 * Handle throttle checkboxes, including overriding the generated checkboxes for required modules.
239 */
240 if (module_exist('throttle')) {
241 $form['throttle'] = array('#type' => 'checkboxes', '#default_value' => $throttle, '#options' => $options);
242 $throttle_required = array_merge($required, array('throttle'));
243 foreach ($throttle_required as $require) {
244 $form['throttle'][$require] = array('#type' => 'hidden', '#value' => 0, '#suffix' => t('required'));
245 }
246 }
247
248 $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
249
250 // Any 'group' with just 1 member gets rolled back into 'individual'.
251 foreach ($order as $group => $files) {
252 if (count($files) == 1) {
253 $order['other modules not in a package'][] = current($files);
254 unset($order[$group]);
255 }
256 }
257
258 sort($order['modules']);
259 $form['order'] = array('#type' => 'value', '#value' => $order);
260 $form['original'] = array('#type' => 'value', '#value' => $orig_status);
261 $form['original_throttle'] = array('#type' => 'value', '#value' => $orig_throttle);
262 return drupal_get_form('alternadmin_modules_form', $form);
263 }
264
265 function theme_alternadmin_modules_form($form) {
266 $header = array(t('Name'), t('Description'), t('Enabled'));
267 if (module_exist('throttle')) {
268 $header[] = t('Throttle');
269 }
270 $settings = module_implements('settings');
271
272 foreach ($form['order']['#value'] as $group => $files) {
273 if ($group == 'modules') {
274 $group = t('drupal core modules');
275 }
276 $rows = array();
277 foreach($files as $key) {
278 $row = array();
279 $row[] = array('data' => form_render($form['name'][$key]), 'class' => 'module');
280 $row[] = form_render($form['description'][$key]);
281 $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
282
283 if (module_exist('throttle')) {
284 $row[] = array('data' => form_render($form['throttle'][$key]), 'align' => 'center');
285 }
286 if ($form['status'][$key]['#value']) {
287 $active_row = $row;
288 $row[2] = t('enabled');
289 $links = array();
290 if (in_array($key, $settings)) {
291 $links = array(l(t('settings'), 'alternadmin/settings/' . $key));
292 }
293 if (module_exist('help')) {
294 if (module_invoke($key, 'help', "admin/help#$key")) {
295 $links[] = l(t('help'), "admin/help/$key");
296 }
297 }
298 $links = array_merge($links, module_invoke($key, 'admin_links'));
299 $active_row[] = theme('links', $links);
300 $active_rows[$key] = $active_row;
301 $active_modules++;
302 }
303 $rows[] = $row;
304 }
305 $output .= '<div class="tab-page"><h2 class="tab">' . $group . '</h2>';
306 $output .= theme('table', $header, $rows, array('class' => 'modules'));
307 $output .= '</div>';
308 }
309
310 $header[] = '&nbsp;';
311 ksort($active_rows);
312 $active = '<div class="tab-page"><h2 class="tab">enabled modules</h2>';
313 $active .= theme('table', $header, $active_rows, array('class' => 'modules'));
314 $active .= '</div>';
315 $output .= "<p>$active_modules modules enabled out of " . count($form['original']['#value']) . '</p>';
316 $output .= form_render($form);
317 $output = '<div class="tab-pane">' . $active . $output . '</div>';
318 return $output;
319 }
320
321
322 function alternadmin_modules_form_submit($form_id, $edit) {
323 // db_query("UPDATE {system} SET status = 0, throttle = 0 WHERE type = 'module'");
324
325 $new_modules = array();
326 foreach ($edit['status'] as $key => $choice) {
327 if ((bool) $choice != $edit['original'][$key]) {
328 db_query("UPDATE {system} SET status = %d WHERE type = 'module' AND name = '%s'", (bool) $choice, $key);
329 drupal_set_message(t('%module has been %changed', array('%module' => $key, '%changed' => $choice ? t('enabled') : t('disabled'))));
330 if (!module_exist($key)) {
331 $new_modules[] = $key;
332 }
333 }
334 }
335
336 if (is_array($edit['throttle'])) {
337 foreach ($edit['throttle'] as $key => $choice) {
338 if ((bool) $choice != $edit['original_throttle'][$key]) {
339 db_query("UPDATE {system} SET throttle = %d WHERE type = 'module' and name = '%s'", (bool) $choice, $key);
340 drupal_set_message(t('%module has been %changed', array('%module' => $key, '%changed' => $choice ? t('throttled') : t('unthrottled'))));
341 }
342 }
343 }
344
345 module_list(TRUE, FALSE);
346
347 include './includes/install.inc';
348 foreach ($new_modules as $module) {
349 // Set the installed schema version for newly-enabled modules
350 $versions = drupal_get_schema_versions($module);
351 if (drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
352 drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
353 module_invoke($module, 'install');
354 }
355 }
356
357 menu_rebuild();
358
359 return 'alternadmin/modules';
360 }
361
362 // -------------------------------------------------------------------------
363 // Alternadmin helper functions
364
365 /**
366 * This is really just to clean up the syntax a little and make it easier
367 * to change the module name.
368 */
369 function alternadmin_get_path() {
370 return drupal_get_path('module', 'alternadmin');
371 }
372
373 /**
374 * Set up header stuff on demand. Safe to be called multiple times.
375 */
376 function alternadmin_set_head() {
377 static $done = false;
378 if (!$done) {
379 $path = alternadmin_get_path();
380 theme_add_style($path . '/alternadmin.css');
381 drupal_add_js($path . '/js/collapse_div.js');
382 drupal_add_js($path . '/js/menus.js');
383 drupal_add_js($path . '/js/tabs.js');
384 $done = true;
385 }
386 }
387
388 // -------------------------------------------------------------------------
389 // Alternadmin block construction
390
391 /**
392 * Ripped code off from jstools -- why not just jstools? Dunno.
393 */
394 function theme_alternadmin_tabpage($element) {
395 return ' <div class="tab-page">
396 <h2 class="tab">' . $element['#title'] . '</h2>
397 ' . $element['#children'] . '
398 </div>
399 ';
400 }
401
402 /**
403 * implementation of hook_administer_blocks
404 */
405 function alternadmin_administer_blocks() {
406 $items[] = array(
407 'title' => t('Site Configuration'),
408 'description' => t('This block contains some basic site configuration options'),
409 'content' => alternadmin_admin_settings_block(),
410 );
411 return $items;
412 }
413
414 function alternadmin_admin_settings_block() {
415 $output = '<dl>';
416 $output .= ' <dt>' . l('system settings', 'alternadmin/settings') . '</dt>';
417 $output .= ' <dd>' . t('Configure general system settings') . '</dd>';
418 $output .= ' <dt>' . l('system modules', 'alternadmin/modules') . '</dt>';
419 $output .= ' <dd>' . t('Configure modules and their settings') . '</dd>';
420 $output .= '</dl>';
421 return $output;
422 }
423 // -------------------------------------------------------------------------
424 // Themables
425
426 function theme_alternadmin_block($block) {
427 $output = <<< EOT
428 <div class="alternadmin-panel collapsible">
429 <div class="head">
430 $block[title]
431 </div>
432 <div class="body">
433 <div class="desc">
434 $block[description]
435 </div>
436 $block[content]
437 </div>
438 </div>
439 EOT;
440 return $output;
441 }
442
443
444
445 // -------------------------------------------------------------------------
446 // Proof of concept stuff to make this work a little better.
447
448 function views_admin_links() {
449 return array(
450 l('administer', 'admin/views'),
451 );
452 }
453

  ViewVC Help
Powered by ViewVC 1.1.2