/[drupal]/contributions/modules/accessibility/accessibility_init.php
ViewVC logotype

Contents of /contributions/modules/accessibility/accessibility_init.php

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Jun 21 11:02:04 2007 UTC (2 years, 5 months ago) by jaburns
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
Initial import for Drupal 5
1 <?php
2 // $Id: accessibility_init.php, v2.1 2007/06/21 15:15:00 jaburns Exp $
3 /**
4 * @file: accessibility_init.php
5 * @author: Jamie Burns
6 * Make your Drupal site accessibile from any device
7 * For drupal version >= 4.7 AND 5.1x
8 * So long and confusing, it deserved its own file
9 */
10
11 function accessibility_init() {
12
13 global $mime, $accessibility, $user, $conf, $fix;
14 $leave = array ('cron.php', 'update.php', 'install.php', 'upgrade.php', 'update.php');
15
16 $accessibility['is_mobi'] = (defined('IS_MOBI')) ? IS_MOBI : is_mobi();
17 $accessibility['content_type'] = (defined('CONTENT_TYPE')) ? CONTENT_TYPE : content_type();
18 $accessibility['head'] = 'Content-Type: '. $mime['content'][0] .'; charset=utf-8';
19 $accessibility['meta'] = "\n".'<meta http-equiv="Content-Type" content="'. $mime['content'][0] .'; charset=utf-8" />'."\n";
20 $accessibility['paged'] = FALSE;
21 $content_type = $accessibility['content_type'];
22 $fix = FALSE;
23
24 if ( defined('IS_MOBI') AND IS_MOBI == TRUE ) { // Site wide override settings
25
26 //~ Variables, perhaps override above
27 $accessibility['condition'] = 'mobile site override';
28 $accessibility['paged'] = TRUE;
29 $fix = TRUE;
30 $conf['theme_custom'] = ( $content_type != $mime['wml'] ) ? $mime['theme'][$mime['mhtml']] : $mime['theme'][$content_type];
31 $conf['theme_default'] = ( $content_type != $mime['wml'] ) ? $mime['theme'][$mime['mhtml']] : $mime['theme'][$content_type];
32 $conf['default_nodes_main'] = $mime['nodes'];
33 $conf['site_footer'] = $conf['site_name'] .' '. date('Y');
34 //~ Set HTTP headers and html_headers if required
35 drupal_set_header('Vary: Accept');
36 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .'; charset=utf-8');
37 drupal_set_header("Expires: " . date("D, d M Y H:i:s", time() + 60 * 60 * 24 * 30) . " GMT");
38 drupal_set_header("Cache-Control: Public");
39 drupal_set_html_head("\n".'<meta http-equiv="Content-Type" content="'. $mime['content'][$content_type] .'; charset=utf-8" />'."\n");
40 //~ Fix Code for mobiles
41 if ( !in_array($content_type, $mime['xml']) ) {
42 ob_start('htmlfix');
43 } elseif ( in_array($content_type, $mime['xml']) AND $content_type != $mime['wml'] ) {
44 ob_start('mobifix');
45 } elseif ( $content_type == $mime['wml'] ) {
46 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .', true');
47 ob_start('wmlfix');
48 } //~ end xxxfix
49 mobi_user();
50
51 } else { // No override, just detect if required
52
53 if ( variable_get('accessibility_enabled', 0) == 1 ) { //~ module is enabled
54
55 $fix = variable_get('accessibility_fixhtml', 0);
56 drupal_set_header('Vary: Accept');
57
58 if ( accessibility_check() == TRUE OR in_array(basename($_SERVER['PHP_SELF']),$leave) ){ //~ protected page
59 $accessibility['condition'] = 'protected page';
60
61 if ( $user->uid == 1 OR $accessibility['is_mobi'] == FALSE ) { //~ admin or web browser
62
63 $content_type = 0;
64 $accessibility['content_type'] = $content_type;
65 $conf['theme_custom'] = $mime['theme'][$content_type];
66
67 drupal_set_header($accessibility['head']);
68 drupal_set_html_head($accessibility['meta']);
69
70 } else { //~ block content from mobiles
71
72 $accessibility['condition'] = 'protected from mobiles';
73
74 if ( $content_type != $mime['wml'] ) {
75 $conf['theme_custom'] = $mime['theme'][$mime['mhtml']];
76 $conf['theme_default'] = $mime['theme'][$mime['mhtml']];
77 } else {
78 $conf['theme_custom'] = $mime['theme'][$content_type];
79 $conf['theme_default'] = $mime['theme'][$content_type];
80 }
81 $conf['site_footer'] = $conf['site_name'] .' '. date('Y');
82
83 drupal_set_header('HTTP/1.0 403 Forbidden');
84 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .'; charset=utf-8');
85 drupal_set_html_head("\n".'<meta http-equiv="Content-Type" content="'. $mime['content'][$content_type] .'; charset=utf-8" />'."\n");
86 mobi_user();
87
88 if ( $content_type == $mime['wml'] ) {
89 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .', true');
90 ob_start('wmlfix');
91 }
92
93 $title = '<h1>'. t('Forbidden') .'</h1>';
94 $return = '<p class="error">'.
95 t('This service is currently unavailable to your device.<br />
96 Please use a real web browser.') .'</p>';
97 print theme('page', $title ."\n". $return);
98 exit();
99
100 }
101
102 } elseif ( variable_get('accessibility_override', 0) != 0 AND $user->uid == 1) { //~ change type of pages
103 $accessibility['condition'] = 'change type of pages for admin';
104 $content_type = variable_get('accessibility_override', 0);
105 $accessibility['content_type'] = $content_type;
106 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .'; charset=utf-8');
107 drupal_set_html_head("\n".'<meta http-equiv="Content-Type" content="'. $mime['content'][$content_type] .'; charset=utf-8" />'."\n");
108
109 if ( in_array($content_type, $mime['mobis']) ) { //~ pretending to be a mobile
110 $accessibility['paged'] = variable_get('accessibility_paged', 0);
111 $accessibility['is_mobi'] = TRUE;
112 if ( $content_type != $mime['wml'] ) {
113 $conf['theme_custom'] = $mime['theme'][$mime['mhtml']];
114 $conf['theme_default'] = $mime['theme'][$mime['mhtml']];
115 } else {
116 $conf['theme_custom'] = $mime['theme'][$content_type];
117 $conf['theme_default'] = $mime['theme'][$content_type];
118 }
119 $conf['default_nodes_main'] = $mime['nodes'];
120 $conf['site_footer'] = $conf['site_name'] .' '. date('Y');
121
122 #die($conf['default_nodes_main'] .' '. $conf['theme_default']);
123 if ($content_type == $mime['chtml']) {
124 ob_start('htmlfix');
125 } elseif ( in_array($content_type, $mime['xml']) AND $content_type != $mime['wml'] ) {
126 ob_start('mobifix');
127 } elseif ( $content_type == $mime['wml'] ) {
128 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .', true');
129 ob_start('wmlfix');
130 } //~ end xxxfix
131
132 }
133
134 } elseif ( variable_get('accessibility_change_type', 0) != 0 ) { //~ stop pages breaking
135 $accessibility['condition'] = 'stop pages breaking';
136 $content_type = 0;
137 $accessibility['content_type'] = $content_type;
138 drupal_set_header($accessibility['head']);
139 drupal_set_html_head($accessibility['meta']);
140
141 if ( $accessibility['is_mobi'] == TRUE OR is_mobi_role () == TRUE ) {
142 $accessibility['paged'] = variable_get('accessibility_paged', 0);
143 if ( $content_type != $mime['wml'] ) {
144 $conf['theme_custom'] = $mime['theme'][$mime['mhtml']];
145 $conf['theme_default'] = $mime['theme'][$mime['mhtml']];
146 } else {
147 $conf['theme_custom'] = $mime['theme'][$content_type];
148 $conf['theme_default'] = $mime['theme'][$content_type];
149 }
150 $conf['default_nodes_main'] = $mime['nodes'];
151 $conf['site_footer'] = $conf['site_name'] .' '. date('Y');
152
153 if ($content_type == $mime['chtml']) {
154 ob_start('htmlfix');
155 } elseif ( in_array($content_type, $mime['xml']) AND $content_type != $mime['wml'] ) {
156 ob_start('mobifix');
157 } elseif ( $content_type == $mime['wml'] ) {
158 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .', true');
159 ob_start('wmlfix');
160 } //~ end xxxfix
161 mobi_user();
162 }
163
164 } else { //~ detect
165 $accessibility['condition'] = 'detect';
166 $content_type = $accessibility['content_type'];
167 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .'; charset=utf-8');
168 drupal_set_html_head("\n".'<meta http-equiv="Content-Type" content="'. $mime['content'][$content_type] .'; charset=utf-8" />'."\n");
169
170 if ( $accessibility['is_mobi'] == TRUE OR is_mobi_role () == TRUE ) { //~ pretending to be a mobile
171 $accessibility['paged'] = variable_get('accessibility_paged', 0);
172 drupal_set_header("Expires: " . date("D, d M Y H:i:s", time() + 60 * 60 * 24 * 30) . " GMT");
173 drupal_set_header("Cache-Control: Public");
174
175 if ( $content_type != $mime['wml'] ) {
176 $conf['theme_custom'] = $mime['theme'][$mime['mhtml']];
177 $conf['theme_default'] = $mime['theme'][$mime['mhtml']];
178 } else {
179 $conf['theme_custom'] = $mime['theme'][$content_type];
180 $conf['theme_default'] = $mime['theme'][$content_type];
181 }
182
183 $conf['default_nodes_main'] = $mime['nodes'];
184 $conf['site_footer'] = $conf['site_name'] .' '. date('Y');
185
186
187 if ($content_type == $mime['chtml']) {
188 ob_start('htmlfix');
189 } elseif ( in_array($content_type, $mime['xml']) AND $content_type != $mime['wml'] ) {
190 ob_start('mobifix');
191 } elseif ( is_mobi_role () == TRUE ) {
192 ob_start('mobifix');
193 } elseif ( $content_type == $mime['wml'] ) {
194 drupal_set_header('Content-Type: '. $mime['content'][$content_type] .', true');
195 ob_start('wmlfix');
196 } //~ end xxxfix
197 mobi_user();
198 }
199
200 }
201
202 //~ set default theme
203 if ( variable_get('accessibility_theme', 0) != 0 ) { //~ user default "web" theme
204 if ( $accessibility['is_mobi'] == FALSE ) {
205 $conf['theme_default'] = $mime['theme'][0];
206 }
207 }
208
209 } else { // disabled
210
211 $content_type = 0;
212 $accessibility['content_type'] = $content_type;
213 $accessibility['condition'] = 'module is not active, send as text/html';
214 drupal_set_header($accessibility['head']);
215 drupal_set_html_head($accessibility['meta']);
216
217 } // end enabled? condition
218
219 } // end override condition
220
221 } // end function

  ViewVC Help
Powered by ViewVC 1.1.2