PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / addons / comments / comments.class.php

comments.class.php in InfiniteWP Client trunk, at addons/comments/comments.class.php

272 lines 9.7 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 *
6 * Get comments
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12 if ( ! defined('ABSPATH') )
13 die();
14 class IWP_MMB_Comment extends IWP_MMB_Core
15 {
16 function __construct()
17 {
18 parent::__construct();
19 }
20
21 function change_status($args)
22 {
23
24 global $wpdb;
25 $comment_id = $args['comment_id'];
26 $status = $args['status'];
27
28 if ( 'approve' == $status )
29 $status_sql = '1';
30 elseif ( 'unapprove' == $status )
31 $status_sql = '0';
32 elseif ( 'spam' == $status )
33 $status_sql = 'spam';
34 elseif ( 'trash' == $status )
35 $status_sql = 'trash';
36 $sql = "update ".$wpdb->base_prefix."comments set comment_approved = '%s' where comment_ID = '%s'";
37 $success = $wpdb->query($wpdb->prepare($sql, $status_sql, $comment_id));
38
39
40 return $success;
41 }
42
43 function get_comments($args){
44
45 global $wpdb;
46
47 $where='';
48
49 extract($args);
50
51 if(!empty($filter_comments))
52 {
53 $where.=" AND (c.comment_author LIKE '%".esc_sql($filter_comments)."%' OR c.comment_content LIKE '%".esc_sql($filter_comments)."%')";
54 }
55 $comment_array = array();
56 $comment_statuses = array('approved', 'pending', 'spam', 'trash');
57 foreach ($args as $checkbox => $checkbox_val)
58 {
59 if($checkbox_val=="on") {
60 $status_val = str_replace("iwp_get_comments_","",$checkbox);
61 if (in_array($status_val, $comment_statuses, true)) {
62 if($status_val == 'approved'){
63 $status_val = 1;
64 }elseif($status_val == 'pending'){
65 $status_val = 0;
66 }
67 $comment_array[] = $status_val;
68 }
69 }
70 }
71 if(!empty($comment_array))
72 {
73 $placeholders = implode(',', array_fill(0, count($comment_array), '%s'));
74 $where .= $wpdb->prepare(" AND c.comment_approved IN ($placeholders)", $comment_array);
75 }
76
77 $sql_query = "$wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID ".$where;
78
79 $comments_total = $wpdb->get_results("SELECT count(*) as total_comments FROM ".$sql_query);
80 $total=$comments_total[0]->total_comments;
81 $comments_approved = $this->comment_total();
82
83 $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");
84 $comments = array();
85 foreach ( $query_comments as $comments_info )
86 {
87 $comment_total_approved = 0;
88 if(isset($comments_approved[$comments_info->comment_post_ID]['approved'])){
89 $comment_total_approved = $comments_approved[$comments_info->comment_post_ID]['approved'];
90 }
91 $comment_total_pending = 0;
92 if(isset($comments_approved[$comments_info->comment_post_ID]['pending'])){
93 $comment_total_pending = $comments_approved[$comments_info->comment_post_ID]['pending'];
94 }
95 $comment_parent_author = '';
96 if($comments_info->comment_parent > 0){
97 $select_parent_author = "SELECT comment_author FROM $wpdb->comments WHERE comment_ID = ".$comments_info->comment_parent;
98 $select_parent_author_res = $wpdb->get_row($select_parent_author);
99 $comment_parent_author = $select_parent_author_res->comment_author;
100 }
101
102 $comments[$comments_info->comment_ID] = array(
103 "comment_post_ID" => $comments_info->comment_post_ID,
104 "comment_author" => $comments_info->comment_author,
105 "comment_author_email" => $comments_info->comment_author_email,
106 "comment_author_url" => $comments_info->comment_author_url,
107 "comment_author_IP" => $comments_info->comment_author_IP,
108 "comment_date" => $comments_info->comment_date,
109 "comment_content" => $comments_info->comment_content,
110 "comment_approved" => $comments_info->comment_approved,
111 "comment_parent" => $comments_info->comment_parent,
112 "comment_parent_author" => $comment_parent_author,
113 "post_title" => $comments_info->post_title,
114 "post_type" => $comments_info->post_type,
115 "guid" => $comments_info->guid,
116 "comment_total_approved" => $comment_total_approved,
117 "comment_total_pending" => $comment_total_pending,
118 );
119 }
120
121 return array('comments' => $comments, 'total' => $total);
122 }
123
124 function comment_total(){
125 global $wpdb;
126 $totals = array();
127 $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";
128 $select_total_approved_res = $wpdb->get_results($select_total_approved);
129
130 if(!empty($select_total_approved_res)){
131 foreach($select_total_approved_res as $row){
132 $totals[$row->ID]['approved'] = $row->total;
133 }
134 }
135 $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";
136 $select_total_pending_res = $wpdb->get_results($select_total_pending);
137 if(!empty($select_total_pending_res)){
138 foreach($select_total_pending_res as $row){
139 $totals[$row->ID]['pending'] = $row->total;
140 }
141 }
142
143 return $totals;
144 }
145
146 function action_comment($args){
147 global $wpdb;
148 extract($args);
149 if($docomaction == 'approve'){
150 $docomaction = '1';
151 }else if($docomaction == 'unapprove' || $docomaction == 'untrash' || $docomaction == 'unspam'){
152 $docomaction = '0';
153 }
154
155 if(!empty($comment_id)){
156 $comment_id = (int)$comment_id;
157 if($docomaction == 'delete'){
158 $update_query = $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d", $comment_id);
159 $delete_query = $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id);
160 $wpdb->query($delete_query);
161 }else{
162 $update_query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID = %d", $docomaction, $comment_id);
163 }
164 $wpdb->query($update_query);
165
166 return 'Comment updated.';
167 }else{
168 return 'No ID...';
169 }
170 }
171
172 function bulk_action_comments($args){
173 global $wpdb;
174 extract($args);
175
176 if(isset($docomaction) && ($docomaction=='unapprove' || $docomaction == 'untrash' || $docomaction == 'unspam')){
177 $docomaction = '0';
178 }else if(isset($docomaction) && $docomaction == 'approve'){
179 $docomaction = '1';
180 }
181
182 foreach($args as $key=>$val){
183
184 if(!empty($val) && is_numeric($val))
185 {
186 $comment_id = (int)$val;
187 if(isset($docomaction) && $docomaction=='delete'){
188 $delete_query = $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id);
189 $wpdb->query($delete_query);
190 $update_query = $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d", $comment_id);
191 }else{
192 $update_query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID = %d", $docomaction, $comment_id);
193 }
194
195 $wpdb->query($update_query);
196 }
197 }
198 return "comments updated";
199 }
200
201 function reply_comment($args){
202 global $wpdb, $current_user;
203
204 extract($args);
205
206 $comments = array();
207
208 if(!empty($comment_id) && !empty($reply_text)){
209 $admins = get_userdata($current_user->ID);
210 $now = time();
211 $insert_reply = $wpdb->prepare(
212 "INSERT INTO $wpdb->comments(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_karma, comment_approved, comment_agent, comment_parent, user_id) VALUES(%d, %s, %s, %s, %s, NOW(), NOW(), %s, 0, 1, %s, %d, %d)",
213 absint($post_id),
214 (string) $admins->user_login,
215 (string) $admins->user_email,
216 (string) $admins->user_url,
217 (string) $_SERVER['REMOTE_ADDR'],
218 (string) $reply_text,
219 (string) $_SERVER['HTTP_USER_AGENT'],
220 absint($comment_id),
221 absint($current_user->ID)
222 );
223 $insert_reply_res = $wpdb->query($insert_reply);
224 $lastid = $wpdb->insert_id;
225
226 $comments_approved = $this->comment_total();
227
228 $comment_total_approved = 0;
229 if(isset($comments_approved[$post_id]['approved'])){
230 $comment_total_approved = $comments_approved[$post_id]['approved'];
231 }
232 $comment_total_pending = 0;
233 if(isset($comments_approved[$post_id]['pending'])){
234 $comment_total_pending = $comments_approved[$post_id]['pending'];
235 }
236
237 $comment_parent_author = '';
238 if($comment_id > 0){
239 $select_parent_author = $wpdb->prepare(
240 "SELECT c.comment_author, p.post_title, p.post_type, p.guid FROM $wpdb->comments as c, $wpdb->posts as p WHERE c.comment_post_ID = p.ID AND c.comment_ID = %d",
241 absint($comment_id)
242 );
243 $select_parent_author_res = $wpdb->get_row($select_parent_author);
244 $comment_parent_author = $select_parent_author_res->comment_author;
245 }
246
247 $comments[$lastid] = array(
248 "comment_post_ID" => $post_id,
249 "comment_author" => $admins->user_login,
250 "comment_author_email" => $admins->user_email,
251 "comment_author_url" => $admins->user_url,
252 "comment_author_IP" => $_SERVER['REMOTE_ADDR'],
253 "comment_date" => $now,
254 "comment_content" => $reply_text,
255 "comment_approved" => '1',
256 "comment_parent" => $comment_id,
257 "comment_parent_author" => $comment_parent_author,
258 "post_title" => $select_parent_author_res->post_title,
259 "post_type" => $select_parent_author_res->post_type,
260 "guid" => $select_parent_author_res->guid,
261 "comment_total_approved" => $comment_total_approved,
262 "comment_total_pending" => $comment_total_pending,
263 );
264
265
266 }
267
268 return $comments;
269 }
270
271 }
272 ?>