PluginProbe
ManageWP Worker / 4.9.16
ManageWP Worker v4.9.16
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MMB / Comment.php

Comment.php in ManageWP Worker 4.9.16, at src/MMB/Comment.php

133 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*************************************************************
4 * comment.class.php
5 * Get comments
6 * Copyright (c) 2011 Prelovac Media
7 * www.prelovac.com
8 **************************************************************/
9 class MMB_Comment extends MMB_Core
10 {
11 public function get_comments($args)
12 {
13 /** @var wpdb $wpdb */
14 global $wpdb;
15
16 $where = '';
17
18 extract($args);
19
20 if (!empty($filter_comments)) {
21 $where .= " AND (c.comment_author LIKE '%".esc_sql($filter_comments)."%' OR c.comment_content LIKE '%".esc_sql($filter_comments)."%')";
22 }
23 $comment_array = array();
24 $comment_statuses = array('approved', 'pending', 'spam', 'trash');
25 foreach ($args as $checkbox => $checkbox_val) {
26 if ($checkbox_val == "on") {
27 $status_val = str_replace("mwp_get_comments_", "", $checkbox);
28 if ($status_val == 'approved') {
29 $status_val = 1;
30 } elseif ($status_val == 'pending') {
31 $status_val = 0;
32 }
33 $comment_array[] = "'".$status_val."'";
34 }
35 }
36 if (!empty($comment_array)) {
37 $where .= " AND c.comment_approved IN (".implode(",", $comment_array).")";
38 }
39
40 $sql_query = "$wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID ".$where;
41
42 $comments_total = $wpdb->get_results("SELECT count(*) as total_comments FROM ".$sql_query);
43 $total = $comments_total[0]->total_comments;
44 $comments_approved = $this->comment_total();
45
46 $query_comments = $wpdb->get_results("SELECT c.comment_ID, c.comment_post_ID, c.comment_author, c.comment_author_email, c.comment_author_url, c.comment_author_IP, c.comment_date, c.comment_content, c.comment_approved, c.comment_parent, p.post_title, p.post_type, p.guid FROM ".$sql_query." ORDER BY c.comment_date DESC LIMIT 500");
47 $comments = array();
48 foreach ($query_comments as $comments_info) {
49 $comment_total_approved = 0;
50 if (isset($comments_approved[$comments_info->comment_post_ID]['approved'])) {
51 $comment_total_approved = $comments_approved[$comments_info->comment_post_ID]['approved'];
52 }
53 $comment_total_pending = 0;
54 if (isset($comments_approved[$comments_info->comment_post_ID]['pending'])) {
55 $comment_total_pending = $comments_approved[$comments_info->comment_post_ID]['pending'];
56 }
57 $comment_parent_author = '';
58 if ($comments_info->comment_parent > 0) {
59 $select_parent_author = "SELECT comment_author FROM $wpdb->comments WHERE comment_ID = ".$comments_info->comment_parent;
60 $select_parent_author_res = $wpdb->get_row($select_parent_author);
61 $comment_parent_author = $select_parent_author_res->comment_author;
62 }
63
64 $comments[$comments_info->comment_ID] = array(
65 "comment_post_ID" => $comments_info->comment_post_ID,
66 "comment_author" => $comments_info->comment_author,
67 "comment_author_email" => $comments_info->comment_author_email,
68 "comment_author_url" => $comments_info->comment_author_url,
69 "comment_author_IP" => $comments_info->comment_author_IP,
70 "comment_date" => $comments_info->comment_date,
71 "comment_content" => htmlspecialchars($comments_info->comment_content),
72 "comment_approved" => $comments_info->comment_approved,
73 "comment_parent" => $comments_info->comment_parent,
74 "comment_parent_author" => $comment_parent_author,
75 "post_title" => htmlspecialchars($comments_info->post_title),
76 "post_type" => $comments_info->post_type,
77 "guid" => $comments_info->guid,
78 "comment_total_approved" => $comment_total_approved,
79 "comment_total_pending" => $comment_total_pending,
80 );
81 }
82
83 return array('comments' => $comments, 'total' => $total);
84 }
85
86 public function comment_total()
87 {
88 /** @var wpdb $wpdb */
89 global $wpdb;
90 $totals = array();
91 $select_total_approved = "SELECT COUNT(*) as total, p.ID FROM $wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID AND c.comment_approved = 1 GROUP BY p.ID";
92 $select_total_approved_res = $wpdb->get_results($select_total_approved);
93
94 if (!empty($select_total_approved_res)) {
95 foreach ($select_total_approved_res as $row) {
96 $totals[$row->ID]['approved'] = $row->total;
97 }
98 }
99 $select_total_pending = "SELECT COUNT(*) as total, p.ID FROM $wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID AND c.comment_approved = 0 GROUP BY p.ID";
100 $select_total_pending_res = $wpdb->get_results($select_total_pending);
101 if (!empty($select_total_pending_res)) {
102 foreach ($select_total_pending_res as $row) {
103 $totals[$row->ID]['pending'] = $row->total;
104 }
105 }
106
107 return $totals;
108 }
109
110 public function bulk_action_comments($args)
111 {
112 $docomaction = $args['docomaction'];
113
114 foreach ($args as $val) {
115 if (!empty($val) && is_numeric($val)) {
116 if ($docomaction == 'delete') {
117 wp_delete_comment($val, true);
118 } elseif ($docomaction == 'unapprove' || $docomaction == 'untrash' || $docomaction == 'unspam') {
119 wp_set_comment_status($val, 'hold');
120 } elseif ($docomaction == 'approve') {
121 wp_set_comment_status($val, 'approve');
122 } elseif ($docomaction == 'spam') {
123 wp_set_comment_status($val, 'spam');
124 } elseif ($docomaction == 'trash') {
125 wp_set_comment_status($val, 'trash');
126 }
127 }
128 }
129
130 return "comments updated";
131 }
132 }
133