2 namespace wcf\acp\form
;
3 use wcf\data\style\StyleEditor
;
4 use wcf\form\AbstractForm
;
5 use wcf\system\cache\builder\StyleCacheBuilder
;
6 use wcf\system\exception\SystemException
;
7 use wcf\system\exception\UserInputException
;
8 use wcf\system\package\PackageArchive
;
9 use wcf\system\request\LinkHandler
;
11 use wcf\util\FileUtil
;
12 use wcf\util\HeaderUtil
;
15 * Shows the style import form.
17 * @author Alexander Ebert
18 * @copyright 2001-2014 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package com.woltlab.wcf
21 * @subpackage acp.form
22 * @category Community Framework
24 class StyleImportForm
extends AbstractForm
{
26 * @see \wcf\page\AbstractPage::$activeMenuItem
28 public $activeMenuItem = 'wcf.acp.menu.link.style.import';
31 * @see \wcf\page\AbstractPage::$neededPermissions
33 public $neededPermissions = array('admin.style.canManageStyle');
39 public $source = array();
43 * @var \wcf\data\style\StyleEditor
48 * @see \wcf\form\IForm::readFormParameters()
50 public function readFormParameters() {
51 parent
::readFormParameters();
53 if (isset($_FILES['source'])) $this->source
= $_FILES['source'];
57 * @see \wcf\form\IForm::validate()
59 public function validate() {
62 if (empty($this->source
['name'])) {
63 throw new UserInputException('source');
66 if (empty($this->source
['tmp_name'])) {
67 throw new UserInputException('source', 'uploadFailed');
71 // check if the uploaded file is a package
72 $archive = new PackageArchive($this->source
['tmp_name']);
73 $archive->openArchive();
75 // check if the package is an application
76 if ($archive->getPackageInfo('isApplication')) {
77 throw new SystemException("Package is application");
80 // check if the package includes a style
81 $containsStyle = false;
82 $installInstructions = $archive->getInstallInstructions();
83 foreach ($installInstructions as $instruction) {
84 if ($instruction['pip'] == 'style') {
85 $containsStyle = true;
90 if (!$containsStyle) {
91 throw new SystemException("Package contains no style");
94 $filename = FileUtil
::getTemporaryFilename('package_', preg_replace('!^.*(?=\.(?:tar\.gz|tgz|tar)$)!i', '', basename($this->source
['name'])));
96 if (!@move_uploaded_file
($this->source
['tmp_name'], $filename)) {
97 throw new SystemException("Cannot move uploaded file");
100 WCF
::getSession()->register('stylePackageImportLocation', $filename);
102 HeaderUtil
::redirect(LinkHandler
::getInstance()->getLink('PackageStartInstall', array(
103 'action' => 'install'
107 catch (SystemException
$e) {
112 $this->style
= StyleEditor
::import($this->source
['tmp_name']);
114 catch (\Exception
$e) {
115 @unlink
($this->source
['tmp_name']);
116 throw new UserInputException('source', 'importFailed');
121 * @see \wcf\form\IForm::save()
123 public function save() {
126 StyleCacheBuilder
::getInstance()->reset();
128 @unlink
($this->source
['tmp_name']);
131 WCF
::getTPL()->assign('success', true);