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/events.php | 53 ++++++++++++++++------ utils/modules/news.php | 49 +++++++++++++++----- utils/modules/rss.php | 114 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 24 deletions(-) create mode 100644 utils/modules/rss.php (limited to 'utils/modules') diff --git a/utils/modules/events.php b/utils/modules/events.php index be11dcf..3bccce6 100644 --- a/utils/modules/events.php +++ b/utils/modules/events.php @@ -21,23 +21,22 @@ class Event { fwrite($fp, "\n"); } - public function show() + public function show($eventpage) { - global $ICONS_DIR, $EVENT_PAGE; - $icons = new Icons($ICONS_DIR."/"); - $icon = $icons->icons[$this->flyer]; - $content = Markdown(htmlspecialchars_decode($this->description)); $str = "
\n"; $str .= "
" . date("D M jS Y", $this->time) . "
\n"; $str .= " \n"; $str .= "
" . $content . "
\n"; /* if($this->flyer) { + global $ICONS_DIR; + $icons = new Icons($ICONS_DIR."/"); + $icon = $icons->icons[$this->flyer]; $str .= " \"flyer\"prefix.$icon->file."\"/>\n"; } */ @@ -58,12 +57,32 @@ class Events { private $file; private $events = array(); + public $eventpage; // Admin config public $admin_title = "Events"; public $admin_submodules = array("Add Event" => "add", "Edit Event" => "edit", - "Delete Event" => "delete"); + "Delete Event" => "delete", + "Config" => "config"); + + public function admin_config($action, $vars) + { + switch($action) { + case "update": + $this->eventpage = $vars["eventpage"]; + // echo "The title has now been changed to \"". $this->value("title") . "\""; + $this->write(); + break; + + default: + $form = new Form("update"); + $form->addWidget(new LineEdit("Event page:", "eventpage", $this->eventpage)); + $form->addWidget(new Button("Update")); + $form->render(); + break; + } + } public function admin_add($action, $vars) { @@ -83,7 +102,7 @@ class Events { $vars["description"], $vars["icon"]); echo "
\n"; echo "
\n"; - echo $event->show(); + echo $event->show($this->eventpage); echo "
\n"; echo "
\n"; echo "

Looking ok?

"; @@ -134,7 +153,7 @@ class Events { $vars["description"], $vars["icon"]); echo "
\n"; echo "
\n"; - echo $event->show(); + echo $event->show($this->eventpage); echo "
\n"; echo "
\n"; echo "

Looking ok?

"; @@ -227,6 +246,9 @@ class Events { public function admin($sub, $action, $vars) { switch($sub) { + case "config": + $this->admin_config($action, $vars); + break; case "add": $this->admin_add($action, $vars); break; @@ -269,7 +291,7 @@ class Events { if($single == true) { if($eventid && $this->events[$eventid]) { - $str .= $this->events[$eventid]->show(); + $str .= $this->events[$eventid]->show($this->eventpage); } else { $str .= "No such show!\n"; } @@ -308,7 +330,7 @@ class Events { foreach($this->events as $event) { $foundany = true; - $str .= $event->show(); + $str .= $event->show($this->eventpage); $number--; if(!$number) return $str; } @@ -332,7 +354,7 @@ class Events { foreach($this->events as $event) { if($event->time >= time()) { $foundany = true; - $str .= $event->show(); + $str .= $event->show($this->eventpage); $number--; } if(!$number) return $str; @@ -354,7 +376,7 @@ class Events { foreach($this->events as $event) { if($event->time <= time()) { - $str .= $event->show(); + $str .= $event->show($this->eventpage); $number--; } if(!$number) return $str; @@ -373,7 +395,7 @@ class Events { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); - fwrite($fp, "\n"); + fwrite($fp, "eventpage)."\">\n"); foreach($this->events as $event) { $event->write($fp); } @@ -389,6 +411,9 @@ class Events { $dom->load($this->file); $params = $dom->getElementsByTagName('event'); + $events = $dom->documentElement; + $this->eventpage = $events->getAttribute('eventpage'); + foreach ($params as $param) { $event = new Event($param->getAttribute('title'), $param->getAttribute('time'), diff --git a/utils/modules/news.php b/utils/modules/news.php index 032c342..b59b7fd 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -17,9 +17,9 @@ class NewsEntry { public $userid; public $icon; - public function show() + public function show($newspage) { - global $users, $DATA_DIR, $ICONS_DIR, $NEWS_PAGE; + global $users, $DATA_DIR, $ICONS_DIR; if(!isset($users)) $users = new Users($DATA_DIR . "/users.xml"); @@ -35,7 +35,7 @@ class NewsEntry { $str .= "
" . date("D M jS Y G:i", $this->time) . "
\n"; $str .= " \n"; $str .= "
By: " . $userid . "
\n"; @@ -80,13 +80,32 @@ class News { private $file; private $news = array(); + public $newspage; // Admin config public $admin_title = "News"; public $admin_submodules = array("New entry" => "new", "Edit entry" => "edit", - "Delete entry" => "delete"); + "Delete entry" => "delete", + "Config" => "config"); + public function admin_config($action, $vars) + { + switch($action) { + case "update": + $this->newspage = $vars["newspage"]; + $this->write(); + break; + + default: + $form = new Form("update"); + $form->addWidget(new LineEdit("News page (single):", "newspage", $this->newspage)); + $form->addWidget(new Button("Update")); + $form->render(); + break; + } + } + public function admin_add($action, $vars) { global $UID, $ICONS_DIR; @@ -109,7 +128,7 @@ class News { $UID, $vars["icon"]); echo "
\n"; echo "
\n"; - echo $n->show(); + echo $n->show($this->newspage); echo "
\n"; echo "
\n"; echo "

Looking ok?

"; @@ -166,7 +185,7 @@ class News { $vars["category"], $vars["description"], $UID, $vars["icon"]); echo "
\n"; echo "
\n"; - echo $n->show(); + echo $n->show($this->newspage); echo "
\n"; echo "
\n"; echo "

Looking ok?

"; @@ -265,6 +284,10 @@ class News { public function admin($sub, $action, $vars) { switch($sub) { + case "config": + $this->admin_config($action, $vars); + break; + case "new": $this->admin_add($action, $vars); break; @@ -308,7 +331,7 @@ class News { if($single) { if($newsid && $this->news[$newsid]) { // $str .= $this->show($number, $module); - $str .= $this->news[$newsid]->show(); + $str .= $this->news[$newsid]->show($this->newspage); } else { $str .= "No such news entry!\n"; } @@ -328,7 +351,7 @@ class News { foreach($this->news as $newsentry) { if($newsentry->category == $category || $category == "all") { - $str .= $newsentry->show(); + $str .= $newsentry->show($this->newspage); $number--; } if(!$number) return $str; @@ -343,10 +366,12 @@ class News { public function write() { + global $DATA_DIR; + $fp = fopen($this->file, "w"); fwrite($fp, "\n"); - fwrite($fp, "\n"); + fwrite($fp, "newspage)."\">\n"); foreach($this->news as $newsentry) { $newsentry->write($fp); } @@ -354,7 +379,7 @@ class News { fclose($fp); - $rss = new RSS($this->file, "rss.xml"); + $rss = new RSS($this->file, $DATA_DIR."/rss.xml"); $rss->write(); } @@ -363,6 +388,10 @@ class News { $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); + + $n = $dom->documentElement; + $this->newspage = $n->getAttribute('newspage'); + $params = $dom->getElementsByTagName('newsentry'); foreach ($params as $param) { 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