From ece28c2188aadfd1ecafecf686f422659a4e1a76 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 15 May 2016 13:04:55 +0200 Subject: [PATCH] Added `isBlockElement` for bbcodes --- com.woltlab.wcf/bbcode.xml | 19 +-- .../install/files/acp/templates/bbcodeAdd.tpl | 16 +-- .../lib/acp/form/BBCodeAddForm.class.php | 68 +++++----- .../lib/acp/form/BBCodeEditForm.class.php | 42 +++--- .../files/lib/data/bbcode/BBCode.class.php | 2 +- .../system/bbcode/HtmlBBCodeParser.class.php | 56 ++++++-- ...mlInputNodeWoltlabMetacodeMarker.class.php | 121 ++++++++++++++---- .../BBCodePackageInstallationPlugin.class.php | 64 +++++---- wcfsetup/install/lang/de.xml | 4 +- wcfsetup/install/lang/en.xml | 4 +- wcfsetup/setup/db/install.sql | 2 +- 11 files changed, 241 insertions(+), 157 deletions(-) diff --git a/com.woltlab.wcf/bbcode.xml b/com.woltlab.wcf/bbcode.xml index 302db0badc..5927a02661 100644 --- a/com.woltlab.wcf/bbcode.xml +++ b/com.woltlab.wcf/bbcode.xml @@ -4,36 +4,29 @@ b b - all^b i i - all^i span style="text-decoration: underline" span - all^u s s - all^s sub sub - all^sub sup sup - all^sup - none^img,b,i,u,s,sub,sup,color,size,font 1 @@ -86,6 +79,7 @@ 1 + 1 @@ -95,10 +89,10 @@ fa-quote-left wcf.bbcode.button.quote + 1 - none @@ -107,10 +101,10 @@ 1 fa-code wcf.bbcode.button.code + 1 - none 1 @@ -127,7 +121,6 @@ - none^img,b,i,u,s,sub,sup,color,size,font 1 @@ -138,16 +131,16 @@ - none^img,b,i,u,s,sub,sup,color,size,font,list,url,email,attach,tt ^(1|a|none|circle|square|disc|decimal|lower-roman|upper-roman|decimal-leading-zero|lower-greek|lower-latin|upper-latin|armenian|georgian)$ + 1 - all^table + 1 @@ -160,11 +153,11 @@ fa-eye-slash wcf.bbcode.button.spoiler + 1 kbd kbd - none 1 fa-terminal wcf.bbcode.button.inlineCode diff --git a/wcfsetup/install/files/acp/templates/bbcodeAdd.tpl b/wcfsetup/install/files/acp/templates/bbcodeAdd.tpl index 99bc608606..661e19c1e3 100644 --- a/wcfsetup/install/files/acp/templates/bbcodeAdd.tpl +++ b/wcfsetup/install/files/acp/templates/bbcodeAdd.tpl @@ -134,19 +134,11 @@ - -
+
+
- - {if $errorField == 'allowedChildren'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {lang}wcf.acp.bbcode.allowedChildren.error.{$errorType}{/lang} - {/if} - - {/if} + + {lang}wcf.acp.bbcode.isBlockElement.description{/lang}
diff --git a/wcfsetup/install/files/lib/acp/form/BBCodeAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BBCodeAddForm.class.php index f5c9585985..531ff8223d 100644 --- a/wcfsetup/install/files/lib/acp/form/BBCodeAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BBCodeAddForm.class.php @@ -15,7 +15,7 @@ use wcf\util\StringUtil; * Shows the bbcode add form. * * @author Tim Duesterhus - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage acp.form @@ -23,7 +23,7 @@ use wcf\util\StringUtil; */ class BBCodeAddForm extends AbstractForm { /** - * @see \wcf\page\AbstractPage::$activeMenuItem + * @inheritDoc */ public $activeMenuItem = 'wcf.acp.menu.link.bbcode.add'; @@ -37,7 +37,7 @@ class BBCodeAddForm extends AbstractForm { * list of attributes * @var object[] */ - public $attributes = array(); + public $attributes = []; /** * tag name @@ -69,6 +69,12 @@ class BBCodeAddForm extends AbstractForm { */ public $htmlOpen = ''; + /** + * true if bbcode is a block element + * @var boolean + */ + public $isBlockElement = false; + /** * true, if bbcode contains source code * @var boolean @@ -76,12 +82,12 @@ class BBCodeAddForm extends AbstractForm { public $isSourceCode = false; /** - * @see \wcf\page\AbstractPage::$neededPermissions + * @inheritDoc */ - public $neededPermissions = array('admin.content.bbcode.canManageBBCode'); + public $neededPermissions = ['admin.content.bbcode.canManageBBCode']; /** - * @see \wcf\page\AbstractPage::$templateName + * @inheritDoc */ public $templateName = 'bbcodeAdd'; @@ -98,7 +104,7 @@ class BBCodeAddForm extends AbstractForm { public $wysiwygIcon = ''; /** - * @see \wcf\page\IPage::readParameters() + * @inheritDoc */ public function readParameters() { parent::readParameters(); @@ -107,7 +113,7 @@ class BBCodeAddForm extends AbstractForm { } /** - * @see \wcf\form\IForm::readFormParameters() + * @inheritDoc */ public function readFormParameters() { parent::readFormParameters(); @@ -118,6 +124,7 @@ class BBCodeAddForm extends AbstractForm { if (isset($_POST['className'])) $this->className = StringUtil::trim($_POST['className']); if (isset($_POST['htmlClose'])) $this->htmlClose = StringUtil::trim($_POST['htmlClose']); if (isset($_POST['htmlOpen'])) $this->htmlOpen = StringUtil::trim($_POST['htmlOpen']); + if (isset($_POST['isBlockElement'])) $this->isBlockElement = true; if (isset($_POST['isSourceCode'])) $this->isSourceCode = true; if (isset($_POST['showButton'])) $this->showButton = true; if (isset($_POST['wysiwygIcon'])) $this->wysiwygIcon = StringUtil::trim($_POST['wysiwygIcon']); @@ -143,7 +150,7 @@ class BBCodeAddForm extends AbstractForm { } /** - * @see \wcf\form\IForm::validate() + * @inheritDoc */ public function validate() { parent::validate(); @@ -169,16 +176,6 @@ class BBCodeAddForm extends AbstractForm { throw new UserInputException('bbcodeTag', 'inUse'); } - // handle empty case first - if (empty($this->allowedChildren)) { - throw new UserInputException('allowedChildren'); - } - - // validate syntax of allowedChildren: Optional all|none^ followed by a comma-separated list of bbcodes - if (!empty($this->allowedChildren) && !Regex::compile('^(?:(?:all|none)\^)?(?:[a-zA-Z0-9]+,)*[a-zA-Z0-9]+$')->match($this->allowedChildren)) { - throw new UserInputException('allowedChildren', 'notValid'); - } - // validate class if (!empty($this->className) && !class_exists($this->className)) { throw new UserInputException('className', 'notFound'); @@ -215,34 +212,34 @@ class BBCodeAddForm extends AbstractForm { } /** - * @see \wcf\form\IForm::save() + * @inheritDoc */ public function save() { parent::save(); // save bbcode - $this->objectAction = new BBCodeAction(array(), 'create', array('data' => array_merge($this->additionalFields, array( - 'allowedChildren' => $this->allowedChildren, + $this->objectAction = new BBCodeAction([], 'create', ['data' => array_merge($this->additionalFields, [ 'bbcodeTag' => $this->bbcodeTag, 'buttonLabel' => $this->buttonLabel, 'className' => $this->className, 'htmlOpen' => $this->htmlOpen, 'htmlClose' => $this->htmlClose, + 'isBlockElement' => ($this->isBlockElement ? 1 : 0), 'isSourceCode' => ($this->isSourceCode ? 1 : 0), 'packageID' => 1, 'showButton' => ($this->showButton ? 1 : 0), 'wysiwygIcon' => $this->wysiwygIcon - )))); + ])]); $returnValues = $this->objectAction->executeAction(); foreach ($this->attributes as $attribute) { - $attributeAction = new BBCodeAttributeAction(array(), 'create', array('data' => array( + $attributeAction = new BBCodeAttributeAction([], 'create', ['data' => [ 'bbcodeID' => $returnValues['returnValues']->bbcodeID, 'attributeNo' => $attribute->attributeNo, 'attributeHtml' => $attribute->attributeHtml, 'validationPattern' => $attribute->validationPattern, 'required' => $attribute->required, 'useText' => $attribute->useText, - ))); + ]]); $attributeAction->executeAction(); } @@ -252,47 +249,46 @@ class BBCodeAddForm extends AbstractForm { // update button label $bbcodeEditor = new BBCodeEditor($returnValues['returnValues']); - $bbcodeEditor->update(array( + $bbcodeEditor->update([ 'buttonLabel' => 'wcf.bbcode.buttonLabel'.$bbcodeID - )); + ]); } $this->saved(); // reset values $this->bbcodeTag = $this->htmlOpen = $this->htmlClose = $this->className = $this->buttonLabel = $this->wysiwygIcon = ''; - $this->allowedChildren = 'all'; - $this->attributes = array(); - $this->isSourceCode = $this->showButton = false; + $this->attributes = []; + $this->isBlockElement = $this->isSourceCode = $this->showButton = false; I18nHandler::getInstance()->reset(); // show success - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'success' => true - )); + ]); } /** - * @see \wcf\page\IPage::assignVariables() + * @inheritDoc */ public function assignVariables() { parent::assignVariables(); I18nHandler::getInstance()->assignVariables(); - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'action' => 'add', - 'allowedChildren' => $this->allowedChildren, 'attributes' => $this->attributes, 'bbcodeTag' => $this->bbcodeTag, 'buttonLabel' => $this->buttonLabel, 'className' => $this->className, 'htmlOpen' => $this->htmlOpen, 'htmlClose' => $this->htmlClose, + 'isBlockElement' => $this->isBlockElement, 'isSourceCode' => $this->isSourceCode, 'showButton' => $this->showButton, 'wysiwygIcon' => $this->wysiwygIcon - )); + ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/BBCodeEditForm.class.php b/wcfsetup/install/files/lib/acp/form/BBCodeEditForm.class.php index 67b38a10e3..358f7b92ad 100644 --- a/wcfsetup/install/files/lib/acp/form/BBCodeEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BBCodeEditForm.class.php @@ -13,7 +13,7 @@ use wcf\system\WCF; * Shows the bbcode edit form. * * @author Tim Duesterhus - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage acp.form @@ -21,14 +21,14 @@ use wcf\system\WCF; */ class BBCodeEditForm extends BBCodeAddForm { /** - * @see \wcf\page\AbstractPage::$activeMenuItem + * @inheritDoc */ public $activeMenuItem = 'wcf.acp.menu.link.bbcode'; /** - * @see \wcf\page\AbstractPage::$neededPermissions + * @inheritDoc */ - public $neededPermissions = array('admin.content.bbcode.canManageBBCode'); + public $neededPermissions = ['admin.content.bbcode.canManageBBCode']; /** * bbcode id @@ -46,10 +46,10 @@ class BBCodeEditForm extends BBCodeAddForm { * list of native bbcodes * @var string[] */ - public static $nativeBBCodes = array('b', 'i', 'u', 's', 'sub', 'sup', 'list', 'align', 'color', 'size', 'font', 'url', 'img', 'email', 'table'); + public static $nativeBBCodes = ['b', 'i', 'u', 's', 'sub', 'sup', 'list', 'align', 'color', 'size', 'font', 'url', 'img', 'email', 'table']; /** - * @see \wcf\page\IPage::readParameters() + * @inheritDoc */ public function readParameters() { AbstractForm::readParameters(); @@ -66,7 +66,7 @@ class BBCodeEditForm extends BBCodeAddForm { } /** - * @see \wcf\acp\form\BBCodeAddForm::readButtonLabelFormParameter() + * @inheritDoc */ protected function readButtonLabelFormParameter() { if (!in_array($this->bbcode->bbcodeTag, self::$nativeBBCodes)) { @@ -75,7 +75,7 @@ class BBCodeEditForm extends BBCodeAddForm { } /** - * @see \wcf\form\IForm::save() + * @inheritDoc */ public function save() { AbstractForm::save(); @@ -92,47 +92,47 @@ class BBCodeEditForm extends BBCodeAddForm { } // update bbcode - $this->objectAction = new BBCodeAction(array($this->bbcodeID), 'update', array('data' => array_merge($this->additionalFields, array( - 'allowedChildren' => $this->allowedChildren, + $this->objectAction = new BBCodeAction([$this->bbcodeID], 'update', ['data' => array_merge($this->additionalFields, [ 'bbcodeTag' => $this->bbcodeTag, 'buttonLabel' => $this->buttonLabel, 'className' => $this->className, 'htmlClose' => $this->htmlClose, 'htmlOpen' => $this->htmlOpen, + 'isBlockElement' => ($this->isBlockElement ? 1 : 0), 'isSourceCode' => ($this->isSourceCode ? 1 : 0), 'showButton' => ($this->showButton ? 1 : 0), 'wysiwygIcon' => $this->wysiwygIcon - )))); + ])]); $this->objectAction->executeAction(); // clear existing attributes $sql = "DELETE FROM wcf".WCF_N."_bbcode_attribute WHERE bbcodeID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->bbcodeID)); + $statement->execute([$this->bbcodeID]); foreach ($this->attributes as $attribute) { - $attributeAction = new BBCodeAttributeAction(array(), 'create', array('data' => array( + $attributeAction = new BBCodeAttributeAction([], 'create', ['data' => [ 'bbcodeID' => $this->bbcodeID, 'attributeNo' => $attribute->attributeNo, 'attributeHtml' => $attribute->attributeHtml, 'validationPattern' => $attribute->validationPattern, 'required' => $attribute->required, 'useText' => $attribute->useText, - ))); + ]]); $attributeAction->executeAction(); } $this->saved(); // show success - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'success' => true - )); + ]); } /** - * @see \wcf\page\IPage::readData() + * @inheritDoc */ public function readData() { parent::readData(); @@ -145,7 +145,7 @@ class BBCodeEditForm extends BBCodeAddForm { $this->bbcodeTag = $this->bbcode->bbcodeTag; $this->htmlOpen = $this->bbcode->htmlOpen; $this->htmlClose = $this->bbcode->htmlClose; - $this->allowedChildren = $this->bbcode->allowedChildren; + $this->isBlockElement = $this->bbcode->isBlockElement; $this->isSourceCode = $this->bbcode->isSourceCode; $this->className = $this->bbcode->className; $this->showButton = $this->bbcode->showButton; @@ -154,17 +154,17 @@ class BBCodeEditForm extends BBCodeAddForm { } /** - * @see \wcf\page\IPage::assignVariables() + * @inheritDoc */ public function assignVariables() { parent::assignVariables(); I18nHandler::getInstance()->assignVariables(!empty($_POST)); - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'bbcode' => $this->bbcode, 'action' => 'edit', 'nativeBBCode' => (in_array($this->bbcode->bbcodeTag, self::$nativeBBCodes)) - )); + ]); } } diff --git a/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php b/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php index 55c5126916..1d34e2818d 100644 --- a/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php +++ b/wcfsetup/install/files/lib/data/bbcode/BBCode.class.php @@ -21,8 +21,8 @@ use wcf\system\WCF; * @property-read integer $packageID * @property-read string $htmlOpen * @property-read string $htmlClose - * @property-read string $allowedChildren * @property-read string $className + * @property-read integer $isBlockElement * @property-read string $wysiwygIcon * @property-read string $buttonLabel * @property-read integer $isSourceCode diff --git a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php index 73048ecbd5..a6f9b239c3 100644 --- a/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/HtmlBBCodeParser.class.php @@ -13,12 +13,13 @@ use wcf\util\StringUtil; * are