From ef9d938216f4a2a54a9bd789b39ee67053556f0d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 22 Nov 2012 23:52:04 +0100 Subject: [PATCH] Added style import form --- acpMenu.xml | 7 ++ acptemplates/styleImport.tpl | 54 ++++++++++++ acptemplates/styleList.tpl | 2 + files/lib/acp/form/StyleImportForm.class.php | 92 ++++++++++++++++++++ language/de.xml | 5 ++ 5 files changed, 160 insertions(+) create mode 100644 acptemplates/styleImport.tpl create mode 100644 files/lib/acp/form/StyleImportForm.class.php diff --git a/acpMenu.xml b/acpMenu.xml index d03c7fa486..ea4924a678 100644 --- a/acpMenu.xml +++ b/acpMenu.xml @@ -20,6 +20,13 @@ admin.style.canAddStyle 2 + + + index.php/StyleImport/ + wcf.acp.menu.link.style + admin.style.canAddStyle + 3 + diff --git a/acptemplates/styleImport.tpl b/acptemplates/styleImport.tpl new file mode 100644 index 0000000000..848f7d9374 --- /dev/null +++ b/acptemplates/styleImport.tpl @@ -0,0 +1,54 @@ +{include file='header' pageTitle='wcf.acp.style.importStyle'} + +
+
+

{lang}wcf.acp.style.importStyle{/lang}

+
+
+ +{if $success|isset} +

{lang}wcf.global.form.add.success{/lang}

+{/if} + +
+ +
+ +
+
+
+ {lang}wcf.acp.style.import.source{/lang} + + +
+
+ + {if $errorField == 'source'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.style.import.source.error.{@$errorType}{/lang} + {/if} + + {/if} + {lang}wcf.acp.style.import.source.upload.description{/lang} +
+ + + {event name='sourceFields'} +
+ + {event name='fieldsets'} +
+ +
+ +
+
+ +{include file='footer'} \ No newline at end of file diff --git a/acptemplates/styleList.tpl b/acptemplates/styleList.tpl index cbc66b9163..a85cce32e7 100644 --- a/acptemplates/styleList.tpl +++ b/acptemplates/styleList.tpl @@ -25,6 +25,7 @@ {content} {if $__wcf->session->getPermission('admin.style.canAddStyle')}
  • {lang}wcf.acp.menu.link.style.add{/lang}
  • +
  • {lang}wcf.acp.menu.link.style.import{/lang}
  • {/if} {event name='largeButtons'} @@ -81,6 +82,7 @@ {content} {if $__wcf->session->getPermission('admin.style.canAddStyle')}
  • {lang}wcf.acp.menu.link.style.add{/lang}
  • +
  • {lang}wcf.acp.menu.link.style.import{/lang}
  • {/if} {event name='largeButtons'} diff --git a/files/lib/acp/form/StyleImportForm.class.php b/files/lib/acp/form/StyleImportForm.class.php new file mode 100644 index 0000000000..e9e7745664 --- /dev/null +++ b/files/lib/acp/form/StyleImportForm.class.php @@ -0,0 +1,92 @@ + + * @package com.woltlab.wcf.acp.style + * @subpackage acp.form + * @category Community Framework + */ +class StyleImportForm extends ACPForm { + /** + * @see wcf\acp\form\ACPForm::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.style.import'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.style.canAddStyle'); + + /** + * upload data + * @var array + */ + public $source = array(); + + /** + * style editor object + * @var wcf\data\style\StyleEditor + */ + public $style = null; + + /** + * @see wcf\form\IForm::readFormParameters() + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_FILES['source'])) $this->source = $_FILES['source']; + } + + /** + * @see wcf\form\IForm::validate() + */ + public function validate() { + parent::validate(); + + if (empty($this->source['name'])) { + throw new UserInputException('source'); + } + + if (empty($this->source['tmp_name'])) { + throw new UserInputException('source', 'uploadFailed'); + } + + // get filename + $this->source['name'] = FileUtil::getTemporaryFilename('style_', preg_replace('!^.*(?=\.(?:tar\.gz|tgz|tar)$)!i', '', basename($this->source['name']))); + + if (!@move_uploaded_file($this->source['tmp_name'], $this->source['name'])) { + throw new UserInputException('source', 'uploadFailed'); + } + + + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + parent::save(); + + try { + $this->style = StyleEditor::import($this->source['name']); + } + catch (\Exception $e) { + @unlink($this->source['name']); + } + + @unlink($this->source['name']); + $this->saved(); + + WCF::getTPL()->assign('success', true); + } +} diff --git a/language/de.xml b/language/de.xml index eacfc00bfa..d860474195 100644 --- a/language/de.xml +++ b/language/de.xml @@ -3,6 +3,7 @@ + @@ -75,6 +76,10 @@ + + + + -- 2.20.1