[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief antispam, a plugin for Dotclear 2 |
---|
| 4 | * |
---|
| 5 | * @package Dotclear |
---|
| 6 | * @subpackage Plugins |
---|
| 7 | * |
---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 9 | * @copyright GPL-2.0-only |
---|
| 10 | */ |
---|
| 11 | |
---|
[3730] | 12 | if (!defined('DC_RC_PATH')) {return;} |
---|
[0] | 13 | |
---|
| 14 | class dcSpamFilter |
---|
| 15 | { |
---|
[3730] | 16 | public $name; |
---|
| 17 | public $description; |
---|
| 18 | public $active = true; |
---|
| 19 | public $order = 100; |
---|
| 20 | public $auto_delete = false; |
---|
| 21 | public $help = null; |
---|
[2566] | 22 | |
---|
[3730] | 23 | protected $has_gui = false; |
---|
| 24 | protected $gui_url = null; |
---|
[2566] | 25 | |
---|
[3730] | 26 | protected $core; |
---|
[2566] | 27 | |
---|
[3730] | 28 | /** |
---|
| 29 | Object constructor |
---|
[2566] | 30 | |
---|
[3730] | 31 | @param core <b>dcCore</b> Dotclear core object |
---|
| 32 | */ |
---|
| 33 | public function __construct($core) |
---|
| 34 | { |
---|
| 35 | $this->core = &$core; |
---|
| 36 | $this->setInfo(); |
---|
[2566] | 37 | |
---|
[3730] | 38 | if (!$this->name) { |
---|
| 39 | $this->name = get_class($this); |
---|
| 40 | } |
---|
[2566] | 41 | |
---|
[3730] | 42 | if ($core && isset($core->adminurl)) { |
---|
[3874] | 43 | $this->gui_url = $core->adminurl->get('admin.plugin.antispam', ['f' => get_class($this)], '&'); |
---|
[3730] | 44 | } |
---|
| 45 | } |
---|
[2566] | 46 | |
---|
[3730] | 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 | } |
---|
[2566] | 55 | |
---|
[3730] | 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. |
---|
[2566] | 60 | |
---|
[3730] | 61 | Your filter should also fill $status variable with its own information if |
---|
| 62 | comment is a spam. |
---|
[2566] | 63 | |
---|
[3730] | 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 | } |
---|
[2566] | 77 | |
---|
[3730] | 78 | /** |
---|
| 79 | This method is called when a non-spam (ham) comment becomes spam or when a |
---|
| 80 | spam becomes a ham. |
---|
[2566] | 81 | |
---|
[3730] | 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 | } |
---|
[2566] | 96 | |
---|
[3730] | 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. |
---|
[2566] | 101 | |
---|
[3730] | 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 | } |
---|
[2566] | 110 | |
---|
[3730] | 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. |
---|
[2566] | 114 | |
---|
[3730] | 115 | In this method you should put everything related to filter configuration. |
---|
| 116 | $url variable is the URL of GUI <i>unescaped</i>. |
---|
[2566] | 117 | |
---|
[3730] | 118 | @param url <b>string</b> GUI URL. |
---|
| 119 | */ |
---|
| 120 | public function gui($url) |
---|
| 121 | { |
---|
| 122 | } |
---|
[2566] | 123 | |
---|
[3730] | 124 | public function hasGUI() |
---|
| 125 | { |
---|
| 126 | if (!$this->core->auth->check('admin', $this->core->blog->id)) { |
---|
| 127 | return false; |
---|
| 128 | } |
---|
[2566] | 129 | |
---|
[3730] | 130 | if (!$this->has_gui) { |
---|
| 131 | return false; |
---|
| 132 | } |
---|
[2566] | 133 | |
---|
[3730] | 134 | return true; |
---|
| 135 | } |
---|
[2566] | 136 | |
---|
[3730] | 137 | public function guiURL() |
---|
| 138 | { |
---|
| 139 | if (!$this->hasGui()) { |
---|
| 140 | return false; |
---|
| 141 | } |
---|
[2566] | 142 | |
---|
[3730] | 143 | return $this->gui_url; |
---|
| 144 | } |
---|
[2566] | 145 | |
---|
[3730] | 146 | /** |
---|
| 147 | Returns a link to filter GUI if exists or only filter name if has_gui |
---|
| 148 | property is false. |
---|
[2566] | 149 | |
---|
[3730] | 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 | } |
---|
[2566] | 160 | |
---|
[3730] | 161 | return sprintf($link, $this->name, $url); |
---|
| 162 | } |
---|
[2322] | 163 | |
---|
[3730] | 164 | public function help() |
---|
| 165 | { |
---|
| 166 | } |
---|
[0] | 167 | } |
---|