summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-01-22 12:23:17 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-01-22 12:23:17 -0500
commit4dca7a57b05de6efa38828eb3c90549a1d07857c (patch)
tree2e23e5b135f048c91ed28e314417c9ed73d82197
parent0931872fe633addf5bfcbda64735b1f7c00b066c (diff)
downloadampache-4dca7a57b05de6efa38828eb3c90549a1d07857c.tar.gz
ampache-4dca7a57b05de6efa38828eb3c90549a1d07857c.tar.bz2
ampache-4dca7a57b05de6efa38828eb3c90549a1d07857c.zip
Update Horde_Browser to git HEAD
git clone git://github.com/horde/horde git diff f93a5f19 112808d8 framework/Browser/lib/Horde/Browser.php
-rw-r--r--modules/horde/Browser.php324
1 files changed, 210 insertions, 114 deletions
diff --git a/modules/horde/Browser.php b/modules/horde/Browser.php
index da6f12eb..149f532b 100644
--- a/modules/horde/Browser.php
+++ b/modules/horde/Browser.php
@@ -1,14 +1,13 @@
<?php
/**
- * The Horde_Browser class provides capability information for the current
- * web client.
+ * This provides capability information for the current web client.
*
* Browser identification is performed by examining the HTTP_USER_AGENT
* environment variable provided by the web server.
*
* @TODO http://ajaxian.com/archives/parse-user-agent
*
- * Copyright 1999-2011 Horde LLC (http://www.horde.org/)
+ * Copyright 1999-2013 Horde LLC (http://www.horde.org/)
* Copyright 2011 Paul MacIain (local changes for Ampache)
*
* See the enclosed file COPYING for license information (LGPL). If you
@@ -17,6 +16,7 @@
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jon Parise <jon@horde.org>
* @category Horde
+ * @license http://www.horde.org/licenses/lgpl21 LGPL
* @package Browser
*/
class Horde_Browser
@@ -200,60 +200,32 @@ class Horde_Browser
protected $_mobile = false;
/**
+ * Is this a tablet browser?
+ *
+ * @var boolean
+ */
+ protected $_tablet = false;
+
+ /**
* Features.
*
* @var array
*/
protected $_features = array(
+ 'frames' => true,
'html' => true,
- 'hdml' => false,
- 'wml' => false,
'images' => true,
- 'iframes' => false,
- 'frames' => true,
- 'tables' => true,
'java' => true,
'javascript' => true,
- 'dom' => false,
- 'utf' => false,
- 'rte' => false,
- 'homepage' => false,
- 'accesskey' => false,
- 'optgroup' => false,
- 'xmlhttpreq' => false,
- 'cite' => false,
- // RFC 2397
- 'dataurl' => false,
- // Webkit browsers
- 'ischrome' => false,
- 'iskonqueror' => false,
- 'issafari' => false,
+ 'tables' => true
);
/**
- * Quirks
+ * Quirks.
*
* @var array
*/
- protected $_quirks = array(
- 'avoid_popup_windows' => false,
- 'break_disposition_header' => false,
- 'break_disposition_filename' => false,
- 'broken_multipart_form' => false,
- 'buggy_compression' => false,
- 'cache_same_url' => false,
- 'cache_ssl_downloads' => false,
- 'double_linebreak_textarea' => false,
- 'empty_file_input_value' => false,
- 'must_cache_forms' => false,
- 'no_filename_spaces' => false,
- 'no_hidden_overflow_tables' => false,
- 'ow_gui_1.3' => false,
- 'png_transparency' => false,
- 'scrollbar_in_way' => false,
- 'scroll_tds' => false,
- 'windowed_controls' => false,
- );
+ protected $_quirks = array();
/**
* List of viewable image MIME subtypes.
@@ -319,13 +291,33 @@ class Horde_Browser
if (strpos($lowerAgent, 'iemobile') !== false ||
strpos($lowerAgent, 'mobileexplorer') !== false ||
- strpos($lowerAgent, 'openwave') !== false ||
- strpos($lowerAgent, 'opera mini') !== false ||
- strpos($lowerAgent, 'operamini') !== false) {
+ strpos($lowerAgent, 'openwave') !== false) {
$this->setFeature('frames', false);
$this->setFeature('javascript', false);
$this->setQuirk('avoid_popup_windows');
$this->setMobile(true);
+
+ if (preg_match('|iemobile[/ ]([0-9.]+)|', $lowerAgent, $version)) {
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
+ if ($this->_majorVersion >= 7) {
+ // Windows Phone, Modern Browser
+ $this->setBrowser('msie');
+ $this->setFeature('javascript');
+ $this->setFeature('xmlhttpreq');
+ $this->setFeature('ajax');
+ $this->setFeature('dom');
+ $this->setFeature('utf');
+ $this->setFeature('rte');
+ $this->setFeature('cite');
+ }
+ }
+ } elseif (strpos($lowerAgent, 'opera mini') !== false ||
+ strpos($lowerAgent, 'operamini') !== false) {
+ $this->setBrowser('opera');
+ $this->setFeature('frames', false);
+ $this->setFeature('javascript');
+ $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]);
@@ -336,6 +328,9 @@ class Horde_Browser
* agent strings. */
if (preg_match('/; (120x160|240x280|240x320|320x320)\)/', $agent)) {
$this->setMobile(true);
+ } elseif (preg_match('|Tablet|', $agent)) {
+ $this->setMobile(true);
+ $this->setTablet(true);
}
if ($this->_majorVersion >= 7) {
@@ -346,6 +341,7 @@ class Horde_Browser
if ($this->_majorVersion >= 9) {
$this->setFeature('dataurl', 4100);
if ($this->_minorVersion >= 5) {
+ $this->setFeature('ajax');
$this->setFeature('rte');
}
}
@@ -396,21 +392,12 @@ class Horde_Browser
switch ($this->_majorVersion) {
default:
+ case 10:
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;
-
case 7:
$this->setFeature('javascript', 1.4);
+ $this->setFeature('ajax');
$this->setFeature('dom');
$this->setFeature('iframes');
$this->setFeature('utf');
@@ -418,6 +405,10 @@ class Horde_Browser
$this->setFeature('homepage');
$this->setFeature('accesskey');
$this->setFeature('optgroup');
+ if ($this->_majorVersion != 7) {
+ $this->setFeature('cite');
+ $this->setFeature('dataurl', ($this->_majorVersion == 8) ? 32768 : true);
+ }
break;
case 6:
@@ -488,9 +479,19 @@ class Horde_Browser
$this->setFeature('dataurl');
if (strpos($agent, 'Mobile') !== false ||
- strpos($agent, 'NokiaN') !== false ||
- strpos($agent, 'SymbianOS') !== false) {
+ strpos($agent, 'Android') !== false ||
+ strpos($agent, 'SAMSUNG-GT') !== false ||
+ ((strpos($agent, 'Nokia') !== false ||
+ strpos($agent, 'Symbian') !== false) &&
+ strpos($agent, 'WebKit') !== false) ||
+ (strpos($agent, 'N900') !== false &&
+ strpos($agent, 'Maemo Browser') !== false) ||
+ (strpos($agent, 'MeeGo') !== false &&
+ strpos($agent, 'NokiaN9') !== false)) {
// WebKit Mobile
+ $this->setFeature('frames', false);
+ $this->setFeature('javascript');
+ $this->setQuirk('avoid_popup_windows');
$this->setMobile(true);
}
@@ -499,12 +500,14 @@ class Horde_Browser
$this->_minorVersion = $version[2];
}
- if (stripos($agent, 'Chrome/') !== false) {
+ if (stripos($agent, 'Chrome/') !== false ||
+ stripos($agent, 'CriOS/') !== false) {
// Google Chrome.
$this->setFeature('ischrome');
$this->setFeature('rte');
$this->setFeature('utf');
$this->setFeature('javascript', 1.4);
+ $this->setFeature('ajax');
$this->setFeature('dom');
$this->setFeature('iframes');
$this->setFeature('accesskey');
@@ -524,6 +527,7 @@ class Horde_Browser
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('ajax');
$this->setFeature('rte');
} elseif ($this->_majorVersion >= 412) {
$this->_majorVersion = 2;
@@ -557,7 +561,8 @@ class Horde_Browser
case 3:
$this->setFeature('dom');
$this->setFeature('iframes');
- if ($this->_minorVersion >= 5 || $this->_majorVersion == 4) {
+ if ($this->_minorVersion >= 5 ||
+ $this->_majorVersion == 4) {
$this->setFeature('accesskey');
$this->setFeature('xmlhttpreq');
}
@@ -570,26 +575,37 @@ class Horde_Browser
list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
switch ($this->_majorVersion) {
+ default:
case 5:
if ($this->getPlatform() == 'win') {
$this->setQuirk('break_disposition_filename');
}
$this->setFeature('javascript', 1.4);
+ $this->setFeature('ajax');
$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) {
+ if (version_compare($revision[1], '1', '>=')) {
$this->setFeature('iframes');
}
- if ($revision[1] >= 1.3) {
+ if (version_compare($revision[1], '1.3', '>=')) {
$this->setFeature('rte');
}
if (version_compare($revision[1], '1.8.1', '>=')) {
$this->setFeature('dataurl');
}
+ if (version_compare($revision[1], '10.0', '>=')) {
+ $this->setFeature('utf');
+ }
+ }
+ if (stripos($agent, 'mobile') !== false) {
+ $this->setMobile(true);
+ } elseif (stripos($agent, 'tablet') !== false) {
+ $this->setTablet(true);
+ $this->setMobile(true);
}
break;
@@ -599,7 +615,9 @@ class Horde_Browser
break;
case 3:
- default:
+ case 2:
+ case 1:
+ case 0:
$this->setFeature('javascript', 1);
$this->setQuirk('buggy_compression');
break;
@@ -680,13 +698,22 @@ class Horde_Browser
$this->setBrowser('imode');
$this->setFeature('images', false);
$this->setMobile(true);
- } elseif (strpos($agent, 'BlackBerry') !== false) {
+ } elseif (preg_match('|BlackBerry.*?/([0-9.]+)|', $agent, $version)) {
+ list($this->_majorVersion, $this->_minorVersion) = explode('.', $version[1]);
$this->setBrowser('blackberry');
$this->setFeature('html', false);
$this->setFeature('javascript', false);
$this->setFeature('hdml');
$this->setFeature('wml');
$this->setMobile(true);
+ if ($this->_majorVersion >= 5 ||
+ ($this->_majorVersion == 4 && $this->_minorVersion >= 6)) {
+ $this->setFeature('ajax');
+ $this->setFeature('iframes');
+ $this->setFeature('javascript', 1.5);
+ $this->setFeature('dom');
+ $this->setFeature('xmlhttpreq');
+ }
} elseif (strpos($agent, 'MOT-') !== false) {
$this->setBrowser('motorola');
$this->setFeature('html', false);
@@ -770,6 +797,32 @@ class Horde_Browser
}
/**
+ * Set this browser as a tablet device.
+ *
+ * @since 2.1.0
+ *
+ * @param boolean $tablet True if the browser is a tablet device.
+ */
+ public function setTablet($tablet)
+ {
+ $this->_tablet = (bool)$tablet;
+ }
+
+ /**
+ * Is the current browser a tablet device? This is not 100% reliable, as
+ * most browsers do not differentiate between smartphone and tablet
+ * versions.
+ *
+ * @since 2.1.0
+ *
+ * @return boolean True if we do, false if we don't.
+ */
+ public function isTablet()
+ {
+ return $this->_tablet;
+ }
+
+ /**
* Is the browser a robot?
*
* @return boolean True if browser is a known robot.
@@ -840,12 +893,33 @@ class Horde_Browser
/**
* Sets unique behavior for the current browser.
*
- * @param string $quirk The behavior to set.
+ * @param string $quirk The behavior to set. Quirks:
+ * - avoid_popup_windows
+ * - break_disposition_header
+ * - break_disposition_filename
+ * - broken_multipart_form
+ * - buggy_compression
+ * - cache_same_url
+ * - cache_ssl_downloads
+ * - double_linebreak_textarea
+ * - empty_file_input_value
+ * - must_cache_forms
+ * - no_filename_spaces
+ * - no_hidden_overflow_tables
+ * - ow_gui_1.3
+ * - png_transparency
+ * - scrollbar_in_way
+ * - scroll_tds
+ * - windowed_controls
* @param string $value Special behavior parameter.
*/
public function setQuirk($quirk, $value = true)
{
- $this->_quirks[$quirk] = $value;
+ if ($value) {
+ $this->_quirks[$quirk] = $value;
+ } else {
+ unset($this->_quirks[$quirk]);
+ }
}
/**
@@ -877,12 +951,38 @@ class Horde_Browser
/**
* Sets capabilities for the current browser.
*
- * @param string $feature The capability to set.
+ * @param string $feature The capability to set. Features:
+ * - accesskey
+ * - ajax
+ * - cite
+ * - dataurl
+ * - dom
+ * - frames
+ * - hdml
+ * - html
+ * - homepage
+ * - iframes
+ * - images
+ * - ischrome
+ * - iskonqueror
+ * - issafari
+ * - java
+ * - javascript
+ * - optgroup
+ * - rte
+ * - tables
+ * - utf
+ * - wml
+ * - xmlhttpreq
* @param string $value Special capability parameter.
*/
public function setFeature($feature, $value = true)
{
- $this->_features[$feature] = $value;
+ if ($value) {
+ $this->_features[$feature] = $value;
+ } else {
+ unset($this->_features[$feature]);
+ }
}
/**
@@ -930,13 +1030,9 @@ class Horde_Browser
*/
public function getHTTPProtocol()
{
- if (isset($_SERVER['SERVER_PROTOCOL'])) {
- if (($pos = strrpos($_SERVER['SERVER_PROTOCOL'], '/'))) {
- return substr($_SERVER['SERVER_PROTOCOL'], $pos + 1);
- }
- }
-
- return null;
+ return (isset($_SERVER['SERVER_PROTOCOL']) && ($pos = strrpos($_SERVER['SERVER_PROTOCOL'], '/')))
+ ? substr($_SERVER['SERVER_PROTOCOL'], $pos + 1)
+ : null;
}
/**
@@ -960,51 +1056,51 @@ class Horde_Browser
*/
public static function allowFileUploads()
{
- if (ini_get('file_uploads')) {
- if (($dir = ini_get('upload_tmp_dir')) &&
- !is_writable($dir)) {
- return 0;
- }
- $filesize = ini_get('upload_max_filesize');
- switch (strtolower(substr($filesize, -1, 1))) {
- case 'k':
- $filesize = intval(floatval($filesize) * 1024);
- break;
+ if (!ini_get('file_uploads') ||
+ (($dir = ini_get('upload_tmp_dir')) &&
+ !is_writable($dir))) {
+ return 0;
+ }
- case 'm':
- $filesize = intval(floatval($filesize) * 1024 * 1024);
- break;
+ $filesize = ini_get('upload_max_filesize');
+ switch (strtolower(substr($filesize, -1, 1))) {
+ case 'k':
+ $filesize = intval(floatval($filesize) * 1024);
+ break;
- case 'g':
- $filesize = intval(floatval($filesize) * 1024 * 1024 * 1024);
- break;
+ case 'm':
+ $filesize = intval(floatval($filesize) * 1024 * 1024);
+ break;
- default:
- $filesize = intval($filesize);
- break;
- }
- $postsize = ini_get('post_max_size');
- switch (strtolower(substr($postsize, -1, 1))) {
- case 'k':
- $postsize = intval(floatval($postsize) * 1024);
- break;
+ case 'g':
+ $filesize = intval(floatval($filesize) * 1024 * 1024 * 1024);
+ break;
- case 'm':
- $postsize = intval(floatval($postsize) * 1024 * 1024);
- break;
+ default:
+ $filesize = intval($filesize);
+ break;
+ }
- case 'g':
- $postsize = intval(floatval($postsize) * 1024 * 1024 * 1024);
- break;
+ $postsize = ini_get('post_max_size');
+ switch (strtolower(substr($postsize, -1, 1))) {
+ case 'k':
+ $postsize = intval(floatval($postsize) * 1024);
+ break;
- default:
- $postsize = intval($postsize);
- break;
- }
- return min($filesize, $postsize);
- } else {
- return 0;
+ 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);
}
/**
@@ -1057,7 +1153,7 @@ class Horde_Browser
// SUCCESS
} elseif (($error == UPLOAD_ERR_INI_SIZE) ||
($error == UPLOAD_ERR_FORM_SIZE)) {
- 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);
+ 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, $uploadSize), $error);
} elseif ($error == UPLOAD_ERR_PARTIAL) {
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);
}