Index: trunk/extensions/PatchOutputMobile/DeviceDetection.php |
— | — | @@ -0,0 +1,372 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Extension PatchOutputMobile — Device Detection |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Patrick Reilly |
| 9 | + * @copyright © 2011 Patrick Reilly |
| 10 | + * @licence GNU General Public Licence 2.0 or later |
| 11 | + */ |
| 12 | + |
| 13 | +// Provides an abstraction for a device |
| 14 | +// A device can select which format a request should recieve and |
| 15 | +// may be extended to provide access to particular devices functionality |
| 16 | +class DeviceDetection { |
| 17 | + |
| 18 | + public function availableFormats() { |
| 19 | + $formats = array ( |
| 20 | + 'html' => |
| 21 | + array ( |
| 22 | + 'view_format' => 'html', |
| 23 | + 'search_bar' => 'default', |
| 24 | + 'footmenu' => 'default', |
| 25 | + 'with_layout' => 'application', |
| 26 | + 'css_file_name' => 'default', |
| 27 | + 'supports_javascript' => false, |
| 28 | + 'disable_zoom' => true, |
| 29 | + 'parser' => 'html', |
| 30 | + 'disable_links' => true, |
| 31 | + ), |
| 32 | + 'capable' => |
| 33 | + array ( |
| 34 | + 'view_format' => 'html', |
| 35 | + 'search_bar' => 'default', |
| 36 | + 'footmenu' => 'default', |
| 37 | + 'with_layout' => 'application', |
| 38 | + 'css_file_name' => 'default', |
| 39 | + 'supports_javascript' => true, |
| 40 | + 'disable_zoom' => true, |
| 41 | + 'parser' => 'html', |
| 42 | + 'disable_links' => true, |
| 43 | + ), |
| 44 | + 'simplehtml' => |
| 45 | + array ( |
| 46 | + 'view_format' => 'html', |
| 47 | + 'search_bar' => 'simple', |
| 48 | + 'footmenu' => 'simple', |
| 49 | + 'with_layout' => 'application', |
| 50 | + 'css_file_name' => 'simple', |
| 51 | + 'supports_javascript' => false, |
| 52 | + 'disable_zoom' => true, |
| 53 | + 'parser' => 'html', |
| 54 | + 'disable_links' => true, |
| 55 | + ), |
| 56 | + 'webkit' => |
| 57 | + array ( |
| 58 | + 'view_format' => 'html', |
| 59 | + 'search_bar' => 'webkit', |
| 60 | + 'footmenu' => 'default', |
| 61 | + 'with_layout' => 'application', |
| 62 | + 'css_file_name' => 'webkit', |
| 63 | + 'supports_javascript' => true, |
| 64 | + 'disable_zoom' => true, |
| 65 | + 'parser' => 'html', |
| 66 | + 'disable_links' => true, |
| 67 | + ), |
| 68 | + 'webkit_old' => |
| 69 | + array ( |
| 70 | + 'view_format' => 'html', |
| 71 | + 'search_bar' => 'default', |
| 72 | + 'footmenu' => 'default', |
| 73 | + 'with_layout' => 'application', |
| 74 | + 'css_file_name' => 'webkit_old', |
| 75 | + 'supports_javascript' => true, |
| 76 | + 'disable_zoom' => true, |
| 77 | + 'parser' => 'html', |
| 78 | + 'disable_links' => true, |
| 79 | + ), |
| 80 | + 'android' => |
| 81 | + array ( |
| 82 | + 'view_format' => 'html', |
| 83 | + 'search_bar' => 'default', |
| 84 | + 'footmenu' => 'default', |
| 85 | + 'with_layout' => 'application', |
| 86 | + 'css_file_name' => 'android', |
| 87 | + 'supports_javascript' => true, |
| 88 | + 'disable_zoom' => false, |
| 89 | + 'parser' => 'html', |
| 90 | + 'disable_links' => true, |
| 91 | + ), |
| 92 | + 'iphone' => |
| 93 | + array ( |
| 94 | + 'view_format' => 'html', |
| 95 | + 'search_bar' => 'webkit', |
| 96 | + 'footmenu' => 'default', |
| 97 | + 'with_layout' => 'application', |
| 98 | + 'css_file_name' => 'iphone', |
| 99 | + 'supports_javascript' => true, |
| 100 | + 'disable_zoom' => true, |
| 101 | + 'parser' => 'html', |
| 102 | + 'disable_links' => true, |
| 103 | + ), |
| 104 | + 'iphone2' => |
| 105 | + array ( |
| 106 | + 'view_format' => 'html', |
| 107 | + 'search_bar' => 'default', |
| 108 | + 'footmenu' => 'default', |
| 109 | + 'with_layout' => 'application', |
| 110 | + 'css_file_name' => 'iphone2', |
| 111 | + 'supports_javascript' => true, |
| 112 | + 'disable_zoom' => true, |
| 113 | + 'parser' => 'html', |
| 114 | + 'disable_links' => true, |
| 115 | + ), |
| 116 | + 'native_iphone' => |
| 117 | + array ( |
| 118 | + 'view_format' => 'html', |
| 119 | + 'search_bar' => false, |
| 120 | + 'footmenu' => 'default', |
| 121 | + 'with_layout' => 'application', |
| 122 | + 'css_file_name' => 'default', |
| 123 | + 'supports_javascript' => true, |
| 124 | + 'disable_zoom' => true, |
| 125 | + 'parser' => 'html', |
| 126 | + 'disable_links' => false, |
| 127 | + ), |
| 128 | + 'palm_pre' => |
| 129 | + array ( |
| 130 | + 'view_format' => 'html', |
| 131 | + 'search_bar' => 'default', |
| 132 | + 'footmenu' => 'default', |
| 133 | + 'with_layout' => 'application', |
| 134 | + 'css_file_name' => 'palm_pre', |
| 135 | + 'supports_javascript' => true, |
| 136 | + 'disable_zoom' => true, |
| 137 | + 'parser' => 'html', |
| 138 | + 'disable_links' => true, |
| 139 | + ), |
| 140 | + 'kindle' => |
| 141 | + array ( |
| 142 | + 'view_format' => 'html', |
| 143 | + 'search_bar' => 'kindle', |
| 144 | + 'footmenu' => 'default', |
| 145 | + 'with_layout' => 'application', |
| 146 | + 'css_file_name' => 'kindle', |
| 147 | + 'supports_javascript' => false, |
| 148 | + 'disable_zoom' => true, |
| 149 | + 'parser' => 'html', |
| 150 | + 'disable_links' => true, |
| 151 | + ), |
| 152 | + 'kindle2' => |
| 153 | + array ( |
| 154 | + 'view_format' => 'html', |
| 155 | + 'search_bar' => 'kindle', |
| 156 | + 'footmenu' => 'default', |
| 157 | + 'with_layout' => 'application', |
| 158 | + 'css_file_name' => 'kindle', |
| 159 | + 'supports_javascript' => false, |
| 160 | + 'disable_zoom' => true, |
| 161 | + 'parser' => 'html', |
| 162 | + 'disable_links' => true, |
| 163 | + ), |
| 164 | + 'blackberry' => |
| 165 | + array ( |
| 166 | + 'view_format' => 'html', |
| 167 | + 'search_bar' => 'default', |
| 168 | + 'footmenu' => 'default', |
| 169 | + 'with_layout' => 'application', |
| 170 | + 'css_file_name' => 'blackberry', |
| 171 | + 'supports_javascript' => true, |
| 172 | + 'disable_zoom' => true, |
| 173 | + 'parser' => 'html', |
| 174 | + 'disable_links' => true, |
| 175 | + ), |
| 176 | + 'netfront' => |
| 177 | + array ( |
| 178 | + 'view_format' => 'html', |
| 179 | + 'search_bar' => 'simple', |
| 180 | + 'footmenu' => 'simple', |
| 181 | + 'with_layout' => 'application', |
| 182 | + 'css_file_name' => 'simple', |
| 183 | + 'supports_javascript' => false, |
| 184 | + 'disable_zoom' => true, |
| 185 | + 'parser' => 'html', |
| 186 | + 'disable_links' => true, |
| 187 | + ), |
| 188 | + 'wap2' => |
| 189 | + array ( |
| 190 | + 'view_format' => 'html', |
| 191 | + 'search_bar' => 'simple', |
| 192 | + 'footmenu' => 'simple', |
| 193 | + 'with_layout' => 'application', |
| 194 | + 'css_file_name' => 'simple', |
| 195 | + 'supports_javascript' => false, |
| 196 | + 'disable_zoom' => true, |
| 197 | + 'parser' => 'html', |
| 198 | + 'disable_links' => true, |
| 199 | + ), |
| 200 | + 'psp' => |
| 201 | + array ( |
| 202 | + 'view_format' => 'html', |
| 203 | + 'search_bar' => 'simple', |
| 204 | + 'footmenu' => 'simple', |
| 205 | + 'with_layout' => 'application', |
| 206 | + 'css_file_name' => 'psp', |
| 207 | + 'supports_javascript' => false, |
| 208 | + 'disable_zoom' => true, |
| 209 | + 'parser' => 'html', |
| 210 | + 'disable_links' => true, |
| 211 | + ), |
| 212 | + 'ps3' => |
| 213 | + array ( |
| 214 | + 'view_format' => 'html', |
| 215 | + 'search_bar' => 'simple', |
| 216 | + 'footmenu' => 'simple', |
| 217 | + 'with_layout' => 'application', |
| 218 | + 'css_file_name' => 'simple', |
| 219 | + 'supports_javascript' => false, |
| 220 | + 'disable_zoom' => true, |
| 221 | + 'parser' => 'html', |
| 222 | + 'disable_links' => true, |
| 223 | + ), |
| 224 | + 'wii' => |
| 225 | + array ( |
| 226 | + 'view_format' => 'html', |
| 227 | + 'search_bar' => 'wii', |
| 228 | + 'footmenu' => 'default', |
| 229 | + 'with_layout' => 'application', |
| 230 | + 'css_file_name' => 'wii', |
| 231 | + 'supports_javascript' => true, |
| 232 | + 'disable_zoom' => true, |
| 233 | + 'parser' => 'html', |
| 234 | + 'disable_links' => true, |
| 235 | + ), |
| 236 | + 'operamini' => |
| 237 | + array ( |
| 238 | + 'view_format' => 'html', |
| 239 | + 'search_bar' => 'simple', |
| 240 | + 'footmenu' => 'simple', |
| 241 | + 'with_layout' => 'application', |
| 242 | + 'css_file_name' => 'operamini', |
| 243 | + 'supports_javascript' => false, |
| 244 | + 'disable_zoom' => true, |
| 245 | + 'parser' => 'html', |
| 246 | + 'disable_links' => true, |
| 247 | + ), |
| 248 | + 'nokia' => |
| 249 | + array ( |
| 250 | + 'view_format' => 'html', |
| 251 | + 'search_bar' => 'webkit', |
| 252 | + 'footmenu' => 'default', |
| 253 | + 'with_layout' => 'application', |
| 254 | + 'css_file_name' => 'nokia', |
| 255 | + 'supports_javascript' => true, |
| 256 | + 'disable_zoom' => true, |
| 257 | + 'parser' => 'html', |
| 258 | + 'disable_links' => true, |
| 259 | + ), |
| 260 | + 'wml' => |
| 261 | + array ( |
| 262 | + 'view_format' => 'wml', |
| 263 | + 'search_bar' => 'wml', |
| 264 | + 'supports_javascript' => false, |
| 265 | + 'parser' => 'wml', |
| 266 | + ), |
| 267 | + ); |
| 268 | + return $formats; |
| 269 | + } |
| 270 | + |
| 271 | + public function format( $formatName ) { |
| 272 | + $format = $this->availableFormats(); |
| 273 | + return ( isset( $format[$formatName] ) ) ? $format[$formatName] : array(); |
| 274 | + } |
| 275 | + |
| 276 | + public function testFormatName() { |
| 277 | + $testResults = ''; |
| 278 | + |
| 279 | + $userAgents = array(); |
| 280 | + $userAgents['android'] = 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17'; |
| 281 | + $userAgents['iphone2'] = 'Mozilla/5.0 (ipod: U;CPU iPhone OS 2_2 like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'; |
| 282 | + $userAgents['iphone'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'; |
| 283 | + $userAgents['nokia'] = 'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413'; |
| 284 | + $userAgents['palm_pre'] = 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0'; |
| 285 | + $userAgents['wii'] = 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)'; |
| 286 | + $userAgents['operamini'] = 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)'; |
| 287 | + $userAgents['iphone'] = 'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)'; |
| 288 | + $userAgents['kindle'] = 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)'; |
| 289 | + $userAgents['kindle2'] = 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)'; |
| 290 | + $userAgents['capable'] = 'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'; |
| 291 | + $userAgents['netfront'] = 'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2'; |
| 292 | + $userAgents['wap2'] = 'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
| 293 | + $userAgents['wap2'] = 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
| 294 | + $userAgents['psp'] = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'; |
| 295 | + $userAgents['ps3'] = 'Mozilla/5.0 (PLAYSTATION 3; 1.00)'; |
| 296 | + |
| 297 | + foreach ( $userAgents as $formatName => $userAgent ) { |
| 298 | + if ( $this->formatName( $userAgent ) === $formatName ) { |
| 299 | + $result = ' has PASSED!'; |
| 300 | + } else { |
| 301 | + $result = ' has FAILED!'; |
| 302 | + } |
| 303 | + |
| 304 | + $testResults .= $formatName . $result . '<br/>' . PHP_EOL; |
| 305 | + } |
| 306 | + return $testResults; |
| 307 | + } |
| 308 | + |
| 309 | + public function formatName( $userAgent, $acceptHeader = '' ) { |
| 310 | + $formatName = ''; |
| 311 | + |
| 312 | + if ( preg_match( '/Android/', $userAgent ) ) { |
| 313 | + $formatName = 'android'; |
| 314 | + } elseif ( preg_match( '/iPhone.* Safari/', $userAgent ) ) { |
| 315 | + if ( strpos( $userAgent, 'iPhone OS 2' ) !== false ) { |
| 316 | + $formatName = 'iphone2'; |
| 317 | + } else { |
| 318 | + $formatName = 'iphone'; |
| 319 | + } |
| 320 | + } elseif ( preg_match( '/iPhone/', $userAgent ) ) { |
| 321 | + if ( strpos( $userAgent, 'Opera' ) !== false ) { |
| 322 | + $formatName = 'operamini'; |
| 323 | + } else { |
| 324 | + $formatName = 'native_iphone'; |
| 325 | + } |
| 326 | + } elseif ( preg_match( '/WebKit/', $userAgent ) ) { |
| 327 | + if ( preg_match( '/Series60/', $userAgent ) ) { |
| 328 | + $formatName = 'nokia'; |
| 329 | + } elseif ( preg_match( '/webOS/', $userAgent ) ) { |
| 330 | + $formatName = 'palm_pre'; |
| 331 | + } else { |
| 332 | + $formatName = 'webkit'; |
| 333 | + } |
| 334 | + } elseif ( preg_match( '/Opera/', $userAgent ) ) { |
| 335 | + if ( strpos( $userAgent, 'Nintendo Wii' ) !== false ) { |
| 336 | + $formatName = 'wii'; |
| 337 | + } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) { |
| 338 | + $formatName = 'operamini'; |
| 339 | + } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) { |
| 340 | + $formatName = 'iphone'; |
| 341 | + } else { |
| 342 | + $formatName = 'webkit'; |
| 343 | + } |
| 344 | + } elseif ( preg_match( '/Kindle\/1.0/', $userAgent ) ) { |
| 345 | + $formatName = 'kindle'; |
| 346 | + } elseif ( preg_match( '/Kindle\/2.0/', $userAgent ) ) { |
| 347 | + $formatName = 'kindle2'; |
| 348 | + } elseif ( preg_match( '/Firefox/', $userAgent ) ) { |
| 349 | + $formatName = 'capable'; |
| 350 | + } elseif ( preg_match( '/NetFront/', $userAgent ) ) { |
| 351 | + $formatName = 'netfront'; |
| 352 | + } elseif ( preg_match( '/SEMC-Browser/', $userAgent ) ) { |
| 353 | + $formatName = 'wap2'; |
| 354 | + } elseif ( preg_match( '/Series60/', $userAgent ) ) { |
| 355 | + $formatName = 'wap2'; |
| 356 | + } elseif ( preg_match( '/PlayStation Portable/', $userAgent ) ) { |
| 357 | + $formatName = 'psp'; |
| 358 | + } elseif ( preg_match( '/PLAYSTATION 3/', $userAgent ) ) { |
| 359 | + $formatName = 'ps3'; |
| 360 | + } |
| 361 | + |
| 362 | + if ( $formatName === '' ) { |
| 363 | + if ( strpos( $acceptHeader, 'application/vnd.wap.xhtml+xml' ) !== false ) { |
| 364 | + $formatName = 'wap2'; |
| 365 | + } elseif ( strpos( $acceptHeader, 'vnd.wap.wml' ) !== false ) { |
| 366 | + $formatName = 'wml'; |
| 367 | + } else { |
| 368 | + $formatName = 'html'; |
| 369 | + } |
| 370 | + } |
| 371 | + return $formatName; |
| 372 | + } |
| 373 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/PatchOutputMobile/DeviceDetection.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 374 | + native |
Index: trunk/extensions/PatchOutputMobile/CssDetection.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Extension PatchOutputMobile — Css Detection |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Patrick Reilly |
| 9 | + * @copyright © 2011 Patrick Reilly |
| 10 | + * @licence GNU General Public Licence 2.0 or later |
| 11 | + */ |
| 12 | + |
| 13 | +class CssDetection { |
| 14 | + |
| 15 | + public static function detectIdCssOrTag( $snippet, &$type, &$rawName ) { |
| 16 | + $output = ''; |
| 17 | + |
| 18 | + if ( strpos( $snippet, '.' ) === 0 ) { |
| 19 | + $output = 'Class found: '; |
| 20 | + $type = 'CLASS'; |
| 21 | + $rawName = substr( $snippet, 1 ); |
| 22 | + } |
| 23 | + |
| 24 | + if ( strpos( $snippet, '#' ) === 0 ) { |
| 25 | + $output = 'ID found: '; |
| 26 | + $type = 'ID'; |
| 27 | + $rawName = substr( $snippet, 1 ); |
| 28 | + } |
| 29 | + |
| 30 | + if ( strpos( $snippet, '.' ) !== 0 && |
| 31 | + strpos( $snippet, '.' ) !== false ) { |
| 32 | + $output = 'Tag with Class found: '; |
| 33 | + $type = 'TAG_CLASS'; |
| 34 | + $rawName = $snippet; |
| 35 | + } |
| 36 | + |
| 37 | + if ( strpos( $snippet, '.' ) === false && |
| 38 | + strpos( $snippet, '#' ) === false && |
| 39 | + strpos( $snippet, '[' ) === false && |
| 40 | + strpos( $snippet, ']' ) === false ) { |
| 41 | + $output = 'Tag found: '; |
| 42 | + $type = 'TAG'; |
| 43 | + $rawName = $snippet; |
| 44 | + } |
| 45 | + |
| 46 | + if ( empty( $output ) ) { |
| 47 | + $output = 'Unknown HTML snippet found: '; |
| 48 | + $type = 'UNKNOWN'; |
| 49 | + $rawName = $snippet; |
| 50 | + } |
| 51 | + |
| 52 | + return $output; |
| 53 | + } |
| 54 | +} |
Property changes on: trunk/extensions/PatchOutputMobile/CssDetection.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 55 | + native |
Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php |
— | — | @@ -29,6 +29,9 @@ |
30 | 30 | |
31 | 31 | $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR; |
32 | 32 | $wgExtensionMessagesFiles['PatchOutputMobile'] = $dir . 'PatchOutputMobile.i18n.php'; |
| 33 | +//autoload extension classes |
| 34 | +$wgAutoloadClasses['DeviceDetection'] = $dir . 'DeviceDetection.php'; |
| 35 | +$wgAutoloadClasses['CssDetection'] = $dir . 'CssDetection.php'; |
33 | 36 | |
34 | 37 | $wgExtPatchOutputMobile = new ExtPatchOutputMobile(); |
35 | 38 | |
— | — | @@ -36,7 +39,7 @@ |
37 | 40 | 'onOutputPageBeforeHTML' ); |
38 | 41 | |
39 | 42 | class ExtPatchOutputMobile { |
40 | | - const VERSION = '0.3.5'; |
| 43 | + const VERSION = '0.3.6'; |
41 | 44 | |
42 | 45 | private $doc; |
43 | 46 | |
— | — | @@ -102,7 +105,7 @@ |
103 | 106 | |
104 | 107 | $userAgent = $_SERVER['HTTP_USER_AGENT']; |
105 | 108 | $acceptHeader = $_SERVER["HTTP_ACCEPT"]; |
106 | | - $device = new Device(); |
| 109 | + $device = new DeviceDetection(); |
107 | 110 | $formatName = $device->formatName( $userAgent, $acceptHeader ); |
108 | 111 | self::$device = $device->format( $formatName ); |
109 | 112 | |
— | — | @@ -336,408 +339,3 @@ |
337 | 340 | return $applicationHtml; |
338 | 341 | } |
339 | 342 | } |
340 | | - |
341 | | -class CssDetection { |
342 | | - |
343 | | - public static function detectIdCssOrTag( $snippet, &$type, &$rawName ) { |
344 | | - $output = ''; |
345 | | - |
346 | | - if ( strpos( $snippet, '.' ) === 0 ) { |
347 | | - $output = 'Class found: '; |
348 | | - $type = 'CLASS'; |
349 | | - $rawName = substr( $snippet, 1 ); |
350 | | - } |
351 | | - |
352 | | - if ( strpos( $snippet, '#' ) === 0 ) { |
353 | | - $output = 'ID found: '; |
354 | | - $type = 'ID'; |
355 | | - $rawName = substr( $snippet, 1 ); |
356 | | - } |
357 | | - |
358 | | - if ( strpos( $snippet, '.' ) !== 0 && |
359 | | - strpos( $snippet, '.' ) !== false ) { |
360 | | - $output = 'Tag with Class found: '; |
361 | | - $type = 'TAG_CLASS'; |
362 | | - $rawName = $snippet; |
363 | | - } |
364 | | - |
365 | | - if ( strpos( $snippet, '.' ) === false && |
366 | | - strpos( $snippet, '#' ) === false && |
367 | | - strpos( $snippet, '[' ) === false && |
368 | | - strpos( $snippet, ']' ) === false ) { |
369 | | - $output = 'Tag found: '; |
370 | | - $type = 'TAG'; |
371 | | - $rawName = $snippet; |
372 | | - } |
373 | | - |
374 | | - if ( empty( $output ) ) { |
375 | | - $output = 'Unknown HTML snippet found: '; |
376 | | - $type = 'UNKNOWN'; |
377 | | - $rawName = $snippet; |
378 | | - } |
379 | | - |
380 | | - return $output; |
381 | | - } |
382 | | -} |
383 | | - |
384 | | -// Provides an abstraction for a device |
385 | | -// A device can select which format a request should recieve and |
386 | | -// may be extended to provide access to particular devices functionality |
387 | | -class Device { |
388 | | - |
389 | | - public function availableFormats() { |
390 | | - $formats = array ( |
391 | | - 'html' => |
392 | | - array ( |
393 | | - 'view_format' => 'html', |
394 | | - 'search_bar' => 'default', |
395 | | - 'footmenu' => 'default', |
396 | | - 'with_layout' => 'application', |
397 | | - 'css_file_name' => 'default', |
398 | | - 'supports_javascript' => false, |
399 | | - 'disable_zoom' => true, |
400 | | - 'parser' => 'html', |
401 | | - 'disable_links' => true, |
402 | | - ), |
403 | | - 'capable' => |
404 | | - array ( |
405 | | - 'view_format' => 'html', |
406 | | - 'search_bar' => 'default', |
407 | | - 'footmenu' => 'default', |
408 | | - 'with_layout' => 'application', |
409 | | - 'css_file_name' => 'default', |
410 | | - 'supports_javascript' => true, |
411 | | - 'disable_zoom' => true, |
412 | | - 'parser' => 'html', |
413 | | - 'disable_links' => true, |
414 | | - ), |
415 | | - 'simplehtml' => |
416 | | - array ( |
417 | | - 'view_format' => 'html', |
418 | | - 'search_bar' => 'simple', |
419 | | - 'footmenu' => 'simple', |
420 | | - 'with_layout' => 'application', |
421 | | - 'css_file_name' => 'simple', |
422 | | - 'supports_javascript' => false, |
423 | | - 'disable_zoom' => true, |
424 | | - 'parser' => 'html', |
425 | | - 'disable_links' => true, |
426 | | - ), |
427 | | - 'webkit' => |
428 | | - array ( |
429 | | - 'view_format' => 'html', |
430 | | - 'search_bar' => 'webkit', |
431 | | - 'footmenu' => 'default', |
432 | | - 'with_layout' => 'application', |
433 | | - 'css_file_name' => 'webkit', |
434 | | - 'supports_javascript' => true, |
435 | | - 'disable_zoom' => true, |
436 | | - 'parser' => 'html', |
437 | | - 'disable_links' => true, |
438 | | - ), |
439 | | - 'webkit_old' => |
440 | | - array ( |
441 | | - 'view_format' => 'html', |
442 | | - 'search_bar' => 'default', |
443 | | - 'footmenu' => 'default', |
444 | | - 'with_layout' => 'application', |
445 | | - 'css_file_name' => 'webkit_old', |
446 | | - 'supports_javascript' => true, |
447 | | - 'disable_zoom' => true, |
448 | | - 'parser' => 'html', |
449 | | - 'disable_links' => true, |
450 | | - ), |
451 | | - 'android' => |
452 | | - array ( |
453 | | - 'view_format' => 'html', |
454 | | - 'search_bar' => 'default', |
455 | | - 'footmenu' => 'default', |
456 | | - 'with_layout' => 'application', |
457 | | - 'css_file_name' => 'android', |
458 | | - 'supports_javascript' => true, |
459 | | - 'disable_zoom' => false, |
460 | | - 'parser' => 'html', |
461 | | - 'disable_links' => true, |
462 | | - ), |
463 | | - 'iphone' => |
464 | | - array ( |
465 | | - 'view_format' => 'html', |
466 | | - 'search_bar' => 'webkit', |
467 | | - 'footmenu' => 'default', |
468 | | - 'with_layout' => 'application', |
469 | | - 'css_file_name' => 'iphone', |
470 | | - 'supports_javascript' => true, |
471 | | - 'disable_zoom' => true, |
472 | | - 'parser' => 'html', |
473 | | - 'disable_links' => true, |
474 | | - ), |
475 | | - 'iphone2' => |
476 | | - array ( |
477 | | - 'view_format' => 'html', |
478 | | - 'search_bar' => 'default', |
479 | | - 'footmenu' => 'default', |
480 | | - 'with_layout' => 'application', |
481 | | - 'css_file_name' => 'iphone2', |
482 | | - 'supports_javascript' => true, |
483 | | - 'disable_zoom' => true, |
484 | | - 'parser' => 'html', |
485 | | - 'disable_links' => true, |
486 | | - ), |
487 | | - 'native_iphone' => |
488 | | - array ( |
489 | | - 'view_format' => 'html', |
490 | | - 'search_bar' => false, |
491 | | - 'footmenu' => 'default', |
492 | | - 'with_layout' => 'application', |
493 | | - 'css_file_name' => 'default', |
494 | | - 'supports_javascript' => true, |
495 | | - 'disable_zoom' => true, |
496 | | - 'parser' => 'html', |
497 | | - 'disable_links' => false, |
498 | | - ), |
499 | | - 'palm_pre' => |
500 | | - array ( |
501 | | - 'view_format' => 'html', |
502 | | - 'search_bar' => 'default', |
503 | | - 'footmenu' => 'default', |
504 | | - 'with_layout' => 'application', |
505 | | - 'css_file_name' => 'palm_pre', |
506 | | - 'supports_javascript' => true, |
507 | | - 'disable_zoom' => true, |
508 | | - 'parser' => 'html', |
509 | | - 'disable_links' => true, |
510 | | - ), |
511 | | - 'kindle' => |
512 | | - array ( |
513 | | - 'view_format' => 'html', |
514 | | - 'search_bar' => 'kindle', |
515 | | - 'footmenu' => 'default', |
516 | | - 'with_layout' => 'application', |
517 | | - 'css_file_name' => 'kindle', |
518 | | - 'supports_javascript' => false, |
519 | | - 'disable_zoom' => true, |
520 | | - 'parser' => 'html', |
521 | | - 'disable_links' => true, |
522 | | - ), |
523 | | - 'kindle2' => |
524 | | - array ( |
525 | | - 'view_format' => 'html', |
526 | | - 'search_bar' => 'kindle', |
527 | | - 'footmenu' => 'default', |
528 | | - 'with_layout' => 'application', |
529 | | - 'css_file_name' => 'kindle', |
530 | | - 'supports_javascript' => false, |
531 | | - 'disable_zoom' => true, |
532 | | - 'parser' => 'html', |
533 | | - 'disable_links' => true, |
534 | | - ), |
535 | | - 'blackberry' => |
536 | | - array ( |
537 | | - 'view_format' => 'html', |
538 | | - 'search_bar' => 'default', |
539 | | - 'footmenu' => 'default', |
540 | | - 'with_layout' => 'application', |
541 | | - 'css_file_name' => 'blackberry', |
542 | | - 'supports_javascript' => true, |
543 | | - 'disable_zoom' => true, |
544 | | - 'parser' => 'html', |
545 | | - 'disable_links' => true, |
546 | | - ), |
547 | | - 'netfront' => |
548 | | - array ( |
549 | | - 'view_format' => 'html', |
550 | | - 'search_bar' => 'simple', |
551 | | - 'footmenu' => 'simple', |
552 | | - 'with_layout' => 'application', |
553 | | - 'css_file_name' => 'simple', |
554 | | - 'supports_javascript' => false, |
555 | | - 'disable_zoom' => true, |
556 | | - 'parser' => 'html', |
557 | | - 'disable_links' => true, |
558 | | - ), |
559 | | - 'wap2' => |
560 | | - array ( |
561 | | - 'view_format' => 'html', |
562 | | - 'search_bar' => 'simple', |
563 | | - 'footmenu' => 'simple', |
564 | | - 'with_layout' => 'application', |
565 | | - 'css_file_name' => 'simple', |
566 | | - 'supports_javascript' => false, |
567 | | - 'disable_zoom' => true, |
568 | | - 'parser' => 'html', |
569 | | - 'disable_links' => true, |
570 | | - ), |
571 | | - 'psp' => |
572 | | - array ( |
573 | | - 'view_format' => 'html', |
574 | | - 'search_bar' => 'simple', |
575 | | - 'footmenu' => 'simple', |
576 | | - 'with_layout' => 'application', |
577 | | - 'css_file_name' => 'psp', |
578 | | - 'supports_javascript' => false, |
579 | | - 'disable_zoom' => true, |
580 | | - 'parser' => 'html', |
581 | | - 'disable_links' => true, |
582 | | - ), |
583 | | - 'ps3' => |
584 | | - array ( |
585 | | - 'view_format' => 'html', |
586 | | - 'search_bar' => 'simple', |
587 | | - 'footmenu' => 'simple', |
588 | | - 'with_layout' => 'application', |
589 | | - 'css_file_name' => 'simple', |
590 | | - 'supports_javascript' => false, |
591 | | - 'disable_zoom' => true, |
592 | | - 'parser' => 'html', |
593 | | - 'disable_links' => true, |
594 | | - ), |
595 | | - 'wii' => |
596 | | - array ( |
597 | | - 'view_format' => 'html', |
598 | | - 'search_bar' => 'wii', |
599 | | - 'footmenu' => 'default', |
600 | | - 'with_layout' => 'application', |
601 | | - 'css_file_name' => 'wii', |
602 | | - 'supports_javascript' => true, |
603 | | - 'disable_zoom' => true, |
604 | | - 'parser' => 'html', |
605 | | - 'disable_links' => true, |
606 | | - ), |
607 | | - 'operamini' => |
608 | | - array ( |
609 | | - 'view_format' => 'html', |
610 | | - 'search_bar' => 'simple', |
611 | | - 'footmenu' => 'simple', |
612 | | - 'with_layout' => 'application', |
613 | | - 'css_file_name' => 'operamini', |
614 | | - 'supports_javascript' => false, |
615 | | - 'disable_zoom' => true, |
616 | | - 'parser' => 'html', |
617 | | - 'disable_links' => true, |
618 | | - ), |
619 | | - 'nokia' => |
620 | | - array ( |
621 | | - 'view_format' => 'html', |
622 | | - 'search_bar' => 'webkit', |
623 | | - 'footmenu' => 'default', |
624 | | - 'with_layout' => 'application', |
625 | | - 'css_file_name' => 'nokia', |
626 | | - 'supports_javascript' => true, |
627 | | - 'disable_zoom' => true, |
628 | | - 'parser' => 'html', |
629 | | - 'disable_links' => true, |
630 | | - ), |
631 | | - 'wml' => |
632 | | - array ( |
633 | | - 'view_format' => 'wml', |
634 | | - 'search_bar' => 'wml', |
635 | | - 'supports_javascript' => false, |
636 | | - 'parser' => 'wml', |
637 | | - ), |
638 | | - ); |
639 | | - return $formats; |
640 | | - } |
641 | | - |
642 | | - public function format( $formatName ) { |
643 | | - $format = $this->availableFormats(); |
644 | | - return ( isset( $format[$formatName] ) ) ? $format[$formatName] : array(); |
645 | | - } |
646 | | - |
647 | | - public function testFormatName() { |
648 | | - $testResults = ''; |
649 | | - |
650 | | - $userAgents = array(); |
651 | | - $userAgents['android'] = 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17'; |
652 | | - $userAgents['iphone2'] = 'Mozilla/5.0 (ipod: U;CPU iPhone OS 2_2 like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'; |
653 | | - $userAgents['iphone'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'; |
654 | | - $userAgents['nokia'] = 'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413'; |
655 | | - $userAgents['palm_pre'] = 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0'; |
656 | | - $userAgents['wii'] = 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)'; |
657 | | - $userAgents['operamini'] = 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)'; |
658 | | - $userAgents['iphone'] = 'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)'; |
659 | | - $userAgents['kindle'] = 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)'; |
660 | | - $userAgents['kindle2'] = 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)'; |
661 | | - $userAgents['capable'] = 'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'; |
662 | | - $userAgents['netfront'] = 'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2'; |
663 | | - $userAgents['wap2'] = 'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
664 | | - $userAgents['wap2'] = 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
665 | | - $userAgents['psp'] = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'; |
666 | | - $userAgents['ps3'] = 'Mozilla/5.0 (PLAYSTATION 3; 1.00)'; |
667 | | - |
668 | | - foreach ( $userAgents as $formatName => $userAgent ) { |
669 | | - if ( $this->formatName( $userAgent ) === $formatName ) { |
670 | | - $result = ' has PASSED!'; |
671 | | - } else { |
672 | | - $result = ' has FAILED!'; |
673 | | - } |
674 | | - |
675 | | - $testResults .= $formatName . $result . '<br/>' . PHP_EOL; |
676 | | - } |
677 | | - return $testResults; |
678 | | - } |
679 | | - |
680 | | - public function formatName( $userAgent, $acceptHeader = '' ) { |
681 | | - $formatName = ''; |
682 | | - |
683 | | - if ( preg_match( '/Android/', $userAgent ) ) { |
684 | | - $formatName = 'android'; |
685 | | - } elseif ( preg_match( '/iPhone.* Safari/', $userAgent ) ) { |
686 | | - if ( strpos( $userAgent, 'iPhone OS 2' ) !== false ) { |
687 | | - $formatName = 'iphone2'; |
688 | | - } else { |
689 | | - $formatName = 'iphone'; |
690 | | - } |
691 | | - } elseif ( preg_match( '/iPhone/', $userAgent ) ) { |
692 | | - if ( strpos( $userAgent, 'Opera' ) !== false ) { |
693 | | - $formatName = 'operamini'; |
694 | | - } else { |
695 | | - $formatName = 'native_iphone'; |
696 | | - } |
697 | | - } elseif ( preg_match( '/WebKit/', $userAgent ) ) { |
698 | | - if ( preg_match( '/Series60/', $userAgent ) ) { |
699 | | - $formatName = 'nokia'; |
700 | | - } elseif ( preg_match( '/webOS/', $userAgent ) ) { |
701 | | - $formatName = 'palm_pre'; |
702 | | - } else { |
703 | | - $formatName = 'webkit'; |
704 | | - } |
705 | | - } elseif ( preg_match( '/Opera/', $userAgent ) ) { |
706 | | - if ( strpos( $userAgent, 'Nintendo Wii' ) !== false ) { |
707 | | - $formatName = 'wii'; |
708 | | - } elseif ( strpos( $userAgent, 'Opera Mini' ) !== false ) { |
709 | | - $formatName = 'operamini'; |
710 | | - } elseif ( strpos( $userAgent, 'Opera Mobi' ) !== false ) { |
711 | | - $formatName = 'iphone'; |
712 | | - } else { |
713 | | - $formatName = 'webkit'; |
714 | | - } |
715 | | - } elseif ( preg_match( '/Kindle\/1.0/', $userAgent ) ) { |
716 | | - $formatName = 'kindle'; |
717 | | - } elseif ( preg_match( '/Kindle\/2.0/', $userAgent ) ) { |
718 | | - $formatName = 'kindle2'; |
719 | | - } elseif ( preg_match( '/Firefox/', $userAgent ) ) { |
720 | | - $formatName = 'capable'; |
721 | | - } elseif ( preg_match( '/NetFront/', $userAgent ) ) { |
722 | | - $formatName = 'netfront'; |
723 | | - } elseif ( preg_match( '/SEMC-Browser/', $userAgent ) ) { |
724 | | - $formatName = 'wap2'; |
725 | | - } elseif ( preg_match( '/Series60/', $userAgent ) ) { |
726 | | - $formatName = 'wap2'; |
727 | | - } elseif ( preg_match( '/PlayStation Portable/', $userAgent ) ) { |
728 | | - $formatName = 'psp'; |
729 | | - } elseif ( preg_match( '/PLAYSTATION 3/', $userAgent ) ) { |
730 | | - $formatName = 'ps3'; |
731 | | - } |
732 | | - |
733 | | - if ( $formatName === '' ) { |
734 | | - if ( strpos( $acceptHeader, 'application/vnd.wap.xhtml+xml' ) !== false ) { |
735 | | - $formatName = 'wap2'; |
736 | | - } elseif ( strpos( $acceptHeader, 'vnd.wap.wml' ) !== false ) { |
737 | | - $formatName = 'wml'; |
738 | | - } else { |
739 | | - $formatName = 'html'; |
740 | | - } |
741 | | - } |
742 | | - return $formatName; |
743 | | - } |
744 | | -} |