From b972bcf6e935d480d7a8df0ff1f55df4fc4d14e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Schl=C3=B6be?= Date: Fri, 23 Jan 2015 20:55:26 +0100 Subject: [PATCH] Implements #3 --- files.tar | Bin 7680 -> 8704 bytes ...ThreadAddFormAntiURLSpamListener.class.php | 55 ++++++++++++++++-- languages/de-informal.xml | 2 + languages/de.xml | 2 + languages/en.xml | 2 + package.xml | 4 +- xml/options.xml | 7 ++- 7 files changed, 65 insertions(+), 7 deletions(-) diff --git a/files.tar b/files.tar index 822678ea1582280367c259ee9fdb3b64bf5b965e..f9a7ee96dcae896f1eaad25d2a8827896f7e3e08 100644 GIT binary patch delta 1270 zcmaJ=%Wl(95RFv|a!`R*P!Mb;Q4~8>O6;UbrM6C~3Ie1eL?5iGR>rgZG zbWO%%`0Mu1>kmt;>(a%xOJDkoM84_aoJ}!t@Oj=YLAi`=@hJSeaQJ)vgVe{e+QNcB z0vopNGB?0(W9Y%^66<}kLxR;kG8q9U_AOovS71;}apYCtBgc>enAj_gbqMPxpb`C! z*c0nH8G#jef?*`VC&wV3Rpp?|SV+}%W2IKBD4Z8r=BMkZU;v1=6+4o#_4$9fos0b15d zjtGk*A6OI<0bG{PX7YX12yf|yKcr=j=}}RKSqx_yJtu5T912c^CJREY#D6qGrpJj+ zl|fDJqer<#k!NxedVx(;rK(h6Fgtgzzqz-w`})-(7boF*B%6Z{zBnxwI;(xOdvjDIsaE5`R9eV^&7?&v&{D46i z5lVa}s<}fmXI=qh+?ib50_lb9G>w+az>Qll6a{}EcvryA9bAxEUA1_ApsuetpSrAq r7F}>ev!PfL2uU2Y% delta 198 zcmZp0X|S2lEo5R~U}|7)Y{Xz-U}kD+&Y)mAS&%VhGb3XcBa)n * @package com.woltlab.wcf * @subpackage system.event.listener @@ -46,6 +47,13 @@ class ThreadAddFormAntiURLSpamListener implements IEventListener { */ protected $imgCount = 0; + /** + * list of custom URLs + * @var array + */ + protected $customUrls = array(); + + /** * @see \wcf\system\event\IEventListener::execute() */ @@ -62,7 +70,7 @@ public function execute($obj, $className, $eventName) { } $data = $objects[0]; - + // check all disablers if ($data->isDisabled || !POST_LINKRESTRICTION_ENABLE || WCF::getSession()->getPermission('user.board.canBypassLinkRestriction') @@ -124,7 +132,9 @@ public function parse($text) { $match1 = trim($match[1], '"=\''); $match2 = trim($match[2], '"=\''); if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match1) && - !\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match2)) { + !$this->isInternalURLCustom($match1) && + !\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match2) && + !$this->isInternalURLCustom($match2)) { $count++; } } @@ -139,4 +149,41 @@ public function parse($text) { return $this->text; } + + /** + * Additional custom URL checks + */ + private function isInternalURLCustom($url) { + $this->customUrls = $this->getCustomURLS(); + $protocolRegex = new Regex('^https(?=://)'); + + if( count($this->customUrls) > 0 ) { + foreach ($this->customUrls as $pageURL) { + if (stripos($protocolRegex->replace($url, 'http'), $pageURL) === 0) { + return true; + } + } + } + + return false; + } + + /** + * Get custom URLs from options + */ + private function getCustomURLS() { + $customURLs = explode(',', POST_LINKRESTRICTION_CUSTOM_URLS); + $customURLs = array_map(array($this, 'addHttpToCustomURLs'), $customURLs); + return $customURLs; + } + + /** + * Auto add http scheme if it's not present + */ + function addHttpToCustomURLs($url) { + if (!empty($url) && $url!='' && !preg_match("~^(?:f|ht)tps?://~i", $url)) { + $url = "http://".$url; + } + return $url; + } } \ No newline at end of file diff --git a/languages/de-informal.xml b/languages/de-informal.xml index ff3e742..ee77662 100644 --- a/languages/de-informal.xml +++ b/languages/de-informal.xml @@ -13,6 +13,8 @@ + + diff --git a/languages/de.xml b/languages/de.xml index 47fc3aa..4214502 100644 --- a/languages/de.xml +++ b/languages/de.xml @@ -13,6 +13,8 @@ + + diff --git a/languages/en.xml b/languages/en.xml index ed35a29..866e1e5 100644 --- a/languages/en.xml +++ b/languages/en.xml @@ -13,6 +13,8 @@ + + diff --git a/package.xml b/package.xml index 5ae083f..bfec803 100644 --- a/package.xml +++ b/package.xml @@ -7,8 +7,8 @@ Disables user posts if they have a too low post counter and the post contains external URIs. - 1.1.3 - 2014-12-04 + 1.1.4 + 2015-01-23 LGPL diff --git a/xml/options.xml b/xml/options.xml index bfa6043..8185940 100644 --- a/xml/options.xml +++ b/xml/options.xml @@ -6,7 +6,7 @@ board.post.add boolean 1 - post_linkrestriction_min_posts,post_linkrestriction_max_urls,post_linkrestriction_enable_image_restriction + post_linkrestriction_min_posts,post_linkrestriction_custom_urls,post_linkrestriction_max_urls,post_linkrestriction_enable_image_restriction +