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

Diff of /contributions/modules/awesome_install/awesome_install.module

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

revision 1.3, Thu Mar 6 05:05:56 2008 UTC revision 1.4, Thu Mar 6 19:31:09 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: awesome_install.module,v 1.2 2008/03/05 22:11:55 cwgordon7 Exp $  // $Id: awesome_install.module,v 1.3 2008/03/06 05:05:56 cwgordon7 Exp $
3    
4    //unset($_SESSION);
5    
6  // Ugliness!  // Ugliness!
7  if (isset($_SESSION['awesome install'])) {  // @TODO: find a way to make it slightly LESS ugly!
8    if ($_SESSION['awesome install']) {  // @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']) {      if ($_GET['q'] != $_SESSION['awesome install']['path']) {
12        drupal_goto($_SESSION['awesome install']['path']);        drupal_goto($_SESSION['awesome install']['path']);
13      }      }
# Line 14  if (isset($_SESSION['awesome install'])) Line 18  if (isset($_SESSION['awesome install']))
18   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
19   */   */
20  function awesome_install_form_alter(&$form, $form_state, $form_id) {  function awesome_install_form_alter(&$form, $form_state, $form_id) {
   if (arg(2) == 'search') {  
     drupal_set_message(print_r($_SESSION, TRUE));  
   }  
21    if ($form_id == 'system_modules' || isset($_SESSION['awesome install'])) {    if ($form_id == 'system_modules' || isset($_SESSION['awesome install'])) {
22      if ($form_id == 'system_modules') {      if ($form_id == 'system_modules') {
23        $form['old_modules'] = array('#type' => 'value', '#value' => module_list());        $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';      $form['#submit'][] = 'awesome_install_submit';
27    }    }
28  }  }
# Line 30  function awesome_install_form_alter(&$fo Line 32  function awesome_install_form_alter(&$fo
32   * (Yes, it's awesome).   * (Yes, it's awesome).
33   */   */
34  function awesome_install_submit($form, &$form_state) {  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'];    $data = $_SESSION['awesome install'];
42    if (!isset($data['modsleft'])) {    if (!isset($data['paths'])) {
43      if (!empty($form_state['storage'])) {      if (!empty($form_state['storage'])) {
44        // It's an alien! Abort!        // It's an alien! Abort!
45        return;        return;
# Line 46  function awesome_install_submit($form, & Line 54  function awesome_install_submit($form, &
54          unset($status[$module]);          unset($status[$module]);
55        }        }
56      }      }
57      $data['modsleft'] = $status;      $modules = $status;
58    }      if (empty($modules)) {
59    if (!isset($data['steps'])) {        return;
     $data['steps'] = module_invoke_all('configuration_steps');  
   }  
   // Continue through the modules while $continue.  
   $continue = TRUE;  
   while ($continue) {  
     $continue = FALSE;  
     if (!isset($data['module'])) {  
       $module = reset($data['modsleft']);  
     }  
     else {  
       $module = $data['module'];  
60      }      }
61      if (!$module) {      $paths = array();
62        // We're as done as we're going to be, I guess.      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']);        unset($_SESSION['awesome install']);
73        return;        return;
74      }      }
     $steps = $data['steps'];  
     if (!isset($data['step'])) {  
       $data['step'] = reset($steps);  
     }  
     $continue2 = TRUE;  
     while ($continue2) {  
       foreach ($steps as $step) {  
         if ($data['step'] == $step) {  
           $path = $step($module);  
           if (!empty($path)) {  
             $data['path'] = $path;  
             $continue2 = FALSE;  
             break;  
           }  
           else {  
             $data['step'] = next($steps);  
           }  
         }  
       }  
       if ($continue2) {  
         $data['module'] = next($data['modsleft']);  
         $module = $data['module'];  
         if (!$module) {  
           unset($_SESSION['awesome install']);  
           return;  
         }  
         $data['step'] = reset($steps);  
       }  
     }  
75    }    }
76    $_SESSION['awesome install'] = $data;    $_SESSION['awesome install'] = $data;
77  }  }
78    
79  function awesome_install_find_settings_form($module) {  /**
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');    $menu = module_invoke($module, 'menu');
101    foreach ($menu as $callback => $item) {    $return = array();
102      if (strpos($callback, 'admin/') === 0) {    foreach ($menu as $callback => $value) {
103        if ($item['page callback'] == 'drupal_get_form') {      if (strpos($callback, 'admin/') === 0 && strpos($callback, '%') === FALSE) {
104          // @TODO: More than one config form?        $return[] = $callback;
         $filepath = !empty($item['file path']) ? $item['file path'] : drupal_get_path('module', $module);  
         require_once $filepath .'/'. $item['file'];  
         return reset($item['page arguments']);  
       }  
105      }      }
106    }    }
107    return FALSE;    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  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.2