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

Contents of /contributions/modules/accessibility/accessibility.module

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


Revision 1.4 - (show annotations) (download) (as text)
Wed Mar 5 23:21:00 2008 UTC (20 months, 3 weeks ago) by jaburns
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.3: +4 -15 lines
File MIME type: text/x-php
Rollback, last change seemed to mess up headers.
1 <?php
2 // $Id: accessibility.module,v 1.1 2007/06/21 11:02:04 jaburns Exp $
3 /**
4 * @file
5 * accessibility.module
6 *
7 * Depends on:
8 * 'browser.inc' -> list of know handheld devices and
9 * 'accessibility.php' -> detection script
10 * 'accessibility_init.php' -> accessibility_init()
11 * 'accessibility_help.inc' -> help file
12 *
13 * Themes required ($mime['theme']):
14 * web, mobi, wap
15 *
16 * Changes required to 'includes/common.inc' lines 116 and 1839
17 * See documentation for more information
18 *
19 * @author Jamie Burns <http://www.skiffie.com/>
20 * @link http://www.skiffie.com/
21 */
22
23 /**
24 * Get the device detection script
25 */
26 if ( function_exists('drupal_get_path') ) {
27 include_once drupal_get_path('module', 'accessibility') . '/accessibility.php';
28 } else {
29 include_once dirname(__FILE__) . '/accessibility.php';
30 }
31
32 function accessibility_override() {
33 global $mime;
34 foreach ($mime['desc'] as $key => $val) {
35 $accept[$key] = trim($val);
36 }
37 return $accept;
38 }
39
40 /**
41 * Helps links.
42 */
43
44 function accessibility_help($section='') {
45 $output = '';
46 switch ($section) {
47 case "admin/modules#description":
48 $output = t("Make your site accessible from any device");
49 break;
50 case 'admin/settings/accessibility#pages':
51 $output = 'admin*
52 *edit*
53 imce*';
54 break;
55 case 'admin/help#accessibility':
56 include_once drupal_get_path('module', 'accessibility') . '/accessibility_help.inc';
57 }
58 return $output;
59 }
60
61 /**
62 * Implementation of hook_menu().
63 */
64 function accessibility_menu($may_cache) {
65 $items = array();
66
67 $items[] = array(
68 'path' => 'admin/settings/accessibility',
69 'title' => t('Accessibility'),
70 'description' => t('Settings for the accessibility module'),
71 'callback' => 'drupal_get_form',
72 'callback arguments' => 'accessibility_admin_settings',
73 'access' => user_access('administer site configuration'),
74 'type' => MENU_NORMAL_ITEM,
75 );
76 return $items;
77 }
78
79 /**
80 * Implementation of hook_settings().
81 *
82 * @return array
83 */
84 function accessibility_admin_settings() {
85 $form['accessibility'] = array(
86 '#type' => 'fieldset',
87 '#title' => t("Make your site accessible from any device"),
88 '#tree' => FALSE,
89 '#description' => t('Allows limited accessibility from any device. ') .
90 l('Help', 'admin/help/accessibility') .'.'
91 );
92 $form['accessibility']['accessibility_enabled'] = array(
93 '#type'=>'checkbox',
94 '#title'=>t('Enable Accessibility'),
95 '#default_value'=>variable_get('accessibility_enabled', 0),
96 '#description' => t("Enable this module.")
97 );
98
99 $form['accessibility']['or'] = array(
100 '#type' => 'fieldset', '#title' => t('Override Pages'),
101 '#collapsible' => TRUE, '#collapsed' =>
102 (variable_get('accessibility_enabled', 0) == 1 ? FALSE : TRUE)
103 );
104
105 $form['accessibility']['or']['accessibility_pages'] = array(
106 '#type' => 'textarea',
107 '#title' => t('Pages'),
108 '#default_value' => variable_get('accessibility_pages',accessibility_help('admin/settings/accessibility#pages')),
109 '#cols' => 30,
110 '#rows' => 5,
111 '#description' => t("List of pages for which the module is <b>disabled</b>.
112 Use the <em>*</em> character for wildcard, each entry in a new line.")
113 );
114
115 $form['accessibility']['os'] = array(
116 '#type' => 'fieldset', '#title' => t('Override Settings'),
117 '#collapsible' => TRUE, '#collapsed' => (variable_get('accessibility_enabled', 0) == 1 ? FALSE : TRUE)
118 );
119
120 $form['accessibility']['os']['accessibility_override'] = array(
121 '#type'=>'select',
122 '#title'=> t('Enable Media Type Override'),
123 '#default_value'=> variable_get('accessibility_override', 0),
124 '#options' => accessibility_override(),
125 '#description' => t("You can override detection here. For testing only (user 1).")
126 );
127
128 $form['accessibility']['os']['accessibility_change_type'] = array(
129 '#type'=>'checkbox',
130 '#title'=>t('Override xHTML mime type'),
131 '#default_value'=> variable_get('accessibility_change_type', 0),
132 '#description' => t("If pages break sending content as application/xhtml+xml, enable this.")
133 );
134
135 $form['accessibility']['os']['accessibility_fixhtml'] = array(
136 '#type'=>'checkbox',
137 '#title'=>t('Try to correct HTML'),
138 '#default_value'=> variable_get('accessibility_fixhtml', 0),
139 '#description' => t("Make code XHTML compliant for mobile devices. Disable if this interferes with other modules.")
140 );
141
142 $form['accessibility']['as'] = array(
143 '#type' => 'fieldset', '#title' => t('Additional Settings'),
144 '#collapsible' => TRUE, '#collapsed' => (variable_get('accessibility_enabled', 0) == 1 ? FALSE : TRUE)
145 );
146
147 $form['accessibility']['as']['accessibility_paging'] = array(
148 '#type'=> 'textfield',
149 '#title'=> t('Choose your page break character for mobile devices'),
150 '#default_value'=> variable_get('accessibility_paging', '<br class="mobi" />'),
151 '#size' => 30, '#maxlength' => 30,
152 '#description' => t("This allows you to break up content into smaller pieces.") .'<br />'.
153 t("Leave empty to not utilize this feature. See help for more.")
154 );
155
156 $form['accessibility']['as']['accessibility_paged'] = array(
157 '#type'=>'checkbox',
158 '#title'=>t('Allow paging'),
159 '#default_value'=> variable_get('accessibility_paged', 0),
160 '#description' => t("Split your pages into smaller pieces for mobiles. Disable if this interferes with other paging modules.")
161 );
162
163 $form['accessibility']['as']['accessibility_theme'] = array(
164 '#type'=>'checkbox',
165 '#title'=>t('Select the default "web" theme'),
166 '#default_value'=>variable_get('accessibility_theme', 0),
167 '#description' => t("Choose whether the default 'web theme' is user or not.")
168 );
169
170 return system_settings_form($form);
171 }
172
173 //~ mobi_user ()
174 function mobi_user () {
175 global $role, $user;
176 if ( $user->uid != 1 ) {
177 //~ Set role for mobile users
178 $sql = db_query("SELECT rid FROM {role} WHERE name='mobi'");
179 if (db_num_rows($sql)){
180 $result = db_result($sql);
181 unset($user->roles);
182 return $user->roles[$result] = 'mobi';
183 }
184 }
185 }
186
187 //~ mobi_user ()
188 function is_mobi_role () {
189 global $user;
190 $sql = db_query("SELECT r.name FROM {role} r INNER JOIN {users_roles} ur ON r.rid = ur.rid WHERE ur.uid=". $user->uid);
191 if (db_num_rows($sql)){
192 $result = db_result($sql);
193 if ($result == 'mobi') {
194 return TRUE;
195 }
196 }
197 }
198
199 include_once drupal_get_path('module', 'accessibility') . '/accessibility_init.php';
200
201 /**
202 * Override formatting of primary and secondary links
203 * Taken from 'mobi_loader.module' by David Kent Norman <http://deekayen.net/>
204 *
205 * @return string
206 */
207 function theme_accessibility_primary_links($links) {
208 $output = '';
209
210 if (count($links) > 0) {
211 $num_links = count($links);
212 $i = 1;
213
214 foreach ($links as $link) {
215 $html = isset($link['html']) && $link['html'];
216
217 $link['query'] = isset($link['query']) ? $link['query'] : NULL;
218 $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;
219
220 if (isset($link['href'])) {
221 $output .= l($link['title'], $link['href'], array_merge($link['attributes'], array('accesskey' => $i)), $link['query'], $link['fragment'], FALSE, $html);
222 }
223 else if ($link['title']) {
224 if (!$html) {
225 $link['title'] = check_plain($link['title']);
226 }
227 $output .= $link['title'];
228 }
229 $output .= ' | ';
230 $i++;
231 }
232 }
233 return empty($output) ? '' : substr($output, 0, -3);
234 }
235
236
237 /**
238 * Based on 'paging.module' that was rewritten and considerably shortened and made more Drupal-friendly
239 * by Earl Miles. Original module written by Marco Scutari
240 *
241 */
242
243 function accessibility_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
244 if (isset($node->field_body[0]['view'])) { // support for CCK
245 _accessibility_nodeapi($node,
246 $node->field_body[0]['view'],
247 $node->field_teaser[0]['view'],
248 $op, $teaser, $page);
249 } elseif (isset($node->field_body[0]['value'])) { // support for CCK
250 _accessibility_nodeapi($node,
251 $node->field_body[0]['value'],
252 $node->field_teaser[0]['value'],
253 $op, $teaser, $page);
254 } else {
255 _accessibility_nodeapi($node, $node->body, $node->teaser, $op, $teaser, $page);
256 }
257 }
258
259 /*
260 * Helper function for accessibility_nodeapi()
261 */
262 function _accessibility_nodeapi(&$node, &$nodebody, &$nodeteaser, $op, $teaser, $page) {
263
264 global $mime, $accessibility;
265
266 $breaker = variable_get('accessibility_paging', '<br class="mobi" />') == ''
267 ? FALSE : variable_get('accessibility_paging', '<br class="mobi" />');
268
269 switch ($op) {
270 case 'load':
271 $node->pages = explode($breaker, $nodebody);
272 $node->pages_count = count($node->pages);
273 break;
274
275 case 'view':
276 $node_type = TRUE;
277 if (!$node->in_preview AND $accessibility['paged'] == TRUE ){
278 $element = 1;
279 if (!$teaser && $node->pages_count > 1 && arg(2) != 'print' && arg(2) != 'full') {
280 global $pager_page_array, $pager_total;
281 $page = isset($_GET['page']) ? $_GET['page'] : '';
282 $pager_page_array = explode(',', $page);
283 $pager_total[$element] = $node->pages_count;
284 $page = isset($pager_page_array[$element]) ? $pager_page_array[$element] : 0;
285 $node->content['body']['#value'] = check_markup($node->pages[$page], $node->format, false);
286 $node->content['body']['#value'] .= theme('pager', NULL, 1, $element);
287 }
288 elseif ($teaser && $node->pages_count > 1 && strlen($node->teaser) > strlen($node->pages[0])) {
289 // check to see if the teaser is longer than our first page.
290 $node->content['body']['#value'] = check_markup($node->pages[0], $node->format, false);
291 $node->pagemore = true;
292 }
293 }
294 break;
295 }
296 }
297
298 /**
299 * Implementation of hook_link().
300 */
301 function accessibility_link($type, $node = NULL, $teaser = FALSE) {
302 $links = array();
303 global $accessibility;
304 if ($type == 'node') {
305 if (array_key_exists('links', $node)) {
306 $links = $node->links;
307 }
308
309 if ($teaser AND $accessibility['paged'] == TRUE) {
310 $links['node_read_more'] = array(
311 'title' => t('[6] More ..'),
312 'href' => drupal_get_path_alias("node/$node->nid"),
313 'attributes' => array('title' => t('Read more'), 'class' => 'read-more-paging', 'accesskey' => 6),
314 'query' => 'page=0,1'
315 );
316 }
317 }
318
319 return $links;
320 }
321
322 /**
323 * Check the pages that are not required to be changed
324 *
325 */
326 function accessibility_check() {
327 $pages = variable_get('accessibility_pages', accessibility_help('admin/settings/accessibility#pages'));
328 $path = drupal_get_path_alias($_GET['q']);
329 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/';
330 return preg_match($regexp, $path);
331 }
332
333 /**
334 * Implementation of hook_uninstall().
335 */
336 function accessibility_uninstall() {
337 variable_del('accessibility');
338 watchdog("Accessibility","Accessibility module removed.");
339 $accessibility_install = @file_get_contents('http://www.skiffie.com/go/installation/v5/uninstall');
340 }

  ViewVC Help
Powered by ViewVC 1.1.2