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

Contents of /contributions/modules/enabled_modules/enabled_modules.module

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


Revision 1.1 - (show annotations) (download) (as text)
Wed Apr 9 17:18:43 2008 UTC (19 months, 2 weeks ago) by agaric
Branch: MAIN
CVS Tags: DRUPAL-5--0-1-ALPHA, HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
Second attempt at initial commit
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * TODO: Enter file description here.
7 */
8
9 /**
10 * Implementation of hook_block().
11 */
12 function enabled_modules_block($op = 'list', $delta = 0, $edit = array()) {
13 if ($op == 'list') {
14 $blocks['recently_enabled']['info'] = t('Recently enabled modules with administration links.');
15 $blocks['recently_disabled']['info'] = t('Recently disabled modules.');
16 return $blocks;
17 }
18 else if ($op == 'configure') {
19 // OPTIONAL: Enter form elements to add to block configuration screen, if required.
20 }
21 else if ($op == 'save') {
22 // OPTIONAL: Add code to trigger when block configuration is saved, if required.
23 }
24 else if ($op == 'view') {
25 switch ($delta) {
26 case 'recently_enabled':
27 $block['subject'] = t('Recently enabled modules');
28 $block['content'] = t('TODO: Enter block content');
29 break;
30 case 'recently_disabled':
31 $block['subject'] = t('Recently disabled modules');
32 $block['content'] = t('TODO: Enter block content');
33 break;
34 }
35 return $block;
36 }
37 }
38
39
40 /**
41 * Implementation of hook_help().
42 */
43 function enabled_modules_help($path) {
44 switch ($section) {
45 case 'admin/help#enabled_modules':
46 return t('Provides a page showing all enabled modules, including modules missing from the file system, and blocks showing recently enabled and recently disabled modules.');
47 case 'admin/modules#description':
48 return t('Show enabled, missing, and recently toggled modules.');
49 // OPTIONAL: Add additional cases for other paths that should display help text.
50 }
51 }
52
53
54 /**
55 * Implementation of hook_perm().
56 */
57 function enabled_modules_perm() {
58 return array('view enabled modules');
59 }
60
61
62 /**
63 * Implementation of hook_menu().
64 */
65 function enabled_modules_menu($may_cache) {
66 $items = array();
67
68 if ($may_cache) {
69 $items[] = array(
70 'path' => 'enabled_modules',
71 'title' => t('Enabled modules'),
72 'access' => user_access('view enabled modules'),
73 'callback' => 'enabled_modules_list',
74 'type' => MENU_NORMAL_ITEM,
75 );
76 // OPTIONAL: Fill in additional static menu items
77 }
78 // OPTIONAL: Put in else statement for dynamic menu items that can't be cached.
79
80 return $items;
81 }
82
83
84 /**
85 * Implementation of hook_watchdog().
86 */
87 function enabled_modules_watchdog($log_msg) {
88
89 }
90
91
92 // Helper functions
93
94 /**
95 *
96 */
97 function enabled_modules_list() {
98 $modules = enabled_modules_fetch_enabled();
99 return theme('enabled_modules_list', $modules);
100 }
101
102 /**
103 * List all enabled modules.
104 *
105 * @return
106 * An array of system table objects of type module and status 1.
107 */
108 function enabled_modules_fetch_enabled() {
109 static $modules = array();
110 if (!isset($modules) || empty($modules)) {
111 // @TODO maybe implement our own cache, flushed each time module page saved
112 $result = db_query("SELECT filename, name, description, throttle, bootstrap, schema_version FROM {system} WHERE type = 'module' AND status = '1' ORDER BY name");
113 while ($module = db_fetch_object($result)) {
114 if (file_exists($module->filename)) {
115 $module->exists = 'present';
116 $module->tasks = enabled_modules_module_admin_tasks($module->name);
117 }
118 else {
119 $module->exists = 'missing';
120 $module->tasks = '';
121 }
122 $modules[] = $module;
123 }
124 }
125 return $modules;
126 }
127
128 /**
129 * adapted from http://api.drupal.org/api/function/system_admin_by_module/5
130 */
131 function enabled_modules_module_admin_tasks($module) {
132 $admin_tasks = system_get_module_admin_tasks($module);
133
134 // Check for help links.
135 if (module_invoke($module, 'help', "admin/help#$module")) {
136 $admin_tasks[100] = l(t('Get help'), "admin/help/$module");
137 }
138
139 // Only display a section if there are any available tasks.
140 if (count($admin_tasks)) {
141 // Sort.
142 ksort($admin_tasks);
143 return $admin_tasks;
144 }
145 else {
146 return array();
147 }
148 }
149
150
151 function theme_enabled_modules_module_admin_tasks($admin_tasks = array()) {
152 // Output links
153 if (count($admin_tasks)) {
154 return theme('item_list', $admin_tasks);
155 }
156 else {
157 return theme('item_list', array(t('No tasks')));
158 }
159 }
160
161
162 function theme_enabled_modules_list($modules) {
163 $output = '';
164 // @TODO - for table sorting to work, the table must be built directly with SQL
165 // it will not sort data in an array. We may need our own table anyway, so
166 // we can track when modules are enabled and disabled, so could redo that way.
167 $header = array(
168 array(
169 'data' => t('Name'),
170
171 ),
172 array(
173 'data' => t('Description'),
174 ),
175 array(
176 'data' => t('Installed'),
177 ),
178 );
179 if (user_access('administer site configuration')) {
180 $header[] = array('data' => t('Administer'));
181 }
182
183 $rows = array();
184 foreach ($modules as $module) {
185 $row = array();
186 $row[] = array(
187 'class' => 'enabled-module-name',
188 'data' => $module->name,
189 );
190 $row[] = array(
191 'class' => 'enabled-module-description',
192 'data' => $module->description,
193 );
194 $row[] = array(
195 'class' => 'enabled-module-installed',
196 'data' => $module->exists,
197 );
198 if (user_access('administer site configuration')) {
199 $row[] = array(
200 'class' => 'enabled-module-administer',
201 'data' => theme('enabled_modules_module_admin_tasks', $module->tasks),
202 );
203 }
204 $rows[] = $row;
205 }
206
207 $output .= theme('table', $header, $rows, array('class' => 'enabled-modules-list'));
208
209 return $output;
210 }

  ViewVC Help
Powered by ViewVC 1.1.2