Added style import form
authorAlexander Ebert <ebert@woltlab.com>
Thu, 22 Nov 2012 22:52:04 +0000 (23:52 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 22 Nov 2012 22:52:04 +0000 (23:52 +0100)
acpMenu.xml
acptemplates/styleImport.tpl [new file with mode: 0644]
acptemplates/styleList.tpl
files/lib/acp/form/StyleImportForm.class.php [new file with mode: 0644]
language/de.xml

index d03c7fa4867967adbbf13993dc4df8c2ffe23218..ea4924a678402965154b6f932b500e0c4579a47e 100644 (file)
                        <permissions>admin.style.canAddStyle</permissions>
                        <showorder>2</showorder>
                </acpmenuitem>
+               
+               <acpmenuitem name="wcf.acp.menu.link.style.import">
+                       <link>index.php/StyleImport/</link>
+                       <parent>wcf.acp.menu.link.style</parent>
+                       <permissions>admin.style.canAddStyle</permissions>
+                       <showorder>3</showorder>
+               </acpmenuitem>
                <!-- /style -->
        </import>
 </data>
diff --git a/acptemplates/styleImport.tpl b/acptemplates/styleImport.tpl
new file mode 100644 (file)
index 0000000..848f7d9
--- /dev/null
@@ -0,0 +1,54 @@
+{include file='header' pageTitle='wcf.acp.style.importStyle'}
+
+<header class="boxHeadline">
+       <hgroup>
+               <h1>{lang}wcf.acp.style.importStyle{/lang}</h1>
+       </hgroup>
+</header>
+
+{if $success|isset}
+       <p class="success">{lang}wcf.global.form.add.success{/lang}</p> 
+{/if}
+
+<div class="contentNavigation">
+       <nav>
+               <ul>
+                       <li><a href="{link controller='StyleList'}{/link}" title="{lang}wcf.acp.menu.link.style.list{/lang}" class="button"><img src="{@$__wcf->getPath()}icon/list.svg" alt="" class="icon24" /> <span>{lang}wcf.acp.menu.link.style.list{/lang}</span></a></li>
+               </ul>
+       </nav>
+</div>
+
+<form method="post" action="{link controller='StyleImport'}{/link}" enctype="multipart/form-data">
+       <div class="container containerPadding marginTop shadow">
+               <fieldset>
+                       <legend>{lang}wcf.acp.style.import.source{/lang}</legend>
+                       
+                       <dl{if $errorField == 'source'} class="formError"{/if}>
+                               <dt><label for="source">{lang}wcf.acp.style.import.source.upload{/lang}</label></dt>
+                               <dd>
+                                       <input type="file" id="source" name="source" value="" />
+                                       {if $errorField == 'source'}
+                                               <small class="innerError">
+                                                       {if $errorType == 'empty'}
+                                                               {lang}wcf.global.form.error.empty{/lang}
+                                                       {else}
+                                                               {lang}wcf.acp.style.import.source.error.{@$errorType}{/lang}
+                                                       {/if}
+                                               </small>
+                                       {/if}
+                                       <small>{lang}wcf.acp.style.import.source.upload.description{/lang}</small>
+                               </dd>
+                       </dl>
+                       
+                       {event name='sourceFields'}
+               </fieldset>
+               
+               {event name='fieldsets'}
+       </div>
+
+       <div class="formSubmit">
+               <input type="submit" name="submitButton" value="{lang}wcf.global.button.submit{/lang}" accesskey="s" />
+       </div>
+</form>
+
+{include file='footer'}
\ No newline at end of file
index cbc66b91633941e92bc41210dd0f83cc441d2978..a85cce32e7de6728809d308bcae84d654bcb526c 100644 (file)
@@ -25,6 +25,7 @@
                                {content}
                                        {if $__wcf->session->getPermission('admin.style.canAddStyle')}
                                                <li><a href="{link controller='StyleAdd'}{/link}" title="{lang}wcf.acp.menu.link.style.add{/lang}" class="button"><img src="{@$__wcf->getPath()}icon/add.svg" alt="" class="icon24" /> <span>{lang}wcf.acp.menu.link.style.add{/lang}</span></a></li>
+                                               <li><a href="{link controller='StyleImport'}{/link}" title="{lang}wcf.acp.menu.link.style.import{/lang}" class="button"><img src="{@$__wcf->getPath()}icon/upload.svg" alt="" class="icon24" /> <span>{lang}wcf.acp.menu.link.style.import{/lang}</span></a></li>
                                        {/if}
                                        
                                        {event name='largeButtons'}
@@ -81,6 +82,7 @@
                                {content}
                                        {if $__wcf->session->getPermission('admin.style.canAddStyle')}
                                                <li><a href="{link controller='StyleAdd'}{/link}" title="{lang}wcf.acp.menu.link.style.add{/lang}" class="button"><img src="{@$__wcf->getPath()}icon/add.svg" alt="" class="icon24" /> <span>{lang}wcf.acp.menu.link.style.add{/lang}</span></a></li>
+                                               <li><a href="{link controller='StyleImport'}{/link}" title="{lang}wcf.acp.menu.link.style.import{/lang}" class="button"><img src="{@$__wcf->getPath()}icon/upload.svg" alt="" class="icon24" /> <span>{lang}wcf.acp.menu.link.style.import{/lang}</span></a></li>
                                        {/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 (file)
index 0000000..e9e7745
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+namespace wcf\acp\form;
+use wcf\data\style\StyleEditor;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+use wcf\util\FileUtil;
+
+/**
+ * Shows the style import form.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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<string>
+        */
+       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);
+       }
+}
index eacfc00bfa7b5c67fae9f07fa2d9cc139acb60ba..d8604741954f4b25cf61beb6cfc6eb828ce3694f 100644 (file)
@@ -3,6 +3,7 @@
        <category name="wcf.acp.menu">
                <item name="wcf.acp.menu.link.style"><![CDATA[Stile]]></item>
                <item name="wcf.acp.menu.link.style.add"><![CDATA[Stil hinzufügen]]></item>
