~quam-plures-core/quam-plures/file_manager_limits

« back to all changes in this revision

Viewing changes to qp_inc/antispam/views/_ban.form.php

  • Committer: EdB
  • Date: 2013-03-04 07:15:41 UTC
  • mfrom: (7655.1.3 qp5_antispam)
  • Revision ID: 1912webworks@gmail.com-20130304071541-x462crs4d531rh69
http://forums.quamplures.net/viewtopic.php?f=6&t=1887

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
 * This file implements the UI controller for the antispam management.
4
 
 *
5
 
 * This file is part of the Quam Plures project - {@link http://quamplures.net/}.
6
 
 * See also {@link https://launchpad.net/quam-plures}.
7
 
 *
8
 
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
9
 
 * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
10
 
 *
11
 
 * @license http://quamplures.net/license.html GNU General Public License (GPL)
12
 
 *
13
 
 * {@internal Open Source relicensing agreement:
14
 
 * }}
15
 
 *
16
 
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
17
 
 *
18
 
 * @todo Allow applying / re-checking of the known data, not just after an update!
19
 
 *
20
 
 * @package pond
 
3
 * This file implements the UI controller for the antispam management
 
4
 *
 
5
 * @uses antispam_check()
 
6
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
7
 * @author {@link http://fplanque.net/ Francois PLANQUE}
 
8
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
9
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 
10
 * @package antispam
21
11
 */
22
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
12
if(!defined('QP_MAIN_INIT')) die('fail');
23
13
 
 
14
global $aspm_source;
 
15
global $aspm_shortened;
 
16
global $keyword;
 
17
global $row_stats; // for hit functions
24
18
global $Settings;
25
 
global $keyword;
26
 
global $aspm_source;
27
 
 
28
 
global $row_stats;      // for hit functions
29
19
 
30
20
$Form = new Form( NULL, 'antispam_ban', 'post', 'compact' );
31
 
$Form->global_icon( T_('Cancel!'), 'close', regenerate_url( 'action' ) );
32
 
$Form->begin_form( 'fform',  T_('Confirm ban & delete') );
33
 
        $Form->hidden_ctrl();
34
 
        $Form->hiddens_by_key( get_memorized() );
35
 
        $Form->hidden( 'confirm', 'confirm' );
36
 
        $Form->hidden( 'aspm_source', $aspm_source );
37
 
 
38
 
        // Check for junk:
39
 
 
40
 
        // Check for potentially affected logged hits:
41
 
        $sql = 'SELECT hit_ID, UNIX_TIMESTAMP(hit_datetime) as hit_datetime, hit_uri, hit_referer, dom_name,
42
 
                                                                        hit_blog_ID, hit_remote_addr, blog_shortname
43
 
                                         FROM T_hitlog INNER JOIN T_basedomains ON hit_referer_dom_ID = dom_ID
44
 
                                                                LEFT JOIN T_blogs ON hit_blog_ID = blog_ID
45
 
                                        WHERE hit_referer LIKE '.$DB->quote('%'.$keyword.'%').'
46
 
                                        ORDER BY dom_name ASC
47
 
                                        LIMIT 500';
48
 
        $res_affected_hits = $DB->get_results( $sql, ARRAY_A );
49
 
        if( $DB->num_rows == 0 )
50
 
        { // No matching hits.
51
 
                printf( '<p><strong>'.T_('No log-hits match the keyword [%s].').'</strong></p>', htmlspecialchars($keyword) );
52
 
        }
53
 
        else
54
 
        {
55
 
        ?>
56
 
                <p>
57
 
                        <input type="checkbox" name="delhits" id="delhits_cb" value="1" checked="checked" />
58
 
                        <label for="delhits_cb">
59
 
                        <strong><?php printf ( T_('Delete the following %s referer hits:'), $DB->num_rows == 500 ? '500+' : $DB->num_rows ) ?></strong>
60
 
                        </label>
61
 
                </p>
62
 
                <table class="grouped" cellspacing="0">
63
 
                        <thead>
64
 
                        <tr>
65
 
                                <th class="firstcol"><?php echo T_('Date') ?></th>
66
 
                                <th><?php echo T_('Referer') ?></th>
67
 
                                <th><?php echo T_('Ref. IP') ?></th>
68
 
                                <th><?php echo T_('Target Blog') ?></th>
69
 
                                <th><?php echo T_('Target URL') ?></th>
70
 
                        </tr>
71
 
                        </thead>
72
 
                        <tbody>
73
 
                        <?php
74
 
                        load_funcs('sessions/model/_hitlog.funcs.php');
75
 
                        $count = 0;
76
 
                        foreach( $res_affected_hits as $row_stats )
77
 
                        {
78
 
                                ?>
79
 
                                <tr class="<?php echo ($count%2 == 1) ? 'odd' : 'even' ?>">
80
 
                                        <td class="firstcol"><?php stats_time() ?></td>
81
 
                                        <td><a href="<?php stats_referer() ?>"><?php stats_basedomain() ?></a></td>
82
 
                                        <td><?php stats_hit_remote_addr() ?></td>
83
 
                                        <td><?php echo format_to_output( $row_stats['blog_shortname'], 'htmlbody' ); ?></td>
84
 
                                        <td><?php disp_url( $row_stats['hit_uri'], 50 ); ?></td>
85
 
                                </tr>
86
 
                                <?php
87
 
                                $count++;
88
 
                        } ?>
89
 
                        </tbody>
90
 
                </table>
91
 
        <?php
92
 
        }
93
 
 
94
 
        // Check for potentially affected comments:
95
 
        $sql = 'SELECT comment_ID, comment_date, comment_author, comment_author_url,
96
 
                                                                        comment_author_IP, comment_content
97
 
                                                FROM T_comments
98
 
                                         WHERE comment_author LIKE '.$DB->quote('%'.$keyword.'%').'
99
 
                                                                 OR comment_author_email LIKE '.$DB->quote('%'.$keyword.'%').'
100
 
                                                                 OR comment_author_url LIKE '.$DB->quote('%'.$keyword.'%').'
101
 
                                         OR comment_content LIKE '.$DB->quote('%'.$keyword.'%').'
102
 
                                         ORDER BY comment_date ASC
103
 
                                         LIMIT 500';
104
 
        $res_affected_comments = $DB->get_results( $sql, ARRAY_A, 'Find matching comments' );
105
 
        if( $DB->num_rows == 0 )
106
 
        { // No matching hits.
107
 
                printf( '<p><strong>'.T_('No comments match the keyword [%s].').'</strong></p>', htmlspecialchars($keyword) );
108
 
        }
109
 
        else
110
 
        {
111
 
        ?>
112
 
                <p>
113
 
                        <input type="checkbox" name="delcomments" id="delcomments_cb" value="1" checked="checked" />
114
 
                        <label for="delcomments_cb">
115
 
                        <strong><?php printf ( T_('Delete the following %s comments:'), $DB->num_rows == 500 ? '500+' : $DB->num_rows ) ?></strong>
116
 
                        </label>
117
 
                </p>
118
 
                <table class="grouped" cellspacing="0">
119
 
                        <thead>
120
 
                        <tr>
121
 
                                <th class="firstcol"><?php echo T_('Date') ?></th>
122
 
                                <th><?php echo T_('Author') ?></th>
123
 
                                <th><?php echo T_('Auth. URL') ?></th>
124
 
                                <th><?php echo T_('Auth. IP') ?></th>
125
 
                                <th><?php echo T_('Content starts with...') ?></th>
126
 
                                <th><?php echo T_('Action') ?></th>
127
 
                        </tr>
128
 
                        </thead>
129
 
                        <tbody>
130
 
                        <?php
131
 
                        $count = 0;
132
 
                        foreach( $res_affected_comments as $row_stats )
133
 
                        { // TODO: new Comment( $row_stats )
134
 
                                ?>
135
 
                                <tr class="<?php echo ($count%2 == 1) ? 'odd' : 'even' ?>">
136
 
                                <td class="firstcol"><?php echo mysql2date(locale_datefmt().' '.locale_timefmt(), $row_stats['comment_date'] ); ?></td>
137
 
                                <td><?php echo $row_stats['comment_author'] ?></td>
138
 
                                <td><?php disp_url( $row_stats['comment_author_url'], 50 ); ?></td>
139
 
                                <td><?php echo $row_stats['comment_author_IP'] ?></td>
140
 
                                <td><?php
141
 
                                $comment_content = strip_tags( $row_stats['comment_content'] );
142
 
                                if ( evo_strlen($comment_content) > 70 )
143
 
                                {
144
 
                                        // Trail off (truncate and add '...') after 70 chars
145
 
                                        echo evo_substr($comment_content, 0, 70) . "...";
146
 
                                }
147
 
                                else
148
 
                                {
149
 
                                        echo $comment_content;
150
 
                                }
151
 
                                ?></td>
152
 
                                <td><?php echo action_icon( T_('Edit...'), 'edit', '?ctrl=comments&amp;action=edit&amp;comment_ID='.$row_stats['comment_ID'] ) ?></td>
153
 
                                </tr>
154
 
                                <?php
155
 
                        $count++;
156
 
                        } ?>
157
 
                        </tbody>
158
 
                </table>
159
 
        <?php
160
 
        }
161
 
 
162
 
        // Check if the string is already in the blacklist:
163
 
        if( antispam_check($keyword) )
164
 
        { // Already there:
165
 
                printf( '<p><strong>'.T_('The keyword [%s] is already handled by the blacklist.').'</strong></p>', htmlspecialchars($keyword) );
166
 
        }
167
 
        else
168
 
        { // Not in blacklist
169
 
                ?>
170
 
                <p>
171
 
                <input type="checkbox" name="blacklist_locally" id="blacklist_locally_cb" value="1" checked="checked" />
172
 
                <label for="blacklist_locally_cb">
173
 
                        <strong><?php printf ( T_('Blacklist the keyword [%s] locally.'), htmlspecialchars($keyword) ) ?></strong>
174
 
                </label>
175
 
                </p>
176
 
 
177
 
                <?php
178
 
        }
179
 
 
180
 
        $Form->buttons( array(
 
21
$Form->global_icon( T_('Cancel!'), 'close', regenerate_url( 'action' ), T_('cancel'), 3, 4 );
 
22
$Form->begin_form( 'fform', T_('Confirm ban & delete') );
 
23
$Form->hidden_ctrl();
 
24
$Form->hiddens_by_key( get_memorized() );
 
25
$Form->hidden( 'confirm', 'confirm' );
 
26
$Form->hidden( 'aspm_source', $aspm_source );
 
27
$Form->hidden( 'aspm_shortened', $aspm_shortened );
 
28
 
 
29
// Check for potentially affected logged hits:
 
30
$sql = 'SELECT hit_ID, UNIX_TIMESTAMP(hit_datetime) as hit_datetime, hit_uri, hit_referer, dom_name,
 
31
        hit_blog_ID, hit_remote_addr, blog_shortname
 
32
        FROM T_hitlog INNER JOIN T_basedomains ON hit_referer_dom_ID = dom_ID
 
33
        LEFT JOIN T_blogs ON hit_blog_ID = blog_ID
 
34
        WHERE hit_referer LIKE '.$DB->quote( '%'.$keyword.'%' ).'
 
35
        ORDER BY dom_name ASC LIMIT 500';
 
36
$res_affected_hits = $DB->get_results( $sql, ARRAY_A );
 
37
if( $DB->num_rows == 0 ) // No matching hits
 
38
{
 
39
        printf( '<p><strong>'.T_('No log-hits match the keyword [%s].').'</strong></p>', htmlspecialchars( $keyword ) );
 
40
}
 
41
else
 
42
{
 
43
        ?>
 
44
        <p>
 
45
        <input type="checkbox" name="delhits" id="delhits_cb" value="1" checked="checked" />
 
46
        <label for="delhits_cb">
 
47
        <strong><?php printf ( T_('Delete the following %s referer hits:'), $DB->num_rows == 500 ? '500+' : $DB->num_rows ) ?></strong>
 
48
        </label>
 
49
        </p>
 
50
        <table class="grouped" cellspacing="0">
 
51
        <thead>
 
52
        <tr>
 
53
        <th class="firstcol"><?php echo T_('Date') ?></th>
 
54
        <th><?php echo T_('Referer') ?></th>
 
55
        <th><?php echo T_('Ref. IP') ?></th>
 
56
        <th><?php echo T_('Target Blog') ?></th>
 
57
        <th><?php echo T_('Target URL') ?></th>
 
58
        </tr>
 
59
        </thead>
 
60
        <tbody>
 
61
        <?php
 
62
        load_funcs( 'sessions/model/_hitlog.funcs.php' );
 
63
        $count = 0;
 
64
        foreach( $res_affected_hits as $row_stats )
 
65
        {
 
66
                ?>
 
67
                <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even' ?>">
 
68
                <td class="firstcol"><?php stats_time() ?></td>
 
69
                <td><a href="<?php stats_referer() ?>"><?php stats_basedomain() ?></a></td>
 
70
                <td><?php stats_hit_remote_addr() ?></td>
 
71
                <td><?php echo format_to_output( $row_stats['blog_shortname'], 'htmlbody' ); ?></td>
 
72
                <td><?php disp_url( $row_stats['hit_uri'], 50 ); ?></td>
 
73
                </tr>
 
74
                <?php
 
75
                $count++;
 
76
        }
 
77
        ?>
 
78
        </tbody>
 
79
        </table>
 
80
        <?php
 
81
}
 
82
 
 
83
// Check for potentially affected comments
 
84
$sql = 'SELECT comment_ID, comment_date, comment_author, comment_author_url, comment_author_IP, comment_content
 
85
        FROM T_comments
 
86
        WHERE comment_author LIKE '.$DB->quote( '%'.$keyword.'%' ).'
 
87
        OR comment_author_email LIKE '.$DB->quote( '%'.$keyword.'%' ).'
 
88
        OR comment_author_url LIKE '.$DB->quote( '%'.$keyword.'%' ).'
 
89
        OR comment_content LIKE '.$DB->quote( '%'.$keyword.'%' ).'
 
90
        ORDER BY comment_date ASC LIMIT 500';
 
91
$res_affected_comments = $DB->get_results( $sql, ARRAY_A, 'Find matching comments' );
 
92
if( $DB->num_rows == 0 )
 
93
{
 
94
        // No matching hits.
 
95
        printf( '<p><strong>'.T_('No comments match the keyword [%s].').'</strong></p>', htmlspecialchars( $keyword ) );
 
96
}
 
97
else
 
98
{
 
99
        ?>
 
100
        <p>
 
101
        <input type="checkbox" name="delcomments" id="delcomments_cb" value="1" checked="checked" />
 
102
        <label for="delcomments_cb">
 
103
        <strong><?php printf ( T_('Delete the following %s comments:'), $DB->num_rows == 500 ? '500+' : $DB->num_rows ) ?></strong>
 
104
        </label>
 
105
        </p>
 
106
        <table class="grouped" cellspacing="0">
 
107
        <thead>
 
108
        <tr>
 
109
        <th class="firstcol"><?php echo T_('Date') ?></th>
 
110
        <th><?php echo T_('Author') ?></th>
 
111
        <th><?php echo T_('Auth. URL') ?></th>
 
112
        <th><?php echo T_('Auth. IP') ?></th>
 
113
        <th><?php echo T_('Content starts with...') ?></th>
 
114
        <th><?php echo T_('Action') ?></th>
 
115
        </tr>
 
116
        </thead>
 
117
        <tbody>
 
118
        <?php
 
119
        $count = 0;
 
120
        foreach( $res_affected_comments as $row_stats )
 
121
        {
 
122
                ?>
 
123
                <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even' ?>">
 
124
                <td class="firstcol"><?php echo mysql2date(locale_datefmt().' '.locale_timefmt(), $row_stats['comment_date'] ); ?></td>
 
125
                <td><?php echo $row_stats['comment_author'] ?></td>
 
126
                <td><?php disp_url( $row_stats['comment_author_url'], 50 ); ?></td>
 
127
                <td><?php echo $row_stats['comment_author_IP'] ?></td>
 
128
                <td><?php
 
129
                $comment_content = strip_tags( $row_stats['comment_content'] );
 
130
                if( app_strlen( $comment_content ) > 70 ) // Truncate and add '...' after 70 chars
 
131
                {
 
132
                        echo app_substr( $comment_content, 0, 70 )."...";
 
133
                }
 
134
                else
 
135
                {
 
136
                        echo $comment_content;
 
137
                }
 
138
                ?>
 
139
                </td>
 
140
                <td><?php echo action_icon( T_('Edit...'), 'edit', '?ctrl=comments&amp;action=edit&amp;comment_ID='.$row_stats['comment_ID'] ) ?></td>
 
141
                </tr>
 
142
                <?php
 
143
                $count++;
 
144
        }
 
145
        ?>
 
146
        </tbody>
 
147
        </table>
 
148
        <?php
 
149
}
 
150
 
 
151
// Check if the string is already in the blacklist
 
152
if( antispam_check( $keyword ) )
 
153
{
 
154
        printf( '<p><strong>'.T_('The keyword [%s] is already handled by the blacklist.').'</strong></p>', htmlspecialchars( $keyword ) );
 
155
}
 
156
else
 
157
{
 
158
        ?>
 
159
        <p>
 
160
        <input type="checkbox" name="blacklist_locally" id="blacklist_locally_cb" value="1" checked="checked" />
 
161
        <label for="blacklist_locally_cb">
 
162
        <strong><?php printf ( T_('Blacklist the keyword [%s] locally.'), htmlspecialchars( $keyword ) ) ?></strong>
 
163
        </label>
 
164
        </p>
 
165
        <?php
 
166
}
 
167
 
 
168
$Form->buttons( array(
181
169
                array( '', 'actionArray[ban]', T_('Perform selected operations'), 'DeleteButton' ),
182
 
        ) );
183
 
 
 
170
) );
184
171
$Form->end_form();
185
172
 
186
173
// this is when you click a "ban" symbol next to a comment domain
189
176
$offer_shorter = true;
190
177
 
191
178
if( substr( $keyword, 0, 2 ) == '//' )
192
 
{ // remove and remember leading // characters
 
179
{
 
180
        // remove and remember leading // characters
193
181
        $start_char = '//';
194
182
        $string = substr( $keyword, 2 );
195
183
}
196
184
elseif( substr( $keyword, 0, 1 ) == '.' )
197
 
{ // or remove and remember leading . character
 
185
{
 
186
        // or remove and remember leading . character
198
187
        $start_char = '.';
199
188
        $string = substr( $keyword, 1 );
200
189
}
201
190
else
202
 
{ // or we're done (this is not from clicking the "ban" symbol)
 
191
{
 
192
        // or we're done (this is not from clicking the "ban" symbol)
203
193
        $offer_shorter = false;
204
194
}
205
195
 
206
 
if( $aspm_source == 'local' )
207
 
{ // no shortening if the keyword was manually entered
 
196
if( $aspm_source == 'entered' )
 
197
{
 
198
        // no shortening if the keyword was manually entered
208
199
        $offer_shorter = false;
209
200
}
210
201
 
211
202
if( $offer_shorter )
212
 
{ // count /s and .s and split into elements
 
203
{
 
204
        // count /s and .s and split into elements
213
205
        $string_slash_array = explode( '/', $string );
214
206
        $slash_elements = count( $string_slash_array );
215
207
        $string_dot_array = explode( '.', $string_slash_array[0] );
216
208
        $dot_elements = count( $string_dot_array );
217
209
 
218
210
        if( $slash_elements > 1 )
219
 
        { // we have at least one / so let's shrink from the right...
 
211
        {
 
212
                // we have at least one / so let's shrink from the right...
220
213
                $new_keyword = '';
221
214
                $ii = 0;
222
 
                while( $ii < $slash_elements-2 )
223
 
                { // rebuild the keyword from the left to the right
 
215
                while( $ii < $slash_elements-2 ) // rebuild the keyword from the left to the right
 
216
                {
224
217
                        $new_keyword .= $string_slash_array[$ii];
225
 
                        if( $slash_elements > 3 )
226
 
                        { // add a trailing / unless we are down to domain.com
 
218
                        if( $slash_elements > 3 ) // add a trailing / unless we are down to domain.com
 
219
                        {
227
220
                                $new_keyword .= '/';
228
221
                        }
229
222
                        $ii++;
230
223
                }
231
224
        }
232
 
 
233
225
        elseif( $dot_elements > 2 )
234
 
        { // no /s to work on and we have at least one . so let's shrink from the left...
 
226
        {
 
227
                // no /s to work on and we have at least one . so let's shrink from the left...
235
228
                $new_keyword = '';
236
229
                $ii = $dot_elements-1;
237
230
                while( $ii )
238
 
                { // rebuild the keyword from the right to the left
 
231
                {
 
232
                        // rebuild the keyword from the right to the left
239
233
                        $new_keyword = $string_dot_array[$ii].$new_keyword;
240
234
                        $new_keyword = '.'.$new_keyword;
241
235
                        $ii--;
243
237
                // whatever $start_char was, it got removed with the first subdo
244
238
                $start_char = '';
245
239
        }
246
 
 
247
 
        else
248
 
        { // no /s or .s so the form is not displayed
 
240
        else // no /s or .s so the form is not displayed
 
241
        {
249
242
                $offer_shorter = false;
250
243
        }
251
244
 
252
245
        $new_keyword = $start_char.$new_keyword;
253
 
 
254
246
}
255
247
 
 
248
// offer to check and ban a shortened version of the original keyword
256
249
if( $offer_shorter )
257
 
{ // offer to check and ban a shortened version of the original keyword
 
250
{
258
251
        $Form = new Form( NULL, 'antispam_add', 'post', 'compact' );
259
252
        $Form->begin_form( 'fform', T_('Cast a wider net?') );
260
253
        $Form->hidden_ctrl();
261
254
        $Form->hidden( 'action', 'ban' );
262
 
        $Form->hidden( 'aspm_source', 'central' ); // central means modified
263
255
        $Form->hidden( 'keyword', $new_keyword );
 
256
        $Form->hidden( 'aspm_shortened', '1' );
264
257
        $Form->info( T_('Check this instead'), $new_keyword, '<br />'.T_('Check this shorter version of the URL you clicked to ban') );
265
 
        $Form->end_form( array( array( 'submit', 'submit', T_('Check & ban...'), 'SaveButton' ) ) );
 
258
        $Form->end_form( array(
 
259
                array( 'submit', 'submit', T_('Check & ban...'), 'SaveButton' ),
 
260
        ) );
266
261
}
267
262
 
268
263
?>