diff options
author | deva <deva> | 2009-04-23 07:41:28 +0000 |
---|---|---|
committer | deva <deva> | 2009-04-23 07:41:28 +0000 |
commit | 3f1dda1e19e1f77e908df1d49d028d0932d0f1a1 (patch) | |
tree | d44586018a0594aa53cfbe172d7a576bbe5f593c | |
parent | 9fc8170f4492c3e5900156610061e59c84aa9d83 (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.
-rw-r--r-- | htdocs/index.php | 14 | ||||
-rw-r--r-- | utils/forms.php | 361 | ||||
-rw-r--r-- | utils/modules/config.php | 144 | ||||
-rw-r--r-- | utils/modules/events.php | 49 | ||||
-rw-r--r-- | utils/modules/gallery.php | 36 | ||||
-rw-r--r-- | utils/modules/news.php | 176 | ||||
-rw-r--r-- | utils/modules/pages.php | 37 |
7 files changed, 568 insertions, 249 deletions
diff --git a/htdocs/index.php b/htdocs/index.php index 6783187..5d05807 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -1,6 +1,8 @@ <?php include_once("config.php"); -include_once($UTIL_DIR . "/config.php"); +include_once($MODULES_DIR . "/config.php"); + +$config = new Config($DATA_DIR . "/config.xml"); include_once($UTIL_DIR . "/guestbook.php"); header("Content-Type: text/html; charset=UTF-8"); @@ -16,7 +18,7 @@ $pages = new Pages($DATA_DIR . "/pages.xml"); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> - <title><?php echo config('title');?></title> + <title><?php echo $config->value('title');?></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta name="MSSmartTagsPreventParsing" content="true"/> <meta http-equiv="Content-Type" content="text/html"/> @@ -43,7 +45,7 @@ $pages = new Pages($DATA_DIR . "/pages.xml"); <body> <div style="display: none;"> <?php -$ps = config('preload'); +$ps = $config->value('preload'); foreach($ps as $p) { echo " <img alt=\"preload\" src=\"".$p."\"/>\n"; } @@ -55,7 +57,7 @@ foreach($ps as $p) { echo "style=\"width: 848px;\""; ?>> <?php -$menu = config('menu'); +$menu = $config->value('menu'); foreach($menu as $_m => $_t) { echo " <a href=\"?page=".$_m."\" class=\"menu_entry_".$_m."\"></a>\n"; echo " <a href=\"?page=".$_m."\" class=\"menutitle\">".$t."</a>\n"; @@ -70,13 +72,11 @@ foreach($menu as $_m => $_t) { echo "style=\"width: 599px;\""; ?>> <?php -include_once("config.php"); - if($page == "admin") { include($PAGE_DIR."/admin.php"); } else { if($page) $p = $pages->getPage($page); - else $p = $pages->getPage(config('default')); + else $p = $pages->getPage($config->value('default')); if($p) $p->show(); } ?> diff --git a/utils/forms.php b/utils/forms.php index d5216f2..dd0a768 100644 --- a/utils/forms.php +++ b/utils/forms.php @@ -1,147 +1,262 @@ <?php +class LineEdit { + private $label, $name, $value; + + function LineEdit($label, $name, $value = "") + { + $this->label = $label; + $this->name = $name; + $this->value = $value; + } -function beginform($action, $hasfile = false) -{ - global $m, $s; -?> -<form method="post" -<?php if($hasfile) { ?> enctype="multipart/form-data" -<?php } ?> action="?page=admin&m=<?php echo $m; ?>&s=<?php echo $s; ?>&a=<?php echo $action; ?>"> -<?php + function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">". $this->label ."</div>\n"; + $str .= $indent . " <div class=\"widget\"><input name=\"vars[".$this->name."]\" value=\"".$this->value."\"/></div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function endform() -{ -?> -</form> -<?php -} +class FileUpload { + private $label, $name, $accept; -function button($label) -{ -?> - <div class="input"> - <div class="label"></div> - <div class="widget"><button type="submit"><?php echo $label; ?></button></div> - </div> -<?php + public function FileUpload($label, $name, $accept = "*") + { + $this->label = $label; + $this->name = $name; + $this->accept = $accept; + } + + public function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">". $this->label . "</div>\n"; + $str .= $indent . " <div class=\"widget\"><input type=\"file\" name=\"" + . $this->name. "\" accept=\"". $this->accept ."\"/></div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function lineedit($label, $name, $value = "") -{ -?> - <div class="input"> - <div class="label"><?php echo $label; ?></div> - <div class="widget"><input name="<?php echo "vars[".$name."]"; ?>" value="<?php echo $value; ?>"/></div> - </div> -<?php +class Button { + private $label; + + public function Button($label) + { + $this->label = $label; + } + + public function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\"></div>\n"; + $str .= $indent . " <div class=\"widget\"><button type=\"submit\">". + $this->label."</button></div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function fileupload($label, $name, $accept = "*") -{ -?> - <div class="input"> - <div class="label"><?php echo $label; ?></div> - <div class="widget"><input type="file" name="<?php echo $name; ?>" accept="<?php echo $accept;?>"/></div> - </div> -<?php +class CheckBox { + private $label, $name, $value; + + public function CheckBox($label, $name, $value = "") + { + $this->label = $label; + $this->name = $name; + $this->value = $value; + } + + public function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">". $this->label ."</div>\n"; + $str .= $indent . " <div class=\"widget\"><input type=\"checkbox\" name=\"vars[".$this->name."]\" value=\"".$this->value."\"/></div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function hidden($values) -{ - foreach($values as $key => $value) { -?> - <input type="hidden" name="<?php echo "vars[".$key."]"; ?>" value="<?php echo $value; ?>"/> -<?php - } +class ComboBox { + private $label, $name, $value, $values; + + public function ComboBox($label, $name, $value, $values) + { + $this->label = $label; + $this->name = $name; + $this->value = $value; + $this->values = $values; + } + + public function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">".$this->label."</div>\n"; + $str .= $indent . " <div class=\"widget\">\n"; + $str .= $indent . " <select name=\"vars[".$this->name."]\">\n"; + foreach($this->values as $k => $v) { + if($v != $this->value) $str .= $indent . " <option value=\"".$v."\">".$k."</option>\n"; + else $str .= $indent . " <option value=\"".$v."\" selected>".$k."</option>\n"; + } + $str .= $indent . " </select>\n"; + $str .= $indent . " </div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function textedit($label, $name, $value = "") -{ -?> - <div class="input"> - <div class="label"><?php echo $label; ?></div> - <div class="widget"><textarea class="textedit" name="<?php echo "vars[".$name."]"; ?>"><?php echo $value; ?></textarea></div> - </div> -<?php +class Hidden { + private $values; + + public function Hidden($values) + { + $this->values = $values; + } + + public function render($indent = "") + { + $str = ""; + foreach($this->values as $key => $value) { + $str .= $indent . "<input type=\"hidden\" name=\"vars[".$key."]\" value=\"".$value."\"/>\n"; + } + return $str; + } } -function datetimeedit($label, $name, $timestamp = 0) -{ - if($timestamp == 0) $timestamp = time(); +class TextEdit { + private $label, $name, $value; + + function TextEdit($label, $name, $value = "") + { + $this->label = $label; + $this->name = $name; + $this->value = $value; + } - $second = date('s',$timestamp); - $minute = date('i',$timestamp); - $hour = date('G',$timestamp); - $day = date('d',$timestamp); - $month = date('m',$timestamp); - $year = date('Y',$timestamp); -?> - <div class="input"> - <div class="label"><?php echo $label; ?></div> - <div class="widget"> - <input style="width: 40px;" name="<?php echo "vars[".$name."_year]"; ?>" value="<?php echo $year; ?>"/>/<input style="width: 20px;" name="<?php echo "vars[".$name."_month]"; ?>" value="<?php echo $month; ?>"/>/<input style="width: 20px;" name="<?php echo "vars[".$name."_day]"; ?>" value="<?php echo $day; ?>"/> - - - <input style="width: 20px;" name="<?php echo "vars[".$name."_hour]"; ?>" value="<?php echo $hour; ?>"/>:<input style="width: 20px;" name="<?php echo "vars[".$name."_minute]"; ?>" value="<?php echo $minute; ?>"/>:<input style="width: 20px;" name="<?php echo "vars[".$name."_second]"; ?>" value="<?php echo $second; ?>"/> - </div> - </div> -<?php + function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">". $this->label ."</div>\n"; + $str .= $indent . " <div class=\"widget\"><textarea class=\"textedit\" name=\"vars[".$this->name."]\">".$this->value."</textarea></div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function totimestamp($t, $name) -{ - $timestring = sprintf("%d", $t[$name."_year"]) ."/". - sprintf("%d", $t[$name."_month"]) ."/". - sprintf("%d", $t[$name."_day"]) ." ". - sprintf("%d", $t[$name."_hour"]) .":". - sprintf("%02d", $t[$name."_minute"]).":". - sprintf("%02d", $t[$name."_second"]); - - //echo $timestring; - - return strtotime($timestring); + +class DateTimeEdit { + private $label, $name, $timestamp; + + function DateTimeEdit($label, $name, $timestamp = 0) + { + $this->label = $label; + $this->name = $name; + $this->timestamp = $timestamp; + } + + function render($indent = "") + { + if($this->timestamp == 0) $t = time(); + else $t = $this->timestamp; + + $second = date('s',$t); + $minute = date('i',$t); + $hour = date('G',$t); + $day = date('d',$t); + $month = date('m',$t); + $year = date('Y',$t); + + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">".$this->label."</div>\n"; + $str .= $indent . " <div class=\"widget\">\n"; + $str .= $indent . " <input style=\"width: 50px;\" name=\"vars[".$this->name."_year]\" value=\"".$year."\"/>"; + $str .= "/<input style=\"width: 30px;\" name=\"vars[".$this->name."_month]\" value=\"".$month."\"/>"; + $str .= "/<input style=\"width: 30px;\" name=\"vars[".$this->name."_day]\" value=\"".$day."\"/>"; + $str .= " - "; + $str .= "<input style=\"width: 30px;\" name=\"vars[".$this->name."_hour]\" value=\"".$hour."\"/>"; + $str .= ":<input style=\"width: 30px;\" name=\"vars[".$this->name."_minute]\" value=\"".$minute."\"/>"; + $str .= ":<input style=\"width: 30px;\" name=\"vars[".$this->name."_second]\" value=\"".$second."\"/>\n"; + $str .= $indent . " </div>\n"; + $str .= $indent . "</div>\n"; + + return $str; + } + + public function toTimestamp($t, $name) + { + $timestring = sprintf("%d", $t[$name."_year"]) ."/". + sprintf("%d", $t[$name."_month"]) ."/". + sprintf("%d", $t[$name."_day"]) ." ". + sprintf("%d", $t[$name."_hour"]) .":". + sprintf("%02d", $t[$name."_minute"]).":". + sprintf("%02d", $t[$name."_second"]); + + return strtotime($timestring); + } } -function combobox($label, $name, $value, $values) -{ -?> - <div class="input"> - <div class="label"><?php echo $label; ?></div> - <div class="widget"> - <select name="<?php echo "vars[".$name."]"; ?>"> -<?php - - foreach($values as $k => $v) { - if($v != $value) echo " <option value=\"$v\">$k</option>\n"; - else echo " <option value=\"$v\" selected>$k</option>\n"; - } -?> - </select> - </div> - </div> -<?php +class ImageComboBox { + private $label, $name, $value, $values; + + public function ImageComboBox($label, $name, $value, $values) + { + $this->label = $label; + $this->name = $name; + $this->value = $value; + $this->values = $values; + } + + public function render($indent = "") + { + $str = $indent . "<div class=\"input\">\n"; + $str .= $indent . " <div class=\"label\">".$this->label."</div>\n"; + $str .= $indent . " <div class=\"widget\">\n"; + $str .= $indent . " <select name=\"vars[".$this->name."]\">\n"; + + foreach($this->values as $k => $v) { + $str .= $indent . " <optgroup style=\"background-image: url(".$v."); height: 100px; width: 100px;\"/>\n"; + $str .= $indent . " <option value=\"".$k."\""; + if($v == $value) $str .= " selected"; + $str .=">".$k."</option>\n"; + $str .= $indent . " </optgroup>\n"; + } + + $str .= $indent . " </select>\n"; + $str .= $indent . " </div>\n"; + $str .= $indent . "</div>\n"; + return $str; + } } -function imagecombobox($label, $name, $value, $values) -{ -?> - <div class="input"> - <div class="label"><?php echo $label; ?></div> - <div class="widget"> - <select name="<?php echo "vars[".$name."]"; ?>"> -<?php - - foreach($values as $k => $v) { -?> - <optgroup style="background-image: url(<?php echo $v;?>); height: 100px; width: 100px;"/> - <option value="<?php echo $k; ?>"<?php if($v == $value) echo " selected";?>><?php echo $k;?></option> - </optgroup> -<?php - } -?> - </select> - </div> - </div> -<?php +class Form { + private $widgets = array(); + private $action; + private $hasFileUpload = false; + + public function addWidget($widget) + { + if(get_class($widget) == "FileUpload") $this->hasFileUpload = true; + array_push($this->widgets, $widget); + } + + public function render($indent = "") + { + global $m, $s; + $str = $indent . "<form method=\"post\"\n"; + if($this->hasFileUpload) $str .= $indent . " enctype=\"multipart/form-data\"\n"; + $str .= $indent . " action=\"?page=admin&m=".$m."&s=".$s."&a=".$this->action."\">\n"; + foreach($this->widgets as $widget) { + $str .= $widget->render($indent . " "); + } + $str .= $indent . "</form>\n"; + echo $str; + } + + public function Form($action) + { + $this->action = $action; + } } ?> 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; } } |