| @@ -1,115 +1,193 @@ | ||
| 1 | 1 | <?php |
| 2 | -class ODB_Logger | |
| 3 | -{ | |
| 2 | +/************************************************************************************************ | |
| 3 | + * | |
| 4 | + * LOGGER CLASS | |
| 5 | + * | |
| 6 | + ************************************************************************************************/ | |
| 7 | +?> | |
| 8 | +<?php | |
| 9 | +class ODB_Logger { | |
| 10 | + | |
| 11 | + var $sql = ''; | |
| 12 | + var $res = array(); | |
| 13 | + | |
| 4 | 14 | /******************************************************************************************** |
| 5 | 15 | * CONSTRUCTOR |
| 6 | - ********************************************************************************************/ | |
| 7 | - function __construct() | |
| 8 | - { | |
| 16 | + ********************************************************************************************/ | |
| 17 | + function __construct() { | |
| 9 | 18 | } // __construct() |
| 10 | - | |
| 11 | 19 | |
| 20 | + | |
| 12 | 21 | /******************************************************************************************** |
| 13 | - * WRITE RESULTS TO LOG FILE | |
| 14 | - ********************************************************************************************/ | |
| 15 | - function write_log() | |
| 16 | - { | |
| 17 | - global $odb_class; | |
| 22 | + * WRITE RESULTS TO LOG TABLE - v4.6 | |
| 23 | + ********************************************************************************************/ | |
| 24 | + function odb_add_log() { | |
| 25 | + global $odb_class, $wpdb; | |
| 18 | 26 | |
| 19 | - if($odb_class->odb_rvg_options['logging_on'] == "Y") | |
| 20 | - { $file = $odb_class->odb_logfile_path; | |
| 21 | - if(!file_exists($file)) | |
| 22 | - { // NEW LOG FILE | |
| 23 | - $html = ' | |
| 24 | -<!doctype html> | |
| 25 | -<html> | |
| 26 | -<head> | |
| 27 | -<meta charset="utf-8"> | |
| 28 | -<title>Optimize Database after Deleting Revisions v'.$odb_class->odb_version.' - LOG</title> | |
| 29 | -<style type="text/css"> | |
| 30 | -body, td, th { | |
| 31 | - font-family: Arial, Helvetica, sans-serif; | |
| 32 | - font-size: 12px; | |
| 33 | -} | |
| 34 | -th { | |
| 35 | - border-top:solid 1px #000; | |
| 36 | - border-bottom:solid 1px #000; | |
| 37 | -} | |
| 38 | -td { | |
| 39 | - padding-bottom:4px; | |
| 40 | - border-bottom:dotted 1px #CCC; | |
| 41 | -} | |
| 42 | -#header { | |
| 43 | - margin-left:6px; | |
| 44 | - margin-bottom:8px; | |
| 45 | -} | |
| 46 | -#header a { | |
| 47 | - text-decoration:none; | |
| 48 | - font-weight:bold; | |
| 49 | -} | |
| 50 | -</style> | |
| 51 | -</head> | |
| 52 | -<body> | |
| 53 | -<div id="header"> | |
| 54 | -<h2><a href="https://wordpress.org/plugins/rvg-optimize-database/" target="_blank">Optimize Database after Deleting Revisions v'.$odb_class->odb_version.'</a></h2> | |
| 55 | - '.__('A WordPress Plugin by','rvg-optimize-database').' <a href="http://cagewebdev.com" target="_blank"><span class="odb-bold">CAGE Web Design</span></a> | <a href="http://rvg.cage.nl" target="_blank"><span class="odb-bold">Rolf van Gelder</span></a>, Eindhoven, '.__('The Netherlands','rvg-optimize-database').'</span> | |
| 27 | + // IS LOGGING ENABLED? | |
| 28 | + if($odb_class->odb_rvg_options['logging_on'] == "Y") { | |
| 29 | + | |
| 30 | + // CONVERT A TIMESTAMP TO THE mm/dd/yyyy hh:mm:ss format | |
| 31 | + $d = $odb_class->odb_utilities_obj->odb_parse_timestamp($odb_class->log_arr['timestamp']); | |
| 32 | + | |
| 33 | + $this->sql = " | |
| 34 | + INSERT INTO `" . $odb_class->odb_logtable_name . "` | |
| 35 | + ( | |
| 36 | + odb_timestamp, | |
| 37 | + odb_revisions, | |
| 38 | + odb_trash, | |
| 39 | + odb_spam, | |
| 40 | + odb_tags, | |
| 41 | + odb_transients, | |
| 42 | + odb_pingbacks, | |
| 43 | + odb_oembeds, | |
| 44 | + odb_orphans, | |
| 45 | + odb_tables, | |
| 46 | + odb_before, | |
| 47 | + odb_after, | |
| 48 | + odb_savings | |
| 49 | + ) | |
| 50 | + VALUES | |
| 51 | + ( | |
| 52 | + '" . $d . "', | |
| 53 | + ". $odb_class->log_arr['revisions'] . ", | |
| 54 | + ". $odb_class->log_arr['trash'] . ", | |
| 55 | + ". $odb_class->log_arr['spam'] . ", | |
| 56 | + ". $odb_class->log_arr['tags'] . ", | |
| 57 | + ". $odb_class->log_arr['transients'] . ", | |
| 58 | + ". $odb_class->log_arr['pingbacks'] . ", | |
| 59 | + ". $odb_class->log_arr['oembeds'] . ", | |
| 60 | + ". $odb_class->log_arr['orphans'] . ", | |
| 61 | + ". $odb_class->log_arr['tables'] . ", | |
| 62 | + '". $odb_class->log_arr['before'] . "', | |
| 63 | + '". $odb_class->log_arr['after'] . "', | |
| 64 | + '". $odb_class->log_arr['savings'] . "' | |
| 65 | + ) | |
| 66 | + "; | |
| 67 | + $wpdb->get_results($this->sql); | |
| 68 | + } // if($odb_class->odb_rvg_options['logging_on'] == "Y") | |
| 69 | + } // odb_add_log() | |
| 70 | + | |
| 71 | + | |
| 72 | + /******************************************************************************************** | |
| 73 | + * TRUNCATE THE LOG TABLE - v4.6 | |
| 74 | + ********************************************************************************************/ | |
| 75 | + function odb_clear_log() { | |
| 76 | + global $odb_class, $wpdb; | |
| 77 | + | |
| 78 | + $this->sql = " | |
| 79 | + TRUNCATE TABLE `" . $odb_class->odb_logtable_name . "` | |
| 80 | + "; | |
| 81 | + | |
| 82 | + $wpdb->get_results($this->sql); | |
| 83 | + } // clear_log() | |
| 84 | + | |
| 85 | + | |
| 86 | + /******************************************************************************************** | |
| 87 | + * VIEW THE LOGS - v4.6.1 | |
| 88 | + ********************************************************************************************/ | |
| 89 | + function odb_view_log() { | |
| 90 | + global $odb_class, $wpdb; | |
| 91 | + | |
| 92 | + $this->sql = " | |
| 93 | + SELECT * FROM `" . $odb_class->odb_logtable_name . "` ORDER BY odb_id ASC | |
| 94 | + "; | |
| 95 | + $this->res = $wpdb->get_results($this->sql, ARRAY_A); | |
| 96 | + | |
| 97 | + $odb_class->odb_displayer_obj->display_header(); | |
| 98 | +?> | |
| 99 | +<div class="odb-title-bar"> | |
| 100 | + <h2><?php _e('Logs','rvg-optimize-database')?></h2> | |
| 56 | 101 | </div> |
| 57 | -<table width="100%" border="0" cellspacing="6" cellpadding="1"> | |
| 58 | - <tr> | |
| 59 | - <th width="8%" align="left" valign="top">'.__('time','rvg-optimize-database').'</th> | |
| 60 | - <th width="8%" align="right" valign="top">'.__('deleted<br />revisions','rvg-optimize-database').'</th> | |
| 61 | - <th width="8%" align="right" valign="top">'.__('deleted<br />trash','rvg-optimize-database').'</th> | |
| 62 | - <th width="8%" align="right" valign="top">'.__('deleted<br />spam','rvg-optimize-database').'</th> | |
| 63 | - <th width="8%" align="right" valign="top">'.__('deleted<br />tags','rvg-optimize-database').'</th> | |
| 64 | - <th width="8%" align="right" valign="top">'.__('deleted<br />transients','rvg-optimize-database').'</th> | |
| 65 | - <th width="8%" align="right" valign="top">'.__('deleted<br />pingbacks<br />trackbacks','rvg-optimize-database').'</th> | |
| 66 | - <th width="8%" align="right" valign="top">'.__('deleted<br />orphans','rvg-optimize-database').'</th> | |
| 67 | - <th width="8%" align="right" valign="top">'.__('nr of optimized tables','rvg-optimize-database').'</th> | |
| 68 | - <th width="8%" align="right" valign="top">'.__('database size BEFORE','rvg-optimize-database').'</th> | |
| 69 | - <th width="8%" align="right" valign="top">'.__('database size AFTER','rvg-optimize-database').'</th> | |
| 70 | - <th width="8%" align="right" valign="top">'.__('SAVINGS','rvg-optimize-database').'</th> | |
| 102 | +<br> | |
| 103 | +<br> | |
| 104 | +<div class="odb-log-table"> | |
| 105 | +<table width="97%" border="0" cellspacing="6" cellpadding="0"> | |
| 106 | +<?php | |
| 107 | + | |
| 108 | + echo ' | |
| 109 | + <tr valign="top"> | |
| 110 | + '; | |
| 111 | + | |
| 112 | + echo '<th align="left">'.__('date','rvg-optimize-database').'</th>'; | |
| 113 | + echo '<th align="right">'.__('deleted<br>revisions','rvg-optimize-database').'</th>'; | |
| 114 | + echo '<th align="right">'.__('deleted<br>trash','rvg-optimize-database').'</th>'; | |
| 115 | + echo '<th align="right">'.__('deleted<br>spam','rvg-optimize-database').'</th>'; | |
| 116 | + echo '<th align="right">'.__('deleted<br>tags','rvg-optimize-database').'</th>'; | |
| 117 | + echo '<th align="right">'.__('deleted<br>transients','rvg-optimize-database').'</th>'; | |
| 118 | + echo '<th align="right">'.__('deleted<br>pingbacks<br>trackbacks','rvg-optimize-database').'</th>'; | |
| 119 | + echo '<th align="right">'.__('deleted<br>oEmbed<br>records','rvg-optimize-database').'</th>'; | |
| 120 | + echo '<th align="right">'.__('deleted<br>orphans','rvg-optimize-database').'</th>'; | |
| 121 | + echo '<th align="right">'.__('nr of<br>optimized<br>tables','rvg-optimize-database').'</th>'; | |
| 122 | + echo '<th align="right">'.__('database<br> size<br>BEFORE','rvg-optimize-database').'</th>'; | |
| 123 | + echo '<th align="right">'.__('database<br>size<br>AFTER','rvg-optimize-database').'</th>'; | |
| 124 | + echo '<th align="right">'.__('SAVINGS','rvg-optimize-database').'</th>'; | |
| 125 | + echo ' | |
| 71 | 126 | </tr> |
| 72 | -</table> | |
| 73 | - '; | |
| 74 | - file_put_contents($file, $html, FILE_APPEND); | |
| 75 | - } | |
| 76 | - | |
| 77 | - $html = ' | |
| 78 | -<table width="100%" border="0" cellspacing="6" cellpadding="0"> | |
| 79 | - <tr> | |
| 80 | - <td width="8%" valign="top"><span class="odb-bold">'.$odb_class->log_arr["time"].'</span></td> | |
| 81 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["revisions"].'</td> | |
| 82 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["trash"].'</td> | |
| 83 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["spam"].'</td> | |
| 84 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["tags"].'</td> | |
| 85 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["transients"].'</td> | |
| 86 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["pingbacks"].'</td> | |
| 87 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["orphans"].'</td> | |
| 88 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["tables"].'</td> | |
| 89 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["before"].'</td> | |
| 90 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["after"].'</td> | |
| 91 | - <td width="8%" align="right" valign="top">'.$odb_class->log_arr["savings"].'</td> | |
| 127 | + '; | |
| 128 | + | |
| 129 | + for($i = 0; $i < count($this->res); $i++) { | |
| 130 | + echo ' | |
| 131 | + <tr valign="top"> | |
| 132 | + '; | |
| 133 | + echo '<td>' . $this->res[$i]['odb_timestamp'] .'</td>'; | |
| 134 | + echo '<td align="right">' . $this->res[$i]['odb_revisions'].'</td>'; | |
| 135 | + echo '<td align="right">' . $this->res[$i]['odb_trash'].'</td>'; | |
| 136 | + echo '<td align="right">' . $this->res[$i]['odb_spam'].'</td>'; | |
| 137 | + echo '<td align="right">' . $this->res[$i]['odb_tags'].'</td>'; | |
| 138 | + echo '<td align="right">' . $this->res[$i]['odb_transients'].'</td>'; | |
| 139 | + echo '<td align="right">' . $this->res[$i]['odb_pingbacks'].'</td>'; | |
| 140 | + echo '<td align="right">' . $this->res[$i]['odb_oembeds'].'</td>'; | |
| 141 | + echo '<td align="right">' . $this->res[$i]['odb_orphans'].'</td>'; | |
| 142 | + echo '<td align="right">' . $this->res[$i]['odb_tables'].'</td>'; | |
| 143 | + echo '<td align="right">' . $this->res[$i]['odb_before'].'</td>'; | |
| 144 | + echo '<td align="right">' . $this->res[$i]['odb_after'].'</td>'; | |
| 145 | + echo '<td align="right">' . $this->res[$i]['odb_savings'].'</td>'; | |
| 146 | + echo ' | |
| 92 | 147 | </tr> |
| 148 | + '; | |
| 149 | + } | |
| 150 | + | |
| 151 | + echo ' | |
| 93 | 152 | </table> |
| 94 | - '; | |
| 95 | - file_put_contents($file, $html, FILE_APPEND); | |
| 96 | - } // if($odb_class->odb_rvg_options['logging_on'] == "Y") | |
| 97 | - } // write_log() | |
| 153 | + '; | |
| 154 | + // v4.6.2 | |
| 155 | + $msg = str_replace("'", "\'", __('Clear the log?', 'rvg-optimize-database')); | |
| 156 | +?> | |
| 157 | +<script> | |
| 158 | +function odb_confirm_delete() { | |
| 159 | + if(confirm('<?php echo $msg?>')) { | |
| 160 | + self.location = 'tools.php?page=rvg-optimize-database&action=clear_log' | |
| 161 | + return; | |
| 162 | + } | |
| 163 | +} // function odb_confirm_delete() | |
| 164 | +</script> | |
| 165 | +<br> | |
| 166 | +<input class="button odb-normal" type="button" name="change_options" value="<?php _e('Change Settings', 'rvg-optimize-database')?>" onclick="self.location='options-general.php?page=odb_settings_page'" /> | |
| 167 | + | |
| 168 | +<input class="button odb-normal" type="button" name="clear_log" value="<?php _e('Clear Log', 'rvg-optimize-database') ?>" onclick="return odb_confirm_delete();" /> | |
| 169 | + | |
| 170 | +<input class="button-primary button-large" type="button" name="optimize_summary" value="<?php _e('Optimize (summary)', 'rvg-optimize-database')?>" onclick="self.location='tools.php?page=rvg-optimize-database&action=run_summary'" class="odb-bold" /> | |
| 171 | + | |
| 172 | +<input class="button-primary button-large" type="button" name="optimize_detail" value="<?php _e('Optimize (detail)', 'rvg-optimize-database')?>" onclick="self.location='tools.php?page=rvg-optimize-database&action=run_summary'" class="odb-bold" /> | |
| 173 | +<?php | |
| 174 | + } // odb_view_log() | |
| 98 | 175 | |
| 99 | 176 | |
| 100 | 177 | /******************************************************************************************** |
| 101 | - * ADD A MESSAGE TO THE DEBUG LOG FILE | |
| 102 | - ********************************************************************************************/ | |
| 103 | - function write_debug_log($msg) | |
| 104 | - { | |
| 105 | - global $odb_class; | |
| 106 | - | |
| 107 | - if (defined('WP_DEBUG') && WP_DEBUG) | |
| 108 | - { // ONLY USE THIS LOG IN DEBUG MODE | |
| 109 | - $file = $odb_class->odb_logfile_debug_path; | |
| 110 | - $txt = Date('Y/m/d H:i:s').' '.$msg."\n"; | |
| 111 | - file_put_contents($file, $txt, FILE_APPEND); | |
| 112 | - } | |
| 113 | - } // write_debug_log() | |
| 114 | - | |
| 178 | + * GET THE NUMBER OF LOG RECORDS - v4.6 | |
| 179 | + ********************************************************************************************/ | |
| 180 | + function odb_log_count() { | |
| 181 | + global $odb_class, $wpdb; | |
| 182 | + | |
| 183 | + $this->sql = " | |
| 184 | + SELECT COUNT(*) AS logcnt FROM `" . $odb_class->odb_logtable_name . "` | |
| 185 | + "; | |
| 186 | + $this->res = $wpdb->get_results($this->sql, ARRAY_A); | |
| 187 | + return $this->res[0]['logcnt']; | |
| 188 | + } // odb_log_count() | |
| 189 | + | |
| 115 | 190 | } // ODB_Logger |
| 191 | + | |
| 192 | + | |
| 193 | + | |