110 lines
2.3 KiB
PHP
110 lines
2.3 KiB
PHP
<?php
|
|
// This stuff all relates to reading and parsing the configuration files.
|
|
// A lot of the code is HIDEOUS - but it does work. It needs a cleanup.
|
|
|
|
function get_config($page) {
|
|
|
|
$xml_parser = make_xml_parser("ConfigcharacterData", "ConfigstartElement",
|
|
"ConfigendElement");
|
|
|
|
if (!($fp = fopen("dong.conf", 'r'))) {
|
|
die("Could not open config file for parsing!\n");
|
|
}
|
|
|
|
// loop through the file and parse baby!
|
|
while ($data = fread($fp, 4096)) {
|
|
if (!($data = utf8_encode($data))) {
|
|
echo 'ERROR'."\n";
|
|
}
|
|
|
|
if (!xml_parse($xml_parser, $data, feof($fp))) {
|
|
die(sprintf( "XML error: %s at line %d\n\n",
|
|
xml_error_string(xml_get_error_code($xml_parser)),
|
|
xml_get_current_line_number($xml_parser)));
|
|
}
|
|
}
|
|
|
|
xml_parser_free($xml_parser);
|
|
|
|
}
|
|
|
|
function ConfigstartElement($parser, $name, $attrs=''){
|
|
|
|
global $config_open_tags, $current_tag, $isfirst, $gotnamed, $isdefault,
|
|
$page, $isnamed, $config, $storeflag, $public, $publicflag;
|
|
|
|
$current_tag = $name;
|
|
|
|
switch($name){
|
|
case 'WEBLOG':
|
|
if ($attrs[PUBLIC]) {
|
|
$publicflag=1;
|
|
$public[TEMPNAME]=$attrs[NAME];
|
|
}
|
|
|
|
if (!$isfirst && !$gotnamed) {
|
|
$config[NAME]=$attrs[NAME];
|
|
$storeflag=1;
|
|
$isfirst=1;
|
|
}
|
|
|
|
if ($attrs[MAIN]=="true" && !$gotnamed) {
|
|
$config[NAME]=$attrs[NAME];
|
|
$storeflag=1;
|
|
}
|
|
|
|
if ($attrs[NAME] == $page) {
|
|
$isnamed=1;
|
|
$storeflag=1;
|
|
$config[NAME]=$attrs[NAME];
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
function ConfigendElement($parser, $name, $attrs=''){
|
|
|
|
global $confg_close_tags, $isdefault, $gotnamed, $isnamed, $storeflag, $publicflag;
|
|
|
|
switch($name){
|
|
case 'WEBLOG':
|
|
$isdefault = 0;
|
|
if($isnamed == 1) {
|
|
$isnamed = 0;
|
|
$gotnamed = 1;
|
|
}
|
|
$storeflag=0;
|
|
$publicflag=0;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
function ConfigcharacterData($parser, $data) {
|
|
|
|
global $current_tag, $storeflag, $config, $public, $publicflag;
|
|
|
|
$data=chop($data);
|
|
|
|
if ($storeflag && $data) {
|
|
$config[$current_tag]=$data;
|
|
}
|
|
|
|
if ($publicflag && ($current_tag == "URL") && $data) {
|
|
if (preg_match("/\?/",$data)) {
|
|
$switchchar="&";
|
|
}
|
|
else {
|
|
$switchchar="?";
|
|
}
|
|
|
|
$public[$public[TEMPNAME]]=$data.$switchchar."mode=rss";
|
|
}
|
|
}
|
|
|
|
?>
|