diff options
| author | deva <deva> | 2009-04-23 07:41:28 +0000 | 
|---|---|---|
| committer | deva <deva> | 2009-04-23 07:41:28 +0000 | 
| commit | 3f1dda1e19e1f77e908df1d49d028d0932d0f1a1 (patch) | |
| tree | d44586018a0594aa53cfbe172d7a576bbe5f593c /utils/modules/config.php | |
| parent | 9fc8170f4492c3e5900156610061e59c84aa9d83 (diff) | |
A completely new forms class, to replace the old function based method. Also some work on a new config module, evenmtuelly to replace the old hardcoded values.
Diffstat (limited to 'utils/modules/config.php')
| -rw-r--r-- | utils/modules/config.php | 144 | 
1 files changed, 144 insertions, 0 deletions
diff --git a/utils/modules/config.php b/utils/modules/config.php new file mode 100644 index 0000000..a7068ef --- /dev/null +++ b/utils/modules/config.php @@ -0,0 +1,144 @@ +<?php +/* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +include_once($UTIL_DIR . "/convert.php"); + +class Config { + +  private $file; +  private $configs = array(); + +  // Admin config +  public $admin_title = "Site Config"; +  public $admin_submodules = array("Title" => "title", +				   "Menu" => "menu"); + +  public function admin_title($action, $vars) +  { +    switch($action) { +    case "update": +      $this->setValue("title", $vars["title"]); +			echo "The title has now been changed to \"". $this->value("title") . "\""; +			$this->write(); +			break; +			 +    default: +      $form = new Form("update"); +      $form->addWidget(new LineEdit("Site title:", "title", $this->value("title", "Title not yet set"))); +      $form->addWidget(new Button("Update")); +      $form->render(); +      break; +    } +  } + +  public function admin_menu($action, $vars) +  { +    switch($action) { +    case "update": +      $this->setValue("menu", array("news" => "News", +				    "shop" => "Shop", +				    "downloads" => "Downloads", +				    "biography" => "Biography", +				    "live" => "Concerts", +				    "discography" => "Discography", +				    "guestbook" => "Guestbook", +				    "members" => "Members", +				    "gallery" => "Gallery", +				    "contact" => "Contact")); +      $this->write(); +      break; +			 +    default: +      $form = new Form("update"); +      echo "Coming soon!"; +      $form->addWidget(new Button("Update")); +      $form->render(); +      break; +    } +  } + +  public function admin($sub, $action, $vars) +  { +    switch($sub) { +    case "title": +      $this->admin_title($action, $vars); +      break; +    case "menu": +      $this->admin_menu($action, $vars); +      break; +    } +  } + +  public function write() +  { +    $fp = fopen($this->file, "w"); +    fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + +    fwrite($fp, "<configs>\n"); +    foreach($this->configs as $name => $value) { +      fwrite($fp, "  <config name=\"".$name."\"\n"); +      fwrite($fp, "          value=\"". +	     htmlspecialchars(serialize($value), ENT_QUOTES, "UTF-8")."\"/>\n"); +    } +    fwrite($fp, "</configs>\n"); + +    fclose($fp); +  } + +  private function read() +  { +    $dom = new DomDocument; +    $dom->preserveWhiteSpace = TRUE; +    $dom->load($this->file); +    $configElems = $dom->getElementsByTagName('config'); + +    foreach ($configElems as $config) { +      $this->setValue($config->getAttribute('name'), +		      unserialize(htmlspecialchars_decode($config->getAttribute('value'), ENT_QUOTES))); +    } +  } + +  public function value($name, $default = "") +  { +    if(isset($this->configs[$name])) return $this->configs[$name]; + +		////////// +		////////// TEMPORARY VAR EXPANSION - Remove when the real values are done. +		////////// +		global $TITLE, $PRELOAD, $DEFAULT_PAGE, $MENU; +		switch($name) { +		case 'title': +			return $TITLE; +		case 'preload': +			return $PRELOAD; +		case 'default': +			return $DEFAULT_PAGE; +		case 'menu': +			return $MENU; +		default: +			return $default; +		} + +    return $default; +  } + +  public function setValue($name, $value) +  { +    $this->configs[$name] = $value; +  } + +  public function Config($file) +  { +    $this->file =  $file; +    if(file_exists($file)) $this->read(); +  } + +} + +function config_init() +{ +  global $DATA_DIR; +  return new Config($DATA_DIR . "/config.xml"); +} + +?>  | 
