Skip to content

Commit

Permalink
1.4.0 update
Browse files Browse the repository at this point in the history
WSC 3.0, WSF 5.0 compatibility bugfixes, removed image checks
  • Loading branch information
oliverschloebe committed May 28, 2017
1 parent 3e35dec commit e177c3f
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 102 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Anti-Spam: Link Restriction Plugin for WoltLab Burning Board 4.x
Anti-Spam: Link Restriction Plugin for WoltLab Burning Board 4.x and Woltlab Suite 3.0
====================

**This plugin adds a feature that disables new posts, if they come from a user who has only a few submissions and contains external links. Thus, they must be tested first by a moderator. This will act against link spam, where users or spambots to register in the forum, only to publish links to external content and benefit from the links in search engines. Looks up to only external links.**

The options of the plugin can be found in the ACP under "System"-> "Options" -> "Forum" -> "Posts" -> "Post creation".
The options of the plugin can be found in the ACP under "Configuration" -> "Forum" -> "Posts" -> "Post creation".

In addition, the function for all user groups can be turned off. The user group option can be found under "General Rights" -> "Forum" -> "Write permissions".
In addition, the plugin can be turned off for each user group. The user group option can be found under "Users" -> "List User Groups" -> "General Permissions" -> "Forum".

## Readme/Screenshots

See the [Plugin page on woltlab.com](http://www.woltlab.com/pluginstore/index.php/File/1972-Anti-Spam-Link-restriction/).
See the [Plugin page on woltlab.com](https://pluginstore.woltlab.com/file/1972-anti-spam-link-restriction/).

## Bugs/Suggestions

Expand Down
Binary file modified files.tar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,99 +9,90 @@
* 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-2015 Oliver Schlöbe
* @copyright 2001-2009 WoltLab GmbH, 2014-2017 Oliver Schlöbe
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.event.listener
* @category Community Framework
* @package WoltLabSuite\Forum\System\Event\Listener
* @since 5.0
*/
class ThreadAddFormAntiURLSpamListener implements IParameterizedEventListener {
private $illegalChars = '[^\x0-\x2C\x2E\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+';
private $sourceCodeRegEx = null;

/**
* holds the event object on execution
*
* @var object
*/
protected $obj = null;

/**
* post/thread message
*
* @var string
*/
public $text = '';

/**
* external url count in text
*
* @var integer
*/
protected $urlCount = 0;

/**
* image count in text
*
* @var integer
*/
protected $imgCount = 0;


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


/**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute()
*/
public function execute($eventObj, $className, $eventName, array &$parameters) {
$actionName = $eventObj->getActionName();
$parameters = $eventObj->getParameters();

switch ($actionName) {
case 'triggerPublication':
case 'update':
$objects = $eventObj->getObjects();
if (empty($objects[0])) {
return;
}

$data = $objects[0];

// check all disablers
if ($data->isDisabled || !POST_LINKRESTRICTION_ENABLE
|| WCF::getSession()->getPermission('user.board.canBypassLinkRestriction')
|| WCF::getUser()->wbbPosts > POST_LINKRESTRICTION_MIN_POSTS) {
return;
}

if (isset($parameters['data']['message']) && !empty($parameters['data']['message'])) {
$message = $parameters['data']['message'];
} else {
$message = $data->getMessage();
}

$this->text = $this->parse($message);

if (($this->urlCount > POST_LINKRESTRICTION_MAX_URLS)
|| (POST_LINKRESTRICTION_ENABLE_IMAGE_RESTRICTION && $this->imgCount > POST_LINKRESTRICTION_MAX_IMAGES)) {
$eventObj->disable();
}
break;
|| WCF::getSession()->getPermission('user.board.canBypassLinkRestriction')
|| WCF::getUser()->wbbPosts >= POST_LINKRESTRICTION_MIN_POSTS) {
return;
}

if (isset($parameters['data']['message']) && !empty($parameters['data']['message'])) {
$message = $parameters['data']['message'];
} else {
$message = $data->getMessage();
}

$this->text = $this->parse($message);

if (($this->urlCount > POST_LINKRESTRICTION_MAX_URLS)) {
$eventObj->disable();
}
break;
}
}

/**
* Slightly modified parse method
*
* @see URLParser::parse()
*/
public function parse($text) {
$this->text = $text;

// define pattern
$urlPattern = '~(?<!\B|"|\'|=|/|\]|,|\?)
(?: # hostname
Expand All @@ -110,9 +101,9 @@ public function parse($text) {
www\.(?:'.$this->illegalChars.'\.)+
(?:[a-z]{2,4}(?=\b))
)
(?::\d+)? # port
(?:
/
[^!.,?;"\'<>()\[\]{}\s]*
Expand All @@ -121,39 +112,29 @@ public function parse($text) {
)*
)?
~ix';

// add url tags
$this->text = preg_replace($urlPattern, '[url]\\0[/url]', $this->text);

// search in text w/o code bbcodes for urls
preg_match_all('~\[url(.*)\](.*)\[\/url\]~isU', $this->text, $matches, PREG_SET_ORDER);

// search for urls in text
preg_match_all('~\<a href(.*)\>(.*)\<\/a\>~isU', $this->text, $matches, PREG_SET_ORDER);
$count = 0;
foreach ($matches as $match) {
$match1 = trim($match[1], '"=\'');
$match2 = trim($match[2], '"=\'');

if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match1) &&
!$this->isInternalURLCustom($match1)) {
$count++;
}

if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match2) &&
!$this->isInternalURLCustom($match2)) {
$count++;
}
!$this->isInternalURLCustom($match1)) {
$count++;
}
if (!\wcf\system\application\ApplicationHandler::getInstance()->isInternalURL($match2) &&
!$this->isInternalURLCustom($match2)) {
$count++;
}
}
$this->urlCount = $count;

