Skip to content

Commit

Permalink
1.1.3 update
Browse files Browse the repository at this point in the history
Fixed a bug that prevented anti-spam checking on edit
  • Loading branch information
Oliver Schlöbe committed Dec 4, 2014
1 parent 5aec531 commit 1cfd901
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
Binary file modified files.tar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,67 @@
class ThreadAddFormAntiURLSpamListener implements IEventListener {
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;

/**
* @see \wcf\system\event\IEventListener::execute()
*/
public function execute($obj, $className, $eventName) {
$controller = $_GET['controller'];
$returnValues = $obj->getReturnValues();
public function execute($obj, $className, $eventName) {
$actionName = $obj->getActionName();

$parameters = $obj->getParameters();

switch ($actionName) {
case 'triggerPublication':
case 'update':
$objects = $obj->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;
}

// get parsed text
$text = $this->parse($data->getMessage());


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)) {
$obj->disable();
Expand All @@ -89,7 +93,7 @@ public function execute($obj, $className, $eventName) {
*/
public function parse($text) {
$this->text = $text;

// define pattern
$urlPattern = '~(?<!\B|"|\'|=|/|\]|,|\?)
(?: # hostname
Expand All @@ -112,7 +116,7 @@ public function parse($text) {

// 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);
$count = 0;
Expand All @@ -125,14 +129,14 @@ public function parse($text) {
}
}
$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;
}
}
6 changes: 3 additions & 3 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.2</version>
<date>2014-11-03</date>
<version>1.1.3</version>
<date>2014-12-04</date>
<license>LGPL</license>
</packageinformation>

Expand All @@ -20,7 +20,7 @@
<requiredpackages>
<requiredpackage minversion="2.0.0">com.woltlab.wcf</requiredpackage>
<requiredpackage minversion="4.0.0">com.woltlab.wbb</requiredpackage>
</requiredpackages>
</requiredpackages>

<instructions type="install">
<instruction type="file" application="wbb">files.tar</instruction>
Expand Down
2 changes: 1 addition & 1 deletion xml/eventlistener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<environment>user</environment>
<inherit>1</inherit>
</eventlistener>
<!-- /user -->
<!-- /user -->
</import>
</data>

0 comments on commit 1cfd901

Please sign in to comment.