Automatically convert article links
authorMatthias Schmidt <gravatronics@live.com>
Sun, 12 Mar 2017 13:36:49 +0000 (14:36 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 12 Mar 2017 13:36:49 +0000 (14:36 +0100)
See #2186

com.woltlab.wcf/eventListener.xml
wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php [new file with mode: 0644]

index 1fa97d58ca00d45af02b87394aeed266764e7119..f09ad68d932941f07eb560a83a170e7a41bd45c4 100644 (file)
                        <inherit>1</inherit>
                        <listenerclassname>wcf\system\event\listener\SessionAccessLogListener</listenerclassname>
                </eventlistener>
+               
+               <eventlistener name="articleLinkhtmlInputNodeProcessor">
+                       <eventclassname>wcf\system\html\input\node\HtmlInputNodeProcessor</eventclassname>
+                       <eventname>afterProcess</eventname>
+                       <listenerclassname>wcf\system\event\listener\ArticleLinkHtmlInputNodeProcessorListener</listenerclassname>
+               </eventlistener>
        </import>
        
        <delete>
diff --git a/wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php b/wcfsetup/install/files/lib/system/event/listener/ArticleLinkHtmlInputNodeProcessorListener.class.php
new file mode 100644 (file)
index 0000000..cd68759
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace wcf\system\event\listener;
+use wcf\data\article\AccessibleArticleList;
+use wcf\system\html\input\node\HtmlInputNodeProcessor;
+use wcf\system\request\LinkHandler;
+
+/**
+ * Parses URLs of articles.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Event\Listener
+ * @since      3.1
+ */
+class ArticleLinkHtmlInputNodeProcessorListener extends AbstractHtmlInputNodeProcessorListener {
+       /**
+        * @inheritDoc
+        */
+       public function execute($eventObj, $className, $eventName, array &$parameters) {
+               /** @var HtmlInputNodeProcessor $eventObj */
+               
+               $regex = $this->getRegexFromLink(LinkHandler::getInstance()->getLink('Article'));
+               $articleIDs = $this->getObjectIDs($eventObj, $regex);
+               
+               if (!empty($articleIDs)) {
+                       $articleList = new AccessibleArticleList();
+                       $articleList->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]);
+                       $articleList->readObjects();
+                       
+                       $this->setObjectTitles($eventObj, $regex, $articleList->getObjects());
+               }
+       }
+}