C:\xampp\htdocs\landing\wp-content\plugins\wp-optimize\optimizations\spam.php


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
<?php

if (!defined('WPO_VERSION')) die('No direct access allowed');

class 
WP_Optimization_spam extends WP_Optimization {

    public 
$available_for_auto true;
    
    public 
$auto_default true;

    public 
$setting_default true;

    public 
$available_for_saving true;

    public 
$ui_sort_order 3500;

    protected 
$dom_id 'clean-comments';

    protected 
$setting_id 'spams';

    protected 
$auto_id 'spams';

    private 
$processed_spam_count;

    private 
$processed_trash_count;

    private 
$found_spam_count;

    private 
$found_trash_count;

    
/**
     * Prepare data for preview widget.
     *
     * @param array $params
     *
     * @return array
     */
    
public function preview($params) {

        
// get clicked comment type link.
        
$type = isset($params['type']) && 'spam' == $params['type'] ? 'spam' 'trash';

        
$retention_subquery '';

        if (
'true' == $this->retention_enabled) {
            
$retention_subquery ' and comment_date < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }

        
// get data requested for preview.
        
$sql $this->wpdb->prepare(
            
"SELECT comment_ID, comment_author, SUBSTR(comment_content, 1, 128) AS comment_content FROM".
            
" `" $this->wpdb->comments "`".
            
" WHERE comment_approved = '{$type}'".
            
$retention_subquery.
            
" ORDER BY `comment_ID` LIMIT %d, %d;",
            array(
                
$params['offset'],
                
$params['limit'],
            )
        );

        
$posts $this->wpdb->get_results($sqlARRAY_A);

        
// fix empty revision titles.
        
if (!empty($posts)) {
            foreach (
$posts as $key => $post) {
                
$posts[$key]['post_title'] = array(
                    
'text' => '' == $post['post_title'] ? '('.__('no title''wp-optimize').')' $post['post_title'],
                    
'url' => get_edit_post_link($post['ID']),
                );
            }
        }

        
// get total count comments for optimization.
        
$sql "SELECT COUNT(*) FROM `" $this->wpdb->comments "` WHERE comment_approved = '{$type}' ".$retention_subquery.";";

        
$total $this->wpdb->get_var($sql);

        return array(
            
'id_key' => 'comment_ID',
            
'columns' => array(
                
'comment_ID' => __('ID''wp-optimize'),
                
'comment_author' => __('Author''wp-optimize'),
                
'comment_content' => __('Comment''wp-optimize'),
            ),
            
'offset' => $params['offset'],
            
'limit' => $params['limit'],
            
'total' => $total,
            
'data' => $this->htmlentities_array($posts, array('comment_ID')),
            
'message' => $total '' __('No spam or trashed comments found''wp-optimize'),
        );
    }

    
/**
     * Do actions before optimize() function.
     */
    
public function before_optimize() {
        
$this->processed_spam_count 0;
        
$this->processed_trash_count 0;
    }

    
/**
     * Do actions after optimize() function.
     */
    
public function after_optimize() {
        
$message sprintf(_n('%s spam comment deleted''%s spam comments deleted'$this->processed_spam_count'wp-optimize'), number_format_i18n($this->processed_spam_count));
        
$message1 sprintf(_n('%s comment removed from Trash''%s comments removed from Trash'$this->processed_trash_count'wp-optimize'), number_format_i18n($this->processed_trash_count));


        if (
$this->is_multisite_mode()) {
            
$blogs_count_text sprintf(_n('across %s site''across %s sites'count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));

            
$message .= ' '.$blogs_count_text;
            
$message1 .= ' '.$blogs_count_text;
        }

        
$this->logger->info($message);
        
$this->logger->info($message1);

        
$this->register_output($message);
        
$this->register_output($message1);
    }

    
/**
     * Do optimization.
     */
    
public function optimize() {
        
// remove spam comments.

        
$this->processed_spam_count += $this->get_count_comments('spam');
        
$this->delete_comments_by_type('spam');

        
$this->processed_trash_count += $this->get_count_comments('trash');
        
$this->delete_comments_by_type('trash');
    }

    
/**
     * Delete comments by $type along with comments meta from database.
     *
     * @param string $type comment type.
     * @return array
     */
    
public function delete_comments_by_type($type) {
        
$clean "DELETE c, cm FROM `" $this->wpdb->comments "` c LEFT JOIN `" $this->wpdb->commentmeta "` cm ON c.comment_ID = cm.comment_id WHERE c.comment_approved = '{$type}'";

        if (
'true' == $this->retention_enabled) {
            
$clean .= ' and c.comment_date < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }

        
// if posted ids in params, then remove only selected items. used by preview widget.
        
if (isset($this->data['ids'])) {
            
$clean .= ' AND c.comment_ID in ('.join(','$this->data['ids']).')';
        }

        
$clean .= ';';
        return 
$this->query($clean);
    }

    
/**
     * Do actions before get_info() function.
     */
    
public function before_get_info() {
        
$this->found_spam_count 0;
        
$this->found_trash_count 0;
    }

    
/**
     * Do actions after get_info() function.
     */
    
public function after_get_info() {

        if (
$this->found_spam_count 0) {
            
$message sprintf(_n('%s spam comment found''%s spam comments found'$this->found_spam_count'wp-optimize'), number_format_i18n($this->found_spam_count));

            
// if current version is not premium and Preview feature not supported then
            // add to message Review link to comments page
            
if (!WP_Optimize::is_premium()) {
                
$message .= ' | <a id="wp-optimize-edit-comments-spam" href="'.admin_url('edit-comments.php?comment_status=spam').'">'.' '.__('Review''wp-optimize').'</a>';
            }

        } else {
            
$message __('No spam comments found''wp-optimize');
        }

        if (
$this->found_trash_count 0) {
            
$message1 sprintf(_n('%s trashed comment found''%s trashed comments found'$this->found_trash_count'wp-optimize'), number_format_i18n($this->found_trash_count));

            
// if current version is not premium and Preview feature not supported then
            // add to message Review link to comments page
            
if (!WP_Optimize::is_premium()) {
                
$message1 .= ' | <a id="wp-optimize-edit-comments-trash" href="'.admin_url('edit-comments.php?comment_status=trash').'">'.' '.__('Review''wp-optimize').'</a>';
            }
        } else {
            
$message1 __('No trashed comments found''wp-optimize');
        }

        if (
$this->is_multisite_mode()) {
            
$blogs_count_text sprintf(_n('across %s site''across %s sites'count($this->blogs_ids), 'wp-optimize'), count($this->blogs_ids));

            
$message .= ' '.$blogs_count_text;
            
$message1 .= ' '.$blogs_count_text;
        }

        
// add preview link to message.
        
if ($this->found_spam_count 0) {
            
$message $this->get_preview_link($message, array('data-type' => 'spam'));
        }

        
// add preview link to message.
        
if ($this->found_trash_count 0) {
            
$message1 $this->get_preview_link($message1, array('data-type' => 'trash'));
        }

        
$this->register_output($message);
        
$this->register_output($message1);
    }

    
/**
     * Count records those can be optimized.
     */
    
public function get_info() {
        
$this->found_spam_count += $this->get_count_comments('spam');
        
$this->found_trash_count += $this->get_count_comments('trash');
    }

    
/**
     * Returns count comments by $type.
     *
     * @param string $type comment type.
     * @return mixed
     */
    
public function get_count_comments($type) {
        
$sql "SELECT COUNT(*) FROM `" $this->wpdb->comments "` WHERE comment_approved = '{$type}'";
        if (
'true' == $this->retention_enabled) {
            
$sql .= ' and comment_date < NOW() - INTERVAL ' $this->retention_period ' WEEK';
        }
        
$sql .= ';';

        return 
$this->wpdb->get_var($sql);
    }

    
/**
     * Do actions after get_info() function.
     */
    
public function settings_label() {
    
        if (
'true' == $this->retention_enabled) {
            return 
sprintf(__('Remove spam and trashed comments which are older than %d weeks''wp-optimize'), $this->retention_period);
        } else {
            return 
__('Remove spam and trashed comments''wp-optimize');
        }
    }

    public function 
get_auto_option_description() {
        return 
__('Remove spam and trashed comments''wp-optimize');
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586