diff --git a/_define.php b/_define.php index cebd4d3..a9f69d2 100644 --- a/_define.php +++ b/_define.php @@ -1,32 +1,31 @@ registerModule( - "Duplicate filter", - "Antispam for duplicate comments on multiblog", - "Jean-Christian Denis, Pierre Van Glabeke", - '0.8', + 'Duplicate filter', + 'Antispam for duplicate comments on multiblog', + 'Jean-Christian Denis, Pierre Van Glabeke', + '0.9', [ - 'requires' => [['core', '2.19']], - 'permissions' => 'admin', - 'priority' => 200, - 'type' => 'plugin', - 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332947#p332947', - 'details' => 'http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/dcFilterDuplicate/master/dcstore.xml' + 'requires' => [['core', '2.24']], + 'permissions' => dcAuth::PERMISSION_ADMIN, + 'priority' => 200, + 'type' => 'plugin', + 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=332947#p332947', + 'details' => 'http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate', + 'repository' => 'https://raw.githubusercontent.com/JcDenis/dcFilterDuplicate/master/dcstore.xml', ] -); \ No newline at end of file +); diff --git a/_install.php b/_install.php index 009caf2..4dbdba2 100644 --- a/_install.php +++ b/_install.php @@ -1,63 +1,70 @@ getVersion($mod_id), - $core->plugins->moduleInfo($mod_id, 'version'), + dcCore::app()->getVersion($mod_id), + dcCore::app()->plugins->moduleInfo($mod_id, 'version'), '>=' )) { return null; } # Check Dotclear version $dc_min = $this->modules[$mod_id]['requires'][0][1]; - if (!method_exists('dcUtils', 'versionsCompare') + if (!method_exists('dcUtils', 'versionsCompare') || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false) ) { throw new Exception(sprintf( - '%s requires Dotclear %s', $mod_id, $dc_min + '%s requires Dotclear %s', + $mod_id, + $dc_min )); } # Set module settings - $core->blog->settings->addNamespace($mod_id); - foreach($mod_conf as $v) { - $core->blog->settings->{$mod_id}->put( - $v[0], $v[2], $v[3], $v[1], false, true + dcCore::app()->blog->settings->addNamespace($mod_id); + foreach ($mod_conf as $v) { + dcCore::app()->blog->settings->{$mod_id}->put( + $v[0], + $v[2], + $v[3], + $v[1], + false, + true ); } # Set module version - $core->setVersion( + dcCore::app()->setVersion( $mod_id, - $core->plugins->moduleInfo($mod_id, 'version') + dcCore::app()->plugins->moduleInfo($mod_id, 'version') ); + return true; -} -catch (Exception $e) { - $core->error->add($e->getMessage()); +} catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); + return false; -} \ No newline at end of file +} diff --git a/_prepend.php b/_prepend.php index ad820d7..2917fc2 100644 --- a/_prepend.php +++ b/_prepend.php @@ -1,21 +1,19 @@ autoload(['dcFilterDuplicate' => __DIR__ . '/inc/class.filter.duplicate.php']); -$core->spamfilters[] = 'dcFilterDuplicate'; \ No newline at end of file +dcCore::app()->spamfilters[] = 'dcFilterDuplicate'; diff --git a/_uninstall.php b/_uninstall.php index 6ae07a4..4f12315 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -1,16 +1,15 @@ addUserAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ $mod_id, - /* desc */ __('delete all settings') + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + $mod_id, + /* desc */ + __('delete all settings') ); $this->addUserAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ __('delete plugin files') + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + $mod_id, + /* desc */ + __('delete plugin files') ); $this->addUserAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ __('delete the version number') + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + $mod_id, + /* desc */ + __('delete the version number') ); $this->addDirectAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ $mod_id, - /* desc */ sprintf(__('delete all %s settings'), $mod_id) + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + $mod_id, + /* desc */ + sprintf(__('delete all %s settings'), $mod_id) ); $this->addDirectAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ sprintf(__('delete %s version number'), $mod_id) + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + $mod_id, + /* desc */ + sprintf(__('delete %s version number'), $mod_id) ); $this->addDirectAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ sprintf(__('delete %s plugin files'), $mod_id) -); \ No newline at end of file + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + $mod_id, + /* desc */ + sprintf(__('delete %s plugin files'), $mod_id) +); diff --git a/inc/class.filter.duplicate.php b/inc/class.filter.duplicate.php index a90a04c..1cfc789 100644 --- a/inc/class.filter.duplicate.php +++ b/inc/class.filter.duplicate.php @@ -1,16 +1,15 @@ name = __('Duplicate'); + $this->name = __('Duplicate'); $this->description = __('Same comments on others blogs of a multiblog'); } @@ -36,7 +35,7 @@ class dcFilterDuplicate extends dcSpamFilter if ($type != 'comment') { return null; } - if (strlen($content) < abs((integer) $this->core->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen'))) { + if (strlen($content) < $this->getMinLength()) { return null; } @@ -44,10 +43,11 @@ class dcFilterDuplicate extends dcSpamFilter if ($this->isDuplicate($content, $ip)) { $this->markDuplicate($content, $ip); $status = 'Duplicate on other blog'; + return true; - } else { - return null; } + + return null; } catch (Exception $e) { throw new Exception($e->getMessage()); } @@ -55,41 +55,42 @@ class dcFilterDuplicate extends dcSpamFilter public function isDuplicate($content, $ip) { - $rs = $this->core->con->select( - 'SELECT C.comment_id '. - 'FROM ' . $this->core->prefix . 'comment C ' . - 'LEFT JOIN ' . $this->core->prefix . 'post P ON C.post_id=P.post_id ' . - "WHERE P.blog_id != '" . $this->core->blog->id . "' " . - "AND C.comment_content='" . $this->core->con->escape($content) . "' " . + $rs = dcCore::app()->con->select( + 'SELECT C.comment_id ' . + 'FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' . + 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON C.post_id=P.post_id ' . + "WHERE P.blog_id != '" . dcCore::app()->blog->id . "' " . + "AND C.comment_content='" . dcCore::app()->con->escape($content) . "' " . "AND C.comment_ip='" . $ip . "' " ); + return !$rs->isEmpty(); } public function markDuplicate($content, $ip) { - $cur = $this->core->con->openCursor($this->core->prefix . 'comment'); - $this->core->con->writeLock($this->core->prefix . 'comment'); + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME); + dcCore::app()->con->writeLock(dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME); - $cur->comment_status = -2; + $cur->comment_status = -2; $cur->comment_spam_status = 'Duplicate on other blog'; $cur->comment_spam_filter = 'dcFilterDuplicate'; $cur->update( - "WHERE comment_content='" . $this->core->con->escape($content) . "' " . + "WHERE comment_content='" . dcCore::app()->con->escape($content) . "' " . "AND comment_ip='" . $ip . "' " ); - $this->core->con->unlock(); + dcCore::app()->con->unlock(); $this->triggerOtherBlogs($content, $ip); } - public function gui($url) + public function gui(string $url): string { - if ($this->core->auth->isSuperAdmin()) { - $this->core->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen'); + if (dcCore::app()->auth->isSuperAdmin()) { + dcCore::app()->blog->settings->dcFilterDuplicate->drop('dcfilterduplicate_minlen'); if (isset($_POST['dcfilterduplicate_minlen'])) { - $this->core->blog->settings->dcFilterDuplicate->put( + dcCore::app()->blog->settings->dcFilterDuplicate->put( 'dcfilterduplicate_minlen', - abs((integer) $_POST['dcfilterduplicate_minlen']), + abs((int) $_POST['dcfilterduplicate_minlen']), 'integer', 'Minimum lenght of comment to filter', true, @@ -99,46 +100,46 @@ class dcFilterDuplicate extends dcSpamFilter http::redirect($url); } - return + return '
' . '

' . '

' . - $this->core->formNonce() . '

' . + dcCore::app()->formNonce() . '

' . '
'; - } else { - return - '

' . sprintf( - __('Super administrator set the minimum length of comment content to %d chars.'), - $this->getMinlength() - ) . '

'; } + + return + '

' . sprintf( + __('Super administrator set the minimum length of comment content to %d chars.'), + $this->getMinlength() + ) . '

'; } private function getMinLength() { - return abs((integer) $this->core->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen')); + return abs((int) dcCore::app()->blog->settings->dcFilterDuplicate->getGlobal('dcfilterduplicate_minlen')); } public function triggerOtherBlogs($content, $ip) { - $rs = $this->core->con->select( + $rs = dcCore::app()->con->select( 'SELECT P.blog_id ' . - 'FROM ' . $this->core->prefix . 'comment C ' . - 'LEFT JOIN ' . $this->core->prefix . 'post P ON C.post_id=P.post_id ' . - "WHERE C.comment_content='" . $this->core->con->escape($content) . "' " . + 'FROM ' . dcCore::app()->prefix . dcBlog::COMMENT_TABLE_NAME . ' C ' . + 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON C.post_id=P.post_id ' . + "WHERE C.comment_content='" . dcCore::app()->con->escape($content) . "' " . "AND C.comment_ip='" . $ip . "' " ); while ($rs->fetch()) { - $b = new dcBlog($this, $rs->blog_id); + $b = new dcBlog($rs->blog_id); $b->triggerBlog(); unset($b); } } -} \ No newline at end of file +} diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php deleted file mode 100644 index 44eb0ba..0000000 --- a/locales/fr/main.lang.php +++ /dev/null @@ -1,21 +0,0 @@ -