Skip to content

Commit

Permalink
Implements #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Schlöbe committed Jan 23, 2015
1 parent 1cfd901 commit b972bcf
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
Binary file modified files.tar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
use wcf\system\event\IEventListener;
use wcf\util;
use wcf\system\WCF;
use wcf\system\Regex;

/**
* Disables posts by board newcomers if their posts contains external links
* Disables posts by board newcomers if their posts contain external links
*
* @author Oliver Schlöbe, Marcel Werk, Oliver Kliebisch
* @copyright 2001-2009 WoltLab GmbH, 2014 Oliver Schlöbe
* @copyright 2001-2009 WoltLab GmbH, 2014-2015 Oliver Schlöbe
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.event.listener
Expand Down Expand Up @@ -46,6 +47,13 @@ class ThreadAddFormAntiURLSpamListener implements IEventListener {
*/
protected $imgCount = 0;

/**
* list of custom URLs
* @var array<string>
*/
protected $customUrls = array();


/**
* @see \wcf\system\event\IEventListener::execute()
*/
Expand All @@ -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')
Expand Down Expand Up @@ -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++;
}
}
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions languages/de-informal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<item name="wcf.acp.option.post_linkrestriction_enable_image_restriction.description"><![CDATA[Ist diese Option aktiviert, werden auch Bilder in den Beiträgen berücksichtigt. Dies betrifft nur den img-BBCode.]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_urls"><![CDATA[Maximale Linkanzahl]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_urls.description"><![CDATA[Maximale Zahl an externen Links, die ein Beitrag enthalten darf, bevor die Linkbeschränkung greift.]]></item>
<item name="wcf.acp.option.post_linkrestriction_custom_urls"><![CDATA[Zusätzliche interne URLs]]></item>
<item name="wcf.acp.option.post_linkrestriction_custom_urls.description"><![CDATA[Eine komma-separierte Liste von zusätzlichen Domains, die beim Prüfen den Beitrag nicht deaktivieren.]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_images"><![CDATA[Maximale Bilderanzahl]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_images.description"><![CDATA[Maximale Zahl an Bildern, die in ein Beitrag enthalten darf, bevor die Linkbeschränkung greift.]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards"><![CDATA[Ausgeschlossene Foren]]></item>
Expand Down
2 changes: 2 additions & 0 deletions languages/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<item name="wcf.acp.option.post_linkrestriction_enable_image_restriction.description"><![CDATA[Ist diese Option aktiviert, werden auch Bilder in den Beiträgen berücksichtigt. Dies betrifft nur den img-BBCode.]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_urls"><![CDATA[Maximale Linkanzahl]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_urls.description"><![CDATA[Maximale Zahl an externen Links, die ein Beitrag enthalten darf, bevor die Linkbeschränkung greift.]]></item>
<item name="wcf.acp.option.post_linkrestriction_custom_urls"><![CDATA[Zusätzliche interne URLs]]></item>
<item name="wcf.acp.option.post_linkrestriction_custom_urls.description"><![CDATA[Eine komma-separierte Liste von zusätzlichen Domains, die beim Prüfen den Beitrag nicht deaktivieren.]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_images"><![CDATA[Maximale Bilderanzahl]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_images.description"><![CDATA[Maximale Zahl an Bildern, die in ein Beitrag enthalten darf, bevor die Linkbeschränkung greift.]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards"><![CDATA[Ausgeschlossene Foren]]></item>
Expand Down
2 changes: 2 additions & 0 deletions languages/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<item name="wcf.acp.option.post_linkrestriction_enable_image_restriction.description"><![CDATA[If this is activated, img bbcodes are also considered in posts.]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_urls"><![CDATA[Maximum link count]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_urls.description"><![CDATA[The max number of links in a post before the link restriction activates.]]></item>
<item name="wcf.acp.option.post_linkrestriction_custom_urls"><![CDATA[Custom internal URLs]]></item>
<item name="wcf.acp.option.post_linkrestriction_custom_urls.description"><![CDATA[A comma-separated list of domains to be considered internal when checking.]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_images"><![CDATA[Maximum image count]]></item>
<item name="wcf.acp.option.post_linkrestriction_max_images.description"><![CDATA[The max number of images in a post before the link restriction activates.]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards"><![CDATA[Excluded boards]]></item>
Expand Down
4 changes: 2 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<packagedescription>Disables user posts if they have a too low post counter and the post contains external URIs.</packagedescription>
<packagedescription language="de"><![CDATA[Deaktiviert Beiträge von Benutzern mit zu wenig Beiträgen, falls der Beitrag externe URLs enthält.]]></packagedescription>
<packagedescription language="de-informal"><![CDATA[Deaktiviert Beiträge von Benutzern mit zu wenig Beiträgen, falls der externe Beitrag URLs enthält.]]></packagedescription>
<version>1.1.3</version>
<date>2014-12-04</date>
<version>1.1.4</version>
<date>2015-01-23</date>
<license>LGPL</license>
</packageinformation>

Expand Down
7 changes: 6 additions & 1 deletion xml/options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<categoryname>board.post.add</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>1</defaultvalue>
<enableoptions>post_linkrestriction_min_posts,post_linkrestriction_max_urls,post_linkrestriction_enable_image_restriction</enableoptions>
<enableoptions>post_linkrestriction_min_posts,post_linkrestriction_custom_urls,post_linkrestriction_max_urls,post_linkrestriction_enable_image_restriction</enableoptions>
</option>
<option name="post_linkrestriction_min_posts">
<categoryname>board.post.add</categoryname>
Expand All @@ -18,6 +18,11 @@
<optiontype>integer</optiontype>
<defaultvalue>0</defaultvalue>
</option>
<option name="post_linkrestriction_custom_urls">
<categoryname>board.post.add</categoryname>
<optiontype>text</optiontype>
<defaultvalue/>
</option>
<option name="post_linkrestriction_enable_image_restriction">
<categoryname>board.post.add</categoryname>
<optiontype>boolean</optiontype>
Expand Down

0 comments on commit b972bcf

Please sign in to comment.