All pastes #507200 Raw Edit

Mine

public text v1 · immutable
·published 2007-05-24 12:49 UTC
rendered paste body
<?php

#################################################
#                                               #
#         Name: Aries Management System         #
#         File: includes.php                    #
#                                               #
#       Copyright (c) Thomas Cameron 2007       #
#                                               #
#################################################

/* define the constants */
define('IS_ARIES', true); // this is to stop hacking attempts
define('BASEDIR', '/var/www'); // this is the base directory path

/* include and parse the configuration file */
function conf_parse($cfile)
{
	if(!file_exists(BASEDIR.$cfile))
		return 0;
	
	$conf = simplexml_load_file($cfile);
	return $conf;
}

/* a function to convert our new object to an array..
   kindly 'borrowed' from php.net/simplexml_load_file */
   
function obj2array($object)
{
   var $return;
      
   if(is_array($object))
   {
       foreach($object as $key => $value)
           $return[$key] = object2array($value);
   }
   else
   {
       $var = get_object_vars($object);
          
       if($var)
       {
           foreach($var as $key => $value)
               $return[$key] = object2array($value);
       }
       else
           return strval($object);
   }

   return $return;
}

/* now lets do the rest of the parsing */

$conf = conf_parse('config.xml');

if($conf == 0)
	die("ERROR: Could not include or parse configuration file.");
	
/* include the function libraries that are enabled */
$conf = obj2array($conf);

foreach($conf['libraries'] as $lib)
	include(BASEDIR.$lib) or echo "<b>WARNING:</b> Could not load function library <b>".$lib."</b>!";
	
# eof

?>