summaryrefslogtreecommitdiff
path: root/utils/modules
diff options
context:
space:
mode:
authordeva <deva>2009-03-23 09:19:13 +0000
committerdeva <deva>2009-03-23 09:19:13 +0000
commit93a934051be4af5f61e28d98650808fcc701ae91 (patch)
tree75e22f28c1fbb1fca50cb1d6955261b6b2667ed6 /utils/modules
parent9059fdbae945e9ba925254203f835ad02907cfa2 (diff)
Restructured the files and formats of the modules.
Diffstat (limited to 'utils/modules')
-rw-r--r--utils/modules/events.php153
-rw-r--r--utils/modules/news.php119
2 files changed, 272 insertions, 0 deletions
diff --git a/utils/modules/events.php b/utils/modules/events.php
new file mode 100644
index 0000000..339102e
--- /dev/null
+++ b/utils/modules/events.php
@@ -0,0 +1,153 @@
+<?php
+
+include_once($UTIL_DIR . "/convert.php");
+
+class Event {
+ public $title;
+ public $time;
+ public $description;
+ public $flyer;
+
+ public function show()
+ {
+ $str = "<div class=\"event\">\n";
+ $str .= " <div class=\"event_title\">" .
+ htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n";
+ $str .= " <div class=\"event_time\">" . date("D M jS Y", $this->time) . "</div>\n";
+ $str .= " <div class=\"event_description\">" .
+ htmlspecialchars_decode($this->description, ENT_QUOTES) . "</div>\n";
+ if($this->flyer) {
+ $str .= " <img class=\"event_flyer\" alt=\"flyer\" src=\"gfx/flyers/" . $this->flyer . "\"/>\n";
+ }
+ $str .= "</div>\n";
+ return $str;
+ }
+
+ public function Event($title, $time, $description, $flyer = "")
+ {
+ $this->title = $title;
+ $this->time = $time;
+ $this->description = $description;
+ $this->flyer = $flyer;
+ }
+}
+
+class Events {
+
+ private $file;
+ private $events = array();
+
+ public function run($params)
+ {
+ foreach($params as $param) {
+ switch($param) {
+ case "coming":
+ return $this->showcoming(-1);
+ break;
+
+ case "old":
+ default:
+ return $this->showold(-1);
+ break;
+ }
+ }
+ }
+
+ public function showcoming($number)
+ {
+ $str = "";
+
+ $foundany = false;
+
+ // Key sort
+ ksort($this->events);
+
+ // If number is -1 show all shows.
+ if($number == -1) $number = 100000;
+
+ foreach($this->events as $event) {
+ if($event->time >= time()) {
+ $foundany = true;
+ $str .= $event->show();
+ $number--;
+ }
+ if(!$number) return $str;
+ }
+
+ if($foundany == false) return "No shows available at the moment.";
+ return $str;
+ }
+
+ public function showold($number)
+ {
+ $str = "";
+
+ // Key sort
+ krsort($this->events);
+
+ // If number is -1 show all shows.
+ if($number == -1) $number = 100000;
+
+ foreach($this->events as $event) {
+ if($event->time <= time()) {
+ $str .= $event->show();
+ $number--;
+ }
+ if(!$number) return $str;
+ }
+ return $str;
+ }
+
+ public function add($event) {
+ $key = $event->time;
+ // array_push($this->events, $event);
+ $this->events[$key] = $event;
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<events>\n");
+ foreach($this->events as $event) {
+ fwrite($fp, " <event title=\"" .
+ htmlspecialchars($event->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " time=\"" . $event->time . "\"\n");
+ fwrite($fp, " description=\"" .
+ htmlspecialchars($event->description, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " flyer=\"" . $event->flyer . "\">\n");
+ fwrite($fp, " </event>\n");
+ }
+ fwrite($fp, "</events>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = FALSE;
+ $dom->load($this->file);
+ $params = $dom->getElementsByTagName('event');
+
+ foreach ($params as $param) {
+ $event = new Event($param->getAttribute('title'),
+ $param->getAttribute('time'),
+ $param->getAttribute('description'),
+ $param->getAttribute('flyer'));
+ $this->add($event);
+ }
+
+ }
+
+ public function Events($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+
+}
+
+?>
diff --git a/utils/modules/news.php b/utils/modules/news.php
new file mode 100644
index 0000000..22de6a0
--- /dev/null
+++ b/utils/modules/news.php
@@ -0,0 +1,119 @@
+<?php
+
+include_once($UTIL_DIR . "/convert.php");
+
+class NewsEntry {
+ public $title;
+ public $time;
+ public $description;
+ public $category;
+
+ public function show()
+ {
+ $str = "<div class=\"news_entry\">\n";
+ $str .= " <div class=\"news_title\">" .
+ htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n";
+ $str .= " <div class=\"news_time\">" . date("D M jS Y G:i", $this->time) . "</div>\n";
+ $str .= " <div class=\"news_description\">" .
+ htmlspecialchars_decode($this->description, ENT_QUOTES) . "</div>\n";
+ $str .= "</div>\n";
+ return $str;
+ }
+
+ public function NewsEntry($title, $time, $category, $description)
+ {
+ $this->title = $title;
+ $this->time = $time;
+ $this->category = $category;
+ $this->description = $description;
+ }
+}
+
+class News {
+
+ private $file;
+ private $news = array();
+
+ public function run($module)
+ {
+ global $show;
+
+ switch($module) {
+ case "news":
+ default:
+ if($show == "all") return $this->show(-1, "all");
+ else return $this->show(-1, "main");
+ break;
+ }
+ }
+
+ public function show($number, $category)
+ {
+ $str = "";
+
+ // If number is -1 show all shows.
+ if($number == -1) $number = 100000;
+
+ foreach($this->news as $newsentry) {
+ if($newsentry->category == $category || $category == "all") {
+ $str .= $newsentry->show();
+ $number--;
+ }
+ if(!$number) return $str;
+ }
+ return $str;
+ }
+
+ public function add($newsentry) {
+ $key = $newsentry->time;
+ $this->news[$key] = $newsentry;
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<news>\n");
+ foreach($this->news as $newsentry) {
+ fwrite($fp, " <newsentry title=\"" .
+ htmlspecialchars($newsentry->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " time=\"" . $newsentry->time . "\"\n");
+ fwrite($fp, " category=\"" . $newsentry->category . "\"\n");
+ fwrite($fp, " description=\"" .
+ htmlspecialchars($newsentry->description, ENT_QUOTES, "UTF-8") . "\">\n");
+ fwrite($fp, " </newsentry>\n");
+ }
+ fwrite($fp, "</news>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = FALSE;
+ $dom->load($this->file);
+ $params = $dom->getElementsByTagName('newsentry');
+
+ foreach ($params as $param) {
+ $newsentry = new NewsEntry($param->getAttribute('title'),
+ $param->getAttribute('time'),
+ $param->getAttribute('category'),
+ $param->getAttribute('description'));
+ $this->add($newsentry);
+ }
+
+ // Key sort
+ krsort($this->news);
+ }
+
+ public function News($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+
+}
+
+?>