From 93a934051be4af5f61e28d98650808fcc701ae91 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 23 Mar 2009 09:19:13 +0000 Subject: Restructured the files and formats of the modules. --- utils/events.php | 151 ---------------------------------------------- utils/modules.php | 11 ++-- utils/modules/events.php | 153 +++++++++++++++++++++++++++++++++++++++++++++++ utils/modules/news.php | 119 ++++++++++++++++++++++++++++++++++++ utils/news.php | 119 ------------------------------------ utils/pages.php | 11 ++-- 6 files changed, 285 insertions(+), 279 deletions(-) delete mode 100644 utils/events.php create mode 100644 utils/modules/events.php create mode 100644 utils/modules/news.php delete mode 100644 utils/news.php diff --git a/utils/events.php b/utils/events.php deleted file mode 100644 index 2257e33..0000000 --- a/utils/events.php +++ /dev/null @@ -1,151 +0,0 @@ -\n"; - $str .= "
" . - htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; - $str .= "
" . date("D M jS Y", $this->time) . "
\n"; - $str .= "
" . - htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; - if($this->flyer) { - $str .= " \"flyer\"flyer . "\"/>\n"; - } - $str .= "\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($module) - { - switch($module) { - case "events_coming": - return $this->showcoming(-1); - break; - - case "events_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, "\n"); - - fwrite($fp, "\n"); - foreach($this->events as $event) { - fwrite($fp, " 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, " \n"); - } - fwrite($fp, "\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(); - } - -} - -?> \ No newline at end of file diff --git a/utils/modules.php b/utils/modules.php index 6983d6b..62e64d3 100644 --- a/utils/modules.php +++ b/utils/modules.php @@ -1,8 +1,10 @@ \ No newline at end of file +?> 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 @@ +\n"; + $str .= "
" . + htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; + $str .= "
" . date("D M jS Y", $this->time) . "
\n"; + $str .= "
" . + htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; + if($this->flyer) { + $str .= " \"flyer\"flyer . "\"/>\n"; + } + $str .= "\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, "\n"); + + fwrite($fp, "\n"); + foreach($this->events as $event) { + fwrite($fp, " 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, " \n"); + } + fwrite($fp, "\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 @@ +\n"; + $str .= "
" . + htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; + $str .= "
" . date("D M jS Y G:i", $this->time) . "
\n"; + $str .= "
" . + htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; + $str .= "\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, "\n"); + + fwrite($fp, "\n"); + foreach($this->news as $newsentry) { + fwrite($fp, " 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, " \n"); + } + fwrite($fp, "\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(); + } + +} + +?> diff --git a/utils/news.php b/utils/news.php deleted file mode 100644 index 0493804..0000000 --- a/utils/news.php +++ /dev/null @@ -1,119 +0,0 @@ -\n"; - $str .= "
" . - htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; - $str .= "
" . date("D M jS Y G:i", $this->time) . "
\n"; - $str .= "
" . - htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; - $str .= "\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, "\n"); - - fwrite($fp, "\n"); - foreach($this->news as $newsentry) { - fwrite($fp, " 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, " \n"); - } - fwrite($fp, "\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(); - } - -} - -?> diff --git a/utils/pages.php b/utils/pages.php index 60156b8..0ab52a8 100644 --- a/utils/pages.php +++ b/utils/pages.php @@ -23,12 +23,15 @@ class Page { $str = Markdown($this->content); - if(preg_match_all("/\[\[([a-zA-Z0-9_]+)\]\]/", $str, $res)) { + if(preg_match_all("/\[\[([\?,a-zA-Z0-9_]+)\]\]/", $str, $res)) { $modulecodes = array_unique($res[1]); foreach($modulecodes as $modulecode) { - if($modules[$modulecode]) { - $modulestr = $modules[$modulecode]->run($modulecode); + $m = explode("?", $modulecode); + $module = $m[0]; + $params = explode(",", $m[1]); + if($modules[$module]) { + $modulestr = $modules[$module]->run($params); } else { $modulestr = "

CMS ERROR: Could not find module: [[" . $modulecode . "]]

"; } @@ -98,4 +101,4 @@ class Pages { } } -?> \ No newline at end of file +?> -- cgit v1.2.3