Mercurial > hg > MPIWG-drupal-modules
comparison sites/all/modules/custom/solrext/solrext.module @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:015d06b10d37 |
---|---|
1 <?php | |
2 /** | |
3 * @file | |
4 * Helps site builders and module developers investigate a site. | |
5 */ | |
6 /** | |
7 * Implements hook_form_alter() to show each form's identifier. | |
8 */ | |
9 function solrext_form_alter(&$form, &$form_state, $form_id) { | |
10 $form['solrext_display_form_id'] = array( | |
11 '#type' => 'item', | |
12 '#title' => t('Form ID'), | |
13 '#markup' => $form_id, | |
14 '#theme_wrappers' => array('container__solrext__form'), | |
15 '#attributes' => array('class' => array('solrext')), | |
16 '#weight' => -100, | |
17 ); | |
18 //debug($form, $form_id, TRUE); | |
19 } | |
20 | |
21 | |
22 /** | |
23 * Implements hook_help(). | |
24 */ | |
25 function solrext_help($path, $arg) { | |
26 switch ($path) { | |
27 case 'admin/structure/block': | |
28 return t('This site has stuff!'); | |
29 case 'admin/appearance':{ | |
30 return _solrext_help_admin_appearance(); | |
31 }} | |
32 } | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 /** | |
39 * Help text for the admin/appearance page. | |
40 */ | |
41 function _solrext_help_admin_appearance() { | |
42 $output = ''; | |
43 $data = solrext_stats_enabled_themes(); | |
44 $output .= format_plural( | |
45 $data['num_hidden'], | |
46 'There is one hidden theme.', | |
47 'There are @count hidden themes.' | |
48 ); | |
49 return theme('solrext_help', array('text' => $output)); | |
50 } | |
51 | |
52 /** | |
53 * Implements hook_menu(). | |
54 */ | |
55 function solrext_menu() { | |
56 $items['admin/reports/solrtext'] = array( | |
57 'title' => 'X-ray technical site overview', | |
58 'description' => 'See the internal structure of this site.', | |
59 'page callback' => 'solrtext_overview_page', | |
60 'access callback' => TRUE, | |
61 'access arguments' => array('access site reports'), | |
62 ); | |
63 | |
64 $items['admin/reports/solrtext/overview'] = array( | |
65 'title' => 'Overview', | |
66 'description' => "Technical overview of the site's internals.", | |
67 'type' => MENU_DEFAULT_LOCAL_TASK, | |
68 'weight' => -10, | |
69 ); | |
70 | |
71 $items['admin/reports/solrtext/overview2'] = array( | |
72 'title' => 'Overview2', | |
73 'description' => "Technical overview of the site's internals.", | |
74 'type' => MENU_LOCAL_TASK, | |
75 'weight' => -1, | |
76 'page callback' => 'solrext_permission_names_page', | |
77 'access arguments' => array('access site reports'), | |
78 ); | |
79 | |
80 | |
81 return $items; | |
82 } | |
83 | |
84 | |
85 function solrtext_overview_page(){ | |
86 return "XX"; | |
87 } | |
88 | |
89 | |
90 | |
91 /** | |
92 * Display the X-ray permission names page. | |
93 */ | |
94 function solrext_permission_names_page_OLD() { | |
95 | |
96 $names = solrext_permission_names(); | |
97 //debug($names); | |
98 return theme('solrext_permission_names', array('names' => $names)); | |
99 } | |
100 /** | |
101 * Collect permission names. | |
102 */ | |
103 function solrext_permission_names() { | |
104 | |
105 $names = array(); | |
106 $permissions = module_invoke_all('permission'); | |
107 // Extract just the permission title from each permission array. | |
108 | |
109 foreach ($permissions as $machine_name => $permission) { | |
110 $names[$machine_name] = $permission['title']; | |
111 } | |
112 // Put permission names in alphabetical order by title. | |
113 asort($names); | |
114 | |
115 return $names; | |
116 } | |
117 /** | |
118 * Returns HTML of permission machine and display names in a table. | |
119 * | |
120 * @param $variables | |
121 * An associative array containing: | |
122 * - names: Array of human-readable names keyed by machine names. | |
123 * | |
124 * @ingroup themeable | |
125 */ | |
126 function theme_solrext_permission_names($variables) { | |
127 $names = $variables['names']; | |
128 $output = ''; | |
129 $header = array(t('Permission title'), t('Permission machine name')); | |
130 $rows = array(); | |
131 foreach ($names as $machine_name => $title) { | |
132 $rows[] = array($title, $machine_name); | |
133 } | |
134 $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => | |
135 array('id' => 'solrext-permission-names'))); | |
136 return $output; | |
137 | |
138 | |
139 | |
140 /** | |
141 * Fetch information about themes. | |
142 */ | |
143 function solrext_stats_enabled_themes() { | |
144 $themes = list_themes(); | |
145 $num_themes = count($themes); | |
146 // Initialize variables for the data you will collect. | |
147 $num_hidden = 0; // Number of hidden themes. | |
148 $num_enabled = 0; | |
149 $summaries = array(); | |
150 // Iterate through each theme, gathering data that you care about. | |
151 foreach ($themes as $themename => $theme) { | |
152 // Do not gather statistics for hidden themes, but keep a count of them. | |
153 if (isset($theme->info['hidden']) && $theme->info['hidden']) { | |
154 $num_hidden++; | |
155 } | |
156 else { // This is a visible theme. | |
157 if ($theme->status) { | |
158 $num_enabled++; | |
159 // This is an enabled theme, provide more stats. | |
160 $summaries[$theme->info['name']] = array( | |
161 'regions' => count($theme->info['regions']), | |
162 'overlay_regions' => count($theme->info['overlay_regions']), | |
163 'regions_hidden' => count($theme->info['regions_hidden']), | |
164 'features' => count($theme->info['features']), | |
165 'kindsofstylesheets' => count($theme->info['stylesheets']), | |
166 'allstylesheets' => isset($theme->info['stylesheets']['all']) ? count($theme->info['stylesheets']['all']) : 0, | |
167 ); | |
168 } | |
169 } | |
170 } | |
171 return compact('num_themes', 'num_hidden', 'num_enabled', 'summaries'); | |
172 } | |
173 } | |
174 | |
175 | |
176 /** | |
177 * Implements hook_theme(). | |
178 */ | |
179 function solrext_theme() { | |
180 | |
181 return array( | |
182 'solrext_permission_names' => array( | |
183 'render element' => 'names', | |
184 ), | |
185 'solrext_show_page_callback' => array( | |
186 'variables' => array( | |
187 'page_callback' => NULL, | |
188 'include_file' => NULL, | |
189 'page_arguments' => NULL, | |
190 ), | |
191 ), | |
192 ); | |
193 } | |
194 | |
195 | |
196 /** | |
197 * Display permission machine and display names in a table. | |
198 * | |
199 * @return | |
200 * An array as expected by drupal_render(). | |
201 */ | |
202 function solrext_permission_names_page() { | |
203 $build = array(); | |
204 // Gather data, an array of human-readable names keyed by machine names. | |
205 $names = solrext_permission_names(); | |
206 // Format the data as a table. | |
207 $header = array(t('Permission title'), t('Permission machine name')); | |
208 $rows = array(); | |
209 foreach ($names as $machine_name => $title) { | |
210 $rows[] = array($title, $machine_name); | |
211 } | |
212 $build['names_table'] = array( | |
213 '#theme' => 'table__solrext__permission_names', | |
214 '#header' => $header, | |
215 '#rows' => $rows, | |
216 '#attributes' => array('id' => 'solrext-permission-names') | |
217 ); | |
218 return $build; | |
219 } | |
220 | |
221 | |
222 /** | |
223 * Provide the page callback function (and other router item information). | |
224 */ | |
225 function solrext_show_page_callback() { | |
226 debug("XX"); | |
227 // Do not hand in the path; menu_get_item() finds dynamic paths on its own | |
228 // but fails if handed help's $path variable which is node/% for node/1. | |
229 $router_item = menu_get_item(); | |
230 // menu_get_item() can return null when called via drush command line. | |
231 if ($router_item) { | |
232 return theme('solrext_show_page_callback', $router_item); | |
233 } | |
234 } | |
235 /** | |
236 * Theme the page callback and optionally other elements of a router item. | |
237 */ | |
238 function theme_solrext_show_page_callback($variables) { | |
239 extract($variables, EXTR_SKIP); | |
240 $output = ''; | |
241 $output .= '<p class="solrext-help solrext-page-callback">'; | |
242 $output .= t('This page is brought to you by '); | |
243 if ($page_arguments) { | |
244 foreach ($page_arguments as $key => $value) { | |
245 $page_arguments[$key] = drupal_placeholder($value); | |
246 } | |
247 $output .= format_plural(count($page_arguments), | |
248 'the argument !arg handed to ', | |
249 'the arguments !arg handed to ', | |
250 array('!arg' => solrext_oxford_comma_list($page_arguments)) | |
251 ); | |
252 } | |
253 $output .= t('the function %func', | |
254 array('%func' => $page_callback . '()')); | |
255 if ($include_file) { | |
256 $output .= t(' and the included file %file', | |
257 array('%file' => $include_file)); | |
258 } | |
259 $output .= '.</p>'; | |
260 return $output; | |
261 } |