From eec8fdf3fd36f6f8511bdb4bea0899f82bf3f6ab Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 23 Mar 2009 18:41:22 +0000 Subject: First attempt on a modularized plugin system, complete with admin, and parameters. --- utils/forms.php | 119 +++++++++++++++++++ utils/login.php | 5 +- utils/modules.php | 20 ++-- utils/modules/events.php | 296 +++++++++++++++++++++++++---------------------- utils/modules/news.php | 255 +++++++++++++++++++++++++--------------- 5 files changed, 452 insertions(+), 243 deletions(-) create mode 100644 utils/forms.php (limited to 'utils') diff --git a/utils/forms.php b/utils/forms.php new file mode 100644 index 0000000..4383d0a --- /dev/null +++ b/utils/forms.php @@ -0,0 +1,119 @@ + +
+ +
+ +
+
+
+
+ +
+
+
" value=""/>
+
+ $value) { +?> + " value=""/> + +
+
+
+
+ +
+
+
+ " value=""/> + / + " value=""/> + / + " value=""/> + - + " value=""/> + : + " value=""/> + : + " value=""/> +
+
+ +
+
+
+ +
+
+ diff --git a/utils/login.php b/utils/login.php index 950476e..88ba53a 100644 --- a/utils/login.php +++ b/utils/login.php @@ -13,6 +13,7 @@ function checklogin() global $loggedin; global $action; global $DATA_DIR; + global $ADMIN_TIMEOUT; $users = new Users($DATA_DIR . "/users.xml"); @@ -25,8 +26,8 @@ function checklogin() } else { _log("Wrong password", $userid); } - setcookie("UserID", $userid, time()+600); // expire in 10 minutes - setcookie("Password", $password, time()+600); // expire in 10 minutes + setcookie("UserID", $userid, time()+$ADMIN_TIMEOUT); + setcookie("Password", $password, time()+$ADMIN_TIMEOUT); return; } else { _log("Failed", $userid); diff --git a/utils/modules.php b/utils/modules.php index 62e64d3..4c34228 100644 --- a/utils/modules.php +++ b/utils/modules.php @@ -1,17 +1,15 @@ diff --git a/utils/modules/events.php b/utils/modules/events.php index 339102e..efba697 100644 --- a/utils/modules/events.php +++ b/utils/modules/events.php @@ -1,153 +1,177 @@ \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; - } + public $title; + public $time; + public $description; + public $flyer; + + public function show() + { + $str = "
\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; + private $file; + private $events = array(); + + // Admin config + public $admin_title = "Events"; + public $admin_submodules = array("New Event" => "new", + "Edit Event" => "edit", + "Delete Event" => "delete"); + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "new": + echo "New"; + break; + case "edit": + echo "Edit"; + break; + case "delete": + echo "Delete"; + break; + } + } + + 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; - } + 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 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); - } + 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); - } - - } + 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(); + } - public function Events($file) - { - $this->file = $file; - if(file_exists($file)) $this->read(); - } +} +function events_init() +{ + global $DATA_DIR; + return new Events($DATA_DIR . "/events.xml"); } ?> diff --git a/utils/modules/news.php b/utils/modules/news.php index 22de6a0..2505ffb 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -1,119 +1,186 @@ \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; - } + public $title; + public $time; + public $description; + public $category; + + public function show() + { + $str = "
\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") { + private $file; + private $news = array(); + + // Admin config + public $admin_title = "News"; + public $admin_submodules = array("New Newsentry" => "new", + "Edit Newsentry" => "edit", + "Delete Newsentry" => "delete"); + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "new": + switch($action) { + case "add": + $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); + $this->add($n); + $this->write(); + break; + + case "preview": + $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]); + echo "
\n"; + echo "
\n"; + echo $n->show(); + echo "
\n"; + echo "
\n"; + echo "

Looking ok?

"; + beginform("add"); + hidden($vars); + button("yes"); + endform(); + beginform("retry"); + hidden($vars); + button("no"); + endform(); + break; + + case "retry": + $title = $vars["title"]; + $time = totimestamp($vars, "time"); + $category = $vars["category"]; + $description = $vars["description"]; + default: + beginform("preview"); + lineedit("Title", "title", $title); + datetimeedit("Time", "time", $time); + combobox("Category", "category", $category, array("Main" => "main", "Site" => "site")); + textedit("Description", "description", $description); + button("Post news"); + endform(); + break; + } + break; + + case "edit": + echo "Edit"; + break; + case "delete": + echo "Delete"; + break; + } + } + + 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; - } + } + 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, " 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=\"" . + 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"); + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); - fclose($fp); - } + 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'), + 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); - } + $this->add($newsentry); + } - // Key sort - krsort($this->news); - } + // Key sort + krsort($this->news); + } - public function News($file) - { - $this->file = $file; - if(file_exists($file)) $this->read(); - } + public function News($file) + { + $this->file = $file; + if(file_exists($file)) $this->read(); + } } +function news_init() +{ + global $DATA_DIR; + return new News($DATA_DIR . "/news.xml"); +} ?> -- cgit v1.2.3