<?php
/*
* @package ContentCMS
* @author Dan Goldsmith
* @copyright Dan Goldsmith 2012
* @link http://contentcms.d2g.org.uk/
* @version {SUBVERSION_BUILD_NUMBER}
*
* @licence MPL 2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
* You might think that parse_ini_file already exists and your right it does but this fixes the difference in version between
* php 5.2 and php 5.3 where single quotes are left on on version 5.2 and removed on v5.3
*
* This function only exists as a work around for the change to the parse_ini_file function between php v5.2 and v5.3
* In version 5.3 it does nothing and passes directly to parse_ini_file, in 5.2 it uses parse_ini_file and fixes the result to match that expected in 5.3
*/
function read_ini_file($filename,$process_sections = false,$scanner_mode = INI_SCANNER_NORMAL)
{
if (!defined('PHP_VERSION_ID'))
{
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
if(PHP_VERSION_ID < 50300)
{
$parsed_ini = parse_ini_file($filename,$process_sections);
$new_ini = array();
foreach($parsed_ini as $key => $value)
{
if(is_array($value))
{
$child_items = array();
foreach($value as $first_child_key => $first_child_value)
{
if(is_array($first_child_value))
{
$second_child_items = array();
foreach($first_child_value as $second_child_key => $second_child_value)
{
if(substr($second_child_value,0,1) == '\'' && substr($second_child_value,-1) == '\'')
{
$second_child_items[$second_child_key] = substr($second_child_value,1,strlen($second_child_value) -2);
}
else
{
$second_child_items[$second_child_key] = $second_child_value;
}
}
$child_items[$first_child_key] = $second_child_items;
}
else
{
if(substr($first_child_value,0,1) == '\'' && substr($first_child_value,-1) == '\'')
{
$child_items[$first_child_key] = substr($first_child_value,1,strlen($first_child_value) -2);
}
else
{
$child_items[$first_child_key] = $first_child_value;
}
}
}
$new_ini[$key] = $child_items;
}
else
{
if(substr($value,0,1) == '\'' && substr($value,-1) == '\'')
{
$new_ini[$key] = substr($value,1,strlen($value) -2);
}
else
{
$new_ini[$key] = $value;
}
}
}
return $new_ini;
}
else
{
$parsed_ini = parse_ini_file($filename,$process_sections,$scanner_mode);
return $parsed_ini;
}
}
?>