summaryrefslogtreecommitdiff
path: root/utils/modules
diff options
context:
space:
mode:
authordeva <deva>2009-04-23 07:41:28 +0000
committerdeva <deva>2009-04-23 07:41:28 +0000
commit3f1dda1e19e1f77e908df1d49d028d0932d0f1a1 (patch)
treed44586018a0594aa53cfbe172d7a576bbe5f593c /utils/modules
parent9fc8170f4492c3e5900156610061e59c84aa9d83 (diff)
A completely new forms class, to replace the old function based method. Also some work on a new config module, evenmtuelly to replace the old hardcoded values.
Diffstat (limited to 'utils/modules')
-rw-r--r--utils/modules/config.php144
-rw-r--r--utils/modules/events.php49
-rw-r--r--utils/modules/gallery.php36
-rw-r--r--utils/modules/news.php176
-rw-r--r--utils/modules/pages.php37
5 files changed, 323 insertions, 119 deletions
diff --git a/utils/modules/config.php b/utils/modules/config.php
new file mode 100644
index 0000000..a7068ef
--- /dev/null
+++ b/utils/modules/config.php
@@ -0,0 +1,144 @@
+<?php
+/* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+include_once($UTIL_DIR . "/convert.php");
+
+class Config {
+
+ private $file;
+ private $configs = array();
+
+ // Admin config
+ public $admin_title = "Site Config";
+ public $admin_submodules = array("Title" => "title",
+ "Menu" => "menu");
+
+ public function admin_title($action, $vars)
+ {
+ switch($action) {
+ case "update":
+ $this->setValue("title", $vars["title"]);
+ echo "The title has now been changed to \"". $this->value("title") . "\"";
+ $this->write();
+ break;
+
+ default:
+ $form = new Form("update");
+ $form->addWidget(new LineEdit("Site title:", "title", $this->value("title", "Title not yet set")));
+ $form->addWidget(new Button("Update"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin_menu($action, $vars)
+ {
+ switch($action) {
+ case "update":
+ $this->setValue("menu", array("news" => "News",
+ "shop" => "Shop",
+ "downloads" => "Downloads",
+ "biography" => "Biography",
+ "live" => "Concerts",
+ "discography" => "Discography",
+ "guestbook" => "Guestbook",
+ "members" => "Members",
+ "gallery" => "Gallery",
+ "contact" => "Contact"));
+ $this->write();
+ break;
+
+ default:
+ $form = new Form("update");
+ echo "Coming soon!";
+ $form->addWidget(new Button("Update"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function admin($sub, $action, $vars)
+ {
+ switch($sub) {
+ case "title":
+ $this->admin_title($action, $vars);
+ break;
+ case "menu":
+ $this->admin_menu($action, $vars);
+ break;
+ }
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<configs>\n");
+ foreach($this->configs as $name => $value) {
+ fwrite($fp, " <config name=\"".$name."\"\n");
+ fwrite($fp, " value=\"".
+ htmlspecialchars(serialize($value), ENT_QUOTES, "UTF-8")."\"/>\n");
+ }
+ fwrite($fp, "</configs>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = TRUE;
+ $dom->load($this->file);
+ $configElems = $dom->getElementsByTagName('config');
+
+ foreach ($configElems as $config) {
+ $this->setValue($config->getAttribute('name'),
+ unserialize(htmlspecialchars_decode($config->getAttribute('value'), ENT_QUOTES)));
+ }
+ }
+
+ public function value($name, $default = "")
+ {
+ if(isset($this->configs[$name])) return $this->configs[$name];
+
+ //////////
+ ////////// TEMPORARY VAR EXPANSION - Remove when the real values are done.
+ //////////
+ global $TITLE, $PRELOAD, $DEFAULT_PAGE, $MENU;
+ switch($name) {
+ case 'title':
+ return $TITLE;
+ case 'preload':
+ return $PRELOAD;
+ case 'default':
+ return $DEFAULT_PAGE;
+ case 'menu':
+ return $MENU;
+ default:
+ return $default;
+ }
+
+ return $default;
+ }
+
+ public function setValue($name, $value)
+ {
+ $this->configs[$name] = $value;
+ }
+
+ public function Config($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+
+}
+
+function config_init()
+{
+ global $DATA_DIR;
+ return new Config($DATA_DIR . "/config.xml");
+}
+
+?>
diff --git a/utils/modules/events.php b/utils/modules/events.php
index efba697..bdbe43e 100644
--- a/utils/modules/events.php
+++ b/utils/modules/events.php
@@ -39,8 +39,8 @@ class Events {
// Admin config
public $admin_title = "Events";
public $admin_submodules = array("New Event" => "new",
- "Edit Event" => "edit",
- "Delete Event" => "delete");
+ "Edit Event" => "edit",
+ "Delete Event" => "delete");
public function admin($sub, $action, $vars)
{
@@ -62,17 +62,44 @@ class Events {
foreach($params as $param) {
switch($param) {
case "coming":
- return $this->showcoming(-1);
- break;
+ return $this->showcoming(-1);
+ break;
+
+ case "all":
+ return $this->showall(-1);
+ break;
case "old":
default:
- return $this->showold(-1);
- break;
+ return $this->showold(-1);
+ break;
}
}
}
+ public function showall($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) {
+ $foundany = true;
+ $str .= $event->show();
+ $number--;
+ if(!$number) return $str;
+ }
+
+ if($foundany == false) return "No shows available at the moment.";
+ return $str;
+ }
+
public function showcoming($number)
{
$str = "";
@@ -87,9 +114,9 @@ class Events {
foreach($this->events as $event) {
if($event->time >= time()) {
- $foundany = true;
- $str .= $event->show();
- $number--;
+ $foundany = true;
+ $str .= $event->show();
+ $number--;
}
if(!$number) return $str;
}
@@ -110,8 +137,8 @@ class Events {
foreach($this->events as $event) {
if($event->time <= time()) {
- $str .= $event->show();
- $number--;
+ $str .= $event->show();
+ $number--;
}
if(!$number) return $str;
}
diff --git a/utils/modules/gallery.php b/utils/modules/gallery.php
index 4820a04..c6d2f86 100644
--- a/utils/modules/gallery.php
+++ b/utils/modules/gallery.php
@@ -83,8 +83,8 @@ class Album {
htmlspecialchars($this->copyright, ENT_QUOTES, "UTF-8") . "\"\n");
fwrite($fp, " icon=\"" .
htmlspecialchars($this->icon, ENT_QUOTES, "UTF-8") . "\"\n");
- fwrite($fp, " enabled=\"" .
- htmlspecialchars($this->enabled, ENT_QUOTES, "UTF-8") . "\">\n");
+ if($this->enabled) fwrite($fp, " enabled=\"true\">\n");
+ else fwrite($fp, " enabled=\"false\">\n");
foreach($this->photos as $photo) {
$photo->write($fp);
}
@@ -124,7 +124,7 @@ class Album {
$this->title = $title;
$this->copyright = $copyright;
$this->icon = $icon;
- $this->enabled = $enabled;
+ $this->enabled = $enabled == 'on';
}
}
@@ -178,9 +178,11 @@ class Gallery {
// Admin config
public $admin_title = "Gallery";
- public $admin_submodules = array("New gallery" => "newgallery");
+ public $admin_submodules = array("New album" => "new",
+ "Edit album" => "edit",
+ "Delete album" => "delete");
- public function admin_newgallery($action, $vars)
+ public function admin_new($action, $vars)
{
global $ALBUMS_DIR;
switch($action) {
@@ -194,13 +196,13 @@ class Gallery {
case "select":
default:
- beginform("create", true);
- lineedit("Album title:", "title");
- lineedit("Album copyright:", "copyright");
- lineedit("Album enabled:", "enabled", "true");
- fileupload("Select image archive:", "images", "application/zip");
- button("Create");
- endform();
+ $form = new Form("create");
+ $form->addWidget(new LineEdit("Album title:", "title"));
+ $form->addWidget(new LineEdit("Album copyright:", "copyright"));
+ $form->addWidget(new CheckBox("Album enabled:", "enabled"));
+ $form->addWidget(new FileUpload("Select image archive:", "images", "application/zip"));
+ $form->addWidget(new Button("Create"));
+ $form->render();
break;
}
}
@@ -208,8 +210,14 @@ class Gallery {
public function admin($sub, $action, $vars)
{
switch($sub) {
- case "newgallery":
- $this->admin_newgallery($action, $vars);
+ case "new":
+ $this->admin_new($action, $vars);
+ break;
+ case "edit":
+ $this->admin_new($action, $vars);
+ break;
+ case "delete":
+ $this->admin_new($action, $vars);
break;
}
}
diff --git a/utils/modules/news.php b/utils/modules/news.php
index d26f8cb..52b8112 100644
--- a/utils/modules/news.php
+++ b/utils/modules/news.php
@@ -2,36 +2,55 @@
include_once($UTIL_DIR . "/convert.php");
include_once($UTIL_DIR . "/forms.php");
+include_once($UTIL_DIR . "/user.php");
class NewsEntry {
public $title;
public $time;
public $description;
public $category;
+ public $userid;
public function show()
{
+ global $users, $DATA_DIR;
+ if(!isset($users)) $users = new Users($DATA_DIR . "/users.xml");
+
$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\">" .
+ $str .= " <div class=\"news_user\">By: " . $users->findUser($this->userid)->userid . "</div>\n";
+ $str .= " <div class=\"news_description\">" .
htmlspecialchars_decode($this->description, ENT_QUOTES) . "</div>\n";
$str .= "</div>\n";
return $str;
}
+ public function write($fp)
+ {
+ fwrite($fp, " <newsentry title=\"" .
+ htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " time=\"" . $this->time . "\"\n");
+ fwrite($fp, " category=\"" . $this->category . "\"\n");
+ fwrite($fp, " userid=\"" . $this->userid . "\"\n");
+ fwrite($fp, " description=\"" .
+ htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\">\n");
+ fwrite($fp, " </newsentry>\n");
+ }
+
public function __toString()
{
return $this->title;
}
- public function NewsEntry($title, $time, $category, $description)
+ public function NewsEntry($title, $time, $category, $description, $userid)
{
$this->title = $title;
$this->time = $time;
$this->category = $category;
$this->description = $description;
+ $this->userid = $userid;
}
}
@@ -45,66 +64,73 @@ class News {
public $admin_submodules = array("New Newsentry" => "new",
"Edit Newsentry" => "edit",
"Delete Newsentry" => "delete");
-
public function admin_add($action, $vars)
{
+ global $UID;
+
switch($action) {
case "add":
- $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]);
+ $n = new NewsEntry($vars["title"], DateTimeEdit::toTimestamp($vars, "time"),
+ $vars["category"], $vars["description"], $UID);
+ echo "\"" .$n->title . "\" has now been added.";
$this->add($n);
$this->write();
break;
case "preview":
- $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]);
+ $n = new NewsEntry($vars["title"], DateTimeEdit::toTimestamp($vars, "time"),
+ $vars["category"], $vars["description"], $UID);
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();
+ $form = new Form("add");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("yes"));
+ $form->render();
+
+ $form = new Form("retry");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("no"));
+ $form->render();
break;
case "retry":
$title = $vars["title"];
- $time = totimestamp($vars, "time");
+ $time = DateTimeEdit::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);
- imagecombobox("Icon", "icon", $icon,
- array("Logo1" => "http://www.executionroom.com/gfx/logos/die_logo_black_thumb.png",
- "Logo2" => "http://www.executionroom.com/gfx/logos/die_logo_bloody_thumb.png",
- "Logo3" => "http://www.executionroom.com/gfx/logos/die_logo_red_thumb_.png",
- "Logo4" => "http://www.executionroom.com/gfx/logos/die_logo_white_thumb.png",
- "Logo5" => "http://www.executionroom.com/gfx/die_group_2008_thumb.jpg",
- "Logo6" => "http://www.executionroom.com/gfx/die_group_thumb.jpg")
- );
- button("Post news");
- endform();
+ $form = new Form("preview");
+ $form->addWidget(new LineEdit("Title", "title", $title));
+ $form->addWidget(new DateTimeEdit("Time", "time", $time));
+ $form->addWidget(new ComboBox("Category", "category", $category, array("Main" => "main", "Site" => "site")));
+ $form->addWidget(new TextEdit("Description", "description", $description));
+ $form->addWidget(new ImageComboBox("Icon", "icon", $icon,
+ array("Logo1" => "http://www.executionroom.com/gfx/logos/die_logo_black_thumb.png",
+ "Logo2" => "http://www.executionroom.com/gfx/logos/die_logo_bloody_thumb.png",
+ "Logo3" => "http://www.executionroom.com/gfx/logos/die_logo_red_thumb_.png",
+ "Logo4" => "http://www.executionroom.com/gfx/logos/die_logo_white_thumb.png",
+ "Logo5" => "http://www.executionroom.com/gfx/die_group_2008_thumb.jpg",
+ "Logo6" => "http://www.executionroom.com/gfx/die_group_thumb.jpg")));
+ $form->addWidget(new Button("Post news"));
+ $form->render();
break;
}
}
public function admin_edit($action, $vars)
{
+ global $UID;
+
switch($action) {
case "add":
$this->news[$vars["newsid"]]->title = $vars["title"];
- $this->news[$vars["newsid"]]->time = totimestamp($vars, "time");
+ $this->news[$vars["newsid"]]->userid = $UID;
+ $this->news[$vars["newsid"]]->time = DateTimeEdit::toTimestamp($vars, "time");
$this->news[$vars["newsid"]]->category = $vars["category"];
$this->news[$vars["newsid"]]->description = $vars["description"];
$this->write();
@@ -112,42 +138,44 @@ class News {
break;
case "preview":
- $n = new NewsEntry($vars["title"], totimestamp($vars, "time"), $vars["category"], $vars["description"]);
+ $n = new NewsEntry($vars["title"], DatetimeEdit::toTimestamp($vars, "time"), $vars["category"], $vars["description"], $UID);
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();
+ $form = new Form("add");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("yes"));
+ $form->render();
+
+ $form = new Form("retry");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("no"));
+ $form->render();
break;
case "edit":
case "retry":
if(isset($vars["title"])) $title = $vars["title"];
else $title = $this->news[$vars["newsid"]]->title;
- if(isset($vars["time_year"])) $time = totimestamp($vars, "time");
+ if(isset($vars["time_year"])) $time = DateTimeEdit::toTimestamp($vars, "time");
else $time = $this->news[$vars["newsid"]]->time;
if(isset($vars["category"])) $category = $vars["category"];
else $category = $this->news[$vars["newsid"]]->category;
if(isset($vars["description"])) $description = $vars["description"];
else $description = $this->news[$vars["newsid"]]->description;
- beginform("preview");
- hidden($vars);
- 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();
+ $form = new Form("preview");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new LineEdit("Title", "title", $title));
+ $form->addWidget(new DateTimeEdit("Time", "time", $time));
+ $form->addWidget(new ComboBox("Category", "category", $category,
+ array("Main" => "main", "Site" => "site")));
+ $form->addWidget(new TextEdit("Description", "description", $description));
+ $form->addWidget(new Button("Post news"));
+ $form->render();
break;
case "select":
@@ -156,10 +184,11 @@ class News {
foreach($this->news as $newsentry) {
$newslist[$newsentry->title] = $newsentry->time;
}
- beginform("edit");
- combobox("Edit this entry:", "newsid", "", $newslist);
- button("Edit...");
- endform();
+
+ $form = new Form("edit");
+ $form->addWidget(new ComboBox("Edit this entry:", "newsid", "", $newslist));
+ $form->addWidget(new Button("Edit..."));
+ $form->render();
break;
}
}
@@ -168,21 +197,22 @@ class News {
{
switch($action) {
case "delete":
- echo $this->news[$vars["newsid"]]->title . " has now been deleted.";
+ echo "\"". $this->news[$vars["newsid"]]->title . "\" has now been deleted.";
unset($this->news[$vars["newsid"]]);
$this->write();
break;
case "confirm":
echo "Really delete: " . $this->news[$vars["newsid"]]->title . "?";
- beginform("delete");
- hidden($vars);
- button("yes");
- endform();
- beginform("select");
- hidden($vars);
- button("no");
- endform();
+ $form = new Form("delete");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("yes"));
+ $form->render();
+
+ $form = new Form("select");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("no"));
+ $form->render();
break;
case "select":
@@ -191,10 +221,10 @@ class News {
foreach($this->news as $newsentry) {
$newslist[$newsentry->title] = $newsentry->time;
}
- beginform("confirm");
- combobox("Delete this entry:", "newsid", "", $newslist);
- button("Delete...");
- endform();
+ $form = new Form("confirm");
+ $form->addWidget(new ComboBox("Delete this entry:", "newsid", "", $newslist));
+ $form->addWidget(new Button("Delete..."));
+ $form->render();
break;
}
}
@@ -216,12 +246,11 @@ class News {
}
}
- public function run($module)
+ public function run($params)
{
global $show;
- switch($module) {
- case "news":
+ switch($params) {
default:
if($show == "all") return $this->show(-1, "all");
else return $this->show(-1, "main");
@@ -258,13 +287,7 @@ class News {
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");
+ $newsentry->write($fp);
}
fwrite($fp, "</news>\n");
@@ -282,7 +305,8 @@ class News {
$newsentry = new NewsEntry($param->getAttribute('title'),
$param->getAttribute('time'),
$param->getAttribute('category'),
- $param->getAttribute('description'));
+ $param->getAttribute('description'),
+ $param->getAttribute('userid'));
$this->add($newsentry);
}
diff --git a/utils/modules/pages.php b/utils/modules/pages.php
index 373db1a..a3979d3 100644
--- a/utils/modules/pages.php
+++ b/utils/modules/pages.php
@@ -76,14 +76,15 @@ class Pages {
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();
+ $form = new Form("add");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("yes"));
+ $form->render();
+
+ $form = new Form("retry");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new Button("no"));
+ $form->render();
break;
case "edit":
@@ -93,23 +94,23 @@ class Pages {
echo "<p>See <a rel=\"external\" href=\"http://daringfireball.net/projects/markdown/syntax\">markdown</a> syntax.</p>";
- beginform("preview");
- hidden($vars);
- textedit("Content", "content", $content);
- button("Preview");
- endform();
+ $form = new Form("preview");
+ $form->addWidget(new Hidden($vars));
+ $form->addWidget(new TextEdit("Content", "content", $content));
+ $form->addWidget(new Button("Preview"));
+ $form->render();
break;
case "select":
default:
$pagelist = array();
foreach($this->pages as $p) {
- $pagelist[$p->title] = $p->title;
+ $pagelist[$p->title] = $p->title;
}
- beginform("edit");
- combobox("Edit this entry:", "title", "", $pagelist);
- button("Edit...");
- endform();
+ $form = new Form("edit");
+ $form->addWidget(new ComboBox("Edit this entry:", "title", "", $pagelist));
+ $form->addWidget(new Button("Edit..."));
+ $form->render();
break;
}
}