Sources for file plugins/config/file.php in version 2.0 Beta 4



Click on a comment to hide it. Click here to show all comments.
<?PHP

/*
 * Project:     Onyx: PHP Application Backend
 * File:        config/file.php
 *              Method to parse configuration files
 *
 * Version:     2.0b4
 * CVS tag:     $Id: file.php,v 1.6 2002/10/28 14:49:52 bok Exp $
 * Author:      Robert Amos <bok[at]ausmac.net>
 *              Andrew Wellington <proton[at]wiretapped.net>
 * Copyright:   2001,2002 Shiznatz Inc.
*/

class config_file_plugin {

    
/***************************************************************\
    * Method:    parse                        *
    * Description:    Parse Configuration Files            *
    * Syntax:    $this->parse(string file);            *
    * Returns:    an array of the config file (empty if error)    *    
    \***************************************************************/
        
function parse($file=NULL) {

        
// check first
        
if (is_null($file)) {
            
trigger_error('No configuration file specified.'WARNING);
            return array();
        }

        
// check it exists and we can read it
        
if (!file_exists($file) || !is_readable($file)) {
            
trigger_error('File ($file) not found or isnt readable.'WARNING);
            return array();
        }

        
// well what else is there to do now but start it off?
        
$fp fopen($file"r");

        
// keep a line counter for debugging and errors
        
$line 0;

        
// for dealing with variables in config values for later        
        
global $onyx_parent;
        if (
is_object($GLOBALS['smarty']))
            
$vars $GLOBALS['smarty']->get_template_vars();

        
// loop the file
        
while (!feof($fp)) {

            
// read line in
            
$linebuf chop(fgets($fp1024));

            
// deal with comments
            
if (preg_match("/^[^a-zA-Z0-9_]/"$linebuf)) {
                
$line++;
                continue;
            }

            
// split!!
            
if (!preg_match("/^([\S]+?)\s+(.*?)$/"$linebuf$m)) {
                
$line++;
                continue; 
// invalid line ey
            
}

            
// allow for variables in the files
            
if (preg_match_all('/\{\$([^}]*?)}/'$m[2], $variablesPREG_SET_ORDER)) {
                foreach (
$variables as $v) {
                    if (!empty(
$vars[$v[1]])) {
                        
$match[] = $v[0];
                        
$replace[] = $vars[$v[1]];
                    } elseif (!empty(
$onyx_parent->config[$v[1]])) {
                        
$match[] = $v[0];
                        
$replace[] = $onyx_parent->config[$v[1]];
                    } elseif (!empty(
$onyx_parent->page[$v[1]])) {
                        
$match[] = $v[0];
                        
$replace[] = $onyx_parent->page[$v[1]];
                    } elseif (!empty(
$GLOBALS[$v[1]])) {
                        
// only other source, global vars i guess
                        
$match[] = $v[0];
                        
$replace[] = $GLOBALS[$v[1]];
                    } else {
                        
$match[] = $v[0];
                        
$replace[] = str_replace('$''\$'$v[0]);
                    }
                }
            }

            if (
is_array($match)) {
                
$evaluated str_replace($match$replace$m[2]);
            } else {
                
$evaluated $m[2];
            }

            
// there seriously has to be a better way of doing this
            
$varline "['".preg_replace("/\./""']['"$m[1])."']";
            
$varline "return".$varline;

            eval(
"\$$varline = \"$evaluated\";");
        
}

        
fclose($fp);
        
$line++;

        
// phew
        
return $return;
    }
}

?>


Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.