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

Contents of /contributions/modules/awesome_install/awesome_install.module

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


Revision 1.4 - (show annotations) (download) (as text)
Thu Mar 6 19:31:09 2008 UTC (20 months, 3 weeks ago) by cwgordon7
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +77 -62 lines
File MIME type: text/x-php
Update to the awesomeness
1 <?php
2 // $Id: awesome_install.module,v 1.3 2008/03/06 05:05:56 cwgordon7 Exp $
3
4 //unset($_SESSION);
5
6 // Ugliness!
7 // @TODO: find a way to make it slightly LESS ugly!
8 // @TODO: Make this work! Plus make it more awesome!
9 if (isset($_SESSION['awesome install']['path'])) {
10 if ($_SESSION['awesome install']['path']) {
11 if ($_GET['q'] != $_SESSION['awesome install']['path']) {
12 drupal_goto($_SESSION['awesome install']['path']);
13 }
14 }
15 }
16
17 /**
18 * Implementation of hook_form_alter().
19 */
20 function awesome_install_form_alter(&$form, $form_state, $form_id) {
21 if ($form_id == 'system_modules' || isset($_SESSION['awesome install'])) {
22 if ($form_id == 'system_modules') {
23 $form['old_modules'] = array('#type' => 'value', '#value' => module_list());
24 }
25 $form['path'] = array('#type' => 'value', '#value' => $_GET['q']);
26 $form['#submit'][] = 'awesome_install_submit';
27 }
28 }
29
30 /**
31 * Submit callback, for like, all forms in existence.
32 * (Yes, it's awesome).
33 */
34 function awesome_install_submit($form, &$form_state) {
35 if (!isset($_SESSION['awesome install'])) {
36 menu_rebuild();
37 cache_clear_all();
38 $_SESSION['awesome install'] = array();
39 }
40 drupal_set_message(print_r($form_state, TRUE));
41 $data = $_SESSION['awesome install'];
42 if (!isset($data['paths'])) {
43 if (!empty($form_state['storage'])) {
44 // It's an alien! Abort!
45 return;
46 }
47 $status = $form_state['values']['status'];
48 $old = $form_state['values']['old_modules'];
49 foreach ($status as $module => $enabled) {
50 if (!$enabled) {
51 unset($status[$module]);
52 }
53 if (in_array($module, $old)) {
54 unset($status[$module]);
55 }
56 }
57 $modules = $status;
58 if (empty($modules)) {
59 return;
60 }
61 $paths = array();
62 foreach ($modules as $module) {
63 $paths = array_merge($paths, _awesome_install_paths($module));
64 }
65 $data['paths'] = $paths;
66 }
67 if (isset($form_state['values']['path'])) {
68 unset($data['paths'][$form_state['values']['path']]);
69 $data['path'] = reset($data['paths']);
70 $form_state['redirect'] = $data['path'];
71 if (empty($data['paths'])) {
72 unset($_SESSION['awesome install']);
73 return;
74 }
75 }
76 $_SESSION['awesome install'] = $data;
77 }
78
79 /**
80 * Helper function.
81 */
82 function _awesome_install_paths($module) {
83 return module_invoke_all('configuration_steps', $module);
84 }
85
86 /**
87 * Implementation of hook_configuration_steps().
88 */
89 function awesome_install_configuration_steps($module) {
90 $return = awesome_install_find_settings_forms($module);
91 $return = array_merge($return, awesome_install_block($module));
92 $return = array_merge($return, awesome_install_perms($module));
93 return $return;
94 }
95
96 /**
97 * Helper function.
98 */
99 function awesome_install_find_settings_forms($module) {
100 $menu = module_invoke($module, 'menu');
101 $return = array();
102 foreach ($menu as $callback => $value) {
103 if (strpos($callback, 'admin/') === 0 && strpos($callback, '%') === FALSE) {
104 $return[] = $callback;
105 }
106 }
107 return $return;
108 }
109
110 /**
111 * Helper function.
112 */
113 function awesome_install_block($module) {
114 if (module_hook($module, 'block')) {
115 // @TODO. Custom page needed?
116 return array('admin/build/block');
117 }
118 return array();
119 }
120
121 /**
122 * Helper function.
123 */
124 function awesome_install_perms($module) {
125 if (module_hook($module, 'perm')) {
126 // @TODO. Custom page needed?
127 return array('admin/user/permissions');
128 }
129 return array();
130 }

  ViewVC Help
Powered by ViewVC 1.1.2