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