diff options
author | deva <deva> | 2009-04-28 07:36:01 +0000 |
---|---|---|
committer | deva <deva> | 2009-04-28 07:36:01 +0000 |
commit | 3cb7a7f16be016f2d563762379222fdea5767986 (patch) | |
tree | b53f875ae6c3f5b6eaa68c5e1623f32793e94732 /utils/modules | |
parent | 1a8817ea76efb61240a9baa1673b95438e8770d9 (diff) |
Added icon module, and made the news module use it. Also made the ImageComboBox use it if supplied as the values parameter.
Diffstat (limited to 'utils/modules')
-rw-r--r-- | utils/modules/icons.php | 130 | ||||
-rw-r--r-- | utils/modules/news.php | 30 |
2 files changed, 140 insertions, 20 deletions
diff --git a/utils/modules/icons.php b/utils/modules/icons.php new file mode 100644 index 0000000..44df7e9 --- /dev/null +++ b/utils/modules/icons.php @@ -0,0 +1,130 @@ +<?php +/* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +include_once($UTIL_DIR . "/modules.php"); + +class Icon { + public $file; + public $prefix; + + public function src() + { + return "<img alt=\"icon\" src=\"".$this->prefix.$this->file."\"/>\n"; + } + + public function show() + { + echo $this->src(); + } + + public function Icon($file, $prefix) + { + $this->file = $file; + $this->prefix = $prefix; + } +} + +class Icons { + public $icons = array(); + public $prefix; + + // Admin config + public $admin_title = "Icons"; + public $admin_submodules = array("Add icon" => "add", "Delete icon" => "delete"); + + public function admin_add($action, $vars) + { + global $_FILES; + switch($action) { + case "create": + if(is_uploaded_file($_FILES['icon']['tmp_name'])) { + move_uploaded_file($_FILES['icon']['tmp_name'], $this->prefix . $_FILES['icon']['name']); + $i = new Icon($_FILES['icon']['name'], $this->prefix); + $this->icons[$_FILES['icon']['name']] = $i; + $i->show(); + } else { + echo "Failed to upload file: " . $icon['name'] . " to " . $icon['tmp_name'] . "\n"; + } + + default: + echo "Existing icons\n"; + echo "<div style=\"width: 500px; height: 200px; overflow: auto\">\n"; + foreach($this->icons as $icon) { + $icon->show(); + } + echo "</div>\n"; + + $form = new Form("create"); + $form->addWidget(new FileUpload("Select icons:", "icon")); + $form->addWidget(new Button("Upload")); + $form->render(); + break; + } + } + + public function admin_delete($action, $vars) + { + global $_FILES; + switch($action) { + case "confirm": + echo "<p>Are you sure you want to delete this icon?</p>\n"; + $this->icons[$vars['icon']]->show(); + + $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 "delete": + unlink($this->prefix.$vars['icon']); + unset($this->icons[$vars['icon']]); + echo "<p>The icon has now been deleted.</p>\n"; + + case "select": + default: + $form = new Form("confirm"); + $form->addWidget(new ImageComboBox("Icon", "icon", $icon, $this)); + $form->addWidget(new Button("Delete...")); + $form->render(); + break; + } + } + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "add": + $this->admin_add($action, $vars); + break; + case "delete": + $this->admin_delete($action, $vars); + break; + } + } + + public function Icons($prefix) + { + $this->prefix = $prefix; + $df = opendir($prefix); + while(false !== ($file = readdir($df))) { + if($file == '.' || $file == '..') continue; + $icon = new Icon($file, $prefix); + $this->icons[$file] = $icon; + } + closedir($df); + } + +} + +function icons_init() +{ + global $ICONS_DIR; + return new Icons($ICONS_DIR."/"); +} + +?> diff --git a/utils/modules/news.php b/utils/modules/news.php index 9667e44..95cdda1 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -3,6 +3,7 @@ include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/forms.php"); include_once($UTIL_DIR . "/user.php"); +include_once($MODULES_DIR . "/icons.php"); class NewsEntry { public $title; @@ -14,16 +15,19 @@ class NewsEntry { public function show() { - global $users, $DATA_DIR; + global $users, $DATA_DIR, $ICONS_DIR; if(!isset($users)) $users = new Users($DATA_DIR . "/users.xml"); + $icons = new Icons($ICONS_DIR."/"); + $icon = $icons->icons[$this->icon]; + $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_user\">By: " . $users->findUser($this->userid)->userid . "</div>\n"; $str .= " <div class=\"news_description\">\n"; - if($this->icon) $str .= " <img alt=\"icon\" class=\"news_icon\" src=\"" . $this->icon . "\"/>\n"; + if($this->icon) $str .= " <img alt=\"icon\" class=\"news_icon\" src=\"" . $icon->prefix.$icon->file . "\"/>\n"; $str .= " ".htmlspecialchars_decode($this->description, ENT_QUOTES) . "\n"; $str .= " </div>\n"; $str .= "</div>\n"; @@ -72,7 +76,7 @@ class News { public function admin_add($action, $vars) { - global $UID; + global $UID, $ICONS_DIR; switch($action) { case "add": @@ -109,19 +113,12 @@ class News { $category = $vars["category"]; $description = $vars["description"]; default: - $icons = array("http://www.executionroom.com/gfx/logos/die_logo_black_thumb.png", - "http://www.executionroom.com/gfx/logos/die_logo_bloody_thumb.png", - "http://www.executionroom.com/gfx/logos/die_logo_red_thumb_.png", - "http://www.executionroom.com/gfx/logos/die_logo_white_thumb.png", - "http://www.executionroom.com/gfx/die_group_2008_thumb.jpg", - "http://www.executionroom.com/gfx/die_group_thumb.jpg"); - $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, $icons)); + $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Post news")); $form->render(); break; @@ -130,7 +127,7 @@ class News { public function admin_edit($action, $vars) { - global $UID; + global $UID, $ICONS_DIR; switch($action) { case "add": @@ -165,13 +162,6 @@ class News { case "edit": case "retry": - $icons = array("http://www.executionroom.com/gfx/logos/die_logo_black_thumb.png", - "http://www.executionroom.com/gfx/logos/die_logo_bloody_thumb.png", - "http://www.executionroom.com/gfx/logos/die_logo_red_thumb_.png", - "http://www.executionroom.com/gfx/logos/die_logo_white_thumb.png", - "http://www.executionroom.com/gfx/die_group_2008_thumb.jpg", - "http://www.executionroom.com/gfx/die_group_thumb.jpg"); - if(isset($vars["title"])) $title = $vars["title"]; else $title = $this->news[$vars["newsid"]]->title; if(isset($vars["time_year"])) $time = DateTimeEdit::toTimestamp($vars, "time"); @@ -190,7 +180,7 @@ class News { $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, $icons)); + $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Post news")); $form->render(); break; |