+               <item name="wcf.acp.menu.link.style.import"><![CDATA[Stil importieren]]></item>
                <item name="wcf.acp.menu.link.style.list"><![CDATA[Stile auflisten]]></item>
        </category>
        
                <item name="wcf.acp.style.image.description"><![CDATA[Laden Sie hier ein Vorschaubild dieses Stiles hoch, als Bildformate sind JPG und PNG zulässig. Es wird empfohlen Vorschaubilder immer mit der Größe 102px × 64px anzulegen, größere Grafiken werden automatisch skaliert.]]></item>
                <item name="wcf.acp.style.imagePath"><![CDATA[Bilder-Pfad]]></item>
                <item name="wcf.acp.style.imagePath.description"><![CDATA[Wenn Ihr Stil eigene Grafiken benötigt, sollten diese in einem Unterordner des Ordners &bdquo;images&ldquo; ablegen. Geben Sie hier den Pfad zu diesem Ordner an.]]></item>
+               <item name="wcf.acp.style.importStyle"><![CDATA[Stil importieren]]></item>
+               <item name="wcf.acp.style.import.source"><![CDATA[Datenquelle]]></item>
+               <item name="wcf.acp.style.import.source.upload"><![CDATA[Stil hochladen]]></item>
+               <item name="wcf.acp.style.import.source.upload.description"><![CDATA[Geben Sie eine Stil-Datei von Ihrem lokalen Rechner an.]]></item>
                <item name="wcf.acp.style.license"><![CDATA[Lizenz]]></item>
                <item name="wcf.acp.style.list"><![CDATA[Stile auflisten]]></item>
                <item name="wcf.acp.style.packageName"><![CDATA[Paketbezeichner]]></item>