3
* This file implements the UI controller for the antispam management.
5
* This file is part of the Quam Plures project - {@link http://quamplures.net/}.
6
* See also {@link https://launchpad.net/quam-plures}.
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/}.
11
* @license http://quamplures.net/license.html GNU General Public License (GPL)
13
* {@internal Open Source relicensing agreement:
16
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
18
* @todo Allow applying / re-checking of the known data, not just after an update!
3
* This file implements the UI controller for the antispam management
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
22
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
12
if(!defined('QP_MAIN_INIT')) die('fail');
15
global $aspm_shortened;
17
global $row_stats; // for hit functions
28
global $row_stats; // for hit functions
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') );
34
$Form->hiddens_by_key( get_memorized() );
35
$Form->hidden( 'confirm', 'confirm' );
36
$Form->hidden( 'aspm_source', $aspm_source );
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.'%').'
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) );
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>
62
<table class="grouped" cellspacing="0">
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>
74
load_funcs('sessions/model/_hitlog.funcs.php');
76
foreach( $res_affected_hits as $row_stats )
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>
94
// Check for potentially affected comments:
95
$sql = 'SELECT comment_ID, comment_date, comment_author, comment_author_url,
96
comment_author_IP, comment_content
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
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) );
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>
118
<table class="grouped" cellspacing="0">
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>
132
foreach( $res_affected_comments as $row_stats )
133
{ // TODO: new Comment( $row_stats )
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>
141
$comment_content = strip_tags( $row_stats['comment_content'] );
142
if ( evo_strlen($comment_content) > 70 )
144
// Trail off (truncate and add '...') after 70 chars
145
echo evo_substr($comment_content, 0, 70) . "...";
149
echo $comment_content;
152
<td><?php echo action_icon( T_('Edit...'), 'edit', '?ctrl=comments&action=edit&comment_ID='.$row_stats['comment_ID'] ) ?></td>
162
// Check if the string is already in the blacklist:
163
if( antispam_check($keyword) )
165
printf( '<p><strong>'.T_('The keyword [%s] is already handled by the blacklist.').'</strong></p>', htmlspecialchars($keyword) );
168
{ // Not in blacklist
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>
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') );
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 );
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
39
printf( '<p><strong>'.T_('No log-hits match the keyword [%s].').'</strong></p>', htmlspecialchars( $keyword ) );
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>
50
<table class="grouped" cellspacing="0">
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>
62
load_funcs( 'sessions/model/_hitlog.funcs.php' );
64
foreach( $res_affected_hits as $row_stats )
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>
83
// Check for potentially affected comments
84
$sql = 'SELECT comment_ID, comment_date, comment_author, comment_author_url, comment_author_IP, comment_content
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 )
95
printf( '<p><strong>'.T_('No comments match the keyword [%s].').'</strong></p>', htmlspecialchars( $keyword ) );
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>
106
<table class="grouped" cellspacing="0">
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>
120
foreach( $res_affected_comments as $row_stats )
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>
129
$comment_content = strip_tags( $row_stats['comment_content'] );
130
if( app_strlen( $comment_content ) > 70 ) // Truncate and add '...' after 70 chars
132
echo app_substr( $comment_content, 0, 70 )."...";
136
echo $comment_content;
140
<td><?php echo action_icon( T_('Edit...'), 'edit', '?ctrl=comments&action=edit&comment_ID='.$row_stats['comment_ID'] ) ?></td>
151
// Check if the string is already in the blacklist
152
if( antispam_check( $keyword ) )
154
printf( '<p><strong>'.T_('The keyword [%s] is already handled by the blacklist.').'</strong></p>', htmlspecialchars( $keyword ) );
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>
168
$Form->buttons( array(
181
169
array( '', 'actionArray[ban]', T_('Perform selected operations'), 'DeleteButton' ),
184
171
$Form->end_form();
186
173
// this is when you click a "ban" symbol next to a comment domain
189
176
$offer_shorter = true;
191
178
if( substr( $keyword, 0, 2 ) == '//' )
192
{ // remove and remember leading // characters
180
// remove and remember leading // characters
193
181
$start_char = '//';
194
182
$string = substr( $keyword, 2 );
196
184
elseif( substr( $keyword, 0, 1 ) == '.' )
197
{ // or remove and remember leading . character
186
// or remove and remember leading . character
198
187
$start_char = '.';
199
188
$string = substr( $keyword, 1 );
202
{ // or we're done (this is not from clicking the "ban" symbol)
192
// or we're done (this is not from clicking the "ban" symbol)
203
193
$offer_shorter = false;
206
if( $aspm_source == 'local' )
207
{ // no shortening if the keyword was manually entered
196
if( $aspm_source == 'entered' )
198
// no shortening if the keyword was manually entered
208
199
$offer_shorter = false;
211
202
if( $offer_shorter )
212
{ // count /s and .s and split into elements
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 );
218
210
if( $slash_elements > 1 )
219
{ // we have at least one / so let's shrink from the right...
212
// we have at least one / so let's shrink from the right...
220
213
$new_keyword = '';
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
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
227
220
$new_keyword .= '/';
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...
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;
238
{ // rebuild the keyword from the right to the left
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;