| 1 |
<?php |
| 2 |
### Check Whether User Can Manage Database |
| 3 |
if ( ! current_user_can( 'install_plugins' ) ) { |
| 4 |
die( 'Access Denied' ); |
| 5 |
} |
| 6 |
|
| 7 |
|
| 8 |
### Variables Variables Variables |
| 9 |
$base_name = plugin_basename('wp-dbmanager/database-manager.php'); |
| 10 |
$base_page = 'admin.php?page='.$base_name; |
| 11 |
|
| 12 |
### Form Processing |
| 13 |
if(!empty($_POST['do'])) { |
| 14 |
// Lets Prepare The Variables |
| 15 |
$optimize = $_POST['optimize']; |
| 16 |
|
| 17 |
// Decide What To Do |
| 18 |
switch($_POST['do']) { |
| 19 |
case __('Optimize', 'wp-dbmanager'): |
| 20 |
check_admin_referer('wp-dbmanager_optimize'); |
| 21 |
if(!empty($optimize)) { |
| 22 |
$tables_string = ''; |
| 23 |
foreach($optimize as $key => $value) { |
| 24 |
if($value == 'yes') { |
| 25 |
$tables_string .= '`, `'.$key; |
| 26 |
} |
| 27 |
} |
| 28 |
} else { |
| 29 |
$text = '<p style="color: red;">'.__('No Tables Selected', 'wp-dbmanager').'</p>'; |
| 30 |
} |
| 31 |
$selected_tables = substr($tables_string, 3); |
| 32 |
$selected_tables .= '`'; |
| 33 |
if(!empty($selected_tables)) { |
| 34 |
$optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables"); |
| 35 |
if(!$optimize2) { |
| 36 |
$text = '<p style="color: red;">'.sprintf(__('Table(s) \'%s\' NOT Optimized', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>'; |
| 37 |
} else { |
| 38 |
$text = '<p style="color: green;">'.sprintf(__('Table(s) \'%s\' Optimized', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>'; |
| 39 |
} |
| 40 |
} |
| 41 |
break; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
### Show Tables |
| 47 |
$tables = $wpdb->get_col("SHOW TABLES"); |
| 48 |
?> |
| 49 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 50 |
<!-- Optimize Database --> |
| 51 |
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>"> |
| 52 |
<?php wp_nonce_field('wp-dbmanager_optimize'); ?> |
| 53 |
<div class="wrap"> |
| 54 |
<h2><?php _e('Optimize Database', 'wp-dbmanager'); ?></h2> |
| 55 |
<br style="clear" /> |
| 56 |
<table class="widefat"> |
| 57 |
<thead> |
| 58 |
<tr> |
| 59 |
<th><?php _e('Tables', 'wp-dbmanager'); ?></th> |
| 60 |
<th><?php _e('Options', 'wp-dbmanager'); ?></th> |
| 61 |
</tr> |
| 62 |
</thead> |
| 63 |
<?php |
| 64 |
$no = 0; |
| 65 |
foreach($tables as $table_name) { |
| 66 |
if($no%2 == 0) { |
| 67 |
$style = ''; |
| 68 |
} else { |
| 69 |
$style = ' class="alternate"'; |
| 70 |
} |
| 71 |
$no++; |
| 72 |
echo "<tr$style><th align=\"left\" scope=\"row\">$table_name</th>\n"; |
| 73 |
echo "<td><input type=\"radio\" id=\"$table_name-no\" name=\"optimize[$table_name]\" value=\"no\" /> <label for=\"$table_name-no\">".__('No', 'wp-dbmanager')."</label> <input type=\"radio\" id=\"$table_name-yes\" name=\"optimize[$table_name]\" value=\"yes\" checked=\"checked\" /> <label for=\"$table_name-yes\">".__('Yes', 'wp-dbmanager').'</label></td></tr>'; |
| 74 |
} |
| 75 |
?> |
| 76 |
<tr> |
| 77 |
<td colspan="2" align="center"><?php _e('Database should be optimized once every month.', 'wp-dbmanager'); ?></td> |
| 78 |
</tr> |
| 79 |
<tr> |
| 80 |
<td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Optimize', 'wp-dbmanager'); ?>" class="button" /> <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td> |
| 81 |
</tr> |
| 82 |
</table> |
| 83 |
</div> |
| 84 |
</form> |
| 85 |
|