Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

config_xml.php

Go to the documentation of this file.
00001 <?php
00002 /* $Id: config_xml.php,v 1.2 2003/10/03 15:28:41 mikko Exp $ */
00003 /*
00004  * ImaComm - a web based photo album software
00005  * Copyright (C) 2003, Mikko Kokkonen
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or (at
00010  * your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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                 // Albums
00057                 $albums =& $configure->createChild("albums");
00058 
00059                 // Option schemas
00060                 $schemes =& $configure->createChild("schemes");
00061 
00062                 // Default scheme
00063                 $default_scheme =& $schemes->createChild("scheme");
00064                 $default_scheme->attribute("id", "default");
00065                 // FIXME: Load options, generate options
00066                 
00067                 // Plugins
00068                 $plugins =& $configure->createChild("plugins");
00069 
00070                 // And save it out...
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                 // Resolve nesting...
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                                         // Get parent nesting...
00127                                         $cid = $id;     // Current 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                 // Go through all schemes...
00154                 for ($c = 0; $c < $schemes->numChildren(); $c++)
00155                 {
00156                         $scheme =& $schemes->xchildren[$c];
00157                         $id = $scheme->attribute("id");
00158 
00159                         // Go throught all options...
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                 // FIXME
00172         }
00173 }
00174 ?>

Generated on Sun Oct 19 11:08:00 2003 for ImaComm by doxygen1.3