Dotclear

source: plugins/antispam/_admin.php @ 2849:97e1b334e54b

Revision 2849:97e1b334e54b, 3.6 KB checked in by Dsls, 11 years ago (diff)

Deprecated $core->adminurl->decode, use $core->adminurl->get instead (with urlencode set to false)

Added dcPage::getPF to shortcut plugin file inclusion

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
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 null;
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>Antispam</h4>'.
94          '<p><label for="antispam_moderation_ttl" class="classic">'.__('Delete junk comments older than').' '.
95          form::field('antispam_moderation_ttl', 3, 3, $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