| 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_CONTEXT_ADMIN')) {return;} |
|---|
| 13 | |
|---|
| 14 | if (!defined('DC_ANTISPAM_CONF_SUPER')) { |
|---|
| 15 | define('DC_ANTISPAM_CONF_SUPER', false); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | $_menu['Plugins']->addItem(__('Antispam'), |
|---|
| 19 | $core->adminurl->get('admin.plugin.antispam'), |
|---|
| 20 | dcPage::getPF('antispam/icon.png'), |
|---|
| 21 | preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.antispam')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), |
|---|
| 22 | $core->auth->check('admin', $core->blog->id)); |
|---|
| 23 | |
|---|
| 24 | $core->addBehavior('coreAfterCommentUpdate', array('dcAntispam', 'trainFilters')); |
|---|
| 25 | $core->addBehavior('adminAfterCommentDesc', array('dcAntispam', 'statusMessage')); |
|---|
| 26 | $core->addBehavior('adminDashboardIcons', array('dcAntispam', 'dashboardIcon')); |
|---|
| 27 | $core->addBehavior('adminDashboardHeaders', array('dcAntispam', 'dashboardHeaders')); |
|---|
| 28 | |
|---|
| 29 | $core->addBehavior('adminDashboardFavorites', 'antispamDashboardFavorites'); |
|---|
| 30 | $core->addBehavior('adminDashboardFavsIcon', 'antispamDashboardFavsIcon'); |
|---|
| 31 | |
|---|
| 32 | function antispamDashboardFavorites($core, $favs) |
|---|
| 33 | { |
|---|
| 34 | $favs->register('antispam', array( |
|---|
| 35 | 'title' => __('Antispam'), |
|---|
| 36 | 'url' => $core->adminurl->get('admin.plugin.antispam'), |
|---|
| 37 | 'small-icon' => dcPage::getPF('antispam/icon.png'), |
|---|
| 38 | 'large-icon' => dcPage::getPF('antispam/icon-big.png'), |
|---|
| 39 | 'permissions' => 'admin') |
|---|
| 40 | ); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | function antispamDashboardFavsIcon($core, $name, $icon) |
|---|
| 44 | { |
|---|
| 45 | // Check if it is comments favs |
|---|
| 46 | if ($name == 'comments') { |
|---|
| 47 | // Hack comments title if there is at least one spam |
|---|
| 48 | $str = dcAntispam::dashboardIconTitle($core); |
|---|
| 49 | if ($str != '') { |
|---|
| 50 | $icon[0] .= $str; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | if (!DC_ANTISPAM_CONF_SUPER || $core->auth->isSuperAdmin()) { |
|---|
| 56 | $core->addBehavior('adminBlogPreferencesForm', array('antispamBehaviors', 'adminBlogPreferencesForm')); |
|---|
| 57 | $core->addBehavior('adminBeforeBlogSettingsUpdate', array('antispamBehaviors', 'adminBeforeBlogSettingsUpdate')); |
|---|
| 58 | $core->addBehavior('adminCommentsSpamForm', array('antispamBehaviors', 'adminCommentsSpamForm')); |
|---|
| 59 | $core->addBehavior('adminPageHelpBlock', array('antispamBehaviors', 'adminPageHelpBlock')); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | class antispamBehaviors |
|---|
| 63 | { |
|---|
| 64 | public static function adminPageHelpBlock($blocks) |
|---|
| 65 | { |
|---|
| 66 | $found = false; |
|---|
| 67 | foreach ($blocks as $block) { |
|---|
| 68 | if ($block == 'core_comments') { |
|---|
| 69 | $found = true; |
|---|
| 70 | break; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | if (!$found) { |
|---|
| 74 | return; |
|---|
| 75 | } |
|---|
| 76 | $blocks[] = 'antispam_comments'; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public static function adminCommentsSpamForm($core) |
|---|
| 80 | { |
|---|
| 81 | $ttl = $core->blog->settings->antispam->antispam_moderation_ttl; |
|---|
| 82 | if ($ttl != null && $ttl >= 0) { |
|---|
| 83 | echo '<p>' . sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $ttl) . ' ' . |
|---|
| 84 | sprintf(__('You can modify this duration in the %s'), '<a href="' . $core->adminurl->get('admin.blog.pref') . |
|---|
| 85 | '#antispam_moderation_ttl"> ' . __('Blog settings') . '</a>') . |
|---|
| 86 | '.</p>'; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | public static function adminBlogPreferencesForm($core, $settings) |
|---|
| 91 | { |
|---|
| 92 | $ttl = $settings->antispam->antispam_moderation_ttl; |
|---|
| 93 | echo |
|---|
| 94 | '<div class="fieldset"><h4 id="antispam_params">Antispam</h4>' . |
|---|
| 95 | '<p><label for="antispam_moderation_ttl" class="classic">' . __('Delete junk comments older than') . ' ' . |
|---|
| 96 | form::number('antispam_moderation_ttl', -1, 999, $ttl) . |
|---|
| 97 | ' ' . __('days') . |
|---|
| 98 | '</label></p>' . |
|---|
| 99 | '<p class="form-note">' . __('Set -1 to disabled this feature ; Leave empty to use default 7 days delay.') . '</p>' . |
|---|
| 100 | '<p><a href="' . $core->adminurl->get('admin.plugin.antispam') . '">' . __('Set spam filters.') . '</a></p>' . |
|---|
| 101 | '</div>'; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | public static function adminBeforeBlogSettingsUpdate($settings) |
|---|
| 105 | { |
|---|
| 106 | $settings->addNamespace('antispam'); |
|---|
| 107 | $settings->antispam->put('antispam_moderation_ttl', (integer) $_POST['antispam_moderation_ttl']); |
|---|
| 108 | } |
|---|
| 109 | } |
|---|