00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00033 class Configuration_XML
00034 {
00035 function Configuration_XML()
00036 {
00037 $this->prefix = realpath(dirname(__FILE__)."/../");
00038 }
00039
00040 function createFile($vars)
00041 {
00042 $this->file = $this->prefix."/conf/configure.xml";
00043
00044 $minixmlpath = $vars['minixml_path'];
00045 if (!file_exists("$minixmlpath/minixml.inc.php"))
00046 {
00047 $this->file = null;
00048 return null;
00049 }
00050 require_once "$minixmlpath/minixml.inc.php";
00051 $doc = new MiniXMLDoc();
00052 $root =& $doc->getRoot();
00053 $configure =& $root->createChild("configure");
00054 $configure->attribute("version", "1.0");
00055
00056
00057 $albums =& $configure->createChild("albums");
00058
00059
00060 $schemes =& $configure->createChild("schemes");
00061
00062
00063 $default_scheme =& $schemes->createChild("scheme");
00064 $default_scheme->attribute("id", "default");
00065
00066
00067
00068 $plugins =& $configure->createChild("plugins");
00069
00070
00071 $fp = @fopen($this->file, "w");
00072 if ($fp)
00073 {
00074 fputs($fp, $doc->toString());
00075 fclose($fp);
00076 }
00077 return $this->file;
00078 }
00079
00080 function loadData($file)
00081 {
00082 global $settings;
00083
00084 if (is_null($this->minixml))
00085 {
00086 $this->minixml = $settings->attribute("minixml_path");
00087 }
00088 require_once ($this->minixml."/minixml.inc.php");
00089
00090 $doc = new MiniXMLDoc();
00091 $doc->fromFile($file);
00092 $root =& $doc->getRoot();
00093 $configure =& $root->getElement("configure");
00094
00095 $albums =& $configure->getElement("albums");
00096 $albxml = new MiniXMLDoc();
00097 $albroot =& $albxml->getRoot();
00098 $albumsdata["-root-"] =& $albroot->createChild("-root-");
00099
00100 for ($a = 0; $a < $albums->numChildren(); $a++)
00101 {
00102 $album =& $albums->xchildren[$a];
00103 $id = trim($album->attribute("id"));
00104 $nest = trim($album->attribute("nest"));
00105 $source = trim($album->text());
00106
00107 $this->albums[$id] = array(
00108 "source" => $source,
00109 "scheme" => $scheme,
00110 "nest" => $nest);
00111 }
00112
00113 if (is_array($this->albums))
00114 {
00115 $keys = array_keys($this->albums);
00116 for ($a = 0; $a < count($this->albums); $a++)
00117 {
00118 $id = $keys[$a];
00119 $nest = $this->albums[$keys[$a]]['nest'];
00120 if (get_class($albumsdata[$nest]) && !get_class($albumsdata[$id]))
00121 {
00122 $albumsdata[$id] =& $albumsdata[$nest]->createChild($id);
00123 }
00124 elseif (!get_class($albumsdata[$nest]))
00125 {
00126
00127 $cid = $id;
00128 $create = null;
00129 while (!get_class($albumsdata[$cid]))
00130 {
00131 if (!in_array($cid, $keys))
00132 {
00133 break;
00134 }
00135 $create[] = $cid;
00136 $cid = $this->albums[$cid]['nest'];
00137 }
00138 $create = array_reverse($create);
00139 foreach ($create as $alb)
00140 {
00141 $parent = $this->albums[$alb]['nest'];
00142 if (get_class($albumsdata[$parent]))
00143 {
00144 $albumsdata[$alb] =& $albumsdata[$parent]->createChild($alb);
00145 }
00146 }
00147 }
00148 }
00149 }
00150 $this->nesting = $albxml->toArray();
00151 unset($albxml);
00152 $schemes =& $configure->getElement("schemes");
00153
00154 for ($c = 0; $c < $schemes->numChildren(); $c++)
00155 {
00156 $scheme =& $schemes->xchildren[$c];
00157 $id = $scheme->attribute("id");
00158
00159
00160 for ($o = 0; $o < $scheme->numChildren(); $o++)
00161 {
00162 $option =& $scheme->xchildren[$o];
00163 $name = trim($option->attribute("name"));
00164 $type = trim($option->attribute("type"));
00165 $value = trim($option->text());
00166 $this->schemes[$id][$name] = parseValue($value, $type);
00167 }
00168 }
00169
00170 $plugins =& $configure->getElement("plugins");
00171
00172 }
00173 }
00174 ?>