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