[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 | |
---|
[3725] | 12 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
[0] | 13 | |
---|
| 14 | if (!defined('DC_ANTISPAM_CONF_SUPER')) { |
---|
[3725] | 15 | define('DC_ANTISPAM_CONF_SUPER', false); |
---|
[0] | 16 | } |
---|
| 17 | |
---|
[2823] | 18 | $_menu['Plugins']->addItem(__('Antispam'), |
---|
[3725] | 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)); |
---|
[0] | 23 | |
---|
[3874] | 24 | $core->addBehavior('coreAfterCommentUpdate', ['dcAntispam', 'trainFilters']); |
---|
| 25 | $core->addBehavior('adminAfterCommentDesc', ['dcAntispam', 'statusMessage']); |
---|
| 26 | $core->addBehavior('adminDashboardIcons', ['dcAntispam', 'dashboardIcon']); |
---|
| 27 | $core->addBehavior('adminDashboardHeaders', ['dcAntispam', 'dashboardHeaders']); |
---|
[0] | 28 | |
---|
[3725] | 29 | $core->addBehavior('adminDashboardFavorites', 'antispamDashboardFavorites'); |
---|
| 30 | $core->addBehavior('adminDashboardFavsIcon', 'antispamDashboardFavsIcon'); |
---|
[3] | 31 | |
---|
[3725] | 32 | function antispamDashboardFavorites($core, $favs) |
---|
[3] | 33 | { |
---|
[3874] | 34 | $favs->register('antispam', [ |
---|
[3725] | 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'), |
---|
[3874] | 39 | 'permissions' => 'admin'] |
---|
[3725] | 40 | ); |
---|
[3] | 41 | } |
---|
| 42 | |
---|
[3725] | 43 | function antispamDashboardFavsIcon($core, $name, $icon) |
---|
[203] | 44 | { |
---|
[3725] | 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 | } |
---|
[203] | 53 | } |
---|
| 54 | |
---|
[0] | 55 | if (!DC_ANTISPAM_CONF_SUPER || $core->auth->isSuperAdmin()) { |
---|
[3874] | 56 | $core->addBehavior('adminBlogPreferencesForm', ['antispamBehaviors', 'adminBlogPreferencesForm']); |
---|
| 57 | $core->addBehavior('adminBeforeBlogSettingsUpdate', ['antispamBehaviors', 'adminBeforeBlogSettingsUpdate']); |
---|
| 58 | $core->addBehavior('adminCommentsSpamForm', ['antispamBehaviors', 'adminCommentsSpamForm']); |
---|
| 59 | $core->addBehavior('adminPageHelpBlock', ['antispamBehaviors', 'adminPageHelpBlock']); |
---|
[0] | 60 | } |
---|
| 61 | |
---|
| 62 | class antispamBehaviors |
---|
| 63 | { |
---|
[3725] | 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 | } |
---|
[2329] | 78 | |
---|
[3725] | 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 | } |
---|
[1052] | 89 | |
---|
[3725] | 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') . ' ' . |
---|
[3790] | 96 | form::number('antispam_moderation_ttl', -1, 999, $ttl) . |
---|
[3725] | 97 | ' ' . __('days') . |
---|
| 98 | '</label></p>' . |
---|
[3790] | 99 | '<p class="form-note">' . __('Set -1 to disabled this feature ; Leave empty to use default 7 days delay.') . '</p>' . |
---|
[3725] | 100 | '<p><a href="' . $core->adminurl->get('admin.plugin.antispam') . '">' . __('Set spam filters.') . '</a></p>' . |
---|
| 101 | '</div>'; |
---|
| 102 | } |
---|
[2566] | 103 | |
---|
[3725] | 104 | public static function adminBeforeBlogSettingsUpdate($settings) |
---|
| 105 | { |
---|
| 106 | $settings->addNamespace('antispam'); |
---|
| 107 | $settings->antispam->put('antispam_moderation_ttl', (integer) $_POST['antispam_moderation_ttl']); |
---|
| 108 | } |
---|
[0] | 109 | } |
---|