From 3cb7a7f16be016f2d563762379222fdea5767986 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 28 Apr 2009 07:36:01 +0000 Subject: Added icon module, and made the news module use it. Also made the ImageComboBox use it if supplied as the values parameter. --- utils/modules/icons.php | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 utils/modules/icons.php (limited to 'utils/modules/icons.php') 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 @@ +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 "
\n"; + foreach($this->icons as $icon) { + $icon->show(); + } + echo "
\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 "

Are you sure you want to delete this icon?

\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 "

The icon has now been deleted.

\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."/"); +} + +?> -- cgit v1.2.3