<div class="contentNavigation">
<nav>
<ul>
- <li><a href="{link controller='TemplateList'}{/link}" class="button"><span class="icon icon16 icon-list"></span> <span>{lang}wcf.acp.menu.link.template.list{/lang}</span></a></li>
+ <li><a href="{link controller='TemplateList'}{if $action == 'edit'}templateGroupID={@$template->templateGroupID}{/if}{/link}" class="button"><span class="icon icon16 icon-list"></span> <span>{lang}wcf.acp.menu.link.template.list{/lang}</span></a></li>
{event name='contentNavigationButtons'}
</ul>
</dd>
</dl>
- <dl{if $errorField == 'templateName'} class="formError"{/if}>
+ <dl{if $errorField == 'tplName'} class="formError"{/if}>
<dt><label for="tplName">{lang}wcf.global.name{/lang}</label></dt>
<dd>
<input type="text" id="tplName" name="tplName" value="{$tplName}" required="required" class="long" />
- {if $errorField == 'templateName'}
+ {if $errorField == 'tplName'}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
{event name='rowButtons'}
</td>
<td class="columnID">{@$template->templateID}</td>
- <td class="columnTitle columnTemplateName">{if $template->templateGroupID}<a href="{link controller='TemplateEdit' id=$template->templateID}{/link}">{$template->templateName}</a>{else}{$template->templateName}{/if}</td>
+ <td class="columnTitle columnTemplateName">{if $template->packageDir}[{$template->getPackageAbbreviation()}] {/if}{if $template->templateGroupID}<a href="{link controller='TemplateEdit' id=$template->templateID}{/link}">{$template->templateName}</a>{else}{$template->templateName}{/if}</td>
<td class="columnDate columnLastModificationTime">{@$template->lastModificationTime|time}</td>
{event name='columns'}
throw new UserInputException('tplName');
}
- if (!preg_match('^/[a-z0-9_\-]+$/i', $this->tplName)) {
+ if (!preg_match('/^[a-z0-9_\-]+$/i', $this->tplName)) {
throw new UserInputException('tplName', 'notValid');
}
parent::save();
$this->objectAction = new TemplateAction(array(), 'create', array('data' => array(
- 'templateName' => $this->templateName,
+ 'templateName' => $this->tplName,
'packageID' => $this->packageID,
- 'templateGroupID' => ($this->templateGroupID)
+ 'templateGroupID' => $this->templateGroupID
), 'source' => $this->templateSource));
$this->objectAction->executeAction();
$this->saved();
--- /dev/null
+<?php
+namespace wcf\acp\form;
+use wcf\data\template\group\TemplateGroup;
+use wcf\data\template\group\TemplateGroupAction;
+use wcf\data\template\group\TemplateGroupList;
+use wcf\data\template\Template;
+use wcf\data\template\TemplateAction;
+use wcf\form\AbstractForm;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * Shows the form for adding new templates.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2013 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage acp.form
+ * @category Community Framework
+ */
+class TemplateEditForm extends TemplateAddForm {
+ /**
+ * @see wcf\page\AbstractPage::$activeMenuItem
+ */
+ public $activeMenuItem = 'wcf.acp.menu.link.template';
+
+ /**
+ * template id
+ * @var integer
+ */
+ public $templateID = 0;
+
+ /**
+ * template object
+ * @var wcf\data\template\Template
+ */
+ public $template = null;
+
+ /**
+ * @see wcf\page\IPage::readParameters()
+ */
+ public function readParameters() {
+ parent::readParameters();
+
+ if (isset($_REQUEST['id'])) $this->templateID = intval($_REQUEST['id']);
+ $this->template = new Template($this->templateID);
+ if (!$this->template->templateID || !$this->template->templateGroupID) {
+ throw new IllegalLinkException();
+ }
+ $this->packageID = $this->template->packageID;
+ }
+
+ /**
+ * @see wcf\acp\form\TemplateAddForm::validateName()
+ */
+ protected function validateName() {
+ if ($this->tplName != $this->template->templateName) {
+ parent::validateName();
+ }
+ }
+
+ /**
+ * @see wcf\acp\form\TemplateAddForm::validateName()
+ */
+ protected function validateGroup() {
+ if ($this->templateGroupID != $this->template->templateGroupID) {
+ parent::validateName();
+ }
+ }
+
+ /**
+ * @see wcf\form\IForm::save()
+ */
+ public function save() {
+ AbstractForm::save();
+
+ $this->objectAction = new TemplateAction(array($this->template), 'update', array('data' => array(
+ 'templateName' => $this->tplName,
+ 'templateGroupID' => $this->templateGroupID,
+ 'lastModificationTime' => TIME_NOW
+ ), 'source' => $this->templateSource));
+ $this->objectAction->executeAction();
+ $this->saved();
+
+ // show success
+ WCF::getTPL()->assign(array(
+ 'success' => true
+ ));
+ }
+
+ /**
+ * @see wcf\page\IPage::readData()
+ */
+ public function readData() {
+ parent::readData();
+
+ if (!count($_POST)) {
+ $this->tplName = $this->template->templateName;
+ $this->templateSource = $this->template->getSource();
+ $this->templateGroupID = $this->template->templateGroupID;
+ }
+ }
+
+ /**
+ * @see wcf\page\IPage::assignVariables()
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign(array(
+ 'action' => 'edit',
+ 'templateID' => $this->templateID,
+ 'template' => $this->template
+ ));
+ }
+}
use wcf\form\AbstractForm;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
+use wcf\util\FileUtil;
use wcf\util\StringUtil;
/**
parent::readFormParameters();
if (isset($_POST['templateGroupName'])) $this->templateGroupName = StringUtil::trim($_POST['templateGroupName']);
- if (isset($_POST['templateGroupFolderName'])) $this->templateGroupFolderName = StringUtil::trim($_POST['templateGroupFolderName']);
+ if (!empty($_POST['templateGroupFolderName'])) {
+ $this->templateGroupFolderName = StringUtil::trim($_POST['templateGroupFolderName']);
+ if ($this->templateGroupFolderName) $this->templateGroupFolderName = FileUtil::addTrailingSlash($this->templateGroupFolderName);
+ }
if (isset($_POST['parentTemplateGroupID'])) $this->parentTemplateGroupID = intval($_POST['parentTemplateGroupID']);
}
throw new UserInputException('templateGroupName');
}
+ if (!preg_match('/^[a-z0-9_\-]+\/$/i', $this->templateGroupName)) {
+ throw new UserInputException('templateGroupName', 'notValid');
+ }
+
$sql = "SELECT COUNT(*) AS count
FROM wcf".WCF_N."_template_group
WHERE templateGroupName = ?";
<?php
namespace wcf\data\template;
+use wcf\data\package\Package;
use wcf\data\DatabaseObject;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
*/
public function __construct($id, $row = null, DatabaseObject $object = null) {
if ($id !== null) {
- $sql = "SELECT template.*, template_group.templateGroupFolderName, package.packageDir
+ $sql = "SELECT template.*, template_group.templateGroupFolderName,
+ package.package, package.packageDir
FROM wcf".WCF_N."_template template
LEFT JOIN wcf".WCF_N."_template_group template_group
ON (template_group.templateGroupID = template.templateGroupID)
return @file_get_contents($this->getPath());
}
+ /**
+ * Returns the abbreviation of the package name.
+ *
+ * @return string
+ */
+ public function getPackageAbbreviation() {
+ return Package::getAbbreviation($this->package);
+ }
+
/**
* Searches in templates.
*
* @see wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate
*/
protected $permissionsUpdate = array('admin.template.canManageTemplate');
+
+ /**
+ * @see wcf\data\AbstractDatabaseObjectAction::create()
+ */
+ public function create() {
+ $template = parent::create();
+
+ if (isset($this->parameters['source'])) {
+ $editor = new TemplateEditor($template);
+ $editor->setSource($this->parameters['source']);
+ }
+
+ return $template;
+ }
+
+ /**
+ * @see wcf\data\AbstractDatabaseObjectAction::update()
+ */
+ public function update() {
+ parent::update();
+
+ foreach ($this->objects as $template) {
+ // rename file
+ $templateName = (isset($this->parameters['data']['templateName']) ? $this->parameters['data']['templateName'] : $template->templateName);
+ $templateGroupID = (isset($this->parameters['data']['templateGroupID']) ? $this->parameters['data']['templateGroupID'] : $template->templateGroupID);
+ if ($templateName != $template->templateName || $templateGroupID != $template->templateGroupID) {
+ $template->rename($templateName, $templateGroupID);
+ }
+
+ // update source
+ if (isset($this->parameters['source'])) {
+ $template->setSource($this->parameters['source']);
+ }
+ }
+ }
}
public static function create(array $parameters = array()) {
// obtain default values
if (!isset($parameters['packageID'])) $parameters['packageID'] = PACKAGE_ID;
+ if (!isset($parameters['lastModificationTime'])) $parameters['lastModificationTime'] = TIME_NOW;
- parent::create($parameters);
+ return parent::create($parameters);
}
/**
* @param string $name
* @param integer $templateGroupID
*/
- protected function rename($name, $templateGroupID = 0) {
+ public function rename($name, $templateGroupID = 0) {
// get current path
$currentPath = $this->getPath();
// get new path
- $this->data['templateGroupFolderName'] = '';
- if ($templateGroupID != 0) {
+ if ($templateGroupID != $this->templateGroupID) {
// get folder name
$sql = "SELECT templateGroupFolderName
FROM wcf".WCF_N."_template_group
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($templateGroupID));
$row = $statement->fetchArray();
- $this->data['templateGroupFolderName'] = $row['templateGroupFolderName'];
+ $this->object->data['templateGroupFolderName'] = $row['templateGroupFolderName'];
}
// delete compiled templates
$this->deleteCompiledFiles();
// rename
- $this->data['templateName'] = $name;
+ $this->object->data['templateName'] = $name;
$newPath = $this->getPath();
// move file
* @see wcf\data\DatabaseObjectList::$className
*/
public $className = 'wcf\data\template\Template';
+
+ /**
+ * Creates a new TemplateList object.
+ */
+ public function __construct() {
+ parent::__construct();
+
+ $this->sqlSelects = 'package.package, package.packageDir';
+ $this->sqlJoins = " LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = template.packageID)";
+ }
}