Dotclear

Changeset 3262


Ignore:
Timestamp:
11/14/13 08:32:17 (10 years ago)
Author:
JcDenis
Message:

switch to DC 2.6, clean up code

Location:
plugins/dcFilterDuplicate
Files:
2 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • plugins/dcFilterDuplicate/_define.php

    r2902 r3262  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of dcFilterDuplicate, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2011 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_RC_PATH')){return;} 
     15if (!defined('DC_RC_PATH')) { 
     16 
     17     return null; 
     18} 
    1419  
    1520$this->registerModule( 
    16      /* Name */               "Duplicate comment filter", 
    17      /* Description*/              "Antispam for duplicate comments on multiblog", 
    18      /* Author */             "JC Denis", 
    19      /* Version */            '0.4', 
    20      /* Permissions */             'admin', 
    21      /* Priority */           200 
     21     /* Name */ 
     22     "Duplicate comment filter", 
     23     /* Description*/ 
     24     "Antispam for duplicate comments on multiblog", 
     25     /* Author */ 
     26     "Jean-Christian Denis", 
     27     /* Version */ 
     28     '0.5', 
     29     /* Properies */ 
     30     array( 
     31          'permissions' => 'admin', 
     32          'priority' => 200, 
     33          'type' => 'plugin', 
     34          'dc_min' => '2.6', 
     35          'support' => 'http://jcd.lv/q=dcFilterDuplicate', 
     36          'details' => 'http://plugins.dotaddict.org/dc2/details/dcFilterDuplicate' 
     37     ) 
    2238); 
    23      /* date */          #20110120 
    24 ?> 
  • plugins/dcFilterDuplicate/_install.php

    r2902 r3262  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of dcFilterDuplicate, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2011 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_CONTEXT_ADMIN')){return;} 
     15if (!defined('DC_CONTEXT_ADMIN')) { 
    1416 
    15 # Get new version 
    16 $new_version = $core->plugins->moduleInfo('dcFilterDuplicate','version'); 
    17 $old_version = $core->getVersion('dcFilterDuplicate'); 
     17     return null; 
     18} 
    1819 
    19 # Compare versions 
    20 if (version_compare($old_version,$new_version,'>=')) {return;} 
     20# -- Module specs -- 
    2121 
    22 # Install or update 
    23 try 
    24 { 
    25      # Check version 
    26      if (version_compare(str_replace("-r","-p",DC_VERSION),'2.2-alpha','<')) 
    27      { 
    28           throw new Exception('dcFilterDuplicate requires Dotclear 2.2'); 
     22$dc_min = '2.6'; 
     23$mod_id = 'dcFilterDuplicate'; 
     24$mod_conf = array( 
     25     array( 
     26          'dcfilterduplicate_minlen', 
     27          'Minimum lenght of comment to filter', 
     28          30, 
     29          'integer' 
     30     ) 
     31); 
     32 
     33# -- Nothing to change below -- 
     34 
     35try { 
     36 
     37     # Check module version 
     38     if (version_compare( 
     39          $core->getVersion($mod_id), 
     40          $core->plugins->moduleInfo($mod_id, 'version'), 
     41          '>=' 
     42     )) { 
     43 
     44          return null; 
    2945     } 
    30       
    31      # Settings 
    32      $core->blog->settings->addNamespace('dcFilterDuplicate'); 
    33      $core->blog->settings->dcFilterDuplicate->put('dcfilterduplicate_minlen',30,'integer','Minimum lenght of comment to filter',false,true); 
    3446 
    35      # Version 
    36      $core->setVersion('dcFilterDuplicate',$new_version); 
     47     # Check Dotclear version 
     48     if (!method_exists('dcUtils', 'versionsCompare')  
     49      || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { 
     50          throw new Exception(sprintf( 
     51               '%s requires Dotclear %s', $mod_id, $dc_min 
     52          )); 
     53     } 
     54 
     55     # Set module settings 
     56     $core->blog->settings->addNamespace($mod_id); 
     57     foreach($mod_conf as $v) { 
     58          $core->blog->settings->{$mod_id}->put( 
     59               $v[0], $v[2], $v[3], $v[1], false, true 
     60          ); 
     61     } 
     62 
     63     # Set module version 
     64     $core->setVersion( 
     65          $mod_id, 
     66          $core->plugins->moduleInfo($mod_id, 'version') 
     67     ); 
    3768 
    3869     return true; 
    3970} 
    40 catch (Exception $e) 
    41 { 
     71catch (Exception $e) { 
    4272     $core->error->add($e->getMessage()); 
     73 
    4374     return false; 
    4475} 
    45 ?> 
  • plugins/dcFilterDuplicate/_prepend.php

    r2902 r3262  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of dcFilterDuplicate, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2011 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_RC_PATH')){return;} 
     15if (!defined('DC_RC_PATH')) { 
    1416 
    15 global $__autoload, $core; 
     17     return null; 
     18} 
    1619 
    1720$__autoload['dcFilterDuplicate'] =  
     
    1922 
    2023$core->spamfilters[] = 'dcFilterDuplicate'; 
    21 ?> 
  • plugins/dcFilterDuplicate/_uninstall.php

    r2902 r3262  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of dcFilterDuplicate, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2011 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_CONTEXT_ADMIN')){return;} 
     15if (!defined('DC_CONTEXT_ADMIN')) { 
     16 
     17     return null; 
     18} 
     19 
     20$mod_id = 'dcFilterDuplicate'; 
    1421 
    1522$this->addUserAction( 
    16      /* type */ 'settings', 
    17      /* action */ 'delete_all', 
    18      /* ns */ 'dcFilterDuplicate', 
    19      /* description */ __('delete all settings') 
     23     /* type */     'settings', 
     24     /* action */   'delete_all', 
     25     /* ns */       $mod_id, 
     26     /* desc */     __('delete all settings') 
    2027); 
    2128 
    2229$this->addUserAction( 
    23      /* type */ 'plugins', 
    24      /* action */ 'delete', 
    25      /* ns */ 'dcFilterDuplicate', 
    26      /* description */ __('delete plugin files') 
     30     /* type */     'plugins', 
     31     /* action */   'delete', 
     32     /* ns */       $mod_id, 
     33     /* desc */     __('delete plugin files') 
    2734); 
    2835 
    2936$this->addUserAction( 
    30      /* type */ 'versions', 
    31      /* action */ 'delete', 
    32      /* ns */ 'dcFilterDuplicate', 
    33      /* description */ __('delete the version number') 
     37     /* type */     'versions', 
     38     /* action */   'delete', 
     39     /* ns */       $mod_id, 
     40     /* desc */     __('delete the version number') 
    3441); 
    3542 
    3643$this->addDirectAction( 
    37      /* type */ 'settings', 
    38      /* action */ 'delete_all', 
    39      /* ns */ 'dcFilterDuplicate', 
    40      /* description */ sprintf(__('delete all %s settings'),'dcFilterDuplicate') 
     44     /* type */     'settings', 
     45     /* action */   'delete_all', 
     46     /* ns */       $mod_id, 
     47     /* desc */     sprintf(__('delete all %s settings'), $mod_id) 
    4148); 
    4249 
    4350$this->addDirectAction( 
    44      /* type */ 'versions', 
    45      /* action */ 'delete', 
    46      /* ns */ 'dcFilterDuplicate', 
    47      /* description */ sprintf(__('delete %s version number'),'dcFilterDuplicate') 
     51     /* type */     'versions', 
     52     /* action */   'delete', 
     53     /* ns */       $mod_id, 
     54     /* desc */     sprintf(__('delete %s version number'), $mod_id) 
    4855); 
    4956 
    5057$this->addDirectAction( 
    51      /* type */ 'plugins', 
    52      /* action */ 'delete', 
    53      /* ns */ 'dcFilterDuplicate', 
    54      /* description */ sprintf(__('delete %s plugin files'),'dcFilterDuplicate') 
     58     /* type */     'plugins', 
     59     /* action */   'delete', 
     60     /* ns */       $mod_id, 
     61     /* desc */     sprintf(__('delete %s plugin files'), $mod_id) 
    5562); 
    56 ?> 
  • plugins/dcFilterDuplicate/inc/class.filter.duplicate.php

    r2902 r3262  
    11<?php 
    22# -- BEGIN LICENSE BLOCK ---------------------------------- 
     3# 
    34# This file is part of dcFilterDuplicate, a plugin for Dotclear 2. 
    45#  
    5 # Copyright (c) 2009-2011 JC Denis and contributors 
    6 # jcdenis@gdwd.com 
     6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors 
     7# contact@jcdenis.fr http://jcd.lv 
    78#  
    89# Licensed under the GPL version 2.0 license. 
    910# A copy of this license is available in LICENSE file or at 
    1011# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     12# 
    1113# -- END LICENSE BLOCK ------------------------------------ 
    1214 
    13 if (!defined('DC_RC_PATH')){return;} 
     15if (!defined('DC_RC_PATH')) { 
    1416 
     17     return null; 
     18} 
     19 
     20/** 
     21 * @ingroup DC_PLUGIN_DCFILTERDUPLICATE 
     22 * @brief Filter duplicate comments on multiblogs. 
     23 * @since 2.6 
     24 */ 
    1525class dcFilterDuplicate extends dcSpamFilter 
    1626{ 
    1727     public $name = 'Duplicate comment filter'; 
    1828     public $has_gui = true; 
    19       
     29 
    2030     protected function setInfo() 
    2131     { 
     32          $this->name = __('Duplicate comment filter'); 
    2233          $this->description = __('Same comments on others blogs of a multiblog.'); 
    2334     } 
    2435      
    25      public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 
     36     public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) 
    2637     { 
    27           if ($type != 'comment') return null; 
    28            
     38          if ($type != 'comment') { 
     39 
     40               return null; 
     41          } 
     42 
    2943          $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); 
    30           if (strlen($content) < $minlen) return null; 
    31            
    32           try 
    33           { 
    34                if ($this->isDuplicate($content,$ip)) 
    35                { 
    36                     $this->markDuplicate($content,$ip); 
     44          if (strlen($content) < $minlen) { 
     45 
     46               return null; 
     47          } 
     48 
     49          try { 
     50               if ($this->isDuplicate($content, $ip)) { 
     51                    $this->markDuplicate($content, $ip); 
    3752                    $status = 'Duplicate on other blog'; 
     53 
    3854                    return true; 
    3955               } 
    40                else 
    41                { 
     56               else { 
     57 
    4258                    return null; 
    4359               } 
    4460          } 
    45           catch (Exception $e) 
    46           { 
     61          catch (Exception $e) { 
    4762               throw new Exception($e->getMessage()); 
    4863          } 
    4964     } 
    50       
    51      public function isDuplicate($content,$ip) 
     65 
     66     public function isDuplicate($content, $ip) 
    5267     { 
    5368          $rs = $this->core->con->select( 
     
    5974               "AND C.comment_ip='".$ip."' " 
    6075          ); 
     76 
    6177          return !$rs->isEmpty(); 
    6278     } 
    6379      
    64      public function markDuplicate($content,$ip) 
     80     public function markDuplicate($content, $ip) 
    6581     { 
    6682          $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 
    6783          $this->core->con->writeLock($this->core->prefix.'comment'); 
    68            
     84 
    6985          $cur->comment_status = -2; 
    7086          $cur->comment_spam_status = 'Duplicate on other blog'; 
    7187          $cur->comment_spam_filter = 'dcFilterDuplicate'; 
    72            
     88 
    7389          $cur->update( 
    7490               "WHERE comment_content='".$this->core->con->escape($content)."' ". 
     
    7692          ); 
    7793          $this->core->con->unlock(); 
    78            
    79           $this->triggerOtherBlogs($content,$ip); 
     94 
     95          $this->triggerOtherBlogs($content, $ip); 
    8096     } 
    8197 
     
    8399     { 
    84100          $minlen = abs((integer) $this->core->blog->settings->dcFilterDuplicate->dcfilterduplicate_minlen); 
    85           if (isset($_POST['dcfilterduplicate_minlen'])) 
    86           { 
     101          if (isset($_POST['dcfilterduplicate_minlen'])) { 
    87102               $minlen = abs((integer) $_POST['dcfilterduplicate_minlen']); 
    88                $this->core->blog->settings->dcFilterDuplicate->put('dcfilterduplicate_minlen',$minlen,'integer'); 
     103               $this->core->blog->settings->dcFilterDuplicate->put( 
     104                    'dcfilterduplicate_minlen', 
     105                    $minlen, 
     106                    'integer' 
     107               ); 
    89108          } 
    90            
     109 
    91110          $res = 
    92111          '<form action="'.html::escapeURL($url).'" method="post">'. 
    93112          '<p><label class="classic">'.__('Minimum content length before check for duplicate:').'<br />'. 
    94           form::field(array('dcfilterduplicate_minlen'),65,255,$minlen). 
     113          form::field(array('dcfilterduplicate_minlen'), 65, 255, $minlen). 
    95114          '</label></p>'. 
    96           '<p><input type="submit" name="save" value="'.__('save').'" />'. 
     115          '<p><input type="submit" name="save" value="'.__('Save').'" />'. 
    97116          $this->core->formNonce().'</p>'. 
    98117          '</form>'; 
     118 
    99119          return $res; 
    100120     } 
    101       
    102      public function triggerOtherBlogs($content,$ip) 
     121 
     122     public function triggerOtherBlogs($content, $ip) 
    103123     { 
    104124          $rs = $this->core->con->select( 
     
    109129               "AND C.comment_ip='".$ip."' " 
    110130          ); 
    111            
    112           while ($rs->fetch()) 
    113           { 
    114                $b = new dcBlog($this,$rs->blog_id); 
     131 
     132          while ($rs->fetch()) { 
     133               $b = new dcBlog($this, $rs->blog_id); 
    115134               $b->triggerBlog(); 
    116135               unset($b); 
     
    118137     } 
    119138} 
    120 ?> 
  • plugins/dcFilterDuplicate/locales/fr/main.lang.php

    r1981 r3262  
    11<?php 
    2 // Language: français  
    3 // Module: dcFilterDuplicate - 0.2 
    4 // Date: 2009-12-13 20:05:54  
    5 // Translated with dcTranslater - 1.3  
     2// Language: Français  
     3// Module: dcFilterDuplicate - 0.5 
     4// Date: 2013-11-14 07:24:38  
     5// Translated with dcTranslater - 2013.05.11  
    66 
    7 #inc/class.filter.duplicate.php:22 
     7#inc/class.filter.duplicate.php:30 
     8$GLOBALS['__l10n']['Duplicate comment filter'] = 'Filtre de doublon de commentaires'; 
     9 
     10#inc/class.filter.duplicate.php:31 
    811$GLOBALS['__l10n']['Same comments on others blogs of a multiblog.'] = 'Commentaires identiques sur les autres blogs du multiblog.'; 
    912 
    10 #inc/class.filter.duplicate.php:92 
     13#inc/class.filter.duplicate.php:110 
    1114$GLOBALS['__l10n']['Minimum content length before check for duplicate:'] = 'Longueur minimum du contenu pour faire une vérification :'; 
    1215 
     16$GLOBALS['__l10n']['Antispam for duplicate comments on multiblog'] = 'Antispam contre les doublons de commentaires sur un multiblog'; 
     17 
    1318?> 
  • plugins/dcFilterDuplicate/locales/fr/main.po

    r1981 r3262  
    1 # Language: français 
    2 # Module: dcFilterDuplicate - 0.2 
    3 # Date: 2009-12-13 20:05:54 
    4 # Translated with translater 1.3 
     1# Language: Français 
     2# Module: dcFilterDuplicate - 0.5 
     3# Date: 2013-11-14 07:24:39 
     4# Translated with translater 2013.05.11 
    55 
    66msgid "" 
    77msgstr "" 
    88"Content-Type: text/plain; charset=UTF-8\n" 
    9 "Project-Id-Version: dcFilterDuplicate 0.2\n" 
     9"Project-Id-Version: dcFilterDuplicate 0.5\n" 
    1010"POT-Creation-Date: \n" 
    11 "PO-Revision-Date: 2009-12-13T20:05:54+00:00\n" 
    12 "Last-Translator: JC Denis\n" 
     11"PO-Revision-Date: 2013-11-14T07:24:39+00:00\n" 
     12"Last-Translator: Jean-Christian Denis\n" 
    1313"Language-Team: \n" 
    1414"MIME-Version: 1.0\n" 
    1515"Content-Transfer-Encoding: 8bit\n" 
    1616 
    17 #: inc/class.filter.duplicate.php:22 
     17#: inc/class.filter.duplicate.php:30 
     18msgid "Duplicate comment filter" 
     19msgstr "Filtre de doublon de commentaires" 
     20 
     21#: inc/class.filter.duplicate.php:31 
    1822msgid "Same comments on others blogs of a multiblog." 
    1923msgstr "Commentaires identiques sur les autres blogs du multiblog." 
    2024 
    21 #: inc/class.filter.duplicate.php:92 
     25#: inc/class.filter.duplicate.php:110 
    2226msgid "Minimum content length before check for duplicate:" 
    2327msgstr "Longueur minimum du contenu pour faire une vérification :" 
    2428 
     29msgid "Antispam for duplicate comments on multiblog" 
     30msgstr "Antispam contre les doublons de commentaires sur un multiblog" 
     31 
Note: See TracChangeset for help on using the changeset viewer.

Sites map