From c34ccc130e2a507c266ee54a163cdf3a5886d63d Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 2 Mar 2010 15:00:35 +0000 Subject: Made a lot of changes, making it possible to entirely remove th config.php file from the project. These changes includes the creation of a new rss config module, the adding of some config vars in both the events and news modules. --- utils/modules/rss.php | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 utils/modules/rss.php (limited to 'utils/modules/rss.php') diff --git a/utils/modules/rss.php b/utils/modules/rss.php new file mode 100644 index 0000000..02501b3 --- /dev/null +++ b/utils/modules/rss.php @@ -0,0 +1,114 @@ + "config"); + + public function admin_config($action, $vars) + { + switch($action) { + case "update": + $this->title = $vars["title"]; + $this->url = $vars["url"]; + $this->description = $vars["description"]; + $this->editoremail = $vars["editoremail"]; + $this->webmasteremail = $vars["webmasteremail"]; + $this->target = $vars["target"]; + $this->write(); + break; + + default: + $form = new Form("update"); + $form->addWidget(new LineEdit("Title:", "title", $this->title)); + $form->addWidget(new LineEdit("Base URL:", "url", $this->url)); + $form->addWidget(new LineEdit("Description:", "description", $this->description)); + $form->addWidget(new LineEdit("Editor Email:", "editoremail", $this->editoremail)); + $form->addWidget(new LineEdit("Webmaster Email:", "webmasteremail", $this->webmasteremail)); + $form->addWidget(new LineEdit("Target file:", "target", $this->target)); + $form->addWidget(new Button("Update")); + $form->render(); + break; + } + } + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "config": + $this->admin_config($action, $vars); + break; + } + } + + public function write() + { + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "title)."\"\n"); + fwrite($fp, " url=\"".xmlenc($this->url)."\"\n"); + fwrite($fp, " description=\"".xmlenc($this->description)."\"\n"); + fwrite($fp, " editoremail=\"".xmlenc($this->editoremail)."\"\n"); + fwrite($fp, " webmasteremail=\"".xmlenc($this->webmasteremail)."\"\n"); + fwrite($fp, " target=\"".xmlenc($this->target)."\">\n"); + fwrite($fp, "\n"); + + fclose($fp); + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = TRUE; + $dom->load($this->file); + + $rss = $dom->documentElement; + $this->title = $rss->getAttribute('title'); + $this->url = $rss->getAttribute('url'); + $this->description = $rss->getAttribute('description'); + $this->editoremail = $rss->getAttribute('editoremail'); + $this->webmasteremail = $rss->getAttribute('webmasteremail'); + $this->target = $rss->getAttribute('target'); + } + + public function value($name, $default = "") + { + if(isset($this->configs[$name])) return $this->configs[$name]; + return $default; + } + + public function setValue($name, $value) + { + $this->configs[$name] = $value; + } + + public function RSSConfig($file) + { + $this->file = $file; + if(file_exists($file)) $this->read(); + } + +} + +function rss_init() +{ + global $DATA_DIR; + return new RSSConfig($DATA_DIR . "/rss.xml"); +} + +?> \ No newline at end of file -- cgit v1.2.3