Dotclear

source: plugins/antispam/inc/class.dc.spamfilter.php @ 0:54703be25dd6

Revision 0:54703be25dd6, 4.0 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

2.3 branch (trunk) first checkin

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for Dotclear 2.
5#
6# Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcSpamFilter
15{
16     public $name;
17     public $description;
18     public $active = true;
19     public $order = 100;
20     public $auto_delete = false;
21     
22     protected $has_gui = false;
23     protected $gui_url = null;
24     
25     protected $core;
26     
27     /**
28     Object constructor
29     
30     @param    core      <b>dcCore</b>       Dotclear core object
31     */
32     public function __construct($core)
33     {
34          $this->core =& $core;
35          $this->setInfo();
36         
37          if (!$this->name) {
38               $this->name = get_class($this);
39          }
40         
41          $this->gui_url = 'plugin.php?p=antispam&f='.get_class($this);
42     }
43     
44     /**
45     This method is called by the constructor and allows you to change some
46     object properties without overloading object constructor.
47     */
48     protected function setInfo()
49     {
50          $this->description = __('No description');
51     }
52     
53     /**
54     This method should return if a comment is a spam or not. If it returns true
55     or false, execution of next filters will be stoped. If should return nothing
56     to let next filters apply.
57     
58     Your filter should also fill $status variable with its own information if
59     comment is a spam.
60     
61     @param         type      <b>string</b>       Comment type (comment or trackback)
62     @param         author    <b>string</b>       Comment author
63     @param         email     <b>string</b>       Comment author email
64     @param         site      <b>string</b>       Comment author website
65     @param         ip        <b>string</b>       Comment author IP address
66     @param         content   <b>string</b>       Comment content
67     @param         post_id   <b>integer</b>      Comment post_id
68     @param[out]    status    <b>integer</b>      Comment status
69     @return   <b>boolean</b>
70     */
71     public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
72     {
73     }
74     
75     /**
76     This method is called when a non-spam (ham) comment becomes spam or when a
77     spam becomes a ham.
78     
79     @param    type      <b>string</b>       Comment type (comment or trackback)
80     @param    filter    <b>string</b>       Filter name
81     @param    author    <b>string</b>       Comment author
82     @param    email     <b>string</b>       Comment author email
83     @param    site      <b>string</b>       Comment author website
84     @param    ip        <b>string</b>       Comment author IP address
85     @param    content   <b>string</b>       Comment content
86     @param    post_url  <b>string</b>       Post URL
87     @param    rs        <b>record</b>       Comment record
88     @return   <b>boolean</b>
89     */
90     public function trainFilter($status,$filter,$type,$author,$email,$site,$ip,$content,$rs)
91     {
92     }
93     
94     /**
95     This method returns filter status message. You can overload this method to
96     return a custom message. Message is shown in comment details and in
97     comments list.
98     
99     @param    status         <b>string</b>       Filter status.
100     @param    comment_id     <b>record</b>       Comment record
101     @return   <b>string</b>
102     */
103     public function getStatusMessage($status,$comment_id)
104     {
105          return sprintf(__('Filtered by %1$s (%2$s)'),$this->guiLink(),$status);
106     }
107     
108     /**
109     This method is called when you enter filter configuration. Your class should
110     have $has_gui property set to "true" to enable GUI.
111     
112     In this method you should put everything related to filter configuration.
113     $url variable is the URL of GUI <i>unescaped</i>.
114     
115     @param    url       <b>string</b>       GUI URL.
116     */
117     public function gui($url)
118     {
119     }
120     
121     public function hasGUI()
122     {
123          if (!$this->core->auth->check('admin',$this->core->blog->id)) {
124               return false;
125          }
126         
127          if (!$this->has_gui) {
128               return false;
129          }
130         
131          return true;
132     }
133     
134     public function guiURL()
135     {
136          if (!$this->hasGui()) {
137               return false;
138          }
139         
140          return $this->gui_url;
141     }
142     
143     /**
144     Returns a link to filter GUI if exists or only filter name if has_gui
145     property is false.
146     
147     @return   <b>string</b>
148     */
149     public function guiLink()
150     {
151          if (($url = $this->guiURL()) !== false) {
152               $url = html::escapeHTML($url);
153               $link = '<a href="%2$s">%1$s</a>';
154          } else {
155               $link = '%1$s';
156          }
157         
158          return sprintf($link,$this->name,$url);
159     }
160}
161?>
Note: See TracBrowser for help on using the repository browser.

Sites map