summaryrefslogtreecommitdiff
path: root/utils/modules/rss.php
diff options
context:
space:
mode:
authordeva <deva>2010-03-02 15:00:35 +0000
committerdeva <deva>2010-03-02 15:00:35 +0000
commitc34ccc130e2a507c266ee54a163cdf3a5886d63d (patch)
tree42f170422c068bf6c901d2770be938e54fb8b608 /utils/modules/rss.php
parente10832ad013881909cf1a051bbecae732b9e4cad (diff)
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.
Diffstat (limited to 'utils/modules/rss.php')
-rw-r--r--utils/modules/rss.php114
1 files changed, 114 insertions, 0 deletions
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 @@
+<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+global $UTIL_DIR;
+
+include_once($UTIL_DIR . "/convert.php");
+
+class RSSConfig {
+ private $file;
+ private $configs = array();
+
+ public $title;
+ public $url;
+ public $description;
+ public $editoremail;
+ public $webmasteremail;
+ public $target;
+
+ // Admin config
+ public $admin_title = "RSS Config";
+ public $admin_submodules = array("Config" => "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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<rss title=\"".xmlenc($this->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, "</rss>\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