summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2011-10-27 21:07:54 -0400
committerPaul Arthur <paul.arthur@flowerysong.com>2011-10-27 21:07:54 -0400
commita3a087e4043c64349cad9ea52dffce7a964a5656 (patch)
treecf40d043cd7fd4f92922907f0462c1da710fc7eb
parent051805530981acf9ce5e380b790adbb02a234152 (diff)
downloadampache-a3a087e4043c64349cad9ea52dffce7a964a5656.tar.gz
ampache-a3a087e4043c64349cad9ea52dffce7a964a5656.tar.bz2
ampache-a3a087e4043c64349cad9ea52dffce7a964a5656.zip
Update Horde_Browser to latest.
-rw-r--r--admin/system.php2
-rw-r--r--lib/class/stream.class.php1
-rw-r--r--lib/install.php2
-rw-r--r--modules/horde/Browser.php1170
-rw-r--r--play/index.php8
5 files changed, 640 insertions, 543 deletions
diff --git a/admin/system.php b/admin/system.php
index 8592775c..e2fc0faa 100644
--- a/admin/system.php
+++ b/admin/system.php
@@ -46,7 +46,7 @@ switch ($_REQUEST['action']) {
ob_end_clean();
$current = parse_ini_file(Config::get('prefix') . '/config/ampache.cfg.php');
$final = generate_config($current);
- $browser = new Browser();
+ $browser = new Horde_Browser();
$browser->downloadHeaders('ampache.cfg.php','text/plain',false,filesize(Config::get('prefix') . '/config/ampache.cfg.php.dist'));
echo $final;
exit;
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index c64b3a2e..f1765935 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -617,7 +617,6 @@ class Stream {
$min_bitrate = Config::get('min_bit_rate');
$time = time();
$user_sample_rate = Config::get('sample_rate');
- $browser = new Browser();
if (!$song_name) {
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
diff --git a/lib/install.php b/lib/install.php
index 6e88e62f..9c3b2c54 100644
--- a/lib/install.php
+++ b/lib/install.php
@@ -282,7 +282,7 @@ function install_create_config($web_path,$username,$password,$hostname,$database
}
}
else {
- $browser = new Browser();
+ $browser = new Horde_Browser();
$browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, strlen($final));
echo $final;
exit();
diff --git a/modules/horde/Browser.php b/modules/horde/Browser.php
index 637160b2..e42eada0 100644
--- a/modules/horde/Browser.php
+++ b/modules/horde/Browser.php
@@ -1,133 +1,209 @@
<?php
-/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
/**
- * The Browser:: class provides capability information for the current
- * web client. Browser identification is performed by examining the
- * HTTP_USER_AGENT environmental variable provide by the web server.
+ * The Horde_Browser class provides capability information for the current
+ * web client.
*
- * $Horde: framework/Browser/Browser.php,v 1.167 2005/03/02 16:05:15 jan Exp $
+ * Browser identification is performed by examining the HTTP_USER_AGENT
+ * environment variable provided by the web server.
*
- * Copyright 1999-2005 Chuck Hagenbuch <chuck@horde.org>
- * Copyright 1999-2005 Jon Parise <jon@horde.org>
+ * @TODO http://ajaxian.com/archives/parse-user-agent
+ *
+ * Copyright 1999-2011 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ * did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @author Jon Parise <jon@horde.org>
- * @since Horde 1.3
- * @package Horde_Browser
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Jon Parise <jon@horde.org>
+ * @category Horde
+ * @package Browser
*/
-class Browser {
-
+class Horde_Browser
+{
/**
* Major version number.
*
- * @var integer $_majorVersion
+ * @var integer
*/
- var $_majorVersion = 0;
+ protected $_majorVersion = 0;
/**
* Minor version number.
*
- * @var integer $_minorVersion
+ * @var integer
*/
- var $_minorVersion = 0;
+ protected $_minorVersion = 0;
/**
* Browser name.
*
- * @var string $_browser
+ * @var string
*/
- var $_browser = '';
+ protected $_browser = '';
/**
* Full user agent string.
*
- * @var string $_agent
+ * @var string
*/
- var $_agent = '';
+ protected $_agent = '';
/**
* Lower-case user agent string.
*
- * @var string $_agent
+ * @var string
*/
- var $_lowerAgent = '';
+ protected $_lowerAgent = '';
/**
* HTTP_ACCEPT string
*
- * @var string $_accept
+ * @var string
*/
- var $_accept = '';
+ protected $_accept = '';
/**
* Platform the browser is running on.
*
- * @var string $_platform
+ * @var string
*/
- var $_platform = '';
+ protected $_platform = '';
/**
* Known robots.
*
- * @var array $_robots
+ * @var array
*/
- var $_robots = array(
+ protected $_robotAgents = array(
/* The most common ones. */
'Googlebot',
'msnbot',
+ 'bingbot',
'Slurp',
'Yahoo',
/* The rest alphabetically. */
+ 'appie',
'Arachnoidea',
'ArchitextSpider',
'Ask Jeeves',
'B-l-i-t-z-Bot',
+ 'Baiduspider',
+ 'BecomeBot',
+ 'cfetch',
'ConveraCrawler',
'ExtractorPro',
'FAST-WebCrawler',
'FDSE robot',
'fido',
+ 'findlinks',
+ 'Francis',
'geckobot',
'Gigabot',
'Girafabot',
'grub-client',
'Gulliver',
+ 'HTTrack',
'ia_archiver',
+ 'iaskspider',
+ 'iCCrawler',
'InfoSeek',
+ 'kinjabot',
'KIT-Fireball',
+ 'larbin',
'LEIA',
+ 'lmspider',
+ 'lwp-trivial',
'Lycos_Spider',
'Mediapartners-Google',
+ 'MSRBOT',
'MuscatFerret',
'NaverBot',
+ 'OmniExplorer_Bot',
'polybot',
'Pompos',
+ 'RufusBot',
'Scooter',
+ 'Seekbot',
+ 'sogou spider',
+ 'sproose',
'Teoma',
+ 'TheSuBot',
'TurnitinBot',
+ 'Twiceler',
'Ultraseek',
+ 'Vagabondo/Kliksafe',
'ViolaBot',
+ 'voyager',
+ 'W3C-checklink',
'webbandit',
'www.almaden.ibm.com/cs/crawler',
+ 'yacy',
'ZyBorg',
);
/**
+ * Regexp for matching those robot strings.
+ *
+ * @var string
+ */
+ protected $_robotAgentRegexp = null;
+
+ /**
+ * List of mobile user agents.
+ *
+ * Browsers like Mobile Safari (iPhone, iPod Touch) are much more
+ * full featured than OpenWave style browsers. This makes it dicey
+ * in some cases to treat all "mobile" browsers the same way.
+ *
+ * @TODO This list is not used in isMobile yet nor does it provide
+ * the same results as isMobile(). It is here for reference and
+ * future work.
+ */
+ protected $_mobileAgents = array(
+ 'Blackberry',
+ 'Blazer',
+ 'Handspring',
+ 'iPhone',
+ 'iPod',
+ 'Kyocera',
+ 'LG',
+ 'Motorola',
+ 'Nokia',
+ 'Palm',
+ 'PlayStation Portable',
+ 'Samsung',
+ 'Smartphone',
+ 'SonyEricsson',
+ 'Symbian',
+ 'WAP',
+ 'Windows CE',
+ );
+
+ /**
+ * List of televison user agents.
+ *
+ * @TODO This list is not yet used anywhere. It is here for future
+ * media-type differentiation.
+ */
+ protected $_tvAgents = array(
+ 'Nintendo Wii',
+ 'Playstation 3',
+ 'WebTV',
+ );
+
+ /**
* Is this a mobile browser?
*
- * @var boolean $_mobile
+ * @var boolean
*/
- var $_mobile = false;
+ protected $_mobile = false;
/**
* Features.
*
- * @var array $_features
+ * @var array
*/
- var $_features = array(
+ protected $_features = array(
'html' => true,
'hdml' => false,
'wml' => false,
@@ -145,14 +221,20 @@ class Browser {
'optgroup' => false,
'xmlhttpreq' => false,
'cite' => false,
+ // RFC 2397
+ 'dataurl' => false,
+ // Webkit browsers
+ 'ischrome' => false,
+ 'iskonqueror' => false,
+ 'issafari' => false,
);
/**
* Quirks
*
- * @var array $_quirks
+ * @var array
*/
- var $_quirks = array(
+ protected $_quirks = array(
'avoid_popup_windows' => false,
'break_disposition_header' => false,
'break_disposition_filename' => false,
@@ -169,71 +251,36 @@ class Browser {
'png_transparency' => false,
'scrollbar_in_way' => false,
'scroll_tds' => false,
+ 'windowed_controls' => false,
);
/**
* List of viewable image MIME subtypes.
* This list of viewable images works for IE and Netscape/Mozilla.
*
- * @var array $_images
+ * @var array
*/
- var $_images = array('jpeg', 'gif', 'png', 'pjpeg', 'x-png', 'bmp');
-
- /**
+ protected $_images = array('jpeg', 'gif', 'png', 'pjpeg', 'x-png', 'bmp');
/**
- * Returns a reference to the global Browser object, only creating it
- * if it doesn't already exist.
- *
- * This method must be invoked as:
- * $browser = &Browser::singleton([$userAgent[, $accept]]);
- *
- * @access public
- *
- * @param optional string $userAgent The browser string to parse.
- * @param optional string $accept The HTTP_ACCEPT settings to use.
+ * Creates a browser instance (Constructor).
*
- * @return object Browser The Browser object.
+ * @param string $userAgent The browser string to parse.
+ * @param string $accept The HTTP_ACCEPT settings to use.
*/
- function &singleton($userAgent = null, $accept = null)
- {
- static $instances;
-
- if (!isset($instances)) {
- $instances = array();
- }
-
- $signature = serialize(array($userAgent, $accept));
- if (empty($instances[$signature])) {
- $instances[$signature] = new Browser($userAgent, $accept);
- }
-
- return $instances[$signature];
- }
-
- /**
- * Create a browser instance (Constructor).
- *
- * @access public
- *
- * @param optional string $userAgent The browser string to parse.
- * @param optional string $accept The HTTP_ACCEPT settings to use.
- */
- function Browser($userAgent = null, $accept = null)
+ public function __construct($userAgent = null, $accept = null)
{
$this->match($userAgent, $accept);
}
/**
- * Parses the user agent string and inititializes the object with
- * all the known features and quirks for the given browser.
- *
- * @access public
+ * Parses the user agent string and inititializes the object with all the
+ * known features and quirks for the given browser.
*
- * @param optional string $userAgent The browser string to parse.
- * @param optional string $accept The HTTP_ACCEPT settings to use.
+ * @param string $userAgent The browser string to parse.
+ * @param string $accept The HTTP_ACCEPT settings to use.
*/
- function match($userAgent = null, $accept = null)
+ public function match($userAgent = null, $accept = null)
{
// Set our agent string.
if (is_null($userAgent)) {
@@ -243,321 +290,422 @@ class Browser {
} else {
$this->_agent = $userAgent;
}
- $this->_lowerAgent = strtolower($this->_agent);
+ $this->_lowerAgent = Horde_String::lower($this->_agent);
// Set our accept string.
if (is_null($accept)) {
if (isset($_SERVER['HTTP_ACCEPT'])) {
- $this->_accept = strtolower(trim($_SERVER['HTTP_ACCEPT']));
+ $this->_accept = Horde_String::lower(trim($_SERVER['HTTP_ACCEPT']));
}
} else {
- $this->_accept = strtolower($accept);
+ $this->_accept = Horde_String::lower($accept);
}
// Check for UTF support.
if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
- $this->setFeature('utf', strpos(strtolower($_SERVER['HTTP_ACCEPT_CHARSET']), 'utf') !== false);
+ $this->setFeature('utf', strpos(Horde_String::lower($_SERVER['HTTP_ACCEPT_CHARSET']), 'utf') !== false);
}
- if (!empty($this->_agent)) {
- $this->_setPlatform();
+ if (empty($this->_agent)) {
+ return;
+ }
- if (preg_match('|Opera[/ ]([0-9.]+)|', $this->_agent, $version)) {
- $this->setBrowser('opera');
- list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
- $this->setFeature('javascript', true);
- $this->setQuirk('no_filename_spaces');
+ $this->_setPlatform();
+
+ // Use local scope for frequently accessed variables.
+ $agent = $this->_agent;
+ $lowerAgent = $this->_lowerAgent;
+
+ if (strpos($lowerAgent, 'iemobile') !== false ||
+ strpos($lowerAgent, 'mobileexplorer') !== false ||
+ strpos($lowerAgent, 'openwave') !== false ||
+ strpos($lowerAgent, 'opera mini') !== false ||
+ strpos($lowerAgent, 'operamini') !== false) {
+ $this->setFeature('frames', false);
+ $this->setFeature('javascript', false);
+ $this->setQuirk('avoid_popup_windows');
+ $this->setMobile(true);
+ } elseif (preg_match('|Opera[/ ]([0-9.]+)|', $agent, $version)) {
+ $this->setBrowser('opera');
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
+ $this->setFeature('javascript');
+ $this->setQuirk('no_filename_spaces');
+
+ /* Opera Mobile reports its screen resolution in the user
+ * agent strings. */
+ if (preg_match('/; (120x160|240x280|240x320|320x320)\)/', $agent)) {
+ $this->setMobile(true);
+ }
- switch ($this->_majorVersion) {
- case 7:
- $this->setFeature('dom');
- $this->setFeature('iframes');
- $this->setFeature('accesskey');
- $this->setFeature('optgroup');
- $this->setQuirk('double_linebreak_textarea');
- break;
+ if ($this->_majorVersion >= 7) {
+ if ($this->_majorVersion >= 8) {
+ $this->setFeature('xmlhttpreq');
+ $this->setFeature('javascript', 1.5);
}
- } elseif (strpos($this->_lowerAgent, 'elaine/') !== false ||
- strpos($this->_lowerAgent, 'palmsource') !== false ||
- strpos($this->_lowerAgent, 'digital paths') !== false) {
- $this->setBrowser('palm');
- $this->setFeature('images', false);
- $this->setFeature('frames', false);
- $this->setFeature('javascript', false);
- $this->setQuirk('avoid_popup_windows');
- $this->_mobile = true;
- } elseif ((preg_match('|MSIE ([0-9.]+)|', $this->_agent, $version)) ||
- (preg_match('|Internet Explorer/([0-9.]+)|', $this->_agent, $version))) {
+ if ($this->_majorVersion >= 9) {
+ $this->setFeature('dataurl', 4100);
+ if ($this->_minorVersion >= 5) {
+ $this->setFeature('rte');
+ }
+ }
+ $this->setFeature('dom');
+ $this->setFeature('iframes');
+ $this->setFeature('accesskey');
+ $this->setFeature('optgroup');
+ $this->setQuirk('double_linebreak_textarea');
+ }
+ } elseif (strpos($lowerAgent, 'elaine/') !== false ||
+ strpos($lowerAgent, 'palmsource') !== false ||
+ strpos($lowerAgent, 'digital paths') !== false) {
+ $this->setBrowser('palm');
+ $this->setFeature('images', false);
+ $this->setFeature('frames', false);
+ $this->setFeature('javascript', false);
+ $this->setQuirk('avoid_popup_windows');
+ $this->setMobile(true);
+ } elseif ((preg_match('|MSIE ([0-9.]+)|', $agent, $version)) ||
+ (preg_match('|Internet Explorer/([0-9.]+)|', $agent, $version))) {
+ $this->setBrowser('msie');
+ $this->setQuirk('cache_ssl_downloads');
+ $this->setQuirk('cache_same_url');
+ $this->setQuirk('break_disposition_filename');
+
+ if (strpos($version[1], '.') !== false) {
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
+ } else {
+ $this->_majorVersion = $version[1];
+ $this->_minorVersion = 0;
+ }
- $this->setBrowser('msie');
- $this->setQuirk('cache_ssl_downloads');
- $this->setQuirk('cache_same_url');
- $this->setQuirk('break_disposition_filename');
+ /* IE (< 7) on Windows does not support alpha transparency
+ * in PNG images. */
+ if (($this->_majorVersion < 7) &&
+ preg_match('/windows/i', $agent)) {
+ $this->setQuirk('png_transparency');
+ }
- if (strpos($version[1], '.') !== false) {
- list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
- } else {
- $this->_majorVersion = $version[1];
- $this->_minorVersion = 0;
- }
+ /* Some Handhelds have their screen resolution in the user
+ * agent string, which we can use to look for mobile
+ * agents. */
+ if (preg_match('/; (120x160|240x280|240x320|320x320)\)/', $agent)) {
+ $this->setMobile(true);
+ }
- /* IE on Windows does not support alpha transparency in PNG
- * images. */
- if (preg_match('/windows/i', $this->_agent)) {
- $this->setQuirk('png_transparency');
- }
+ $this->setFeature('xmlhttpreq');
- /* IE 6 (pre-SP1) and 5.5 (pre-SP1) has buggy compression.
- * The versions affected are as follows:
- * 6.00.2462.0000 Internet Explorer 6 Public Preview (Beta)
- * 6.00.2479.0006 Internet Explorer 6 Public Preview (Beta)
- Refresh
- * 6.00.2600.0000 Internet Explorer 6 (Windows XP)
- * 5.50.3825.1300 Internet Explorer 5.5 Developer Preview (Beta)
- * 5.50.4030.2400 Internet Explorer 5.5 & Internet Tools Beta
- * 5.50.4134.0100 Internet Explorer 5.5 for Windows Me (4.90.3000)
- * 5.50.4134.0600 Internet Explorer 5.5
- * 5.50.4308.2900 Internet Explorer 5.5 Advanced Security Privacy Beta
- *
- * See:
- * ====
- * http://support.microsoft.com/kb/164539;
- * http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312496)
- * http://support.microsoft.com/default.aspx?scid=kb;en-us;Q313712
- */
- $ie_vers = $this->getIEVersion();
- $buggy_list = array(
- '6,00,2462,0000', '6,00,2479,0006', '6,00,2600,0000',
- '5,50,3825,1300', '5,50,4030,2400', '5,50,4134,0100',
- '5,50,4134,0600', '5,50,4308,2900'
- );
- if (!is_null($ie_vers) && in_array($ie_vers, $buggy_list)) {
- $this->setQuirk('buggy_compression');
- }
+ switch ($this->_majorVersion) {
+ default:
+ case 9:
+ case 8:
+ $this->setFeature('javascript', 1.4);
+ $this->setFeature('dom');
+ $this->setFeature('iframes');
+ $this->setFeature('utf');
+ $this->setFeature('rte');
+ $this->setFeature('homepage');
+ $this->setFeature('accesskey');
+ $this->setFeature('optgroup');
+ $this->setFeature('dataurl', 32768);
+ break;
- /* Some Handhelds have their screen resolution in the
- * user agent string, which we can use to look for
- * mobile agents. */
- if (preg_match('/; (120x160|240x280|240x320)\)/', $this->_agent)) {
- $this->_mobile = true;
- }
+ case 7:
+ $this->setFeature('javascript', 1.4);
+ $this->setFeature('dom');
+ $this->setFeature('iframes');
+ $this->setFeature('utf');
+ $this->setFeature('rte');
+ $this->setFeature('homepage');
+ $this->setFeature('accesskey');
+ $this->setFeature('optgroup');
+ break;
- switch ($this->_majorVersion) {
- case 6:
+ case 6:
+ $this->setFeature('javascript', 1.4);
+ $this->setFeature('dom');
+ $this->setFeature('iframes');
+ $this->setFeature('utf');
+ $this->setFeature('rte');
+ $this->setFeature('homepage');
+ $this->setFeature('accesskey');
+ $this->setFeature('optgroup');
+ $this->setQuirk('scrollbar_in_way');
+ $this->setQuirk('broken_multipart_form');
+ $this->setQuirk('windowed_controls');
+ break;
+
+ case 5:
+ if ($this->getPlatform() == 'mac') {
+ $this->setFeature('javascript', 1.2);
+ $this->setFeature('optgroup');
+ $this->setFeature('xmlhttpreq', false);
+ } else {
+ // MSIE 5 for Windows.
$this->setFeature('javascript', 1.4);
$this->setFeature('dom');
- $this->setFeature('iframes');
- $this->setFeature('utf');
- $this->setFeature('rte');
- $this->setFeature('homepage');
- $this->setFeature('accesskey');
- $this->setFeature('optgroup');
- $this->setFeature('xmlhttpreq');
- $this->setQuirk('scrollbar_in_way');
+ if ($this->_minorVersion >= 5) {
+ $this->setFeature('rte');
+ $this->setQuirk('windowed_controls');
+ }
+ }
+ $this->setFeature('iframes');
+ $this->setFeature('utf');
+ $this->setFeature('homepage');
+ $this->setFeature('accesskey');
+ if ($this->_minorVersion == 5) {
+ $this->setQuirk('break_disposition_header');
$this->setQuirk('broken_multipart_form');
- break;
+ }
+ break;
- case 5:
- if ($this->getPlatform() == 'mac') {
- $this->setFeature('javascript', 1.2);
- $this->setFeature('optgroup');
- } else {
- // MSIE 5 for Windows.
- $this->setFeature('javascript', 1.4);
- $this->setFeature('dom');
- $this->setFeature('xmlhttpreq');
- if ($this->_minorVersion >= 5) {
- $this->setFeature('rte');
- }
- }
- $this->setFeature('iframes');
+ case 4:
+ $this->setFeature('javascript', 1.2);
+ $this->setFeature('accesskey');
+ $this->setFeature('xmlhttpreq', false);
+ if ($this->_minorVersion > 0) {
$this->setFeature('utf');
- $this->setFeature('homepage');
- $this->setFeature('accesskey');
- if ($this->_minorVersion == 5) {
- $this->setQuirk('break_disposition_header');
- $this->setQuirk('broken_multipart_form');
- }
- break;
-
- case 4:
- $this->setFeature('javascript', 1.2);
- $this->setFeature('accesskey');
- if ($this->_minorVersion > 0) {
- $this->setFeature('utf');
- }
- break;
-
- case 3:
- $this->setFeature('javascript', 1.1);
- $this->setQuirk('avoid_popup_windows');
- break;
}
- } elseif (preg_match('|ANTFresco/([0-9]+)|', $this->_agent, $version)) {
- $this->setBrowser('fresco');
+ break;
+
+ case 3:
$this->setFeature('javascript', 1.1);
$this->setQuirk('avoid_popup_windows');
- } elseif (strpos($this->_lowerAgent, 'avantgo') !== false) {
- $this->setBrowser('avantgo');
- $this->_mobile = true;
- } elseif (preg_match('|Konqueror/([0-9]+)|', $this->_agent, $version) ||
- preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $this->_agent, $version)) {
- // Konqueror and Apple's Safari both use the KHTML
- // rendering engine.
- $this->setBrowser('konqueror');
- $this->setQuirk('empty_file_input_value');
- $this->setQuirk('no_hidden_overflow_tables');
- $this->_majorVersion = $version[1];
- if (isset($version[2])) {
- $this->_minorVersion = $version[2];
+ $this->setFeature('xmlhttpreq', false);
+ break;
+ }
+ } elseif (preg_match('|ANTFresco/([0-9]+)|', $agent, $version)) {
+ $this->setBrowser('fresco');
+ $this->setFeature('javascript', 1.1);
+ $this->setQuirk('avoid_popup_windows');
+ } elseif (strpos($lowerAgent, 'avantgo') !== false) {
+ $this->setBrowser('avantgo');
+ $this->setMobile(true);
+ } elseif (preg_match('|Konqueror/([0-9]+)\.?([0-9]+)?|', $agent, $version) ||
+ preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $agent, $version)) {
+ $this->setBrowser('webkit');
+ $this->setQuirk('empty_file_input_value');
+ $this->setQuirk('no_hidden_overflow_tables');
+ $this->setFeature('dataurl');
+
+ if (strpos($agent, 'Mobile') !== false ||
+ strpos($agent, 'NokiaN') !== false ||
+ strpos($agent, 'SymbianOS') !== false) {
+ // WebKit Mobile
+ $this->setMobile(true);
+ }
+
+ $this->_majorVersion = $version[1];
+ if (isset($version[2])) {
+ $this->_minorVersion = $version[2];
+ }
+
+ if (stripos($agent, 'Chrome/') !== false) {
+ // Google Chrome.
+ $this->setFeature('ischrome');
+ $this->setFeature('rte');
+ $this->setFeature('utf');
+ $this->setFeature('javascript', 1.4);
+ $this->setFeature('dom');
+ $this->setFeature('iframes');
+ $this->setFeature('accesskey');
+ $this->setFeature('xmlhttpreq');
+ $this->setQuirk('empty_file_input_value', 0);
+
+ if (preg_match('|Chrome/([0-9.]+)|i', $agent, $version_string)) {
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version_string[1], 2);
+ }
+ } elseif (stripos($agent, 'Safari/') !== false &&
+ $this->_majorVersion >= 60) {
+ // Safari.
+ $this->setFeature('issafari');
+
+ // Truly annoying - Safari did not start putting real version
+ // numbers until Version 3.
+ if (preg_match('|Version/([0-9.]+)|', $agent, $version_string)) {
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version_string[1], 2);
+ $this->_minorVersion = intval($this->_minorVersion);
+ $this->setFeature('rte');
+ } elseif ($this->_majorVersion >= 412) {
+ $this->_majorVersion = 2;
+ $this->_minorVersion = 0;
+ } else {
+ if ($this->_majorVersion >= 312) {
+ $this->_minorVersion = 3;
+ } elseif ($this->_majorVersion >= 124) {
+ $this->_minorVersion = 2;
+ } else {
+ $this->_minorVersion = 0;
+ }
+ $this->_majorVersion = 1;
}
- if (strpos($this->_agent, 'Safari') !== false &&
- $this->_majorVersion >= 60) {
- // Safari.
- $this->setFeature('utf');
- $this->setFeature('javascript', 1.4);
+ $this->setFeature('utf');
+ $this->setFeature('javascript', 1.4);
+ $this->setFeature('dom');
+ $this->setFeature('iframes');
+ if ($this->_majorVersion > 1 || $this->_minorVersion > 2) {
+ // As of Safari 1.3
+ $this->setFeature('accesskey');
+ $this->setFeature('xmlhttpreq');
+ }
+ } else {
+ // Konqueror.
+ $this->setFeature('javascript', 1.1);
+ $this->setFeature('iskonqueror');
+ switch ($this->_majorVersion) {
+ case 4:
+ case 3:
$this->setFeature('dom');
$this->setFeature('iframes');
- if ($this->_majorVersion > 125 ||
- ($this->_majorVersion == 125 &&
- $this->_minorVersion >= 1)) {
- $this->setFeature('utf');
+ if ($this->_minorVersion >= 5 || $this->_majorVersion == 4) {
$this->setFeature('accesskey');
$this->setFeature('xmlhttpreq');
}
- } else {
- // Konqueror.
- $this->setFeature('javascript', 1.1);
- switch ($this->_majorVersion) {
- case 3:
- $this->setFeature('dom');
+ break;
+ }
+ }
+ } elseif (preg_match('|Mozilla/([0-9.]+)|', $agent, $version)) {
+ $this->setBrowser('mozilla');
+ $this->setQuirk('must_cache_forms');
+
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
+ switch ($this->_majorVersion) {
+ case 5:
+ if ($this->getPlatform() == 'win') {
+ $this->setQuirk('break_disposition_filename');
+ }
+ $this->setFeature('javascript', 1.4);
+ $this->setFeature('dom');
+ $this->setFeature('accesskey');
+ $this->setFeature('optgroup');
+ $this->setFeature('xmlhttpreq');
+ $this->setFeature('cite');
+ if (preg_match('|rv:(.*)\)|', $agent, $revision)) {
+ if ($revision[1] >= 1) {
$this->setFeature('iframes');
- break;
}
- }
- } elseif (preg_match('|Mozilla/([0-9.]+)|', $this->_agent, $version)) {
- $this->setBrowser('mozilla');
- $this->setQuirk('must_cache_forms');
-
- list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
- switch ($this->_majorVersion) {
- case 5:
- if ($this->getPlatform() == 'win') {
- $this->setQuirk('break_disposition_filename');
+ if ($revision[1] >= 1.3) {
+ $this->setFeature('rte');
}
- $this->setFeature('javascript', 1.4);
- $this->setFeature('dom');
- $this->setFeature('accesskey');
- $this->setFeature('optgroup');
- $this->setFeature('xmlhttpreq');
- $this->setFeature('cite');
- if (preg_match('|rv:(.*)\)|', $this->_agent, $revision)) {
- if ($revision[1] >= 1) {
- $this->setFeature('iframes');
- }
- if ($revision[1] >= 1.3) {
- $this->setFeature('rte');
- }
+ if (version_compare($revision[1], '1.8.1', '>=')) {
+ $this->setFeature('dataurl');
}
- break;
+ }
+ break;
- case 4:
- $this->setFeature('javascript', 1.3);
- $this->setQuirk('buggy_compression');
- break;
+ case 4:
+ $this->setFeature('javascript', 1.3);
+ $this->setQuirk('buggy_compression');
+ break;
- case 3:
- default:
- $this->setFeature('javascript', 1);
- $this->setQuirk('buggy_compression');
- break;
- }
- } elseif (preg_match('|Lynx/([0-9]+)|', $this->_agent, $version)) {
- $this->setBrowser('lynx');
- $this->setFeature('images', false);
- $this->setFeature('frames', false);
- $this->setFeature('javascript', false);
- $this->setQuirk('avoid_popup_windows');
- } elseif (preg_match('|Links \(([0-9]+)|', $this->_agent, $version)) {
- $this->setBrowser('links');
- $this->setFeature('images', false);
- $this->setFeature('frames', false);
- $this->setFeature('javascript', false);
- $this->setQuirk('avoid_popup_windows');
- } elseif (preg_match('|HotJava/([0-9]+)|', $this->_agent, $version)) {
- $this->setBrowser('hotjava');
- $this->setFeature('javascript', false);
- } elseif (strpos($this->_agent, 'UP/') !== false ||
- strpos($this->_agent, 'UP.B') !== false ||
- strpos($this->_agent, 'UP.L') !== false) {
- $this->setBrowser('up');
- $this->setFeature('html', false);
- $this->setFeature('javascript', false);
- $this->setFeature('hdml');
- $this->setFeature('wml');
-
- if (strpos($this->_agent, 'GUI') !== false &&
- strpos($this->_agent, 'UP.Link') !== false) {
- /* The device accepts Openwave GUI extensions for
- * WML 1.3. Non-UP.Link gateways sometimes have
- * problems, so exclude them. */
- $this->setQuirk('ow_gui_1.3');
- }
- $this->_mobile = true;
- } elseif (strpos($this->_agent, 'Xiino/') !== false) {
- $this->setBrowser('xiino');
- $this->setFeature('hdml');
- $this->setFeature('wml');
- $this->_mobile = true;
- } elseif (strpos($this->_agent, 'Palmscape/') !== false) {
- $this->setBrowser('palmscape');
- $this->setFeature('javascript', false);
- $this->setFeature('hdml');
- $this->setFeature('wml');
- $this->_mobile = true;
- } elseif (strpos($this->_agent, 'Nokia') !== false) {
- $this->setBrowser('nokia');
- $this->setFeature('html', false);
- $this->setFeature('wml');
- $this->setFeature('xhtml');
- $this->_mobile = true;
- } elseif (strpos($this->_agent, 'Ericsson') !== false) {
- $this->setBrowser('ericsson');
- $this->setFeature('html', false);
- $this->setFeature('wml');
- $this->_mobile = true;
- } elseif (strpos($this->_lowerAgent, 'wap') !== false) {
- $this->setBrowser('wap');
- $this->setFeature('html', false);
- $this->setFeature('javascript', false);
- $this->setFeature('hdml');
- $this->setFeature('wml');
- $this->_mobile = true;
- } elseif (strpos($this->_lowerAgent, 'docomo') !== false ||
- strpos($this->_lowerAgent, 'portalmmm') !== false) {
- $this->setBrowser('imode');
- $this->setFeature('images', false);
- $this->_mobile = true;
- } elseif (strpos($this->_lowerAgent, 'j-') !== false) {
- $this->setBrowser('mml');
- $this->_mobile = true;
+ case 3:
+ default:
+ $this->setFeature('javascript', 1);
+ $this->setQuirk('buggy_compression');
+ break;
}
+ } elseif (preg_match('|Lynx/([0-9]+)|', $agent, $version)) {
+ $this->setBrowser('lynx');
+ $this->setFeature('images', false);
+ $this->setFeature('frames', false);
+ $this->setFeature('javascript', false);
+ $this->setQuirk('avoid_popup_windows');
+ } elseif (preg_match('|Links \(([0-9]+)|', $agent, $version)) {
+ $this->setBrowser('links');
+ $this->setFeature('images', false);
+ $this->setFeature('frames', false);
+ $this->setFeature('javascript', false);
+ $this->setQuirk('avoid_popup_windows');
+ } elseif (preg_match('|HotJava/([0-9]+)|', $agent, $version)) {
+ $this->setBrowser('hotjava');
+ $this->setFeature('javascript', false);
+ } elseif (strpos($agent, 'UP/') !== false ||
+ strpos($agent, 'UP.B') !== false ||
+ strpos($agent, 'UP.L') !== false) {
+ $this->setBrowser('up');
+ $this->setFeature('html', false);
+ $this->setFeature('javascript', false);
+ $this->setFeature('hdml');
+ $this->setFeature('wml');
+
+ if (strpos($agent, 'GUI') !== false &&
+ strpos($agent, 'UP.Link') !== false) {
+ /* The device accepts Openwave GUI extensions for WML
+ * 1.3. Non-UP.Link gateways sometimes have problems,
+ * so exclude them. */
+ $this->setQuirk('ow_gui_1.3');
+ }
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'Xiino/') !== false) {
+ $this->setBrowser('xiino');
+ $this->setFeature('hdml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'Palmscape/') !== false) {
+ $this->setBrowser('palmscape');
+ $this->setFeature('javascript', false);
+ $this->setFeature('hdml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'Nokia') !== false) {
+ $this->setBrowser('nokia');
+ $this->setFeature('html', false);
+ $this->setFeature('wml');
+ $this->setFeature('xhtml');
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'Ericsson') !== false) {
+ $this->setBrowser('ericsson');
+ $this->setFeature('html', false);
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'Grundig') !== false) {
+ $this->setBrowser('grundig');
+ $this->setFeature('xhtml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'NetFront') !== false) {
+ $this->setBrowser('netfront');
+ $this->setFeature('xhtml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($lowerAgent, 'wap') !== false) {
+ $this->setBrowser('wap');
+ $this->setFeature('html', false);
+ $this->setFeature('javascript', false);
+ $this->setFeature('hdml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($lowerAgent, 'docomo') !== false ||
+ strpos($lowerAgent, 'portalmmm') !== false) {
+ $this->setBrowser('imode');
+ $this->setFeature('images', false);
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'BlackBerry') !== false) {
+ $this->setBrowser('blackberry');
+ $this->setFeature('html', false);
+ $this->setFeature('javascript', false);
+ $this->setFeature('hdml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($agent, 'MOT-') !== false) {
+ $this->setBrowser('motorola');
+ $this->setFeature('html', false);
+ $this->setFeature('javascript', false);
+ $this->setFeature('hdml');
+ $this->setFeature('wml');
+ $this->setMobile(true);
+ } elseif (strpos($lowerAgent, 'j-') !== false) {
+ $this->setBrowser('mml');
+ $this->setMobile(true);
}
}
/**
- * Match the platform of the browser.
- *
- * This is a pretty simplistic implementation, but it's intended
- * to let us tell what line breaks to send, so it's good enough
- * for its purpose.
+ * Matches the platform of the browser.
*
- * @access public
- *
- * @since Horde 2.2
+ * This is a pretty simplistic implementation, but it's intended to let us
+ * tell what line breaks to send, so it's good enough for its purpose.
*/
- function _setPlatform()
+ protected function _setPlatform()
{
if (strpos($this->_lowerAgent, 'wind') !== false) {
$this->_platform = 'win';
@@ -569,13 +717,11 @@ class Browser {
}
/**
- * Return the currently matched platform.
+ * Returns the currently matched platform.
*
* @return string The user's platform.
- *
- * @since Horde 2.2
*/
- function getPlatform()
+ public function getPlatform()
{
return $this->_platform;
}
@@ -583,153 +729,144 @@ class Browser {
/**
* Sets the current browser.
*
- * @access public
- *
* @param string $browser The browser to set as current.
*/
- function setBrowser($browser)
+ public function setBrowser($browser)
{
$this->_browser = $browser;
}
/**
- * Determine if the given browser is the same as the current.
- *
- * @access public
+ * Determines if the given browser is the same as the current.
*
* @param string $browser The browser to check.
*
* @return boolean Is the given browser the same as the current?
*/
- function isBrowser($browser)
+ public function isBrowser($browser)
{
return ($this->_browser === $browser);
}
/**
- * Do we consider the current browser to be a mobile device?
+ * Set this browser as a mobile device.
+ *
+ * @param boolean $mobile True if the browser is a mobile device.
+ */
+ public function setMobile($mobile)
+ {
+ $this->_mobile = (bool)$mobile;
+ }
+
+ /**
+ * Is the current browser to be a mobile device?
*
* @return boolean True if we do, false if we don't.
*/
- function isMobile()
+ public function isMobile()
{
return $this->_mobile;
}
/**
- * Determines if the browser is a robot or not.
- *
- * @access public
+ * Is the browser a robot?
*
* @return boolean True if browser is a known robot.
*/
- function isRobot()
+ public function isRobot()
{
- foreach ($this->_robots as $robot) {
- if (strpos($this->_agent, $robot) !== false) {
- return true;
+ if (is_null($this->_robotAgentRegexp)) {
+ $regex = array();
+ foreach ($this->_robotAgents as $r) {
+ $regex[] = preg_quote($r, '/');
}
+ $this->_robotAgentRegexp = '/' . implode('|', $regex) . '/';
}
- return false;
+
+ return (bool)preg_match($this->_robotAgentRegexp, $this->_agent);
}
/**
- * Retrieve the current browser.
- *
- * @access public
+ * Returns the current browser.
*
* @return string The current browser.
*/
- function getBrowser()
+ public function getBrowser()
{
return $this->_browser;
}
/**
- * Retrieve the current browser's major version.
- *
- * @access public
+ * Returns the current browser's major version.
*
* @return integer The current browser's major version.
*/
- function getMajor()
+ public function getMajor()
{
return $this->_majorVersion;
}
/**
- * Retrieve the current browser's minor version.
- *
- * @access public
+ * Returns the current browser's minor version.
*
* @return integer The current browser's minor version.
*/
- function getMinor()
+ public function getMinor()
{
return $this->_minorVersion;
}
/**
- * Retrieve the current browser's version.
- *
- * @access public
+ * Returns the current browser's version.
*
* @return string The current browser's version.
*/
- function getVersion()
+ public function getVersion()
{
return $this->_majorVersion . '.' . $this->_minorVersion;
}
/**
- * Return the full browser agent string.
- *
- * @access public
+ * Returns the full browser agent string.
*
* @return string The browser agent string.
*/
- function getAgentString()
+ public function getAgentString()
{
return $this->_agent;
}
/**
- * Set unique behavior for the current browser.
- *
- * @access public
+ * Sets unique behavior for the current browser.
*
- * @param string $quirk The behavior to set.
- * @param optional string $value Special behavior parameter.
+ * @param string $quirk The behavior to set.
+ * @param string $value Special behavior parameter.
*/
- function setQuirk($quirk, $value = true)
+ public function setQuirk($quirk, $value = true)
{
$this->_quirks[$quirk] = $value;
}
/**
- * Check unique behavior for the current browser.
- *
- * @access public
+ * Checks unique behavior for the current browser.
*
* @param string $quirk The behavior to check.
*
* @return boolean Does the browser have the behavior set?
*/
- function hasQuirk($quirk)
+ public function hasQuirk($quirk)
{
return !empty($this->_quirks[$quirk]);
}
/**
- * Retreive unique behavior for the current browser.
- *
- * @access public
+ * Returns unique behavior for the current browser.
*
- * @param string $quirk The behavior to retreive.
+ * @param string $quirk The behavior to retrieve.
*
* @return string The value for the requested behavior.
*/
- function getQuirk($quirk)
+ public function getQuirk($quirk)
{
return isset($this->_quirks[$quirk])
? $this->_quirks[$quirk]
@@ -737,42 +874,36 @@ class Browser {
}
/**
- * Set capabilities for the current browser.
+ * Sets capabilities for the current browser.
*
- * @access public
- *
- * @param string $feature The capability to set.
- * @param optional string $value Special capability parameter.
+ * @param string $feature The capability to set.
+ * @param string $value Special capability parameter.
*/
- function setFeature($feature, $value = true)
+ public function setFeature($feature, $value = true)
{
$this->_features[$feature] = $value;
}
/**
- * Check the current browser capabilities.
- *
- * @access public
+ * Checks the current browser capabilities.
*
* @param string $feature The capability to check.
*
* @return boolean Does the browser have the capability set?
*/
- function hasFeature($feature)
+ public function hasFeature($feature)
{
return !empty($this->_features[$feature]);
}
/**
- * Retreive the current browser capability.
+ * Returns the current browser capability.
*
- * @access public
- *
- * @param string $feature The capability to retreive.
+ * @param string $feature The capability to retrieve.
*
* @return string The value of the requested capability.
*/
- function getFeature($feature)
+ public function getFeature($feature)
{
return isset($this->_features[$feature])
? $this->_features[$feature]
@@ -780,13 +911,11 @@ class Browser {
}
/**
- * Determine if we are using a secure (SSL) connection.
- *
- * @access public
+ * Determines if we are using a secure (SSL) connection.
*
* @return boolean True if using SSL, false if not.
*/
- function usingSSLConnection()
+ public function usingSSLConnection()
{
return ((isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on')) ||
@@ -796,11 +925,9 @@ class Browser {
/**
* Returns the server protocol in use on the current server.
*
- * @access public
- *
* @return string The HTTP server protocol version.
*/
- function getHTTPProtocol()
+ public function getHTTPProtocol()
{
if (isset($_SERVER['SERVER_PROTOCOL'])) {
if (($pos = strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) {
@@ -812,36 +939,68 @@ class Browser {
}
/**
- * Determine if files can be uploaded to the system.
+ * Returns the IP address of the client.
*
- * @access public
+ * @return string The client IP address.
+ */
+ public function getIPAddress()
+ {
+ return empty($_SERVER['HTTP_X_FORWARDED_FOR'])
+ ? $_SERVER['REMOTE_ADDR']
+ : $_SERVER['HTTP_X_FORWARDED_FOR'];
+ }
+
+ /**
+ * Determines if files can be uploaded to the system.
*
* @return integer If uploads allowed, returns the maximum size of the
* upload in bytes. Returns 0 if uploads are not
* allowed.
*/
- function allowFileUploads()
+ public static function allowFileUploads()
{
if (ini_get('file_uploads')) {
if (($dir = ini_get('upload_tmp_dir')) &&
!is_writable($dir)) {
return 0;
}
- $size = ini_get('upload_max_filesize');
- switch (strtolower(substr($size, -1, 1))) {
+ $filesize = ini_get('upload_max_filesize');
+ switch (strtolower(substr($filesize, -1, 1))) {
case 'k':
- $size = intval(floatval($size) * 1024);
+ $filesize = intval(floatval($filesize) * 1024);
break;
case 'm':
- $size = intval(floatval($size) * 1024 * 1024);
+ $filesize = intval(floatval($filesize) * 1024 * 1024);
+ break;
+
+ case 'g':
+ $filesize = intval(floatval($filesize) * 1024 * 1024 * 1024);
break;
default:
- $size = intval($size);
+ $filesize = intval($filesize);
break;
}
- return $size;
+ $postsize = ini_get('post_max_size');
+ switch (strtolower(substr($postsize, -1, 1))) {
+ case 'k':
+ $postsize = intval(floatval($postsize) * 1024);
+ break;
+
+ case 'm':
+ $postsize = intval(floatval($postsize) * 1024 * 1024);
+ break;
+
+ case 'g':
+ $postsize = intval(floatval($postsize) * 1024 * 1024 * 1024);
+ break;
+
+ default:
+ $postsize = intval($postsize);
+ break;
+ }
+ return min($filesize, $postsize);
} else {
return 0;
}
@@ -851,29 +1010,24 @@ class Browser {
* Determines if the file was uploaded or not. If not, will return the
* appropriate error message.
*
- * @access public
- *
- * @param string $field The name of the field containing the
- * uploaded file.
- * @param optional string $name The file description string to use in the
- * error message. Default: 'file'.
+ * @param string $field The name of the field containing the uploaded
+ * file.
+ * @param string $name The file description string to use in the error
+ * message. Default: 'file'.
*
- * @return mixed True on success, PEAR_Error on error.
+ * @throws Horde_Browser_Exception
*/
- function wasFileUploaded($field, $name = null)
+ public function wasFileUploaded($field, $name = null)
{
- require_once 'PEAR.php';
-
if (is_null($name)) {
- $name = _("file");
+ $name = 'file';
}
- if (!($uploadSize = Browser::allowFileUploads())) {
- return PEAR::raiseError(_("File uploads not supported."));
+ if (!($uploadSize = self::allowFileUploads())) {
+ throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
}
/* Get any index on the field name. */
- require_once 'Horde/Array.php';
$index = Horde_Array::getArrayParts($field, $base, $keys);
if ($index) {
@@ -887,38 +1041,36 @@ class Browser {
} else {
/* No index, simple set up of vars to check. */
if (!isset($_FILES[$field])) {
- return PEAR::raiseError(_("No file uploaded"), UPLOAD_ERR_NO_FILE);
+ throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
}
$error = $_FILES[$field]['error'];
$tmp_name = $_FILES[$field]['tmp_name'];
}
- if (!isset($_FILES) || ($error == UPLOAD_ERR_NO_FILE)) {
- return PEAR::raiseError(sprintf(_("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
+ if (empty($_FILES) || ($error == UPLOAD_ERR_NO_FILE)) {
+ throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
} elseif (($error == UPLOAD_ERR_OK) && is_uploaded_file($tmp_name)) {
- return true;
+ if (!filesize($tmp_name)) {
+ throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
+ }
+ // SUCCESS
} elseif (($error == UPLOAD_ERR_INI_SIZE) ||
($error == UPLOAD_ERR_FORM_SIZE)) {
- return PEAR::raiseError(sprintf(_("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
+ throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, min($uploadSize, Horde_Util::getFormData('MAX_FILE_SIZE'))), $error);
} elseif ($error == UPLOAD_ERR_PARTIAL) {
- return PEAR::raiseError(sprintf(_("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
+ throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
}
}
/**
* Returns the headers for a browser download.
*
- * @access public
- *
- * @param optional string $filename The filename of the download.
- * @param optional string $cType The content-type description of the
- * file.
- * @param optional boolean $inline True if inline, false if attachment.
- * @param optional string $cLength The content-length of this file.
- *
- * @since Horde 2.2
+ * @param string $filename The filename of the download.
+ * @param string $cType The content-type description of the file.
+ * @param boolean $inline True if inline, false if attachment.
+ * @param string $cLength The content-length of this file.
*/
- function downloadHeaders($filename = 'unknown', $cType = null,
+ public function downloadHeaders($filename = 'unknown', $cType = null,
$inline = false, $cLength = null)
{
/* Remove linebreaks from file names. */
@@ -929,12 +1081,15 @@ class Browser {
$filename = strtr($filename, ' ', '_');
}
- /* MSIE doesn't like multiple periods in the file name. Convert
- all periods (except the last one) to underscores. */
+ /* MSIE doesn't like multiple periods in the file name. Convert all
+ * periods (except the last one) to underscores. */
if ($this->isBrowser('msie')) {
if (($pos = strrpos($filename, '.'))) {
$filename = strtr(substr($filename, 0, $pos), '.', '_') . substr($filename, $pos);
}
+
+ /* Encode the filename so IE downloads it correctly. (Bug #129) */
+ $filename = rawurlencode($filename);
}
/* Content-Type/Content-Disposition Header. */
@@ -943,7 +1098,6 @@ class Browser {
header('Content-Type: ' . trim($cType));
} elseif ($this->isBrowser('msie')) {
header('Content-Type: application/x-msdownload');
- $filename = rawurlencode($filename);
} else {
header('Content-Type: application/octet-stream');
}
@@ -951,7 +1105,6 @@ class Browser {
} else {
if ($this->isBrowser('msie')) {
header('Content-Type: application/x-msdownload');
- $filename = rawurlencode($filename);
} elseif (!is_null($cType)) {
header('Content-Type: ' . trim($cType));
} else {
@@ -965,16 +1118,17 @@ class Browser {
}
}
- /* Content-Length Header. Don't send Content-Length for
- * HTTP/1.1 servers. */
- if (($this->getHTTPProtocol() != '1.1') && !is_null($cLength)) {
+ /* Content-Length Header. Only send if we are not compressing
+ * output. */
+ if (!is_null($cLength) &&
+ !in_array('ob_gzhandler', ob_list_handlers())) {
header('Content-Length: ' . $cLength);
}
/* Overwrite Pragma: and other caching headers for IE. */
if ($this->hasQuirk('cache_ssl_downloads')) {
header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header('Cache-Control: must-revalidate');
header('Pragma: public');
}
}
@@ -982,15 +1136,13 @@ class Browser {
/**
* Determines if a browser can display a given MIME type.
*
- * @access public
- *
* @param string $mimetype The MIME type to check.
*
* @return boolean True if the browser can display the MIME type.
*/
- function isViewable($mimetype)
+ public function isViewable($mimetype)
{
- $mimetype = strtolower($mimetype);
+ $mimetype = Horde_String::lower($mimetype);
list($type, $subtype) = explode('/', $mimetype);
if (!empty($this->_accept)) {
@@ -1007,10 +1159,9 @@ class Browser {
}
}
- /* image/jpeg and image/pjpeg *appear* to be the same
- * entity, but Mozilla doesn't seem to want to accept the
- * latter. For our purposes, we will treat them the
- * same. */
+ /* image/jpeg and image/pjpeg *appear* to be the same entity, but
+ * Mozilla doesn't seem to want to accept the latter. For our
+ * purposes, we will treat them the same. */
if ($this->isBrowser('mozilla') &&
($mimetype == 'image/pjpeg') &&
(strpos($this->_accept, 'image/jpeg') !== false)) {
@@ -1026,60 +1177,7 @@ class Browser {
return false;
}
- return (in_array($subtype, $this->_images));
- }
-
- /**
- * Escape characters in javascript code if the browser requires it.
- * %23, %26, and %2B (for IE) and %27 need to be escaped or else
- * jscript will interpret it as a single quote, pound sign, or
- * ampersand and refuse to work.
- *
- * @access public
- *
- * @param string $code The JS code to escape.
- *
- * @return string The escaped code.
- */
- function escapeJSCode($code)
- {
- $from = $to = array();
-
- if ($this->isBrowser('msie') ||
- ($this->isBrowser('mozilla') && ($this->getMajor() >= 5))) {
- $from = array('%23', '%26', '%2B');
- $to = array(urlencode('%23'), urlencode('%26'), urlencode('%2B'));
- }
- $from[] = '%27';
- $to[] = '\%27';
-
- return str_replace($from, $to, $code);
- }
-
- /**
- * Set the IE version in the session.
- *
- * @access public
- *
- * @param string $ver The IE Version string.
- */
- function setIEVersion($ver)
- {
- $_SESSION['__browser'] = array(
- 'ie_version' => $ver
- );
- }
-
- /**
- * Return the IE version stored in the session, if available.
- *
- * @access public
- *
- * @return mixed The IE Version string or null if no string is stored.
- */
- function getIEVersion()
- {
- return isset($_SESSION['__browser']['ie_version']) ? $_SESSION['__browser']['ie_version'] : null;
+ return in_array($subtype, $this->_images);
}
}
diff --git a/play/index.php b/play/index.php
index 8e41cbc5..506af18f 100644
--- a/play/index.php
+++ b/play/index.php
@@ -244,6 +244,10 @@ ignore_user_abort(true);
// Format the song name
$media_name = $media->f_artist_full . " - " . $media->title . "." . $media->type;
+
+// Generate browser class for sending headers
+$browser = new Horde_Browser();
+
/* If they are just trying to download make sure they have rights
* and then present them with the download file
*/
@@ -253,9 +257,7 @@ if ($_GET['action'] == 'download' AND Config::get('download')) {
$media->format_pattern();
$media_name = str_replace(array('?','/','\\'),"_",$media->f_file);
- // Use Horde's Browser class to send the headers
header("Content-Length: " . $media->size);
- $browser = new Browser();
$browser->downloadHeaders($media_name,$media->mime,false,$media->size);
$fp = fopen($media->file,'rb');
$bytesStreamed = 0;
@@ -289,8 +291,6 @@ if ($_GET['action'] == 'download' AND Config::get('download')) {
} // if they are trying to download and they can
-// Generate browser class for sending headers
-$browser = new Browser();
header("Accept-Ranges: bytes" );
// Prevent the script from timing out