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

Contents of /contributions/modules/moduleinfo/moduleinfo.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Sep 5 19:08:44 2008 UTC (14 months, 2 weeks ago) by jabapyth
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial commit of ModuleInfo--a module that gives information about installed modules
1 <?php
2 /****
3 an implementation of hook_form_alter.
4 This hook gets the module specific data (from moduleinfo_get_info)
5 for each module and inserts it into the system_modules form
6 which is displayed on the pages admin/build/modules and admin/build/modules/list
7 ****/
8 function moduleinfo_form_alter($form, $form_state, $form_id){
9 $files = module_rebuild_cache();
10 if ($form_id=="system_modules"){
11 foreach($form["description"] as $module=>$description){
12 if ($files[$module]->status=="0")continue;
13
14 $info = moduleinfo_get_info($module);
15 if (!$info)continue;
16
17 $fieldset = array(
18 '#title' => t('ModuleInfo'),
19 '#collapsible' => TRUE,
20 '#collapsed' => TRUE,
21 '#value' => $info,
22 );
23 $form["description"][$module]['#value'] .= theme('fieldset', $fieldset);;
24 }
25 }
26 }
27 /****
28 an implementation of hook_help
29 ****/
30 function moduleinfo_help($section='') {
31 switch ($section) {
32 case "admin/help#moduleinfo":
33 return t("ModuleInfo informs the admin about changes a module makes to the interface.");
34 }
35 return '';
36
37 }
38
39 /*** possible new hook?
40 returns associative array:
41 $info["created"]["pages"] = path => array(name=> description=>)
42 $info["created"]["blocks"] = i => array(name=> description=>)
43 $info["created"]["content-types"] = name => description
44 $info["effected"]....[mirrors created]
45
46 function moduleinfo_moduleinfo(){
47 $info = array();
48 $info["pages"]["effected"]['admin/build/modules/list'] = "Adds module-specific information to each module description.";
49 $info["pages"]["created"]['page_name'] = 'page description';
50 $info["content-types"]["created"]['name'] = 'content-type description';
51 $info['blocks']['created'][] = 'block description';
52 return $info;
53 }
54 ***/
55
56 /*** collects all the information we can find about a module from various hooks ***/
57 function moduleinfo_get_info($module){
58 $output = '';
59 $help = moduleinfo_get_help($module);
60 if ($help){
61 $output.= '<strong>'.t('Help').'</strong>';
62 $output.= '<ul>'.join('',$help).'</ul>';
63 }
64 $pages = moduleinfo_get_pages($module);
65 if (isset($pages["config"])){
66 $output.= '<strong>'.t('Configuration').'</strong>';
67 $output.= '<ul>'.join('',$pages["config"]).'</ul>';
68 }
69 if (isset($pages["other"])){
70 $output.= '<strong>'.t('Pages').'</strong>';
71 $output.= '<ul>'.join('',$pages["other"]).'</ul>';
72 }
73 $blocks = moduleinfo_get_blocks($module);
74 if ($blocks){
75 $output.= '<strong>'.t('Blocks').'</strong>';
76 $output.= '<ul>'.join('',$blocks).'</ul>';
77 }
78 $cts = moduleinfo_get_content_types($module);
79 if ($cts){
80 $output.= '<strong>'.t('Content Types').'</strong>';
81 $output.= '<ul>'.join('',$cts).'</ul>';
82 }
83 return $output;
84 }
85
86 /*** check for help ***/
87 function moduleinfo_get_help($module){
88 if (module_hook($module,"help")){
89 $res = module_invoke($module,"help","admin/help#".$module,arg());
90 if ($res)
91 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>");
92 }
93 return array();
94 }
95
96 /*** check for pages, both config and other ***/
97 /** todo -- display w/ submenu structure **/
98 function moduleinfo_get_pages($module,$cached=TRUE){
99 $pages = array();
100 if (module_hook($module,"menu")){
101 $menus = module_invoke($module, "menu", $cached);
102 if ($menus){
103 foreach ($menus as $path=>$menu){
104 if ($menu["type"]!=MENU_CALLBACK){ /** menu_callbacks wont appear in menus **/
105 $full = moduleinfo_get_breadcrumb($path);
106 $txt="<li>".l(moduleinfo_get_menu_name($path),$path).'<sub>'.t(" ($full)")."</sub></li>\n";
107 if (strpos($path,"admin/settings")!==FALSE)
108 $pages["config"][] = '<li>'.l(moduleinfo_get_menu_name($path),$path).'</li>';
109 else
110 $pages["other"][] = $txt;
111 }
112 }
113 }
114 }
115 return $pages;
116 }
117
118 /*** check for block ***/
119 function moduleinfo_get_blocks($module){
120 /*** check for blocks ***/
121 $blocks = array();
122 if (module_hook($module, "block")){
123 $mblocks = module_invoke($module,"block","list");
124 if ($mblocks){
125 foreach($mblocks as $i=>$block){
126 $blocks[] ="<li>".l($block["info"],"admin/build/block/configure/".$module."/".$i)."</li>\n";
127 }
128 }
129 }
130 return $blocks;
131 }
132
133 /*** check for custom content-types ***/
134 function moduleinfo_get_content_types($module){
135 $content_types = array();
136 if (module_hook($module, "node_info")){
137 $nodes = module_invoke($module,"node_info");
138 if ($nodes){
139 foreach ($nodes as $name=>$node){
140 $content_types[] = "<li>".l($node["name"],"admin/content/types/".$name).": ".$node["description"]."</li>\n";
141 }
142 }
143 }
144 return $content_types;
145 }
146
147 /*** grab a module name from the database ***/
148 function moduleinfo_get_menu_name($path){
149 $result = db_query("SELECT link_title FROM {menu_links} WHERE link_path = '%s'",array($path));
150 $res = db_fetch_object($result)->link_title;
151 if (!$res){
152 $res = array_slice(explode("/",$path),-1);
153 $res = ucwords($res[0]);
154 }
155 return $res;
156 }
157
158 /*** generate a breadcrumb-style string from a menu path ***/
159 function moduleinfo_get_breadcrumb($path){
160 $parts = explode("/",$path);
161 $current = "";
162 $breadcrumb = "";
163 foreach($parts as $part){
164 if ($breadcrumb!="")$breadcrumb.="&raquo;";
165 if ($current!="")$current.="/";
166 $current .= $part;
167 $breadcrumb .= moduleinfo_get_menu_name($current);
168 }
169 return $breadcrumb;
170 }

  ViewVC Help
Powered by ViewVC 1.1.2