forked from joseconti/WangGuard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwangguard-class-wp-queue.php
More file actions
319 lines (319 loc) · 13.8 KB
/
wangguard-class-wp-queue.php
File metadata and controls
319 lines (319 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/**
* WangGuard Queue Table class.
*
*/require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class WangGuard_Queue_Table extends WP_List_Table {
function WangGuard_Queue_Table() {
global $wp_version;
$cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
$callConstructor = version_compare($cur_wp_version , '3.2.1' , ">=");
if (!$callConstructor) {
parent::WP_List_Table( array('singular' => 'report','plural' => 'reports') );
} else {
parent::__construct( array('singular' => 'report','plural' => 'reports') );
}
}
function prepare_items() {
global $usersearch;
$usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] :
'';
$users_per_page = $this->get_items_per_page( "wangguard_page_wangguard_queue_network_per_page" );
$paged = $this->get_pagenum();
$args = array('number' => $users_per_page,'offset' => ( $paged-1 ) * $users_per_page,'search' => $usersearch,'fields' => 'all_with_meta');
$args['search'] = '*' . $args['search'] . '*';
if ( isset( $_REQUEST['orderby'] ) )$args['orderby'] = $_REQUEST['orderby'];
if ( isset( $_REQUEST['order'] ) )$args['order'] = $_REQUEST['order'];
// Query the user IDs for this page
$wp_user_search = new WangGuard_Queue_Query( $args );
$this->items = $wp_user_search->get_results();
$this->set_pagination_args( array('total_items' => $wp_user_search->get_total(),'per_page' => $users_per_page,) );
}
function no_items() {
_e( 'No reported users or blogs were found.' , 'wangguard' );
}
function get_views() {
global $wpdb;
$url = 'admin.php?page=wangguard_queue';
$requestType = "";
if (isset($_REQUEST['type']))$requestType = $_REQUEST['type'];
$table_name = $wpdb->base_prefix . "wangguardreportqueue";
$Count = $wpdb->get_col( "select count(*) as q from $table_name where ID IS NOT NULL");
$total_users = $Count[0];
$Count = $wpdb->get_col( "select count(*) as q from $table_name where blog_id IS NOT NULL");
$total_blogs = $Count[0];
$class = empty($requestType) ? ' class="current"' :
'';
$total = array();
$total['all'] = "<a href='$url'$class>" . sprintf( __( 'All Reports <span class="count">(%s)</span>' , $total_users, 'wangguard' ), number_format_i18n( $total_users + $total_blogs ) ) . '</a>';
$class = ($requestType == "u") ? ' class="current"' :
'';
$total['reporteducount'] = "<a href='" . add_query_arg( 'type', "u", $url ) . "'$class>".sprintf( __( 'Reported users <span class="count">(%s)</span>' , 'wangguard'), number_format_i18n( $total_users ) )."</a>";
$class = ($requestType == "b") ? ' class="current"' :
'';
$total['reportedbcount'] = "<a href='" . add_query_arg( 'type', "b", $url ) . "'$class>".sprintf( __( 'Reported blogs <span class="count">(%s)</span>' , 'wangguard'), number_format_i18n( $total_blogs ) )."</a>";
return $total;
}
function get_bulk_actions() {
$actions = array();
$actions['unreport'] = __( 'Remove from Queue', 'wangguard' );
$actions['reportassplog'] = __( 'Report as Splogger', 'wangguard' );
return $actions;
}
function extra_tablenav( $which ) {
return;
}
function current_action() {
if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )return 'promote';
return parent::current_action();
}
function get_columns() {
$c = array('cb' => '<input type="checkbox" />','username' => __( 'Username' ),'wgtype' => __( 'Type' , "wangguard" ),'email' => __( 'E-mail' ),'wgreported_by' => __( 'Reported by' , 'wangguard' ),'wgreported_on' => __( 'Reported on' , 'wangguard' ));
return $c;
}
function get_sortable_columns() {
$c = array('username' => 'login','wgtype' => 'wgtype','wgreported_by' => 'wgreported_by','wgreported_on' => 'wgreported_on');
return $c;
}
function display_rows() {
// Query the post counts for this page
$style = '';
foreach ( $this->items as $userid => $row_data ) {
$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
echo "\n\t", $this->single_row( $row_data, $style );
}
}
/**
* Generate HTML for a single row on the users.php admin panel.
*/
function single_row( $row_data, $style = '') {
global $wpdb;
if (!isset($_REQUEST['order'])) {
$_REQUEST['order'] = 'desc';
}
if (!isset($_REQUEST['orderby'])) {
$_REQUEST['orderby'] = 'wgreported_on';
}
$url = admin_url('admin.php?page=wangguard_queue&order='.$_REQUEST['order'].'&orderby='.$_REQUEST['orderby']);
$row_data->reported_by->filter = 'display';
$authors_div = "";
if ( is_a( $row_data, 'WP_User' ) ) {
//USER
$row_data->filter = 'display';
$email = $row_data->user_email;
$checkbox = '';
// Set up the hover actions for this user
$actions = array();
$actions['unreport'] = "<a href='javascript:void(0)' rel='".$row_data->ID."' class='wangguard-queue-remove-user'>" . __( 'Remove from Queue', 'wangguard' ) . "</a>";
if (defined('BP_VERSION')) {
$user_editobj_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=" . $row_data->ID ) );
$editobj_link = esc_url( bp_core_get_user_domain($row_data->ID));
// Set up the hover actions for this user
add_thickbox();
$actions['edituser'] = "<a href='{$user_editobj_link}' target='_blank'>" . __( 'Edit user', 'wangguard' ) . "</a>";
$actions['bpprofile'] = "<a href='{$editobj_link}?TB_iframe=true&width=900&height=550' class='thickbox'>" . __( 'BP Profile', 'wangguard' ) . "</a>";
$report = "<strong><a target=\"_blank\" href=\"$editobj_link\">{$row_data->user_login}</a></strong><br />";
} else {
$editobj_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=" . $row_data->ID ) );
$report = "<strong><a target=\"_blank\" href=\"$editobj_link\">{$row_data->user_login}</a></strong><br />";
}
$report .= $this->row_actions( $actions );
// Set up the checkbox ( because the user is editable, otherwise its empty )
$checkbox = "<input type='checkbox' name='users[]' id='user_{$row_data->ID}' value='{$row_data->ID}' />";
$avatar = get_avatar( $row_data->ID, 32 );
$userid = $row_data->ID;
$statushtml = wangguard_user_custom_columns("" , "wangguardstatus" , $userid);
$rowID = "user-".$userid;
} else {
//BLOG
$checkbox = '';
$editobj_link = network_admin_url("site-info.php?id=$row_data->ID");
$email = $row_data->blog_email;
$authors_links = array();
$blog_prefix = $wpdb->get_blog_prefix( $row_data->ID );
$authors = $wpdb->get_results( "SELECT u.user_login, um.user_id, um.meta_value AS caps FROM $wpdb->users u, $wpdb->usermeta um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities'" );
foreach( (array)$authors as $author ) {
$caps = maybe_unserialize( $author->caps );
if ( !isset( $caps['administrator'] ) ) continue;
$editauthor_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=" . $author->user_id ) );
$authors_links[] = "<a target=\"_blank\" href=\"$editauthor_link\">{$author->user_login}</a>";
}
if (count($authors_links)) {
$authors_div = "<div class=\"row-actions\">" . __("Authors: " , "wangguard") . implode(" | ", $authors_links) . "</div>";
}
$actions = array();
$report = "<strong><a target=\"_blank\" href=\"$editobj_link\">$row_data->user_login</a></strong><br />";
$actions['unreport'] = "<a href='javascript:void(0)' rel='".$row_data->ID."' class='wangguard-queue-remove-blog'>" . __( 'Remove from Queue', 'wangguard' ) . "</a>";
$report .= $this->row_actions( $actions );
// Set up the checkbox ( because the user is editable, otherwise its empty )
$checkbox = "<input type='checkbox' name='blogs[]' id='blog_{$row_data->ID}' value='{$row_data->ID}' />";
$avatar = '';
$statushtml .= "<div class=\"row-actions\">";
$statushtml .= '<a href="javascript:void(0)" rel="'.$row_data->ID.'" class="wangguard-splogger-blog">'.esc_html(__('Report authors as Sploggers', 'wangguard')).'</a>';
$statushtml .= '<br/><a href="'.$row_data->site_url.'" target="_blank">'.esc_html(__('Open blog', 'wangguard')).'</a>';
$statushtml .= "</div>";
$rowID = "blog-".$row_data->ID;
}
$r = "<tr id='$rowID'$style>";
list( $columns, $hidden ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$class = "class=\"$column_name column-$column_name\"";
$style = '';
$attributes = "$class$style";
switch ( $column_name ) {
case 'cb':
$r .= "<th scope='row' class='check-column'>$checkbox</th>";
break;
case 'username':
$r .= "<td $attributes>$avatar $report</td>";
break;
case 'wgtype':
$r .= "<td $attributes>$row_data->wgtype $authors_div</td>";
break;
case 'name':
$r .= "<td $attributes>$row_data->first_name $row_data->last_name</td>";
break;
case 'email':
$r .= "<td $attributes><a href='mailto:$email' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a></td>";
break;
case 'wgreported_by':
$edit_reported_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=" . $row_data->reported_by->ID ) );
$r .= "<td $attributes><a href='$edit_reported_link'>{$row_data->reported_by->user_login}</a></td>";
break;
case 'wgreported_on':
$r .= "<td $attributes>".date(get_option('date_format'), strtotime($row_data->reported_on)) . " " . date(get_option('time_format'), strtotime($row_data->reported_on))."</td>";
break;
case 'wgstatus':
$r .= "<td $attributes>" . $statushtml . "</td>";
break;
}
}
$r .= '</tr>';
return $r;
}
}
class WangGuard_Queue_Query {
/**
* List of found user ids
*/
var $results;
/**
* Total number of found users for the current query
*/
var $total_users = 0;
// SQL clauses
var $query_fields_u;
var $query_from_u;
var $query_where_u;
var $query_fields_b;
var $query_from_b;
var $query_where_b;
var $query_orderby;
var $query_limit;
/**
* PHP4 constructor
*/
function WangGuard_Queue_Query( $query = null ) {
$this->__construct( $query );
}
/**
* PHP5 constructor
* @return WangGuard_Queue_Query
*/
function __construct( $query = null ) {
if ( !empty( $query ) ) {
$this->query_vars = wp_parse_args( $query, array('orderby' => 'login','order' => 'ASC','offset' => '', 'number' => '','count_total' => true) );
$this->prepare_query();
$this->query();
}
}
/**
* Prepare the query variables
*/
function prepare_query() {
global $wpdb;
$requestType = "";
if (isset($_REQUEST['type']))$requestType = $_REQUEST['type'];
$qv = &$this->query_vars;
$tableQueue = $wpdb->base_prefix . "wangguardreportqueue";
$this->query_fields_u = "$wpdb->users.ID , $wpdb->users.user_login , 1 as wgtype , $tableQueue.reported_on as wgreported_on , $tableQueue.reported_by_ID as wgreported_by_ID";
$this->query_from_u = "FROM $wpdb->users JOIN $tableQueue ON $wpdb->users.ID = $tableQueue.ID";
if ($requestType=="b")$this->query_where_u = "WHERE 1=2"; else $this->query_where_u = "WHERE 1=1";
$this->query_fields_b = "$wpdb->blogs.blog_id , CONCAT($wpdb->blogs.domain , $wpdb->blogs.path) as path , 0 as wgtype , $tableQueue.reported_on as wgreported_on , $tableQueue.reported_by_ID as wgreported_by_ID";
$this->query_from_b = "FROM $wpdb->blogs JOIN $tableQueue ON $wpdb->blogs.blog_id = $tableQueue.blog_id";
if ($requestType=="u")$this->query_where_b = "WHERE 1=2"; else $this->query_where_b = "WHERE 1=1";
// sorting
switch ($qv['orderby']) {
case "login":
$orderby = '1';
break;
case "wgreported_by":
$orderby = '5';
break;
case "wgreported_on":
$orderby = '4';
break;
default:
$orderby = '2';
break;
}
$qv['order'] = strtoupper( $qv['order'] );
if ( 'ASC' == $qv['order'] )$order = 'ASC'; else $order = 'DESC';
$this->query_orderby = "ORDER BY $orderby $order";
// limit
if ( $qv['number'] ) {
if ( $qv['offset'] )$this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); else $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
}
//_parse_meta_query( $qv );
}
/**
* Execute the query, with the current variables
*/
function query() {
global $wpdb;
$this->results = $wpdb->get_results("
SELECT $this->query_fields_u $this->query_from_u $this->query_where_u " .(!empty ($wpdb->blogs) ?" UNION ALL SELECT $this->query_fields_b $this->query_from_b $this->query_where_b " : "") ." $this->query_orderby $this->query_limit");
if ( $this->query_vars['count_total'] ) {
$this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from_u $this->query_where_u");
if (!empty ($wpdb->blogs))$this->total_blogs = $wpdb->get_var("SELECT COUNT(*) $this->query_from_b $this->query_where_b"); else $this->total_blogs = 0;
$this->total_users += $this->total_blogs;
}
if ( !$this->results )return;
$r = array();
foreach ( $this->results as $userrow ) {
$userid = $userrow->ID;
if ($userrow->wgtype == 1) {
$r[ "u-".$userid ] = new WP_User( $userid );
$r[ "u-".$userid ]->wgtypeID = 1;
$r[ "u-".$userid ]->wgtype = __("User" , "wangguard");
$r[ "u-".$userid ]->reported_on = $userrow->wgreported_on;
$r[ "u-".$userid ]->reported_by = new WP_User( $userrow->wgreported_by_ID);
} else {
switch_to_blog($userrow->ID);
$email = get_option("admin_email");
$url = get_option("siteurl");
restore_current_blog();
$r[ "b-".$userid ] = new _wangguard_dummy();
$r[ "b-".$userid ]->ID = $userrow->ID;
$r[ "b-".$userid ]->user_login = $userrow->user_login;
$r[ "b-".$userid ]->blog_email = $email;
$r[ "b-".$userid ]->wgtypeID = 0;
$r[ "b-".$userid ]->wgtype = __("Blog" , "wangguard");
$r[ "b-".$userid ]->reported_on = $userrow->wgreported_on;
$r[ "b-".$userid ]->reported_by = new WP_User( $userrow->wgreported_by_ID);
$r[ "b-".$userid ]->site_url = $url;
}
}
$this->results = $r;
}
function get_results() {
return $this->results;
}
function get_total() {
return $this->total_users;
}
}
class _wangguard_dummy {
var $dummy = 1;
}
?>