Dotclear

source: plugins/antispam/_admin.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 3.9 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Simplify licence block at the beginning of each file

Line 
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
12if (!defined('DC_CONTEXT_ADMIN')) {return;}
13
14if (!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
28$core->addBehavior('adminDashboardFavorites', 'antispamDashboardFavorites');
29$core->addBehavior('adminDashboardFavsIcon', 'antispamDashboardFavsIcon');
30
31function antispamDashboardFavorites($core, $favs)
32{
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    );
40}
41
42function antispamDashboardFavsIcon($core, $name, $icon)
43{
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    }
52}
53
54if (!DC_ANTISPAM_CONF_SUPER || $core->auth->isSuperAdmin()) {
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'));
59}
60
61class antispamBehaviors
62{
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    }
77
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    }
88
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    }
101
102    public static function adminBeforeBlogSettingsUpdate($settings)
103    {
104        $settings->addNamespace('antispam');
105        $settings->antispam->put('antispam_moderation_ttl', (integer) $_POST['antispam_moderation_ttl']);
106    }
107}
Note: See TracBrowser for help on using the repository browser.

Sites map