| 1 |
<?php |
| 2 |
/* |
| 3 |
+----------------------------------------------------------------+ |
| 4 |
| | |
| 5 |
| WordPress 2.0 Plugin: WP-DBManager 2.04 | |
| 6 |
| Copyright (c) 2005 Lester "GaMerZ" Chan | |
| 7 |
| | |
| 8 |
| File Written By: | |
| 9 |
| - Lester "GaMerZ" Chan | |
| 10 |
| - http://www.lesterchan.net | |
| 11 |
| | |
| 12 |
| File Information: | |
| 13 |
| - Database Optimize | |
| 14 |
| - wp-content/plugins/dbmanager/database-optimize.php | |
| 15 |
| | |
| 16 |
+----------------------------------------------------------------+ |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
### Require Database Config |
| 21 |
require('database-config.php'); |
| 22 |
|
| 23 |
|
| 24 |
### Form Processing |
| 25 |
if($_POST['do']) { |
| 26 |
// Lets Prepare The Variables |
| 27 |
$optimize = $_POST['optimize']; |
| 28 |
|
| 29 |
// Decide What To Do |
| 30 |
switch($_POST['do']) { |
| 31 |
case 'Optimize': |
| 32 |
if(!empty($optimize)) { |
| 33 |
foreach($optimize as $key => $value) { |
| 34 |
if($value == 'yes') { |
| 35 |
$tables_string .= ', '.$key; |
| 36 |
} |
| 37 |
} |
| 38 |
} else { |
| 39 |
$text = '<font color="red">No Tables Selected</font>'; |
| 40 |
} |
| 41 |
$selected_tables = substr($tables_string, 2); |
| 42 |
if(!empty($selected_tables)) { |
| 43 |
$optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables"); |
| 44 |
if(!$optimize2) { |
| 45 |
$text = "<font color=\"red\">Table(s) '$selected_tables' NOT Optimized</font>"; |
| 46 |
} else { |
| 47 |
$text = "<font color=\"green\">Table(s) '$selected_tables' Optimized</font>"; |
| 48 |
} |
| 49 |
} |
| 50 |
break; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
### Show Tables |
| 56 |
$tables = $wpdb->get_results("SHOW TABLES"); |
| 57 |
?> |
| 58 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 59 |
<!-- Optimize Database --> |
| 60 |
<div class="wrap"> |
| 61 |
<h2>Optimize Database</h2> |
| 62 |
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> |
| 63 |
<table width="100%" cellspacing="3" cellpadding="3" border="0"> |
| 64 |
<tr> |
| 65 |
<th align="left" scope="col">Tables</th> |
| 66 |
<th align="left" scope="col">Options</th> |
| 67 |
</tr> |
| 68 |
<?php |
| 69 |
foreach($tables as $dbtable) { |
| 70 |
if($no%2 == 0) { |
| 71 |
$style = 'style=\'background-color: #eee\''; |
| 72 |
} else { |
| 73 |
$style = 'style=\'background-color: none\''; |
| 74 |
} |
| 75 |
$no++; |
| 76 |
$table_name = '$dbtable->Tables_in_'.DB_NAME; |
| 77 |
eval("\$table_name = \"$table_name\";"); |
| 78 |
echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n"; |
| 79 |
echo "<td><input type=\"radio\" name=\"optimize[$table_name]\" value=\"no\" />No <input type=\"radio\" name=\"optimize[$table_name]\" value=\"yes\" checked=\"checked\" />Yes</td></tr>"; |
| 80 |
} |
| 81 |
?> |
| 82 |
<tr> |
| 83 |
<td colspan="2" align="center">Database should be optimize once every month.</td> |
| 84 |
</tr> |
| 85 |
<tr> |
| 86 |
<td colspan="2" align="center"><input type="submit" name="do" value="Optimize" class="button" /> <input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td> |
| 87 |
</tr> |
| 88 |
</table> |
| 89 |
</form> |
| 90 |
</div> |