Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
A lot of code optimization. Added function to detect innoDB (was adde…
Browse files Browse the repository at this point in the history
…d before). Now the function is in action and certain things will act differently when innoDB tables detected. Mainly, Optimization will be disabled and tables view will hide the overhead column.
  • Loading branch information
ruhanirabin committed Apr 30, 2014
1 parent 539f70b commit cad9668
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 88 deletions.
5 changes: 3 additions & 2 deletions wp-optimize-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# --------------------------------------- #
# prevent file from being accessed directly
# --------------------------------------- #
if ('wp-optimize-admin.php' == basename($_SERVER['SCRIPT_FILENAME']))
Die ('Please do not access this file directly. Thanks!');
if ( ! defined( 'WPINC' ) ) {
die;
}

?>

Expand Down
28 changes: 20 additions & 8 deletions wp-optimize-common.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

if ('wp-optimize-common.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not access this file directly. Thanks!');
# --------------------------------------- #
# prevent file from being accessed directly
# --------------------------------------- #
if ( ! defined( 'WPINC' ) ) {
die;
}

// common functions
if (! defined('WPO_PLUGIN_MAIN_PATH'))
Expand Down Expand Up @@ -46,10 +50,12 @@ function wpo_detectDBType() {
$table_engine = $tabletype->Engine;
}

$wpo_table_type = strtolower(strval($table_engine));

if (! defined('WPO_TABLE_TYPE'))
define( WPO_TABLE_TYPE,strtolower($table_engine));
define( WPO_TABLE_TYPE,$wpo_table_type);

return WPO_TABLE_TYPE;
return $wpo_table_type;

}

Expand Down Expand Up @@ -237,7 +243,7 @@ function wpo_cron_action() {

//db optimize part - optimize
// disble optimization if innoDB
if (!WPO_TABLE_TYPE == 'innodb'){
if (WPO_TABLE_TYPE != 'innodb'){

if ($this_options['optimize'] == 'true'){

Expand All @@ -258,7 +264,7 @@ function wpo_cron_action() {
wpo_debugLog('Updating options with value +'.$part2);

} // endif $this_options['optimize']
} //end if if (!WPO_TABLE_TYPE == 'innodb'){
} //end if if (WPO_TABLE_TYPE != 'innodb'){

} // end if ( get_option(OPTION_NAME_SCHEDULE) == 'true')
}
Expand Down Expand Up @@ -331,8 +337,14 @@ function wpo_PluginOptionsSetDefaults() {
}


