| [ Indice ] |
Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4Servizio fornito da VMItalia |
[Vedi sommario] [Stampa] [Vedi testo]
1 <?php 2 /** 3 * @version $Id: browser.php 10707 2008-08-21 09:52:47Z eddieajau $ 4 * @package Joomla.Framework 5 * @subpackage Environment 6 * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant 9 * to the GNU General Public License, and as distributed it includes or 10 * is derivative of works licensed under the GNU General Public License or 11 * other free or open source software licenses. 12 * See COPYRIGHT.php for copyright notices and details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 /** 19 * Browser class, provides capability information about the current web client. 20 * 21 * Browser identification is performed by examining the HTTP_USER_AGENT 22 * environment variable provided by the web server. 23 * 24 * This class has many influences from the lib/Browser.php code in 25 * version 3 of Horde by Chuck Hagenbuch and Jon Parise 26 * 27 * @package Joomla.Framework 28 * @subpackage Environment 29 * @since 1.5 30 */ 31 32 class JBrowser extends JObject 33 { 34 /** 35 * Major version number. 36 * 37 * @var integer 38 */ 39 var $_majorVersion = 0; 40 41 /** 42 * Minor version number. 43 * 44 * @var integer 45 */ 46 var $_minorVersion = 0; 47 48 /** 49 * Browser name. 50 * 51 * @var string 52 */ 53 var $_browser = ''; 54 55 /** 56 * Full user agent string. 57 * 58 * @var string 59 */ 60 var $_agent = ''; 61 62 /** 63 * Lower-case user agent string. 64 * 65 * @var string 66 */ 67 var $_lowerAgent = ''; 68 69 /** 70 * HTTP_ACCEPT string 71 * 72 * @var string 73 */ 74 var $_accept = ''; 75 76 /** 77 * Platform the browser is running on. 78 * 79 * @var string 80 */ 81 var $_platform = ''; 82 83 /** 84 * Known robots. 85 * 86 * @var array 87 */ 88 var $_robots = array( 89 /* The most common ones. */ 90 'Googlebot', 91 'msnbot', 92 'Slurp', 93 'Yahoo', 94 /* The rest alphabetically. */ 95 'Arachnoidea', 96 'ArchitextSpider', 97 'Ask Jeeves', 98 'B-l-i-t-z-Bot', 99 'Baiduspider', 100 'BecomeBot', 101 'cfetch', 102 'ConveraCrawler', 103 'ExtractorPro', 104 'FAST-WebCrawler', 105 'FDSE robot', 106 'fido', 107 'geckobot', 108 'Gigabot', 109 'Girafabot', 110 'grub-client', 111 'Gulliver', 112 'HTTrack', 113 'ia_archiver', 114 'InfoSeek', 115 'kinjabot', 116 'KIT-Fireball', 117 'larbin', 118 'LEIA', 119 'lmspider', 120 'Lycos_Spider', 121 'Mediapartners-Google', 122 'MuscatFerret', 123 'NaverBot', 124 'OmniExplorer_Bot', 125 'polybot', 126 'Pompos', 127 'Scooter', 128 'Teoma', 129 'TheSuBot', 130 'TurnitinBot', 131 'Ultraseek', 132 'ViolaBot', 133 'webbandit', 134 'www.almaden.ibm.com/cs/crawler', 135 'ZyBorg', 136 ); 137 138 /** 139 * Is this a mobile browser? 140 * 141 * @var boolean 142 */ 143 var $_mobile = false; 144 145 /** 146 * Features. 147 * 148 * @var array 149 */ 150 var $_features = array( 151 'html' => true, 152 'hdml' => false, 153 'wml' => false, 154 'images' => true, 155 'iframes' => false, 156 'frames' => true, 157 'tables' => true, 158 'java' => true, 159 'javascript' => true, 160 'dom' => false, 161 'utf' => false, 162 'rte' => false, 163 'homepage' => false, 164 'accesskey' => false, 165 'optgroup' => false, 166 'xmlhttpreq' => false, 167 'cite' => false, 168 'xhtml+xml' => false, 169 'mathml' => false, 170 'svg' => false 171 ); 172 173 /** 174 * Quirks 175 * 176 * @var array 177 */ 178 var $_quirks = array( 179 'avoid_popup_windows' => false, 180 'break_disposition_header' => false, 181 'break_disposition_filename' => false, 182 'broken_multipart_form' => false, 183 'cache_same_url' => false, 184 'cache_ssl_downloads' => false, 185 'double_linebreak_textarea' => false, 186 'empty_file_input_value' => false, 187 'must_cache_forms' => false, 188 'no_filename_spaces' => false, 189 'no_hidden_overflow_tables' => false, 190 'ow_gui_1.3' => false, 191 'png_transparency' => false, 192 'scrollbar_in_way' => false, 193 'scroll_tds' => false, 194 'windowed_controls' => false, 195 ); 196 197 /** 198 * List of viewable image MIME subtypes. 199 * This list of viewable images works for IE and Netscape/Mozilla. 200 * 201 * @var array 202 */ 203 var $_images = array('jpeg', 'gif', 'png', 'pjpeg', 'x-png', 'bmp'); 204 205 206 /** 207 * Create a browser instance (Constructor). 208 * 209 * @param string $userAgent The browser string to parse. 210 * @param string $accept The HTTP_ACCEPT settings to use. 211 */ 212 function __construct($userAgent = null, $accept = null) 213 { 214 $this->match($userAgent, $accept); 215 } 216 217 /** 218 * Returns a reference to the global Browser object, only creating it 219 * if it doesn't already exist. 220 * 221 * This method must be invoked as: 222 * <pre> $browser = &JBrowser::getInstance([$userAgent[, $accept]]);</pre> 223 * 224 * @access public 225 * @param string $userAgent The browser string to parse. 226 * @param string $accept The HTTP_ACCEPT settings to use. 227 * @return JBrowser The Browser object. 228 */ 229 function &getInstance($userAgent = null, $accept = null) 230 { 231 static $instances; 232 233 if (!isset($instances)) { 234 $instances = array(); 235 } 236 237 $signature = serialize(array($userAgent, $accept)); 238 239 if (empty($instances[$signature])) { 240 $instances[$signature] = new JBrowser($userAgent, $accept); 241 } 242 243 return $instances[$signature]; 244 } 245 246 /** 247 * Parses the user agent string and inititializes the object with 248 * all the known features and quirks for the given browser. 249 * 250 * @param string $userAgent The browser string to parse. 251 * @param string $accept The HTTP_ACCEPT settings to use. 252 */ 253 function match($userAgent = null, $accept = null) 254 { 255 // Set our agent string. 256 if (is_null($userAgent)) { 257 if (isset($_SERVER['HTTP_USER_AGENT'])) { 258 $this->_agent = trim($_SERVER['HTTP_USER_AGENT']); 259 } 260 } else { 261 $this->_agent = $userAgent; 262 } 263 $this->_lowerAgent = strtolower($this->_agent); 264 265 // Set our accept string. 266 if (is_null($accept)) { 267 if (isset($_SERVER['HTTP_ACCEPT'])) { 268 $this->_accept = strtolower(trim($_SERVER['HTTP_ACCEPT'])); 269 } 270 } else { 271 $this->_accept = strtolower($accept); 272 } 273 274 275 // Check if browser excepts content type xhtml+xml 276 if (strpos($this->_accept, 'application/xhtml+xml')) { 277 $this->setFeature('xhtml+xml'); 278 } 279 280 // Check for a mathplayer plugin is installed, so we can use MathML on several browsers 281 if (strpos($this->_lowerAgent, 'mathplayer') !== false) { 282 $this->setFeature('mathml'); 283 } 284 285 // Check for UTF support. 286 if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) { 287 $this->setFeature('utf', strpos(strtolower($_SERVER['HTTP_ACCEPT_CHARSET']), 'utf') !== false); 288 } 289 290 if (!empty($this->_agent)) { 291 $this->_setPlatform(); 292 293 if (strpos($this->_lowerAgent, 'mobileexplorer') !== false || 294 strpos($this->_lowerAgent, 'openwave') !== false || 295 strpos($this->_lowerAgent, 'opera mini') !== false || 296 strpos($this->_lowerAgent, 'operamini') !== false) { 297 $this->setFeature('frames', false); 298 $this->setFeature('javascript', false); 299 $this->setQuirk('avoid_popup_windows'); 300 $this->_mobile = true; 301 } elseif (preg_match('|Opera[/ ]([0-9.]+)|', $this->_agent, $version)) { 302 $this->setBrowser('opera'); 303 list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]); 304 $this->setFeature('javascript', true); 305 $this->setQuirk('no_filename_spaces'); 306 307 if ($this->_majorVersion >= 7) { 308 $this->setFeature('dom'); 309 $this->setFeature('iframes'); 310 $this->setFeature('accesskey'); 311 $this->setFeature('optgroup'); 312 $this->setQuirk('double_linebreak_textarea'); 313 } 314 } elseif (strpos($this->_lowerAgent, 'elaine/') !== false || 315 strpos($this->_lowerAgent, 'palmsource') !== false || 316 strpos($this->_lowerAgent, 'digital paths') !== false) { 317 $this->setBrowser('palm'); 318 $this->setFeature('images', false); 319 $this->setFeature('frames', false); 320 $this->setFeature('javascript', false); 321 $this->setQuirk('avoid_popup_windows'); 322 $this->_mobile = true; 323 } elseif ((preg_match('|MSIE ([0-9.]+)|', $this->_agent, $version)) || 324 (preg_match('|Internet Explorer/([0-9.]+)|', $this->_agent, $version))) { 325 326 $this->setBrowser('msie'); 327 $this->setQuirk('cache_ssl_downloads'); 328 $this->setQuirk('cache_same_url'); 329 $this->setQuirk('break_disposition_filename'); 330 331 if (strpos($version[1], '.') !== false) { 332 list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]); 333 } else { 334 $this->_majorVersion = $version[1]; 335 $this->_minorVersion = 0; 336 } 337 338 /* IE (< 7) on Windows does not support alpha transparency in 339 * PNG images. */ 340 if (($this->_majorVersion < 7) && 341 preg_match('/windows/i', $this->_agent)) { 342 $this->setQuirk('png_transparency'); 343 } 344 345 /* Some Handhelds have their screen resolution in the 346 * user agent string, which we can use to look for 347 * mobile agents. */ 348 if (preg_match('/; (120x160|240x280|240x320|320x320)\)/', $this->_agent)) { 349 $this->_mobile = true; 350 } 351 352 switch ($this->_majorVersion) { 353 case 7: 354 $this->setFeature('javascript', 1.4); 355 $this->setFeature('dom'); 356 $this->setFeature('iframes'); 357 $this->setFeature('utf'); 358 $this->setFeature('rte'); 359 $this->setFeature('homepage'); 360 $this->setFeature('accesskey'); 361 $this->setFeature('optgroup'); 362 $this->setFeature('xmlhttpreq'); 363 $this->setQuirk('scrollbar_in_way'); 364 break; 365 366 case 6: 367 $this->setFeature('javascript', 1.4); 368 $this->setFeature('dom'); 369 $this->setFeature('iframes'); 370 $this->setFeature('utf'); 371 $this->setFeature('rte'); 372 $this->setFeature('homepage'); 373 $this->setFeature('accesskey'); 374 $this->setFeature('optgroup'); 375 $this->setFeature('xmlhttpreq'); 376 $this->setQuirk('scrollbar_in_way'); 377 $this->setQuirk('broken_multipart_form'); 378 $this->setQuirk('windowed_controls'); 379 break; 380 381 case 5: 382 if ($this->getPlatform() == 'mac') { 383 $this->setFeature('javascript', 1.2); 384 $this->setFeature('optgroup'); 385 } else { 386 // MSIE 5 for Windows. 387 $this->setFeature('javascript', 1.4); 388 $this->setFeature('dom'); 389 $this->setFeature('xmlhttpreq'); 390 if ($this->_minorVersion >= 5) { 391 $this->setFeature('rte'); 392 $this->setQuirk('windowed_controls'); 393 } 394 } 395 $this->setFeature('iframes'); 396 $this->setFeature('utf'); 397 $this->setFeature('homepage'); 398 $this->setFeature('accesskey'); 399 if ($this->_minorVersion == 5) { 400 $this->setQuirk('break_disposition_header'); 401 $this->setQuirk('broken_multipart_form'); 402 } 403 break; 404 405 case 4: 406 $this->setFeature('javascript', 1.2); 407 $this->setFeature('accesskey'); 408 if ($this->_minorVersion > 0) { 409 $this->setFeature('utf'); 410 } 411 break; 412 413 case 3: 414 $this->setFeature('javascript', 1.5); 415 $this->setQuirk('avoid_popup_windows'); 416 break; 417 } 418 } elseif (preg_match('|amaya/([0-9.]+)|', $this->_agent, $version)) { 419 $this->setBrowser('amaya'); 420 $this->_majorVersion = $version[1]; 421 if (isset($version[2])) { 422 $this->_minorVersion = $version[2]; 423 } 424 if ($this->_majorVersion > 1) { 425 $this->setFeature('mathml'); 426 $this->setFeature('svg'); 427 } 428 $this->setFeature('xhtml+xml'); 429 } elseif (preg_match('|W3C_Validator/([0-9.]+)|', $this->_agent, $version)) { 430 $this->setFeature('mathml'); 431 $this->setFeature('svg'); 432 $this->setFeature('xhtml+xml'); 433 } elseif (preg_match('|ANTFresco/([0-9]+)|', $this->_agent, $version)) { 434 $this->setBrowser('fresco'); 435 $this->setFeature('javascript', 1.5); 436 $this->setQuirk('avoid_popup_windows'); 437 } elseif (strpos($this->_lowerAgent, 'avantgo') !== false) { 438 $this->setBrowser('avantgo'); 439 $this->_mobile = true; 440 } elseif (preg_match('|Konqueror/([0-9]+)|', $this->_agent, $version) || 441 preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $this->_agent, $version)) { 442 // Konqueror and Apple's Safari both use the KHTML 443 // rendering engine. 444 $this->setBrowser('konqueror'); 445 $this->setQuirk('empty_file_input_value'); 446 $this->setQuirk('no_hidden_overflow_tables'); 447 $this->_majorVersion = $version[1]; 448 if (isset($version[2])) { 449 $this->_minorVersion = $version[2]; 450 } 451 452 if (strpos($this->_agent, 'Safari') !== false && 453 $this->_majorVersion >= 60) { 454 // Safari. 455 $this->setFeature('utf'); 456 $this->setFeature('javascript', 1.4); 457 $this->setFeature('dom'); 458 $this->setFeature('iframes'); 459 if ($this->_majorVersion > 125 || 460 ($this->_majorVersion == 125 && 461 $this->_minorVersion >= 1)) { 462 $this->setFeature('accesskey'); 463 $this->setFeature('xmlhttpreq'); 464 } 465 if ($this->_majorVersion > 522) { 466 $this->setFeature('svg'); 467 $this->setFeature('xhtml+xml'); 468 } 469 } else { 470 // Konqueror. 471 $this->setFeature('javascript', 1.5); 472 switch ($this->_majorVersion) { 473 case 3: 474 $this->setFeature('dom'); 475 $this->setFeature('iframes'); 476 $this->setFeature('xhtml+xml'); 477 break; 478 } 479 } 480 } elseif (preg_match('|Mozilla/([0-9.]+)|', $this->_agent, $version)) { 481 $this->setBrowser('mozilla'); 482 $this->setQuirk('must_cache_forms'); 483 484 list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]); 485 switch ($this->_majorVersion) { 486 case 5: 487 if ($this->getPlatform() == 'win') { 488 $this->setQuirk('break_disposition_filename'); 489 } 490 $this->setFeature('javascript', 1.4); 491 $this->setFeature('dom'); 492 $this->setFeature('accesskey'); 493 $this->setFeature('optgroup'); 494 $this->setFeature('xmlhttpreq'); 495 $this->setFeature('cite'); 496 if (preg_match('|rv:(.*)\)|', $this->_agent, $revision)) { 497 if ($revision[1] >= 1) { 498 $this->setFeature('iframes'); 499 } 500 if ($revision[1] >= 1.3) { 501 $this->setFeature('rte'); 502 } 503 if ($revision[1] >= 1.5) { 504 $this->setFeature('svg'); 505 $this->setFeature('mathml'); 506 $this->setFeature('xhtml+xml'); 507 } 508 } 509 break; 510 511 case 4: 512 $this->setFeature('javascript', 1.3); 513 $this->setQuirk('buggy_compression'); 514 break; 515 516 case 3: 517 default: 518 $this->setFeature('javascript', 1); 519 $this->setQuirk('buggy_compression'); 520 break; 521 } 522 } elseif (preg_match('|Lynx/([0-9]+)|', $this->_agent, $version)) { 523 $this->setBrowser('lynx'); 524 $this->setFeature('images', false); 525 $this->setFeature('frames', false); 526 $this->setFeature('javascript', false); 527 $this->setQuirk('avoid_popup_windows'); 528 } elseif (preg_match('|Links \(([0-9]+)|', $this->_agent, $version)) { 529 $this->setBrowser('links'); 530 $this->setFeature('images', false); 531 $this->setFeature('frames', false); 532 $this->setFeature('javascript', false); 533 $this->setQuirk('avoid_popup_windows'); 534 } elseif (preg_match('|HotJava/([0-9]+)|', $this->_agent, $version)) { 535 $this->setBrowser('hotjava'); 536 $this->setFeature('javascript', false); 537 } elseif (strpos($this->_agent, 'UP/') !== false || 538 strpos($this->_agent, 'UP.B') !== false || 539 strpos($this->_agent, 'UP.L') !== false) { 540 $this->setBrowser('up'); 541 $this->setFeature('html', false); 542 $this->setFeature('javascript', false); 543 $this->setFeature('hdml'); 544 $this->setFeature('wml'); 545 546 if (strpos($this->_agent, 'GUI') !== false && 547 strpos($this->_agent, 'UP.Link') !== false) { 548 /* The device accepts Openwave GUI extensions for 549 * WML 1.3. Non-UP.Link gateways sometimes have 550 * problems, so exclude them. */ 551 $this->setQuirk('ow_gui_1.3'); 552 } 553 $this->_mobile = true; 554 } elseif (strpos($this->_agent, 'Xiino/') !== false) { 555 $this->setBrowser('xiino'); 556 $this->setFeature('hdml'); 557 $this->setFeature('wml'); 558 $this->_mobile = true; 559 } elseif (strpos($this->_agent, 'Palmscape/') !== false) { 560 $this->setBrowser('palmscape'); 561 $this->setFeature('javascript', false); 562 $this->setFeature('hdml'); 563 $this->setFeature('wml'); 564 $this->_mobile = true; 565 } elseif (strpos($this->_agent, 'Nokia') !== false) { 566 $this->setBrowser('nokia'); 567 $this->setFeature('html', false); 568 $this->setFeature('wml'); 569 $this->setFeature('xhtml'); 570 $this->_mobile = true; 571 } elseif (strpos($this->_agent, 'Ericsson') !== false) { 572 $this->setBrowser('ericsson'); 573 $this->setFeature('html', false); 574 $this->setFeature('wml'); 575 $this->_mobile = true; 576 } elseif (strpos($this->_lowerAgent, 'wap') !== false) { 577 $this->setBrowser('wap'); 578 $this->setFeature('html', false); 579 $this->setFeature('javascript', false); 580 $this->setFeature('hdml'); 581 $this->setFeature('wml'); 582 $this->_mobile = true; 583 } elseif (strpos($this->_lowerAgent, 'docomo') !== false || 584 strpos($this->_lowerAgent, 'portalmmm') !== false) { 585 $this->setBrowser('imode'); 586 $this->setFeature('images', false); 587 $this->_mobile = true; 588 } elseif (strpos($this->_agent, 'BlackBerry') !== false) { 589 $this->setBrowser('blackberry'); 590 $this->setFeature('html', false); 591 $this->setFeature('javascript', false); 592 $this->setFeature('hdml'); 593 $this->setFeature('wml'); 594 $this->_mobile = true; 595 } elseif (strpos($this->_agent, 'MOT-') !== false) { 596 $this->setBrowser('motorola'); 597 $this->setFeature('html', false); 598 $this->setFeature('javascript', false); 599 $this->setFeature('hdml'); 600 $this->setFeature('wml'); 601 $this->_mobile = true; 602 } elseif (strpos($this->_lowerAgent, 'j-') !== false) { 603 $this->setBrowser('mml'); 604 $this->_mobile = true; 605 } 606 } 607 } 608 609 /** 610 * Match the platform of the browser. 611 * 612 * This is a pretty simplistic implementation, but it's intended 613 * to let us tell what line breaks to send, so it's good enough 614 * for its purpose. 615 */ 616 function _setPlatform() 617 { 618 if (strpos($this->_lowerAgent, 'wind') !== false) { 619 $this->_platform = 'win'; 620 } elseif (strpos($this->_lowerAgent, 'mac') !== false) { 621 $this->_platform = 'mac'; 622 } else { 623 $this->_platform = 'unix'; 624 } 625 } 626 627 /** 628 * Return the currently matched platform. 629 * 630 * @return string The user's platform. 631 */ 632 function getPlatform() { 633 return $this->_platform; 634 } 635 636 /** 637 * Sets the current browser. 638 * 639 * @param string $browser The browser to set as current. 640 */ 641 function setBrowser($browser) { 642 $this->_browser = $browser; 643 } 644 645 /** 646 * Retrieve the current browser. 647 * 648 * @return string The current browser. 649 */ 650 function getBrowser() { 651 return $this->_browser; 652 } 653 654 /** 655 * Retrieve the current browser's major version. 656 * 657 * @return integer The current browser's major version. 658 */ 659 function getMajor() { 660 return $this->_majorVersion; 661 } 662 663 /** 664 * Retrieve the current browser's minor version. 665 * @return integer The current browser's minor version. 666 */ 667 function getMinor() { 668 return $this->_minorVersion; 669 } 670 671 /** 672 * Retrieve the current browser's version. 673 * @return string The current browser's version. 674 */ 675 function getVersion() { 676 return $this->_majorVersion . '.' . $this->_minorVersion; 677 } 678 679 /** 680 * Return the full browser agent string. 681 * 682 * @return string The browser agent string. 683 */ 684 function getAgentString() { 685 return $this->_agent; 686 } 687 688 /** 689 * Returns the server protocol in use on the current server. 690 * 691 * @return string The HTTP server protocol version. 692 */ 693 function getHTTPProtocol() 694 { 695 if (isset($_SERVER['SERVER_PROTOCOL'])) { 696 if (($pos = strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) { 697 return substr($_SERVER['SERVER_PROTOCOL'], $pos + 1); 698 } 699 } 700 return null; 701 } 702 703 /** 704 * Set unique behavior for the current browser. 705 * 706 * @param string $quirk The behavior to set. 707 * @param string $value Special behavior parameter. 708 */ 709 function setQuirk($quirk, $value = true) { 710 $this->_quirks[$quirk] = $value; 711 } 712 713 /** 714 * Check unique behavior for the current browser. 715 * 716 * @param string $quirk The behavior to check. 717 * @return boolean Does the browser have the behavior set? 718 */ 719 function hasQuirk($quirk) { 720 return !empty($this->_quirks[$quirk]); 721 } 722 723 /** 724 * Retrieve unique behavior for the current browser. 725 * 726 * @param string $quirk The behavior to retrieve. 727 * @return string The value for the requested behavior. 728 */ 729 function getQuirk($quirk) 730 { 731 return isset($this->_quirks[$quirk]) 732 ? $this->_quirks[$quirk] 733 : null; 734 } 735 736 /** 737 * Set capabilities for the current browser. 738 * 739 * @param string $feature The capability to set. 740 * @param string $value Special capability parameter. 741 */ 742 function setFeature($feature, $value = true) { 743 $this->_features[$feature] = $value; 744 } 745 746 747 /** 748 * Check the current browser capabilities. 749 * @param string $feature The capability to check. 750 * @return boolean Does the browser have the capability set? 751 */ 752 function hasFeature($feature) { 753 return !empty($this->_features[$feature]); 754 } 755 756 /** 757 * Retrieve the current browser capability. 758 * 759 * @param string $feature The capability to retrieve. 760 * @return string The value of the requested capability. 761 */ 762 function getFeature($feature) { 763 return isset($this->_features[$feature]) 764 ? $this->_features[$feature] 765 : null; 766 } 767 768 /** 769 * Determines if a browser can display a given MIME type. 770 * 771 * @param string $mimetype The MIME type to check. 772 * @return boolean True if the browser can display the MIME type. 773 */ 774 function isViewable($mimetype) 775 { 776 $mimetype = strtolower($mimetype); 777 list($type, $subtype) = explode('/', $mimetype); 778 779 if (!empty($this->_accept)) { 780 $wildcard_match = false; 781 782 if (strpos($this->_accept, $mimetype) !== false) { 783 return true; 784 } 785 786 if (strpos($this->_accept, '*/*') !== false) { 787 $wildcard_match = true; 788 if ($type != 'image') { 789 return true; 790 } 791 } 792 793 /* image/jpeg and image/pjpeg *appear* to be the same 794 * entity, but Mozilla doesn't seem to want to accept the 795 * latter. For our purposes, we will treat them the 796 * same. 797 */ 798 if ($this->isBrowser('mozilla') && 799 ($mimetype == 'image/pjpeg') && 800 (strpos($this->_accept, 'image/jpeg') !== false)) { 801 return true; 802 } 803 804 if (!$wildcard_match) { 805 return false; 806 } 807 } 808 809 if (!$this->hasFeature('images') || ($type != 'image')) { 810 return false; 811 } 812 813 return (in_array($subtype, $this->_images)); 814 } 815 816 /** 817 * Determine if the given browser is the same as the current. 818 * 819 * @param string $browser The browser to check. 820 * @return boolean Is the given browser the same as the current? 821 */ 822 function isBrowser($browser) 823 { 824 return ($this->_browser === $browser); 825 } 826 827 /** 828 * Determines if the browser is a robot or not. 829 * 830 * @return boolean True if browser is a known robot. 831 */ 832 function isRobot() 833 { 834 foreach ($this->_robots as $robot) { 835 if (strpos($this->_agent, $robot) !== false) { 836 return true; 837 } 838 } 839 return false; 840 } 841 842 /** 843 * Determine if we are using a secure (SSL) connection. 844 * 845 * @return boolean True if using SSL, false if not. 846 */ 847 function isSSLConnection() 848 { 849 return ((isset($_SERVER['HTTPS']) && 850 ($_SERVER['HTTPS'] == 'on')) || 851 getenv('SSL_PROTOCOL_VERSION')); 852 } 853 }
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Corpo
| Generato il: Mon Oct 19 20:29:27 2009 | Generato con PHPXref 0.7 |