Update functions.php
This commit is contained in:
+85
-80
@@ -862,67 +862,69 @@ function format_string ($format, $data) {
|
|||||||
|
|
||||||
//browser detection without browscap.ini dependency
|
//browser detection without browscap.ini dependency
|
||||||
function http_user_agent($info = '') {
|
function http_user_agent($info = '') {
|
||||||
$u_agent = $_SERVER['HTTP_USER_AGENT'];
|
|
||||||
$bname = 'Unknown';
|
|
||||||
$platform = 'Unknown';
|
|
||||||
$version= "";
|
|
||||||
|
|
||||||
//get the platform?
|
//set default values
|
||||||
if (preg_match('/linux/i', $u_agent)) {
|
$user_agent = $_SERVER['HTTP_USER_AGENT'];
|
||||||
|
$browser_name = 'Unknown';
|
||||||
|
$platform = 'Unknown';
|
||||||
|
$version= "";
|
||||||
|
|
||||||
|
//get the platform
|
||||||
|
if (preg_match('/linux/i', $user_agent)) {
|
||||||
$platform = 'linux';
|
$platform = 'linux';
|
||||||
}
|
}
|
||||||
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
|
elseif (preg_match('/macintosh|mac os x/i', $user_agent)) {
|
||||||
$platform = 'mac';
|
$platform = 'mac';
|
||||||
}
|
}
|
||||||
elseif (preg_match('/windows|win32/i', $u_agent)) {
|
elseif (preg_match('/windows|win32/i', $user_agent)) {
|
||||||
$platform = 'windows';
|
$platform = 'windows';
|
||||||
}
|
}
|
||||||
|
elseif (preg_match('/mobile/i', $user_agent)) {
|
||||||
|
$platform = 'mobile';
|
||||||
|
}
|
||||||
|
elseif (preg_match('/android/i', $user_agent)) {
|
||||||
|
$platform = 'mobile';
|
||||||
|
}
|
||||||
|
|
||||||
//get the name of the useragent yes seperately and for good reason
|
//get the name of the useragent
|
||||||
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
|
if (preg_match('/MSIE/i',$user_agent) && !preg_match('/Opera/i',$user_agent)) {
|
||||||
{
|
$browser_name = 'Internet Explorer';
|
||||||
$bname = 'Internet Explorer';
|
$browser_shortname = "MSIE";
|
||||||
$ub = "MSIE";
|
|
||||||
}
|
}
|
||||||
elseif(preg_match('/Firefox/i',$u_agent))
|
elseif (preg_match('/Firefox/i',$user_agent)) {
|
||||||
{
|
$browser_name = 'Mozilla Firefox';
|
||||||
$bname = 'Mozilla Firefox';
|
$browser_shortname = "Firefox";
|
||||||
$ub = "Firefox";
|
|
||||||
}
|
}
|
||||||
elseif(preg_match('/Chrome/i',$u_agent))
|
elseif (preg_match('/Chrome/i',$user_agent)) {
|
||||||
{
|
$browser_name = 'Google Chrome';
|
||||||
$bname = 'Google Chrome';
|
$browser_shortname = "Chrome";
|
||||||
$ub = "Chrome";
|
|
||||||
}
|
}
|
||||||
elseif(preg_match('/Safari/i',$u_agent))
|
elseif (preg_match('/Safari/i',$user_agent)) {
|
||||||
{
|
$browser_name = 'Apple Safari';
|
||||||
$bname = 'Apple Safari';
|
$browser_shortname = "Safari";
|
||||||
$ub = "Safari";
|
|
||||||
}
|
}
|
||||||
elseif(preg_match('/Opera/i',$u_agent))
|
elseif (preg_match('/Opera/i',$user_agent)) {
|
||||||
{
|
$browser_name = 'Opera';
|
||||||
$bname = 'Opera';
|
$browser_shortname = "Opera";
|
||||||
$ub = "Opera";
|
|
||||||
}
|
}
|
||||||
elseif(preg_match('/Netscape/i',$u_agent))
|
elseif (preg_match('/Netscape/i',$user_agent)) {
|
||||||
{
|
$browser_name = 'Netscape';
|
||||||
$bname = 'Netscape';
|
$browser_shortname = "Netscape";
|
||||||
$ub = "Netscape";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//finally get the correct version number
|
//finally get the correct version number
|
||||||
$known = array('Version', $ub, 'other');
|
$known = array('Version', $browser_shortname, 'other');
|
||||||
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
|
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
|
||||||
if (!preg_match_all($pattern, $u_agent, $matches)) {
|
if (!preg_match_all($pattern, $user_agent, $matches)) {
|
||||||
// we have no matching number just continue
|
//we have no matching number just continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// see how many we have
|
//see how many we have
|
||||||
$i = count($matches['browser']);
|
$i = count($matches['browser']);
|
||||||
if ($i != 1) {
|
if ($i != 1) {
|
||||||
//we will have two since we are not using 'other' argument yet
|
//we will have two since we are not using 'other' argument yet
|
||||||
//see if version is before or after the name
|
//see if version is before or after the name
|
||||||
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
|
if (strripos($user_agent,"Version") < strripos($user_agent,$browser_shortname)) {
|
||||||
$version= $matches['version'][0];
|
$version= $matches['version'][0];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -933,58 +935,61 @@ function format_string ($format, $data) {
|
|||||||
$version= $matches['version'][0];
|
$version= $matches['version'][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we have a number
|
//check if we have a number
|
||||||
if ($version==null || $version=="") {$version="?";}
|
if ($version == null || $version == "") { $version = "?"; }
|
||||||
|
|
||||||
switch ($info) {
|
//return the data
|
||||||
case "agent": return $u_agent; break;
|
switch ($info) {
|
||||||
case "name": return $bname; break;
|
case "agent": return $user_agent; break;
|
||||||
case "version": return $version; break;
|
case "name": return $browser_name; break;
|
||||||
case "platform": return $platform; break;
|
case "version": return $version; break;
|
||||||
case "pattern": return $pattern; break;
|
case "platform": return $platform; break;
|
||||||
default :
|
case "pattern": return $pattern; break;
|
||||||
return array(
|
default :
|
||||||
'userAgent' => $u_agent,
|
return array(
|
||||||
'name' => $bname,
|
'user_agent' => $user_agent,
|
||||||
'version' => $version,
|
'name' => $browser_name,
|
||||||
'platform' => $platform,
|
'version' => $version,
|
||||||
'pattern' => $pattern
|
'platform' => $platform,
|
||||||
);
|
'pattern' => $pattern
|
||||||
}
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//tail php function for non posix systems
|
//tail php function for non posix systems
|
||||||
function tail($file, $num_to_get=10) {
|
function tail($file, $num_to_get=10) {
|
||||||
$fp = fopen($file, 'r');
|
$fp = fopen($file, 'r');
|
||||||
$position = filesize($file);
|
$position = filesize($file);
|
||||||
$chunklen = 4096;
|
$chunklen = 4096;
|
||||||
if($position-$chunklen<=0) {
|
if($position-$chunklen<=0) {
|
||||||
|
fseek($fp,0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fseek($fp, $position-$chunklen);
|
||||||
|
}
|
||||||
|
$data="";$ret="";$lc=0;
|
||||||
|
while($chunklen > 0) {
|
||||||
|
$data = fread($fp, $chunklen);
|
||||||
|
$dl=strlen($data);
|
||||||
|
for($i=$dl-1;$i>=0;$i--){
|
||||||
|
if($data[$i]=="\n"){
|
||||||
|
if($lc==0 && $ret!="")$lc++;
|
||||||
|
$lc++;
|
||||||
|
if($lc>$num_to_get)return $ret;
|
||||||
|
}
|
||||||
|
$ret=$data[$i].$ret;
|
||||||
|
}
|
||||||
|
if($position-$chunklen<=0){
|
||||||
fseek($fp,0);
|
fseek($fp,0);
|
||||||
|
$chunklen=$chunklen-abs($position-$chunklen);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fseek($fp, $position-$chunklen);
|
fseek($fp, $position-$chunklen);
|
||||||
}
|
}
|
||||||
$data="";$ret="";$lc=0;
|
$position = $position - $chunklen;
|
||||||
while($chunklen > 0)
|
}
|
||||||
{
|
fclose($fp);
|
||||||
$data = fread($fp, $chunklen);
|
return $ret;
|
||||||
$dl=strlen($data);
|
|
||||||
for($i=$dl-1;$i>=0;$i--){
|
|
||||||
if($data[$i]=="\n"){
|
|
||||||
if($lc==0 && $ret!="")$lc++;
|
|
||||||
$lc++;
|
|
||||||
if($lc>$num_to_get)return $ret;
|
|
||||||
}
|
|
||||||
$ret=$data[$i].$ret;
|
|
||||||
}
|
|
||||||
if($position-$chunklen<=0){
|
|
||||||
fseek($fp,0);
|
|
||||||
$chunklen=$chunklen-abs($position-$chunklen);
|
|
||||||
}else fseek($fp, $position-$chunklen);
|
|
||||||
$position = $position - $chunklen;
|
|
||||||
}
|
|
||||||
fclose($fp);
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//generate a random password with upper, lowercase and symbols
|
//generate a random password with upper, lowercase and symbols
|
||||||
|
|||||||
Reference in New Issue
Block a user