summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/forms.php25
-rw-r--r--utils/modules/icons.php130
-rw-r--r--utils/modules/news.php30
3 files changed, 158 insertions, 27 deletions
diff --git a/utils/forms.php b/utils/forms.php
index d946c34..a450463 100644
--- a/utils/forms.php
+++ b/utils/forms.php
@@ -209,7 +209,12 @@ class ImageComboBox {
public function render($indent = "")
{
- $width = 100;
+ $selheight = 64;
+ $height = $selheight * 0.8;
+
+ if(get_class($this->values) == "Icons") $numicons = sizeof($this->values->icons);
+ else $numicons = sizeof($this->values);
+
$str = $indent . "<div class=\"input\">\n";
$str .= $indent . " <div class=\"label\">".$this->label."</div>\n";
$str .= $indent . " <div class=\"widget\">\n";
@@ -220,18 +225,24 @@ class ImageComboBox {
$str .= $indent . " var container = document.getElementById('icons');\n";
$str .= $indent . " var icons = document.getElementsByName('icon');\n";
$str .= $indent . " for(i = 0; i < icons.length; i++) {\n";
- $str .= $indent . " if(icons[i].src == value) icons[i].width = ".$width.";\n";
- $str .= $indent . " else icons[i].width = ".($width - 10).";\n";
+ $str .= $indent . " if(icons[i].alt == value) icons[i].height = ".$selheight.";\n";
+ $str .= $indent . " else icons[i].height = ".$height.";\n";
// $str .= $indent . " if(icons[i].src == value) icons[i].style.border = '10px blue';\n";
// $str .= $indent . " else { icons[i].style.border = '0px' }\n";
$str .= $indent . " }\n";
$str .= $indent . " }\n";
$str .= $indent . " </script>\n";
- $str .= $indent . " <div style=\"width:300px;overflow:scroll;\">\n";
- $str .= $indent . " <div id=\"icons\" style=\"width:".($width + 6)*sizeof($this->values)."px;\">\n";
+ $str .= $indent . " <div style=\"width:300px;overflow:auto;height:".($selheight+24)."px;\">\n";
+ $str .= $indent . " <div id=\"icons\" style=\"text-align: left; height: ".$selheight."px; width:".(($height+8)*($numicons-1)+$selheight)."px; display: block;\">\n";
$str .= $indent . " <input id=\"".$this->name."\" name=\"vars[".$this->name."]\" type=\"hidden\" value=\"\"/>\n";
- foreach($this->values as $k => $v) {
- $str .= $indent . " <img name=\"icon\" src=\"".$v."\" style=\"max-width: ".$width."\" onclick=\"setSelection('".$v."')\"/>\n";
+ if(get_class($this->values) == "Icons") {
+ foreach($this->values->icons as $icon) {
+ $str .= $indent . " <img name=\"icon\" alt=\"".$icon->file."\" src=\"".$icon->prefix.$icon->file."\" onclick=\"setSelection('".$icon->file."')\"/>\n";
+ }
+ } else {
+ foreach($this->values as $k => $v) {
+ $str .= $indent . " <img name=\"icon\" alt=\"".$v."\" src=\"".$v."\" onclick=\"setSelection('".$v."')\"/>\n";
+ }
}
$str .= $indent . " </div>\n"; // box
$str .= $indent . " </div>\n"; // overflow
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;