summaryrefslogtreecommitdiff
path: root/utils/modules/icons.php
diff options
context:
space:
mode:
Diffstat (limited to 'utils/modules/icons.php')
-rw-r--r--utils/modules/icons.php130
1 files changed, 130 insertions, 0 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."/");
+}
+
+?>