Optimize Database after Deleting Revisions - Version 4.7.2

Version Description

[11/12/2018] = * BUG FIX: Fixed a MySQL query

Download this release

Release Info

Developer cageehv
Plugin Icon 128x128 Optimize Database after Deleting Revisions
Version 4.7.2
Comparing to
See all releases

Code changes from version 4.7.1 to 4.7.2

Files changed (3) hide show
  1. classes/odb-cleaner.php +1737 -1737
  2. readme.txt +5 -2
  3. rvg-optimize-database.php +4 -4
classes/odb-cleaner.php CHANGED
@@ -1,1738 +1,1738 @@
1
- <?php
2
- /************************************************************************************************
3
- *
4
- * CLEANER CLASS: DOING THE REAL CLEANING / OPTIMIZATION
5
- *
6
- ************************************************************************************************/
7
- ?>
8
- <?php
9
- class ODB_Cleaner {
10
- var $start_size;
11
- var $nr_of_optimized_tables;
12
-
13
-
14
- /********************************************************************************************
15
- * CONSTRUCTOR
16
- ********************************************************************************************/
17
- function __construct() {
18
- } // __construct()
19
-
20
-
21
- /********************************************************************************************
22
- * RUN CLEANER
23
- ********************************************************************************************/
24
- function odb_run_cleaner($scheduler, $analyzing = false) {
25
- global $odb_class;
26
-
27
- if(!$scheduler) {
28
- if ($analyzing) {
29
- echo '
30
- <div id="odb-cleaner" class="odb-padding-left">
31
- <div class="odb-title-bar">
32
- <h2>'.__('Analyzing Database', $odb_class->odb_txt_domain).'</h2>
33
- </div>
34
- <br>
35
- <br>
36
- ';
37
- } else {
38
- echo '
39
- <div id="odb-cleaner" class="odb-padding-left">
40
- <div class="odb-title-bar">
41
- <h2>'.__('Cleaning Database', $odb_class->odb_txt_domain).'</h2>
42
- </div>
43
- <br>
44
- <br>
45
- ';
46
- }
47
- } // if(!$scheduler)
48
-
49
- // GET THE SIZE OF THE DATABASE BEFORE OPTIMIZATION
50
- $this->start_size = $odb_class->odb_utilities_obj->odb_get_db_size();
51
-
52
- // TIMESTAMP FOR LOG FILE - v4.6
53
- $ct = ($scheduler) ? ' (cron)' : '';
54
-
55
- $odb_class->log_arr["timestamp"] = current_time('YmdHis', 0);
56
- $odb_class->log_arr["after"] = 0;
57
- $odb_class->log_arr["before"] = 0;
58
- $odb_class->log_arr["orphans"] = 0;
59
- $odb_class->log_arr["pingbacks"] = 0;
60
- $odb_class->log_arr["oembeds"] = 0;
61
- $odb_class->log_arr["orphans"] = 0;
62
- $odb_class->log_arr["revisions"] = 0;
63
- $odb_class->log_arr["savings"] = 0;
64
- $odb_class->log_arr["spam"] = 0;
65
- $odb_class->log_arr["tables"] = 0;
66
- $odb_class->log_arr["tags"] = 0;
67
- $odb_class->log_arr["transients"] = 0;
68
- $odb_class->log_arr["trash"] = 0;
69
-
70
- /****************************************************************************************
71
- * DELETE REVISIONS
72
- ****************************************************************************************/
73
- if($odb_class->odb_rvg_options['delete_older'] == 'Y' || $odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
74
- // FIND REVISIONS
75
- $results_older_than = array();
76
- if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
77
- $results_older_than = $this->odb_get_revisions_older_than();
78
- }
79
-
80
- $results_keep_revisions = array();
81
- if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
82
- $results_keep_revisions = $this->odb_get_revisions_keep_revisions();
83
- }
84
-
85
- $total_deleted = 0;
86
- if(count($results_older_than) > 0 || count($results_keep_revisions) > 0) {
87
- // WE HAVE REVISIONS TO DELETE!
88
- if(!$scheduler) {
89
- if ($analyzing) {
90
- $msg1 = __('REVISIONS','rvg-optimize-database');
91
- $msg2 = __('revisions', $odb_class->odb_txt_domain);
92
- } else {
93
- $msg1 = __('DELETED REVISIONS','rvg-optimize-database');
94
- $msg2 = __('revisions deleted', $odb_class->odb_txt_domain);
95
- }
96
- ?>
97
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
98
- <tr>
99
- <td colspan="4"><div class="odb-found"><?php echo $msg1?></div></td>
100
- </tr>
101
- <tr>
102
- <th align="right" class="odb-border-bottom">#</th>
103
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
104
- <th align="left" class="odb-border-bottom"><?php _e('post / page', $odb_class->odb_txt_domain);?></th>
105
- <th align="left" class="odb-border-bottom"><?php _e('revision date', $odb_class->odb_txt_domain);?></th>
106
- <th align="right" class="odb-border-bottom"><?php echo $msg2?></th>
107
- </tr>
108
- <?php
109
- } // if(!$scheduler)
110
-
111
- // LOOP THROUGH THE REVISIONS AND DELETE THEM
112
- $total_deleted = $this->odb_delete_revisions($scheduler, $analyzing);
113
-
114
- if(!$scheduler) {
115
- if ($analyzing) {
116
- $msg1 = __('total number of revisions', $odb_class->odb_txt_domain);
117
- } else {
118
- $msg1 = __('total number of revisions deleted', $odb_class->odb_txt_domain);
119
- } // if (!$analyzing)
120
- ?>
121
- <tr>
122
- <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg1 ?>: <?php echo $total_deleted?></td>
123
- </tr>
124
- </table>
125
- <?php
126
- } // if(!$scheduler)
127
- } else {
128
- if(!$scheduler) {
129
- ?>
130
- <div class="odb-not-found">
131
- <?php _e('No REVISIONS found to delete', $odb_class->odb_txt_domain);?>
132
- </div>
133
- <?php
134
- } // if(!$scheduler)
135
- } // if(count($results)>0)
136
-
137
- // NUMBER OF DELETED REVISIONS FOR LOG FILE
138
- $odb_class->log_arr["revisions"] = $total_deleted;
139
- } // if($odb_class->odb_rvg_options['delete_older'] == 'Y' || $odb_class->odb_rvg_options['rvg_revisions'] == 'Y')
140
-
141
-
142
- /****************************************************************************************
143
- * DELETE TRASHED ITEMS
144
- ****************************************************************************************/
145
- if($odb_class->odb_rvg_options['clear_trash'] == 'Y') {
146
- // GET TRASHED POSTS / PAGES AND COMMENTS
147
- $results = $this->odb_get_trash($analyzing);
148
-
149
- $total_deleted = 0;
150
- if(count($results)>0) {
151
- // WE HAVE TRASH TO DELETE!
152
- if(!$scheduler) {
153
- if ($analyzing) {
154
- $msg1 = __('TRASHED ITEMS', $odb_class->odb_txt_domain);
155
- $msg2 = __('total number of trashed items', $odb_class->odb_txt_domain);
156
- } else {
157
- $msg1 = __('DELETED TRASHED ITEMS', $odb_class->odb_txt_domain);
158
- $msg2 = __('total number of trashed items deleted', $odb_class->odb_txt_domain);
159
- } // if ($analyzing)
160
- ?>
161
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
162
- <tr>
163
- <td colspan="4"><div class="odb-found">
164
- <?php echo $msg1 ?>
165
- </div></td>
166
- </tr>
167
- <tr>
168
- <th align="right" class="odb-border-bottom">#</th>
169
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
170
- <th align="left" class="odb-border-bottom"><?php _e('type', $odb_class->odb_txt_domain);?></th>
171
- <th align="left" class="odb-border-bottom"><?php _e('IP address / title', $odb_class->odb_txt_domain);?></th>
172
- <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('date', $odb_class->odb_txt_domain);?></th>
173
- </tr>
174
- <?php
175
- } // if(!$scheduler)
176
-
177
- // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
178
- $total_deleted = $this->odb_delete_trash($results, $scheduler, $analyzing);
179
-
180
- if(!$scheduler) {
181
- ?>
182
- <tr>
183
- <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
184
- </tr>
185
- </table>
186
- <?php
187
- } // if(!$scheduler)
188
- } else {
189
- if(!$scheduler) {
190
- ?>
191
- <div class="odb-not-found">
192
- <?php _e('No TRASHED ITEMS found to delete', $odb_class->odb_txt_domain);?>
193
- </div>
194
- <?php
195
- } // if(!$scheduler)
196
- } // if(count($results)>0)
197
-
198
- // NUMBER OF DELETED TRASH FOR LOG FILE
199
- $odb_class->log_arr["trash"] = $total_deleted;
200
- } // if($odb_class->odb_rvg_options['clear_trash'] == 'Y')
201
-
202
-
203
- /****************************************************************************************
204
- * DELETE SPAMMED ITEMS
205
- ****************************************************************************************/
206
- if($odb_class->odb_rvg_options['clear_spam'] == 'Y') {
207
- // GET SPAMMED COMMENTS
208
- $results = $this->odb_get_spam($analyzing);
209
-
210
- $total_deleted = 0;
211
- if(count($results)>0) {
212
- // WE HAVE SPAM TO DELETE!
213
- if (!$scheduler) {
214
- if ($analyzing) {
215
- $msg1 = __('SPAMMED ITEMS', $odb_class->odb_txt_domain);
216
- $msg2 = __('total number of spammed items', $odb_class->odb_txt_domain);
217
- } else {
218
- $msg1 = __('DELETED SPAMMED ITEMS', $odb_class->odb_txt_domain);
219
- $msg2 = __('total number of spammed items deleted', $odb_class->odb_txt_domain);
220
- } // if ($analyzing)
221
- ?>
222
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
223
- <tr>
224
- <td colspan="4"><div class="odb-found">
225
- <?php echo $msg1 ?>
226
- </div></td>
227
- </tr>
228
- <tr>
229
- <th align="right" class="odb-border-bottom">#</th>
230
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
231
- <th align="left" class="odb-border-bottom"><?php _e('comment author', $odb_class->odb_txt_domain);?></th>
232
- <th align="left" class="odb-border-bottom"><?php _e('comment author email', $odb_class->odb_txt_domain);?></th>
233
- <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('comment date', $odb_class->odb_txt_domain);?></th>
234
- </tr>
235
- <?php
236
- } // if (!$scheduler)
237
-
238
- // LOOP THROUGH SPAMMED ITEMS AND DELETE THEM
239
- $total_deleted = $this->odb_delete_spam($results, $scheduler, $analyzing);
240
-
241
- if (!$scheduler) {
242
- ?>
243
- <tr>
244
- <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
245
- </tr>
246
- </table>
247
- <?php
248
- } // if (!$scheduler)
249
- } else{
250
- if (!$scheduler) {
251
- ?>
252
- <div class="odb-not-found">
253
- <?php _e('No SPAMMED ITEMS found to delete', $odb_class->odb_txt_domain);?>
254
- </div>
255
- <?php
256
- } // if (!$scheduler)
257
- } // if(count($results)>0)
258
-
259
- // NUMBER OF SPAM DELETED FOR LOG FILE
260
- $odb_class->log_arr["spam"] = $total_deleted;
261
- } // if($odb_class->odb_rvg_options['clear_spam'] == 'Y')
262
-
263
-
264
- /****************************************************************************************
265
- * DELETE UNUSED TAGS
266
- ****************************************************************************************/
267
- if($odb_class->odb_rvg_options['clear_tags'] == 'Y') {
268
- // GET UNUSED TAGS
269
- $results = $this->odb_get_unused_tags($analyzing);
270
-
271
- $total_deleted = 0;
272
-
273
- if(count($results)>0) {
274
- // WE HAVE TAGS TO DELETE!
275
- if (!$scheduler) {
276
- if ($analyzing) {
277
- $msg1 = __('UNUSED TAGS', $odb_class->odb_txt_domain);
278
- $msg2 = __('total number of unused tags', $odb_class->odb_txt_domain);
279
- } else {
280
- $msg1 = __('DELETED UNUSED TAGS', $odb_class->odb_txt_domain);
281
- $msg2 = __('total number of unused tags deleted', $odb_class->odb_txt_domain);
282
- }
283
- ?>
284
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
285
- <tr>
286
- <td colspan="4"><div class="odb-found">
287
- <?php echo $msg1 ?>
288
- </div></td>
289
- </tr>
290
- <tr>
291
- <th align="right" class="odb-border-bottom">#</th>
292
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
293
- <th align="left" class="odb-border-bottom"><?php _e('tag', $odb_class->odb_txt_domain);?></th>
294
- </tr>
295
- <?php
296
- } // if (!$scheduler)
297
-
298
- // LOOP THROUGH UNUSED TAGS AND DELETE THEM
299
- $total_deleted = $this->odb_delete_unused_tags($results, $scheduler, $analyzing);
300
-
301
- if (!$scheduler) {
302
- ?>
303
- <tr>
304
- <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
305
- </tr>
306
- </table>
307
- <?php
308
- } // if (!$scheduler)
309
- } else {
310
- if (!$scheduler) {
311
- ?>
312
- <div class="odb-not-found">
313
- <?php _e('No UNUSED TAGE found to delete', $odb_class->odb_txt_domain);?>
314
- </div>
315
- <?php
316
- } // if (!$scheduler)
317
- } // if(count($results)>0)
318
-
319
- // NUMBER OF SPAM DELETED FOR LOG FILE
320
- $odb_class->log_arr["tags"] = $total_deleted;
321
- } // if($odb_class->odb_rvg_options['clear_spam'] == 'Y')
322
-
323
-
324
- /****************************************************************************************
325
- * DELETE EXPIRED TRANSIENTS
326
- ****************************************************************************************/
327
- if($odb_class->odb_rvg_options['clear_transients'] != 'N') {
328
- // GET TRANSIENTS
329
- $results = $this->odb_get_transients($analyzing);
330
-
331
- $total_deleted = 0;
332
-
333
- if(count($results)>0) {
334
- // WE HAVE SPAM TO DELETE!
335
- if (!$scheduler) {
336
- if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
337
- if ($analyzing){
338
- $msg1 = __('EXPIRED TRANSIENTS', $odb_class->odb_txt_domain);
339
- $msg2 = __('total number of expired transients', $odb_class->odb_txt_domain);
340
- } else {
341
- $msg1 = __('EXPIRED TRANSIENTS DELETED', $odb_class->odb_txt_domain);
342
- $msg2 = __('total number of expired transients deleted', $odb_class->odb_txt_domain);
343
- }
344
- } else {
345
- if ($analyzing){
346
- $msg1 = __('TRANSIENTS', $odb_class->odb_txt_domain);
347
- $msg2 = __('total number of transients', $odb_class->odb_txt_domain);
348
- } else {
349
- $msg1 = __('TRANSIENTS DELETED', $odb_class->odb_txt_domain);
350
- $msg2 = __('total number of transients', $odb_class->odb_txt_domain);
351
- }
352
- } // if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
353
- ?>
354
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
355
- <tr>
356
- <td colspan="4"><div class="odb-found">
357
- <?php echo $msg1 ?>
358
- </div></td>
359
- </tr>
360
- <tr>
361
- <th align="right" class="odb-border-bottom">#</th>
362
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
363
- <th align="left" class="odb-border-bottom"><?php _e('option name', $odb_class->odb_txt_domain);?></th>
364
- </tr>
365
- <?php
366
- } // if (!$scheduler)
367
-
368
- // LOOP THROUGH SPAMMED ITEMS AND DELETE THEM
369
- $total_deleted = $this->odb_delete_transients($results, $scheduler, $analyzing);
370
-
371
- if (!$scheduler) {
372
- ?>
373
- <tr>
374
- <td colspan="3" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
375
- </tr>
376
- </table>
377
- <?php
378
- } // if (!$scheduler)
379
- } else{
380
- if (!$scheduler) {
381
- ?>
382
- <div class="odb-not-found">
383
- <?php
384
- if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
385
- $msg = __('No EXPIRED TRANSIENTS found to delete', $odb_class->odb_txt_domain);
386
- } else {
387
- $msg = __('No TRANSIENTS found to delete', $odb_class->odb_txt_domain);
388
- }
389
- ?>
390
- </div>
391
- <?php
392
- } // if (!$scheduler)
393
- } // if(count($results)>0)
394
-
395
- // NUMBER OF SPAM DELETED FOR LOG FILE
396
- $odb_class->log_arr["transients"] = $total_deleted;
397
- } // if($odb_class->odb_rvg_options['clear_transients'] == 'Y')
398
-
399
- /****************************************************************************************
400
- * DELETE PINGBACKS AND TRACKBACKS
401
- ****************************************************************************************/
402
- if($odb_class->odb_rvg_options['clear_pingbacks'] == 'Y') {
403
- // GET PINGBACKS AND TRACKBACKS
404
- $results = $this->odb_get_pingbacks($analyzing);
405
-
406
- $total_deleted = 0;
407
- if(count($results)>0) {
408
- // WE HAVE TRASH TO DELETE!
409
- if(!$scheduler) {
410
- if ($analyzing) {
411
- $msg1 = __('PINGBACKS AND TRACKBACKS', $odb_class->odb_txt_domain);
412
- $msg2 = __('total number of pingbacks and trackbacks', $odb_class->odb_txt_domain);
413
- } else {
414
- $msg1 = __('DELETED PINGBACKS AND TRACKBACKS', $odb_class->odb_txt_domain);
415
- $msg2 = __('total number of pingbacks and trackbacks deleted', $odb_class->odb_txt_domain);
416
- } // if ($analyzing)
417
- ?>
418
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
419
- <tr>
420
- <td colspan="4"><div class="odb-found">
421
- <?php echo $msg1 ?>
422
- </div></td>
423
- </tr>
424
- <tr>
425
- <th align="right" class="odb-border-bottom">#</th>
426
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
427
- <th align="left" class="odb-border-bottom"><?php _e('type', $odb_class->odb_txt_domain);?></th>
428
- <th align="left" class="odb-border-bottom"><?php _e('comment_author', $odb_class->odb_txt_domain);?></th>
429
- <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('date', $odb_class->odb_txt_domain);?></th>
430
- </tr>
431
- <?php
432
- } // if(!$scheduler)
433
-
434
- // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
435
- $total_deleted = $this->odb_delete_pingbacks($results, $scheduler, $analyzing);
436
-
437
- if(!$scheduler) {
438
- ?>
439
- <tr>
440
- <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
441
- </tr>
442
- </table>
443
- <?php
444
- } // if(!$scheduler)
445
- } else {
446
- if(!$scheduler) {
447
- ?>
448
- <div class="odb-not-found">
449
- <?php _e('No PINGBACKS nor TRACKBACKS found to delete', $odb_class->odb_txt_domain);?>
450
- </div>
451
- <?php
452
- } // if(!$scheduler)
453
- } // if(count($results)>0)
454
-
455
- // NUMBER OF DELETED PINGBACKS FOR LOG FILE
456
- $odb_class->log_arr["pingbacks"] = $total_deleted;
457
- } // if($odb_class->odb_rvg_options['clear_pingbacks'] == 'Y')
458
-
459
-
460
- /****************************************************************************************
461
- * DELETE OEMBED CACHE
462
- ****************************************************************************************/
463
- if($odb_class->odb_rvg_options['clear_oembed'] == 'Y') {
464
-
465
- // GET OEMBED CACHE
466
- $results = $this->odb_get_oembed($analyzing);
467
-
468
- $total_deleted = 0;
469
- if(count($results)>0) {
470
- // WE HAVE TRASH TO DELETE!
471
- if(!$scheduler) {
472
- if ($analyzing) {
473
- $msg1 = __('OEMBED CACHE', $odb_class->odb_txt_domain);
474
- $msg2 = __('total number of oEmbeds', $odb_class->odb_txt_domain);
475
- } else {
476
- $msg1 = __('DELETED OEMBEDS', $odb_class->odb_txt_domain);
477
- $msg2 = __('total number of oEmbeds deleted', $odb_class->odb_txt_domain);
478
- } // if ($analyzing)
479
- ?>
480
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
481
- <tr>
482
- <td colspan="4"><div class="odb-found">
483
- <?php echo $msg1 ?>
484
- </div></td>
485
- </tr>
486
- <tr>
487
- <th align="right" class="odb-border-bottom">#</th>
488
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
489
- <th align="left" class="odb-border-bottom"><?php _e('meta key', $odb_class->odb_txt_domain);?></th>
490
- <th align="left" class="odb-border-bottom"><?php _e('meta value', $odb_class->odb_txt_domain);?></th>
491
- </tr>
492
- <?php
493
- } // if(!$scheduler)
494
-
495
- // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
496
- $total_deleted = $this->odb_delete_oembed($results, $scheduler, $analyzing);
497
-
498
- if(!$scheduler) {
499
- ?>
500
- <tr>
501
- <td colspan="4" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
502
- </tr>
503
- </table>
504
- <?php
505
- } // if(!$scheduler)
506
- } else {
507
- if(!$scheduler) {
508
- ?>
509
- <div class="odb-not-found">
510
- <?php _e('No OEMED CHACHE found to delete', $odb_class->odb_txt_domain);?>
511
- </div>
512
- <?php
513
- } // if(!$scheduler)
514
- } // if(count($results)>0)
515
-
516
- // NUMBER OF DELETED PINGBACKS FOR LOG FILE
517
- $odb_class->log_arr["oembeds"] = $total_deleted;
518
- } // if($odb_class->odb_rvg_options['clear_oembed'] == 'Y')
519
-
520
-
521
- /****************************************************************************************
522
- * DELETE ORPHANS
523
- ****************************************************************************************/
524
- if($odb_class->odb_rvg_options['clear_orphans'] == 'Y') {
525
- $results = $this->odb_get_orphans($results, $scheduler,$analyzing);
526
-
527
- $total_deleted = count($results);
528
-
529
- //$total_deleted = $this->odb_delete_orphans($analyzing);
530
-
531
- if($total_deleted > 0) {
532
- if (!$scheduler) {
533
- if ($analyzing) {
534
- $msg1 = __('POSTMETA ORPHANS', $odb_class->odb_txt_domain);
535
- $msg2 = __('total number of orphans', $odb_class->odb_txt_domain);
536
- } else {
537
- $msg1 = __('DELETED POSTMETA ORPHANS', $odb_class->odb_txt_domain);
538
- $msg2 = __('total number of orphans', $odb_class->odb_txt_domain);
539
- }
540
- ?>
541
- <!-- <div class="odb-found-number">
542
- <?php echo $msg1 ?>: <span class="odb-blue"><?php echo $total_deleted;?></span>
543
- </div>-->
544
- <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
545
- <tr>
546
- <td colspan="8"><div class="odb-found">
547
- <?php echo $msg1 ?>
548
- </div></td>
549
- </tr>
550
- <tr>
551
- <th align="right" class="odb-border-bottom">#</th>
552
- <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
553
- <th align="left" class="odb-border-bottom"><?php _e('type', $odb_class->odb_txt_domain);?></th>
554
- <th align="left" class="odb-border-bottom"><?php _e('id', $odb_class->odb_txt_domain);?></th>
555
- <th align="left" class="odb-border-bottom"><?php _e('title', $odb_class->odb_txt_domain);?></th>
556
- <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('modified', $odb_class->odb_txt_domain);?></th>
557
- <th align="left" class="odb-border-bottom"><?php _e('meta key', $odb_class->odb_txt_domain);?></th>
558
- <th align="left" class="odb-border-bottom"><?php _e('meta value', $odb_class->odb_txt_domain);?></th>
559
- </tr>
560
- <?php
561
- } // if(!$scheduler)
562
-
563
- // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
564
- $total_deleted = $this->odb_delete_orphans($results, $scheduler, $analyzing);
565
-
566
- if(!$scheduler) {
567
- ?>
568
- <tr>
569
- <td colspan="8" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?> <?php echo $total_deleted?></td>
570
- </tr>
571
- </table>
572
-
573
- <?php
574
- } // if (!$scheduler)
575
- } else {
576
- if (!$scheduler) {
577
- ?>
578
- <div class="odb-not-found">
579
- <?php _e('No POSTMETA ORPHANS found to delete', $odb_class->odb_txt_domain);?>
580
- </div>
581
- <?php
582
- } // if (!$scheduler)
583
- } // if($total_deleted > 0)
584
- // FOR LOG FILE
585
- $odb_class->log_arr["orphans"] = $total_deleted;
586
-
587
- if (!$scheduler) {
588
- ?>
589
- </div><!-- /odb-cleaner -->
590
- <?php
591
- } // if (!$scheduler)
592
- } // if($odb_class->odb_rvg_options['clear_oembed'] == 'Y')
593
- } // odb_run_cleaner()
594
-
595
-
596
- /********************************************************************************************
597
- * RUN OPTIMIZER
598
- ********************************************************************************************/
599
- function odb_run_optimizer($scheduler) {
600
- global $odb_class;
601
-
602
- if(!$scheduler) {
603
- ?>
604
- <div class="odb-optimizing-table" class="odb-padding-left">
605
- <div class="odb-title-bar">
606
- <h2><?php _e('Optimizing Database Tables', $odb_class->odb_txt_domain);?></h2>
607
- </div>
608
- <br>
609
- <br>
610
- <table border="0" cellspacing="8" cellpadding="2">
611
- <tr>
612
- <th class="odb-border-bottom" align="right">#</th>
613
- <th class="odb-border-bottom" align="left"><?php _e('table name', $odb_class->odb_txt_domain);?></th>
614
- <th class="odb-border-bottom" align="left"><?php _e('optimization result', $odb_class->odb_txt_domain);?></th>
615
- <th class="odb-border-bottom" align="left"><?php _e('engine', $odb_class->odb_txt_domain);?></th>
616
- <th class="odb-border-bottom" align="right"><?php _e('table rows', $odb_class->odb_txt_domain);?></th>
617
- <th class="odb-border-bottom" align="right"><?php _e('table size', $odb_class->odb_txt_domain);?></th>
618
- </tr>
619
- <?php
620
- } // if(!$scheduler)
621
-
622
- # OPTIMIZE THE DATABASE TABLES
623
- $this->nr_of_optimized_tables = $this->odb_optimize_tables($scheduler);
624
-
625
- if(!$scheduler) {
626
- ?>
627
- </table>
628
- </div><!-- /odb-optimizing-table -->
629
- <?php
630
- } // if(!$scheduler)
631
- } // odb_run_optimizer()
632
-
633
-
634
- /********************************************************************************************
635
- * CALCULATE AND DISPLAY SAVINGS
636
- ********************************************************************************************/
637
- function odb_savings($scheduler) {
638
- global $odb_class;
639
- global $odb_logger_obj;
640
-
641
- // NUMBER OF TABLES
642
- $odb_class->log_arr["tables"] = $this->nr_of_optimized_tables;
643
- // DATABASE SIZE BEFORE OPTIMIZATION
644
- $odb_class->log_arr["before"] = $odb_class->odb_utilities_obj->odb_format_size($this->start_size,3);
645
- // DATABASE SIZE AFTER OPTIMIZATION
646
- $end_size = $odb_class->odb_utilities_obj->odb_get_db_size();
647
- $odb_class->log_arr["after"] = $odb_class->odb_utilities_obj->odb_format_size($end_size,3);
648
- // TOTAL SAVING
649
- $odb_class->log_arr["savings"] = $odb_class->odb_utilities_obj->odb_format_size(($this->start_size - $end_size),3);
650
-
651
- // WRITE RESULTS TO LOG FILE - v4.6
652
- $odb_class->odb_logger_obj->odb_add_log($odb_class->log_arr);
653
-
654
- $total_savings = $odb_class->odb_rvg_options['total_savings'];
655
- $total_savings += ($this->start_size - $end_size);
656
- $odb_class->odb_rvg_options['total_savings'] = $total_savings;
657
-
658
- $odb_class->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $odb_class->odb_rvg_options);
659
-
660
- if(!$scheduler) {
661
- ?>
662
- <div id="odb-savings" class="odb-padding-left">
663
- <div class="odb-title-bar">
664
- <h2><?php _e('Savings', $odb_class->odb_txt_domain);?></h2>
665
- </div>
666
- <br>
667
- <br>
668
- <table border="0" cellspacing="8" cellpadding="2">
669
- <tr>
670
- <th>&nbsp;</th>
671
- <th class="odb-border-bottom"><?php _e('size of the database', $odb_class->odb_txt_domain);?></th>
672
- </tr>
673
- <tr>
674
- <td align="right"><?php _e('BEFORE optimization', $odb_class->odb_txt_domain);?></td>
675
- <td align="right" class="odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size($this->start_size,3); ?></td>
676
- </tr>
677
- <tr>
678
- <td align="right"><?php _e('AFTER optimization', $odb_class->odb_txt_domain);?></td>
679
- <td align="right" class="odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size($end_size,3); ?></td>
680
- </tr>
681
- <tr>
682
- <td align="right" class="odb-bold"><?php _e('SAVINGS THIS TIME', $odb_class->odb_txt_domain);?></td>
683
- <td align="right" class="odb-border-top odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size(($this->start_size - $end_size),3); ?></td>
684
- </tr>
685
- <tr>
686
- <td align="right" class="odb-bold"><?php _e('TOTAL SAVINGS SINCE THE FIRST RUN', $odb_class->odb_txt_domain);?></td>
687
- <td align="right" class="odb-border-top odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size($total_savings,3); ?></td>
688
- </tr>
689
- </table>
690
- </div><!-- /odb-savings -->
691
- <?php
692
- } // if(!$scheduler)
693
- } // odb_savings()
694
-
695
-
696
- /********************************************************************************************
697
- * SHOW LOADING TIME
698
- ********************************************************************************************/
699
- function odb_done($analyze = false) {
700
- global $odb_class;
701
-
702
- $time = microtime();
703
- $time = explode(' ', $time);
704
- $time = $time[1] + $time[0];
705
- $finish = $time;
706
-
707
- $total_time = round(($finish - $odb_class->odb_start_time), 4);
708
- ?>
709
- <div id="odb-done" class="odb-padding-left">
710
- <div class="odb-title-bar">
711
- <h2>
712
- <?php _e('DONE!', $odb_class->odb_txt_domain);?>
713
- </h2>
714
- </div>
715
- <br>
716
- <br>
717
- <?php
718
- if ($analyze) {
719
- ?>
720
- <span class="odb-padding-left"><?php _e('Analysis took', $odb_class->odb_txt_domain)?>&nbsp;<strong><?php echo $total_time;?></strong>&nbsp;<?php _e('seconds', $odb_class->odb_txt_domain)?>.</span>
721
- <?php
722
- } else {
723
- ?>
724
- <span class="odb-padding-left"><?php _e('Optimization took', $odb_class->odb_txt_domain)?>&nbsp;<strong><?php echo $total_time;?></strong>&nbsp;<?php _e('seconds', $odb_class->odb_txt_domain)?>.</span>
725
- <?php
726
- } // if ($analyze)
727
- ?>
728
- <?php
729
- // v4.5.1
730
- $odb_class->odb_last_run_seconds = $total_time;
731
-
732
- if($odb_class->odb_logger_obj->odb_log_count() > 0) {
733
- ?>
734
- <script>
735
- function odb_confirm_delete() {
736
- <?php
737
- // v4.6.2
738
- $msg = str_replace("'", "\'", __('Clear the log?', $odb_class->odb_txt_domain));
739
- ?>
740
- if(confirm('<?php echo $msg?>')) {
741
- self.location = 'tools.php?page=rvg-optimize-database&action=clear_log'
742
- return;
743
- }
744
- } // odb_confirm_delete()
745
- </script>
746
- <br><br>
747
- &nbsp;
748
- <input class="button odb-normal" type="button" name="view_log" value="<?php _e('View Log', $odb_class->odb_txt_domain);?>" onclick="self.location='tools.php?page=rvg-optimize-database&action=view_log'" />
749
- &nbsp;
750
- <input class="button odb-normal" type="button" name="clear_log" value="<?php _e('Clear Log', $odb_class->odb_txt_domain);?>" onclick="return odb_confirm_delete();" />
751
- <?php
752
- } // if($odb_class->odb_logger_obj->odb_log_count() > 0)
753
- ?>
754
- </div><!-- /odb-done -->
755
- <?php
756
- } // odb_done()
757
-
758
-
759
- /********************************************************************************************
760
- * GET REVISIONS (OLDER THAN x DAYS)
761
- ********************************************************************************************/
762
- function odb_get_revisions_older_than() {
763
- global $odb_class, $wpdb;
764
-
765
- $res_arr = array();
766
-
767
- // CUSTOM POST TYPES (from v4.4)
768
- $rel_posttypes = $odb_class->odb_rvg_options['post_types'];
769
- $in = '';
770
- foreach ($rel_posttypes as $posttype => $value) {
771
- if ($value == 'Y') {
772
- if ($in != '') $in .= ',';
773
- $in .= "'" . $posttype . "'";
774
- } // if ($value == 'Y')
775
- } // foreach($rel_posttypes as $posttypes)
776
-
777
- $where = '';
778
- if($in != '') {
779
- $where = " AND p2.`post_type` IN ($in)";
780
- } else {
781
- // NO POST TYPES TO DELETE REVISIONS FOR... SKIP!
782
- return $res_arr;
783
- } // if($in != '')
784
-
785
- $older_than = $odb_class->odb_rvg_options['older_than'];
786
-
787
- $index = 0;
788
-
789
- // LOOP THROUGH THE SITES (IF MULTI SITE)
790
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
791
- $prefix = $odb_class->odb_ms_prefixes[$i];
792
-
793
- $sql = sprintf("
794
- SELECT '$s' AS site,
795
- p1.`ID`,
796
- p1.`post_parent`,
797
- p1.`post_title`,
798
- p1.`post_modified`
799
- FROM %sposts p1, %sposts p2
800
- WHERE p1.`post_type` = 'revision'
801
- AND p1.`post_parent` = p2.ID
802
- %s
803
- AND p1.`post_modified` < date_sub(now(), INTERVAL %d DAY)
804
- ORDER BY UCASE(p1.`post_title`)
805
- ",
806
- $prefix,
807
- $prefix,
808
- $prefix,
809
- $where,
810
- $older_than);
811
-
812
- //echo 'OLDER: '.$sql.'<br>';
813
-
814
- $res = $wpdb->get_results($sql, ARRAY_A);
815
-
816
- for($j=0; $j<count($res); $j++) {
817
- if(isset($res[$j]) && !$this->odb_post_is_excluded($res[$j]['post_parent'])) {
818
- $res_arr[$index] = $res[$j];
819
- $index++;
820
- } // if(isset($res[$j]) && !$this->odb_post_is_excluded($res[$j]['post_parent']))
821
- } // for($j=0; $j<count($res); $j++)
822
-
823
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
824
-
825
- return $res_arr;
826
- } // odb_get_revisions_older_than()
827
-
828
-
829
- /********************************************************************************************
830
- * GET REVISIONS (KEEP MAX NUMBER OF REVISIONS)
831
- ********************************************************************************************/
832
- function odb_get_revisions_keep_revisions() {
833
- global $odb_class, $wpdb;
834
-
835
- $res_arr = array();
836
-
837
- // CUSTOM POST TYPES (from v4.4)
838
- $rel_posttypes = $odb_class->odb_rvg_options['post_types'];
839
- $in = '';
840
- foreach ($rel_posttypes as $posttype => $value) {
841
- if ($value == 'Y') {
842
- if ($in != '') $in .= ',';
843
- $in .= "'" . $posttype . "'";
844
- } // if ($value == 'Y')
845
- } // foreach($rel_posttypes as $posttypes)
846
-
847
- $where1 = '';
848
- if($in != '') {
849
- $where1 = " AND p2.`post_type` IN ($in)";
850
- } else {
851
- // NO POST TYPES TO DELETE REVISIONS FOR... SKIP!
852
- return $res_arr;
853
- } // if($in != '')
854
-
855
- // MAX NUMBER OF REVISIONS TO KEEP
856
- $max_revisions = $odb_class->odb_rvg_options['nr_of_revisions'];
857
-
858
- $index = 0;
859
-
860
- // SKIP REVISIONS THAT WILL BE DELETED BY THE 'OLDER THAN' OPTION
861
- $where2 = '';
862
- if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
863
- $older_than = $odb_class->odb_rvg_options['older_than'];
864
- $where2 = 'AND p1.`post_modified` >= date_sub(now(), INTERVAL '.$older_than.' DAY)';
865
- }
866
-
867
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
868
- $prefix = $odb_class->odb_ms_prefixes[$i];
869
-
870
- $sql = sprintf ("
871
- SELECT '%s' AS site,
872
- p1.`ID`, p1.`post_parent`, p1.`post_title`, COUNT(*) cnt
873
- FROM %sposts p1, %sposts p2
874
- WHERE p1.`post_type` = 'revision'
875
- AND p1.`post_parent` = p2.ID
876
- %s
877
- %s
878
- GROUP BY p1.`post_parent`
879
- HAVING COUNT(*) > %d
880
- ORDER BY UCASE(p1.`post_title`)
881
- ",
882
- $prefix,
883
- $prefix,
884
- $prefix,
885
- $where1,
886
- $where2,
887
- $max_revisions);
888
-
889
- //echo 'KEEP: '.$sql.'<br>';
890
-
891
- $res = $wpdb->get_results($sql, ARRAY_A);
892
- for($j=0; $j<count($res); $j++) {
893
- if(isset($res[$j]) && !$this->odb_post_is_excluded($res[$j]['post_parent'])) {
894
- $res_arr[$index] = $res[$j];
895
- $index++;
896
- }
897
- } // for($j=0; $j<count($res); $j++)
898
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
899
-
900
- return $res_arr;
901
- } // odb_get_revisions_keep_revisions()
902
-
903
-
904
- /********************************************************************************************
905
- * DELETE THE REVISIONS
906
- ********************************************************************************************/
907
- function odb_delete_revisions($scheduler, $analyzing = false) {
908
- global $odb_class, $wpdb;
909
-
910
- $total_deleted = 0;
911
- $nr = 1;
912
-
913
- if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
914
- // DELETE REVISIONS OLDER THAN x DAYS
915
- $results = $this->odb_get_revisions_older_than();
916
- $older_than = $odb_class->odb_rvg_options['older_than'];
917
- $total_deleted += count($results);
918
-
919
- for($i=0; $i<count($results); $i++) {
920
- if (!$scheduler) {
921
- ?>
922
- <tr>
923
- <td align="right" valign="top"><?php echo $nr?>.</td>
924
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
925
- <td valign="top" class="odb-bold"><?php echo $results[$i]['post_title']?></td>
926
- <td valign="top" class="odb-bold"><?php echo $results[$i]['post_modified']?></td><?php
927
- } // if (!$scheduler)
928
-
929
- if (!$analyzing) {
930
- $sql_delete = sprintf ("
931
- DELETE FROM %sposts
932
- WHERE `ID` = %d
933
- ", $results[$i]['site'], $results[$i]['ID']);
934
-
935
- $wpdb->get_results($sql_delete);
936
- } // if (!$analyzing)
937
-
938
- $nr++;
939
- if(!$scheduler) {
940
- ?>
941
- <td align="right" valign="top" class="odb-bold">1</td>
942
- </tr>
943
- <?php
944
- } // if(!$scheduler)
945
- } // for($i=0; $i<count($results); $i++)
946
- } // if($odb_class->odb_rvg_options['delete_older'] == 'Y')
947
-
948
- if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
949
- // KEEP MAX NUMBER OF REVISIONS
950
- $results = $this->odb_get_revisions_keep_revisions();
951
- $max_revisions = $odb_class->odb_rvg_options['nr_of_revisions'];
952
-
953
- for($i=0; $i<count($results); $i++) {
954
- $nr_to_delete = $results[$i]['cnt'] - $max_revisions;
955
- $total_deleted += $nr_to_delete;
956
-
957
- if (!$scheduler) {
958
- ?>
959
- <tr>
960
- <td align="right" valign="top"><?php echo $nr?>.</td>
961
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
962
- <td valign="top" class="odb-bold"><?php echo $results[$i]['post_title']?></td>
963
- <td valign="top"><?php
964
- } // if (!$scheduler)
965
-
966
- $sql_get_posts = sprintf( "
967
- SELECT `ID`, `post_modified`
968
- FROM %sposts
969
- WHERE `post_parent` = %d
970
- AND `post_type` = 'revision'
971
- ORDER BY `post_modified` ASC
972
- ", $results[$i]['site'], $results[$i]['post_parent']);
973
-
974
- $results_get_posts = $wpdb->get_results($sql_get_posts);
975
-
976
- for($j=0; $j<$nr_to_delete; $j++) {
977
- if(!$scheduler) echo $results_get_posts[$j]->post_modified.'<br>';
978
- if (!$analyzing) {
979
- $sql_delete = sprintf ("
980
- DELETE FROM %sposts
981
- WHERE `ID` = %d
982
- ", $results[$i]['site'], $results_get_posts[$j]->ID);
983
-
984
- $wpdb->get_results($sql_delete);
985
- } // if (!$analyzing)
986
- } // for($j=0; $j<$nr_to_delete; $j++)
987
-
988
- $nr++;
989
- if(!$scheduler) {
990
- ?></td>
991
- <td align="right" valign="top" class="odb-bold"><?php echo $nr_to_delete?> <?php _e('of', $odb_class->odb_txt_domain)?> <?php echo $results[$i]['cnt'];?></td>
992
- </tr>
993
- <?php
994
- } // if(!$scheduler)
995
- } // for($i=0; $i<count($results); $i++)
996
- } // if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y')
997
-
998
- return $total_deleted;
999
- } // function odb_delete_revisions()
1000
-
1001
-
1002
- /********************************************************************************************
1003
- * CHECK IF POST IS EXCLUDED BY A CUSTOM FIELD ('keep_revisions')
1004
- ********************************************************************************************/
1005
- function odb_post_is_excluded($parent_id) {
1006
- $keep_revisions = get_post_meta($parent_id, 'keep_revisions', true);
1007
- return ($keep_revisions === 'Y');
1008
- } // odb_post_is_exclude()
1009
-
1010
-
1011
- /********************************************************************************************
1012
- * GET TRASHED POSTS / PAGES AND COMMENTS
1013
- ********************************************************************************************/
1014
- function odb_get_trash($analyzing = false) {
1015
- global $wpdb, $odb_class;
1016
-
1017
- $res_arr = array();
1018
-
1019
- $index = 0;
1020
- // LOOP TROUGH SITES
1021
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1022
- $prefix = $odb_class->odb_ms_prefixes[$i];
1023
-
1024
- $sql = sprintf ("
1025
- SELECT '%s' AS site,
1026
- `ID` AS id,
1027
- 'post' AS post_type,
1028
- `post_title` AS title,
1029
- `post_modified` AS modified
1030
- FROM %sposts
1031
- WHERE `post_status` = 'trash'
1032
- UNION ALL
1033
- SELECT '%s' AS site,
1034
- `comment_ID` AS id,
1035
- 'comment' AS post_type,
1036
- `comment_author_IP` AS title,
1037
- `comment_date` AS modified
1038
- FROM %scomments
1039
- WHERE `comment_approved` = 'trash'
1040
- ORDER BY post_type, UCASE(title)
1041
- ", $prefix, $prefix, $prefix, $prefix);
1042
-
1043
- $res = $wpdb->get_results($sql, ARRAY_A);
1044
-
1045
- if($res != null) {
1046
- $res_arr[$index] = $res[0];
1047
- $index++;
1048
- } // if($res != null)
1049
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1050
-
1051
- return $res_arr;
1052
- } // odb_get_trash()
1053
-
1054
-
1055
- /********************************************************************************************
1056
- * DELETE TRASHED POSTS AND PAGES
1057
- ********************************************************************************************/
1058
- function odb_delete_trash($results, $scheduler, $analyzing) {
1059
- global $wpdb;
1060
-
1061
- $nr = 1;
1062
- $total_deleted = count($results);
1063
-
1064
- for($i=0; $i<$total_deleted; $i++) {
1065
- if(!$scheduler) {
1066
- ?>
1067
- <tr>
1068
- <td align="right" valign="top"><?php echo $nr; ?></td>
1069
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1070
- <td valign="top"><?php echo $results[$i]['post_type']; ?></td>
1071
- <td valign="top"><?php echo $results[$i]['title']; ?></td>
1072
- <td valign="top" nowrap="nowrap"><?php echo $results[$i]['modified']; ?></td>
1073
- </tr>
1074
- <?php
1075
- } // if(!$scheduler)
1076
-
1077
- if($results[$i]['post_type'] == 'comment') {
1078
- // DELETE META DATA (IF ANY...)
1079
- if (!$analyzing) {
1080
- $sql_delete = sprintf ("
1081
- DELETE FROM %scommentmeta
1082
- WHERE `comment_id` = %d
1083
- ", $results[$i]['site'], $results[$i]['id']);
1084
- $wpdb->get_results($sql_delete);
1085
- } // if (!$analyzing)
1086
- } // if($results[$i]['post_type'] == 'comment')
1087
-
1088
- if (!$analyzing) {
1089
- // DELETE TRASHED POSTS / PAGES
1090
- $sql_delete = sprintf ("
1091
- DELETE FROM %sposts
1092
- WHERE `post_status` = 'trash'
1093
- ", $results[$i]['site']);
1094
- $wpdb->get_results($sql_delete);
1095
-
1096
- // DELETE TRASHED COMMENTS
1097
- $sql_delete = sprintf ("
1098
- DELETE FROM %scomments
1099
- WHERE `comment_approved` = 'trash'
1100
- ", $results[$i]['site']);
1101
- $wpdb->get_results($sql_delete);
1102
- } // if (!$analyzing)
1103
-
1104
- $nr++;
1105
- } // for($i=0; $i<count($results); $i++)
1106
-
1107
- return $total_deleted;
1108
- } // odb_delete_trash()
1109
-
1110
-
1111
- /********************************************************************************************
1112
- * GET SPAMMED COMMENTS
1113
- ********************************************************************************************/
1114
- function odb_get_spam($analyzing = false) {
1115
- global $wpdb, $odb_class;
1116
-
1117
- $res_arr = array();
1118
-
1119
- // LOOP THROUGH SITES
1120
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1121
- $prefix = $odb_class->odb_ms_prefixes[$i];
1122
-
1123
- $sql = sprintf ("
1124
- SELECT '%s' AS site,
1125
- `comment_ID`,
1126
- `comment_author`,
1127
- `comment_author_email`,
1128
- `comment_date`
1129
- FROM %scomments
1130
- WHERE `comment_approved` = 'spam'
1131
- ORDER BY UCASE(`comment_author`)
1132
- ", $prefix, $prefix);
1133
-
1134
- $res = $wpdb->get_results($sql, ARRAY_A);
1135
-
1136
- for($j = 0; $j < count($res); $j++) {
1137
- array_push($res_arr, $res[$j]);
1138
- } // for($j = 0; $j < count($res); $j++)
1139
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1140
- return $res_arr;
1141
- } // odb_get_spam()
1142
-
1143
-
1144
- /********************************************************************************************
1145
- * DELETE SPAMMED ITEMS
1146
- ********************************************************************************************/
1147
- function odb_delete_spam($results, $scheduler, $analyzing = false) {
1148
- global $wpdb;
1149
-
1150
- $nr = 1;
1151
- $total_deleted = count($results);
1152
- for($i=0; $i<count($results); $i++) {
1153
- if (!$scheduler) {
1154
- ?>
1155
- <tr>
1156
- <td align="right" valign="top"><?php echo $nr; ?></td>
1157
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1158
- <td valign="top"><?php echo $results[$i]['comment_author']; ?></td>
1159
- <td valign="top"><?php echo $results[$i]['comment_author_email']; ?></td>
1160
- <td valign="top" nowrap="nowrap"><?php echo $results[$i]['comment_date']; ?></td>
1161
- </tr>
1162
- <?php
1163
- } // if (!$scheduler)
1164
-
1165
- if (!$analyzing) {
1166
- $sql_delete = sprintf ("
1167
- DELETE FROM %scommentmeta
1168
- WHERE `comment_id` = %d
1169
- ", $results[$i]['site'], $results[$i]['comment_ID']);
1170
- $wpdb->get_results($sql_delete);
1171
-
1172
- $sql_delete = sprintf ("
1173
- DELETE FROM %scomments
1174
- WHERE `comment_approved` = 'spam'
1175
- ", $results[$i]['site']);
1176
- $wpdb->get_results($sql_delete);
1177
- } // if (!$analyzing)
1178
-
1179
- $nr++;
1180
- } // for($i=0; $i<count($results); $i++)
1181
-
1182
- return $total_deleted;
1183
- } // odb_delete_spam()
1184
-
1185
-
1186
- /********************************************************************************************
1187
- * GET UNUSED TAGS
1188
- ********************************************************************************************/
1189
- function odb_get_unused_tags($analyzing = false) {
1190
- global $wpdb, $odb_class;
1191
-
1192
- $res_arr = array();
1193
-
1194
- // LOOP THROUGH SITES
1195
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1196
- $prefix = $odb_class->odb_ms_prefixes[$i];
1197
-
1198
- $sql = sprintf ("
1199
- SELECT '%s' AS site,
1200
- a.term_id AS term_id, a.name AS name
1201
- FROM `%sterms` a, `%sterm_taxonomy` b
1202
- WHERE a.term_id = b.term_id
1203
- AND b.taxonomy = 'post_tag'
1204
- AND b.term_taxonomy_id NOT IN (
1205
- SELECT term_taxonomy_id
1206
- FROM %sterm_relationships
1207
- )
1208
- ORDER BY name
1209
- ", $prefix, $prefix, $prefix, $prefix);
1210
-
1211
- $res = $wpdb->get_results($sql, ARRAY_A);
1212
-
1213
- for($j = 0; $j < count($res); $j++) {
1214
- array_push($res_arr, $res[$j]);
1215
- } // for($j = 0; $j < count($res); $j++)
1216
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1217
- return $res_arr;
1218
- } // odb_get_unused_tags
1219
-
1220
-
1221
- /********************************************************************************************
1222
- * DELETE UNUSED TAGS
1223
- ********************************************************************************************/
1224
- function odb_delete_unused_tags($results, $scheduler, $analyzing = false) {
1225
- global $wpdb, $odb_class;
1226
-
1227
- $nr = 1;
1228
- $total_deleted = count($results);
1229
- for($i=0; $i<count($results); $i++) {
1230
- if (!$scheduler) {
1231
- ?>
1232
- <tr>
1233
- <td align="right" valign="top"><?php echo $nr; ?></td>
1234
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1235
- <td valign="top"><?php echo $results[$i]['name']; ?></td>
1236
- </tr>
1237
- <?php
1238
- } // if (!$scheduler)
1239
-
1240
- if (!$analyzing) {
1241
- $sql_del = sprintf ("
1242
- DELETE FROM %sterm_taxonomy
1243
- WHERE term_id = %d
1244
- ", $results[$i]['site'], $results[$i]['term_id']);
1245
- $wpdb->get_results($sql_del);
1246
-
1247
- $sql_del = sprintf ("
1248
- DELETE FROM %sterms
1249
- WHERE term_id = %d
1250
- ", $results[$i]['site'], $results[$i]['term_id']);
1251
- $wpdb->get_results($sql_del);
1252
- } // if (!$analyzing)
1253
-
1254
- $nr++;
1255
- } // for($i=0; $i<count($results); $i++)
1256
-
1257
- return $total_deleted;
1258
- } // odb_delete_unused_tags()
1259
-
1260
-
1261
- /********************************************************************************************
1262
- * IS THE UNUSED TAG USED IN ONE OR MORE SCHEDULED POSTS?
1263
- ********************************************************************************************/
1264
- function odb_delete_tags_is_scheduled($term_id, $odb_prefix) {
1265
- global $wpdb;
1266
-
1267
- $sql_get_posts = sprintf ("
1268
- SELECT p.post_status
1269
- FROM %sterm_relationships t, %sposts p
1270
- WHERE t.term_taxonomy_id = '%s'
1271
- AND t.object_id = p.ID
1272
- ", $odb_prefix, $odb_prefix, $term_id);
1273
-
1274
- $results_get_posts = $wpdb->get_results($sql_get_posts);
1275
- for($i=0; $i<count($results_get_posts); $i++)
1276
- if($results_get_posts[$i]->post_status == 'future') return true;
1277
-
1278
- return false;
1279
- } // odb_delete_tags_is_scheduled()
1280
-
1281
-
1282
- /********************************************************************************************
1283
- * DELETE TRANSIENTS (v4.3.1)
1284
- ********************************************************************************************/
1285
- function odb_get_transients($analyzing = false) {
1286
- global $wpdb, $odb_class;
1287
-
1288
- $res_arr = array();
1289
-
1290
- // LOOP THROUGH SITES
1291
- $delay = time() - 60; // ONE MINUTE DELAY
1292
-
1293
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1294
- $prefix = $odb_class->odb_ms_prefixes[$i];
1295
-
1296
- if ($odb_class->odb_rvg_options['clear_transients'] == 'Y' || $odb_class->odb_rvg_options['clear_transients'] == 'A') {
1297
- // DELETE TRANSIENTS
1298
- if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
1299
- // EXPIRED TRANSIENTS ONLY
1300
- $sql = "
1301
- SELECT '" . $prefix . "' AS site,
1302
- `option_name`
1303
- FROM " . $prefix . "options
1304
- WHERE (
1305
- option_name LIKE '_transient_timeout_%'
1306
- OR option_name LIKE '_site_transient_timeout_%'
1307
- )
1308
- AND option_value < '" . $delay . "'" . "
1309
- ORDER BY `option_name`
1310
- ";
1311
- } else {
1312
- // ALL TRANSIENTS
1313
- $sql = "
1314
- SELECT '" . $prefix . "' AS site,
1315
- `option_name`
1316
- FROM " . $prefix . "options
1317
- WHERE (
1318
- option_name LIKE '_transient_timeout_%'
1319
- OR option_name LIKE '_site_transient_timeout_%'
1320
- )
1321
- ORDER BY `option_name`
1322
- ";
1323
- } // if ($odb_class->odb_rvg_options['clear_transients'] == 'Y')
1324
- $res = $wpdb->get_results($sql, ARRAY_A);
1325
-
1326
- for($j = 0; $j < count($res); $j++) {
1327
- array_push($res_arr, $res[$j]);
1328
- } // for($j = 0; $j < count($res); $j++)
1329
- } // if ($odb_class->odb_rvg_options['clear_transients'] == 'Y' || $odb_class->odb_rvg_options['clear_transients'] == 'A')
1330
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1331
- return $res_arr;
1332
- } // odb_get_transients()
1333
-
1334
-
1335
- /********************************************************************************************
1336
- * DELETE TRANSIENTS (v4.3.1)
1337
- ********************************************************************************************/
1338
- function odb_delete_transients($results, $scheduler, $analyzing = false) {
1339
- global $wpdb;
1340
-
1341
- $total_deleted = 0;
1342
-
1343
- $nr = 1;
1344
- $total_deleted = count($results);
1345
- for($i=0; $i<count($results); $i++) {
1346
- if (!$scheduler) {
1347
- ?>
1348
- <tr>
1349
- <td align="right" valign="top"><?php echo $nr; ?></td>
1350
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1351
- <td valign="top"><?php echo $results[$i]['option_name']; ?></td>
1352
- </tr>
1353
- <?php
1354
- } // if (!$scheduler)
1355
-
1356
- // LOOP THROUGH THE RESULTS
1357
- if (!$analyzing) {
1358
- for($j=0; $j<count($results); $j++) {
1359
- if(substr($results[$j]['option_name'], 0, 19) == '_transient_timeout_') {
1360
- // _transient_timeout_%
1361
- $transient = substr($results[$j]['option_name'], 19);
1362
- // DELETE THE TRANSIENT
1363
- delete_transient($transient);
1364
- } else {
1365
- // _site_transient_timeout_%
1366
- $transient = substr($results[$j]['option_name'], 24);
1367
- // DELETE THE TRANSIENT
1368
- delete_site_transient($transient);
1369
- } // if(substr($results[$j]->option_name, 0, 19) == '_transient_timeout_')
1370
- } // for($j=0; $j<count($results); $j++)
1371
- } // if (!$analyzing)
1372
-
1373
- $nr++;
1374
- } // for($i=0; $i<count($results); $i++)
1375
-
1376
- return $total_deleted;
1377
- } // odb_delete_transients()
1378
-
1379
-
1380
- /********************************************************************************************
1381
- * GET PINGBACKS AND TRACKBACKS
1382
- ********************************************************************************************/
1383
- function odb_get_pingbacks($analyzing = false) {
1384
-
1385
- global $wpdb, $odb_class;
1386
-
1387
- $res_arr = array();
1388
-
1389
- // LOOP THROUGH SITES
1390
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1391
- $prefix = $odb_class->odb_ms_prefixes[$i];;
1392
-
1393
- $sql = sprintf ("
1394
- SELECT '%s' AS site,
1395
- `comment_ID`,
1396
- `comment_type`,
1397
- `comment_author`,
1398
- `comment_date`
1399
- FROM %scomments
1400
- WHERE (
1401
- `comment_type` = 'pingback' OR `comment_type` = 'trackback'
1402
- )
1403
- ORDER BY `comment_type`, `comment_author`
1404
- ", $prefix, $prefix);
1405
-
1406
- $res = $wpdb->get_results($sql, ARRAY_A);
1407
-
1408
- for($j = 0; $j < count($res); $j++) {
1409
- array_push($res_arr, $res[$j]);
1410
- } // for($j = 0; $j < count($res); $j++)
1411
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1412
- return $res_arr;
1413
- } // odb_get_pingbacks
1414
-
1415
-
1416
- /********************************************************************************************
1417
- * DELETE PINGBACKS AND TRACKBACKS
1418
- ********************************************************************************************/
1419
- function odb_delete_pingbacks($results, $scheduler, $analyzing) {
1420
- global $wpdb, $odb_class;
1421
-
1422
- $nr = 1;
1423
- $total_deleted = count($results);
1424
- for($i=0; $i<count($results); $i++) {
1425
- if (!$scheduler) {
1426
- ?>
1427
- <tr>
1428
- <td align="right" valign="top"><?php echo $nr; ?></td>
1429
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1430
- <td valign="top"><?php echo $results[$i]['comment_type']?></td>
1431
- <td valign="top"><?php echo $results[$i]['comment_author']?></td>
1432
- <td valign="top" nowrap="nowrap"><?php echo $results[$i]['comment_date']; ?></td>
1433
- </tr>
1434
- <?php
1435
- } // if (!$scheduler)
1436
-
1437
- if (!$analyzing) {
1438
- for($j=0; $j<count($results); $j++) {
1439
- // DELETE METADATA FOR THIS COMMENT (IF ANY)
1440
- $sql = sprintf ("
1441
- DELETE FROM %scommentmeta
1442
- WHERE `comment_id` = %d
1443
- ", $results[$j]['site'], $results[$j]['comment_ID']);
1444
- $wpdb->get_results($sql);
1445
-
1446
- $sql = sprintf ("
1447
- DELETE FROM %scomments
1448
- WHERE (
1449
- `comment_type` = 'pingback'
1450
- OR `comment_type` = 'trackback'
1451
- )
1452
- ", $results[$j]['site']);
1453
- $wpdb->get_results($sql);
1454
- } // for($j=0; $j<count($results); $j++)
1455
- } // if (!$analyzing)
1456
-
1457
- $nr++;
1458
- } // for($i=0; $i<count($results); $i++)
1459
-
1460
- return $total_deleted;
1461
- } // odb_delete_pingbacks()
1462
-
1463
-
1464
- /********************************************************************************************
1465
- * GET OEMBED CACHE
1466
- ********************************************************************************************/
1467
- function odb_get_oembed($analyzing = false) {
1468
- global $wpdb, $odb_class;
1469
-
1470
- $res_arr = array();
1471
-
1472
- // LOOP THROUGH SITES
1473
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1474
- $prefix = $odb_class->odb_ms_prefixes[$i];
1475
-
1476
- $sql = sprintf ("
1477
- SELECT '%s' AS site,
1478
- `meta_id`,
1479
- `meta_key`,
1480
- `meta_value`
1481
- FROM %spostmeta
1482
- WHERE `meta_key` LIKE '_oembed_%%'
1483
- ORDER BY `meta_key`
1484
- ", $prefix, $prefix);
1485
-
1486
- $res = $wpdb->get_results($sql, ARRAY_A);
1487
-
1488
- for($j = 0; $j < count($res); $j++) {
1489
- array_push($res_arr, $res[$j]);
1490
- } // for($j = 0; $j < count($res); $j++)
1491
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1492
- return $res_arr;
1493
- } // odb_get_oembed()
1494
-
1495
-
1496
- /********************************************************************************************
1497
- * CLEAR OEMBED CACHE
1498
- ********************************************************************************************/
1499
- function odb_delete_oembed($results, $scheduler, $analyzing) {
1500
- global $wpdb, $odb_class;
1501
-
1502
- $nr = 1;
1503
- $total_deleted = count($results);
1504
- for($i=0; $i<count($results); $i++) {
1505
- if (!$scheduler) {
1506
- ?>
1507
- <tr>
1508
- <td align="right" valign="top"><?php echo $nr; ?></td>
1509
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1510
- <td valign="top"><?php echo $results[$i]['meta_key']?></td>
1511
- <td valign="top"><?php echo $results[$i]['meta_value']?></td>
1512
- </tr>
1513
- <?php
1514
- } // if (!$scheduler)
1515
-
1516
- if (!$analyzing) {
1517
- // DELETE COMMENTS
1518
- $sql = sprintf ("
1519
- DELETE FROM %spostmeta
1520
- WHERE `meta_key` LIKE '_oembed_%%'
1521
- ", $results[$i]['site']);
1522
-
1523
- $wpdb->get_results($sql);
1524
- } // if (!$analyzing)
1525
-
1526
- $nr++;
1527
- } // for($i=0; $i<count($results); $i++)
1528
-
1529
- return $total_deleted;
1530
- } // odb_delete_oembed()
1531
-
1532
-
1533
- /********************************************************************************************
1534
- * GET ORPHAN POSTMETA AND MEDIA RECORDS
1535
- ********************************************************************************************/
1536
- function odb_get_orphans($results, $scheduler, $analyzing) {
1537
- global $wpdb, $odb_class;
1538
-
1539
- $res_arr = array();
1540
-
1541
- // LOOP THROUGH SITES
1542
- for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1543
- $prefix = $odb_class->odb_ms_prefixes[$i];
1544
-
1545
- $sql = sprintf ("
1546
- SELECT '%s' AS site,
1547
- `ID`,
1548
- 'post' AS type,
1549
- `post_title`,
1550
- `post_modified`,
1551
- '' AS meta_key,
1552
- '' AS meta_value
1553
- FROM %sposts
1554
- WHERE ID NOT IN (SELECT post_id FROM %spostmeta)
1555
- AND post_status = 'auto-draft'
1556
- ORDER BY `ID`
1557
- ", $prefix, $prefix, $prefix);
1558
-
1559
- $results = $wpdb->get_results($sql, ARRAY_A);
1560
- for ($j = 0; $j < count($results); $j++) {
1561
- array_push($res_arr, $results[$j]);
1562
- } // for ($j = 0; $j < count($results); $j++)
1563
-
1564
- // DELETE POSTMETA ORPHANS
1565
- $sql = sprintf ("
1566
- SELECT '%s' AS site,
1567
- `post_id` AS ID,
1568
- 'meta' AS type,
1569
- '' AS post_title,
1570
- '' AS post_modified,`meta_key`, `meta_value`
1571
- FROM %spostmeta
1572
- WHERE post_id NOT IN (SELECT ID FROM %sposts)
1573
- ORDER BY `meta_key`
1574
- ", $prefix, $prefix, $prefix);
1575
-
1576
- $results = $wpdb->get_results($sql, ARRAY_A);
1577
- for ($j = 0; $j < count($results); $j++) {
1578
- array_push($res_arr, $results[$j]);
1579
- } // for ($j = 0; $j < count($results); $j++)
1580
- } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1581
- return $res_arr;
1582
- } // odb_get_orphans()
1583
-
1584
-
1585
- /********************************************************************************************
1586
- * DELETE ORPHAN POSTMETA AND MEDIA RECORDS
1587
- ********************************************************************************************/
1588
- function odb_delete_orphans($results, $scheduler, $analyzing) {
1589
-
1590
- global $wpdb, $odb_class;
1591
-
1592
- $nr = 1;
1593
- $total_deleted = count($results);
1594
- for($i=0; $i<count($results); $i++) {
1595
- if (!$scheduler) {
1596
- ?>
1597
- <tr>
1598
- <td align="right" valign="top"><?php echo $nr; ?></td>
1599
- <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1600
- <td valign="top"><?php echo $results[$i]['type']?></td>
1601
- <td valign="top"><?php echo $results[$i]['ID']?></td>
1602
- <td valign="top"><?php echo $results[$i]['post_title']?></td>
1603
- <td valign="top" nowrap="nowrap"><?php echo substr($results[$i]['post_modified'], 0, 10); ?></td>
1604
- <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_key']; ?></td>
1605
- <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_value']; ?></td>
1606
- </tr>
1607
- <?php
1608
- } // if (!$scheduler)
1609
-
1610
- if (!$analyzing) {
1611
- for($j=0; $j<count($results); $j++) {
1612
- // DELETE METADATA FOR THIS COMMENT (IF ANY)
1613
- if ($results[$j]['type'] == 'meta') {
1614
- $sql = sprintf ("
1615
- DELETE FROM %spostmeta
1616
- WHERE `post_id` = %d
1617
- ", $results[$j]['site'], $results[$j]['ID']);
1618
- } else if ($results[$j]['type'] == 'post') {
1619
- $sql = sprintf ("
1620
- DELETE FROM %sposts
1621
- WHERE `ID` = %d
1622
- ", $results[$j]['site'], $results[$j]['ID']);
1623
- } // if ($results[$j]['type'] == 'meta')
1624
- //echo 'SQL: ' . $sql.'<br>';
1625
- $wpdb->get_results($sql);
1626
- }// for($j=0; $j<count($results); $j++)
1627
- } // if (!$analyzing)
1628
- $nr++;
1629
- } // for($i=0; $i<count($results); $i++)
1630
-
1631
- return $total_deleted;
1632
- } // odb_delete_orphans()
1633
-
1634
-
1635
- /********************************************************************************************
1636
- * OPTIMIZE DATABASE TABLES
1637
- ********************************************************************************************/
1638
- function odb_optimize_tables($scheduler) {
1639
- global $odb_class, $wpdb;
1640
-
1641
- $cnt = 0;
1642
- for ($i=0; $i<count($odb_class->odb_tables); $i++) {
1643
- if(!isset($odb_class->odb_rvg_excluded_tabs[$odb_class->odb_tables[$i][0]])) {
1644
- # TABLE NOT EXCLUDED
1645
- $cnt++;
1646
-
1647
- $sql = sprintf ("
1648
- SELECT engine, (data_length + index_length) AS size, table_rows
1649
- FROM information_schema.TABLES
1650
- WHERE table_schema = '%s'
1651
- AND table_name = '%s'
1652
- ", DB_NAME, $odb_class->odb_tables[$i][0]);
1653
- $table_info = $wpdb->get_results($sql);
1654
-
1655
- if($odb_class->odb_rvg_options["optimize_innodb"] == 'N' && strtolower($table_info[0]->engine) == 'innodb') {
1656
- // SKIP InnoDB tables
1657
- $msg = __('InnoDB table: skipped...', 'rvg-optimize-database');
1658
- } else {
1659
- // v4.6.3
1660
- if (strtolower($table_info[0]->engine) == 'myisam') {
1661
- $result = $this->odb_optimize_myisam($odb_class->odb_tables[$i][0]);
1662
- $msg = $result[0]->Msg_text;
1663
- if ($msg == 'OK') {
1664
- $msg = __('<span class="odb-optimized">TABLE OPTIMIZED</span>', 'rvg-optimize-database');
1665
- } else if ($msg == 'Table is already up to date') {
1666
- $msg = __('Table is already up to date', 'rvg-optimize-database');
1667
- }
1668
- } else {
1669
- $result = $this->odb_optimize_innodb($odb_class->odb_tables[$i][0]);
1670
- $msg = $result[0]->Msg_text;
1671
- if ($msg == 'Table is already up to date') {
1672
- $msg = __('Table is already up to date', 'rvg-optimize-database');
1673
- } else {
1674
- $msg = __('<span class="odb-optimized">TABLE OPTIMIZED</span>', 'rvg-optimize-database');
1675
- }
1676
- } // if (strtolower($table_info[0]->engine) == 'myisam')
1677
- } // if($odb_class->odb_rvg_options["optimize_innodb"] == 'N' && strtolower($table_info[0]->engine) == 'innodb')
1678
-
1679
- if (!$scheduler)
1680
- { // NOT FROM THE SCEDULER
1681
- ?>
1682
- <tr>
1683
- <td align="right" valign="top"><?php echo $cnt?>.</td>
1684
- <td valign="top" class="odb-bold"><?php echo $odb_class->odb_tables[$i][0] ?></td>
1685
- <td valign="top"><?php echo $msg ?></td>
1686
- <td valign="top"><?php echo $table_info[0]->engine ?></td>
1687
- <td align="right" valign="top"><?php echo $table_info[0]->table_rows ?></td>
1688
- <td align="right" valign="top"><?php echo $odb_class->odb_utilities_obj->odb_format_size($table_info[0]->size) ?></td>
1689
- </tr>
1690
- <?php
1691
- } // if (!$scheduler)
1692
- } // if(!$excluded)
1693
- } // for ($i=0; $i<count($tables); $i++)
1694
- return $cnt;
1695
-
1696
- } // odb_optimize_tables()
1697
-
1698
-
1699
- /********************************************************************************************
1700
- * OPTIMIZE A MyISAM TABLE
1701
- ********************************************************************************************/
1702
- function odb_optimize_myisam($table_name) {
1703
- global $wpdb;
1704
- $query = "OPTIMIZE TABLE " . $table_name;
1705
- return $wpdb->get_results($query);
1706
- } // odb_optimize_myisam()
1707
-
1708
-
1709
- /********************************************************************************************
1710
- * OPTIMIZE AN InnoDB TABLE
1711
- ********************************************************************************************/
1712
- function odb_optimize_innodb($table_name) {
1713
- global $wpdb;
1714
-
1715
- $query = "OPTIMIZE TABLE " . $table_name;
1716
- return $wpdb->get_results($query);
1717
-
1718
- /* // https://www.percona.com/blog/2010/12/09/mysql-optimize-tables-innodb-stop/
1719
- $query = "SHOW KEYS FROM " . $table_name . " WHERE Key_name <> 'PRIMARY'";
1720
- $result = $wpdb->get_results($query);
1721
- if (count($result) > 0) {
1722
- for ($i = 0; $i < count($result); $i++) {
1723
- $key_name = $result[$i]->Key_name;
1724
-
1725
- $query = "ALTER TABLE " . $table_name . " DROP KEY " . $key_name;
1726
- $result = $wpdb->get_results($query);
1727
-
1728
- $query = "ALTER TABLE " . $table_name . " add key(" . $key_name . ")";
1729
- $result = $wpdb->get_results($query);
1730
- } // for ($i = 0; $i < count($result); $i++)
1731
- return __('<span class="odb-optimized">TABLE OPTIMIZED</span>', 'rvg-optimize-database');
1732
- } else {
1733
- return __('Table is already up to date', 'rvg-optimize-database');
1734
- } // if (count($result) > 0*/
1735
- } // odb_optimize_innodb()
1736
-
1737
- } // ODB_Cleaner
1738
  ?>
1
+ <?php
2
+ /************************************************************************************************
3
+ *
4
+ * CLEANER CLASS: DOING THE REAL CLEANING / OPTIMIZATION
5
+ *
6
+ ************************************************************************************************/
7
+ ?>
8
+ <?php
9
+ class ODB_Cleaner {
10
+ var $start_size;
11
+ var $nr_of_optimized_tables;
12
+
13
+
14
+ /********************************************************************************************
15
+ * CONSTRUCTOR
16
+ ********************************************************************************************/
17
+ function __construct() {
18
+ } // __construct()
19
+
20
+
21
+ /********************************************************************************************
22
+ * RUN CLEANER
23
+ ********************************************************************************************/
24
+ function odb_run_cleaner($scheduler, $analyzing = false) {
25
+ global $odb_class;
26
+
27
+ if(!$scheduler) {
28
+ if ($analyzing) {
29
+ echo '
30
+ <div id="odb-cleaner" class="odb-padding-left">
31
+ <div class="odb-title-bar">
32
+ <h2>'.__('Analyzing Database', $odb_class->odb_txt_domain).'</h2>
33
+ </div>
34
+ <br>
35
+ <br>
36
+ ';
37
+ } else {
38
+ echo '
39
+ <div id="odb-cleaner" class="odb-padding-left">
40
+ <div class="odb-title-bar">
41
+ <h2>'.__('Cleaning Database', $odb_class->odb_txt_domain).'</h2>
42
+ </div>
43
+ <br>
44
+ <br>
45
+ ';
46
+ }
47
+ } // if(!$scheduler)
48
+
49
+ // GET THE SIZE OF THE DATABASE BEFORE OPTIMIZATION
50
+ $this->start_size = $odb_class->odb_utilities_obj->odb_get_db_size();
51
+
52
+ // TIMESTAMP FOR LOG FILE - v4.6
53
+ $ct = ($scheduler) ? ' (cron)' : '';
54
+
55
+ $odb_class->log_arr["timestamp"] = current_time('YmdHis', 0);
56
+ $odb_class->log_arr["after"] = 0;
57
+ $odb_class->log_arr["before"] = 0;
58
+ $odb_class->log_arr["orphans"] = 0;
59
+ $odb_class->log_arr["pingbacks"] = 0;
60
+ $odb_class->log_arr["oembeds"] = 0;
61
+ $odb_class->log_arr["orphans"] = 0;
62
+ $odb_class->log_arr["revisions"] = 0;
63
+ $odb_class->log_arr["savings"] = 0;
64
+ $odb_class->log_arr["spam"] = 0;
65
+ $odb_class->log_arr["tables"] = 0;
66
+ $odb_class->log_arr["tags"] = 0;
67
+ $odb_class->log_arr["transients"] = 0;
68
+ $odb_class->log_arr["trash"] = 0;
69
+
70
+ /****************************************************************************************
71
+ * DELETE REVISIONS
72
+ ****************************************************************************************/
73
+ if($odb_class->odb_rvg_options['delete_older'] == 'Y' || $odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
74
+ // FIND REVISIONS
75
+ $results_older_than = array();
76
+ if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
77
+ $results_older_than = $this->odb_get_revisions_older_than();
78
+ }
79
+
80
+ $results_keep_revisions = array();
81
+ if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
82
+ $results_keep_revisions = $this->odb_get_revisions_keep_revisions();
83
+ }
84
+
85
+ $total_deleted = 0;
86
+ if(count($results_older_than) > 0 || count($results_keep_revisions) > 0) {
87
+ // WE HAVE REVISIONS TO DELETE!
88
+ if(!$scheduler) {
89
+ if ($analyzing) {
90
+ $msg1 = __('REVISIONS','rvg-optimize-database');
91
+ $msg2 = __('revisions', $odb_class->odb_txt_domain);
92
+ } else {
93
+ $msg1 = __('DELETED REVISIONS','rvg-optimize-database');
94
+ $msg2 = __('revisions deleted', $odb_class->odb_txt_domain);
95
+ }
96
+ ?>
97
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
98
+ <tr>
99
+ <td colspan="4"><div class="odb-found"><?php echo $msg1?></div></td>
100
+ </tr>
101
+ <tr>
102
+ <th align="right" class="odb-border-bottom">#</th>
103
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
104
+ <th align="left" class="odb-border-bottom"><?php _e('post / page', $odb_class->odb_txt_domain);?></th>
105
+ <th align="left" class="odb-border-bottom"><?php _e('revision date', $odb_class->odb_txt_domain);?></th>
106
+ <th align="right" class="odb-border-bottom"><?php echo $msg2?></th>
107
+ </tr>
108
+ <?php
109
+ } // if(!$scheduler)
110
+
111
+ // LOOP THROUGH THE REVISIONS AND DELETE THEM
112
+ $total_deleted = $this->odb_delete_revisions($scheduler, $analyzing);
113
+
114
+ if(!$scheduler) {
115
+ if ($analyzing) {
116
+ $msg1 = __('total number of revisions', $odb_class->odb_txt_domain);
117
+ } else {
118
+ $msg1 = __('total number of revisions deleted', $odb_class->odb_txt_domain);
119
+ } // if (!$analyzing)
120
+ ?>
121
+ <tr>
122
+ <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg1 ?>: <?php echo $total_deleted?></td>
123
+ </tr>
124
+ </table>
125
+ <?php
126
+ } // if(!$scheduler)
127
+ } else {
128
+ if(!$scheduler) {
129
+ ?>
130
+ <div class="odb-not-found">
131
+ <?php _e('No REVISIONS found to delete', $odb_class->odb_txt_domain);?>
132
+ </div>
133
+ <?php
134
+ } // if(!$scheduler)
135
+ } // if(count($results)>0)
136
+
137
+ // NUMBER OF DELETED REVISIONS FOR LOG FILE
138
+ $odb_class->log_arr["revisions"] = $total_deleted;
139
+ } // if($odb_class->odb_rvg_options['delete_older'] == 'Y' || $odb_class->odb_rvg_options['rvg_revisions'] == 'Y')
140
+
141
+
142
+ /****************************************************************************************
143
+ * DELETE TRASHED ITEMS
144
+ ****************************************************************************************/
145
+ if($odb_class->odb_rvg_options['clear_trash'] == 'Y') {
146
+ // GET TRASHED POSTS / PAGES AND COMMENTS
147
+ $results = $this->odb_get_trash($analyzing);
148
+
149
+ $total_deleted = 0;
150
+ if(count($results)>0) {
151
+ // WE HAVE TRASH TO DELETE!
152
+ if(!$scheduler) {
153
+ if ($analyzing) {
154
+ $msg1 = __('TRASHED ITEMS', $odb_class->odb_txt_domain);
155
+ $msg2 = __('total number of trashed items', $odb_class->odb_txt_domain);
156
+ } else {
157
+ $msg1 = __('DELETED TRASHED ITEMS', $odb_class->odb_txt_domain);
158
+ $msg2 = __('total number of trashed items deleted', $odb_class->odb_txt_domain);
159
+ } // if ($analyzing)
160
+ ?>
161
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
162
+ <tr>
163
+ <td colspan="4"><div class="odb-found">
164
+ <?php echo $msg1 ?>
165
+ </div></td>
166
+ </tr>
167
+ <tr>
168
+ <th align="right" class="odb-border-bottom">#</th>
169
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
170
+ <th align="left" class="odb-border-bottom"><?php _e('type', $odb_class->odb_txt_domain);?></th>
171
+ <th align="left" class="odb-border-bottom"><?php _e('IP address / title', $odb_class->odb_txt_domain);?></th>
172
+ <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('date', $odb_class->odb_txt_domain);?></th>
173
+ </tr>
174
+ <?php
175
+ } // if(!$scheduler)
176
+
177
+ // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
178
+ $total_deleted = $this->odb_delete_trash($results, $scheduler, $analyzing);
179
+
180
+ if(!$scheduler) {
181
+ ?>
182
+ <tr>
183
+ <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
184
+ </tr>
185
+ </table>
186
+ <?php
187
+ } // if(!$scheduler)
188
+ } else {
189
+ if(!$scheduler) {
190
+ ?>
191
+ <div class="odb-not-found">
192
+ <?php _e('No TRASHED ITEMS found to delete', $odb_class->odb_txt_domain);?>
193
+ </div>
194
+ <?php
195
+ } // if(!$scheduler)
196
+ } // if(count($results)>0)
197
+
198
+ // NUMBER OF DELETED TRASH FOR LOG FILE
199
+ $odb_class->log_arr["trash"] = $total_deleted;
200
+ } // if($odb_class->odb_rvg_options['clear_trash'] == 'Y')
201
+
202
+
203
+ /****************************************************************************************
204
+ * DELETE SPAMMED ITEMS
205
+ ****************************************************************************************/
206
+ if($odb_class->odb_rvg_options['clear_spam'] == 'Y') {
207
+ // GET SPAMMED COMMENTS
208
+ $results = $this->odb_get_spam($analyzing);
209
+
210
+ $total_deleted = 0;
211
+ if(count($results)>0) {
212
+ // WE HAVE SPAM TO DELETE!
213
+ if (!$scheduler) {
214
+ if ($analyzing) {
215
+ $msg1 = __('SPAMMED ITEMS', $odb_class->odb_txt_domain);
216
+ $msg2 = __('total number of spammed items', $odb_class->odb_txt_domain);
217
+ } else {
218
+ $msg1 = __('DELETED SPAMMED ITEMS', $odb_class->odb_txt_domain);
219
+ $msg2 = __('total number of spammed items deleted', $odb_class->odb_txt_domain);
220
+ } // if ($analyzing)
221
+ ?>
222
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
223
+ <tr>
224
+ <td colspan="4"><div class="odb-found">
225
+ <?php echo $msg1 ?>
226
+ </div></td>
227
+ </tr>
228
+ <tr>
229
+ <th align="right" class="odb-border-bottom">#</th>
230
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
231
+ <th align="left" class="odb-border-bottom"><?php _e('comment author', $odb_class->odb_txt_domain);?></th>
232
+ <th align="left" class="odb-border-bottom"><?php _e('comment author email', $odb_class->odb_txt_domain);?></th>
233
+ <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('comment date', $odb_class->odb_txt_domain);?></th>
234
+ </tr>
235
+ <?php
236
+ } // if (!$scheduler)
237
+
238
+ // LOOP THROUGH SPAMMED ITEMS AND DELETE THEM
239
+ $total_deleted = $this->odb_delete_spam($results, $scheduler, $analyzing);
240
+
241
+ if (!$scheduler) {
242
+ ?>
243
+ <tr>
244
+ <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
245
+ </tr>
246
+ </table>
247
+ <?php
248
+ } // if (!$scheduler)
249
+ } else{
250
+ if (!$scheduler) {
251
+ ?>
252
+ <div class="odb-not-found">
253
+ <?php _e('No SPAMMED ITEMS found to delete', $odb_class->odb_txt_domain);?>
254
+ </div>
255
+ <?php
256
+ } // if (!$scheduler)
257
+ } // if(count($results)>0)
258
+
259
+ // NUMBER OF SPAM DELETED FOR LOG FILE
260
+ $odb_class->log_arr["spam"] = $total_deleted;
261
+ } // if($odb_class->odb_rvg_options['clear_spam'] == 'Y')
262
+
263
+
264
+ /****************************************************************************************
265
+ * DELETE UNUSED TAGS
266
+ ****************************************************************************************/
267
+ if($odb_class->odb_rvg_options['clear_tags'] == 'Y') {
268
+ // GET UNUSED TAGS
269
+ $results = $this->odb_get_unused_tags($analyzing);
270
+
271
+ $total_deleted = 0;
272
+
273
+ if(count($results)>0) {
274
+ // WE HAVE TAGS TO DELETE!
275
+ if (!$scheduler) {
276
+ if ($analyzing) {
277
+ $msg1 = __('UNUSED TAGS', $odb_class->odb_txt_domain);
278
+ $msg2 = __('total number of unused tags', $odb_class->odb_txt_domain);
279
+ } else {
280
+ $msg1 = __('DELETED UNUSED TAGS', $odb_class->odb_txt_domain);
281
+ $msg2 = __('total number of unused tags deleted', $odb_class->odb_txt_domain);
282
+ }
283
+ ?>
284
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
285
+ <tr>
286
+ <td colspan="4"><div class="odb-found">
287
+ <?php echo $msg1 ?>
288
+ </div></td>
289
+ </tr>
290
+ <tr>
291
+ <th align="right" class="odb-border-bottom">#</th>
292
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
293
+ <th align="left" class="odb-border-bottom"><?php _e('tag', $odb_class->odb_txt_domain);?></th>
294
+ </tr>
295
+ <?php
296
+ } // if (!$scheduler)
297
+
298
+ // LOOP THROUGH UNUSED TAGS AND DELETE THEM
299
+ $total_deleted = $this->odb_delete_unused_tags($results, $scheduler, $analyzing);
300
+
301
+ if (!$scheduler) {
302
+ ?>
303
+ <tr>
304
+ <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
305
+ </tr>
306
+ </table>
307
+ <?php
308
+ } // if (!$scheduler)
309
+ } else {
310
+ if (!$scheduler) {
311
+ ?>
312
+ <div class="odb-not-found">
313
+ <?php _e('No UNUSED TAGE found to delete', $odb_class->odb_txt_domain);?>
314
+ </div>
315
+ <?php
316
+ } // if (!$scheduler)
317
+ } // if(count($results)>0)
318
+
319
+ // NUMBER OF SPAM DELETED FOR LOG FILE
320
+ $odb_class->log_arr["tags"] = $total_deleted;
321
+ } // if($odb_class->odb_rvg_options['clear_spam'] == 'Y')
322
+
323
+
324
+ /****************************************************************************************
325
+ * DELETE EXPIRED TRANSIENTS
326
+ ****************************************************************************************/
327
+ if($odb_class->odb_rvg_options['clear_transients'] != 'N') {
328
+ // GET TRANSIENTS
329
+ $results = $this->odb_get_transients($analyzing);
330
+
331
+ $total_deleted = 0;
332
+
333
+ if(count($results)>0) {
334
+ // WE HAVE SPAM TO DELETE!
335
+ if (!$scheduler) {
336
+ if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
337
+ if ($analyzing){
338
+ $msg1 = __('EXPIRED TRANSIENTS', $odb_class->odb_txt_domain);
339
+ $msg2 = __('total number of expired transients', $odb_class->odb_txt_domain);
340
+ } else {
341
+ $msg1 = __('EXPIRED TRANSIENTS DELETED', $odb_class->odb_txt_domain);
342
+ $msg2 = __('total number of expired transients deleted', $odb_class->odb_txt_domain);
343
+ }
344
+ } else {
345
+ if ($analyzing){
346
+ $msg1 = __('TRANSIENTS', $odb_class->odb_txt_domain);
347
+ $msg2 = __('total number of transients', $odb_class->odb_txt_domain);
348
+ } else {
349
+ $msg1 = __('TRANSIENTS DELETED', $odb_class->odb_txt_domain);
350
+ $msg2 = __('total number of transients', $odb_class->odb_txt_domain);
351
+ }
352
+ } // if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
353
+ ?>
354
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
355
+ <tr>
356
+ <td colspan="4"><div class="odb-found">
357
+ <?php echo $msg1 ?>
358
+ </div></td>
359
+ </tr>
360
+ <tr>
361
+ <th align="right" class="odb-border-bottom">#</th>
362
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
363
+ <th align="left" class="odb-border-bottom"><?php _e('option name', $odb_class->odb_txt_domain);?></th>
364
+ </tr>
365
+ <?php
366
+ } // if (!$scheduler)
367
+
368
+ // LOOP THROUGH SPAMMED ITEMS AND DELETE THEM
369
+ $total_deleted = $this->odb_delete_transients($results, $scheduler, $analyzing);
370
+
371
+ if (!$scheduler) {
372
+ ?>
373
+ <tr>
374
+ <td colspan="3" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
375
+ </tr>
376
+ </table>
377
+ <?php
378
+ } // if (!$scheduler)
379
+ } else{
380
+ if (!$scheduler) {
381
+ ?>
382
+ <div class="odb-not-found">
383
+ <?php
384
+ if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
385
+ $msg = __('No EXPIRED TRANSIENTS found to delete', $odb_class->odb_txt_domain);
386
+ } else {
387
+ $msg = __('No TRANSIENTS found to delete', $odb_class->odb_txt_domain);
388
+ }
389
+ ?>
390
+ </div>
391
+ <?php
392
+ } // if (!$scheduler)
393
+ } // if(count($results)>0)
394
+
395
+ // NUMBER OF SPAM DELETED FOR LOG FILE
396
+ $odb_class->log_arr["transients"] = $total_deleted;
397
+ } // if($odb_class->odb_rvg_options['clear_transients'] == 'Y')
398
+
399
+ /****************************************************************************************
400
+ * DELETE PINGBACKS AND TRACKBACKS
401
+ ****************************************************************************************/
402
+ if($odb_class->odb_rvg_options['clear_pingbacks'] == 'Y') {
403
+ // GET PINGBACKS AND TRACKBACKS
404
+ $results = $this->odb_get_pingbacks($analyzing);
405
+
406
+ $total_deleted = 0;
407
+ if(count($results)>0) {
408
+ // WE HAVE TRASH TO DELETE!
409
+ if(!$scheduler) {
410
+ if ($analyzing) {
411
+ $msg1 = __('PINGBACKS AND TRACKBACKS', $odb_class->odb_txt_domain);
412
+ $msg2 = __('total number of pingbacks and trackbacks', $odb_class->odb_txt_domain);
413
+ } else {
414
+ $msg1 = __('DELETED PINGBACKS AND TRACKBACKS', $odb_class->odb_txt_domain);
415
+ $msg2 = __('total number of pingbacks and trackbacks deleted', $odb_class->odb_txt_domain);
416
+ } // if ($analyzing)
417
+ ?>
418
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
419
+ <tr>
420
+ <td colspan="4"><div class="odb-found">
421
+ <?php echo $msg1 ?>
422
+ </div></td>
423
+ </tr>
424
+ <tr>
425
+ <th align="right" class="odb-border-bottom">#</th>
426
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
427
+ <th align="left" class="odb-border-bottom"><?php _e('type', $odb_class->odb_txt_domain);?></th>
428
+ <th align="left" class="odb-border-bottom"><?php _e('comment_author', $odb_class->odb_txt_domain);?></th>
429
+ <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('date', $odb_class->odb_txt_domain);?></th>
430
+ </tr>
431
+ <?php
432
+ } // if(!$scheduler)
433
+
434
+ // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
435
+ $total_deleted = $this->odb_delete_pingbacks($results, $scheduler, $analyzing);
436
+
437
+ if(!$scheduler) {
438
+ ?>
439
+ <tr>
440
+ <td colspan="5" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
441
+ </tr>
442
+ </table>
443
+ <?php
444
+ } // if(!$scheduler)
445
+ } else {
446
+ if(!$scheduler) {
447
+ ?>
448
+ <div class="odb-not-found">
449
+ <?php _e('No PINGBACKS nor TRACKBACKS found to delete', $odb_class->odb_txt_domain);?>
450
+ </div>
451
+ <?php
452
+ } // if(!$scheduler)
453
+ } // if(count($results)>0)
454
+
455
+ // NUMBER OF DELETED PINGBACKS FOR LOG FILE
456
+ $odb_class->log_arr["pingbacks"] = $total_deleted;
457
+ } // if($odb_class->odb_rvg_options['clear_pingbacks'] == 'Y')
458
+
459
+
460
+ /****************************************************************************************
461
+ * DELETE OEMBED CACHE
462
+ ****************************************************************************************/
463
+ if($odb_class->odb_rvg_options['clear_oembed'] == 'Y') {
464
+
465
+ // GET OEMBED CACHE
466
+ $results = $this->odb_get_oembed($analyzing);
467
+
468
+ $total_deleted = 0;
469
+ if(count($results)>0) {
470
+ // WE HAVE TRASH TO DELETE!
471
+ if(!$scheduler) {
472
+ if ($analyzing) {
473
+ $msg1 = __('OEMBED CACHE', $odb_class->odb_txt_domain);
474
+ $msg2 = __('total number of oEmbeds', $odb_class->odb_txt_domain);
475
+ } else {
476
+ $msg1 = __('DELETED OEMBEDS', $odb_class->odb_txt_domain);
477
+ $msg2 = __('total number of oEmbeds deleted', $odb_class->odb_txt_domain);
478
+ } // if ($analyzing)
479
+ ?>
480
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
481
+ <tr>
482
+ <td colspan="4"><div class="odb-found">
483
+ <?php echo $msg1 ?>
484
+ </div></td>
485
+ </tr>
486
+ <tr>
487
+ <th align="right" class="odb-border-bottom">#</th>
488
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
489
+ <th align="left" class="odb-border-bottom"><?php _e('meta key', $odb_class->odb_txt_domain);?></th>
490
+ <th align="left" class="odb-border-bottom"><?php _e('meta value', $odb_class->odb_txt_domain);?></th>
491
+ </tr>
492
+ <?php
493
+ } // if(!$scheduler)
494
+
495
+ // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
496
+ $total_deleted = $this->odb_delete_oembed($results, $scheduler, $analyzing);
497
+
498
+ if(!$scheduler) {
499
+ ?>
500
+ <tr>
501
+ <td colspan="4" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?>: <?php echo $total_deleted?></td>
502
+ </tr>
503
+ </table>
504
+ <?php
505
+ } // if(!$scheduler)
506
+ } else {
507
+ if(!$scheduler) {
508
+ ?>
509
+ <div class="odb-not-found">
510
+ <?php _e('No OEMED CHACHE found to delete', $odb_class->odb_txt_domain);?>
511
+ </div>
512
+ <?php
513
+ } // if(!$scheduler)
514
+ } // if(count($results)>0)
515
+
516
+ // NUMBER OF DELETED PINGBACKS FOR LOG FILE
517
+ $odb_class->log_arr["oembeds"] = $total_deleted;
518
+ } // if($odb_class->odb_rvg_options['clear_oembed'] == 'Y')
519
+
520
+
521
+ /****************************************************************************************
522
+ * DELETE ORPHANS
523
+ ****************************************************************************************/
524
+ if($odb_class->odb_rvg_options['clear_orphans'] == 'Y') {
525
+ $results = $this->odb_get_orphans($results, $scheduler,$analyzing);
526
+
527
+ $total_deleted = count($results);
528
+
529
+ //$total_deleted = $this->odb_delete_orphans($analyzing);
530
+
531
+ if($total_deleted > 0) {
532
+ if (!$scheduler) {
533
+ if ($analyzing) {
534
+ $msg1 = __('POSTMETA ORPHANS', $odb_class->odb_txt_domain);
535
+ $msg2 = __('total number of orphans', $odb_class->odb_txt_domain);
536
+ } else {
537
+ $msg1 = __('DELETED POSTMETA ORPHANS', $odb_class->odb_txt_domain);
538
+ $msg2 = __('total number of orphans', $odb_class->odb_txt_domain);
539
+ }
540
+ ?>
541
+ <!-- <div class="odb-found-number">
542
+ <?php echo $msg1 ?>: <span class="odb-blue"><?php echo $total_deleted;?></span>
543
+ </div>-->
544
+ <table border="0" cellspacing="8" cellpadding="2" class="odb-result-table">
545
+ <tr>
546
+ <td colspan="8"><div class="odb-found">
547
+ <?php echo $msg1 ?>
548
+ </div></td>
549
+ </tr>
550
+ <tr>
551
+ <th align="right" class="odb-border-bottom">#</th>
552
+ <th align="left" class="odb-border-bottom"><?php _e('prefix', $odb_class->odb_txt_domain);?></th>
553
+ <th align="left" class="odb-border-bottom"><?php _e('type', $odb_class->odb_txt_domain);?></th>
554
+ <th align="left" class="odb-border-bottom"><?php _e('id', $odb_class->odb_txt_domain);?></th>
555
+ <th align="left" class="odb-border-bottom"><?php _e('title', $odb_class->odb_txt_domain);?></th>
556
+ <th align="left" nowrap="nowrap" class="odb-border-bottom"><?php _e('modified', $odb_class->odb_txt_domain);?></th>
557
+ <th align="left" class="odb-border-bottom"><?php _e('meta key', $odb_class->odb_txt_domain);?></th>
558
+ <th align="left" class="odb-border-bottom"><?php _e('meta value', $odb_class->odb_txt_domain);?></th>
559
+ </tr>
560
+ <?php
561
+ } // if(!$scheduler)
562
+
563
+ // LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
564
+ $total_deleted = $this->odb_delete_orphans($results, $scheduler, $analyzing);
565
+
566
+ if(!$scheduler) {
567
+ ?>
568
+ <tr>
569
+ <td colspan="8" align="right" class="odb-border-top odb-bold"><?php echo $msg2 ?> <?php echo $total_deleted?></td>
570
+ </tr>
571
+ </table>
572
+
573
+ <?php
574
+ } // if (!$scheduler)
575
+ } else {
576
+ if (!$scheduler) {
577
+ ?>
578
+ <div class="odb-not-found">
579
+ <?php _e('No POSTMETA ORPHANS found to delete', $odb_class->odb_txt_domain);?>
580
+ </div>
581
+ <?php
582
+ } // if (!$scheduler)
583
+ } // if($total_deleted > 0)
584
+ // FOR LOG FILE
585
+ $odb_class->log_arr["orphans"] = $total_deleted;
586
+
587
+ if (!$scheduler) {
588
+ ?>
589
+ </div><!-- /odb-cleaner -->
590
+ <?php
591
+ } // if (!$scheduler)
592
+ } // if($odb_class->odb_rvg_options['clear_oembed'] == 'Y')
593
+ } // odb_run_cleaner()
594
+
595
+
596
+ /********************************************************************************************
597
+ * RUN OPTIMIZER
598
+ ********************************************************************************************/
599
+ function odb_run_optimizer($scheduler) {
600
+ global $odb_class;
601
+
602
+ if(!$scheduler) {
603
+ ?>
604
+ <div class="odb-optimizing-table" class="odb-padding-left">
605
+ <div class="odb-title-bar">
606
+ <h2><?php _e('Optimizing Database Tables', $odb_class->odb_txt_domain);?></h2>
607
+ </div>
608
+ <br>
609
+ <br>
610
+ <table border="0" cellspacing="8" cellpadding="2">
611
+ <tr>
612
+ <th class="odb-border-bottom" align="right">#</th>
613
+ <th class="odb-border-bottom" align="left"><?php _e('table name', $odb_class->odb_txt_domain);?></th>
614
+ <th class="odb-border-bottom" align="left"><?php _e('optimization result', $odb_class->odb_txt_domain);?></th>
615
+ <th class="odb-border-bottom" align="left"><?php _e('engine', $odb_class->odb_txt_domain);?></th>
616
+ <th class="odb-border-bottom" align="right"><?php _e('table rows', $odb_class->odb_txt_domain);?></th>
617
+ <th class="odb-border-bottom" align="right"><?php _e('table size', $odb_class->odb_txt_domain);?></th>
618
+ </tr>
619
+ <?php
620
+ } // if(!$scheduler)
621
+
622
+ # OPTIMIZE THE DATABASE TABLES
623
+ $this->nr_of_optimized_tables = $this->odb_optimize_tables($scheduler);
624
+
625
+ if(!$scheduler) {
626
+ ?>
627
+ </table>
628
+ </div><!-- /odb-optimizing-table -->
629
+ <?php
630
+ } // if(!$scheduler)
631
+ } // odb_run_optimizer()
632
+
633
+
634
+ /********************************************************************************************
635
+ * CALCULATE AND DISPLAY SAVINGS
636
+ ********************************************************************************************/
637
+ function odb_savings($scheduler) {
638
+ global $odb_class;
639
+ global $odb_logger_obj;
640
+
641
+ // NUMBER OF TABLES
642
+ $odb_class->log_arr["tables"] = $this->nr_of_optimized_tables;
643
+ // DATABASE SIZE BEFORE OPTIMIZATION
644
+ $odb_class->log_arr["before"] = $odb_class->odb_utilities_obj->odb_format_size($this->start_size,3);
645
+ // DATABASE SIZE AFTER OPTIMIZATION
646
+ $end_size = $odb_class->odb_utilities_obj->odb_get_db_size();
647
+ $odb_class->log_arr["after"] = $odb_class->odb_utilities_obj->odb_format_size($end_size,3);
648
+ // TOTAL SAVING
649
+ $odb_class->log_arr["savings"] = $odb_class->odb_utilities_obj->odb_format_size(($this->start_size - $end_size),3);
650
+
651
+ // WRITE RESULTS TO LOG FILE - v4.6
652
+ $odb_class->odb_logger_obj->odb_add_log($odb_class->log_arr);
653
+
654
+ $total_savings = $odb_class->odb_rvg_options['total_savings'];
655
+ $total_savings += ($this->start_size - $end_size);
656
+ $odb_class->odb_rvg_options['total_savings'] = $total_savings;
657
+
658
+ $odb_class->odb_multisite_obj->odb_ms_update_option('odb_rvg_options', $odb_class->odb_rvg_options);
659
+
660
+ if(!$scheduler) {
661
+ ?>
662
+ <div id="odb-savings" class="odb-padding-left">
663
+ <div class="odb-title-bar">
664
+ <h2><?php _e('Savings', $odb_class->odb_txt_domain);?></h2>
665
+ </div>
666
+ <br>
667
+ <br>
668
+ <table border="0" cellspacing="8" cellpadding="2">
669
+ <tr>
670
+ <th>&nbsp;</th>
671
+ <th class="odb-border-bottom"><?php _e('size of the database', $odb_class->odb_txt_domain);?></th>
672
+ </tr>
673
+ <tr>
674
+ <td align="right"><?php _e('BEFORE optimization', $odb_class->odb_txt_domain);?></td>
675
+ <td align="right" class="odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size($this->start_size,3); ?></td>
676
+ </tr>
677
+ <tr>
678
+ <td align="right"><?php _e('AFTER optimization', $odb_class->odb_txt_domain);?></td>
679
+ <td align="right" class="odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size($end_size,3); ?></td>
680
+ </tr>
681
+ <tr>
682
+ <td align="right" class="odb-bold"><?php _e('SAVINGS THIS TIME', $odb_class->odb_txt_domain);?></td>
683
+ <td align="right" class="odb-border-top odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size(($this->start_size - $end_size),3); ?></td>
684
+ </tr>
685
+ <tr>
686
+ <td align="right" class="odb-bold"><?php _e('TOTAL SAVINGS SINCE THE FIRST RUN', $odb_class->odb_txt_domain);?></td>
687
+ <td align="right" class="odb-border-top odb-bold"><?php echo $odb_class->odb_utilities_obj->odb_format_size($total_savings,3); ?></td>
688
+ </tr>
689
+ </table>
690
+ </div><!-- /odb-savings -->
691
+ <?php
692
+ } // if(!$scheduler)
693
+ } // odb_savings()
694
+
695
+
696
+ /********************************************************************************************
697
+ * SHOW LOADING TIME
698
+ ********************************************************************************************/
699
+ function odb_done($analyze = false) {
700
+ global $odb_class;
701
+
702
+ $time = microtime();
703
+ $time = explode(' ', $time);
704
+ $time = $time[1] + $time[0];
705
+ $finish = $time;
706
+
707
+ $total_time = round(($finish - $odb_class->odb_start_time), 4);
708
+ ?>
709
+ <div id="odb-done" class="odb-padding-left">
710
+ <div class="odb-title-bar">
711
+ <h2>
712
+ <?php _e('DONE!', $odb_class->odb_txt_domain);?>
713
+ </h2>
714
+ </div>
715
+ <br>
716
+ <br>
717
+ <?php
718
+ if ($analyze) {
719
+ ?>
720
+ <span class="odb-padding-left"><?php _e('Analysis took', $odb_class->odb_txt_domain)?>&nbsp;<strong><?php echo $total_time;?></strong>&nbsp;<?php _e('seconds', $odb_class->odb_txt_domain)?>.</span>
721
+ <?php
722
+ } else {
723
+ ?>
724
+ <span class="odb-padding-left"><?php _e('Optimization took', $odb_class->odb_txt_domain)?>&nbsp;<strong><?php echo $total_time;?></strong>&nbsp;<?php _e('seconds', $odb_class->odb_txt_domain)?>.</span>
725
+ <?php
726
+ } // if ($analyze)
727
+ ?>
728
+ <?php
729
+ // v4.5.1
730
+ $odb_class->odb_last_run_seconds = $total_time;
731
+
732
+ if($odb_class->odb_logger_obj->odb_log_count() > 0) {
733
+ ?>
734
+ <script>
735
+ function odb_confirm_delete() {
736
+ <?php
737
+ // v4.6.2
738
+ $msg = str_replace("'", "\'", __('Clear the log?', $odb_class->odb_txt_domain));
739
+ ?>
740
+ if(confirm('<?php echo $msg?>')) {
741
+ self.location = 'tools.php?page=rvg-optimize-database&action=clear_log'
742
+ return;
743
+ }
744
+ } // odb_confirm_delete()
745
+ </script>
746
+ <br><br>
747
+ &nbsp;
748
+ <input class="button odb-normal" type="button" name="view_log" value="<?php _e('View Log', $odb_class->odb_txt_domain);?>" onclick="self.location='tools.php?page=rvg-optimize-database&action=view_log'" />
749
+ &nbsp;
750
+ <input class="button odb-normal" type="button" name="clear_log" value="<?php _e('Clear Log', $odb_class->odb_txt_domain);?>" onclick="return odb_confirm_delete();" />
751
+ <?php
752
+ } // if($odb_class->odb_logger_obj->odb_log_count() > 0)
753
+ ?>
754
+ </div><!-- /odb-done -->
755
+ <?php
756
+ } // odb_done()
757
+
758
+
759
+ /********************************************************************************************
760
+ * GET REVISIONS (OLDER THAN x DAYS)
761
+ ********************************************************************************************/
762
+ function odb_get_revisions_older_than() {
763
+ global $odb_class, $wpdb;
764
+
765
+ $res_arr = array();
766
+
767
+ // CUSTOM POST TYPES (from v4.4)
768
+ $rel_posttypes = $odb_class->odb_rvg_options['post_types'];
769
+ $in = '';
770
+ foreach ($rel_posttypes as $posttype => $value) {
771
+ if ($value == 'Y') {
772
+ if ($in != '') $in .= ',';
773
+ $in .= "'" . $posttype . "'";
774
+ } // if ($value == 'Y')
775
+ } // foreach($rel_posttypes as $posttypes)
776
+
777
+ $where = '';
778
+ if($in != '') {
779
+ $where = " AND p2.`post_type` IN ($in)";
780
+ } else {
781
+ // NO POST TYPES TO DELETE REVISIONS FOR... SKIP!
782
+ return $res_arr;
783
+ } // if($in != '')
784
+
785
+ $older_than = $odb_class->odb_rvg_options['older_than'];
786
+
787
+ $index = 0;
788
+
789
+ // LOOP THROUGH THE SITES (IF MULTI SITE)
790
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
791
+ $prefix = $odb_class->odb_ms_prefixes[$i];
792
+
793
+ $sql = sprintf("
794
+ SELECT '%s' AS site,
795
+ p1.`ID`,
796
+ p1.`post_parent`,
797
+ p1.`post_title`,
798
+ p1.`post_modified`
799
+ FROM %sposts p1, %sposts p2
800
+ WHERE p1.`post_type` = 'revision'
801
+ AND p1.`post_parent` = p2.ID
802
+ %s
803
+ AND p1.`post_modified` < date_sub(now(), INTERVAL %d DAY)
804
+ ORDER BY UCASE(p1.`post_title`)
805
+ ",
806
+ $prefix,
807
+ $prefix,
808
+ $prefix,
809
+ $where,
810
+ $older_than);
811
+
812
+ //echo 'OLDER: '.$sql.'<br>';
813
+
814
+ $res = $wpdb->get_results($sql, ARRAY_A);
815
+
816
+ for($j=0; $j<count($res); $j++) {
817
+ if(isset($res[$j]) && !$this->odb_post_is_excluded($res[$j]['post_parent'])) {
818
+ $res_arr[$index] = $res[$j];
819
+ $index++;
820
+ } // if(isset($res[$j]) && !$this->odb_post_is_excluded($res[$j]['post_parent']))
821
+ } // for($j=0; $j<count($res); $j++)
822
+
823
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
824
+
825
+ return $res_arr;
826
+ } // odb_get_revisions_older_than()
827
+
828
+
829
+ /********************************************************************************************
830
+ * GET REVISIONS (KEEP MAX NUMBER OF REVISIONS)
831
+ ********************************************************************************************/
832
+ function odb_get_revisions_keep_revisions() {
833
+ global $odb_class, $wpdb;
834
+
835
+ $res_arr = array();
836
+
837
+ // CUSTOM POST TYPES (from v4.4)
838
+ $rel_posttypes = $odb_class->odb_rvg_options['post_types'];
839
+ $in = '';
840
+ foreach ($rel_posttypes as $posttype => $value) {
841
+ if ($value == 'Y') {
842
+ if ($in != '') $in .= ',';
843
+ $in .= "'" . $posttype . "'";
844
+ } // if ($value == 'Y')
845
+ } // foreach($rel_posttypes as $posttypes)
846
+
847
+ $where1 = '';
848
+ if($in != '') {
849
+ $where1 = " AND p2.`post_type` IN ($in)";
850
+ } else {
851
+ // NO POST TYPES TO DELETE REVISIONS FOR... SKIP!
852
+ return $res_arr;
853
+ } // if($in != '')
854
+
855
+ // MAX NUMBER OF REVISIONS TO KEEP
856
+ $max_revisions = $odb_class->odb_rvg_options['nr_of_revisions'];
857
+
858
+ $index = 0;
859
+
860
+ // SKIP REVISIONS THAT WILL BE DELETED BY THE 'OLDER THAN' OPTION
861
+ $where2 = '';
862
+ if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
863
+ $older_than = $odb_class->odb_rvg_options['older_than'];
864
+ $where2 = 'AND p1.`post_modified` >= date_sub(now(), INTERVAL '.$older_than.' DAY)';
865
+ }
866
+
867
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
868
+ $prefix = $odb_class->odb_ms_prefixes[$i];
869
+
870
+ $sql = sprintf ("
871
+ SELECT '%s' AS site,
872
+ p1.`ID`, p1.`post_parent`, p1.`post_title`, COUNT(*) cnt
873
+ FROM %sposts p1, %sposts p2
874
+ WHERE p1.`post_type` = 'revision'
875
+ AND p1.`post_parent` = p2.ID
876
+ %s
877
+ %s
878
+ GROUP BY p1.`post_parent`
879
+ HAVING COUNT(*) > %d
880
+ ORDER BY UCASE(p1.`post_title`)
881
+ ",
882
+ $prefix,
883
+ $prefix,
884
+ $prefix,
885
+ $where1,
886
+ $where2,
887
+ $max_revisions);
888
+
889
+ //echo 'KEEP: '.$sql.'<br>';
890
+
891
+ $res = $wpdb->get_results($sql, ARRAY_A);
892
+ for($j=0; $j<count($res); $j++) {
893
+ if(isset($res[$j]) && !$this->odb_post_is_excluded($res[$j]['post_parent'])) {
894
+ $res_arr[$index] = $res[$j];
895
+ $index++;
896
+ }
897
+ } // for($j=0; $j<count($res); $j++)
898
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
899
+
900
+ return $res_arr;
901
+ } // odb_get_revisions_keep_revisions()
902
+
903
+
904
+ /********************************************************************************************
905
+ * DELETE THE REVISIONS
906
+ ********************************************************************************************/
907
+ function odb_delete_revisions($scheduler, $analyzing = false) {
908
+ global $odb_class, $wpdb;
909
+
910
+ $total_deleted = 0;
911
+ $nr = 1;
912
+
913
+ if($odb_class->odb_rvg_options['delete_older'] == 'Y') {
914
+ // DELETE REVISIONS OLDER THAN x DAYS
915
+ $results = $this->odb_get_revisions_older_than();
916
+ $older_than = $odb_class->odb_rvg_options['older_than'];
917
+ $total_deleted += count($results);
918
+
919
+ for($i=0; $i<count($results); $i++) {
920
+ if (!$scheduler) {
921
+ ?>
922
+ <tr>
923
+ <td align="right" valign="top"><?php echo $nr?>.</td>
924
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
925
+ <td valign="top" class="odb-bold"><?php echo $results[$i]['post_title']?></td>
926
+ <td valign="top" class="odb-bold"><?php echo $results[$i]['post_modified']?></td><?php
927
+ } // if (!$scheduler)
928
+
929
+ if (!$analyzing) {
930
+ $sql_delete = sprintf ("
931
+ DELETE FROM %sposts
932
+ WHERE `ID` = %d
933
+ ", $results[$i]['site'], $results[$i]['ID']);
934
+
935
+ $wpdb->get_results($sql_delete);
936
+ } // if (!$analyzing)
937
+
938
+ $nr++;
939
+ if(!$scheduler) {
940
+ ?>
941
+ <td align="right" valign="top" class="odb-bold">1</td>
942
+ </tr>
943
+ <?php
944
+ } // if(!$scheduler)
945
+ } // for($i=0; $i<count($results); $i++)
946
+ } // if($odb_class->odb_rvg_options['delete_older'] == 'Y')
947
+
948
+ if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y') {
949
+ // KEEP MAX NUMBER OF REVISIONS
950
+ $results = $this->odb_get_revisions_keep_revisions();
951
+ $max_revisions = $odb_class->odb_rvg_options['nr_of_revisions'];
952
+
953
+ for($i=0; $i<count($results); $i++) {
954
+ $nr_to_delete = $results[$i]['cnt'] - $max_revisions;
955
+ $total_deleted += $nr_to_delete;
956
+
957
+ if (!$scheduler) {
958
+ ?>
959
+ <tr>
960
+ <td align="right" valign="top"><?php echo $nr?>.</td>
961
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
962
+ <td valign="top" class="odb-bold"><?php echo $results[$i]['post_title']?></td>
963
+ <td valign="top"><?php
964
+ } // if (!$scheduler)
965
+
966
+ $sql_get_posts = sprintf( "
967
+ SELECT `ID`, `post_modified`
968
+ FROM %sposts
969
+ WHERE `post_parent` = %d
970
+ AND `post_type` = 'revision'
971
+ ORDER BY `post_modified` ASC
972
+ ", $results[$i]['site'], $results[$i]['post_parent']);
973
+
974
+ $results_get_posts = $wpdb->get_results($sql_get_posts);
975
+
976
+ for($j=0; $j<$nr_to_delete; $j++) {
977
+ if(!$scheduler) echo $results_get_posts[$j]->post_modified.'<br>';
978
+ if (!$analyzing) {
979
+ $sql_delete = sprintf ("
980
+ DELETE FROM %sposts
981
+ WHERE `ID` = %d
982
+ ", $results[$i]['site'], $results_get_posts[$j]->ID);
983
+
984
+ $wpdb->get_results($sql_delete);
985
+ } // if (!$analyzing)
986
+ } // for($j=0; $j<$nr_to_delete; $j++)
987
+
988
+ $nr++;
989
+ if(!$scheduler) {
990
+ ?></td>
991
+ <td align="right" valign="top" class="odb-bold"><?php echo $nr_to_delete?> <?php _e('of', $odb_class->odb_txt_domain)?> <?php echo $results[$i]['cnt'];?></td>
992
+ </tr>
993
+ <?php
994
+ } // if(!$scheduler)
995
+ } // for($i=0; $i<count($results); $i++)
996
+ } // if($odb_class->odb_rvg_options['rvg_revisions'] == 'Y')
997
+
998
+ return $total_deleted;
999
+ } // function odb_delete_revisions()
1000
+
1001
+
1002
+ /********************************************************************************************
1003
+ * CHECK IF POST IS EXCLUDED BY A CUSTOM FIELD ('keep_revisions')
1004
+ ********************************************************************************************/
1005
+ function odb_post_is_excluded($parent_id) {
1006
+ $keep_revisions = get_post_meta($parent_id, 'keep_revisions', true);
1007
+ return ($keep_revisions === 'Y');
1008
+ } // odb_post_is_exclude()
1009
+
1010
+
1011
+ /********************************************************************************************
1012
+ * GET TRASHED POSTS / PAGES AND COMMENTS
1013
+ ********************************************************************************************/
1014
+ function odb_get_trash($analyzing = false) {
1015
+ global $wpdb, $odb_class;
1016
+
1017
+ $res_arr = array();
1018
+
1019
+ $index = 0;
1020
+ // LOOP TROUGH SITES
1021
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1022
+ $prefix = $odb_class->odb_ms_prefixes[$i];
1023
+
1024
+ $sql = sprintf ("
1025
+ SELECT '%s' AS site,
1026
+ `ID` AS id,
1027
+ 'post' AS post_type,
1028
+ `post_title` AS title,
1029
+ `post_modified` AS modified
1030
+ FROM %sposts
1031
+ WHERE `post_status` = 'trash'
1032
+ UNION ALL
1033
+ SELECT '%s' AS site,
1034
+ `comment_ID` AS id,
1035
+ 'comment' AS post_type,
1036
+ `comment_author_IP` AS title,
1037
+ `comment_date` AS modified
1038
+ FROM %scomments
1039
+ WHERE `comment_approved` = 'trash'
1040
+ ORDER BY post_type, UCASE(title)
1041
+ ", $prefix, $prefix, $prefix, $prefix);
1042
+
1043
+ $res = $wpdb->get_results($sql, ARRAY_A);
1044
+
1045
+ if($res != null) {
1046
+ $res_arr[$index] = $res[0];
1047
+ $index++;
1048
+ } // if($res != null)
1049
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1050
+
1051
+ return $res_arr;
1052
+ } // odb_get_trash()
1053
+
1054
+
1055
+ /********************************************************************************************
1056
+ * DELETE TRASHED POSTS AND PAGES
1057
+ ********************************************************************************************/
1058
+ function odb_delete_trash($results, $scheduler, $analyzing) {
1059
+ global $wpdb;
1060
+
1061
+ $nr = 1;
1062
+ $total_deleted = count($results);
1063
+
1064
+ for($i=0; $i<$total_deleted; $i++) {
1065
+ if(!$scheduler) {
1066
+ ?>
1067
+ <tr>
1068
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1069
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1070
+ <td valign="top"><?php echo $results[$i]['post_type']; ?></td>
1071
+ <td valign="top"><?php echo $results[$i]['title']; ?></td>
1072
+ <td valign="top" nowrap="nowrap"><?php echo $results[$i]['modified']; ?></td>
1073
+ </tr>
1074
+ <?php
1075
+ } // if(!$scheduler)
1076
+
1077
+ if($results[$i]['post_type'] == 'comment') {
1078
+ // DELETE META DATA (IF ANY...)
1079
+ if (!$analyzing) {
1080
+ $sql_delete = sprintf ("
1081
+ DELETE FROM %scommentmeta
1082
+ WHERE `comment_id` = %d
1083
+ ", $results[$i]['site'], $results[$i]['id']);
1084
+ $wpdb->get_results($sql_delete);
1085
+ } // if (!$analyzing)
1086
+ } // if($results[$i]['post_type'] == 'comment')
1087
+
1088
+ if (!$analyzing) {
1089
+ // DELETE TRASHED POSTS / PAGES
1090
+ $sql_delete = sprintf ("
1091
+ DELETE FROM %sposts
1092
+ WHERE `post_status` = 'trash'
1093
+ ", $results[$i]['site']);
1094
+ $wpdb->get_results($sql_delete);
1095
+
1096
+ // DELETE TRASHED COMMENTS
1097
+ $sql_delete = sprintf ("
1098
+ DELETE FROM %scomments
1099
+ WHERE `comment_approved` = 'trash'
1100
+ ", $results[$i]['site']);
1101
+ $wpdb->get_results($sql_delete);
1102
+ } // if (!$analyzing)
1103
+
1104
+ $nr++;
1105
+ } // for($i=0; $i<count($results); $i++)
1106
+
1107
+ return $total_deleted;
1108
+ } // odb_delete_trash()
1109
+
1110
+
1111
+ /********************************************************************************************
1112
+ * GET SPAMMED COMMENTS
1113
+ ********************************************************************************************/
1114
+ function odb_get_spam($analyzing = false) {
1115
+ global $wpdb, $odb_class;
1116
+
1117
+ $res_arr = array();
1118
+
1119
+ // LOOP THROUGH SITES
1120
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1121
+ $prefix = $odb_class->odb_ms_prefixes[$i];
1122
+
1123
+ $sql = sprintf ("
1124
+ SELECT '%s' AS site,
1125
+ `comment_ID`,
1126
+ `comment_author`,
1127
+ `comment_author_email`,
1128
+ `comment_date`
1129
+ FROM %scomments
1130
+ WHERE `comment_approved` = 'spam'
1131
+ ORDER BY UCASE(`comment_author`)
1132
+ ", $prefix, $prefix);
1133
+
1134
+ $res = $wpdb->get_results($sql, ARRAY_A);
1135
+
1136
+ for($j = 0; $j < count($res); $j++) {
1137
+ array_push($res_arr, $res[$j]);
1138
+ } // for($j = 0; $j < count($res); $j++)
1139
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1140
+ return $res_arr;
1141
+ } // odb_get_spam()
1142
+
1143
+
1144
+ /********************************************************************************************
1145
+ * DELETE SPAMMED ITEMS
1146
+ ********************************************************************************************/
1147
+ function odb_delete_spam($results, $scheduler, $analyzing = false) {
1148
+ global $wpdb;
1149
+
1150
+ $nr = 1;
1151
+ $total_deleted = count($results);
1152
+ for($i=0; $i<count($results); $i++) {
1153
+ if (!$scheduler) {
1154
+ ?>
1155
+ <tr>
1156
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1157
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1158
+ <td valign="top"><?php echo $results[$i]['comment_author']; ?></td>
1159
+ <td valign="top"><?php echo $results[$i]['comment_author_email']; ?></td>
1160
+ <td valign="top" nowrap="nowrap"><?php echo $results[$i]['comment_date']; ?></td>
1161
+ </tr>
1162
+ <?php
1163
+ } // if (!$scheduler)
1164
+
1165
+ if (!$analyzing) {
1166
+ $sql_delete = sprintf ("
1167
+ DELETE FROM %scommentmeta
1168
+ WHERE `comment_id` = %d
1169
+ ", $results[$i]['site'], $results[$i]['comment_ID']);
1170
+ $wpdb->get_results($sql_delete);
1171
+
1172
+ $sql_delete = sprintf ("
1173
+ DELETE FROM %scomments
1174
+ WHERE `comment_approved` = 'spam'
1175
+ ", $results[$i]['site']);
1176
+ $wpdb->get_results($sql_delete);
1177
+ } // if (!$analyzing)
1178
+
1179
+ $nr++;
1180
+ } // for($i=0; $i<count($results); $i++)
1181
+
1182
+ return $total_deleted;
1183
+ } // odb_delete_spam()
1184
+
1185
+
1186
+ /********************************************************************************************
1187
+ * GET UNUSED TAGS
1188
+ ********************************************************************************************/
1189
+ function odb_get_unused_tags($analyzing = false) {
1190
+ global $wpdb, $odb_class;
1191
+
1192
+ $res_arr = array();
1193
+
1194
+ // LOOP THROUGH SITES
1195
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1196
+ $prefix = $odb_class->odb_ms_prefixes[$i];
1197
+
1198
+ $sql = sprintf ("
1199
+ SELECT '%s' AS site,
1200
+ a.term_id AS term_id, a.name AS name
1201
+ FROM `%sterms` a, `%sterm_taxonomy` b
1202
+ WHERE a.term_id = b.term_id
1203
+ AND b.taxonomy = 'post_tag'
1204
+ AND b.term_taxonomy_id NOT IN (
1205
+ SELECT term_taxonomy_id
1206
+ FROM %sterm_relationships
1207
+ )
1208
+ ORDER BY name
1209
+ ", $prefix, $prefix, $prefix, $prefix);
1210
+
1211
+ $res = $wpdb->get_results($sql, ARRAY_A);
1212
+
1213
+ for($j = 0; $j < count($res); $j++) {
1214
+ array_push($res_arr, $res[$j]);
1215
+ } // for($j = 0; $j < count($res); $j++)
1216
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1217
+ return $res_arr;
1218
+ } // odb_get_unused_tags
1219
+
1220
+
1221
+ /********************************************************************************************
1222
+ * DELETE UNUSED TAGS
1223
+ ********************************************************************************************/
1224
+ function odb_delete_unused_tags($results, $scheduler, $analyzing = false) {
1225
+ global $wpdb, $odb_class;
1226
+
1227
+ $nr = 1;
1228
+ $total_deleted = count($results);
1229
+ for($i=0; $i<count($results); $i++) {
1230
+ if (!$scheduler) {
1231
+ ?>
1232
+ <tr>
1233
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1234
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1235
+ <td valign="top"><?php echo $results[$i]['name']; ?></td>
1236
+ </tr>
1237
+ <?php
1238
+ } // if (!$scheduler)
1239
+
1240
+ if (!$analyzing) {
1241
+ $sql_del = sprintf ("
1242
+ DELETE FROM %sterm_taxonomy
1243
+ WHERE term_id = %d
1244
+ ", $results[$i]['site'], $results[$i]['term_id']);
1245
+ $wpdb->get_results($sql_del);
1246
+
1247
+ $sql_del = sprintf ("
1248
+ DELETE FROM %sterms
1249
+ WHERE term_id = %d
1250
+ ", $results[$i]['site'], $results[$i]['term_id']);
1251
+ $wpdb->get_results($sql_del);
1252
+ } // if (!$analyzing)
1253
+
1254
+ $nr++;
1255
+ } // for($i=0; $i<count($results); $i++)
1256
+
1257
+ return $total_deleted;
1258
+ } // odb_delete_unused_tags()
1259
+
1260
+
1261
+ /********************************************************************************************
1262
+ * IS THE UNUSED TAG USED IN ONE OR MORE SCHEDULED POSTS?
1263
+ ********************************************************************************************/
1264
+ function odb_delete_tags_is_scheduled($term_id, $odb_prefix) {
1265
+ global $wpdb;
1266
+
1267
+ $sql_get_posts = sprintf ("
1268
+ SELECT p.post_status
1269
+ FROM %sterm_relationships t, %sposts p
1270
+ WHERE t.term_taxonomy_id = '%s'
1271
+ AND t.object_id = p.ID
1272
+ ", $odb_prefix, $odb_prefix, $term_id);
1273
+
1274
+ $results_get_posts = $wpdb->get_results($sql_get_posts);
1275
+ for($i=0; $i<count($results_get_posts); $i++)
1276
+ if($results_get_posts[$i]->post_status == 'future') return true;
1277
+
1278
+ return false;
1279
+ } // odb_delete_tags_is_scheduled()
1280
+
1281
+
1282
+ /********************************************************************************************
1283
+ * DELETE TRANSIENTS (v4.3.1)
1284
+ ********************************************************************************************/
1285
+ function odb_get_transients($analyzing = false) {
1286
+ global $wpdb, $odb_class;
1287
+
1288
+ $res_arr = array();
1289
+
1290
+ // LOOP THROUGH SITES
1291
+ $delay = time() - 60; // ONE MINUTE DELAY
1292
+
1293
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1294
+ $prefix = $odb_class->odb_ms_prefixes[$i];
1295
+
1296
+ if ($odb_class->odb_rvg_options['clear_transients'] == 'Y' || $odb_class->odb_rvg_options['clear_transients'] == 'A') {
1297
+ // DELETE TRANSIENTS
1298
+ if ($odb_class->odb_rvg_options['clear_transients'] == 'Y') {
1299
+ // EXPIRED TRANSIENTS ONLY
1300
+ $sql = "
1301
+ SELECT '" . $prefix . "' AS site,
1302
+ `option_name`
1303
+ FROM " . $prefix . "options
1304
+ WHERE (
1305
+ option_name LIKE '_transient_timeout_%'
1306
+ OR option_name LIKE '_site_transient_timeout_%'
1307
+ )
1308
+ AND option_value < '" . $delay . "'" . "
1309
+ ORDER BY `option_name`
1310
+ ";
1311
+ } else {
1312
+ // ALL TRANSIENTS
1313
+ $sql = "
1314
+ SELECT '" . $prefix . "' AS site,
1315
+ `option_name`
1316
+ FROM " . $prefix . "options
1317
+ WHERE (
1318
+ option_name LIKE '_transient_timeout_%'
1319
+ OR option_name LIKE '_site_transient_timeout_%'
1320
+ )
1321
+ ORDER BY `option_name`
1322
+ ";
1323
+ } // if ($odb_class->odb_rvg_options['clear_transients'] == 'Y')
1324
+ $res = $wpdb->get_results($sql, ARRAY_A);
1325
+
1326
+ for($j = 0; $j < count($res); $j++) {
1327
+ array_push($res_arr, $res[$j]);
1328
+ } // for($j = 0; $j < count($res); $j++)
1329
+ } // if ($odb_class->odb_rvg_options['clear_transients'] == 'Y' || $odb_class->odb_rvg_options['clear_transients'] == 'A')
1330
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1331
+ return $res_arr;
1332
+ } // odb_get_transients()
1333
+
1334
+
1335
+ /********************************************************************************************
1336
+ * DELETE TRANSIENTS (v4.3.1)
1337
+ ********************************************************************************************/
1338
+ function odb_delete_transients($results, $scheduler, $analyzing = false) {
1339
+ global $wpdb;
1340
+
1341
+ $total_deleted = 0;
1342
+
1343
+ $nr = 1;
1344
+ $total_deleted = count($results);
1345
+ for($i=0; $i<count($results); $i++) {
1346
+ if (!$scheduler) {
1347
+ ?>
1348
+ <tr>
1349
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1350
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1351
+ <td valign="top"><?php echo $results[$i]['option_name']; ?></td>
1352
+ </tr>
1353
+ <?php
1354
+ } // if (!$scheduler)
1355
+
1356
+ // LOOP THROUGH THE RESULTS
1357
+ if (!$analyzing) {
1358
+ for($j=0; $j<count($results); $j++) {
1359
+ if(substr($results[$j]['option_name'], 0, 19) == '_transient_timeout_') {
1360
+ // _transient_timeout_%
1361
+ $transient = substr($results[$j]['option_name'], 19);
1362
+ // DELETE THE TRANSIENT
1363
+ delete_transient($transient);
1364
+ } else {
1365
+ // _site_transient_timeout_%
1366
+ $transient = substr($results[$j]['option_name'], 24);
1367
+ // DELETE THE TRANSIENT
1368
+ delete_site_transient($transient);
1369
+ } // if(substr($results[$j]->option_name, 0, 19) == '_transient_timeout_')
1370
+ } // for($j=0; $j<count($results); $j++)
1371
+ } // if (!$analyzing)
1372
+
1373
+ $nr++;
1374
+ } // for($i=0; $i<count($results); $i++)
1375
+
1376
+ return $total_deleted;
1377
+ } // odb_delete_transients()
1378
+
1379
+
1380
+ /********************************************************************************************
1381
+ * GET PINGBACKS AND TRACKBACKS
1382
+ ********************************************************************************************/
1383
+ function odb_get_pingbacks($analyzing = false) {
1384
+
1385
+ global $wpdb, $odb_class;
1386
+
1387
+ $res_arr = array();
1388
+
1389
+ // LOOP THROUGH SITES
1390
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1391
+ $prefix = $odb_class->odb_ms_prefixes[$i];;
1392
+
1393
+ $sql = sprintf ("
1394
+ SELECT '%s' AS site,
1395
+ `comment_ID`,
1396
+ `comment_type`,
1397
+ `comment_author`,
1398
+ `comment_date`
1399
+ FROM %scomments
1400
+ WHERE (
1401
+ `comment_type` = 'pingback' OR `comment_type` = 'trackback'
1402
+ )
1403
+ ORDER BY `comment_type`, `comment_author`
1404
+ ", $prefix, $prefix);
1405
+
1406
+ $res = $wpdb->get_results($sql, ARRAY_A);
1407
+
1408
+ for($j = 0; $j < count($res); $j++) {
1409
+ array_push($res_arr, $res[$j]);
1410
+ } // for($j = 0; $j < count($res); $j++)
1411
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1412
+ return $res_arr;
1413
+ } // odb_get_pingbacks
1414
+
1415
+
1416
+ /********************************************************************************************
1417
+ * DELETE PINGBACKS AND TRACKBACKS
1418
+ ********************************************************************************************/
1419
+ function odb_delete_pingbacks($results, $scheduler, $analyzing) {
1420
+ global $wpdb, $odb_class;
1421
+
1422
+ $nr = 1;
1423
+ $total_deleted = count($results);
1424
+ for($i=0; $i<count($results); $i++) {
1425
+ if (!$scheduler) {
1426
+ ?>
1427
+ <tr>
1428
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1429
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1430
+ <td valign="top"><?php echo $results[$i]['comment_type']?></td>
1431
+ <td valign="top"><?php echo $results[$i]['comment_author']?></td>
1432
+ <td valign="top" nowrap="nowrap"><?php echo $results[$i]['comment_date']; ?></td>
1433
+ </tr>
1434
+ <?php
1435
+ } // if (!$scheduler)
1436
+
1437
+ if (!$analyzing) {
1438
+ for($j=0; $j<count($results); $j++) {
1439
+ // DELETE METADATA FOR THIS COMMENT (IF ANY)
1440
+ $sql = sprintf ("
1441
+ DELETE FROM %scommentmeta
1442
+ WHERE `comment_id` = %d
1443
+ ", $results[$j]['site'], $results[$j]['comment_ID']);
1444
+ $wpdb->get_results($sql);
1445
+
1446
+ $sql = sprintf ("
1447
+ DELETE FROM %scomments
1448
+ WHERE (
1449
+ `comment_type` = 'pingback'
1450
+ OR `comment_type` = 'trackback'
1451
+ )
1452
+ ", $results[$j]['site']);
1453
+ $wpdb->get_results($sql);
1454
+ } // for($j=0; $j<count($results); $j++)
1455
+ } // if (!$analyzing)
1456
+
1457
+ $nr++;
1458
+ } // for($i=0; $i<count($results); $i++)
1459
+
1460
+ return $total_deleted;
1461
+ } // odb_delete_pingbacks()
1462
+
1463
+
1464
+ /********************************************************************************************
1465
+ * GET OEMBED CACHE
1466
+ ********************************************************************************************/
1467
+ function odb_get_oembed($analyzing = false) {
1468
+ global $wpdb, $odb_class;
1469
+
1470
+ $res_arr = array();
1471
+
1472
+ // LOOP THROUGH SITES
1473
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1474
+ $prefix = $odb_class->odb_ms_prefixes[$i];
1475
+
1476
+ $sql = sprintf ("
1477
+ SELECT '%s' AS site,
1478
+ `meta_id`,
1479
+ `meta_key`,
1480
+ `meta_value`
1481
+ FROM %spostmeta
1482
+ WHERE `meta_key` LIKE '_oembed_%%'
1483
+ ORDER BY `meta_key`
1484
+ ", $prefix, $prefix);
1485
+
1486
+ $res = $wpdb->get_results($sql, ARRAY_A);
1487
+
1488
+ for($j = 0; $j < count($res); $j++) {
1489
+ array_push($res_arr, $res[$j]);
1490
+ } // for($j = 0; $j < count($res); $j++)
1491
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1492
+ return $res_arr;
1493
+ } // odb_get_oembed()
1494
+
1495
+
1496
+ /********************************************************************************************
1497
+ * CLEAR OEMBED CACHE
1498
+ ********************************************************************************************/
1499
+ function odb_delete_oembed($results, $scheduler, $analyzing) {
1500
+ global $wpdb, $odb_class;
1501
+
1502
+ $nr = 1;
1503
+ $total_deleted = count($results);
1504
+ for($i=0; $i<count($results); $i++) {
1505
+ if (!$scheduler) {
1506
+ ?>
1507
+ <tr>
1508
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1509
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1510
+ <td valign="top"><?php echo $results[$i]['meta_key']?></td>
1511
+ <td valign="top"><?php echo $results[$i]['meta_value']?></td>
1512
+ </tr>
1513
+ <?php
1514
+ } // if (!$scheduler)
1515
+
1516
+ if (!$analyzing) {
1517
+ // DELETE COMMENTS
1518
+ $sql = sprintf ("
1519
+ DELETE FROM %spostmeta
1520
+ WHERE `meta_key` LIKE '_oembed_%%'
1521
+ ", $results[$i]['site']);
1522
+
1523
+ $wpdb->get_results($sql);
1524
+ } // if (!$analyzing)
1525
+
1526
+ $nr++;
1527
+ } // for($i=0; $i<count($results); $i++)
1528
+
1529
+ return $total_deleted;
1530
+ } // odb_delete_oembed()
1531
+
1532
+
1533
+ /********************************************************************************************
1534
+ * GET ORPHAN POSTMETA AND MEDIA RECORDS
1535
+ ********************************************************************************************/
1536
+ function odb_get_orphans($results, $scheduler, $analyzing) {
1537
+ global $wpdb, $odb_class;
1538
+
1539
+ $res_arr = array();
1540
+
1541
+ // LOOP THROUGH SITES
1542
+ for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++) {
1543
+ $prefix = $odb_class->odb_ms_prefixes[$i];
1544
+
1545
+ $sql = sprintf ("
1546
+ SELECT '%s' AS site,
1547
+ `ID`,
1548
+ 'post' AS type,
1549
+ `post_title`,
1550
+ `post_modified`,
1551
+ '' AS meta_key,
1552
+ '' AS meta_value
1553
+ FROM %sposts
1554
+ WHERE ID NOT IN (SELECT post_id FROM %spostmeta)
1555
+ AND post_status = 'auto-draft'
1556
+ ORDER BY `ID`
1557
+ ", $prefix, $prefix, $prefix);
1558
+
1559
+ $results = $wpdb->get_results($sql, ARRAY_A);
1560
+ for ($j = 0; $j < count($results); $j++) {
1561
+ array_push($res_arr, $results[$j]);
1562
+ } // for ($j = 0; $j < count($results); $j++)
1563
+
1564
+ // DELETE POSTMETA ORPHANS
1565
+ $sql = sprintf ("
1566
+ SELECT '%s' AS site,
1567
+ `post_id` AS ID,
1568
+ 'meta' AS type,
1569
+ '' AS post_title,
1570
+ '' AS post_modified,`meta_key`, `meta_value`
1571
+ FROM %spostmeta
1572
+ WHERE post_id NOT IN (SELECT ID FROM %sposts)
1573
+ ORDER BY `meta_key`
1574
+ ", $prefix, $prefix, $prefix);
1575
+
1576
+ $results = $wpdb->get_results($sql, ARRAY_A);
1577
+ for ($j = 0; $j < count($results); $j++) {
1578
+ array_push($res_arr, $results[$j]);
1579
+ } // for ($j = 0; $j < count($results); $j++)
1580
+ } // for($i=0; $i<count($odb_class->odb_ms_prefixes); $i++)
1581
+ return $res_arr;
1582
+ } // odb_get_orphans()
1583
+
1584
+
1585
+ /********************************************************************************************
1586
+ * DELETE ORPHAN POSTMETA AND MEDIA RECORDS
1587
+ ********************************************************************************************/
1588
+ function odb_delete_orphans($results, $scheduler, $analyzing) {
1589
+
1590
+ global $wpdb, $odb_class;
1591
+
1592
+ $nr = 1;
1593
+ $total_deleted = count($results);
1594
+ for($i=0; $i<count($results); $i++) {
1595
+ if (!$scheduler) {
1596
+ ?>
1597
+ <tr>
1598
+ <td align="right" valign="top"><?php echo $nr; ?></td>
1599
+ <td align="left" valign="top"><?php echo $results[$i]['site']?></td>
1600
+ <td valign="top"><?php echo $results[$i]['type']?></td>
1601
+ <td valign="top"><?php echo $results[$i]['ID']?></td>
1602
+ <td valign="top"><?php echo $results[$i]['post_title']?></td>
1603
+ <td valign="top" nowrap="nowrap"><?php echo substr($results[$i]['post_modified'], 0, 10); ?></td>
1604
+ <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_key']; ?></td>
1605
+ <td valign="top" nowrap="nowrap"><?php echo $results[$i]['meta_value']; ?></td>
1606
+ </tr>
1607
+ <?php
1608
+ } // if (!$scheduler)
1609
+
1610
+ if (!$analyzing) {
1611
+ for($j=0; $j<count($results); $j++) {
1612
+ // DELETE METADATA FOR THIS COMMENT (IF ANY)
1613
+ if ($results[$j]['type'] == 'meta') {
1614
+ $sql = sprintf ("
1615
+ DELETE FROM %spostmeta
1616
+ WHERE `post_id` = %d
1617
+ ", $results[$j]['site'], $results[$j]['ID']);
1618
+ } else if ($results[$j]['type'] == 'post') {
1619
+ $sql = sprintf ("
1620
+ DELETE FROM %sposts
1621
+ WHERE `ID` = %d
1622
+ ", $results[$j]['site'], $results[$j]['ID']);
1623
+ } // if ($results[$j]['type'] == 'meta')
1624
+ //echo 'SQL: ' . $sql.'<br>';
1625
+ $wpdb->get_results($sql);
1626
+ }// for($j=0; $j<count($results); $j++)
1627
+ } // if (!$analyzing)
1628
+ $nr++;
1629
+ } // for($i=0; $i<count($results); $i++)
1630
+
1631
+ return $total_deleted;
1632
+ } // odb_delete_orphans()
1633
+
1634
+
1635
+ /********************************************************************************************
1636
+ * OPTIMIZE DATABASE TABLES
1637
+ ********************************************************************************************/
1638
+ function odb_optimize_tables($scheduler) {
1639
+ global $odb_class, $wpdb;
1640
+
1641
+ $cnt = 0;
1642
+ for ($i=0; $i<count($odb_class->odb_tables); $i++) {
1643
+ if(!isset($odb_class->odb_rvg_excluded_tabs[$odb_class->odb_tables[$i][0]])) {
1644
+ # TABLE NOT EXCLUDED
1645
+ $cnt++;
1646
+
1647
+ $sql = sprintf ("
1648
+ SELECT engine, (data_length + index_length) AS size, table_rows
1649
+ FROM information_schema.TABLES
1650
+ WHERE table_schema = '%s'
1651
+ AND table_name = '%s'
1652
+ ", DB_NAME, $odb_class->odb_tables[$i][0]);
1653
+ $table_info = $wpdb->get_results($sql);
1654
+
1655
+ if($odb_class->odb_rvg_options["optimize_innodb"] == 'N' && strtolower($table_info[0]->engine) == 'innodb') {
1656
+ // SKIP InnoDB tables
1657
+ $msg = __('InnoDB table: skipped...', 'rvg-optimize-database');
1658
+ } else {
1659
+ // v4.6.3
1660
+ if (strtolower($table_info[0]->engine) == 'myisam') {
1661
+ $result = $this->odb_optimize_myisam($odb_class->odb_tables[$i][0]);
1662
+ $msg = $result[0]->Msg_text;
1663
+ if ($msg == 'OK') {
1664
+ $msg = __('<span class="odb-optimized">TABLE OPTIMIZED</span>', 'rvg-optimize-database');
1665
+ } else if ($msg == 'Table is already up to date') {
1666
+ $msg = __('Table is already up to date', 'rvg-optimize-database');
1667
+ }
1668
+ } else {
1669
+ $result = $this->odb_optimize_innodb($odb_class->odb_tables[$i][0]);
1670
+ $msg = $result[0]->Msg_text;
1671
+ if ($msg == 'Table is already up to date') {
1672
+ $msg = __('Table is already up to date', 'rvg-optimize-database');
1673
+ } else {
1674
+ $msg = __('<span class="odb-optimized">TABLE OPTIMIZED</span>', 'rvg-optimize-database');
1675
+ }
1676
+ } // if (strtolower($table_info[0]->engine) == 'myisam')
1677
+ } // if($odb_class->odb_rvg_options["optimize_innodb"] == 'N' && strtolower($table_info[0]->engine) == 'innodb')
1678
+
1679
+ if (!$scheduler)
1680
+ { // NOT FROM THE SCEDULER
1681
+ ?>
1682
+ <tr>
1683
+ <td align="right" valign="top"><?php echo $cnt?>.</td>
1684
+ <td valign="top" class="odb-bold"><?php echo $odb_class->odb_tables[$i][0] ?></td>
1685
+ <td valign="top"><?php echo $msg ?></td>
1686
+ <td valign="top"><?php echo $table_info[0]->engine ?></td>
1687
+ <td align="right" valign="top"><?php echo $table_info[0]->table_rows ?></td>
1688
+ <td align="right" valign="top"><?php echo $odb_class->odb_utilities_obj->odb_format_size($table_info[0]->size) ?></td>
1689
+ </tr>
1690
+ <?php
1691
+ } // if (!$scheduler)
1692
+ } // if(!$excluded)
1693
+ } // for ($i=0; $i<count($tables); $i++)
1694
+ return $cnt;
1695
+
1696
+ } // odb_optimize_tables()
1697
+
1698
+
1699
+ /********************************************************************************************
1700
+ * OPTIMIZE A MyISAM TABLE
1701
+ ********************************************************************************************/
1702
+ function odb_optimize_myisam($table_name) {
1703
+ global $wpdb;
1704
+ $query = "OPTIMIZE TABLE " . $table_name;
1705
+ return $wpdb->get_results($query);
1706
+ } // odb_optimize_myisam()
1707
+
1708
+
1709
+ /********************************************************************************************
1710
+ * OPTIMIZE AN InnoDB TABLE
1711
+ ********************************************************************************************/
1712
+ function odb_optimize_innodb($table_name) {
1713
+ global $wpdb;
1714
+
1715
+ $query = "OPTIMIZE TABLE " . $table_name;
1716
+ return $wpdb->get_results($query);
1717
+
1718
+ /* // https://www.percona.com/blog/2010/12/09/mysql-optimize-tables-innodb-stop/
1719
+ $query = "SHOW KEYS FROM " . $table_name . " WHERE Key_name <> 'PRIMARY'";
1720
+ $result = $wpdb->get_results($query);
1721
+ if (count($result) > 0) {
1722
+ for ($i = 0; $i < count($result); $i++) {
1723
+ $key_name = $result[$i]->Key_name;
1724
+
1725
+ $query = "ALTER TABLE " . $table_name . " DROP KEY " . $key_name;
1726
+ $result = $wpdb->get_results($query);
1727
+
1728
+ $query = "ALTER TABLE " . $table_name . " add key(" . $key_name . ")";
1729
+ $result = $wpdb->get_results($query);
1730
+ } // for ($i = 0; $i < count($result); $i++)
1731
+ return __('<span class="odb-optimized">TABLE OPTIMIZED</span>', 'rvg-optimize-database');
1732
+ } else {
1733
+ return __('Table is already up to date', 'rvg-optimize-database');
1734
+ } // if (count($result) > 0*/
1735
+ } // odb_optimize_innodb()
1736
+
1737
+ } // ODB_Cleaner
1738
  ?>
readme.txt CHANGED
@@ -10,8 +10,8 @@ Contributors: cageehv
10
  Requires at least: 2.8
11
  Requires PHP: 5.0
12
  Tested up to: 5.0
13
- Stable tag: 4.7.1
14
- Version: 4.7.1
15
  License: GPLv2 or later
16
 
17
  == Description ==
@@ -111,6 +111,9 @@ http://cagewebdev.com/wordpress-plugins/
111
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
112
 
113
  == Changelog ==
 
 
 
114
  = 4.7.1 [11/11/2018] =
115
  * BUG FIX: Fixed an 'undefined variable' notice
116
 
10
  Requires at least: 2.8
11
  Requires PHP: 5.0
12
  Tested up to: 5.0
13
+ Stable tag: 4.7.2
14
+ Version: 4.7.2
15
  License: GPLv2 or later
16
 
17
  == Description ==
111
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
112
 
113
  == Changelog ==
114
+ = 4.7.2 [11/12/2018] =
115
+ * BUG FIX: Fixed a MySQL query
116
+
117
  = 4.7.1 [11/11/2018] =
118
  * BUG FIX: Fixed an 'undefined variable' notice
119
 
rvg-optimize-database.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
- * @version 4.7.1
5
  */
6
  /*
7
  Plugin Name: Optimize Database after Deleting Revisions
@@ -10,7 +10,7 @@ Description: Optimizes the Wordpress Database after Cleaning it out
10
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
11
  Author URI: http://cagewebdev.com
12
  Network: True
13
- Version: 4.7.1
14
  */
15
 
16
  /********************************************************************************************
@@ -24,8 +24,8 @@ $odb_class = new OptimizeDatabase();
24
 
25
  class OptimizeDatabase {
26
  // VERSION
27
- var $odb_version = '4.7.1';
28
- var $odb_release_date = '11/11/2018';
29
 
30
  // PLUGIN OPTIONS
31
  var $odb_rvg_options = array();
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
+ * @version 4.7.2
5
  */
6
  /*
7
  Plugin Name: Optimize Database after Deleting Revisions
10
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
11
  Author URI: http://cagewebdev.com
12
  Network: True
13
+ Version: 4.7.2
14
  */
15
 
16
  /********************************************************************************************
24
 
25
  class OptimizeDatabase {
26
  // VERSION
27
+ var $odb_version = '4.7.2';
28
+ var $odb_release_date = '11/12/2018';
29
 
30
  // PLUGIN OPTIONS
31
  var $odb_rvg_options = array();