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

Diff of /contributions/modules/moduleinfo/moduleinfo.module

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

revision 1.1.2.3, Wed May 27 16:20:37 2009 UTC revision 1.1.2.4, Thu Oct 29 06:41:14 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    // $Id$
3    
4  /**  /**
5   * Implementation of hook_menu().   * Implementation of hook_menu().
# Line 18  function moduleinfo_menu() { Line 18  function moduleinfo_menu() {
18  /**  /**
19   * Implementation of hook_perm().   * Implementation of hook_perm().
20   */   */
21  function moduleinfo_perm(){  function moduleinfo_perm() {
22    return array('moduleinfo settings');    return array('moduleinfo settings');
23  }  }
24    
25  /****  /**
26  an implementation of hook_form_alter.   * Implementation of hook_form_alter().
27  This hook gets the module specific data (from moduleinfo_get_info)   * This hook gets the module specific data (from moduleinfo_get_info)
28  for each module and inserts it into the system_modules form   * for each module and inserts it into the system_modules form
29  which is displayed on the pages admin/build/modules and admin/build/modules/list   * which is displayed on the pages admin/build/modules and admin/build/modules/list
30  ****/   */
31  function moduleinfo_form_alter($form, $form_state, $form_id){  function moduleinfo_form_alter($form, $form_state, $form_id) {
32      if ($form_id=="system_modules"){    if ($form_id == 'system_modules') {
33        if ("admin/build/modules/info" == $_GET['q'] || variable_get('moduleinfo_shown',TRUE)){      if ('admin/build/modules/info' == $_GET['q'] || variable_get('moduleinfo_shown', TRUE)) {
34          $files = module_rebuild_cache();        $files = module_rebuild_cache();
35          foreach($form["description"] as $module=>$description){        foreach ($form['description'] as $module => $description) {
36              if ($files[$module]->status=="0")continue;          if ($files[$module]->status == '0') {
37              continue;
             $info = moduleinfo_get_info($module);  
             if (!$info)continue;  
   
             $fieldset = array(  
               '#title' => t('ModuleInfo'),  
               '#collapsible' => TRUE,  
               '#collapsed' => TRUE,  
               '#value' => $info,  
             );  
             $form["description"][$module]['#value'] .= theme('fieldset', $fieldset);;  
38          }          }
39        }          $info = moduleinfo_get_info($module);
40        else {          if (!$info) {
41          drupal_set_message(l(t("View info about your modules"),"admin/build/modules/info"));            continue;
42            }
43    
44            $fieldset = array(
45              '#title' => t('ModuleInfo'),
46              '#collapsible' => TRUE,
47              '#collapsed' => TRUE,
48              '#value' => $info,
49            );
50            $form['description'][$module]['#value'] .= theme('fieldset', $fieldset);
51        }        }
52      }      }
53        else {
54          drupal_set_message(l(t('View info about your modules'), 'admin/build/modules/info'));
55        }
56      }
57  }  }
58  /****  
59  an implementation of hook_help  /**
60  ****/   * Implementation of hook_help().
61  function moduleinfo_help($section='') {   */
62    function moduleinfo_help($section = '') {
63    switch ($section) {    switch ($section) {
64      case "admin/help#moduleinfo":      case 'admin/help#moduleinfo':
65        return t("ModuleInfo informs the admin about changes a module makes to the interface.");        return t('ModuleInfo informs the admin about changes a module makes to the interface.');
66    }    }
   return '';  
   
67  }  }
68    
69  /*** possible new hook?  /** possible new hook?
70  returns associative array:   * returns associative array:
71  $info["created"]["pages"] = path => array(name=> description=>)   * $info["created"]["pages"] = path => array(name=> description=>)
72  $info["created"]["blocks"] = i => array(name=> description=>)   * $info["created"]["blocks"] = i => array(name=> description=>)
73  $info["created"]["content-types"] = name => description   * $info["created"]["content-types"] = name => description
74  $info["effected"]....[mirrors created]   * $info["effected"]....[mirrors created]
75    
76  function moduleinfo_moduleinfo(){  function moduleinfo_moduleinfo(){
77      $info = array();      $info = array();
# Line 79  function moduleinfo_moduleinfo(){ Line 81  function moduleinfo_moduleinfo(){
81      $info['blocks']['created'][] = 'block description';      $info['blocks']['created'][] = 'block description';
82      return $info;      return $info;
83  }  }
84  ***/   */
85    
86  /*** collects all the information we can find about a module from various hooks ***/  /**
87  function moduleinfo_get_info($module){   * Collects all the information we can find about a module from various hooks.
88      $output = '';   */
89      $help = moduleinfo_get_help($module);  function moduleinfo_get_info($module) {
90      if ($help){    $output = '';
91          $output.= '<strong>'.t('Help').'</strong>';    $help = moduleinfo_get_help($module);
92          $output.= '<ul>'.join('',$help).'</ul>';    if ($help) {
93      }      $output .= '<strong>'. t('Help') .'</strong>';
94      $pages = moduleinfo_get_pages($module);      $output .= '<ul>'. join('', $help) .'</ul>';
95      if (isset($pages["config"])){    }
96          $output.= '<strong>'.t('Configuration').'</strong>';    $pages = moduleinfo_get_pages($module);
97          $output.= '<ul>'.join('',$pages["config"]).'</ul>';    if (isset($pages['config'])) {
98      }      $output .= '<strong>'. t('Configuration') .'</strong>';
99      if (isset($pages["other"])){      $output .= '<ul>'. join('', $pages['config']) .'</ul>';
100          $output.= '<strong>'.t('Pages').'</strong>';    }
101          $output.= '<ul>'.join('',$pages["other"]).'</ul>';    if (isset($pages['other'])) {
102      }      $output .= '<strong>'. t('Pages') .'</strong>';
103      $blocks = moduleinfo_get_blocks($module);      $output .= '<ul>'. join('', $pages['other']) .'</ul>';
104      if ($blocks){    }
105          $output.= '<strong>'.t('Blocks').'</strong>';    $blocks = moduleinfo_get_blocks($module);
106          $output.= '<ul>'.join('',$blocks).'</ul>';    if ($blocks) {
107      }      $output .= '<strong>'. t('Blocks') .'</strong>';
108      $cts = moduleinfo_get_content_types($module);      $output .= '<ul>'. join('', $blocks) .'</ul>';
109      if ($cts){    }
110          $output.= '<strong>'.t('Content Types').'</strong>';    $content_types = moduleinfo_get_content_types($module);
111          $output.= '<ul>'.join('',$cts).'</ul>';    if ($content_types) {
112      }      $output .= '<strong>'. t('Content types') .'</strong>';
113      return $output;      $output .= '<ul>'. join('', $content_types) .'</ul>';
114  }    }
115      return $output;
116  /*** check for help ***/  }
117  function moduleinfo_get_help($module){  
118      if (module_hook($module,"help")){  /**
119          $res = module_invoke($module,"help","admin/help#".$module,arg());   * Check for help.
120          if ($res)   */
121              return array("<li>".t("You can find help for this module on the page ").l(moduleinfo_get_menu_name("admin/help/".$module).t(" help"),"admin/help/".$module)."</li>");  function moduleinfo_get_help($module) {
122      }    if (module_hook($module, 'help')) {
123      return array();      $res = module_invoke($module, 'help', "admin/help#$module", arg());
124  }      if ($res) {
125          return array('<li>'. t('You can find help for this module on the page <a href="@help-page">@help-tile help</a>.', array('@help-page' => "admin/help/$module", '@help-tile' => moduleinfo_get_menu_name("admin/help/$module"))) .'</li>');
 /*** check for pages, both config and other ***/  
 /** todo -- display w/ submenu structure **/  
 function moduleinfo_get_pages($module,$cached=TRUE){  
     $pages = array();  
     if (module_hook($module,"menu")){  
         $menus = module_invoke($module, "menu", $cached);  
         if ($menus){  
             foreach ($menus as $path=>$menu){  
                 if ($menu["type"]!=MENU_CALLBACK){  /** menu_callbacks wont appear in menus **/  
                     $full = moduleinfo_get_breadcrumb($path);  
                     $txt="<li>".l(moduleinfo_get_menu_name($path),$path).'<sub>'.t(" ($full)")."</sub></li>\n";  
                     if (strpos($path,"admin/settings")!==FALSE)  
                         $pages["config"][] = '<li>'.l(moduleinfo_get_menu_name($path),$path).'</li>';  
                     else  
                         $pages["other"][] = $txt;  
                 }  
             }  
         }  
126      }      }
127      return $pages;    }
128      return array();
129  }  }
130    
131  /*** check for block ***/  /**
132  function moduleinfo_get_blocks($module){   * Check for pages, both config and other.
133      /*** check for blocks ***/   * todo: display w/ submenu structure
134      $blocks = array();   */
135      if (module_hook($module, "block")){  function moduleinfo_get_pages($module, $cached = TRUE) {
136              $mblocks = module_invoke($module,"block","list");    $pages = array();
137              if ($mblocks){    if (module_hook($module, 'menu')) {
138                  foreach($mblocks as $i=>$block){      $menus = module_invoke($module, 'menu', $cached);
139                      $blocks[] ="<li>".l($block["info"],"admin/build/block/configure/".$module."/".$i)."</li>\n";      if ($menus) {
140                  }        foreach ($menus as $path => $menu) {
141              }          // menu_callbacks wont appear in menus.
142            if ($menu['type'] != MENU_CALLBACK) {
143              if (strpos($path, 'admin/settings') !== FALSE) {
144                $pages['config'][] = '<li>'. l(moduleinfo_get_menu_name($path), $path) .'</li>';
145              }
146              else {
147                $pages['other'][] = '<li>'. l(moduleinfo_get_menu_name($path), $path) .'<sub> ('. moduleinfo_get_breadcrumb($path) .')</sub></li>';
148              }
149          }          }
150      return $blocks;        }
151        }
152      }
153      return $pages;
154  }  }
155    
156  /*** check for custom content-types ***/  /**
157  function moduleinfo_get_content_types($module){   * Check for blocks.
158      $content_types = array();   */
159      if (module_hook($module, "node_info")){  function moduleinfo_get_blocks($module) {
160              $nodes = module_invoke($module,"node_info");    $blocks = array();
161              if ($nodes){    if (module_hook($module, 'block')) {
162                  foreach ($nodes as $name=>$node){      $mblocks = module_invoke($module, 'block', 'list');
163                      $content_types[] = "<li>".l($node["name"],"admin/content/types/".$name).": ".$node["description"]."</li>\n";      if ($mblocks) {
164                  }        foreach ($mblocks as $i => $block) {
165              }          $blocks[] = '<li>'. l($block['info'], "admin/build/block/configure/$module/$i") .'</li>';
166          }        }
167      return $content_types;      }
168      }
169      return $blocks;
170  }  }
171    
172  /*** grab a module name from the database ***/  /**
173  function moduleinfo_get_menu_name($path){   * Check for custom content types.
174      $result = db_query("SELECT link_title FROM {menu_links} WHERE link_path = '%s'",array($path));   */
175      $res = db_fetch_object($result)->link_title;  function moduleinfo_get_content_types($module) {
176      if (!$res){    $content_types = array();
177          $res = array_slice(explode("/",$path),-1);    if (module_hook($module, 'node_info')) {
178          $res = ucwords($res[0]);      $nodes = module_invoke($module, 'node_info');
179      }      if ($nodes) {
180      return $res;        foreach ($nodes as $name => $node) {
181  }          $content_types[] = '<li>'. l($node['name'], "admin/content/types/$name") .': '. $node['description'] .'</li>';
182          }
 /*** generate a breadcrumb-style string from a menu path ***/  
 function moduleinfo_get_breadcrumb($path){  
     $parts = explode("/",$path);  
     $current = "";  
     $breadcrumb = "";  
     foreach($parts as $part){  
         if ($breadcrumb!="")$breadcrumb.="&raquo;";  
         if ($current!="")$current.="/";  
         $current .= $part;  
         $breadcrumb .= moduleinfo_get_menu_name($current);  
183      }      }
184      return $breadcrumb;    }
185      return $content_types;
186  }  }
187    
188  function moduleinfo_settings_form() {  /**
189     * Grab a module name from the database.
190     */
191    function moduleinfo_get_menu_name($path) {
192      $result = db_query("SELECT link_title FROM {menu_links} WHERE link_path = '%s'", array($path));
193      $res = db_fetch_object($result)->link_title;
194      if (!$res) {
195        $res = array_slice(explode('/', $path), -1);
196        $res = ucwords($res[0]);
197      }
198      return $res;
199    }
200    
201    /**
202     * Generate a breadcrumb-style string from a menu path.
203     */
204    function moduleinfo_get_breadcrumb($path) {
205      $parts = explode('/', $path);
206      $current = '';
207      $breadcrumb = '';
208      foreach ($parts as $part) {
209        if ($breadcrumb != '') {
210          $breadcrumb .= "&raquo;";
211        }
212        if ($current != '') {
213          $current .= '/';
214        }
215        $current .= $part;
216        $breadcrumb .= moduleinfo_get_menu_name($current);
217      }
218      return $breadcrumb;
219    }
220    
221    /**
222     * Settings form.
223     */
224    function moduleinfo_settings_form() {
225    $form['moduleinfo_shown'] = array(    $form['moduleinfo_shown'] = array(
226      '#title' => t('Shown by Default'),      '#title' => t('Shown by default'),
227      '#type' => 'checkbox',      '#type' => 'checkbox',
228      '#description' => t('Show info on the main modules page or only on the sub-page (admin/build/modules/info)'),      '#description' => t('Show info on the main modules page or only on the sub-page (admin/build/modules/info).'),
229      '#default_value' => variable_get('moduleinfo_shown', TRUE),      '#default_value' => variable_get('moduleinfo_shown', TRUE),
230    );    );
231    $form[] = array(    $form['submit'] = array(
232      '#type' => 'submit',      '#type' => 'submit',
233      '#value' => t('Save Settings'),      '#value' => t('Save'),
234    );    );
235    
236    return $form;    return $form;
237  }  }
238    
239    /**
240     * Submit handler for settings form.
241     */
242  function moduleinfo_settings_form_submit($form, &$form_state) {  function moduleinfo_settings_form_submit($form, &$form_state) {
243    foreach ($form_state['values'] AS $name => $value) {    foreach ($form_state['values'] as $name => $value) {
244      if (!strcmp(drupal_substr($name, 0, drupal_strlen('moduleinfo_')), 'moduleinfo_')) {      if (!strcmp(drupal_substr($name, 0, drupal_strlen('moduleinfo_')), 'moduleinfo_')) {
245        variable_set($name, $value);        variable_set($name, $value);
246      }      }
247    }    }
248    drupal_set_message(t("The settings have been saved."));    drupal_set_message(t('The settings have been saved.'));
249  }  }
   

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

  ViewVC Help
Powered by ViewVC 1.1.2