<?php
/*
phpCookBook INI Class
http://phpcookbook.sourceforge.net
Copyright (c)2002 Floris Barthel <hide@address.com>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
included LICENCE file for more details.
*/
class ini
{
var $iniFile = 'settings.ini';
var $iniContents = array();
function ini($iniFile)
{
if(!file_exists($iniFile))
return false;
if(isset($iniFile))
$this->iniFile = $iniFile;
unset($iniFile);
$this->iniContents = parse_ini_file($this->iniFile, true);
if($this->iniRead('medium') == 'XML' && !preg_match("/\(/", $this->iniRead('name', 'xml')))
trigger_error("Ini parse error. XML::NAME must contain a dynamic variable.");
}
function iniRead($option, $section = '')
{
$option = strtoupper($option);
$section = strtoupper($section);
if(isset($section) && $section != '') {
return $this->iniContents[$section][$option];
} else {
return $this->iniContents[$option];
}
}
function iniReadAll()
{
foreach($this->iniContents as $section => $array)
{
if(!is_array($array))
$iniSettings[strtolower($section)] = $array;
elseif(is_array($array)) {
foreach($array as $var => $value)
{
$iniSettings[strtolower($section)][strtolower($var)] = $value;
}
}
}
return $iniSettings;
}
function iniParseName($str_name, $username, $userid)
{
global $ext;
$from_array = array('(YYYY)', '(YY)', '(MM)', '(DD)', '(EXTENSION)', '(ID)', '(USERNAME)');
$to_array = array(date("Y"), date("y"), date("m"), date("d"), $ext, $userid, $username);
$str_name = str_replace($from_array, $to_array, $str_name);
$str_name = preg_replace("/\[(.+?)\]/is", "\\1", $str_name);
return $str_name;
}
}