Modified and improved browser checking

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3278 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2011-02-06 15:29:06 +00:00
parent 1027b1c75b
commit 5985897a5c
1 changed files with 70 additions and 29 deletions

View File

@ -802,29 +802,43 @@ function getBrowser( &$browser, &$version )
{ {
if ( version_compare( phpversion(), "4.1.0", "<") ) if ( version_compare( phpversion(), "4.1.0", "<") )
{ {
global $_SERVER; global $_SERVER, $_SESSION;
} }
if ( isset($_SESSION['browser']) )
{
error_log( "Cached" );
$browser = $_SESSION['browser'];
$version = $_SESSION['version'];
}
else
{
error_log( "Uncached" );
if ( preg_match( '/MSIE ([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) if ( preg_match( '/MSIE ([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) )
{ {
$version = $logVersion[1]; $version = $logVersion[1];
$browser = 'ie'; $browser = 'ie';
} }
elseif ( preg_match( '/Chrome\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) )
{
$version = $logVersion[1];
$browser = 'chrome';
}
elseif ( preg_match( '/Safari\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) elseif ( preg_match( '/Safari\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) )
{ {
$version = $logVersion[1]; $version = $logVersion[1];
$browser = 'safari'; $browser = 'safari';
} }
elseif ( preg_match( '/Opera[ \/]([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) )
{
$version = $logVersion[1];
$browser = 'opera';
}
elseif ( preg_match( '/Konqueror\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) elseif ( preg_match( '/Konqueror\/([0-9.]+)/', $_SERVER['HTTP_USER_AGENT'], $logVersion) )
{ {
$version = $logVersion[1]; $version = $logVersion[1];
$browser = 'konqueror'; $browser = 'konqueror';
} }
elseif (preg_match( '/Opera ([0-9].[0-9]{1,2})/',$_SERVER['HTTP_USER_AGENT'],$logVersion))
{
$version = $logVersion[1];
$browser = 'opera';
}
elseif ( preg_match( '/Mozilla\/([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) ) elseif ( preg_match( '/Mozilla\/([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'], $logVersion) )
{ {
$version = $logVersion[1]; $version = $logVersion[1];
@ -835,9 +849,12 @@ function getBrowser( &$browser, &$version )
$version = 0; $version = 0;
$browser = 'unknown'; $browser = 'unknown';
} }
$_SESSION['browser'] = $browser;
$_SESSION['version'] = $version;
}
} }
function isNetscape() function isMozilla()
{ {
getBrowser( $browser, $version ); getBrowser( $browser, $version );
@ -858,6 +875,29 @@ function isInternetExplorer()
return( $browser == "ie" ); return( $browser == "ie" );
} }
function isChrome()
{
getBrowser( $browser, $version );
error_log( "B:".$browser );
error_log( "V:".$version );
return( $browser == "chrome" );
}
function isOpera()
{
getBrowser( $browser, $version );
return( $browser == "opera" );
}
function isSafari()
{
getBrowser( $browser, $version );
return( $browser == "safari" );
}
function isWindows() function isWindows()
{ {
if ( version_compare( phpversion(), "4.1.0", "<") ) if ( version_compare( phpversion(), "4.1.0", "<") )
@ -875,7 +915,8 @@ function canStreamIframe()
function canStreamNative() function canStreamNative()
{ {
return( ZM_WEB_CAN_STREAM == "yes" || ( ZM_WEB_CAN_STREAM == "auto" && (isNetscape() || isKonqueror()) ) ); // Chrome can display the stream, but then it blocks everything else (Chrome bug 5876)
return( ZM_WEB_CAN_STREAM == "yes" || ( ZM_WEB_CAN_STREAM == "auto" && (!isInternetExplorer() && !isChrome()) ) );
} }
function canStreamApplet() function canStreamApplet()