Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

Location:
plugins/antispam
Files:
12 edited
1 moved

Legend:

Unmodified
Added
Removed
  • plugins/antispam/_define.php

    r3333 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414$this->registerModule( 
    15      /* Name */               "Antispam", 
    16      /* Description*/         "Generic antispam plugin for Dotclear", 
    17      /* Author */             "Alain Vagner", 
    18      /* Version */            '1.4.1', 
    19      array( 
    20           'permissions' =>    'usage,contentadmin', 
    21           'priority' =>       10, 
    22           'settings'     =>        array( 
    23                                         'self' => '', 
    24                                         'blog' => '#params.antispam_params' 
    25                                    ) 
    26      ) 
     15    "Antispam",                             // Name 
     16    "Generic antispam plugin for Dotclear", // Description 
     17    "Alain Vagner",                         // Author 
     18    '1.4.1',                                // Version 
     19    array( 
     20        'permissions' => 'usage,contentadmin', 
     21        'priority'    => 10, 
     22        'settings'    => array( 
     23            'self' => '', 
     24            'blog' => '#params.antispam_params' 
     25        ) 
     26    ) 
    2727); 
  • plugins/antispam/_install.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 
     12if (!defined('DC_CONTEXT_ADMIN')) {return;} 
    1313 
    14 $version = $core->plugins->moduleInfo('antispam','version'); 
    15 if (version_compare($core->getVersion('antispam'),$version,'>=')) { 
    16      return; 
     14$version = $core->plugins->moduleInfo('antispam', 'version'); 
     15if (version_compare($core->getVersion('antispam'), $version, '>=')) { 
     16    return; 
    1717} 
    1818 
    1919/* Database schema 
    2020-------------------------------------------------------- */ 
    21 $s = new dbStruct($core->con,$core->prefix); 
     21$s = new dbStruct($core->con, $core->prefix); 
    2222 
    2323$s->spamrule 
    24      ->rule_id      ('bigint',     0,   false) 
    25      ->blog_id      ('varchar',    32,  true) 
    26      ->rule_type    ('varchar',    16,  false,    "'word'") 
    27      ->rule_content ('varchar',    128, false) 
     24    ->rule_id('bigint', 0, false) 
     25    ->blog_id('varchar', 32, true) 
     26    ->rule_type('varchar', 16, false, "'word'") 
     27    ->rule_content('varchar', 128, false) 
    2828 
    29      ->primary('pk_spamrule','rule_id') 
    30      ; 
     29    ->primary('pk_spamrule', 'rule_id') 
     30; 
    3131 
    32 $s->spamrule->index('idx_spamrule_blog_id','btree','blog_id'); 
    33 $s->spamrule->reference('fk_spamrule_blog','blog_id','blog','blog_id','cascade','cascade'); 
     32$s->spamrule->index('idx_spamrule_blog_id', 'btree', 'blog_id'); 
     33$s->spamrule->reference('fk_spamrule_blog', 'blog_id', 'blog', 'blog_id', 'cascade', 'cascade'); 
    3434 
    3535if ($s->driver() == 'pgsql') { 
    36      $s->spamrule->index('idx_spamrule_blog_id_null','btree','(blog_id IS NULL)'); 
     36    $s->spamrule->index('idx_spamrule_blog_id_null', 'btree', '(blog_id IS NULL)'); 
    3737} 
    3838 
    3939# Schema installation 
    40 $si = new dbStruct($core->con,$core->prefix); 
     40$si      = new dbStruct($core->con, $core->prefix); 
    4141$changes = $si->synchronize($s); 
    4242 
    4343# Creating default wordslist 
    4444if ($core->getVersion('antispam') === null) { 
    45      $_o = new dcFilterWords($core); 
    46      $_o->defaultWordsList(); 
    47      unset($_o); 
     45    $_o = new dcFilterWords($core); 
     46    $_o->defaultWordsList(); 
     47    unset($_o); 
    4848} 
    4949 
    50 $settings = new dcSettings($core,null); 
     50$settings = new dcSettings($core, null); 
    5151$settings->addNamespace('antispam'); 
    52 $settings->antispam->put('antispam_moderation_ttl',0,'integer','Antispam Moderation TTL (days)',false); 
     52$settings->antispam->put('antispam_moderation_ttl', 0, 'integer', 'Antispam Moderation TTL (days)', false); 
    5353 
    54 $core->setVersion('antispam',$version); 
     54$core->setVersion('antispam', $version); 
    5555return true; 
  • plugins/antispam/_prepend.php

    r2095 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    14 $__autoload['dcSpamFilter'] = dirname(__FILE__).'/inc/class.dc.spamfilter.php'; 
    15 $__autoload['dcSpamFilters'] = dirname(__FILE__).'/inc/class.dc.spamfilters.php'; 
    16 $__autoload['dcAntispam'] = dirname(__FILE__).'/inc/lib.dc.antispam.php'; 
    17 $__autoload['dcAntispamURL'] = dirname(__FILE__).'/inc/lib.dc.antispam.url.php'; 
     14$__autoload['dcSpamFilter']  = dirname(__FILE__) . '/inc/class.dc.spamfilter.php'; 
     15$__autoload['dcSpamFilters'] = dirname(__FILE__) . '/inc/class.dc.spamfilters.php'; 
     16$__autoload['dcAntispam']    = dirname(__FILE__) . '/inc/lib.dc.antispam.php'; 
     17$__autoload['dcAntispamURL'] = dirname(__FILE__) . '/inc/lib.dc.antispam.url.php'; 
    1818 
    19 $__autoload['dcFilterIP'] = dirname(__FILE__).'/filters/class.dc.filter.ip.php'; 
    20 $__autoload['dcFilterIpLookup'] = dirname(__FILE__).'/filters/class.dc.filter.iplookup.php'; 
    21 $__autoload['dcFilterLinksLookup'] = dirname(__FILE__).'/filters/class.dc.filter.linkslookup.php'; 
    22 $__autoload['dcFilterWords'] = dirname(__FILE__).'/filters/class.dc.filter.words.php'; 
     19$__autoload['dcFilterIP']          = dirname(__FILE__) . '/filters/class.dc.filter.ip.php'; 
     20$__autoload['dcFilterIpLookup']    = dirname(__FILE__) . '/filters/class.dc.filter.iplookup.php'; 
     21$__autoload['dcFilterLinksLookup'] = dirname(__FILE__) . '/filters/class.dc.filter.linkslookup.php'; 
     22$__autoload['dcFilterWords']       = dirname(__FILE__) . '/filters/class.dc.filter.words.php'; 
    2323 
    24 $core->spamfilters = array('dcFilterIP','dcFilterIpLookup','dcFilterWords','dcFilterLinksLookup'); 
     24$core->spamfilters = array('dcFilterIP', 'dcFilterIpLookup', 'dcFilterWords', 'dcFilterLinksLookup'); 
    2525 
    26 $core->url->register('spamfeed','spamfeed','^spamfeed/(.+)$',array('dcAntispamURL','spamFeed')); 
    27 $core->url->register('hamfeed','hamfeed','^hamfeed/(.+)$',array('dcAntispamURL','hamFeed')); 
     26$core->url->register('spamfeed', 'spamfeed', '^spamfeed/(.+)$', array('dcAntispamURL', 'spamFeed')); 
     27$core->url->register('hamfeed', 'hamfeed', '^hamfeed/(.+)$', array('dcAntispamURL', 'hamFeed')); 
  • plugins/antispam/_public.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    14 $core->addBehavior('publicBeforeCommentCreate',array('dcAntispam','isSpam')); 
    15 $core->addBehavior('publicBeforeTrackbackCreate',array('dcAntispam','isSpam')); 
    16 $core->addBehavior('publicBeforeDocument',array('dcAntispam','purgeOldSpam')); 
     14$core->addBehavior('publicBeforeCommentCreate', array('dcAntispam', 'isSpam')); 
     15$core->addBehavior('publicBeforeTrackbackCreate', array('dcAntispam', 'isSpam')); 
     16$core->addBehavior('publicBeforeDocument', array('dcAntispam', 'purgeOldSpam')); 
  • plugins/antispam/filters/class.dc.filter.iplookup.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcFilterIpLookup extends dcSpamFilter 
    1515{ 
    16      public $name = 'IP Lookup'; 
    17      public $has_gui = true; 
    18      public $help = 'iplookup-filter'; 
     16    public $name    = 'IP Lookup'; 
     17    public $has_gui = true; 
     18    public $help    = 'iplookup-filter'; 
    1919 
    20      private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net'; 
     20    private $default_bls = 'sbl-xbl.spamhaus.org , bsb.spamlookup.net'; 
    2121 
    22      public function __construct($core) 
    23      { 
    24           parent::__construct($core); 
     22    public function __construct($core) 
     23    { 
     24        parent::__construct($core); 
    2525 
    26           if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) { 
    27                $this->has_gui = false; 
    28           } 
    29      } 
     26        if (defined('DC_DNSBL_SUPER') && DC_DNSBL_SUPER && !$core->auth->isSuperAdmin()) { 
     27            $this->has_gui = false; 
     28        } 
     29    } 
    3030 
    31      protected function setInfo() 
    32      { 
    33           $this->description = __('Checks sender IP address against DNSBL servers'); 
    34      } 
     31    protected function setInfo() 
     32    { 
     33        $this->description = __('Checks sender IP address against DNSBL servers'); 
     34    } 
    3535 
    36      public function getStatusMessage($status,$comment_id) 
    37      { 
    38           return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status); 
    39      } 
     36    public function getStatusMessage($status, $comment_id) 
     37    { 
     38        return sprintf(__('Filtered by %1$s with server %2$s.'), $this->guiLink(), $status); 
     39    } 
    4040 
    41      public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 
    42      { 
    43           if (!$ip || long2ip(ip2long($ip)) != $ip) { 
    44                return; 
    45           } 
     41    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) 
     42    { 
     43        if (!$ip || long2ip(ip2long($ip)) != $ip) { 
     44            return; 
     45        } 
    4646 
    47           $bls = $this->getServers(); 
    48           $bls = preg_split('/\s*,\s*/',$bls); 
     47        $bls = $this->getServers(); 
     48        $bls = preg_split('/\s*,\s*/', $bls); 
    4949 
    50           foreach ($bls as $bl) { 
    51                if ($this->dnsblLookup($ip,$bl)) { 
    52                     // Pass by reference $status to contain matching DNSBL 
    53                     $status = $bl; 
    54                     return true; 
    55                } 
    56           } 
    57      } 
     50        foreach ($bls as $bl) { 
     51            if ($this->dnsblLookup($ip, $bl)) { 
     52                // Pass by reference $status to contain matching DNSBL 
     53                $status = $bl; 
     54                return true; 
     55            } 
     56        } 
     57    } 
    5858 
    59      public function gui($url) 
    60      { 
    61           $bls = $this->getServers(); 
     59    public function gui($url) 
     60    { 
     61        $bls = $this->getServers(); 
    6262 
    63           if (isset($_POST['bls'])) 
    64           { 
    65                try { 
    66                     $this->core->blog->settings->addNamespace('antispam'); 
    67                     $this->core->blog->settings->antispam->put('antispam_dnsbls',$_POST['bls'],'string','Antispam DNSBL servers',true,false); 
    68                     dcPage::addSuccessNotice(__('The list of DNSBL servers has been succesfully updated.')); 
    69                     http::redirect($url); 
    70                } catch (Exception $e) { 
    71                     $core->error->add($e->getMessage()); 
    72                } 
    73           } 
     63        if (isset($_POST['bls'])) { 
     64            try { 
     65                $this->core->blog->settings->addNamespace('antispam'); 
     66                $this->core->blog->settings->antispam->put('antispam_dnsbls', $_POST['bls'], 'string', 'Antispam DNSBL servers', true, false); 
     67                dcPage::addSuccessNotice(__('The list of DNSBL servers has been succesfully updated.')); 
     68                http::redirect($url); 
     69            } catch (Exception $e) { 
     70                $core->error->add($e->getMessage()); 
     71            } 
     72        } 
    7473 
    75           /* DISPLAY 
    76           ---------------------------------------------- */ 
    77           $res = dcPage::notices(); 
     74        /* DISPLAY 
     75        ---------------------------------------------- */ 
     76        $res = dcPage::notices(); 
    7877 
    79           $res .= 
    80           '<form action="'.html::escapeURL($url).'" method="post" class="fieldset">'. 
    81           '<h3>' . __('IP Lookup servers') . '</h3>'. 
    82           '<p><label for="bls">'.__('Add here a coma separated list of servers.').'</label>'. 
    83           form::textarea('bls',40,3,html::escapeHTML($bls),'maximal'). 
    84           '</p>'. 
    85           '<p><input type="submit" value="'.__('Save').'" />'. 
    86           $this->core->formNonce().'</p>'. 
    87           '</form>'; 
     78        $res .= 
     79        '<form action="' . html::escapeURL($url) . '" method="post" class="fieldset">' . 
     80        '<h3>' . __('IP Lookup servers') . '</h3>' . 
     81        '<p><label for="bls">' . __('Add here a coma separated list of servers.') . '</label>' . 
     82        form::textarea('bls', 40, 3, html::escapeHTML($bls), 'maximal') . 
     83        '</p>' . 
     84        '<p><input type="submit" value="' . __('Save') . '" />' . 
     85        $this->core->formNonce() . '</p>' . 
     86            '</form>'; 
    8887 
    89           return $res; 
    90      } 
     88        return $res; 
     89    } 
    9190 
    92      private function getServers() 
    93      { 
    94           $bls = $this->core->blog->settings->antispam->antispam_dnsbls; 
    95           if ($bls === null) { 
    96                $this->core->blog->settings->addNamespace('antispam'); 
    97                $this->core->blog->settings->antispam->put('antispam_dnsbls',$this->default_bls,'string','Antispam DNSBL servers',true,false); 
    98                return $this->default_bls; 
    99           } 
     91    private function getServers() 
     92    { 
     93        $bls = $this->core->blog->settings->antispam->antispam_dnsbls; 
     94        if ($bls === null) { 
     95            $this->core->blog->settings->addNamespace('antispam'); 
     96            $this->core->blog->settings->antispam->put('antispam_dnsbls', $this->default_bls, 'string', 'Antispam DNSBL servers', true, false); 
     97            return $this->default_bls; 
     98        } 
    10099 
    101           return $bls; 
    102      } 
     100        return $bls; 
     101    } 
    103102 
    104      private function dnsblLookup($ip,$bl) 
    105      { 
    106           $revIp = implode('.',array_reverse(explode('.',$ip))); 
     103    private function dnsblLookup($ip, $bl) 
     104    { 
     105        $revIp = implode('.', array_reverse(explode('.', $ip))); 
    107106 
    108           $host = $revIp.'.'.$bl.'.'; 
    109           if (gethostbyname($host) != $host) { 
    110                return true; 
    111           } 
     107        $host = $revIp . '.' . $bl . '.'; 
     108        if (gethostbyname($host) != $host) { 
     109            return true; 
     110        } 
    112111 
    113           return false; 
    114      } 
     112        return false; 
     113    } 
    115114} 
  • plugins/antispam/filters/class.dc.filter.linkslookup.php

    r2567 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcFilterLinksLookup extends dcSpamFilter 
    1515{ 
    16      public $name = 'Links Lookup'; 
     16    public $name = 'Links Lookup'; 
    1717 
    18      private $server = 'multi.surbl.org'; 
     18    private $server = 'multi.surbl.org'; 
    1919 
    20      protected function setInfo() 
    21      { 
    22           $this->description = __('Checks links in comments against surbl.org'); 
    23      } 
     20    protected function setInfo() 
     21    { 
     22        $this->description = __('Checks links in comments against surbl.org'); 
     23    } 
    2424 
    25      public function getStatusMessage($status,$comment_id) 
    26      { 
    27           return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status); 
    28      } 
     25    public function getStatusMessage($status, $comment_id) 
     26    { 
     27        return sprintf(__('Filtered by %1$s with server %2$s.'), $this->guiLink(), $status); 
     28    } 
    2929 
    30      public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 
    31      { 
    32           if (!$ip || long2ip(ip2long($ip)) != $ip) { 
    33                return; 
    34           } 
     30    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) 
     31    { 
     32        if (!$ip || long2ip(ip2long($ip)) != $ip) { 
     33            return; 
     34        } 
    3535 
    36           $urls = $this->getLinks($content); 
    37           array_unshift($urls,$site); 
     36        $urls = $this->getLinks($content); 
     37        array_unshift($urls, $site); 
    3838 
    39           foreach ($urls as $u) 
    40           { 
    41                $b = parse_url($u); 
    42                if (!isset($b['host']) || !$b['host']) { 
    43                     continue; 
    44                } 
     39        foreach ($urls as $u) { 
     40            $b = parse_url($u); 
     41            if (!isset($b['host']) || !$b['host']) { 
     42                continue; 
     43            } 
    4544 
    46                $domain = preg_replace('/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/','$1',$b['host']); 
    47                $domain_elem = explode(".",$domain); 
     45            $domain      = preg_replace('/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/', '$1', $b['host']); 
     46            $domain_elem = explode(".", $domain); 
    4847 
    49                $i = count($domain_elem) - 1; 
    50                if ($i == 0) { 
    51                     // "domain" is 1 word long, don't check it 
    52                     return null; 
    53                } 
    54                $host = $domain_elem[$i]; 
    55                do 
    56                { 
    57                     $host = $domain_elem[$i - 1].'.'.$host; 
    58                     $i--; 
    59                     if (substr(gethostbyname($host.'.'.$this->server),0,3) == "127" ) 
    60                     { 
    61                          $status = substr($domain,0,128); 
    62                          return true; 
    63                     } 
    64                } while ($i > 0); 
    65           } 
    66      } 
     48            $i = count($domain_elem) - 1; 
     49            if ($i == 0) { 
     50                // "domain" is 1 word long, don't check it 
     51                return; 
     52            } 
     53            $host = $domain_elem[$i]; 
     54            do { 
     55                $host = $domain_elem[$i - 1] . '.' . $host; 
     56                $i--; 
     57                if (substr(gethostbyname($host . '.' . $this->server), 0, 3) == "127") { 
     58                    $status = substr($domain, 0, 128); 
     59                    return true; 
     60                } 
     61            } while ($i > 0); 
     62        } 
     63    } 
    6764 
    68      private function getLinks($text) 
    69      { 
    70           // href attribute on "a" tags is second match 
    71           preg_match_all('|<a.*?href="(http.*?)"|', $text, $parts); 
     65    private function getLinks($text) 
     66    { 
     67        // href attribute on "a" tags is second match 
     68        preg_match_all('|<a.*?href="(http.*?)"|', $text, $parts); 
    7269 
    73           return $parts[1]; 
    74      } 
     70        return $parts[1]; 
     71    } 
    7572} 
  • plugins/antispam/inc/class.dc.spamfilter.php

    r3396 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcSpamFilter 
    1515{ 
    16      public $name; 
    17      public $description; 
    18      public $active = true; 
    19      public $order = 100; 
    20      public $auto_delete = false; 
    21      public $help = null; 
     16    public $name; 
     17    public $description; 
     18    public $active      = true; 
     19    public $order      = 100; 
     20    public $auto_delete = false; 
     21    public $help        = null; 
    2222 
    23      protected $has_gui = false; 
    24      protected $gui_url = null; 
     23    protected $has_gui = false; 
     24    protected $gui_url = null; 
    2525 
    26      protected $core; 
     26    protected $core; 
    2727 
    28      /** 
    29      Object constructor 
     28    /** 
     29    Object constructor 
    3030 
    31      @param    core      <b>dcCore</b>       Dotclear core object 
    32      */ 
    33      public function __construct($core) 
    34      { 
    35           $this->core =& $core; 
    36           $this->setInfo(); 
     31    @param    core        <b>dcCore</b>        Dotclear core object 
     32     */ 
     33    public function __construct($core) 
     34    { 
     35        $this->core = &$core; 
     36        $this->setInfo(); 
    3737 
    38           if (!$this->name) { 
    39                $this->name = get_class($this); 
    40           } 
     38        if (!$this->name) { 
     39            $this->name = get_class($this); 
     40        } 
    4141 
    42           if ($core && isset($core->adminurl)) { 
    43              $this->gui_url = $core->adminurl->get('admin.plugin.antispam',array('f' => get_class($this)),'&'); 
    44           } 
    45      } 
     42        if ($core && isset($core->adminurl)) { 
     43            $this->gui_url = $core->adminurl->get('admin.plugin.antispam', array('f' => get_class($this)), '&'); 
     44        } 
     45    } 
    4646 
    47      /** 
    48      This method is called by the constructor and allows you to change some 
    49      object properties without overloading object constructor. 
    50      */ 
    51      protected function setInfo() 
    52      { 
    53           $this->description = __('No description'); 
    54      } 
     47    /** 
     48    This method is called by the constructor and allows you to change some 
     49    object properties without overloading object constructor. 
     50     */ 
     51    protected function setInfo() 
     52    { 
     53        $this->description = __('No description'); 
     54    } 
    5555 
    56      /** 
    57      This method should return if a comment is a spam or not. If it returns true 
    58      or false, execution of next filters will be stoped. If should return nothing 
    59      to let next filters apply. 
     56    /** 
     57    This method should return if a comment is a spam or not. If it returns true 
     58    or false, execution of next filters will be stoped. If should return nothing 
     59    to let next filters apply. 
    6060 
    61      Your filter should also fill $status variable with its own information if 
    62      comment is a spam. 
     61    Your filter should also fill $status variable with its own information if 
     62    comment is a spam. 
    6363 
    64      @param         type      <b>string</b>       Comment type (comment or trackback) 
    65      @param         author    <b>string</b>       Comment author 
    66      @param         email     <b>string</b>       Comment author email 
    67      @param         site      <b>string</b>       Comment author website 
    68      @param         ip        <b>string</b>       Comment author IP address 
    69      @param         content   <b>string</b>       Comment content 
    70      @param         post_id   <b>integer</b>      Comment post_id 
    71      @param[out]    status    <b>integer</b>      Comment status 
    72      @return   <b>boolean</b> 
    73      */ 
    74      public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status) 
    75      { 
    76      } 
     64    @param        type        <b>string</b>        Comment type (comment or trackback) 
     65    @param        author    <b>string</b>        Comment author 
     66    @param        email    <b>string</b>        Comment author email 
     67    @param        site        <b>string</b>        Comment author website 
     68    @param        ip        <b>string</b>        Comment author IP address 
     69    @param        content    <b>string</b>        Comment content 
     70    @param        post_id    <b>integer</b>        Comment post_id 
     71    @param[out]    status    <b>integer</b>        Comment status 
     72    @return    <b>boolean</b> 
     73     */ 
     74    public function isSpam($type, $author, $email, $site, $ip, $content, $post_id, &$status) 
     75    { 
     76    } 
    7777 
    78      /** 
    79      This method is called when a non-spam (ham) comment becomes spam or when a 
    80      spam becomes a ham. 
     78    /** 
     79    This method is called when a non-spam (ham) comment becomes spam or when a 
     80    spam becomes a ham. 
    8181 
    82      @param    type      <b>string</b>       Comment type (comment or trackback) 
    83      @param    filter    <b>string</b>       Filter name 
    84      @param    author    <b>string</b>       Comment author 
    85      @param    email     <b>string</b>       Comment author email 
    86      @param    site      <b>string</b>       Comment author website 
    87      @param    ip        <b>string</b>       Comment author IP address 
    88      @param    content   <b>string</b>       Comment content 
    89      @param    post_url  <b>string</b>       Post URL 
    90      @param    rs        <b>record</b>       Comment record 
    91      @return   <b>boolean</b> 
    92      */ 
    93      public function trainFilter($status,$filter,$type,$author,$email,$site,$ip,$content,$rs) 
    94      { 
    95      } 
     82    @param    type        <b>string</b>        Comment type (comment or trackback) 
     83    @param    filter    <b>string</b>        Filter name 
     84    @param    author    <b>string</b>        Comment author 
     85    @param    email    <b>string</b>        Comment author email 
     86    @param    site        <b>string</b>        Comment author website 
     87    @param    ip        <b>string</b>        Comment author IP address 
     88    @param    content    <b>string</b>        Comment content 
     89    @param    post_url    <b>string</b>        Post URL 
     90    @param    rs        <b>record</b>        Comment record 
     91    @return    <b>boolean</b> 
     92     */ 
     93    public function trainFilter($status, $filter, $type, $author, $email, $site, $ip, $content, $rs) 
     94    { 
     95    } 
    9696 
    97      /** 
    98      This method returns filter status message. You can overload this method to 
    99      return a custom message. Message is shown in comment details and in 
    100      comments list. 
     97    /** 
     98    This method returns filter status message. You can overload this method to 
     99    return a custom message. Message is shown in comment details and in 
     100    comments list. 
    101101 
    102      @param    status         <b>string</b>       Filter status. 
    103      @param    comment_id     <b>record</b>       Comment record 
    104      @return   <b>string</b> 
    105      */ 
    106      public function getStatusMessage($status,$comment_id) 
    107      { 
    108           return sprintf(__('Filtered by %1$s (%2$s)'),$this->guiLink(),$status); 
    109      } 
     102    @param    status        <b>string</b>        Filter status. 
     103    @param    comment_id    <b>record</b>        Comment record 
     104    @return    <b>string</b> 
     105     */ 
     106    public function getStatusMessage($status, $comment_id) 
     107    { 
     108        return sprintf(__('Filtered by %1$s (%2$s)'), $this->guiLink(), $status); 
     109    } 
    110110 
    111      /** 
    112      This method is called when you enter filter configuration. Your class should 
    113      have $has_gui property set to "true" to enable GUI. 
     111    /** 
     112    This method is called when you enter filter configuration. Your class should 
     113    have $has_gui property set to "true" to enable GUI. 
    114114 
    115      In this method you should put everything related to filter configuration. 
    116      $url variable is the URL of GUI <i>unescaped</i>. 
     115    In this method you should put everything related to filter configuration. 
     116    $url variable is the URL of GUI <i>unescaped</i>. 
    117117 
    118      @param    url       <b>string</b>       GUI URL. 
    119      */ 
    120      public function gui($url) 
    121      { 
    122      } 
     118    @param    url        <b>string</b>        GUI URL. 
     119     */ 
     120    public function gui($url) 
     121    { 
     122    } 
    123123 
    124      public function hasGUI() 
    125      { 
    126           if (!$this->core->auth->check('admin',$this->core->blog->id)) { 
    127                return false; 
    128           } 
     124    public function hasGUI() 
     125    { 
     126        if (!$this->core->auth->check('admin', $this->core->blog->id)) { 
     127            return false; 
     128        } 
    129129 
    130           if (!$this->has_gui) { 
    131                return false; 
    132           } 
     130        if (!$this->has_gui) { 
     131            return false; 
     132        } 
    133133 
    134           return true; 
    135      } 
     134        return true; 
     135    } 
    136136 
    137      public function guiURL() 
    138      { 
    139           if (!$this->hasGui()) { 
    140                return false; 
    141           } 
     137    public function guiURL() 
     138    { 
     139        if (!$this->hasGui()) { 
     140            return false; 
     141        } 
    142142 
    143           return $this->gui_url; 
    144      } 
     143        return $this->gui_url; 
     144    } 
    145145 
    146      /** 
    147      Returns a link to filter GUI if exists or only filter name if has_gui 
    148      property is false. 
     146    /** 
     147    Returns a link to filter GUI if exists or only filter name if has_gui 
     148    property is false. 
    149149 
    150      @return   <b>string</b> 
    151      */ 
    152      public function guiLink() 
    153      { 
    154           if (($url = $this->guiURL()) !== false) { 
    155                $url = html::escapeHTML($url); 
    156                $link = '<a href="%2$s">%1$s</a>'; 
    157           } else { 
    158                $link = '%1$s'; 
    159           } 
     150    @return    <b>string</b> 
     151     */ 
     152    public function guiLink() 
     153    { 
     154        if (($url = $this->guiURL()) !== false) { 
     155            $url = html::escapeHTML($url); 
     156            $link = '<a href="%2$s">%1$s</a>'; 
     157        } else { 
     158            $link = '%1$s'; 
     159        } 
    160160 
    161           return sprintf($link,$this->name,$url); 
    162      } 
     161        return sprintf($link, $this->name, $url); 
     162    } 
    163163 
    164      public function help() 
    165      { 
    166      } 
     164    public function help() 
     165    { 
     166    } 
    167167} 
  • plugins/antispam/inc/class.dc.spamfilters.php

    r3159 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcSpamFilters 
    1515{ 
    16      private $filters = array(); 
    17      private $filters_opt = array(); 
    18      private $core; 
     16    private $filters    = array(); 
     17    private $filters_opt = array(); 
     18    private $core; 
    1919 
    20      public function __construct($core) 
    21      { 
    22           $this->core =& $core; 
    23      } 
     20    public function __construct($core) 
     21    { 
     22        $this->core = &$core; 
     23    } 
    2424 
    25      public function init($filters) 
    26      { 
    27           foreach ($filters as $f) 
    28           { 
    29                if (!class_exists($f)) { 
    30                     continue; 
    31                } 
     25    public function init($filters) 
     26    { 
     27        foreach ($filters as $f) { 
     28            if (!class_exists($f)) { 
     29                continue; 
     30            } 
    3231 
    33                $r = new ReflectionClass($f); 
    34                $p = $r->getParentClass(); 
     32            $r = new ReflectionClass($f); 
     33            $p = $r->getParentClass(); 
    3534 
    36                if (!$p || $p->name != 'dcSpamFilter') { 
    37                     continue; 
    38                } 
     35            if (!$p || $p->name != 'dcSpamFilter') { 
     36                continue; 
     37            } 
    3938 
    40                $this->filters[$f] = new $f($this->core); 
    41           } 
     39            $this->filters[$f] = new $f($this->core); 
     40        } 
    4241 
    43           $this->setFilterOpts(); 
    44           if (!empty($this->filters_opt)) { 
    45                uasort($this->filters,array($this,'orderCallBack')); 
    46           } 
    47      } 
     42        $this->setFilterOpts(); 
     43        if (!empty($this->filters_opt)) { 
     44            uasort($this->filters, array($this, 'orderCallBack')); 
     45        } 
     46    } 
    4847 
    49      public function getFilters() 
    50      { 
    51           return $this->filters; 
    52      } 
     48    public function getFilters() 
     49    { 
     50        return $this->filters; 
     51    } 
    5352 
    54      public function isSpam($cur) 
    55      { 
    56           foreach ($this->filters as $fid => $f) 
    57           { 
    58                if (!$f->active) { 
    59                     continue; 
    60                } 
     53    public function isSpam($cur) 
     54    { 
     55        foreach ($this->filters as $fid => $f) { 
     56            if (!$f->active) { 
     57                continue; 
     58            } 
    6159 
    62                $type = $cur->comment_trackback ? 'trackback' : 'comment'; 
    63                $author = $cur->comment_author; 
    64                $email = $cur->comment_email; 
    65                $site = $cur->comment_site; 
    66                $ip = $cur->comment_ip; 
    67                $content = $cur->comment_content; 
    68                $post_id = $cur->post_id; 
     60            $type    = $cur->comment_trackback ? 'trackback' : 'comment'; 
     61            $author = $cur->comment_author; 
     62            $email  = $cur->comment_email; 
     63            $site    = $cur->comment_site; 
     64            $ip      = $cur->comment_ip; 
     65            $content = $cur->comment_content; 
     66            $post_id = $cur->post_id; 
    6967 
    70                $is_spam = $f->isSpam($type,$author,$email,$site,$ip,$content,$post_id,$status); 
     68            $is_spam = $f->isSpam($type, $author, $email, $site, $ip, $content, $post_id, $status); 
    7169 
    72                if ($is_spam === true) { 
    73                     if ($f->auto_delete) { 
    74                          $cur->clean(); 
    75                     } else { 
    76                          $cur->comment_status = -2; 
    77                          $cur->comment_spam_status = $status; 
    78                          $cur->comment_spam_filter = $fid; 
    79                     } 
    80                     return true; 
    81                } elseif ($is_spam === false) { 
    82                     return false; 
    83                } 
    84           } 
     70            if ($is_spam === true) { 
     71                if ($f->auto_delete) { 
     72                    $cur->clean(); 
     73                } else { 
     74                    $cur->comment_status      = -2; 
     75                    $cur->comment_spam_status = $status; 
     76                    $cur->comment_spam_filter = $fid; 
     77                } 
     78                return true; 
     79            } elseif ($is_spam === false) { 
     80                return false; 
     81            } 
     82        } 
    8583 
    86           return false; 
    87      } 
     84        return false; 
     85    } 
    8886 
    89      public function trainFilters($rs,$status,$filter_name) 
    90      { 
    91           foreach ($this->filters as $fid => $f) 
    92           { 
    93                if (!$f->active) { 
    94                     continue; 
    95                } 
     87    public function trainFilters($rs, $status, $filter_name) 
     88    { 
     89        foreach ($this->filters as $fid => $f) { 
     90            if (!$f->active) { 
     91                continue; 
     92            } 
    9693 
    97                $type = $rs->comment_trackback ? 'trackback' : 'comment'; 
    98                $author = $rs->comment_author; 
    99                $email = $rs->comment_email; 
    100                $site = $rs->comment_site; 
    101                $ip = $rs->comment_ip; 
    102                $content = $rs->comment_content; 
     94            $type    = $rs->comment_trackback ? 'trackback' : 'comment'; 
     95            $author = $rs->comment_author; 
     96            $email  = $rs->comment_email; 
     97            $site    = $rs->comment_site; 
     98            $ip      = $rs->comment_ip; 
     99            $content = $rs->comment_content; 
    103100 
    104                $f->trainFilter($status,$filter_name,$type,$author,$email,$site,$ip,$content,$rs); 
    105           } 
    106      } 
     101            $f->trainFilter($status, $filter_name, $type, $author, $email, $site, $ip, $content, $rs); 
     102        } 
     103    } 
    107104 
    108      public function statusMessage($rs,$filter_name) 
    109      { 
    110           $f = isset($this->filters[$filter_name]) ? $this->filters[$filter_name] : null; 
     105    public function statusMessage($rs, $filter_name) 
     106    { 
     107        $f = isset($this->filters[$filter_name]) ? $this->filters[$filter_name] : null; 
    111108 
    112           if ($f === null) 
    113           { 
    114                return __('Unknown filter.'); 
    115           } 
    116           else 
    117           { 
    118                $status = $rs->exists('comment_spam_status') ? $rs->comment_spam_status : null; 
     109        if ($f === null) { 
     110            return __('Unknown filter.'); 
     111        } else { 
     112            $status = $rs->exists('comment_spam_status') ? $rs->comment_spam_status : null; 
    119113 
    120                return $f->getStatusMessage($status,$rs->comment_id); 
    121           } 
    122      } 
     114            return $f->getStatusMessage($status, $rs->comment_id); 
     115        } 
     116    } 
    123117 
    124      public function saveFilterOpts($opts,$global=false) 
    125      { 
    126           $this->core->blog->settings->addNamespace('antispam'); 
    127           if ($global) { 
    128                $this->core->blog->settings->antispam->drop('antispam_filters'); 
    129           } 
    130           $this->core->blog->settings->antispam->put('antispam_filters',$opts,'array','Antispam Filters',true,$global); 
    131      } 
     118    public function saveFilterOpts($opts, $global = false) 
     119    { 
     120        $this->core->blog->settings->addNamespace('antispam'); 
     121        if ($global) { 
     122            $this->core->blog->settings->antispam->drop('antispam_filters'); 
     123        } 
     124        $this->core->blog->settings->antispam->put('antispam_filters', $opts, 'array', 'Antispam Filters', true, $global); 
     125    } 
    132126 
    133      private function setFilterOpts() 
    134      { 
    135           if ($this->core->blog->settings->antispam->antispam_filters !== null) { 
    136                $this->filters_opt = $this->core->blog->settings->antispam->antispam_filters; 
    137           } 
     127    private function setFilterOpts() 
     128    { 
     129        if ($this->core->blog->settings->antispam->antispam_filters !== null) { 
     130            $this->filters_opt = $this->core->blog->settings->antispam->antispam_filters; 
     131        } 
    138132 
    139           # Create default options if needed 
    140           if (!is_array($this->filters_opt)) { 
    141                $this->saveFilterOpts(array(),true); 
    142                $this->filters_opt = array(); 
    143           } 
     133        # Create default options if needed 
     134        if (!is_array($this->filters_opt)) { 
     135            $this->saveFilterOpts(array(), true); 
     136            $this->filters_opt = array(); 
     137        } 
    144138 
    145           foreach ($this->filters_opt as $k => $o) 
    146           { 
    147                if (isset($this->filters[$k]) && is_array($o)) { 
    148                     $this->filters[$k]->active = isset($o[0])?$o[0]:false; 
    149                     $this->filters[$k]->order = isset($o[1])?$o[1]:0; 
    150                     $this->filters[$k]->auto_delete = isset($o[2])?$o[2]:false; 
    151                } 
    152           } 
    153      } 
     139        foreach ($this->filters_opt as $k => $o) { 
     140            if (isset($this->filters[$k]) && is_array($o)) { 
     141                $this->filters[$k]->active      = isset($o[0]) ? $o[0] : false; 
     142                $this->filters[$k]->order       = isset($o[1]) ? $o[1] : 0; 
     143                $this->filters[$k]->auto_delete = isset($o[2]) ? $o[2] : false; 
     144            } 
     145        } 
     146    } 
    154147 
    155      private function orderCallBack($a,$b) 
    156      { 
    157           if ($a->order == $b->order) { 
    158                return 0; 
    159           } 
     148    private function orderCallBack($a, $b) 
     149    { 
     150        if ($a->order == $b->order) { 
     151            return 0; 
     152        } 
    160153 
    161           return $a->order > $b->order ? 1 : -1; 
    162      } 
     154        return $a->order > $b->order ? 1 : -1; 
     155    } 
    163156} 
  • plugins/antispam/inc/lib.dc.antispam.php

    r3627 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcAntispam 
    1515{ 
    16      public static $filters; 
    17  
    18      public static function initFilters() 
    19      { 
    20           global $core; 
    21  
    22           if (!isset($core->spamfilters)) { 
    23                return; 
    24           } 
    25  
    26           self::$filters = new dcSpamFilters($core); 
    27           self::$filters->init($core->spamfilters); 
    28      } 
    29  
    30      public static function isSpam($cur) 
    31      { 
    32           self::initFilters(); 
    33           self::$filters->isSpam($cur); 
    34      } 
    35  
    36      public static function trainFilters($blog,$cur,$rs) 
    37      { 
    38           $status = null; 
    39           # From ham to spam 
    40           if ($rs->comment_status != -2 && $cur->comment_status == -2) { 
    41                $status = 'spam'; 
    42           } 
    43  
    44           # From spam to ham 
    45           if ($rs->comment_status == -2 && $cur->comment_status == 1) { 
    46                $status = 'ham'; 
    47           } 
    48  
    49           # the status of this comment has changed 
    50           if ($status) 
    51           { 
    52                $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 
    53  
    54                self::initFilters(); 
    55                self::$filters->trainFilters($rs,$status,$filter_name); 
    56           } 
    57      } 
    58  
    59      public static function statusMessage($rs) 
    60      { 
    61           if ($rs->exists('comment_status') && $rs->comment_status == -2) 
    62           { 
    63                $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 
    64  
    65                self::initFilters(); 
    66  
    67                return 
    68                '<p><strong>'.__('This comment is a spam:').'</strong> '. 
    69                self::$filters->statusMessage($rs,$filter_name).'</p>'; 
    70           } 
    71      } 
    72  
    73      public static function dashboardIcon($core, $icons) 
    74      { 
    75           if (($count = self::countSpam($core)) > 0) { 
    76                $str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)'); 
    77                $icons['comments'][0] .= '</span></a> <br /><a href="'.$core->adminurl->get('admin.comments',array('status' => '-2')).'"><span>'. 
    78                     sprintf($str,$count); 
    79           } 
    80      } 
    81  
    82      public static function dashboardIconTitle($core) 
    83      { 
    84           if (($count = self::countSpam($core)) > 0) { 
    85                $str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)'); 
    86                return '</span></a> <br /><a href="'.$core->adminurl->get('admin.comments',array('status' => '-2')).'"><span>'. 
    87                     sprintf($str,$count); 
    88           } else { 
    89                return ''; 
    90           } 
    91      } 
    92  
    93      public static function countSpam($core) 
    94      { 
    95           return $core->blog->getComments(array('comment_status'=>-2),true)->f(0); 
    96      } 
    97  
    98      public static function countPublishedComments($core) 
    99      { 
    100           return $core->blog->getComments(array('comment_status'=>1),true)->f(0); 
    101      } 
    102  
    103      public static function delAllSpam($core, $beforeDate = null) 
    104      { 
    105           $strReq = 
    106           'SELECT comment_id '. 
    107           'FROM '.$core->prefix.'comment C '. 
    108           'JOIN '.$core->prefix.'post P ON P.post_id = C.post_id '. 
    109           "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ". 
    110           'AND comment_status = -2 '; 
    111           if ($beforeDate) { 
    112                $strReq .= 'AND comment_dt < \''.$beforeDate.'\' '; 
    113           } 
    114  
    115           $rs = $core->con->select($strReq); 
    116           $r = array(); 
    117           while ($rs->fetch()) { 
    118                $r[] = (integer) $rs->comment_id; 
    119           } 
    120  
    121           if (empty($r)) { 
    122                return; 
    123           } 
    124  
    125           $strReq = 
    126           'DELETE FROM '.$core->prefix.'comment '. 
    127           'WHERE comment_id '.$core->con->in($r).' '; 
    128  
    129           $core->con->execute($strReq); 
    130      } 
    131  
    132      public static function getUserCode($core) 
    133      { 
    134           $code = 
    135           pack('a32',$core->auth->userID()). 
    136           pack('H*',$core->auth->cryptLegacy($core->auth->getInfo('user_pwd'))); 
    137           return bin2hex($code); 
    138      } 
    139  
    140      public static function checkUserCode($core,$code) 
    141      { 
    142           $code = pack('H*',$code); 
    143  
    144           $user_id = trim(@pack('a32',substr($code,0,32))); 
    145           $pwd = @unpack('H*hex',substr($code,32)); 
    146  
    147           if ($user_id === false || $pwd === false) { 
    148                return false; 
    149           } 
    150  
    151           $pwd = $pwd['hex']; 
    152  
    153           $strReq = 'SELECT user_id, user_pwd '. 
    154                     'FROM '.$core->prefix.'user '. 
    155                     "WHERE user_id = '".$core->con->escape($user_id)."' "; 
    156  
    157           $rs = $core->con->select($strReq); 
    158  
    159           if ($rs->isEmpty()) { 
    160                return false; 
    161           } 
    162  
    163           if ($core->auth->cryptLegacy($rs->user_pwd) != $pwd) { 
    164                return false; 
    165           } 
    166  
    167           $permissions = $core->getBlogPermissions($core->blog->id); 
    168  
    169           if ( empty($permissions[$rs->user_id]) ) { 
    170                return false; 
    171           } 
    172  
    173           return $rs->user_id; 
    174      } 
    175  
    176      public static function purgeOldSpam($core) 
    177      { 
    178           $defaultDateLastPurge = time(); 
    179           $defaultModerationTTL = '7'; 
    180           $init = false; 
    181  
    182           // settings 
    183           $core->blog->settings->addNamespace('antispam'); 
    184  
    185           $dateLastPurge = $core->blog->settings->antispam->antispam_date_last_purge; 
    186           if ($dateLastPurge === null) { 
    187                $init = true; 
    188                $core->blog->settings->antispam->put('antispam_date_last_purge',$defaultDateLastPurge,'integer','Antispam Date Last Purge (unix timestamp)',true,false); 
    189                $dateLastPurge = $defaultDateLastPurge; 
    190           } 
    191           $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl; 
    192           if ($moderationTTL === null) { 
    193                $core->blog->settings->antispam->put('antispam_moderation_ttl',$defaultModerationTTL,'integer','Antispam Moderation TTL (days)',true,false); 
    194                $moderationTTL = $defaultModerationTTL; 
    195           } 
    196  
    197           if ($moderationTTL < 0) { 
    198                // disabled 
    199                return; 
    200           } 
    201  
    202           // we call the purge every day 
    203           if ((time()-$dateLastPurge) > (86400)) { 
    204                // update dateLastPurge 
    205                if (!$init) { 
    206                     $core->blog->settings->antispam->put('antispam_date_last_purge',time(),null,null,true,false); 
    207                } 
    208                $date = date('Y-m-d H:i:s', time() - $moderationTTL*86400); 
    209                dcAntispam::delAllSpam($core, $date); 
    210           } 
    211      } 
     16    public static $filters; 
     17 
     18    public static function initFilters() 
     19    { 
     20        global $core; 
     21 
     22        if (!isset($core->spamfilters)) { 
     23            return; 
     24        } 
     25 
     26        self::$filters = new dcSpamFilters($core); 
     27        self::$filters->init($core->spamfilters); 
     28    } 
     29 
     30    public static function isSpam($cur) 
     31    { 
     32        self::initFilters(); 
     33        self::$filters->isSpam($cur); 
     34    } 
     35 
     36    public static function trainFilters($blog, $cur, $rs) 
     37    { 
     38        $status = null; 
     39        # From ham to spam 
     40        if ($rs->comment_status != -2 && $cur->comment_status == -2) { 
     41            $status = 'spam'; 
     42        } 
     43 
     44        # From spam to ham 
     45        if ($rs->comment_status == -2 && $cur->comment_status == 1) { 
     46            $status = 'ham'; 
     47        } 
     48 
     49        # the status of this comment has changed 
     50        if ($status) { 
     51            $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 
     52 
     53            self::initFilters(); 
     54            self::$filters->trainFilters($rs, $status, $filter_name); 
     55        } 
     56    } 
     57 
     58    public static function statusMessage($rs) 
     59    { 
     60        if ($rs->exists('comment_status') && $rs->comment_status == -2) { 
     61            $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 
     62 
     63            self::initFilters(); 
     64 
     65            return 
     66            '<p><strong>' . __('This comment is a spam:') . '</strong> ' . 
     67            self::$filters->statusMessage($rs, $filter_name) . '</p>'; 
     68        } 
     69    } 
     70 
     71    public static function dashboardIcon($core, $icons) 
     72    { 
     73        if (($count = self::countSpam($core)) > 0) { 
     74            $str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)'); 
     75            $icons['comments'][0] .= '</span></a> <br /><a href="' . $core->adminurl->get('admin.comments', array('status' => '-2')) . '"><span>' . 
     76            sprintf($str, $count); 
     77        } 
     78    } 
     79 
     80    public static function dashboardIconTitle($core) 
     81    { 
     82        if (($count = self::countSpam($core)) > 0) { 
     83            $str = ($count > 1) ? __('(including %d spam comments)') : __('(including %d spam comment)'); 
     84            return '</span></a> <br /><a href="' . $core->adminurl->get('admin.comments', array('status' => '-2')) . '"><span>' . 
     85            sprintf($str, $count); 
     86        } else { 
     87            return ''; 
     88        } 
     89    } 
     90 
     91    public static function countSpam($core) 
     92    { 
     93        return $core->blog->getComments(array('comment_status' => -2), true)->f(0); 
     94    } 
     95 
     96    public static function countPublishedComments($core) 
     97    { 
     98        return $core->blog->getComments(array('comment_status' => 1), true)->f(0); 
     99    } 
     100 
     101    public static function delAllSpam($core, $beforeDate = null) 
     102    { 
     103        $strReq = 
     104        'SELECT comment_id ' . 
     105        'FROM ' . $core->prefix . 'comment C ' . 
     106        'JOIN ' . $core->prefix . 'post P ON P.post_id = C.post_id ' . 
     107        "WHERE blog_id = '" . $core->con->escape($core->blog->id) . "' " . 
     108            'AND comment_status = -2 '; 
     109        if ($beforeDate) { 
     110            $strReq .= 'AND comment_dt < \'' . $beforeDate . '\' '; 
     111        } 
     112 
     113        $rs = $core->con->select($strReq); 
     114        $r  = array(); 
     115        while ($rs->fetch()) { 
     116            $r[] = (integer) $rs->comment_id; 
     117        } 
     118 
     119        if (empty($r)) { 
     120            return; 
     121        } 
     122 
     123        $strReq = 
     124        'DELETE FROM ' . $core->prefix . 'comment ' . 
     125        'WHERE comment_id ' . $core->con->in($r) . ' '; 
     126 
     127        $core->con->execute($strReq); 
     128    } 
     129 
     130    public static function getUserCode($core) 
     131    { 
     132        $code = 
     133        pack('a32', $core->auth->userID()) . 
     134        pack('H*', $core->auth->cryptLegacy($core->auth->getInfo('user_pwd'))); 
     135        return bin2hex($code); 
     136    } 
     137 
     138    public static function checkUserCode($core, $code) 
     139    { 
     140        $code = pack('H*', $code); 
     141 
     142        $user_id = trim(@pack('a32', substr($code, 0, 32))); 
     143        $pwd     = @unpack('H*hex', substr($code, 32)); 
     144 
     145        if ($user_id === false || $pwd === false) { 
     146            return false; 
     147        } 
     148 
     149        $pwd = $pwd['hex']; 
     150 
     151        $strReq = 'SELECT user_id, user_pwd ' . 
     152        'FROM ' . $core->prefix . 'user ' . 
     153        "WHERE user_id = '" . $core->con->escape($user_id) . "' "; 
     154 
     155        $rs = $core->con->select($strReq); 
     156 
     157        if ($rs->isEmpty()) { 
     158            return false; 
     159        } 
     160 
     161        if ($core->auth->cryptLegacy($rs->user_pwd) != $pwd) { 
     162            return false; 
     163        } 
     164 
     165        $permissions = $core->getBlogPermissions($core->blog->id); 
     166 
     167        if (empty($permissions[$rs->user_id])) { 
     168            return false; 
     169        } 
     170 
     171        return $rs->user_id; 
     172    } 
     173 
     174    public static function purgeOldSpam($core) 
     175    { 
     176        $defaultDateLastPurge = time(); 
     177        $defaultModerationTTL = '7'; 
     178        $init                 = false; 
     179 
     180        // settings 
     181        $core->blog->settings->addNamespace('antispam'); 
     182 
     183        $dateLastPurge = $core->blog->settings->antispam->antispam_date_last_purge; 
     184        if ($dateLastPurge === null) { 
     185            $init = true; 
     186            $core->blog->settings->antispam->put('antispam_date_last_purge', $defaultDateLastPurge, 'integer', 'Antispam Date Last Purge (unix timestamp)', true, false); 
     187            $dateLastPurge = $defaultDateLastPurge; 
     188        } 
     189        $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl; 
     190        if ($moderationTTL === null) { 
     191            $core->blog->settings->antispam->put('antispam_moderation_ttl', $defaultModerationTTL, 'integer', 'Antispam Moderation TTL (days)', true, false); 
     192            $moderationTTL = $defaultModerationTTL; 
     193        } 
     194 
     195        if ($moderationTTL < 0) { 
     196            // disabled 
     197            return; 
     198        } 
     199 
     200        // we call the purge every day 
     201        if ((time() - $dateLastPurge) > (86400)) { 
     202            // update dateLastPurge 
     203            if (!$init) { 
     204                $core->blog->settings->antispam->put('antispam_date_last_purge', time(), null, null, true, false); 
     205            } 
     206            $date = date('Y-m-d H:i:s', time() - $moderationTTL * 86400); 
     207            dcAntispam::delAllSpam($core, $date); 
     208        } 
     209    } 
    212210} 
  • plugins/antispam/inc/lib.dc.antispam.url.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcAntispamURL extends dcUrlHandlers 
    1515{ 
    16      public static function hamFeed($args) 
    17      { 
    18           self::genFeed('ham',$args); 
    19      } 
     16    public static function hamFeed($args) 
     17    { 
     18        self::genFeed('ham', $args); 
     19    } 
    2020 
    21      public static function spamFeed($args) 
    22      { 
    23           self::genFeed('spam',$args); 
    24      } 
     21    public static function spamFeed($args) 
     22    { 
     23        self::genFeed('spam', $args); 
     24    } 
    2525 
    26      private static function genFeed($type,$args) 
    27      { 
    28           global $core; 
    29           $user_id = dcAntispam::checkUserCode($core,$args); 
     26    private static function genFeed($type, $args) 
     27    { 
     28        global $core; 
     29        $user_id = dcAntispam::checkUserCode($core, $args); 
    3030 
    31           if ($user_id === false) { 
    32                self::p404(); 
    33                return; 
    34           } 
     31        if ($user_id === false) { 
     32            self::p404(); 
     33            return; 
     34        } 
    3535 
    36           $core->auth->checkUser($user_id,null,null); 
     36        $core->auth->checkUser($user_id, null, null); 
    3737 
    38           header('Content-Type: application/xml; charset=UTF-8'); 
     38        header('Content-Type: application/xml; charset=UTF-8'); 
    3939 
    40           $title = $core->blog->name.' - '.__('Spam moderation'). ' - '; 
    41           $params = array(); 
    42           $end_url = ''; 
    43           if ($type == 'spam') { 
    44                $title .= __('Spam'); 
    45                $params['comment_status'] = -2; 
    46                $end_url = '?status=-2'; 
    47           } else { 
    48                $title .= __('Ham'); 
    49                $params['sql'] = ' AND comment_status IN (1,-1) '; 
    50           } 
     40        $title   = $core->blog->name . ' - ' . __('Spam moderation') . ' - '; 
     41        $params = array(); 
     42        $end_url = ''; 
     43        if ($type == 'spam') { 
     44            $title .= __('Spam'); 
     45            $params['comment_status'] = -2; 
     46            $end_url                  = '?status=-2'; 
     47        } else { 
     48            $title .= __('Ham'); 
     49            $params['sql'] = ' AND comment_status IN (1,-1) '; 
     50        } 
    5151 
    52           echo 
    53           '<?xml version="1.0" encoding="utf-8"?>'."\n". 
    54           '<rss version="2.0"'."\n". 
    55           'xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n". 
    56           'xmlns:content="http://purl.org/rss/1.0/modules/content/">'."\n". 
    57           '<channel>'."\n". 
    58           '<title>'.html::escapeHTML($title).'</title>'."\n". 
    59           '<link>'.(DC_ADMIN_URL ? DC_ADMIN_URL.'comments.php'.$end_url : 'about:blank').'</link>'."\n". 
    60           '<description></description>'."\n"; 
     52        echo 
     53        '<?xml version="1.0" encoding="utf-8"?>' . "\n" . 
     54        '<rss version="2.0"' . "\n" . 
     55        'xmlns:dc="http://purl.org/dc/elements/1.1/"' . "\n" . 
     56        'xmlns:content="http://purl.org/rss/1.0/modules/content/">' . "\n" . 
     57        '<channel>' . "\n" . 
     58        '<title>' . html::escapeHTML($title) . '</title>' . "\n" . 
     59            '<link>' . (DC_ADMIN_URL ? DC_ADMIN_URL . 'comments.php' . $end_url : 'about:blank') . '</link>' . "\n" . 
     60            '<description></description>' . "\n"; 
    6161 
    62           $rs = $core->blog->getComments($params); 
    63           $maxitems = 20; 
    64           $nbitems = 0; 
     62        $rs      = $core->blog->getComments($params); 
     63        $maxitems = 20; 
     64        $nbitems = 0; 
    6565 
    66           while ($rs->fetch() && ($nbitems < $maxitems)) 
    67           { 
    68                $nbitems++; 
    69                $uri = DC_ADMIN_URL ? DC_ADMIN_URL.'comment.php?id='.$rs->comment_id : 'about:blank'; 
    70                $author = $rs->comment_author; 
    71                $title = $rs->post_title.' - '.$author; 
    72                if ($type == 'spam') { 
    73                     $title .= '('.$rs->comment_spam_filter.')'; 
    74                } 
    75                $id = $rs->getFeedID(); 
     66        while ($rs->fetch() && ($nbitems < $maxitems)) { 
     67            $nbitems++; 
     68            $uri    = DC_ADMIN_URL ? DC_ADMIN_URL . 'comment.php?id=' . $rs->comment_id : 'about:blank'; 
     69            $author = $rs->comment_author; 
     70            $title  = $rs->post_title . ' - ' . $author; 
     71            if ($type == 'spam') { 
     72                $title .= '(' . $rs->comment_spam_filter . ')'; 
     73            } 
     74            $id = $rs->getFeedID(); 
    7675 
    77                $content = '<p>IP: '.$rs->comment_ip; 
     76            $content = '<p>IP: ' . $rs->comment_ip; 
    7877 
    79                if (trim($rs->comment_site)) { 
    80                     $content .= '<br />URL: <a href="'.$rs->comment_site.'">'.$rs->comment_site.'</a>'; 
    81                } 
    82                $content .= "</p><hr />\n"; 
    83                $content .= $rs->comment_content; 
     78            if (trim($rs->comment_site)) { 
     79                $content .= '<br />URL: <a href="' . $rs->comment_site . '">' . $rs->comment_site . '</a>'; 
     80            } 
     81            $content .= "</p><hr />\n"; 
     82            $content .= $rs->comment_content; 
    8483 
    85                echo 
    86                '<item>'."\n". 
    87                '  <title>'.html::escapeHTML($title).'</title>'."\n". 
    88                '  <link>'.$uri.'</link>'."\n". 
    89                '  <guid>'.$id.'</guid>'."\n". 
    90                '  <pubDate>'.$rs->getRFC822Date().'</pubDate>'."\n". 
    91                '  <dc:creator>'.html::escapeHTML($author).'</dc:creator>'."\n". 
    92                '  <description>'.html::escapeHTML($content).'</description>'."\n". 
    93                '</item>'; 
    94           } 
     84            echo 
     85            '<item>' . "\n" . 
     86            '  <title>' . html::escapeHTML($title) . '</title>' . "\n" . 
     87            '  <link>' . $uri . '</link>' . "\n" . 
     88            '  <guid>' . $id . '</guid>' . "\n" . 
     89            '  <pubDate>' . $rs->getRFC822Date() . '</pubDate>' . "\n" . 
     90            '  <dc:creator>' . html::escapeHTML($author) . '</dc:creator>' . "\n" . 
     91            '  <description>' . html::escapeHTML($content) . '</description>' . "\n" . 
     92                '</item>'; 
     93        } 
    9594 
    96           echo "</channel>\n</rss>"; 
    97      } 
     95        echo "</channel>\n</rss>"; 
     96    } 
    9897} 
  • plugins/antispam/index.php

    r3725 r3730  
    108108    dcPage::jsLoad('js/jquery/jquery-ui.custom.js') . 
    109109    dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') . 
    110     dcPage::jsLoad(dcPage::getPF('antispam/antispam.js')); 
     110    dcPage::jsLoad(dcPage::getPF('antispam/js/antispam.js')); 
    111111} 
    112112echo dcPage::cssLoad(dcPage::getPF('antispam/style.css')); 
  • plugins/antispam/style.css

    r1516 r3730  
    11ul.spaminfo { 
    2      display: block; 
    3      list-style: none; 
    4      margin: 1em 0; 
    5      padding: 0; 
     2  display: block; 
     3  list-style: none; 
     4  margin: 1em 0; 
     5  padding: 0; 
    66} 
    77ul.spaminfo li { 
    8      margin: 0.5em 0; 
    9      padding-left: 16px; 
    10      background-color: transparent; 
    11      background-position: center left; 
    12      background-repeat: no-repeat; 
     8  margin: 0.5em 0; 
     9  padding-left: 16px; 
     10  background-color: transparent; 
     11  background-position: center left; 
     12  background-repeat: no-repeat; 
    1313} 
    1414ul.spaminfo .spamcount { 
    15      background-image: url(images/junk.png); 
     15  background-image: url(images/junk.png); 
    1616} 
    1717ul.spaminfo .hamcount { 
    18      background-image: url(images/check-on.png); 
     18  background-image: url(images/check-on.png); 
    1919} 
    2020ul.spaminfo .feed { 
    21      background-image: url(index.php?pf=antispam/feed.png); 
     21  background-image: url(index.php?pf=antispam/feed.png); 
    2222} 
    2323/* ---------------------------------------------------------- listing of IPs / bad words */ 
     24 
    2425.antispam { 
    25      height: 200px; 
    26      overflow: auto; 
    27      margin-bottom: 1em; 
     26  height: 200px; 
     27  overflow: auto; 
     28  margin-bottom: 1em; 
    2829} 
    2930.antispam p { 
    30      margin: 1px 0 0 0; 
    31      padding: 0.2em 0.5em; 
     31  margin: 1px 0 0 0; 
     32  padding: 0.2em 0.5em; 
    3233} 
    3334.antispam p.global { 
    34      background: #fec; 
     35  background: #fec; 
    3536} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map