summaryrefslogtreecommitdiff
path: root/utils/modules/news.php
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/news.php
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/news.php')
-rw-r--r--utils/modules/news.php176
1 files changed, 100 insertions, 76 deletions
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);
}