summaryrefslogtreecommitdiff
path: root/utils/modules/news.php
diff options
context:
space:
mode:
authordeva <deva>2009-03-23 18:41:22 +0000
committerdeva <deva>2009-03-23 18:41:22 +0000
commiteec8fdf3fd36f6f8511bdb4bea0899f82bf3f6ab (patch)
treeeefac33e9ef9980c81fd6200a437f39c12e63ba8 /utils/modules/news.php
parent93a934051be4af5f61e28d98650808fcc701ae91 (diff)
First attempt on a modularized plugin system, complete with admin, and parameters.
Diffstat (limited to 'utils/modules/news.php')
-rw-r--r--utils/modules/news.php255
1 files changed, 161 insertions, 94 deletions
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 @@
<?php
include_once($UTIL_DIR . "/convert.php");
+include_once($UTIL_DIR . "/forms.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;
- }
+ 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") {
+ 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 "<div class=\"preview\">\n";
+ echo "<div class=\"content\">\n";
+ echo $n->show();
+ echo "</div>\n";
+ echo "</div>\n";
+ echo "<p>Looking ok?</p>";
+ 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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
-
- fwrite($fp, "<news>\n");
- foreach($this->news as $newsentry) {
- fwrite($fp, " <newsentry title=\"" .
+ 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=\"" .
+ 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");
+ fwrite($fp, " </newsentry>\n");
+ }
+ fwrite($fp, "</news>\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");
+}
?>