| 1 | <?php |
|---|
| 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 | |
|---|
| 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 | if ($core && isset($core->adminurl)) { |
|---|
| 43 | $this->gui_url = $core->adminurl->get('admin.plugin.antispam', array('f' => get_class($this)), '&'); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 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 | } |
|---|
| 55 | |
|---|
| 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. |
|---|
| 60 | |
|---|
| 61 | Your filter should also fill $status variable with its own information if |
|---|
| 62 | comment is a spam. |
|---|
| 63 | |
|---|
| 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 | } |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | This method is called when a non-spam (ham) comment becomes spam or when a |
|---|
| 80 | spam becomes a ham. |
|---|
| 81 | |
|---|
| 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 | } |
|---|
| 96 | |
|---|
| 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. |
|---|
| 101 | |
|---|
| 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 | } |
|---|
| 110 | |
|---|
| 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. |
|---|
| 114 | |
|---|
| 115 | In this method you should put everything related to filter configuration. |
|---|
| 116 | $url variable is the URL of GUI <i>unescaped</i>. |
|---|
| 117 | |
|---|
| 118 | @param url <b>string</b> GUI URL. |
|---|
| 119 | */ |
|---|
| 120 | public function gui($url) |
|---|
| 121 | { |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | public function hasGUI() |
|---|
| 125 | { |
|---|
| 126 | if (!$this->core->auth->check('admin', $this->core->blog->id)) { |
|---|
| 127 | return false; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | if (!$this->has_gui) { |
|---|
| 131 | return false; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | return true; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public function guiURL() |
|---|
| 138 | { |
|---|
| 139 | if (!$this->hasGui()) { |
|---|
| 140 | return false; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | return $this->gui_url; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | /** |
|---|
| 147 | Returns a link to filter GUI if exists or only filter name if has_gui |
|---|
| 148 | property is false. |
|---|
| 149 | |
|---|
| 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 | } |
|---|
| 160 | |
|---|
| 161 | return sprintf($link, $this->name, $url); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | public function help() |
|---|
| 165 | { |
|---|
| 166 | } |
|---|
| 167 | } |
|---|