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