if (POST_LINKRESTRICTION_ENABLE_IMAGE_RESTRICTION) {
// search in text for img bbcodes
// quite primitve at the moment
preg_match_all('~\[img(.*)\](.*)(\[\/img\])?~isU', $this->text, $matches, PREG_SET_ORDER);
$this->imgCount = count($matches);
}


return $this->text;
}

/**
* Additional custom URL checks
*/
Expand All @@ -171,7 +152,7 @@ private function isInternalURLCustom($url) {

return false;
}

/**
* Get custom URLs from options
*/
Expand Down
6 changes: 1 addition & 5 deletions languages/de-informal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
<item name="wcf.acp.option.post_linkrestriction_enable.description"><![CDATA[Aktiviert die Linkbeschränkung. Diese deaktiviert neue Beiträge von Benutzern mit wenigen Beiträgen, die externe Links enthalten, sodass diese zuerst von einem Moderator geprüft werden können.]]></item>
<item name="wcf.acp.option.post_linkrestriction_min_posts"><![CDATA[Mindestbeitragszahl]]></item>
<item name="wcf.acp.option.post_linkrestriction_min_posts.description"><![CDATA[Hat der Benutzer mehr Beiträge als die hier angegeben Zahl, greift die Linkbeschränkung nicht mehr.]]></item>
<item name="wcf.acp.option.post_linkrestriction_enable_image_restriction"><![CDATA[Beschränkung auf Bilder ausweiten]]></item>
<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_custom_urls.description"><![CDATA[Eine komma-separierte Liste von zusätzlichen Domains, die den Beitrag nicht deaktivieren.]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards"><![CDATA[Ausgeschlossene Foren]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards.description"><![CDATA[In den hier ausgewählten Foren greift die Linkbeschränkung nicht. Dies ist beispielsweise für Vorstellungsforen nützlich.]]></item>
</category>
Expand Down
6 changes: 1 addition & 5 deletions languages/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
<item name="wcf.acp.option.post_linkrestriction_enable.description"><![CDATA[Aktiviert die Linkbeschränkung. Diese deaktiviert neue Beiträge von Benutzern mit wenigen Beiträgen, die externe Links enthalten, sodass diese zuerst von einem Moderator geprüft werden können.]]></item>
<item name="wcf.acp.option.post_linkrestriction_min_posts"><![CDATA[Mindestbeitragszahl]]></item>
<item name="wcf.acp.option.post_linkrestriction_min_posts.description"><![CDATA[Hat der Benutzer mehr Beiträge als die hier angegeben Zahl, greift die Linkbeschränkung nicht mehr.]]></item>
<item name="wcf.acp.option.post_linkrestriction_enable_image_restriction"><![CDATA[Beschränkung auf Bilder ausweiten]]></item>
<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_custom_urls.description"><![CDATA[Eine komma-separierte Liste von zusätzlichen Domains, die den Beitrag nicht deaktivieren.]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards"><![CDATA[Ausgeschlossene Foren]]></item>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards.description"><![CDATA[In den hier ausgewählten Foren greift die Linkbeschränkung nicht. Dies ist beispielsweise für Vorstellungsforen nützlich.]]></item>
</category>
Expand Down
4 changes: 0 additions & 4 deletions languages/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
<item name="wcf.acp.option.post_linkrestriction_enable.description"><![CDATA[Enables the link restriction. This function disables posts by users with too few posts if they contain external links. This allows a moderator pre-check.]]></item>
<item name="wcf.acp.option.post_linkrestriction_min_posts"><![CDATA[Minimum post count]]></item>
<item name="wcf.acp.option.post_linkrestriction_min_posts.description"><![CDATA[If the user has more post than this value, the link restriction will become inactive.]]></item>
<item name="wcf.acp.option.post_linkrestriction_enable_image_restriction"><![CDATA[Enhance restriction to images]]></item>
<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>
<item name="wcf.acp.option.post_linkrestriction_excluded_boards.description"><![CDATA[The link restriction is disabled in the selected boards. This is particularly useful for presentational boards.]]></item>
</category>
Expand Down
13 changes: 8 additions & 5 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
<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.2.0</version>
<date>2015-04-26</date>
<version>1.4.0</version>
<date>2017-05-28</date>
<license>LGPL</license>
</packageinformation>

<authorinformation>
<author><![CDATA[Oliver Schlöbe]]></author>
<authorurl><![CDATA[http://www.schloebe.de]]></authorurl>
<authorurl><![CDATA[https://www.schloebe.de]]></authorurl>
</authorinformation>

<requiredpackages>
<requiredpackage minversion="2.1.0">com.woltlab.wcf</requiredpackage>
<requiredpackage minversion="4.1.0">com.woltlab.wbb</requiredpackage>
<requiredpackage minversion="3.0.0">com.woltlab.wcf</requiredpackage>
</requiredpackages>

<excludedpackages>
<excludedpackage version="3.1.0 Alpha 1">com.woltlab.wcf</excludedpackage>
</excludedpackages>

<instructions type="install">
<instruction type="file" application="wbb">files.tar</instruction>
Expand Down
4 changes: 2 additions & 2 deletions xml/eventlistener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<!-- user -->
<eventlistener>
<eventclassname><![CDATA[wbb\data\post\ThreadAction]]></eventclassname>
<eventname>initializeAction</eventname>
<eventname>finalizeAction</eventname>
<listenerclassname><![CDATA[wbb\system\event\listener\ThreadAddFormAntiURLSpamListener]]></listenerclassname>
<environment>user</environment>
<inherit>1</inherit>
</eventlistener>
<eventlistener>
<eventclassname><![CDATA[wbb\data\post\PostAction]]></eventclassname>
<eventname>initializeAction</eventname>
<eventname>finalizeAction</eventname>
<listenerclassname><![CDATA[wbb\system\event\listener\ThreadAddFormAntiURLSpamListener]]></listenerclassname>
<environment>user</environment>
<inherit>1</inherit>
Expand Down
13 changes: 1 addition & 12 deletions 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_custom_urls,post_linkrestriction_max_urls,post_linkrestriction_enable_image_restriction</enableoptions>
<enableoptions>post_linkrestriction_min_posts,post_linkrestriction_custom_urls,post_linkrestriction_max_urls</enableoptions>
</option>
<option name="post_linkrestriction_min_posts">
<categoryname>board.post.add</categoryname>
Expand All @@ -23,17 +23,6 @@
<optiontype>text</optiontype>
<defaultvalue/>
</option>
<option name="post_linkrestriction_enable_image_restriction">
<categoryname>board.post.add</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
<enableoptions>post_linkrestriction_max_images</enableoptions>
</option>
<option name="post_linkrestriction_max_images">
<categoryname>board.post.add</categoryname>
<optiontype>integer</optiontype>
<defaultvalue>0</defaultvalue>
</option>
</options>
</import>
</data>

0 comments on commit e177c3f

Please sign in to comment.