From bfc001556afc1ce335df729e8260292c9e78d336 Mon Sep 17 00:00:00 2001 From: Alexey Osodoev Date: Sat, 12 Mar 2011 04:51:59 +0800 Subject: [PATCH] Issue #664424: Fixe boolean values in PHP >= 5.3 --- browscap.module | 30 ++++++++++++------------------ 1 files changed, 12 insertions(+), 18 deletions(-) diff --git a/browscap.module b/browscap.module index af316eb..0b900b4 100644 --- a/browscap.module +++ b/browscap.module @@ -336,11 +336,6 @@ function _browscap_import($cron = TRUE) { return; } - // Fetch the new version, and dump it in the temp directory - $server = $_SERVER['SERVER_NAME']; - $path = variable_get('file_directory_temp', '/tmp'); - $browscapfile = "$path/browscap_$server.ini"; - $browscap = drupal_http_request('http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI'); if (isset($browscap->error) || empty($browscap)) { watchdog('browscap', t("Couldn't retrieve updated browscap: ") . $browscap->error); @@ -350,22 +345,21 @@ function _browscap_import($cron = TRUE) { return; } - // The file as downloaded from browser.garykeith.com has semicolon (;) and - // single-quote (') characters in the section strings, either of which will - // cause parse_ini_file() to abort and return FALSE. To fix this, simply - // escape them with the backslash character. - $browscap->data = preg_replace(array("/(?data); - - $browscapfp = fopen($browscapfile, "w"); - fwrite($browscapfp, $browscap->data); - fclose($browscapfp); - if (version_compare(PHP_VERSION, '5.3.0', '>=')) { - $a = parse_ini_file($browscapfile, TRUE, INI_SCANNER_RAW); - } - else { + // Parse as string + $browscap->data = strtr($browscap->data, array("=true\r" => "=1\r", "=false\r" => "=0\r")); + $a = parse_ini_string($browscap->data, TRUE, INI_SCANNER_RAW); + } else { + // Dump it in the temp directory and parse + $server = $_SERVER['SERVER_NAME']; + $path = variable_get('file_directory_temp', '/tmp'); + $browscapfile = "$path/browscap_$server.ini"; + $browscapfp = fopen($browscapfile, "w"); + fwrite($browscapfp, $browscap->data); + fclose($browscapfp); $a = parse_ini_file($browscapfile, TRUE); } + if ($a) { // the first entry in the array is the version info $version = array_shift($a); -- 1.7.1