TimeTrex Community Edition v16.2.0

This commit is contained in:
2022-12-13 07:10:06 +01:00
commit 472f000c1b
6810 changed files with 2636142 additions and 0 deletions

View File

@@ -0,0 +1,169 @@
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: Apache.php 203595 2005-12-24 02:34:39Z aashley $
/**
* Simple config parser for apache httpd.conf files
* A more complex version could handle directives as
* associative arrays.
*
* @author Bertrand Mansion <bmansion@mamasam.com>
* @package Config
*/
class Config_Container_Apache {
/**
* This class options
* Not used at the moment
*
* @var array
*/
var $options = array();
/**
* Constructor
*
* @access public
* @param string $options (optional)Options to be used by renderer
*/
function __construct($options = array())
{
$this->options = $options;
} // end constructor
/**
* Parses the data of the given configuration file
*
* @access public
* @param string $datasrc path to the configuration file
* @param object $obj reference to a config object
* @return mixed returns a PEAR_ERROR, if error occurs or true if ok
*/
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!is_readable($datasrc)) {
return PEAR::raiseError("Datasource file cannot be read.", null, PEAR_ERROR_RETURN);
}
$lines = file($datasrc);
$n = 0;
$lastline = '';
$sections[0] =& $obj->container;
foreach ($lines as $line) {
$n++;
if (!preg_match('/^\s*#/', $line) &&
preg_match('/^\s*(.*)\s+\\\$/', $line, $match)) {
// directive on more than one line
$lastline .= $match[1].' ';
continue;
}
if ($lastline != '') {
$line = $lastline.trim($line);
$lastline = '';
}
if (preg_match('/^\s*#+\s*(.*?)\s*$/', $line, $match)) {
// a comment
$currentSection =& $sections[count($sections)-1];
$currentSection->createComment($match[1]);
} elseif (trim($line) == '') {
// a blank line
$currentSection =& $sections[count($sections)-1];
$currentSection->createBlank();
} elseif (preg_match('/^\s*(\w+)(?:\s+(.*?)|)\s*$/', $line, $match)) {
// a directive
$currentSection =& $sections[count($sections)-1];
$currentSection->createDirective($match[1], $match[2]);
} elseif (preg_match('/^\s*<(\w+)(?:\s+([^>]*)|\s*)>\s*$/', $line, $match)) {
// a section opening
if (!isset($match[2]))
$match[2] = '';
$currentSection =& $sections[count($sections)-1];
$attributes = explode(' ', $match[2]);
$sections[] =& $currentSection->createSection($match[1], $attributes);
} elseif (preg_match('/^\s*<\/(\w+)\s*>\s*$/', $line, $match)) {
// a section closing
$currentSection =& $sections[count($sections)-1];
if ($currentSection->name != $match[1]) {
return PEAR::raiseError("Section not closed in '$datasrc' at line $n.", null, PEAR_ERROR_RETURN);
}
array_pop($sections);
} else {
return PEAR::raiseError("Syntax error in '$datasrc' at line $n.", null, PEAR_ERROR_RETURN);
}
}
return $return;
} // end func parseDatasrc
/**
* Returns a formatted string of the object
* @param object $obj Container object to be output as string
* @access public
* @return string
*/
function toString(&$obj)
{
static $deep = -1;
$ident = '';
if (!$obj->isRoot()) {
// no indent for root
$deep++;
$ident = str_repeat(' ', $deep);
}
if (!isset($string)) {
$string = '';
}
switch ($obj->type) {
case 'blank':
$string = "\n";
break;
case 'comment':
$string = $ident.'# '.$obj->content."\n";
break;
case 'directive':
$string = $ident.$obj->name.' '.$obj->content."\n";
break;
case 'section':
if (!$obj->isRoot()) {
$string = $ident.'<'.$obj->name;
if (is_array($obj->attributes) && count($obj->attributes) > 0) {
foreach ($obj->attributes as $attr => $val) {
$string .= ' '.$val;
}
}
$string .= ">\n";
}
if (count($obj->children) > 0) {
for ($i = 0; $i < count($obj->children); $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
if (!$obj->isRoot()) {
// object is not root
$string .= $ident.'</'.$obj->name.">\n";
}
break;
default:
$string = '';
}
if (!$obj->isRoot()) {
$deep--;
}
return $string;
} // end func toString
} // end class Config_Container_Apache
?>

View File

@@ -0,0 +1,139 @@
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: GenericConf.php 306537 2010-12-21 08:09:34Z cweiske $
/**
* Config parser for generic .conf files like
* htdig.conf...
*
* @author Bertrand Mansion <bmansion@mamasam.com>
* @package Config
*/
class Config_Container_GenericConf {
/**
* This class options:
* Ex: $options['comment'] = '#';
* Ex: $options['equals'] = ':';
* Ex: $options['newline'] = '\\';
*
* @var array
*/
var $options = array();
/**
* Constructor
*
* @access public
* @param string $options (optional)Options to be used by renderer
*/
function __construct($options = array())
{
if (empty($options['comment'])) {
$options['comment'] = '#';
}
if (empty($options['equals'])) {
$options['equals'] = ':';
}
if (empty($options['newline'])) {
$options['newline'] = '\\';
}
$this->options = $options;
} // end constructor
/**
* Parses the data of the given configuration file
*
* @access public
* @param string $datasrc path to the configuration file
* @param object $obj reference to a config object
* @return mixed returns a PEAR_ERROR, if error occurs or true if ok
*/
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!is_readable($datasrc)) {
return PEAR::raiseError("Datasource file cannot be read.", null, PEAR_ERROR_RETURN);
}
$lines = file($datasrc);
$n = 0;
$lastline = '';
$currentSection =& $obj->container;
foreach ($lines as $line) {
$n++;
if (!preg_match('/^\s*'.$this->options['comment'].'/', $line) &&
preg_match('/^\s*(.*)'.$this->options['newline'].'\s*$/', $line, $match)) {
// directive on more than one line
$lastline .= $match[1];
continue;
}
if ($lastline != '') {
$line = $lastline.trim($line);
$lastline = '';
}
if (preg_match('/^\s*'.$this->options['comment'].'+\s*(.*?)\s*$/', $line, $match)) {
// a comment
$currentSection->createComment($match[1]);
} elseif (preg_match('/^\s*$/', $line)) {
// a blank line
$currentSection->createBlank();
} elseif (preg_match('/^\s*([\w-]+)\s*'.$this->options['equals'].'\s*((.*?)|)\s*$/', $line, $match)) {
// a directive
$currentSection->createDirective($match[1], $match[2]);
} else {
return PEAR::raiseError("Syntax error in '$datasrc' at line $n.", null, PEAR_ERROR_RETURN);
}
}
return $return;
} // end func parseDatasrc
/**
* Returns a formatted string of the object
* @param object $obj Container object to be output as string
* @access public
* @return string
*/
function toString(&$obj)
{
$string = '';
switch ($obj->type) {
case 'blank':
$string = "\n";
break;
case 'comment':
$string = $this->options['comment'].$obj->content."\n";
break;
case 'directive':
$string = $obj->name.$this->options['equals'].$obj->content."\n";
break;
case 'section':
// How to deal with sections ???
if (count($obj->children) > 0) {
for ($i = 0; $i < count($obj->children); $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
break;
default:
$string = '';
}
return $string;
} // end func toString
} // end class Config_Container_GenericConf
?>

View File

@@ -0,0 +1,365 @@
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: IniCommented.php 306554 2010-12-21 20:04:20Z cweiske $
/**
* Config parser for PHP .ini files with comments
*
* @author Bertrand Mansion <bmansion@mamasam.com>
* @package Config
*/
class Config_Container_IniCommented {
/**
* Options for this class:
* - linebreak - Character to use as new line break when serializing
*
* @var array
*/
var $options = array(
'linebreak' => "\n"
);
/**
* Constructor
*
* @access public
* @param string $options (optional)Options to be used by renderer
*/
function __construct($options = array())
{
$this->options = array_merge($this->options, $options);
} // end constructor
/**
* Parses the data of the given configuration file
*
* @access public
* @param string $datasrc path to the configuration file
* @param object $obj reference to a config object
* @return mixed returns a PEAR_ERROR, if error occurs or true if ok
*/
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!file_exists($datasrc)) {
return PEAR::raiseError(
'Datasource file does not exist.',
null, PEAR_ERROR_RETURN
);
}
$lines = file($datasrc);
if ($lines === false) {
return PEAR::raiseError(
'File could not be read',
null, PEAR_ERROR_RETURN
);
}
$n = 0;
$lastline = '';
$currentSection =& $obj->container;
foreach ($lines as $line) {
$n++;
if (preg_match('/^\s*;(.*?)\s*$/', $line, $match)) {
// a comment
$currentSection->createComment($match[1]);
} elseif (preg_match('/^\s*$/', $line)) {
// a blank line
$currentSection->createBlank();
} elseif (preg_match('/^\s*\[\s*(.*)\s*\]\s*$/', $line, $match)) { //Do this before the below directive, so it matches sections first.
// a section
$currentSection =& $obj->container->createSection($match[1]);
} elseif (preg_match('/^\s*([a-zA-Z0-9_\-\.\s:\[\]]*)\s*=\s*(.*)\s*$/', $line, $match)) { //Must support [] (square brackets) in directives ie: myval[subarray] = blah
// a directive
$values = $this->_quoteAndCommaParser($match[2]);
if (PEAR::isError($values)) {
return PEAR::raiseError($values);
}
if (count($values)) {
foreach($values as $value) {
if ($value[0] == 'normal') {
$currentSection->createDirective(trim($match[1]), $value[1]);
}
if ($value[0] == 'comment') {
$currentSection->createComment(substr($value[1], 1));
}
}
}
} else {
$retval = PEAR::raiseError("Syntax error in '$datasrc' at line $n.", null, PEAR_ERROR_RETURN);
return $retval;
}
}
return $return;
} // end func parseDatasrc
/**
* Quote and Comma Parser for INI files
*
* This function allows complex values such as:
*
* <samp>
* mydirective = "Item, number \"1\"", Item 2 ; "This" is really, really tricky
* </samp>
* @param string $text value of a directive to parse for quotes/multiple values
* @return array The array returned contains multiple values, if any (unquoted literals
* to be used as is), and a comment, if any. The format of the array is:
*
* <pre>
* array(array('normal', 'first value'),
* array('normal', 'next value'),...
* array('comment', '; comment with leading ;'))
* </pre>
* @author Greg Beaver <cellog@users.sourceforge.net>
* @access private
*/
function _quoteAndCommaParser($text)
{
$text = trim($text);
if ($text == '') {
$emptyNode = array();
$emptyNode[0][0] = 'normal';
$emptyNode[0][1] = '';
return $emptyNode;
}
// tokens
$tokens['normal'] = array('"', ';', ',');
$tokens['quote'] = array('"', '\\');
$tokens['escape'] = false; // cycle
$tokens['after_quote'] = array(',', ';');
// events
$events['normal'] = array('"' => 'quote', ';' => 'comment', ',' => 'normal');
$events['quote'] = array('"' => 'after_quote', '\\' => 'escape');
$events['after_quote'] = array(',' => 'normal', ';' => 'comment');
// state stack
$stack = array();
// return information
$return = array();
$returnpos = 0;
$returntype = 'normal';
// initialize
array_push($stack, 'normal');
$pos = 0; // position in $text
do {
$char = $text[$pos];
$state = $this->_getQACEvent($stack);
if ($tokens[$state]) {
if (in_array($char, $tokens[$state])) {
switch($events[$state][$char]) {
case 'quote' :
if ($state == 'normal' &&
isset($return[$returnpos]) &&
!empty($return[$returnpos][1])) {
return PEAR::raiseError(
'invalid ini syntax, quotes cannot follow'
. " text '$text'",
null, PEAR_ERROR_RETURN
);
}
if ($returnpos >= 0 && isset($return[$returnpos])) {
// trim any unnecessary whitespace in earlier entries
$return[$returnpos][1] = trim($return[$returnpos][1]);
} else {
$returnpos++;
}
$return[$returnpos] = array('normal', '');
array_push($stack, 'quote');
continue 2;
break;
case 'comment' :
// comments go to the end of the line, so we are done
$return[++$returnpos] = array('comment', substr($text, $pos));
return $return;
break;
case 'after_quote' :
array_push($stack, 'after_quote');
break;
case 'escape' :
// don't save the first slash
array_push($stack, 'escape');
continue 2;
break;
case 'normal' :
// start a new segment
if ($state == 'normal') {
$returnpos++;
continue 2;
} else {
while ($state != 'normal') {
array_pop($stack);
$state = $this->_getQACEvent($stack);
}
$returnpos++;
}
break;
default :
PEAR::raiseError(
"::_quoteAndCommaParser oops, state missing",
null, PEAR_ERROR_DIE
);
break;
}
} else {
if ($state != 'after_quote') {
if (!isset($return[$returnpos])) {
$return[$returnpos] = array('normal', '');
}
// add this character to the current ini segment if
// non-empty, or if in a quote
if ($state == 'quote') {
$return[$returnpos][1] .= $char;
} elseif (!empty($return[$returnpos][1]) ||
(empty($return[$returnpos][1]) && trim($char) != '')) {
if (!isset($return[$returnpos])) {
$return[$returnpos] = array('normal', '');
}
$return[$returnpos][1] .= $char;
if (strcasecmp('true', $return[$returnpos][1]) == 0) {
$return[$returnpos][1] = TRUE;
} elseif (strcasecmp('false', $return[$returnpos][1]) == 0) {
$return[$returnpos][1] = FALSE;
}
}
} else {
if (trim($char) != '') {
return PEAR::raiseError(
'invalid ini syntax, text after a quote'
. " not allowed '$text'",
null, PEAR_ERROR_RETURN
);
}
}
}
} else {
if ( $state == 'escape' ) {
$return[$returnpos][1] .= '\\'.$char;
} else {
// no tokens, so add this one and cycle to previous state
$return[$returnpos][1] .= $char;
}
//$return[$returnpos][1] .= $char;
array_pop($stack);
}
} while (++$pos < strlen($text));
return $return;
} // end func _quoteAndCommaParser
/**
* Retrieve the state off of a state stack for the Quote and Comma Parser
* @param array $stack The parser state stack
* @author Greg Beaver <cellog@users.sourceforge.net>
* @access private
*/
function _getQACEvent($stack)
{
return array_pop($stack);
} // end func _getQACEvent
/**
* Returns a formatted string of the object
* @param object $obj Container object to be output as string
* @access public
* @return string
*/
function toString(&$obj)
{
static $childrenCount, $commaString;
if (!isset($string)) {
$string = '';
}
switch ($obj->type) {
case 'blank':
$string = $this->options['linebreak'];
break;
case 'comment':
$string = ';'.$obj->content . $this->options['linebreak'];
break;
case 'directive':
$count = $obj->parent->countChildren('directive', $obj->name);
$content = $obj->content;
if ($content === false) {
$content = 'FALSE';
} elseif ($content === true) {
$content = 'TRUE';
} elseif ( strlen(trim($content)) < strlen($content) ||
strpos($content, ',') !== false ||
strpos($content, ';') !== false ||
strpos($content, ':') !== false ||
strpos($content, '\\') !== false ||
strpos($content, '/') !== false ||
strpos($content, '=') !== false ||
strpos($content, '"') !== false ||
strpos($content, '%') !== false ||
strpos($content, '~') !== false ||
strpos($content, '!') !== false ||
strpos($content, '|') !== false ||
strpos($content, '&') !== false ||
strpos($content, '(') !== false ||
strpos($content, ')') !== false ||
$content === 'none') {
$content = '"'. $content .'"';
}
if ($count > 1) {
// multiple values for a directive are separated by a comma
if (isset($childrenCount[$obj->name])) {
$childrenCount[$obj->name]++;
} else {
$childrenCount[$obj->name] = 0;
$commaString[$obj->name] = $obj->name.' = ';
}
if ($childrenCount[$obj->name] == $count-1) {
// Clean the static for future calls to toString
$string .= $commaString[$obj->name] . $content
. $this->options['linebreak'];
unset($childrenCount[$obj->name]);
unset($commaString[$obj->name]);
} else {
$commaString[$obj->name] .= $content.', ';
}
} else {
$string = $obj->name.' = '.$content . $this->options['linebreak'];
}
break;
case 'section':
if (!$obj->isRoot()) {
$string = '[' . $obj->name . ']' . $this->options['linebreak'];
}
if (count($obj->children) > 0) {
for ($i = 0; $i < count($obj->children); $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
break;
default:
$string = '';
}
return $string;
} // end func toString
} // end class Config_Container_IniCommented
?>

View File

@@ -0,0 +1,217 @@
<?php
/**
* Part of the PEAR Config package
*
* PHP Version 4
*
* @category Configuration
* @package Config
* @author Bertrand Mansion <bmansion@mamasam.com>
* @license http://www.php.net/license PHP License
* @link http://pear.php.net/package/Config
*/
/**
* Config parser for PHP .ini files
* Faster because it uses parse_ini_file() but get rid of comments,
* quotes, types and converts On, Off, True, False, Yes, No to 0 and 1.
*
* Empty lines and comments are not preserved.
*
* @category Configuration
* @package Config
* @author Bertrand Mansion <bmansion@mamasam.com>
* @license http://www.php.net/license PHP License
* @link http://pear.php.net/package/Config
*/
class Config_Container_IniFile
{
/**
* This class options
* Not used at the moment
*
* @var array
*/
var $options = array();
/**
* Constructor
*
* @param string $options (optional)Options to be used by renderer
*
* @access public
*/
function __construct($options = array())
{
$this->options = $options;
} // end constructor
/**
* Parses the data of the given configuration file
*
* @param string $datasrc path to the configuration file
* @param object &$obj reference to a config object
*
* @return mixed Returns a PEAR_ERROR, if error occurs or true if ok
*
* @access public
*/
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!file_exists($datasrc)) {
return PEAR::raiseError(
"Datasource file does not exist.",
null, PEAR_ERROR_RETURN
);
}
$currentSection =& $obj->container;
$confArray = parse_ini_file($datasrc, true);
if (!$confArray) {
return PEAR::raiseError(
"File '$datasrc' does not contain configuration data.",
null, PEAR_ERROR_RETURN
);
}
foreach ($confArray as $key => $value) {
if (is_array($value)) {
$currentSection =& $obj->container->createSection($key);
foreach ($value as $directive => $content) {
// try to split the value if comma found
if (!is_array($content) && strpos($content, '"') === false) {
$values = preg_split('/\s*,\s+/', $content);
if (count($values) > 1) {
foreach ($values as $k => $v) {
$currentSection->createDirective($directive, $v);
}
} else {
$currentSection->createDirective($directive, $content);
}
} else {
$currentSection->createDirective($directive, $content);
}
}
} else {
$currentSection->createDirective($key, $value);
}
}
return $return;
} // end func parseDatasrc
/**
* Returns a formatted string of the object
*
* @param object &$obj Container object to be output as string
*
* @return string
*
* @access public
*/
function toString(&$obj)
{
static $childrenCount, $commaString;
if (!isset($string)) {
$string = '';
}
switch ($obj->type) {
case 'blank':
$string = "\n";
break;
case 'comment':
$string = ';'.$obj->content."\n";
break;
case 'directive':
$count = $obj->parent->countChildren('directive', $obj->name);
$content = $obj->content;
if (!is_array($content)) {
$content = $this->contentToString($content);
if ($count > 1) {
// multiple values for a directive are separated by a comma
if (isset($childrenCount[$obj->name])) {
$childrenCount[$obj->name]++;
} else {
$childrenCount[$obj->name] = 0;
$commaString[$obj->name] = $obj->name.'=';
}
if ($childrenCount[$obj->name] == $count-1) {
// Clean the static for future calls to toString
$string .= $commaString[$obj->name].$content."\n";
unset($childrenCount[$obj->name]);
unset($commaString[$obj->name]);
} else {
$commaString[$obj->name] .= $content.', ';
}
} else {
$string = $obj->name.'='.$content."\n";
}
} else {
//array
$string = '';
$n = 0;
foreach ($content as $contentKey => $contentValue) {
if (is_integer($contentKey) && $contentKey == $n) {
$stringKey = '';
++$n;
} else {
$stringKey = $contentKey;
}
$string .= $obj->name . '[' . $stringKey . ']='
. $this->contentToString($contentValue) . "\n";
}
}
break;
case 'section':
if (!$obj->isRoot()) {
$string = '['.$obj->name."]\n";
}
if (count($obj->children) > 0) {
for ($i = 0; $i < count($obj->children); $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
break;
default:
$string = '';
}
return $string;
} // end func toString
/**
* Converts a given content variable to a string that can
* be used as value in a ini file
*
* @param mixed $content Value
*
* @return string $content String to be used as ini value
*/
function contentToString($content)
{
if ($content === false) {
$content = '0';
} else if ($content === true) {
$content = '1';
} else if (strlen(trim($content)) < strlen($content)
|| strpos($content, ',') !== false
|| strpos($content, ';') !== false
|| strpos($content, '=') !== false
|| strpos($content, '"') !== false
|| strpos($content, '%') !== false
|| strpos($content, '~') !== false
|| strpos($content, '!') !== false
|| strpos($content, '|') !== false
|| strpos($content, '&') !== false
|| strpos($content, '(') !== false
|| strpos($content, ')') !== false
|| $content === 'none'
) {
$content = '"'.addslashes($content).'"';
}
return $content;
}
} // end class Config_Container_IniFile
?>

View File

@@ -0,0 +1,258 @@
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: PHPArray.php 306488 2010-12-20 08:45:09Z cweiske $
/**
* Config parser for common PHP configuration array
* such as found in the horde project.
*
* Options expected is:
* 'name' => 'conf'
* Name of the configuration array.
* Default is $conf[].
* 'useAttr' => true
* Whether we render attributes
*
* @author Bertrand Mansion <bmansion@mamasam.com>
* @package Config
*/
class Config_Container_PHPArray {
/**
* This class options:
* - name of the config array to parse/output
* Ex: $options['name'] = 'myconf';
* - Whether to add attributes to the array
* Ex: $options['useAttr'] = false;
* - Whether to treat numbered arrays as duplicates of their parent directive
* or as individual directives
* Ex: $options['duplicateDirectives'] = false;
*
* @var array
*/
var $options = array('name' => 'conf',
'useAttr' => true,
'duplicateDirectives' => true);
/**
* Constructor
*
* @access public
* @param string $options Options to be used by renderer
*/
function __construct($options = array())
{
foreach ($options as $key => $value) {
$this->options[$key] = $value;
}
} // end constructor
/**
* Parses the data of the given configuration file
*
* @access public
* @param string $datasrc path to the configuration file
* @param object $obj reference to a config object
* @return mixed returns a PEAR_ERROR, if error occurs or true if ok
*/
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (empty($datasrc)) {
return PEAR::raiseError("Datasource file path is empty.", null, PEAR_ERROR_RETURN);
}
if (is_array($datasrc)) {
$this->_parseArray($datasrc, $obj->container);
} else {
if (!file_exists($datasrc)) {
return PEAR::raiseError("Datasource file does not exist.", null, PEAR_ERROR_RETURN);
} else {
include($datasrc);
if (!isset(${$this->options['name']}) || !is_array(${$this->options['name']})) {
return PEAR::raiseError("File '$datasrc' does not contain a required '".$this->options['name']."' array.", null, PEAR_ERROR_RETURN);
}
}
$this->_parseArray(${$this->options['name']}, $obj->container);
}
return $return;
} // end func parseDatasrc
/**
* Parses the PHP array recursively
* @param array $array array values from the config file
* @param object $container reference to the container object
* @access private
* @return void
*/
function _parseArray($array, &$container)
{
foreach ($array as $key => $value) {
switch ((string)$key) {
case '@':
$container->setAttributes($value);
break;
case '#':
$container->setType('directive');
$container->setContent($value);
break;
default:
if (is_array($value)) {
if ($this->options['duplicateDirectives'] == true
//speed (first/one key is numeric)
&& is_integer(key($value))
//accuracy (all keys are numeric)
&& 1 == count(array_unique(array_map('is_numeric', array_keys($value))))
) {
foreach ($value as $nestedValue) {
if (is_array($nestedValue)) {
$section =& $container->createSection($key);
$this->_parseArray($nestedValue, $section);
} else {
$container->createDirective($key, $nestedValue);
}
}
} else {
$section =& $container->createSection($key);
$this->_parseArray($value, $section);
}
} else {
$container->createDirective($key, $value);
}
}
}
} // end func _parseArray
/**
* Returns a formatted string of the object
* @param object $obj Container object to be output as string
* @access public
* @return string
*/
function toString(&$obj)
{
if (!isset($string)) {
$string = '';
}
switch ($obj->type) {
case 'blank':
$string .= "\n";
break;
case 'comment':
$string .= '// '.$obj->content."\n";
break;
case 'directive':
$attrString = '';
$parentString = $this->_getParentString($obj);
$attributes = $obj->getAttributes();
if ($this->options['useAttr'] && is_array($attributes) && count($attributes) > 0) {
// Directive with attributes '@' and value '#'
$string .= $parentString."['#']";
foreach ($attributes as $attr => $val) {
$attrString .= $parentString."['@']"
."['".$attr."'] = '".addcslashes($val, "\\'")."';\n";
}
} else {
$string .= $parentString;
}
$string .= ' = ';
if (is_string($obj->content)) {
$string .= "'".addcslashes($obj->content, "\\'")."'";
} elseif (is_int($obj->content) || is_float($obj->content)) {
$string .= $obj->content;
} elseif (is_bool($obj->content)) {
$string .= ($obj->content) ? 'true' : 'false';
} elseif ($obj->content === null) {
$string .= 'null';
}
$string .= ";\n";
$string .= $attrString;
break;
case 'section':
$attrString = '';
$attributes = $obj->getAttributes();
if ($this->options['useAttr'] && is_array($attributes) && count($attributes) > 0) {
$parentString = $this->_getParentString($obj);
foreach ($attributes as $attr => $val) {
$attrString .= $parentString."['@']"
."['".$attr."'] = '".addcslashes($val, "\\'")."';\n";
}
}
$string .= $attrString;
if ($count = count($obj->children)) {
for ($i = 0; $i < $count; $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
break;
default:
$string = '';
}
return $string;
} // end func toString
/**
* Returns a formatted string of the object parents
* @access private
* @return string
*/
function _getParentString(&$obj)
{
$string = '';
if (!$obj->isRoot()) {
$string = is_int($obj->name) ? "[".$obj->name."]" : "['".$obj->name."']";
$string = $this->_getParentString($obj->parent).$string;
$count = $obj->parent->countChildren(null, $obj->name);
if ($count > 1) {
$string .= '['.$obj->getItemPosition(false).']';
}
}
else {
if (empty($this->options['name'])) {
$string .= '$'.$obj->name;
} else {
$string .= '$'.$this->options['name'];
}
}
return $string;
} // end func _getParentString
/**
* Writes the configuration to a file
*
* @param mixed datasrc info on datasource such as path to the configuraton file
* @param string configType (optional)type of configuration
* @access public
* @return string
*/
function writeDatasrc($datasrc, &$obj)
{
$fp = @fopen($datasrc, 'w');
if ($fp) {
$string = "<?php\n". $this->toString($obj) ."?>"; // <? : Fix my syntax coloring
$len = strlen($string);
@flock($fp, LOCK_EX);
@fwrite($fp, $string, $len);
@flock($fp, LOCK_UN);
@fclose($fp);
return true;
} else {
return PEAR::raiseError('Cannot open datasource for writing.', 1, PEAR_ERROR_RETURN);
}
} // end func writeDatasrc
} // end class Config_Container_PHPArray
?>

View File

@@ -0,0 +1,222 @@
<?php
/**
* Part of the PEAR Config package
*
* PHP Version 4
*
* @category Configuration
* @package Config
* @author Phillip Oertel <me@phillipoertel.com>
* @license http://www.php.net/license PHP License
* @version SVN: $Id: PHPConstants.php 306571 2010-12-22 06:50:39Z cweiske $
* @link http://pear.php.net/package/Config
*/
require_once 'Config/Container.php';
/**
* Config parser for PHP constant files
*
* @category Configuration
* @package Config
* @author Phillip Oertel <me@phillipoertel.com>
* @license http://www.php.net/license PHP License
* @link http://pear.php.net/package/Config
*/
class Config_Container_PHPConstants extends Config_Container
{
/**
* Valid config options:
* - "lowercase" - boolean - config names are lowercased when reading them
*
* @var array
*/
var $options = array(
'lowercase' => false
);
/**
* Constructor
*
* @param string $options (optional)Options to be used by renderer
*
* @access public
*/
function __construct($options = array())
{
$this->options = array_merge($this->options, $options);
} // end constructor
/**
* Parses the data of the given configuration file
*
* @param string $datasrc Path to the configuration file
* @param object &$obj Reference to a config object
*
* @return mixed PEAR_ERROR, if error occurs or true if ok
*
* @access public
*/
function &parseDatasrc($datasrc, &$obj)
{
$return = true;
if (!file_exists($datasrc)) {
return PEAR::raiseError(
'Datasource file does not exist.',
null, PEAR_ERROR_RETURN
);
}
$fileContent = file_get_contents($datasrc, true);
if (!$fileContent) {
return PEAR::raiseError(
"File '$datasrc' could not be read.",
null, PEAR_ERROR_RETURN
);
}
$rows = explode("\n", $fileContent);
for ($i=0, $max=count($rows); $i<$max; $i++) {
$line = $rows[$i];
//blanks?
// sections
if (preg_match("/^\/\/\s*$/", $line)) {
preg_match("/^\/\/\s*(.+)$/", $rows[$i+1], $matches);
$obj->container->createSection(trim($matches[1]));
$i += 2;
continue;
}
// comments
if (preg_match("/^\/\/\s*(.+)$/", $line, $matches)
|| preg_match("/^#\s*(.+)$/", $line, $matches)
) {
$obj->container->createComment(trim($matches[1]));
continue;
}
// directives
$regex = "/^\s*define\s*\('([A-Z1-9_]+)',\s*'*(.[^\']*)'*\)/";
preg_match($regex, $line, $matches);
if (!empty($matches)) {
$name = trim($matches[1]);
if ($this->options['lowercase']) {
$name = strtolower($name);
}
$obj->container->createDirective(
$name, trim($matches[2])
);
}
}
return $return;
} // end func parseDatasrc
/**
* Returns a formatted string of the object
*
* @param object &$obj Container object to be output as string
*
* @return string
*
* @access public
*/
function toString(&$obj)
{
$string = '';
switch ($obj->type)
{
case 'blank':
$string = "\n";
break;
case 'comment':
$string = '// '.$obj->content."\n";
break;
case 'directive':
$content = $obj->content;
// don't quote numeric values, true/false and constants
if (is_bool($content)) {
$content = var_export($content, true);
} else if (!is_numeric($content)
&& !in_array($content, array('false', 'true'))
&& !preg_match('/^[A-Z_]+$/', $content)
) {
$content = "'" . str_replace("'", '\\\'', $content) . "'";
}
$string = 'define('
. '\'' . strtoupper($obj->name) . '\''
. ', ' . $content . ');'
. chr(10);
break;
case 'section':
if (!$obj->isRoot()) {
$string = chr(10);
$string .= '//'.chr(10);
$string .= '// '.$obj->name.chr(10);
$string .= '//'.chr(10);
}
if (count($obj->children) > 0) {
for ($i = 0, $max = count($obj->children); $i < $max; $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
break;
default:
$string = '';
}
return $string;
} // end func toString
/**
* Writes the configuration to a file
*
* @param mixed $datasrc Info on datasource such as path to the file
* @param string &$obj Configuration object to write
*
* @return mixed PEAR_Error on failure or boolean true if all went well
*
* @access public
*/
function writeDatasrc($datasrc, &$obj)
{
$fp = @fopen($datasrc, 'w');
if (!$fp) {
return PEAR::raiseError(
'Cannot open datasource for writing.',
1, PEAR_ERROR_RETURN
);
}
$string = "<?php";
$string .= "\n\n";
$string .= '/**' . chr(10);
$string .= ' *' . chr(10);
$string .= ' * AUTOMATICALLY GENERATED CODE - DO NOT EDIT BY HAND' . chr(10);
$string .= ' *' . chr(10);
$string .= '**/' . chr(10);
$string .= $this->toString($obj);
$string .= "\n?>"; // <? : Fix my syntax coloring
$len = strlen($string);
@flock($fp, LOCK_EX);
@fwrite($fp, $string, $len);
@flock($fp, LOCK_UN);
@fclose($fp);
// need an error check here
return true;
} // end func writeDatasrc
} // end class Config_Container_PHPConstants
?>

View File

@@ -0,0 +1,249 @@
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: XML.php 203592 2005-12-24 02:24:30Z aashley $
require_once('XML/Parser.php');
require_once('XML/Util.php');
/**
* Config parser for XML Files
*
* @author Bertrand Mansion <bmansion@mamasam.com>
* @package Config
*/
class Config_Container_XML extends XML_Parser
{
/**
* Deep level used for indentation
*
* @var int
* @access private
*/
var $_deep = -1;
/**
* This class options:
* version (1.0) : XML version
* encoding (ISO-8859-1) : XML content encoding
* name : like in phparray, name of your config global entity
* indent : char used for indentation
* linebreak : char used for linebreak
* addDecl : whether to add the xml declaration at beginning or not
* useAttr : whether to use the attributes
* isFile : whether the given content is a file or an XML string
* useCData : whether to surround data with <![CDATA[...]]>
*
* @var array
*/
var $options = array('version' => '1.0',
'encoding' => 'ISO-8859-1',
'name' => '',
'indent' => ' ',
'linebreak' => "\n",
'addDecl' => true,
'useAttr' => true,
'isFile' => true,
'useCData' => false);
/**
* Container objects
*
* @var array
*/
var $containers = array();
/**
* Constructor
*
* @access public
* @param string $options Options to be used by renderer
* version : (1.0) XML version
* encoding : (ISO-8859-1) XML content encoding
* name : like in phparray, name of your config global entity
* indent : char used for indentation
* linebreak : char used for linebreak
* addDecl : whether to add the xml declaration at beginning or not
* useAttr : whether to use the attributes
* isFile : whether the given content is a file or an XML string
*/
function __construct($options = array())
{
foreach ($options as $key => $value) {
$this->options[$key] = $value;
}
} // end constructor
/**
* Parses the data of the given configuration file
*
* @access public
* @param string $datasrc path to the configuration file
* @param object $obj reference to a config object
* @return mixed returns a PEAR_ERROR, if error occurs or true if ok
*/
function &parseDatasrc($datasrc, &$obj)
{
$err = true;
$this->folding = false;
$this->cdata = null;
$this->XML_Parser($this->options['encoding'], 'event');
$this->containers[0] =& $obj->container;
if (is_string($datasrc)) {
if ($this->options['isFile']) {
$err = $this->setInputFile($datasrc);
if (PEAR::isError($err)) {
return $err;
}
$err = $this->parse();
} else {
$err = $this->parseString($datasrc, true);
}
} else {
$this->setInput($datasrc);
$err = $this->parse();
}
return $err;
} // end func parseDatasrc
/**
* Handler for the xml-data
*
* @param mixed $xp ignored
* @param string $elem name of the element
* @param array $attribs attributes for the generated node
*
* @access private
*/
function startHandler($xp, $elem, &$attribs)
{
$container = new Config_Container('section', $elem, null, $attribs);
$this->containers[] =& $container;
return null;
} // end func startHandler
/**
* Handler for the xml-data
*
* @param mixed $xp ignored
* @param string $elem name of the element
*
* @access private
*/
function endHandler($xp, $elem)
{
$count = count($this->containers);
$container =& $this->containers[$count-1];
$currentSection =& $this->containers[$count-2];
if (count($container->children) == 0) {
$container->setType('directive');
$container->setContent(trim($this->cdata));
}
$currentSection->addItem($container);
array_pop($this->containers);
$this->cdata = null;
return null;
} // end func endHandler
/*
* The xml character data handler
*
* @param mixed $xp ignored
* @param string $data PCDATA between tags
*
* @access private
*/
function cdataHandler($xp, $cdata)
{
$this->cdata .= $cdata;
} // end func cdataHandler
/**
* Returns a formatted string of the object
* @param object $obj Container object to be output as string
* @access public
* @return string
*/
function toString(&$obj)
{
$indent = '';
if (!$obj->isRoot()) {
// no indent for root
$this->_deep++;
$indent = str_repeat($this->options['indent'], $this->_deep);
} else {
// Initialize string with xml declaration
$string = '';
if ($this->options['addDecl']) {
$string .= XML_Util::getXMLDeclaration($this->options['version'], $this->options['encoding']);
$string .= $this->options['linebreak'];
}
if (!empty($this->options['name'])) {
$string .= '<'.$this->options['name'].'>'.$this->options['linebreak'];
$this->_deep++;
$indent = str_repeat($this->options['indent'], $this->_deep);
}
}
if (!isset($string)) {
$string = '';
}
switch ($obj->type) {
case 'directive':
$attributes = ($this->options['useAttr']) ? $obj->attributes : array();
$string .= $indent.XML_Util::createTag($obj->name, $attributes, $obj->content, null,
($this->options['useCData'] ? XML_UTIL_CDATA_SECTION : XML_UTIL_REPLACE_ENTITIES));
$string .= $this->options['linebreak'];
break;
case 'comment':
$string .= $indent.'<!-- '.$obj->content.' -->';
$string .= $this->options['linebreak'];
break;
case 'section':
if (!$obj->isRoot()) {
$string = $indent.'<'.$obj->name;
$string .= ($this->options['useAttr']) ? XML_Util::attributesToString($obj->attributes) : '';
}
if ($children = count($obj->children)) {
if (!$obj->isRoot()) {
$string .= '>'.$this->options['linebreak'];
}
for ($i = 0; $i < $children; $i++) {
$string .= $this->toString($obj->getChild($i));
}
}
if (!$obj->isRoot()) {
if ($children) {
$string .= $indent.'</'.$obj->name.'>'.$this->options['linebreak'];
} else {
$string .= '/>'.$this->options['linebreak'];
}
} else {
if (!empty($this->options['name'])) {
$string .= '</'.$this->options['name'].'>'.$this->options['linebreak'];
}
}
break;
default:
$string = '';
}
if (!$obj->isRoot()) {
$this->_deep--;
}
return $string;
} // end func toString
} // end class Config_Container_XML
?>