### Function: Format Bytes Into KB/MB
if(!function_exists('wpo_format_size')) {
/**
* wpo_format_size()
* Function: Format Bytes Into KB/MB
* @param mixed $rawSize
* @return
*/
if(!function_exists('wpo_format_size')) {

function wpo_format_size($rawSize) {
if($rawSize / 1073741824 > 1)
return number_format_i18n($rawSize/1048576, 1) . ' '.__('Gb', 'wp-optimize');
Expand Down
12 changes: 10 additions & 2 deletions wp-optimize-credits.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?php
# --------------------------------------- #
# prevent file from being accessed directly
# --------------------------------------- #
if ( ! defined( 'WPINC' ) ) {
die;
}
?>
<!-- a feed reader to read the development log -->
<div class="wpo_section wpo_group">
<div class="wpo_col wpo_span_1_of_3">
Expand Down Expand Up @@ -28,7 +36,7 @@
<br /><br />

<h3><?php _e('Contributing Developers','wp-optimize'); ?></h3><br />
<a href="plugins@ruhanirabin.com" target="_blank" alt="" title="E-mail"><?php _e('Help me make this plugin better','wp-optimize'); ?></a>, <?php _e('I am looking for contributing developers.','wp-optimize'); ?><br />
<a href="mailto:plugins@ruhanirabin.com" target="_blank" alt="" title="E-mail"><?php _e('Help me make this plugin better','wp-optimize'); ?></a>, <?php _e('I am looking for contributing developers.','wp-optimize'); ?><br />
<?php _e('Your name and website will be credited here in the plugin','wp-optimize'); ?>.<br />
&nbsp;
</div>
Expand All @@ -49,7 +57,7 @@

<h3><?php _e('Plugin Resources','wp-optimize'); ?></h3>
<h4>
<p><a href="http://ruhanirabin.github.io/WP-Optimize" target="_blank"><?php _e('Plugin Homepage', 'wp-optimize'); ?></a></p>
<p><a href="http://wordpress.org/plugins/wp-optimize/" target="_blank"><?php _e('Plugin Homepage', 'wp-optimize'); ?></a></p>
<p><a href="https://github.com/ruhanirabin/WP-Optimize/issues" target="_blank"><?php _e('Support (GitHub)', 'wp-optimize'); ?></a></p>
<p><a href="http://wordpress.org/plugins/wp-optimize/changelog/" target="_blank"><?php _e('Change Log', 'wp-optimize'); ?></a></p>
<p><a href="http://wordpress.org/plugins/wp-optimize/faq/" target="_blank"><?php _e('FAQ', 'wp-optimize'); ?></a></p>
Expand Down
115 changes: 53 additions & 62 deletions wp-optimize-main.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
# --------------------------------------- #
# prevent file from being accessed directly
# --------------------------------------- #
if ( ! defined( 'WPINC' ) ) {
die;
}

$text = '';

if (isset($_POST["clean-revisions"])) {
Expand Down Expand Up @@ -67,21 +74,22 @@

}

if ($Optimize == true){
$tables = $wpdb->get_col("SHOW TABLES");
foreach($tables as $table_name) {
$local_query = 'OPTIMIZE TABLE '.$table_name;
$result_query = $wpdb->query($local_query);
if ($Optimize == true){
if (WPO_TABLE_TYPE != 'innodb'){
$tables = $wpdb->get_col("SHOW TABLES");
foreach($tables as $table_name) {
$local_query = 'OPTIMIZE TABLE '.$table_name;
$result_query = $wpdb->query($local_query);
wpo_updateTotalCleaned(strval($total_gain));
} // if innodb is false
}

}
wpo_updateTotalCleaned(strval($total_gain));


}
?>



<div class="wpo_section wpo_group">
<form action="#" method="post" enctype="multipart/form-data" name="optimize_form" id="optimize_form">
<div class="wpo_col wpo_span_1_of_3">
Expand Down Expand Up @@ -216,18 +224,28 @@
<label>

<?php
if (!WPO_TABLE_TYPE == 'innodb'){
echo '<input name="optimize-db" id="optimize-db" type="checkbox" value="" />';
echo '<b>';
_e('Optimize database tables', 'wp-optimize');
echo '</b>';
} else {
echo '<input name="optimize-db-disabled" id="optimize-db" type="checkbox" value="" disabled/>';
echo '<b>';
_e('Database optimization not available for InnoDB table types', 'wp-optimize');
echo '</b>';

}
$dbtype = wpo_detectDBType();

switch($dbtype){
case "myisam":
echo '<input name="optimize-db" id="optimize-db" type="checkbox" value="" />';
echo '<b>';
_e('Optimize database tables', 'wp-optimize');
echo '</b>';
break;
case "innodb":
echo '<input name="optimize-db-disabled" id="optimize-db" type="checkbox" value="" disabled/>';
echo '<b>';
_e('Database optimization not available for InnoDB table types', 'wp-optimize');
echo '</b>';
break;
default:
echo '<input name="optimize-db" id="optimize-db" type="checkbox" value="" />';
echo '<b>';
_e('Optimize database tables', 'wp-optimize');
echo '</b>';
}

?>
</label>
</p>
Expand Down Expand Up @@ -350,18 +368,16 @@
?>
<br />

<h2>
<h4>
<?php

if (isset($_POST["optimize-db"])) {
list ($part1, $part2) = wpo_getCurrentDBSize();

if (WPO_TABLE_TYPE != 'innodb'){
_e('Current database size : ', 'wp-optimize');
echo '<font color="blue">';
echo $part1.'</font> ';

if (!WPO_TABLE_TYPE == 'innodb'){

echo ' <br />';
_e('You have saved', 'wp-optimize');
echo ' : ';
Expand All @@ -371,14 +387,14 @@

}
else {
if (WPO_TABLE_TYPE != 'innodb'){
list ($part1, $part2) = wpo_getCurrentDBSize();

_e('Current database size', 'wp-optimize');
_e('Current database size', 'wp-optimize');
echo ' : ';
echo '<font color="blue">';
echo $part1.'</font> ';
$this_value = $part2;
if (!WPO_TABLE_TYPE == 'innodb'){

if ($this_value > 0){
echo ' <br />';
_e('You can save almost', 'wp-optimize');
Expand All @@ -390,60 +406,44 @@
}

?>
</h2>
</h4>
<?php
if (!WPO_TABLE_TYPE == 'innodb'){

if (WPO_TABLE_TYPE != 'innodb'){
$total_cleaned = get_option(OPTION_NAME_TOTAL_CLEANED);
$total_cleaned_num = floatval($total_cleaned);

if ($total_cleaned_num > 0){
echo '<h2>';
echo '<h4>';
_e('Total clean up overall','wp-optimize');
echo ': ';
echo '<font color="green">';
//echo $total_cleaned.' '.__('Kb', 'wp-optimize');
echo wpo_format_size($total_cleaned);
echo '</font>';
echo '</h2>';
//echo '<br />';
echo '</h4>';


}
} //end if WPO_TABLE_TYPE
?>


<!-- <p>
<label>
<input type="checkbox" name="data[user_role][contributor]" value="1">
Contributor </label>
</p>
<p>
<label>
<input type="checkbox" name="data[user_role][subscriber]" value="1">
Subscriber </label>
</p> -->
</div>
</div>
</div>

<div class="wpo_col wpo_span_1_of_3">
<!--<div class="postbox">-->
<!-- <h3 class="hndle"><span>Status</span></h3> -->
<!-- <div class="inside">-->


<p>
<?php wpo_headerImage(); ?>
</p>

<p>
<?php _e('Sponsor','wp-optimize')?></small><br><a href="http://j.mp/1ePlbvc" target="_blank"><img style="border:0px" src="<?php echo WPO_PLUGIN_URL ;?>elegantthemes_sm.png" width="310" height="auto" alt=""></a>
</p>
<!--</div>
</div> -->

</div>
</div>

<!-- TODO: Need to make this checkbox selection thing working -->
<!-- TODO: Need to make this checkbox selection thing persistent -->

<script type="text/javascript">
function SetDefaults() {
Expand All @@ -452,7 +452,7 @@ function SetDefaults() {
document.getElementById("clean-autodraft").checked = true;

<?php
if (!WPO_TABLE_TYPE == 'innodb'){
if (WPO_TABLE_TYPE != 'innodb'){
echo 'document.getElementById("optimize-db").checked = true;';
}
?>
Expand All @@ -461,15 +461,6 @@ function SetDefaults() {
}
</script>

<?php
//_e('Database Optimization Options','wp-optimize');

// echo ' - ';
// echo '<a href="#" onClick="javascript:SetDefaults();">';
// _e('Select recommended','wp-optimize');
// echo '</a>';
//
?>

<script>
SetDefaults();
Expand Down
8 changes: 7 additions & 1 deletion wp-optimize-settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php
//
# --------------------------------------- #
# prevent file from being accessed directly
# --------------------------------------- #
if ( ! defined( 'WPINC' ) ) {
die;
}

$GLOBALS['wpo_auto_options'] = get_option('wp-optimize-auto');
error_reporting( error_reporting() & ~E_NOTICE );

Expand Down
Loading

0 comments on commit cad9668

Please sign in to comment.