Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,572 @@
<?php
class ADBC_Tasks_List extends WP_List_Table {
/** Holds the message to be displayed if any */
private $aDBc_message = "";
/** Holds the class for the message : updated or error. Default is updated */
private $aDBc_class_message = "updated";
/** Holds tasks that will be displayed */
private $aDBc_tasks_to_display = array();
/** Holds counts + info of tasks categories */
private $aDBc_tasks_categories_info = array();
/** Should we display "run search" or "continue search" button (after a timeout failed). Default is "run search" */
private $aDBc_which_button_to_show = "new_search";
// This array contains belongs_to info about plugins and themes
private $array_belongs_to_counts = array();
// Holds msg that will be shown if folder adbc_uploads cannot be created by the plugin (This is verified after clicking on scan button)
private $aDBc_permission_adbc_folder_msg = "";
function __construct() {
parent::__construct( array(
'singular' => __( 'Task', 'advanced-database-cleaner' ),
'plural' => __( 'Tasks', 'advanced-database-cleaner' ),
'ajax' => false
) );
$this->aDBc_prepare_and_count_tasks();
$this->aDBc_print_page_content();
}
/** Prepare items */
function aDBc_prepare_and_count_tasks() {
if ( ADBC_PLUGIN_PLAN == "pro" ) {
// Verify if the adbc_uploads cannot be created
$adbc_folder_permission = get_option( "aDBc_permission_adbc_folder_needed" );
if ( ! empty( $adbc_folder_permission ) ) {
$this->aDBc_permission_adbc_folder_msg = sprintf( __( 'The plugin needs to create the following directory "%1$s" to save the scan results but this was not possible automatically. Please create that directory manually and set correct permissions so it can be writable by the plugin.','advanced-database-cleaner' ), ADBC_UPLOAD_DIR_PATH_TO_ADBC );
// Once we display the msg, we delete that option from DB
delete_option( "aDBc_permission_adbc_folder_needed" );
}
}
// Verify if the user wants to edit the categorization of a task. This block test comes from edit_item_categorization.php
if ( ADBC_PLUGIN_PLAN == "pro" ) {
if ( isset( $_POST['aDBc_cancel'] ) ) {
// If the user cancels the edit, remove the temp file
if ( file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tasks_manually_correction_temp.txt" ) )
unlink( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tasks_manually_correction_temp.txt" );
} else if ( isset( $_POST['aDBc_correct'] ) ) {
// Get the new belongs to of items
$new_belongs_to = $_POST['new_belongs_to'];
// Get value of checkbox to see if user wants to send correction to the server
if ( isset( $_POST['aDBc_send_correction_to_server'] ) ) {
$this->aDBc_message = aDBc_edit_categorization_of_items( "tasks", $new_belongs_to, 1 );
} else {
$this->aDBc_message = aDBc_edit_categorization_of_items( "tasks", $new_belongs_to, 0 );
}
// Remove the temp file
if ( file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tasks_manually_correction_temp.txt" ) )
unlink( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tasks_manually_correction_temp.txt" );
}
}
// Process bulk action if any before preparing tasks to display
$this->process_bulk_action();
// Prepare data
aDBc_prepare_items_to_display(
$this->aDBc_tasks_to_display,
$this->aDBc_tasks_categories_info,
$this->aDBc_which_button_to_show,
array(),
array(),
$this->array_belongs_to_counts,
$this->aDBc_message,
$this->aDBc_class_message,
"tasks"
);
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns() {
$aDBc_belongs_to_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __( 'Indicates the creator of the task: either a plugin, a theme or WordPress itself. If not sure about the creator, an estimation (%) will be displayed. The higher the percentage is, the more likely that the task belongs to that creator.','advanced-database-cleaner' ) ." </span>
</span>";
$columns = array(
'cb' => '<input type="checkbox" />',
'hook_name' => __( 'Hook name','advanced-database-cleaner' ),
'arguments' => __( 'Arguments','advanced-database-cleaner' ),
'next_run' => __( 'Next run - Frequency','advanced-database-cleaner' ),
'site_id' => __( 'Site','advanced-database-cleaner' ),
'hook_belongs_to' => __( 'Belongs to','advanced-database-cleaner' ) . $aDBc_belongs_to_toolip
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'hook_name' => array( 'hook_name', false ),
'site_id' => array( 'site_id', false )
);
return $sortable_columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of tasks to display
$display_data = array_slice($this->aDBc_tasks_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_tasks_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'arguments':
if($item[$column_name] == "none"){
return "<span>" . __('None', 'advanced-database-cleaner') . "</span>";
}else{
$unserialized_args = json_decode($item[$column_name]);
// If the arguments are not an array, we return [N/A]
if (is_array($unserialized_args)) {
$args_as_string = array_map(function($arg) {
return (is_object($arg) || is_array($arg)) ? json_encode($arg) : (string) $arg;
}, $unserialized_args);
return "<span class='aDBc-arguments'>" . implode(" / ", $args_as_string) . "</span>";
} else {
return "<span class='aDBc-arguments'>[N/A]</span>";
}
}
break;
case 'hook_name':
return esc_html($item[$column_name]);
case 'next_run':
case 'site_id':
case 'hook_belongs_to':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb($item) {
$data = array(
'site_id' => $item['site_id'],
'hook_name' => $item['hook_name'],
'timestamp' => $item['timestamp'],
'arguments' => $item['arguments']
);
$value = json_encode($data);
return sprintf(
"<input type='checkbox' name='aDBc_elements_to_process[]' value='%s' />",
esc_attr($value)
);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'scan_selected' => __( 'Scan selected tasks','advanced-database-cleaner' ),
'edit_categorization' => __( 'Edit categorization','advanced-database-cleaner' ),
'delete' => __( 'Delete','advanced-database-cleaner' )
);
if ( ADBC_PLUGIN_PLAN == "free" ) {
unset( $actions['scan_selected'] );
unset( $actions['edit_categorization'] );
}
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('No tasks found!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'delete' ) {
// If the user wants to clean the tasks he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare tasks to delete in organized array to minimize switching from blogs
$tasks_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $task){
$json = wp_unslash( $task ); // Unslash because WP adds slashes to the POST data
$data = json_decode( $json, true );
$site_id = sanitize_html_class($data['site_id']);
if(is_numeric($site_id)){
if(empty($tasks_to_delete[$site_id])){
$tasks_to_delete[$site_id] = array();
}
array_push($tasks_to_delete[$site_id], $task);
}
}
// Delete tasks
foreach($tasks_to_delete as $site_id => $tasks_info){
switch_to_blog($site_id);
foreach($tasks_info as $task) {
$json = wp_unslash( $task ); // Unslash because WP adds slashes to the POST data
$data = json_decode( $json, true );
$hook = $data['hook_name'];
$timestamp = $data['timestamp'];
$args = $data['arguments'];
if(is_numeric($timestamp)){
if($args == "none"){
wp_unschedule_event($timestamp, $hook);
}else{
$args = json_decode(stripslashes($args));
wp_unschedule_event($timestamp, $hook, $args);
// Check if the user has deleted a task beloging to this plugin. If so, update his data in DB to inactive
// A task of ADBC cannot be without an arg, not necessary to add this check to "none" args
if($hook == "aDBc_clean_scheduler"){
aDBc_update_task_in_db_after_delete($args[0], "aDBc_clean_schedule");
}else if($hook == "aDBc_optimize_scheduler"){
aDBc_update_task_in_db_after_delete($args[0], "aDBc_optimize_schedule");
}
}
}
}
restore_current_blog();
}
}else{
foreach($_POST['aDBc_elements_to_process'] as $task) {
$json = wp_unslash( $task ); // Unslash because WP adds slashes to the POST data
$data = json_decode( $json, true );
$hook = $data['hook_name'];
$timestamp = $data['timestamp'];
$args = $data['arguments'];
if(is_numeric($timestamp)){
if($args == "none"){
wp_unschedule_event($timestamp, $hook);
}else{
$args = json_decode(stripslashes($args));
wp_unschedule_event($timestamp, $hook, $args);
// Check if the user has deleted a task beloging to this plugin. If so, update his data in DB to inactive
// A task of ADBC cannot be without an arg, not necessary to add this check to "none" args
if($hook == "aDBc_clean_scheduler"){
aDBc_update_task_in_db_after_delete($args[0], "aDBc_clean_schedule");
}else if($hook == "aDBc_optimize_scheduler"){
aDBc_update_task_in_db_after_delete($args[0], "aDBc_optimize_schedule");
}
}
}
}
}
// Update the message to show to the user
$this->aDBc_message = __('Selected scheduled tasks cleaned successfully!', 'advanced-database-cleaner');
}
}else if($action == 'edit_categorization'){
// If the user wants to edit categorization of the tasks he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
// Create a temp file containing tasks names to change categorization for
$aDBc_path_items = @fopen(ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tasks_manually_correction_temp.txt", "w");
if($aDBc_path_items){
foreach($_POST['aDBc_elements_to_process'] as $task) {
$json = wp_unslash( $task ); // Unslash because WP adds slashes to the POST data
$data = json_decode( $json, true );
$hook = $data['hook_name'];
fwrite($aDBc_path_items, $hook . "\n");
}
fclose($aDBc_path_items);
}
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
// Print a message if any
if($this->aDBc_message != ""){
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
// If the folder adbc_uploads cannot be created, show a msg to users
if(!empty($this->aDBc_permission_adbc_folder_msg)){
echo '<div class="error notice is-dismissible"><p>' . $this->aDBc_permission_adbc_folder_msg . '</p></div>';
}
?>
<div class="aDBc-content-max-width">
<?php
// If tasks_manually_correction_temp.txt exist, this means that user want to edit categorization
if ( ADBC_PLUGIN_PLAN == "pro" && file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . '/tasks_manually_correction_temp.txt' ) ) {
include_once 'edit_item_categorization.php';
} else {
// If not, we print the tasks normally
// Print a notice/warning according to each type of tasks
if ( ADBC_PLUGIN_PLAN == "pro" ) {
if($_GET['aDBc_cat'] == 'o' && $this->aDBc_tasks_categories_info['o']['count'] > 0){
echo '<div class="aDBc-box-warning-orphan">' . __('Tasks below seem to be orphan! However, please delete only those you are sure to be orphan!','advanced-database-cleaner') . '</div>';
}else if(($_GET['aDBc_cat'] == 'all' || $_GET['aDBc_cat'] == 'u') && $this->aDBc_tasks_categories_info['u']['count'] > 0){
$aDBc_settings = get_option('aDBc_settings');
$hide_not_categorized_msg = empty($aDBc_settings['hide_not_categorized_yet_msg']) ? "" : $aDBc_settings['hide_not_categorized_yet_msg'];
if ( $hide_not_categorized_msg != "yes" ) {
echo '<div id="aDBc-box-info" class="aDBc-box-info">'
. '<div style="width:100%">'
. __('Some of your tasks are not categorized yet! Please click on the button below to categorize them!','advanced-database-cleaner')
. '</div>'
. '<div><a href="#" id="aDBc-dismiss-not-categorized-yet-msg" title="' . __('Dismiss similar messages', 'advanced-database-cleaner') . '"><span class="dashicons dashicons-dismiss" style="text-decoration:none;font-size:16px;margin-top:4px"></span></a></div>'
. '</div>';
}
}
}
?>
<div class="aDBc-clear-both" style="margin-top:15px"></div>
<!-- Code for "run new search" button + Show loading image -->
<div style="float:left">
<?php
if ( $this->aDBc_which_button_to_show == "new_search" ) {
$aDBc_search_text = __( 'Scan tasks', 'advanced-database-cleaner' );
} else {
$aDBc_search_text = __( 'Continue scanning ...', 'advanced-database-cleaner' );
}
?>
<!-- Hidden input used by ajax to know which item type we are dealing with -->
<input type="hidden" id="aDBc_item_type" value="tasks"/>
<?php
// These hidden inputs are used by ajax to see if we should execute the scan automatically after reloading a page
$iteration = get_option("aDBc_temp_last_iteration_tasks");
$currently_scanning = get_option("aDBc_temp_currently_scanning_tasks");
?>
<input type="hidden" id="aDBc_currently_scanning" value="<?php echo $currently_scanning; ?>"/>
<input type="hidden" id="aDBc_iteration" value="<?php echo $iteration; ?>"/>
<input type="hidden" id="aDBc_count_uncategorized" value="<?php echo $this->aDBc_tasks_categories_info['u']['count']; ?>"/>
<input type="hidden" id="aDBc_count_all_items" value="<?php echo $this->aDBc_tasks_categories_info['all']['count']; ?>"/>
<?php
if ( ADBC_PLUGIN_PLAN == "pro" ) {
?>
<input id="aDBc_new_search_button" type="submit" class="aDBc-run-new-search" value="<?php echo $aDBc_search_text; ?>" name="aDBc_new_search_button" />
<?php
} else {
?>
<div class="aDBc-premium-tooltip">
<input id="aDBc_new_search_button" type="submit" class="aDBc-run-new-search" value="<?php echo $aDBc_search_text; ?>" name="aDBc_new_search_button" style="opacity:0.5" disabled />
<span style="width:390px" class="aDBc-premium-tooltiptext">
<?php _e('Please <a href="?page=advanced_db_cleaner&aDBc_tab=premium">upgrade</a> to Pro to categorize and detect orphaned tasks','advanced-database-cleaner') ?>
</span>
</div>
<?php
}
?>
</div>
<!-- Print numbers of items found in each category -->
<div class="aDBc-category-counts">
<?php
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
// Remove the paged parameter to start always from the first page when selecting a new category
$aDBc_new_URI = remove_query_arg( 'paged', $aDBc_new_URI );
foreach ( $this->aDBc_tasks_categories_info as $abreviation => $category_info ) {
$aDBc_new_URI = add_query_arg( 'aDBc_cat', $abreviation, $aDBc_new_URI );
$selected_color = $abreviation == $_GET['aDBc_cat'] ? $category_info['color'] : '#eee';
$aDBc_link_style = "color:" . $category_info['color'];
$aDBc_count = $category_info['count'];
if ( ADBC_PLUGIN_PLAN == "free" && $abreviation != "all" && $abreviation != "u" ) {
$aDBc_new_URI = "";
$aDBc_link_style = $aDBc_link_style . ";cursor:default;pointer-events:none";
$aDBc_count = "-";
}
?>
<span class="<?php echo $abreviation == $_GET['aDBc_cat'] ? 'aDBc-selected-category' : ''?>">
<span class="aDBc-premium-tooltip aDBc-category-span">
<a href="<?php echo esc_url( $aDBc_new_URI ) ?>" class="aDBc-category-counts-links" style="<?php echo $aDBc_link_style ?>">
<span><?php echo $category_info['name']; ?></span>
</a>
<div class="aDBc-category-total" style="border:1px solid <?php echo $selected_color ?>; border-bottom:3px solid <?php echo $selected_color ?>;">
<span style="color:#000"><?php echo $aDBc_count ?></span>
</div>
<?php
if ( ADBC_PLUGIN_PLAN == "free" && $abreviation != "all" && $abreviation != "u" ) {
?>
<span style="width:150px" class="aDBc-premium-tooltiptext">
<a href="https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner/" target="_blank">
<?php _e( 'Available in Pro version!', 'advanced-database-cleaner' ); ?>
</a>
</span>
<?php
}
?>
</span>
</span>
<?php
}
?>
</div>
<div class="aDBc-clear-both"></div>
<div id="aDBc-progress-container">
<span id="aDBc_collected_files" href="#" style="color:gray">
</span>
<div class="aDBc-progress-background">
<div id="aDBc-progress-bar" class="aDBc-progress-bar"></div>
</div>
<a id="aDBc_stop_scan" href="#" style="color:red">
<?php _e('Stop the scan','advanced-database-cleaner') ?>
</a>
<span id="aDBc_stopping_msg" style="display:none">
<?php _e('Stopping...','advanced-database-cleaner') ?>
</span>
</div>
<?php include_once 'header_page_filter.php'; ?>
<div class="aDBc-clear-both"></div>
<form id="aDBc_form" action="" method="post">
<?php
$this->display();
?>
</form>
<?php
}
?>
</div>
<?php
}
}
new ADBC_Tasks_List();
?>

View File

@@ -0,0 +1,632 @@
<?php
class ADBC_Options_List extends WP_List_Table {
/** Holds the message to be displayed if any */
private $aDBc_message = "";
/** Holds the class for the message : updated or error. Default is updated */
private $aDBc_class_message = "updated";
/** Holds options that will be displayed */
private $aDBc_options_to_display = array();
/** Holds counts + info of options categories */
private $aDBc_options_categories_info = array();
/** Should we display "run search" or "continue search" button (after a timeout failed). Default is "run search" */
private $aDBc_which_button_to_show = "new_search";
// This array contains belongs_to info about plugins and themes
private $array_belongs_to_counts = array();
// Holds msg that will be shown if folder adbc_uploads cannot be created by the plugin (This is verified after clicking on scan button)
private $aDBc_permission_adbc_folder_msg = "";
function __construct(){
parent::__construct(array(
'singular' => __('Option', 'advanced-database-cleaner'),
'plural' => __('Options', 'advanced-database-cleaner'),
'ajax' => false
));
$this->aDBc_prepare_and_count_options();
$this->aDBc_print_page_content();
}
/** Prepare items */
function aDBc_prepare_and_count_options() {
if ( ADBC_PLUGIN_PLAN == "pro" ) {
// Verify if the adbc_uploads cannot be created
$adbc_folder_permission = get_option( "aDBc_permission_adbc_folder_needed" );
if ( ! empty( $adbc_folder_permission ) ) {
$this->aDBc_permission_adbc_folder_msg = sprintf( __( 'The plugin needs to create the following directory "%1$s" to save the scan results but this was not possible automatically. Please create that directory manually and set correct permissions so it can be writable by the plugin.','advanced-database-cleaner' ), ADBC_UPLOAD_DIR_PATH_TO_ADBC );
// Once we display the msg, we delete that option from DB
delete_option( "aDBc_permission_adbc_folder_needed" );
}
}
// Verify if the user wants to edit the categorization of an option. This block test comes from edit_item_categorization.php
if ( ADBC_PLUGIN_PLAN == "pro" ) {
if ( isset( $_POST['aDBc_cancel'] ) ) {
// If the user cancels the edit, remove the temp file
if ( file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/options_manually_correction_temp.txt" ) )
unlink( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/options_manually_correction_temp.txt" );
} else if ( isset( $_POST['aDBc_correct'] ) ) {
// Get the new belongs to of items
$new_belongs_to = $_POST['new_belongs_to'];
// Get value of checkbox to see if user wants to send correction to the server
if ( isset( $_POST['aDBc_send_correction_to_server'] ) ) {
$this->aDBc_message = aDBc_edit_categorization_of_items( "options", $new_belongs_to, 1 );
} else {
$this->aDBc_message = aDBc_edit_categorization_of_items( "options", $new_belongs_to, 0 );
}
// Remove the temp file
if ( file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/options_manually_correction_temp.txt" ) )
unlink( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/options_manually_correction_temp.txt" );
}
}
// Process bulk action if any before preparing options to display
$this->process_bulk_action();
// Prepare data
aDBc_prepare_items_to_display(
$this->aDBc_options_to_display,
$this->aDBc_options_categories_info,
$this->aDBc_which_button_to_show,
array(),
array(),
$this->array_belongs_to_counts,
$this->aDBc_message,
$this->aDBc_class_message,
"options"
);
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns(){
$aDBc_belongs_to_tooltip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __('Indicates the creator of the option: either a plugin, a theme or WordPress itself. If not sure about the creator, an estimation (%) will be displayed. The higher the percentage is, the more likely that the option belongs to that creator.','advanced-database-cleaner') ." </span>
</span>";
$autoload_true_values = 'yes';
$autoload_false_values = 'no';
if(function_exists('wp_autoload_values_to_autoload')){
$autoload_true_values = 'yes, on, auto, auto-on';
$autoload_false_values = 'no, off, auto-off';
}
$autoload_message = sprintf(
__( 'Indicates whether an option is autoloaded or not. Values to autoload are: %1$s. Values to not autoload are: %2$s', 'advanced-database-cleaner' ),
$autoload_true_values,
$autoload_false_values
);
$aDBc_autoload_tooltip = "<span class='aDBc-tooltips-headers' style='position:absolute;margin-left:18px;margin-top:-1px'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . $autoload_message ." </span>
</span>";
$columns = array(
'cb' => '<input type="checkbox" />',
'option_name' => __('Option name','advanced-database-cleaner'),
'option_value' => __('Value','advanced-database-cleaner'),
'option_size' => __('Size','advanced-database-cleaner'),
'option_autoload' => __('Autoload','advanced-database-cleaner') . $aDBc_autoload_tooltip,
'site_id' => __('Site','advanced-database-cleaner'),
'option_belongs_to' => __('Belongs to','advanced-database-cleaner') . $aDBc_belongs_to_tooltip
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'option_name' => array('option_name',false),
'option_size' => array('option_size',false),
'option_autoload' => array('option_autoload',false),
'site_id' => array('site_id',false)
);
return $sortable_columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of options to display
$display_data = array_slice($this->aDBc_options_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_options_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'option_name':
return esc_html($item[$column_name]);
case 'option_size':
return aDBc_format_bytes((int) $item[$column_name]);
case 'option_value':
case 'option_autoload':
case 'site_id':
case 'option_belongs_to':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb($item) {
$value = $item['site_id'] . "|" . $item['option_name'];
return sprintf(
'<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />',
esc_attr($value)
);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$autoload_on = function_exists('wp_autoload_values_to_autoload') ? " (on)" : "";
$autoload_off = function_exists('wp_autoload_values_to_autoload') ? " (off)" : "";
$actions = array(
'scan_selected' => __( 'Scan selected options','advanced-database-cleaner' ),
'edit_categorization' => __( 'Edit categorization','advanced-database-cleaner' ),
'autoload_yes' => __( 'Set autoload to yes','advanced-database-cleaner' ) . $autoload_on,
'autoload_no' => __( 'Set autoload to no','advanced-database-cleaner' ) . $autoload_off,
'delete' => __( 'Delete','advanced-database-cleaner' )
);
if ( ADBC_PLUGIN_PLAN == "free" ) {
unset( $actions['scan_selected'] );
unset( $actions['edit_categorization'] );
}
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e( 'No options found!', 'advanced-database-cleaner' );
}
/** WP: Process bulk actions */
public function process_bulk_action() {
global $wpdb;
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'delete' ) {
// If the user wants to clean the options he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare options to delete in organized array to minimize switching from blogs
$options_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $option){
$option_info = explode("|", $option, 2);
$site_id = sanitize_html_class($option_info[0]);
$option_name = wp_unslash($option_info[1]);
if(is_numeric($site_id)){
if(empty($options_to_delete[$site_id])){
$options_to_delete[$site_id] = array();
}
array_push($options_to_delete[$site_id], $option_name);
}
}
// Delete options
foreach($options_to_delete as $site_id => $options){
switch_to_blog($site_id);
foreach($options as $option) {
delete_option($option);
}
restore_current_blog();
}
}else{
foreach($_POST['aDBc_elements_to_process'] as $option) {
$aDBc_option_info = explode("|", $option, 2);
$option_name = wp_unslash($aDBc_option_info[1]); // Because WP adds slashes to options in the POST array
delete_option($option_name);
}
}
// Update the message to show to the user
$this->aDBc_message = __('Selected options cleaned successfully!', 'advanced-database-cleaner');
}
} else if ( $action == 'autoload_yes' || $action == 'autoload_no' ) {
$autoload_value = function_exists( 'wp_autoload_values_to_autoload' )
? ( $action == 'autoload_yes' ? 'on' : 'off' )
: ( $action == 'autoload_yes' ? 'yes' : 'no' );
// If the user wants to change autoload for selected options
if ( isset( $_POST['aDBc_elements_to_process'] ) ) {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
// Prepare options to process in organized array to minimize switching from blogs
$options_to_process = array();
foreach ( $_POST['aDBc_elements_to_process'] as $option ) {
$option_info = explode( "|", $option, 2);
$site_id = sanitize_html_class( $option_info[0] );
$option_name = wp_unslash($option_info[1]); // Because WP adds slashes to options in the POST array
if ( is_numeric( $site_id ) ) {
if ( empty( $options_to_process[$site_id] ) )
$options_to_process[$site_id] = array();
array_push( $options_to_process[$site_id], $option_name );
}
}
// Change autoload
foreach ( $options_to_process as $site_id => $options ) {
switch_to_blog( $site_id );
if ( ! empty( $options ) ) {
// Build the placeholders for each option name.
$placeholders = implode( ',', array_fill( 0, count( $options ), '%s' ) );
// Construct the options table name with the blog prefix.
$table_name = $wpdb->prefix . 'options';
// Create the SQL update statement.
$sql = "UPDATE {$table_name} SET autoload = %s WHERE option_name IN ($placeholders)";
// Merge the autoload value and option names into a single array.
$args = array_merge( [ $autoload_value ], $options );
// Execute the prepared query.
$wpdb->query( $wpdb->prepare( $sql, $args ) );
}
restore_current_blog();
}
} else {
// Array to store the option names to update
$options_list = array();
// Loop through the selected options
foreach ( $_POST['aDBc_elements_to_process'] as $option ) {
$aDBc_option_info = explode( "|", $option, 2 );
$option_name = wp_unslash($aDBc_option_info[1]); // Because WP adds slashes to options in the POST array
// Collect the option names to update
$options_list[] = $option_name;
}
// Update the autoload value for the selected options
if ( ! empty( $options_list ) ) {
// Build the placeholders for each option name
$placeholders = implode( ',', array_fill( 0, count( $options_list ), "'%s'" ) );
// Create the SQL update statement
$sql = "UPDATE {$wpdb->options} SET autoload = %s WHERE option_name IN ($placeholders)";
// Merge the autoload value and option names into a single array
$args = array_merge( [ $autoload_value ], $options_list );
// Execute the prepared query
$wpdb->query( $wpdb->prepare( $sql, $args ) );
}
}
// Update the message to show to the user
$this->aDBc_message = __( 'Autoload value successfully changed!', 'advanced-database-cleaner' );
}
} else if ( $action == 'edit_categorization' ) {
// If the user wants to edit categorization of the options he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
// Create a temp file containing options names to change categorization for
$aDBc_path_items = @fopen(ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/options_manually_correction_temp.txt", "w");
if($aDBc_path_items){
foreach($_POST['aDBc_elements_to_process'] as $option){
$option_info = explode("|", $option, 2);
$option_name = wp_unslash($option_info[1]); // Because WP adds slashes to options in the POST array
fwrite($aDBc_path_items, $option_name . "\n");
}
fclose($aDBc_path_items);
}
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
// Print a message if any
if($this->aDBc_message != ""){
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
// If the folder adbc_uploads cannot be created, show a msg to users
if(!empty($this->aDBc_permission_adbc_folder_msg)){
echo '<div class="error notice is-dismissible"><p>' . $this->aDBc_permission_adbc_folder_msg . '</p></div>';
}
?>
<div class="aDBc-content-max-width">
<?php
// If options_manually_correction_temp.txt exist, this means that user want to edit categorization
if ( ADBC_PLUGIN_PLAN == "pro" && file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . '/options_manually_correction_temp.txt' ) ) {
include_once 'edit_item_categorization.php';
} else {
// If not, we print the options normally
// Print a notice/warning according to each type of options
if ( ADBC_PLUGIN_PLAN == "pro" ) {
$aDBc_iteration = get_option( "aDBc_temp_last_iteration_options" );
$aDBc_currently_scanning = get_option( "aDBc_temp_currently_scanning_options" );
if ($aDBc_iteration === false && $aDBc_currently_scanning === false) {
if($_GET['aDBc_cat'] == 'o' && $this->aDBc_options_categories_info['o']['count'] > 0){
echo '<div class="aDBc-box-warning-orphan">' . __('Options below seem to be orphan! However, please delete only those you are sure to be orphan!','advanced-database-cleaner') . '</div>';
}else if(($_GET['aDBc_cat'] == 'all' || $_GET['aDBc_cat'] == 'u') && $this->aDBc_options_categories_info['u']['count'] > 0){
$aDBc_settings = get_option('aDBc_settings');
$hide_not_categorized_msg = empty($aDBc_settings['hide_not_categorized_yet_msg']) ? "" : $aDBc_settings['hide_not_categorized_yet_msg'];
if ( $hide_not_categorized_msg != "yes" ) {
echo '<div id="aDBc-box-info" class="aDBc-box-info">'
. '<div style="width:100%">'
. __('Some of your options are not categorized yet! Please click on the button below to categorize them!','advanced-database-cleaner')
. '</div>'
. '<div><a href="#" id="aDBc-dismiss-not-categorized-yet-msg" title="' . __('Dismiss similar messages', 'advanced-database-cleaner') . '"><span class="dashicons dashicons-dismiss" style="text-decoration:none;font-size:16px;margin-top:4px"></span></a></div>'
. '</div>';
}
}
}
}
?>
<div class="aDBc-clear-both" style="margin-top:15px"></div>
<!-- Code for "run new search" button + Show loading image -->
<div style="float:left">
<?php
if ( $this->aDBc_which_button_to_show == "new_search" ) {
$aDBc_search_text = __( 'Scan options', 'advanced-database-cleaner' );
} else {
$aDBc_search_text = __( 'Continue scanning ...', 'advanced-database-cleaner' );
}
?>
<!-- Hidden input used by ajax to know which item type we are dealing with -->
<input type="hidden" id="aDBc_item_type" value="options"/>
<?php
// These hidden inputs are used by ajax to see if we should execute the scan automatically after reloading a page
$iteration = get_option("aDBc_temp_last_iteration_options");
$currently_scanning = get_option("aDBc_temp_currently_scanning_options");
?>
<input type="hidden" id="aDBc_currently_scanning" value="<?php echo $currently_scanning; ?>"/>
<input type="hidden" id="aDBc_iteration" value="<?php echo $iteration; ?>"/>
<input type="hidden" id="aDBc_count_uncategorized" value="<?php echo $this->aDBc_options_categories_info['u']['count']; ?>"/>
<input type="hidden" id="aDBc_count_all_items" value="<?php echo $this->aDBc_options_categories_info['all']['count']; ?>"/>
<?php
if ( ADBC_PLUGIN_PLAN == "pro" ) {
?>
<input id="aDBc_new_search_button" type="submit" class="aDBc-run-new-search" value="<?php echo $aDBc_search_text; ?>" name="aDBc_new_search_button" />
<?php
} else {
?>
<div class="aDBc-premium-tooltip">
<input id="aDBc_new_search_button" type="submit" class="aDBc-run-new-search" value="<?php echo $aDBc_search_text; ?>" name="aDBc_new_search_button" style="opacity:0.5" disabled />
<span style="width:390px" class="aDBc-premium-tooltiptext">
<?php _e('Please <a href="?page=advanced_db_cleaner&aDBc_tab=premium">upgrade</a> to Pro to categorize and detect orphaned options','advanced-database-cleaner') ?>
</span>
</div>
<?php
}
?>
</div>
<!-- Print numbers of items found in each category -->
<div class="aDBc-category-counts">
<?php
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
// Remove the paged parameter to start always from the first page when selecting a new category
$aDBc_new_URI = remove_query_arg( 'paged', $aDBc_new_URI );
foreach ( $this->aDBc_options_categories_info as $abreviation => $category_info ) {
$aDBc_new_URI = add_query_arg( 'aDBc_cat', $abreviation, $aDBc_new_URI );
$selected_color = $abreviation == $_GET['aDBc_cat'] ? $category_info['color'] : '#eee';
$aDBc_link_style = "color:" . $category_info['color'];
$aDBc_count = $category_info['count'];
if ( ADBC_PLUGIN_PLAN == "free" && $abreviation != "all" && $abreviation != "u" ) {
$aDBc_new_URI = "";
$aDBc_link_style = $aDBc_link_style . ";cursor:default;pointer-events:none";
$aDBc_count = "-";
}
?>
<span class="<?php echo $abreviation == $_GET['aDBc_cat'] ? 'aDBc-selected-category' : ''?>">
<span class="aDBc-premium-tooltip aDBc-category-span">
<a href="<?php echo esc_url( $aDBc_new_URI ) ?>" class="aDBc-category-counts-links" style="<?php echo $aDBc_link_style ?>">
<span><?php echo $category_info['name']; ?></span>
</a>
<div class="aDBc-category-total" style="border:1px solid <?php echo $selected_color ?>; border-bottom:3px solid <?php echo $selected_color ?>;">
<span style="color:#000"><?php echo $aDBc_count ?></span>
</div>
<?php
if ( ADBC_PLUGIN_PLAN == "free" && $abreviation != "all" && $abreviation != "u" ) {
?>
<span style="width:150px" class="aDBc-premium-tooltiptext">
<a href="https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner/" target="_blank">
<?php _e( 'Available in Pro version!', 'advanced-database-cleaner' ); ?>
</a>
</span>
<?php
}
?>
</span>
</span>
<?php
}
?>
</div>
<div class="aDBc-clear-both"></div>
<div id="aDBc-progress-container">
<span id="aDBc_collected_files" href="#" style="color:gray">
</span>
<div class="aDBc-progress-background">
<div id="aDBc-progress-bar" class="aDBc-progress-bar"></div>
</div>
<a id="aDBc_stop_scan" href="#" style="color:red">
<?php _e('Stop the scan','advanced-database-cleaner') ?>
</a>
<span id="aDBc_stopping_msg" style="display:none">
<?php _e('Stopping...','advanced-database-cleaner') ?>
</span>
</div>
<?php include_once 'header_page_filter.php'; ?>
<div class="aDBc-clear-both"></div>
<?php
// print the total size of autoloaded options
[$total_size, $health_status] = adbc_get_total_autoload_size('KB');
$style = $health_status == 'good' ? 'background:rgb(235, 252, 239);border:1px solid rgb(207, 246, 217)':'background:rgb(255, 242, 242);border:1px solid rgb(242, 217, 217)';
$dashicon = $health_status == 'good' ? 'dashicons-yes' : 'dashicons-warning';
$dashicon_style = $health_status == 'good' ? 'color:green' : 'color:orange';
$status_sentence = $health_status == 'good' ? '[' . __('Good', 'advanced-database-cleaner') . ']' : __('This size should be reduced to prevent performance issues', 'advanced-database-cleaner');
echo '<div style="' . $style . ';color:#222;margin-top:-10px;margin-bottom:15px;padding-bottom:10px;padding-left:10px;padding-right:10px;border-radius:4px">'
. '<span class="dashicons ' . $dashicon . '" style="' . $dashicon_style . ';padding-right:5px"></span>'
. __('Total size of autoloaded options: ','advanced-database-cleaner') . '<b>' . $total_size . '</b> KB. ' . $status_sentence . '</div>';
?>
<form id="aDBc_form" action="" method="post">
<?php
$this->display();
?>
</form>
<?php
}
?>
</div>
<?php
}
}
new ADBC_Options_List();
?>

View File

@@ -0,0 +1,869 @@
<?php
class ADBC_Tables_List extends WP_List_Table {
/** Holds the message to be displayed if any */
private $aDBc_message = "";
/** Holds the class for the message : updated or error. Default is updated */
private $aDBc_class_message = "updated";
/** Holds tables that will be displayed */
private $aDBc_tables_to_display = array();
/** Holds counts + info of tables categories */
private $aDBc_tables_categories_info = array();
/** Should we display "run search" or "continue search" button (after a timeout failed). Default is "run search" */
private $aDBc_which_button_to_show = "new_search";
private $aDBc_total_tables_to_optimize = 0;
private $aDBc_total_lost = 0;
private $aDBc_tables_name_to_optimize = array();
private $aDBc_total_tables_to_repair = 0;
private $aDBc_tables_name_to_repair = array();
// This array contains belongs_to info about plugins and themes
private $array_belongs_to_counts = array();
// Holds msg that will be shown if folder adbc_uploads cannot be created by the plugin (This is verified after clicking on scan button)
private $aDBc_permission_adbc_folder_msg = "";
function __construct(){
parent::__construct(array(
'singular' => __('Table', 'advanced-database-cleaner'),
'plural' => __('Tables', 'advanced-database-cleaner'),
'ajax' => false
));
$this->aDBc_prepare_and_count_tables();
$this->aDBc_print_page_content();
}
/** Prepare items */
function aDBc_prepare_and_count_tables() {
if ( ADBC_PLUGIN_PLAN == "pro" ) {
// Verify if the adbc_uploads cannot be created
$adbc_folder_permission = get_option( "aDBc_permission_adbc_folder_needed" );
if ( ! empty( $adbc_folder_permission ) ) {
$this->aDBc_permission_adbc_folder_msg = sprintf( __( 'The plugin needs to create the following directory "%1$s" to save the scan results but this was not possible automatically. Please create that directory manually and set correct permissions so it can be writable by the plugin.','advanced-database-cleaner' ), ADBC_UPLOAD_DIR_PATH_TO_ADBC );
// Once we display the msg, we delete that option from DB
delete_option( "aDBc_permission_adbc_folder_needed" );
}
}
// Test if user wants to delete a scheduled task
if(isset($_POST['aDBc_delete_schedule'])){
//Quick nonce security check!
if(!check_admin_referer('delete_optimize_schedule_nonce', 'delete_optimize_schedule_nonce'))
return; //get out if we didn't click the delete link
// We delete the schedule
$aDBc_sanitized_schedule_name = sanitize_html_class($_POST['aDBc_delete_schedule']);
wp_clear_scheduled_hook('aDBc_optimize_scheduler', array($aDBc_sanitized_schedule_name));
// We delete the item from database
$aDBc_schedules = get_option('aDBc_optimize_schedule');
unset($aDBc_schedules[$aDBc_sanitized_schedule_name]);
update_option('aDBc_optimize_schedule', $aDBc_schedules, "no");
$this->aDBc_message = __('The clean-up schedule deleted successfully!', 'advanced-database-cleaner');
}
// Verify if the user wants to edit the categorization of a table. This block test comes from edit_item_categorization.php
if ( ADBC_PLUGIN_PLAN == "pro" ) {
if ( isset( $_POST['aDBc_cancel'] ) ) {
// If the user cancels the edit, remove the temp file
if ( file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tables_manually_correction_temp.txt" ) )
unlink( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tables_manually_correction_temp.txt" );
} else if ( isset( $_POST['aDBc_correct'] ) ) {
// Get the new belongs to of items
$new_belongs_to = $_POST['new_belongs_to'];
// Get value of checkbox to see if user wants to send correction to the server
if ( isset( $_POST['aDBc_send_correction_to_server'] ) ) {
$this->aDBc_message = aDBc_edit_categorization_of_items( "tables", $new_belongs_to, 1 );
} else {
$this->aDBc_message = aDBc_edit_categorization_of_items( "tables", $new_belongs_to, 0 );
}
// Remove the temp file
if ( file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tables_manually_correction_temp.txt" ) )
unlink( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tables_manually_correction_temp.txt" );
}
}
// Process bulk action if any before preparing tables to display
$this->process_bulk_action();
// Get the names of all tables that should be optimized and count them to print it in the right side of the page
global $wpdb;
$aDBc_tables_to_optimize = $wpdb->get_results("SELECT table_name, data_free FROM information_schema.tables WHERE table_schema = '" . DB_NAME ."' and Engine <> 'InnoDB' and data_free > 0");
$this->aDBc_total_tables_to_optimize = count($aDBc_tables_to_optimize);
foreach($aDBc_tables_to_optimize as $table){
// Get table name
$table_name = "";
// This test to prevent issues in MySQL 8 where tables are not shown
// MySQL 5 uses $table->table_name while MySQL 8 uses $table->TABLE_NAME
if(property_exists($table, "table_name")){
$table_name = $table->table_name;
}else if(property_exists($table, "TABLE_NAME")){
$table_name = $table->TABLE_NAME;
}
array_push($this->aDBc_tables_name_to_optimize, $table_name);
if(property_exists($table, "data_free")){
$this->aDBc_total_lost += $table->data_free;
}
}
// Get the names of all tables that should be repaired and count them to print it in the right side of the page
$aDBc_tables_maybe_repair = $wpdb->get_results("SELECT table_name FROM information_schema.tables WHERE table_schema = '" . DB_NAME ."' and Engine IN ('CSV', 'MyISAM', 'ARCHIVE')");
foreach($aDBc_tables_maybe_repair as $table){
// Get table name
$table_name = "";
// This test to prevent issues in MySQL 8 where tables are not shown
// MySQL 5 uses $table->table_name while MySQL 8 uses $table->TABLE_NAME
if(property_exists($table, "table_name")){
$table_name = $table->table_name;
}else if(property_exists($table, "TABLE_NAME")){
$table_name = $table->TABLE_NAME;
}
$query_result = $wpdb->get_results("CHECK TABLE `" . $table_name. "`");
foreach($query_result as $row){
if($row->Msg_type == 'error'){
if(preg_match('/corrupt/i', $row->Msg_text)){
array_push($this->aDBc_tables_name_to_repair, $table_name);
}
}
}
}
$this->aDBc_total_tables_to_repair = count($this->aDBc_tables_name_to_repair);
// Prepare data
aDBc_prepare_items_to_display(
$this->aDBc_tables_to_display,
$this->aDBc_tables_categories_info,
$this->aDBc_which_button_to_show,
$this->aDBc_tables_name_to_optimize,
$this->aDBc_tables_name_to_repair,
$this->array_belongs_to_counts,
$this->aDBc_message,
$this->aDBc_class_message,
"tables"
);
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns(){
$aDBc_belongs_to_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __('Indicates the creator of the table: either a plugin, a theme or WordPress itself. If not sure about the creator, an estimation (%) will be displayed. The higher the percentage is, the more likely that the table belongs to that creator.','advanced-database-cleaner') ." </span>
</span>";
$columns = array(
'cb' => '<input type="checkbox" />',
'table_name' => __('Table name','advanced-database-cleaner'),
'table_prefix' => __('Prefix','advanced-database-cleaner'),
'table_rows' => __('Rows','advanced-database-cleaner'),
'table_size' => __('Size','advanced-database-cleaner'),
'table_lost' => __('Lost','advanced-database-cleaner'),
'site_id' => __('Site','advanced-database-cleaner'),
'table_belongs_to' => __('Belongs to','advanced-database-cleaner') . $aDBc_belongs_to_toolip
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'table_name' => array( 'table_name', false ),
'table_rows' => array( 'table_rows', false ),
'table_size' => array( 'table_size', false ),
'site_id' => array( 'site_id', false )
);
return $sortable_columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of tables to display
$display_data = array_slice($this->aDBc_tables_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_tables_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns() {
// If MU, nothing to hide, else hide Side ID column
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
return array( 'table_prefix', 'table_lost' );
} else {
return array( 'table_prefix', 'table_lost', 'site_id' );
}
}
/** WP: Column default */
function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'table_name':
$prefix_and_name = $item['table_prefix'] . $item[$column_name];
$return_name = "<span class='aDBc-bold'>" . esc_html($item['table_prefix']) . "</span>" . esc_html($item[$column_name]);
if ( $item['table_lost'] > 0 && in_array( $prefix_and_name, $this->aDBc_tables_name_to_optimize ) ) {
$lost = aDBc_get_size_from_bytes( $item['table_lost'] );
$return_name .= "<br/>";
$return_name .= "<span class='aDBc-lost-space'>" . __( 'Lost space', 'advanced-database-cleaner' ) . "</span>";
$return_name .= "<span style='font-size:12px'> : " . $lost . "</span>";
$return_name .= "<span style='color:grey'> (" . __( 'to optimize', 'advanced-database-cleaner' ) . ")</span>";
}
if ( in_array( $prefix_and_name, $this->aDBc_tables_name_to_repair ) ) {
$return_name .= "<br/>";
$return_name .= "<span class='aDBc-corrupted'>" . __( 'Corrupted!', 'advanced-database-cleaner' ) . "</span>";
$return_name .= "<span style='color:grey'> (" . __( 'to repair', 'advanced-database-cleaner' ) . ")</span>";
}
return $return_name;
break;
case 'table_size':
return aDBc_get_size_from_bytes( $item['table_size'] );
break;
case 'table_lost':
return aDBc_get_size_from_bytes( $item['table_lost'] );
break;
case 'table_prefix':
case 'table_rows':
case 'site_id':
case 'table_belongs_to':
return $item[$column_name];
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb( $item ) {
$value = $item['table_prefix'] . "|" . $item['table_name'];
return sprintf(
'<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />',
esc_attr($value)
);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'scan_selected' => __( 'Scan selected tables', 'advanced-database-cleaner' ),
'edit_categorization' => __( 'Edit categorization', 'advanced-database-cleaner' ),
'optimize' => __( 'Optimize', 'advanced-database-cleaner' ),
'repair' => __( 'Repair', 'advanced-database-cleaner' ),
'empty' => __( 'Empty rows', 'advanced-database-cleaner' ),
'delete' => __( 'Delete', 'advanced-database-cleaner' )
);
if ( ADBC_PLUGIN_PLAN == "free" ) {
unset( $actions['scan_selected'] );
unset( $actions['edit_categorization'] );
}
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e( 'No tables found!', 'advanced-database-cleaner' );
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
// Get the list of all tables names to validate selected tables
global $wpdb;
$sql_rows = "SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '" . DB_NAME . "';";
$valid_tables_names = $wpdb->get_col( $sql_rows );
if ( $action == 'delete' ) {
// Prepare an array containing names of tables deleted
$names_deleted = array();
// If the user wants to clean the tables he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
foreach($_POST['aDBc_elements_to_process'] as $table){
$table_info = explode("|", $table, 2);
$table_prefix = $table_info[0];
$table_name = wp_unslash($table_info[1]); // Because WP adds slashes to the name in the POST request
$full_table_name = $table_prefix . $table_name;
// Validate table name before deleting
if ( in_array( $full_table_name, $valid_tables_names ) ) {
if($wpdb->query("DROP TABLE `" . $full_table_name . "`")){
array_push($names_deleted, $table_name);
}
}
}
// After deleting tables, delete names also from file categorization
// xxx (should I add this as well to options & crons?)
if ( ADBC_PLUGIN_PLAN == "pro" ) {
aDBc_refresh_categorization_file_after_delete($names_deleted, 'tables');
}
// Update the message to show to the user
$this->aDBc_message = __('Selected tables cleaned successfully!', 'advanced-database-cleaner');
}
}else if($action == 'optimize'){
// If the user wants to optimize the tables he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
foreach($_POST['aDBc_elements_to_process'] as $table) {
$table_info = explode("|", $table, 2);
$table_prefix = $table_info[0];
$table_name = wp_unslash($table_info[1]); // Because WP adds slashes to the name in the POST request
$full_table_name = $table_prefix . $table_name;
// Validate table name before optimizing
if ( in_array( $full_table_name, $valid_tables_names ) ) {
$wpdb->query("OPTIMIZE TABLE `" . $full_table_name . "`");
// run analyze sql query to force updating the table statistics
$wpdb->query("ANALYZE TABLE `" . $full_table_name . "`");
}
}
// Update the message to show to the user
$this->aDBc_message = __('Selected tables optimized successfully!', 'advanced-database-cleaner');
}
}else if($action == 'empty'){
// If the user wants to empty the tables he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
foreach($_POST['aDBc_elements_to_process'] as $table) {
$table_info = explode("|", $table, 2);
$table_prefix = $table_info[0];
$table_name = wp_unslash($table_info[1]); // Because WP adds slashes to the name in the POST request
$full_table_name = $table_prefix . $table_name;
// Validate table name before emptying
if ( in_array( $full_table_name, $valid_tables_names ) ) {
$wpdb->query("TRUNCATE TABLE `" . $full_table_name . "`");
// run analyze sql query to force updating the table statistics
$wpdb->query("ANALYZE TABLE `" . $full_table_name . "`");
}
}
// Update the message to show to the user
$this->aDBc_message = __('Selected tables emptied successfully!', 'advanced-database-cleaner');
}
}else if($action == 'repair'){
// If the user wants to repair the tables he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
$cannot_repair = 0;
foreach($_POST['aDBc_elements_to_process'] as $table) {
$table_info = explode("|", $table, 2);
$table_prefix = $table_info[0];
$table_name = wp_unslash($table_info[1]); // Because WP adds slashes to the name in the POST request
$full_table_name = $table_prefix . $table_name;
// Validate table name before repairing
if ( in_array( $full_table_name, $valid_tables_names ) ) {
$query_result = $wpdb->get_results("REPAIR TABLE `" . $full_table_name . "`");
foreach($query_result as $row){
if($row->Msg_type == 'error'){
if(preg_match('/corrupt/i', $row->Msg_text)){
$cannot_repair++;
}
} else {
// run analyze sql query to force updating the table statistics
$wpdb->query("ANALYZE TABLE `" . $full_table_name . "`");
}
}
}
}
// Update the message to show to the user
if($cannot_repair == 0){
$this->aDBc_message = __('Selected tables repaired successfully!', 'advanced-database-cleaner');
}else{
$this->aDBc_class_message = "error";
$this->aDBc_message = __('Some of your tables cannot be repaired!', 'advanced-database-cleaner');
}
}
}else if($action == 'edit_categorization'){
// If the user wants to edit categorization of the tables he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
// Create a temp file containing tables names to change categorization for
$aDBc_path_items = @fopen(ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/tables_manually_correction_temp.txt", "w");
if($aDBc_path_items){
foreach($_POST['aDBc_elements_to_process'] as $table) {
$table_info = explode("|", $table, 2);
$table_prefix = $table_info[0];
$table_name = wp_unslash($table_info[1]); // Because WP adds slashes to the name in the POST request
$full_table_name = $table_prefix . $table_name;
// Validate table name before adding it to the file
if ( in_array( $full_table_name, $valid_tables_names ) ) {
fwrite($aDBc_path_items, $table_name . "\n");
}
}
fclose($aDBc_path_items);
}
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
// Print a message if any
if($this->aDBc_message != ""){
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
// If the folder adbc_uploads cannot be created, show a msg to users
if(!empty($this->aDBc_permission_adbc_folder_msg)){
echo '<div class="error notice is-dismissible"><p>' . $this->aDBc_permission_adbc_folder_msg . '</p></div>';
}
?>
<div class="aDBc-content-max-width">
<?php
// If tables_manually_correction_temp.txt exist, this means that user want to edit categorization.
if ( ADBC_PLUGIN_PLAN == "pro" && file_exists( ADBC_UPLOAD_DIR_PATH_TO_ADBC . '/tables_manually_correction_temp.txt' ) ) {
include_once 'edit_item_categorization.php';
} else {
// If not, we print the tables normally
// Print a notice/warning according to each type of tables
if ( ADBC_PLUGIN_PLAN == "pro" ) {
if($_GET['aDBc_cat'] == 'o' && $this->aDBc_tables_categories_info['o']['count'] > 0){
echo '<div class="aDBc-box-warning-orphan">' . __('Tables below seem to be orphan! However, please delete only those you are sure to be orphan!','advanced-database-cleaner') . '</div>';
}else if(($_GET['aDBc_cat'] == 'all' || $_GET['aDBc_cat'] == 'u') && $this->aDBc_tables_categories_info['u']['count'] > 0){
$aDBc_settings = get_option('aDBc_settings');
$hide_not_categorized_msg = empty($aDBc_settings['hide_not_categorized_yet_msg']) ? "" : $aDBc_settings['hide_not_categorized_yet_msg'];
if ( $hide_not_categorized_msg != "yes" ) {
echo '<div id="aDBc-box-info" class="aDBc-box-info">'
. '<div style="width:100%">'
. __('Some of your tables are not categorized yet! Please click on the button below to categorize them!','advanced-database-cleaner')
. '</div>'
. '<div><a href="#" id="aDBc-dismiss-not-categorized-yet-msg" title="' . __('Dismiss similar messages', 'advanced-database-cleaner') . '"><span class="dashicons dashicons-dismiss" style="text-decoration:none;font-size:16px;margin-top:4px"></span></a></div>'
. '</div>';
}
}
}
?>
<div class="aDBc-clear-both" style="margin-top:15px"></div>
<!-- Code for "run new search" button + Show loading image -->
<div style="float:left">
<?php
if ( $this->aDBc_which_button_to_show == "new_search" ) {
$aDBc_search_text = __( 'Scan tables', 'advanced-database-cleaner' );
} else {
$aDBc_search_text = __( 'Continue scanning ...', 'advanced-database-cleaner' );
}
?>
<!-- Hidden input used by ajax to know which item type we are dealing with -->
<input type="hidden" id="aDBc_item_type" value="tables"/>
<?php
// These hidden inputs are used by ajax to see if we should execute scanning automatically after reloading a page
$iteration = get_option("aDBc_temp_last_iteration_tables");
$currently_scanning = get_option("aDBc_temp_currently_scanning_tables");
?>
<input type="hidden" id="aDBc_currently_scanning" value="<?php echo $currently_scanning; ?>"/>
<input type="hidden" id="aDBc_iteration" value="<?php echo $iteration; ?>"/>
<input type="hidden" id="aDBc_count_uncategorized" value="<?php echo $this->aDBc_tables_categories_info['u']['count']; ?>"/>
<input type="hidden" id="aDBc_count_all_items" value="<?php echo $this->aDBc_tables_categories_info['all']['count']; ?>"/>
<?php
if ( ADBC_PLUGIN_PLAN == "pro" ) {
?>
<input id="aDBc_new_search_button" type="submit" class="aDBc-run-new-search" value="<?php echo $aDBc_search_text; ?>" name="aDBc_new_search_button" />
<?php
} else {
?>
<div class="aDBc-premium-tooltip">
<input id="aDBc_new_search_button" type="submit" class="aDBc-run-new-search" value="<?php echo $aDBc_search_text; ?>" name="aDBc_new_search_button" style="opacity:0.5" disabled />
<span style="width:390px" class="aDBc-premium-tooltiptext">
<?php _e('Please <a href="?page=advanced_db_cleaner&aDBc_tab=premium">upgrade</a> to Pro to categorize and detect orphaned tables','advanced-database-cleaner') ?>
</span>
</div>
<?php
}
?>
</div>
<!-- Print numbers of items found in each category -->
<div class="aDBc-category-counts">
<?php
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
// Remove the paged parameter to start always from the first page when selecting a new category
$aDBc_new_URI = remove_query_arg( 'paged', $aDBc_new_URI );
foreach ( $this->aDBc_tables_categories_info as $abreviation => $category_info ) {
$aDBc_new_URI = add_query_arg( 'aDBc_cat', $abreviation, $aDBc_new_URI );
$selected_color = $abreviation == $_GET['aDBc_cat'] ? $category_info['color'] : '#eee';
$aDBc_link_style = "color:" . $category_info['color'];
$aDBc_count = $category_info['count'];
if ( ADBC_PLUGIN_PLAN == "free" && $abreviation != "all" && $abreviation != "u" ) {
$aDBc_new_URI = "";
$aDBc_link_style = $aDBc_link_style . ";cursor:default;pointer-events:none";
$aDBc_count = "-";
}
?>
<span class="<?php echo $abreviation == $_GET['aDBc_cat'] ? 'aDBc-selected-category' : ''?>">
<span class="aDBc-premium-tooltip aDBc-category-span">
<a href="<?php echo esc_url( $aDBc_new_URI ); ?>" class="aDBc-category-counts-links" style="<?php echo $aDBc_link_style ?>">
<span><?php echo $category_info['name']; ?></span>
</a>
<div class="aDBc-category-total" style="border:1px solid <?php echo $selected_color ?>; border-bottom:3px solid <?php echo $selected_color ?>;">
<span style="color:#000"><?php echo $aDBc_count ?></span>
</div>
<?php
if ( ADBC_PLUGIN_PLAN == "free" && $abreviation != "all" && $abreviation != "u" ) {
?>
<span style="width:150px" class="aDBc-premium-tooltiptext">
<a href="https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner/" target="_blank">
<?php _e( 'Available in Pro version!', 'advanced-database-cleaner' ); ?>
</a>
</span>
<?php
}
?>
</span>
</span>
<?php
}
?>
</div>
<div class="aDBc-clear-both"></div>
<div id="aDBc-progress-container">
<span id="aDBc_collected_files" href="#" style="color:gray">
</span>
<div class="aDBc-progress-background">
<div id="aDBc-progress-bar" class="aDBc-progress-bar"></div>
</div>
<a id="aDBc_stop_scan" href="#" style="color:red">
<?php _e('Stop the scan','advanced-database-cleaner') ?>
</a>
<span id="aDBc_stopping_msg" style="display:none">
<?php _e('Stopping...','advanced-database-cleaner') ?>
</span>
</div>
<?php include_once 'header_page_filter.php'; ?>
<div class="aDBc-clear-both"></div>
<form id="aDBc_form" action="" method="post">
<div class="aDBc-left-content">
<?php
$this->display();
?>
</div>
</form>
<div class="aDBc-right-box">
<div class="aDBc-right-box-content" style="text-align:center">
<?php
if ( $this->aDBc_total_tables_to_optimize == 0 && $this->aDBc_total_tables_to_repair == 0 ) {
?>
<img width="58px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/db_clean.svg'?>"/>
<div class="aDBc-text-status-db"><?php _e( 'Your database is optimized!', 'advanced-database-cleaner' ); ?></div>
<?php
} else {
// Add link to numbers of tables that should be optimized/repaired
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = remove_query_arg( array( 'paged', 's', 'belongs_to' ), $aDBc_new_URI );
$aDBc_new_URI = add_query_arg( 'aDBc_cat', 'all', $aDBc_new_URI );
?>
<img width="55px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/warning.svg'?>"/>
<?php
if ( $this->aDBc_total_tables_to_optimize > 0 ) {
$aDBc_new_URI = add_query_arg( 't_type', 'optimize', $aDBc_new_URI );
?>
<div class="aDBc-text-status-db">
<b><a href="<?php echo esc_url( $aDBc_new_URI ); ?>"><?php echo $this->aDBc_total_tables_to_optimize; ?></a></b>
<?php _e( 'table(s) should be optimized!', 'advanced-database-cleaner' ); ?>
</div>
<div>
<?php
$aDBc_table_size = aDBc_get_size_from_bytes( $this->aDBc_total_lost );
echo __( 'You can save around', 'advanced-database-cleaner' ) . " : " . $aDBc_table_size;
?>
</div>
<?php
}
if ( $this->aDBc_total_tables_to_repair > 0 ) {
$aDBc_new_URI = add_query_arg( 't_type', 'repair', $aDBc_new_URI );
$to_repair_css = $this->aDBc_total_tables_to_optimize > 0 ? "aDBc-to-repair-section" : "";
?>
<div class="aDBc-text-status-db <?php echo $to_repair_css; ?>">
<b><a href="<?php echo esc_url( $aDBc_new_URI ); ?>"><?php echo $this->aDBc_total_tables_to_repair; ?></a></b>
<?php _e( 'table(s) should be repaired!', 'advanced-database-cleaner' ); ?>
</div>
<?php
}
}
?>
</div>
<div class="aDBc-right-box-content">
<div style="text-align:center">
<img width="60px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/alarm-clock.svg'?>"/>
<?php
$aDBc_schedules = get_option( 'aDBc_optimize_schedule' );
$aDBc_schedules = is_array( $aDBc_schedules ) ? $aDBc_schedules : array();
// Count schedules available
$count_schedules = count( $aDBc_schedules );
echo "<div class='aDBc-schedule-text'><b>" . $count_schedules ."</b> " .__('optimize schedule(s) set','advanced-database-cleaner') . "</div>";
?>
</div>
<?php
foreach ( $aDBc_schedules as $hook_name => $hook_params ) {
echo "<div class='aDBc-schedule-hook-box'>";
echo "<b>" . __( 'Name', 'advanced-database-cleaner' ) . "</b> : " . $hook_name;
echo "</br>";
// We convert hook name to a string because the arg maybe only a digit!
$timestamp = wp_next_scheduled( "aDBc_optimize_scheduler", array( $hook_name . '' ) );
if($timestamp){
$next_run = get_date_from_gmt(date('Y-m-d H:i:s', (int) $timestamp), 'M j, Y - H:i');
}else{
$next_run = "---";
}
echo "<b>".__('Next run','advanced-database-cleaner') . "</b> : " . $next_run . "</br>";
$operation1 = in_array('optimize', $hook_params['operations']) ? __('Optimize','advanced-database-cleaner') : '';
$operation2 = in_array('repair', $hook_params['operations']) ? __('Repair','advanced-database-cleaner') : '';
$plus = !empty($operation1) && !empty($operation2) ? " + " : "";
echo "<b>".__('Perform','advanced-database-cleaner') . "</b> : " . $operation1 . $plus . $operation2 . "</br>";
$repeat = $hook_params['repeat'];
switch($repeat){
case "once" :
$repeat = __('Once','advanced-database-cleaner');
break;
case "hourly" :
$repeat = __('Hourly','advanced-database-cleaner');
break;
case "twicedaily" :
$repeat = __('Twice a day','advanced-database-cleaner');
break;
case "daily" :
$repeat = __('Daily','advanced-database-cleaner');
break;
case "weekly" :
$repeat = __('Weekly','advanced-database-cleaner');
break;
case "monthly" :
$repeat = __('Monthly','advanced-database-cleaner');
break;
}
echo "<b>".__('Frequency','advanced-database-cleaner') . "</b> : " . $repeat . "</br>";
echo $hook_params['active'] == "1" ? "<img class='aDBc-schedule-on-off' src='". ADBC_PLUGIN_DIR_PATH . "/images/switch-on.svg" . "'/>" : "<img class='aDBc-schedule-on-off' src='". ADBC_PLUGIN_DIR_PATH . "/images/switch-off.svg" . "'/>";
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = add_query_arg('aDBc_view', 'edit_optimize_schedule', $aDBc_new_URI);
$aDBc_new_URI = add_query_arg('hook_name', $hook_name, $aDBc_new_URI);
?>
<span class="aDBc-edit-delete-schedule">
<a href="<?php echo esc_url( $aDBc_new_URI ); ?>" class="aDBc-edit-schedule-link">
<?php _e( 'Edit', 'advanced-database-cleaner' ); ?>
</a>
|
<form action="" method="post" class="aDBc-delete-schedule-link">
<input type="hidden" name="aDBc_delete_schedule" value="<?php echo $hook_name ?>" />
<input class="aDBc-submit-link" type="submit" value="<?php _e('Delete','advanced-database-cleaner') ?>" />
<?php wp_nonce_field('delete_optimize_schedule_nonce', 'delete_optimize_schedule_nonce') ?>
</form>
</span>
</div>
<?php
}
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = add_query_arg('aDBc_view', 'add_optimize_schedule', $aDBc_new_URI);
?>
<a href="<?php echo esc_url( $aDBc_new_URI ); ?>" id="aDBc_add_schedule" class="button-primary aDBc-add-new-schedule">
<?php _e('Add new schedule','advanced-database-cleaner'); ?>
</a>
</div>
</div>
<div class="aDBc-clear-both"></div>
<?php
}
?>
</div>
<?php
}
}
new ADBC_Tables_List();
?>

View File

@@ -0,0 +1,453 @@
<?php
// Style ok, code not yet
class ADBC_Clean_DB_List extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_total_elements_to_clean = 0;
/**
* Constructor
*/
function __construct(){
parent::__construct(array(
'singular' => __('Element', 'advanced-database-cleaner'), //singular name of the listed records
'plural' => __('Elements', 'advanced-database-cleaner'), //plural name of the listed records
'ajax' => false //does this table support ajax?
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean(){
// Test if user wants to delete a scheduled task
if(isset($_POST['aDBc_delete_schedule'])){
//Quick nonce security check!
if(!check_admin_referer('delete_cleanup_schedule_nonce', 'delete_cleanup_schedule_nonce'))
return; //get out if we didn't click the delete link
// We delete the schedule
$aDBc_sanitized_schedule_name = sanitize_html_class($_POST['aDBc_delete_schedule']);
wp_clear_scheduled_hook('aDBc_clean_scheduler', array($aDBc_sanitized_schedule_name));
// We delete the item from database
$aDBc_schedules = get_option('aDBc_clean_schedule');
unset($aDBc_schedules[$aDBc_sanitized_schedule_name]);
update_option('aDBc_clean_schedule', $aDBc_schedules, "no");
$this->aDBc_message = __('The clean-up schedule deleted successfully!', 'advanced-database-cleaner');
}
// Test if user wants to edit keep_last column for an item
if(isset($_POST['aDBc_keep_input'])){
// Security check - verify nonce
if(!check_admin_referer('aDBc_keep_last_nonce', 'aDBc_keep_last_nonce'))
return; //get out if nonce verification fails
$sanitized_keep_input = sanitize_html_class($_POST['aDBc_keep_input']);
$sanitized_item_keep_to_edit = sanitize_html_class($_POST['aDBc_item_keep_to_edit']);
$settings = get_option('aDBc_settings');
if(empty($settings['keep_last'])){
$keep_value = array($sanitized_item_keep_to_edit => intval($sanitized_keep_input));
}else{
$keep_value = $settings['keep_last'];
$keep_value[$sanitized_item_keep_to_edit] = intval($sanitized_keep_input);
}
$settings['keep_last'] = $keep_value;
update_option('aDBc_settings', $settings, "no");
// Test if the items belongs to a scheduled task. If so, show msg differently
$aDBc_schedules = get_option('aDBc_clean_schedule');
$aDBc_schedules = is_array($aDBc_schedules) ? $aDBc_schedules : array();
$msg_keep_last = __("The 'keep last' value saved successfully!", "advanced-database-cleaner");
foreach($aDBc_schedules as $hook_name => $hook_params){
$lits_of_elements = $hook_params['elements_to_clean'];
if(in_array($sanitized_item_keep_to_edit, $lits_of_elements)){
$msg_keep_last = __("The 'keep last' value saved successfully!", "advanced-database-cleaner") . " <span style='color:orange'>" . __("Please keep in mind that this will change the value of 'keep last' of your corresponding scheduled tasks as well!", "advanced-database-cleaner") . "</span>";
break;
}
}
$this->aDBc_message = $msg_keep_last;
}
// Process bulk action if any before preparing elements to clean
$this->process_bulk_action();
// Get all unused elements
$aDBc_unused_elements = aDBc_count_all_elements_to_clean();
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
// Get settings from DB
$settings = get_option('aDBc_settings');
$aDBc_schedules = get_option('aDBc_clean_schedule');
$aDBc_schedules = is_array($aDBc_schedules) ? $aDBc_schedules : array();
foreach($aDBc_unused_elements as $element_type => $element_info){
// Count total unused elements
$this->aDBc_total_elements_to_clean += $element_info['count'];
// If the item is scheduled, show green image, otherwise show grey one. Select also the text to show next green image
$scheduled_img_name = "grey_clock.svg";
$item_scheduled_in = "";
foreach($aDBc_schedules as $hook_name => $hook_params){
$lits_of_elements = $hook_params['elements_to_clean'];
if(in_array ($element_type, $lits_of_elements)){
$scheduled_img_name = "green_clock.svg";
$item_scheduled_in .= "<div class='aDBc-scheduled-in-row'>" . $hook_name . "</div>";
}
}
if(empty($item_scheduled_in)){
$aDBc_scheduled = "<img style='width:17px' alt='-' src='".ADBC_PLUGIN_DIR_PATH . "/images/" . $scheduled_img_name . "'/>";
}else{
$aDBc_scheduled = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' style='width:17px' alt='-' src='".ADBC_PLUGIN_DIR_PATH . "/images/" . $scheduled_img_name . "'/><span style='width:190px'>" . __('Scheduled in:','advanced-database-cleaner') . $item_scheduled_in . "</span></span>";
}
if($element_info['count'] > 0){
$color = "red";
$aDBc_count = "<font color='$color' style='font-weight:bold'>" . $element_info['count'] . "</font>";
$aDBc_new_URI = add_query_arg('aDBc_view', $element_type, $aDBc_new_URI);
$aDBc_see = "<a href='" . esc_url( $aDBc_new_URI ) . "'><img width='20px' alt='view' src='".ADBC_PLUGIN_DIR_PATH . '/images/see.svg'."'/></a>";
}else{
$aDBc_count = "<font color='#ccc' style='font-weight:bold'>0</font>";
$aDBc_see = "<img width='20px' alt='-' src='".ADBC_PLUGIN_DIR_PATH . '/images/nothing_to_see.svg'."'/>";
}
// Get "keep_last" option. This option is added in ADBC version 3.0, so test if it is not empty before using it
if(empty($settings['keep_last'])){
$keep_number = '0';
}else{
$keep_setting = $settings['keep_last'];
if(empty($keep_setting[$element_type])){
$keep_number = '0';
}else{
$keep_number = $keep_setting[$element_type];
}
}
// If the item can have keep_last, then prepare it, otherwise echo N/A
if($element_type == "revision" ||
$element_type == "auto-draft" ||
$element_type == "trash-posts" ||
$element_type == "moderated-comments" ||
$element_type == "spam-comments" ||
$element_type == "trash-comments" ||
$element_type == "pingbacks" ||
$element_type == "trackbacks"){
$save_button = __('Save','advanced-database-cleaner');
$keep_info = "<span id='aDBc_keep_label_$element_type'>" . $keep_number . " " . __('days','advanced-database-cleaner') . " | </span>" . "<a id='aDBc_edit_keep_$element_type' class='aDBc-keep-link'>" . __("Edit", "advanced-database-cleaner") . "</a>";
$keep_info .= "<form action='' method='post'>
<input type='hidden' name='aDBc_item_keep_to_edit' value='$element_type'>
<input id='aDBc_keep_input_$element_type' class='aDBc-keep-input' name='aDBc_keep_input' value='$keep_number'/>
<input id='aDBc_keep_button_$element_type' class='aDBc-keep-button button-primary' type='submit' value='$save_button' style='display:none'/>
<a id='aDBc_keep_cancel_$element_type' class='aDBc-keep-cancel-link'> " . __('Cancel','advanced-database-cleaner') . "</a>";
$keep_info .= wp_nonce_field('aDBc_keep_last_nonce', 'aDBc_keep_last_nonce', true, false);
$keep_info .= "</form>";
}else{
$keep_info = __('N/A','advanced-database-cleaner') ;
}
if($element_type == "revision"){
}else if($element_type == "revision"){
$keep_info = __('N/A','advanced-database-cleaner') ;
}
array_push($this->aDBc_elements_to_display, array(
'element_to_clean' => "<a href='". $element_info['URL_blog'] ."' target='_blank' class='aDBc-info-icon'>&nbsp;</a>" . $element_info['name'],
'count' => $aDBc_count,
'view' => $aDBc_see,
'scheduled' => $aDBc_scheduled,
'keep' => $keep_info,
'type' => $element_type
)
);
}
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns() {
$aDBc_scheduled_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __('Indicates if you have selected the item to be cleaned automatically on a scheduled task. A green image indicates that the item is scheduled while a grey image indicated the opposite.','advanced-database-cleaner') ." </span>
</span>";
$aDBc_keep_last_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __('Keep the last x days data from being displayed, and therefore from being cleaned. The plugin will always show only data older than the number of days you have specified.','advanced-database-cleaner') ." </span>
</span>";
$columns = array(
'cb' => '<input type="checkbox" />',
'element_to_clean' => __('Elements to clean','advanced-database-cleaner'),
'count' => __('Count','advanced-database-cleaner'),
'view' => __('View','advanced-database-cleaner'),
'scheduled' => __('Scheduled','advanced-database-cleaner') . $aDBc_scheduled_toolip,
'keep' => __('Keep last','advanced-database-cleaner') . $aDBc_keep_last_toolip,
'type' => 'Type'
);
return $columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = array();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice($this->aDBc_elements_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_elements_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
return array('type');
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'element_to_clean':
case 'count':
case 'view':
case 'scheduled':
case 'keep':
case 'type':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('<input id="checkbox_%s" type="checkbox" name="aDBc_elements_to_process[]" value="%s" />', $item['type'], $item['type']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'clean' => __('Clean','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('Your database is clean!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'clean' ) {
// If the user wants to clean the elements he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
// Create an array containing allowed elements_types to clean for security
$aDBc_allowed_types = array("revision", "auto-draft", "trash-posts", "moderated-comments", "spam-comments", "trash-comments", "pingbacks", "trackbacks", "orphan-postmeta", "orphan-commentmeta", "orphan-relationships", "orphan-usermeta", "orphan-termmeta", "expired-transients");
foreach($_POST['aDBc_elements_to_process'] as $element){
$aDBc_sanitized_element = sanitize_html_class($element);
if(in_array($aDBc_sanitized_element, $aDBc_allowed_types)){
aDBc_clean_all_elements_type($aDBc_sanitized_element);
}
}
// Update the message to show to the user
$this->aDBc_message = __('Selected elements successfully cleaned!', 'advanced-database-cleaner');
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
// Print a message if any
if($this->aDBc_message != ""){
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
?>
<div class="aDBc-content-max-width">
<div class="aDBc-left-content">
<form id="aDBc_form" action="" method="post">
<?php
// Print the elements to clean
$this->display();
?>
</form>
</div>
<div class="aDBc-right-box">
<div class="aDBc-right-box-content" style="text-align:center">
<?php
if ( $this->aDBc_total_elements_to_clean == 0 ) {
?>
<img width="58px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/db_clean.svg'?>"/>
<div class="aDBc-text-status-db"><?php _e( 'Your database is clean!', 'advanced-database-cleaner' ); ?></div>
<?php
} else {
?>
<img width="55px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/warning.svg'?>"/>
<div class="aDBc-text-status-db">
<b><?php echo $this->aDBc_total_elements_to_clean; ?></b> <?php _e('Element(s) can be cleaned!','advanced-database-cleaner'); ?>
</div>
<?php
}
?>
</div>
<div class="aDBc-right-box-content">
<div style="text-align:center">
<img width="60px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/alarm-clock.svg'?>"/>
<?php
$aDBc_schedules = get_option( 'aDBc_clean_schedule' );
$aDBc_schedules = is_array( $aDBc_schedules ) ? $aDBc_schedules : array();
// Count schedules available
$count_schedules = count( $aDBc_schedules );
echo "<div class='aDBc-schedule-text'><b>" . $count_schedules ."</b> " .__('Cleanup schedule(s) set','advanced-database-cleaner') . "</div>";
?>
</div>
<?php
foreach ( $aDBc_schedules as $hook_name => $hook_params ) {
echo "<div class='aDBc-schedule-hook-box'>";
echo "<b>" . __( 'Name', 'advanced-database-cleaner' ) . "</b> : " . $hook_name;
echo "</br>";
// We convert hook name to a string because the arg maybe only a digit!
$timestamp = wp_next_scheduled( "aDBc_clean_scheduler", array( $hook_name . '' ) );
if($timestamp){
$next_run = get_date_from_gmt(date('Y-m-d H:i:s', (int) $timestamp), 'M j, Y - H:i');
}else{
$next_run = "---";
}
echo "<b>".__('Next run','advanced-database-cleaner') . "</b> : " . $next_run . "</br>";
$repeat = $hook_params['repeat'];
switch($repeat){
case "once" :
$repeat = __('Once','advanced-database-cleaner');
break;
case "hourly" :
$repeat = __('Hourly','advanced-database-cleaner');
break;
case "twicedaily" :
$repeat = __('Twice a day','advanced-database-cleaner');
break;
case "daily" :
$repeat = __('Daily','advanced-database-cleaner');
break;
case "weekly" :
$repeat = __('Weekly','advanced-database-cleaner');
break;
case "monthly" :
$repeat = __('Monthly','advanced-database-cleaner');
break;
}
echo "<b>".__('Frequency','advanced-database-cleaner') . "</b> : " . $repeat . "</br>";
echo "<b>".__('Items to clean','advanced-database-cleaner') . " : </b>" . count($hook_params['elements_to_clean'])."</br>";
echo $hook_params['active'] == "1" ? "<img class='aDBc-schedule-on-off' src='". ADBC_PLUGIN_DIR_PATH . "/images/switch-on.svg" . "'/>" : "<img class='aDBc-schedule-on-off' src='". ADBC_PLUGIN_DIR_PATH . "/images/switch-off.svg" . "'/>";
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = add_query_arg('aDBc_view', 'edit_cleanup_schedule', $aDBc_new_URI);
$aDBc_new_URI = add_query_arg('hook_name', $hook_name, $aDBc_new_URI);
?>
<span class="aDBc-edit-delete-schedule">
<a href="<?php echo esc_url( $aDBc_new_URI ) ?>" class="aDBc-edit-schedule-link">
<?php _e( 'Edit', 'advanced-database-cleaner' ); ?>
</a>
|
<form action="" method="post" class="aDBc-delete-schedule-link">
<input type="hidden" name="aDBc_delete_schedule" value="<?php echo $hook_name ?>" />
<input class="aDBc-submit-link" type="submit" value="<?php _e('Delete','advanced-database-cleaner') ?>" />
<?php wp_nonce_field('delete_cleanup_schedule_nonce', 'delete_cleanup_schedule_nonce') ?>
</form>
</span>
</div>
<?php
}
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = add_query_arg('aDBc_view', 'add_cleanup_schedule', $aDBc_new_URI);
?>
<a href="<?php echo esc_url( $aDBc_new_URI ) ?>" id="aDBc_add_schedule" class="button-primary aDBc-add-new-schedule">
<?php _e('Add new schedule','advanced-database-cleaner'); ?>
</a>
</div>
</div>
<div class="aDBc-clear-both"></div>
</div>
<?php
}
}
new ADBC_Clean_DB_List();
?>

View File

@@ -0,0 +1,67 @@
<?php
if ( isset( $_GET['aDBc_view'] ) ) {
// If the user wants to perform custom cleaning
if ( $_GET['aDBc_view'] == "revision" ||
$_GET['aDBc_view'] == "auto-draft" ||
$_GET['aDBc_view'] == "trash-posts" ) {
include_once 'custom-clean-view/class_clean_revision_draft_trash.php';
new ADBC_Clean_Revision_Trash_Draft( $_GET['aDBc_view'] );
} else if ( $_GET['aDBc_view'] == "moderated-comments" ||
$_GET['aDBc_view'] == "spam-comments" ||
$_GET['aDBc_view'] == "trash-comments" ||
$_GET['aDBc_view'] == "pingbacks" ||
$_GET['aDBc_view'] == "trackbacks" ) {
include_once 'custom-clean-view/class_clean_comment.php';
new ADBC_Clean_Comment( $_GET['aDBc_view'] );
} else if ( $_GET['aDBc_view'] == "orphan-postmeta" ||
$_GET['aDBc_view'] == "orphan-commentmeta" ||
$_GET['aDBc_view'] == "orphan-usermeta" ||
$_GET['aDBc_view'] == "orphan-termmeta" ) {
include_once 'custom-clean-view/class_clean_meta_comment_post_user_term.php';
new ADBC_Clean_Meta_Comment_Post_User_Term( $_GET['aDBc_view'] );
} else if ( $_GET['aDBc_view'] == "orphan-relationships" ) {
include_once 'custom-clean-view/class_clean_relationships.php';
new ADBC_Clean_Relationship();
} else if ( $_GET['aDBc_view'] == "expired-transients" ) {
include_once 'custom-clean-view/class_clean_transient.php';
new ADBC_Clean_Transient( $_GET['aDBc_view'] );
} else if ( $_GET['aDBc_view'] == "add_cleanup_schedule" ) {
include_once 'custom-schedule-view/class_add_cleanup_schedule.php';
new ADBC_SCHEDULE_CLEANUP( $_GET['aDBc_view'] );
} else if ( $_GET['aDBc_view'] == "edit_cleanup_schedule" ) {
include_once 'custom-schedule-view/class_edit_cleanup_schedule.php';
new EDIT_SCHEDULE_CLEANUP($_GET['aDBc_view']);
}
} else {
// Else, return the general clean-up page
include_once 'class_general_cleanup.php';
}
?>

View File

@@ -0,0 +1,322 @@
<?php
/** Used to view Pending comments, Spam Comments, Trash comments, Pingbacks and Trackbacks */
class ADBC_Clean_Comment extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_type_to_clean = "";
private $aDBc_plural_title = "";
private $aDBc_column_comment_name = "";
private $aDBc_sql_get_elements = "";
private $aDBc_custom_sql_args = "";
private $aDBc_search_sql_arg = "";
private $aDBc_order_by_sql_arg = "";
private $aDBc_limit_offset_sql_arg = "";
private $aDBc_keep_last_sql_arg = "";
/**
* Constructor
*/
function __construct($element_type){
if($element_type == "moderated-comments"){
$this->aDBc_type_to_clean = "0";
$aDBc_singular = __('Pending comment', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Pending comments', 'advanced-database-cleaner');
$this->aDBc_column_comment_name = __('Comment content', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " comment_approved = '0'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('moderated-comments');
}else if($element_type == "spam-comments"){
$this->aDBc_type_to_clean = "spam";
$aDBc_singular = __('Spam comment', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Spam comments', 'advanced-database-cleaner');
$this->aDBc_column_comment_name = __('Comment content', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " comment_approved = 'spam'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('spam-comments');
}else if($element_type == "trash-comments"){
$this->aDBc_type_to_clean = "trash";
$aDBc_singular = __('Trash comment', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Trash comments', 'advanced-database-cleaner');
$this->aDBc_column_comment_name = __('Comment content', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " comment_approved = 'trash'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('trash-comments');
}else if($element_type == "pingbacks"){
$this->aDBc_type_to_clean = "pingback";
$aDBc_singular = __('Pingback', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Pingbacks', 'advanced-database-cleaner');
$this->aDBc_column_comment_name = __('Pingback content', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " comment_type = 'pingback'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('pingbacks');
}else if($element_type == "trackbacks"){
$this->aDBc_type_to_clean = "trackback";
$aDBc_singular = __('Trackback', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Trackbacks', 'advanced-database-cleaner');
$this->aDBc_column_comment_name = __('Trackback content', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " comment_type = 'trackback'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('trackbacks');
}
// Prepare additional sql args if any: per page, LIMIT, OFFSET, etc.
if ( ADBC_PLUGIN_PLAN == "pro" ) {
$this->aDBc_search_sql_arg = aDBc_get_search_sql_arg( "comment_author", "comment_content" );
}
$this->aDBc_order_by_sql_arg = aDBc_get_order_by_sql_arg( "comment_ID" );
$this->aDBc_limit_offset_sql_arg = aDBc_get_limit_offset_sql_args();
parent::__construct(array(
'singular' => $aDBc_singular,
'plural' => $this->aDBc_plural_title,
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean(){
global $wpdb;
// Process bulk action if any before preparing elements to clean
$this->process_bulk_action();
// Get all elements to clean
if(function_exists('is_multisite') && is_multisite()){
$blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach($blogs_ids as $blog_id){
switch_to_blog($blog_id);
$this->aDBc_fill_array_elements_to_clean($blog_id);
restore_current_blog();
}
}else{
$this->aDBc_fill_array_elements_to_clean("1");
}
// Call WP prepare_items function
$this->prepare_items();
}
/** Fill array elements to display */
function aDBc_fill_array_elements_to_clean($blog_id){
global $wpdb;
// Get all elements query
$this->aDBc_sql_get_elements = "SELECT comment_ID, comment_author, comment_content, comment_date FROM $wpdb->comments WHERE"
. $this->aDBc_custom_sql_args
. $this->aDBc_keep_last_sql_arg
. $this->aDBc_search_sql_arg
. $this->aDBc_order_by_sql_arg
//. $this->aDBc_limit_offset_sql_arg
;
$aDBc_all_elements = $wpdb->get_results($this->aDBc_sql_get_elements);
foreach($aDBc_all_elements as $aDBc_element){
// Get author name
$author_name = aDBc_create_tooltip_for_long_string($aDBc_element->comment_author, 16);
// Get comment content
$comment_content = aDBc_create_tooltip_for_long_string($aDBc_element->comment_content, 60);
array_push($this->aDBc_elements_to_display, array(
'comment_id' => $aDBc_element->comment_ID,
'comment_author' => $author_name,
'comment_content' => $comment_content,
'comment_date' => $aDBc_element->comment_date,
'site_id' => $blog_id
)
);
}
}
/** Prepare keep_last element if any **/
function aDBc_get_keep_last_sql_arg($element_type){
$settings = get_option('aDBc_settings');
if(!empty($settings['keep_last'])){
$keep_setting = $settings['keep_last'];
if(!empty($keep_setting[$element_type]))
return " and comment_date < NOW() - INTERVAL " . $keep_setting[$element_type] . " DAY";
}
return "";
}
/** WP: Get columns */
function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'comment_id' => __('ID','advanced-database-cleaner'),
'comment_author' => __('Author','advanced-database-cleaner'),
'comment_content' => $this->aDBc_column_comment_name,
'comment_date' => __('Date','advanced-database-cleaner'),
'site_id' => __('Site id','advanced-database-cleaner')
);
return $columns;
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'comment_id':
case 'comment_author':
case 'comment_content':
case 'comment_date':
case 'site_id':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
function get_sortable_columns() {
$sortable_columns = array(
'comment_id' => array('comment_ID',false),
'comment_author' => array('comment_author',false)
);
// Since order_by works directly with sql request, we will not order_by in mutlisite since it will not work
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return $sortable_columns;
}
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice($this->aDBc_elements_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_elements_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />', $item['site_id']."|".$item['comment_id']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'clean' => __('Clean','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('No elements found!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'clean' ) {
// If the user wants to clean the elements he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare elements to delete
$elements_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $element){
$element_info = explode("|", $element);
$sanitized_site_id = sanitize_html_class($element_info[0]);
$sanitized_item_id = sanitize_html_class($element_info[1]);
// For security, we only proceed if both parts are clean and are numbers
if(is_numeric($sanitized_site_id) && is_numeric($sanitized_item_id)){
if(empty($elements_to_delete[$sanitized_site_id])){
$elements_to_delete[$sanitized_site_id] = array();
}
array_push($elements_to_delete[$sanitized_site_id], $sanitized_item_id);
}
}
// Delete elements
foreach($elements_to_delete as $site_id => $elements_ids){
switch_to_blog($site_id);
global $wpdb;
foreach($elements_ids as $id_comment) {
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_ID = $id_comment");
}
restore_current_blog();
}
}else{
global $wpdb;
foreach($_POST['aDBc_elements_to_process'] as $element) {
$element_info = explode("|", $element);
$sanitized_id = sanitize_html_class($element_info[1]);
if(is_numeric($sanitized_id)){
$wpdb->query("DELETE FROM $wpdb->comments WHERE comment_ID = " . $sanitized_id);
}
}
}
// Update the message to show to the user
$this->aDBc_message = __("Selected '$this->aDBc_plural_title' successfully cleaned!", 'advanced-database-cleaner');
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
include_once 'page_custom_clean.php';
}
}
?>

View File

@@ -0,0 +1,311 @@
<?php
/** View comment meta and post meta */
class ADBC_Clean_Meta_Comment_Post_User_Term extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_type_to_clean = "";
private $aDBc_plural_title = "";
private $aDBc_column_meta_name = "";
private $aDBc_sql_get_elements = "";
private $aDBc_custom_sql_args = "";
private $aDBc_search_sql_arg = "";
private $aDBc_order_by_sql_arg = "";
private $aDBc_limit_offset_sql_arg = "";
private $aDBc_delete_from_table = "";
private $aDBc_metaid_or_umetaid = "";
/**
* Constructor
*/
function __construct($element_type){
if($element_type == "orphan-commentmeta"){
$this->aDBc_type_to_clean = "orphan-commentmeta";
$aDBc_singular = __('Orphaned comment meta', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Orphaned comments meta', 'advanced-database-cleaner');
$this->aDBc_column_meta_name = __('Comment meta key', 'advanced-database-cleaner');
$this->aDBc_delete_from_table = "commentmeta";
$this->aDBc_metaid_or_umetaid = "meta_id";
}else if($element_type == "orphan-postmeta"){
$this->aDBc_type_to_clean = "orphan-postmeta";
$aDBc_singular = __('Orphaned post meta', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Orphaned posts meta', 'advanced-database-cleaner');
$this->aDBc_column_meta_name = __('Post meta key', 'advanced-database-cleaner');
$this->aDBc_delete_from_table = "postmeta";
$this->aDBc_metaid_or_umetaid = "meta_id";
}else if($element_type == "orphan-usermeta"){
$this->aDBc_type_to_clean = "orphan-usermeta";
$aDBc_singular = __('Orphaned User Meta', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Orphaned Users Meta', 'advanced-database-cleaner');
$this->aDBc_column_meta_name = __('User meta key', 'advanced-database-cleaner');
$this->aDBc_delete_from_table = "usermeta";
$this->aDBc_metaid_or_umetaid = "umeta_id";
}else if($element_type == "orphan-termmeta"){
$this->aDBc_type_to_clean = "orphan-termmeta";
$aDBc_singular = __('Orphaned Term Meta', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Orphaned Terms Meta', 'advanced-database-cleaner');
$this->aDBc_column_meta_name = __('Term meta key', 'advanced-database-cleaner');
$this->aDBc_delete_from_table = "termmeta";
$this->aDBc_metaid_or_umetaid = "meta_id";
}
// Prepare additional sql args if any: per page, LIMIT, OFFSET, etc.
if ( ADBC_PLUGIN_PLAN == "pro" ) {
$this->aDBc_search_sql_arg = aDBc_get_search_sql_arg( "meta_key", "meta_value" );
}
$this->aDBc_order_by_sql_arg = aDBc_get_order_by_sql_arg( $this->aDBc_metaid_or_umetaid );
$this->aDBc_limit_offset_sql_arg = aDBc_get_limit_offset_sql_args();
parent::__construct(array(
'singular' => $aDBc_singular,
'plural' => $this->aDBc_plural_title,
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean(){
global $wpdb;
// Process bulk action if any before preparing elements to clean
$this->process_bulk_action();
// Get all elements (for the table usermeta, only one table exists for MU, do not switch over blogs for it)
if(function_exists('is_multisite') && is_multisite() && $this->aDBc_type_to_clean != "orphan-usermeta"){
$blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach($blogs_ids as $blog_id){
switch_to_blog($blog_id);
$this->aDBc_fill_array_elements_to_clean($blog_id);
restore_current_blog();
}
}else{
$this->aDBc_fill_array_elements_to_clean("1");
}
// Call WP prepare_items function
$this->prepare_items();
}
/** Fill array elements to display */
function aDBc_fill_array_elements_to_clean($blog_id){
global $wpdb;
if($this->aDBc_type_to_clean == "orphan-commentmeta"){
$this->aDBc_custom_sql_args = "SELECT meta_id, meta_key, meta_value FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
}else if($this->aDBc_type_to_clean == "orphan-postmeta"){
$this->aDBc_custom_sql_args = "SELECT meta_id, meta_key, meta_value FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
}else if($this->aDBc_type_to_clean == "orphan-usermeta"){
$this->aDBc_custom_sql_args = "SELECT umeta_id, meta_key, meta_value FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)";
}else if($this->aDBc_type_to_clean == "orphan-termmeta"){
$this->aDBc_custom_sql_args = "SELECT meta_id, meta_key, meta_value FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)";
}
// Get all elements query
$this->aDBc_sql_get_elements = $this->aDBc_custom_sql_args
. $this->aDBc_search_sql_arg
. $this->aDBc_order_by_sql_arg
//. $this->aDBc_limit_offset_sql_arg
;
$aDBc_all_elements = $wpdb->get_results($this->aDBc_sql_get_elements);
foreach($aDBc_all_elements as $aDBc_element){
// Get meta key
$meta_key = aDBc_create_tooltip_for_long_string($aDBc_element->meta_key, 28);
// Get meta value
$meta_value = aDBc_create_tooltip_for_long_string($aDBc_element->meta_value, 95);
array_push($this->aDBc_elements_to_display, array(
'meta_id' => ($this->aDBc_metaid_or_umetaid == 'meta_id' ? $aDBc_element->meta_id : $aDBc_element->umeta_id),
'meta_key' => $meta_key,
'meta_value' => $meta_value,
'site_id' => $blog_id
)
);
}
}
/** WP: Get columns */
function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'meta_id' => __('ID','advanced-database-cleaner'),
'meta_key' => $this->aDBc_column_meta_name,
'meta_value' => __('Meta value','advanced-database-cleaner'),
'site_id' => __('Site id','advanced-database-cleaner')
);
return $columns;
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'meta_id':
case 'meta_key':
case 'meta_value':
case 'site_id':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
function get_sortable_columns() {
$sortable_columns = array(
'meta_id' => array($this->aDBc_metaid_or_umetaid, false),
'meta_key' => array('meta_key', false)
);
// Since order_by works directly with sql request, we will not order_by in mutlisite since it will not work
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return $sortable_columns;
}
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice($this->aDBc_elements_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_elements_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />', $item['site_id']."|".$item['meta_id']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'clean' => __('Clean','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('No elements found!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'clean' ) {
// If the user wants to clean the elements he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare meta to delete
$meta_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $meta){
$meta_info = explode("|", $meta);
$sanitized_site_id = sanitize_html_class($meta_info[0]);
$sanitized_item_id = sanitize_html_class($meta_info[1]);
// For security, we only proceed if both parts are clean and are numbers
if(is_numeric($sanitized_site_id) && is_numeric($sanitized_item_id)){
if(empty($meta_to_delete[$sanitized_site_id])){
$meta_to_delete[$sanitized_site_id] = array();
}
array_push($meta_to_delete[$sanitized_site_id], $sanitized_item_id);
}
}
// Delete meta
foreach($meta_to_delete as $site_id => $meta_ids){
switch_to_blog($site_id);
global $wpdb;
foreach($meta_ids as $id_meta) {
$table_name = $wpdb->prefix . $this->aDBc_delete_from_table;
$wpdb->query("DELETE FROM $table_name WHERE $this->aDBc_metaid_or_umetaid = $id_meta");
}
restore_current_blog();
}
}else{
global $wpdb;
$table_name = $wpdb->prefix . $this->aDBc_delete_from_table;
foreach($_POST['aDBc_elements_to_process'] as $meta) {
$meta_info = explode("|", $meta);
$sanitized_id = sanitize_html_class($meta_info[1]);
if(is_numeric($sanitized_id)){
$wpdb->query("DELETE FROM $table_name WHERE $this->aDBc_metaid_or_umetaid = " . $sanitized_id);
}
}
}
// Update the message to show to the user
$this->aDBc_message = __("Selected '$this->aDBc_plural_title' successfully cleaned!", "advanced-database-cleaner");
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
include_once 'page_custom_clean.php';
}
}
?>

View File

@@ -0,0 +1,257 @@
<?php
class ADBC_Clean_Relationship extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_type_to_clean = "";
private $aDBc_plural_title = "";
private $aDBc_column_meta_name = "";
private $aDBc_sql_get_elements = "";
private $aDBc_search_sql_arg = "";
private $aDBc_order_by_sql_arg = "";
private $aDBc_limit_offset_sql_arg = "";
private $aDBc_delete_from_table = "";
/**
* Constructor
*/
function __construct(){
$this->aDBc_plural_title = __('Orphaned Relationships', 'advanced-database-cleaner');
// Prepare additional sql args if any: per page, LIMIT, OFFSET, etc.
if ( ADBC_PLUGIN_PLAN == "pro" ) {
$this->aDBc_search_sql_arg = aDBc_get_search_sql_arg( "term_taxonomy_id", "term_order" );
}
$this->aDBc_order_by_sql_arg = aDBc_get_order_by_sql_arg( "object_id" );
$this->aDBc_limit_offset_sql_arg = aDBc_get_limit_offset_sql_args();
parent::__construct(array(
'singular' => __( 'Orphaned Relationship', 'advanced-database-cleaner' ),
'plural' => $this->aDBc_plural_title,
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean(){
global $wpdb;
// Process bulk action if any before preparing elements to clean
$this->process_bulk_action();
// Get all elements to clean
if(function_exists('is_multisite') && is_multisite()){
$blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach($blogs_ids as $blog_id){
switch_to_blog($blog_id);
$this->aDBc_fill_array_elements_to_clean($blog_id);
restore_current_blog();
}
}else{
$this->aDBc_fill_array_elements_to_clean("1");
}
// Call WP prepare_items function
$this->prepare_items();
}
/** Fill array elements to display */
function aDBc_fill_array_elements_to_clean($blog_id){
global $wpdb;
// Get all elements query
$this->aDBc_sql_get_elements = "SELECT * from $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)"
. $this->aDBc_search_sql_arg
. $this->aDBc_order_by_sql_arg
//. $this->aDBc_limit_offset_sql_arg
;
$aDBc_all_elements = $wpdb->get_results($this->aDBc_sql_get_elements);
foreach($aDBc_all_elements as $aDBc_element){
array_push($this->aDBc_elements_to_display, array(
'object_id' => $aDBc_element->object_id,
'term_taxonomy_id' => $aDBc_element->term_taxonomy_id,
'term_order' => $aDBc_element->term_order,
'site_id' => $blog_id
)
);
}
}
/** WP: Get columns */
function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'object_id' => __('ID','advanced-database-cleaner'),
'term_taxonomy_id' => __('Term taxonomy id','advanced-database-cleaner'),
'term_order' => __('Term order','advanced-database-cleaner'),
'site_id' => __('Site id','advanced-database-cleaner')
);
return $columns;
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'object_id':
case 'term_taxonomy_id':
case 'term_order':
case 'site_id':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
function get_sortable_columns() {
$sortable_columns = array(
'object_id' => array('object_id',false),
'term_taxonomy_id' => array('term_taxonomy_id',false),
'term_order' => array('term_order',false)
);
// Since order_by works directly with sql request, we will not order_by in mutlisite since it will not work
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return $sortable_columns;
}
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice($this->aDBc_elements_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_elements_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />', $item['site_id']."|".$item['object_id']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'clean' => __('Clean','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('No elements found!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'clean' ) {
// If the user wants to clean the elements he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare relationships to delete
$relationships_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $relationship){
$relationship_info = explode("|", $relationship);
$sanitized_site_id = sanitize_html_class($relationship_info[0]);
$sanitized_item_id = sanitize_html_class($relationship_info[1]);
// For security, we only proceed if both parts are clean and are numbers
if(is_numeric($sanitized_site_id) && is_numeric($sanitized_item_id)){
if(empty($relationships_to_delete[$sanitized_site_id])){
$relationships_to_delete[$sanitized_site_id] = array();
}
array_push($relationships_to_delete[$sanitized_site_id], $sanitized_item_id);
}
}
// Delete relationships
foreach($relationships_to_delete as $site_id => $object_ids){
switch_to_blog($site_id);
global $wpdb;
foreach($object_ids as $object_id) {
$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id = $object_id");
}
restore_current_blog();
}
}else{
global $wpdb;
foreach($_POST['aDBc_elements_to_process'] as $relationship){
$relationship_info = explode("|", $relationship);
$sanitized_id = sanitize_html_class($relationship_info[1]);
if(is_numeric($sanitized_id)){
$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id = " . $sanitized_id);
}
}
}
// Update the message to show to the user
$this->aDBc_message = __("Selected 'Orphaned relationships' successfully cleaned!", "advanced-database-cleaner");
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
include_once 'page_custom_clean.php';
}
}
?>

View File

@@ -0,0 +1,303 @@
<?php
/** Used to view revisions, auto-drafts and trash posts */
class ADBC_Clean_Revision_Trash_Draft extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_type_to_clean = "";
private $aDBc_plural_title = "";
private $aDBc_column_post_name_title = "";
private $aDBc_sql_get_elements = "";
private $aDBc_custom_sql_args = "";
private $aDBc_search_sql_arg = "";
private $aDBc_order_by_sql_arg = "";
private $aDBc_limit_offset_sql_arg = "";
private $aDBc_keep_last_sql_arg = "";
/**
* Constructor
*/
function __construct($element_type){
if($element_type == "auto-draft"){
$this->aDBc_type_to_clean = "auto-draft";
$aDBc_singular = __('Auto draft', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Auto drafts', 'advanced-database-cleaner');
$this->aDBc_column_post_name_title = __('Auto draft title', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " post_status = 'auto-draft'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('auto-draft');
}else if($element_type == "trash-posts"){
$this->aDBc_type_to_clean = "trash";
$aDBc_singular = __('Trash post', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Trash posts', 'advanced-database-cleaner');
$this->aDBc_column_post_name_title = __('Trash post title', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " post_status = 'trash'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('trash-posts');
}else if($element_type == "revision"){
$this->aDBc_type_to_clean = "revision";
$aDBc_singular = __('Revision', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Revisions', 'advanced-database-cleaner');
$this->aDBc_column_post_name_title = __('Revision title', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " post_type = 'revision'";
$this->aDBc_keep_last_sql_arg = $this->aDBc_get_keep_last_sql_arg('revision');
}
// Prepare additional sql args if any: per page, LIMIT, OFFSET, etc.
if ( ADBC_PLUGIN_PLAN == "pro" ) {
$this->aDBc_search_sql_arg = aDBc_get_search_sql_arg( "post_title", "post_content" );
}
$this->aDBc_order_by_sql_arg = aDBc_get_order_by_sql_arg( "ID" );
$this->aDBc_limit_offset_sql_arg = aDBc_get_limit_offset_sql_args();
parent::__construct(array(
'singular' => $aDBc_singular,
'plural' => $this->aDBc_plural_title,
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean(){
global $wpdb;
// Process bulk action if any before preparing elements to clean
$this->process_bulk_action();
// Get all elements to clean
if(function_exists('is_multisite') && is_multisite()){
$blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach($blogs_ids as $blog_id){
switch_to_blog($blog_id);
$this->aDBc_fill_array_elements_to_clean($blog_id);
restore_current_blog();
}
}else{
$this->aDBc_fill_array_elements_to_clean("1");
}
// Call WP prepare_items function
$this->prepare_items();
}
/** Fill array elements to display */
function aDBc_fill_array_elements_to_clean($blog_id){
global $wpdb;
// Get all elements query
$this->aDBc_sql_get_elements = "SELECT ID, post_title, post_date, post_content FROM $wpdb->posts WHERE"
. $this->aDBc_custom_sql_args
. $this->aDBc_keep_last_sql_arg
. $this->aDBc_search_sql_arg
. $this->aDBc_order_by_sql_arg
//. $this->aDBc_limit_offset_sql_arg
;
$aDBc_all_elements = $wpdb->get_results($this->aDBc_sql_get_elements);
foreach($aDBc_all_elements as $aDBc_element){
// Susbstr post title
$post_title = aDBc_create_tooltip_for_long_string($aDBc_element->post_title, 35);
// Get content
$post_content = aDBc_create_tooltip_for_long_string($aDBc_element->post_content, 35);
array_push($this->aDBc_elements_to_display, array(
'post_id' => $aDBc_element->ID,
'post_title' => $post_title,
'post_content' => $post_content, //xxx add if empty, replace by 'Empty' to prevent responsive issues in WP table
'post_date' => $aDBc_element->post_date,
'site_id' => $blog_id
)
);
}
}
/** Prepare keep_last element if any **/
function aDBc_get_keep_last_sql_arg($element_type){
$settings = get_option('aDBc_settings');
if(!empty($settings['keep_last'])){
$keep_setting = $settings['keep_last'];
if(!empty($keep_setting[$element_type]))
return " and post_modified < NOW() - INTERVAL " . $keep_setting[$element_type] . " DAY";
}
return "";
}
/** WP: Get columns */
function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'post_id' => __('ID','advanced-database-cleaner'),
'post_title' => $this->aDBc_column_post_name_title,
'post_content' => __('Content','advanced-database-cleaner'),
'post_date' => __('Date','advanced-database-cleaner'),
'site_id' => __('Site id','advanced-database-cleaner')
);
return $columns;
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'post_id':
case 'post_title':
case 'post_content':
case 'post_date':
case 'site_id':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
function get_sortable_columns() {
$sortable_columns = array(
'post_id' => array('ID',false), //true means it's already sorted
'post_title' => array('post_title',false),
'post_date' => array('post_date',false)
);
// Since order_by works directly with sql request, we will not order_by in mutlisite since it will not work
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return $sortable_columns;
}
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice($this->aDBc_elements_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_elements_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />', $item['site_id']."|".$item['post_id']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'clean' => __('Clean','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('No elements found!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'clean' ) {
// If the user wants to clean the elements he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare posts to delete
$posts_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $post){
$post_info = explode("|", $post);
$sanitized_site_id = sanitize_html_class($post_info[0]);
$sanitized_item_id = sanitize_html_class($post_info[1]);
// For security, we only proceed if both parts are clean and are numbers
if(is_numeric($sanitized_site_id) && is_numeric($sanitized_item_id)){
if(empty($posts_to_delete[$sanitized_site_id])){
$posts_to_delete[$sanitized_site_id] = array();
}
array_push($posts_to_delete[$sanitized_site_id], $sanitized_item_id);
}
}
// Delete posts
foreach($posts_to_delete as $site_id => $posts_ids){
switch_to_blog($site_id);
global $wpdb;
foreach($posts_ids as $id_post) {
$wpdb->query("DELETE FROM $wpdb->posts WHERE ID = $id_post");
}
restore_current_blog();
}
}else{
global $wpdb;
foreach($_POST['aDBc_elements_to_process'] as $post){
$post_info = explode("|", $post);
$sanitized_id = sanitize_html_class($post_info[1]);
if(is_numeric($sanitized_id)){
$wpdb->query("DELETE FROM $wpdb->posts WHERE ID = " . $sanitized_id);
}
}
}
// Update the message to show to the user
$this->aDBc_message = __("Selected '$this->aDBc_plural_title' successfully cleaned!", "advanced-database-cleaner");
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
include_once 'page_custom_clean.php';
}
}
?>

View File

@@ -0,0 +1,324 @@
<?php
class ADBC_Clean_Transient extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_type_to_clean = "";
private $aDBc_plural_title = "";
private $aDBc_sql_get_transients = "";
private $aDBc_custom_sql_args = "";
private $aDBc_search_sql_arg = "";
private $aDBc_order_by_sql_arg = "";
private $aDBc_limit_offset_sql_arg = "";
/**
* Constructor
*/
function __construct($element_type){
if($element_type == "expired-transients"){
$this->aDBc_type_to_clean = "expired-transients";
$aDBc_singular = __('Expired transient', 'advanced-database-cleaner');
$this->aDBc_plural_title = __('Expired transients', 'advanced-database-cleaner');
$this->aDBc_custom_sql_args = " AND b.option_value < UNIX_TIMESTAMP()";
}
// Prepare additional sql args if any: per page, LIMIT, OFFSET, etc.
if ( ADBC_PLUGIN_PLAN == "pro" ) {
$this->aDBc_search_sql_arg = aDBc_get_search_sql_arg( "a.option_name", "a.option_value" );
}
$this->aDBc_order_by_sql_arg = aDBc_get_order_by_sql_arg( "a.option_id" );
$this->aDBc_limit_offset_sql_arg = aDBc_get_limit_offset_sql_args();
parent::__construct(array(
'singular' => $aDBc_singular,
'plural' => $this->aDBc_plural_title,
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean(){
global $wpdb;
// Process bulk action if any before preparing elements to clean
$this->process_bulk_action();
// Get all elements to clean
if(function_exists('is_multisite') && is_multisite()){
$blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach($blogs_ids as $blog_id){
switch_to_blog($blog_id);
$this->aDBc_fill_array_elements_to_clean($blog_id);
restore_current_blog();
}
}else{
$this->aDBc_fill_array_elements_to_clean("1");
}
// Call WP prepare_items function
$this->prepare_items();
}
/** Fill array elements to display */
function aDBc_fill_array_elements_to_clean($blog_id){
global $wpdb;
// Get all dashboard transients
$this->aDBc_sql_get_transients = "SELECT a.option_id, a.option_name, a.option_value as option_content, a.autoload, b.option_value as option_timeout FROM $wpdb->options a LEFT JOIN $wpdb->options b ON b.option_name =
CONCAT(
CASE WHEN a.option_name LIKE '\_site\_transient\_%'
THEN '_site_transient_timeout_'
ELSE '_transient_timeout_'
END
,
SUBSTRING(a.option_name, CHAR_LENGTH(
CASE WHEN a.option_name LIKE '\_site\_transient\_%'
THEN '_site_transient_'
ELSE '_transient_'
END
) + 1)
)
WHERE (a.option_name LIKE '\_transient\_%' OR a.option_name LIKE '\_site\_transient\_%') AND a.option_name NOT LIKE '%\_transient\_timeout\_%'"
. $this->aDBc_custom_sql_args
. $this->aDBc_search_sql_arg
. $this->aDBc_order_by_sql_arg
//. $this->aDBc_limit_offset_sql_arg
;
$time_now = time();
$aDBc_all_transient_feed = $wpdb->get_results($this->aDBc_sql_get_transients);
foreach($aDBc_all_transient_feed as $aDBc_transient){
// Get timeout of transient
switch ( $this->aDBc_type_to_clean ) {
case "expired-transients" :
$transient_timeout = __( 'Expired', 'advanced-database-cleaner' );
break;
}
// Get transient content
$transient_content = maybe_unserialize($aDBc_transient->option_content);
if(is_array($transient_content)){
$transient_content = "<i>Array</i>";
}elseif(gettype($transient_content) == 'object'){
$transient_content = "<i>Object</i>";
}else{
$transient_content = aDBc_create_tooltip_for_long_string($aDBc_transient->option_content, 35);
}
// Susbst transient name
$transient_name = aDBc_create_tooltip_for_long_string($aDBc_transient->option_name, 35);
array_push($this->aDBc_elements_to_display, array(
'transient_id' => $aDBc_transient->option_id,
'transient_name' => $transient_name,
'transient_content' => $transient_content,
'transient_timeout' => $transient_timeout,
'transient_autoload' => $aDBc_transient->autoload,
'site_id' => $blog_id
)
);
}
}
/** WP: Get columns */
function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'transient_id' => __('ID','advanced-database-cleaner'),
'transient_name' => __('Transient name','advanced-database-cleaner'),
'transient_content' => __('Value','advanced-database-cleaner'),
'transient_timeout' => __('Expires In','advanced-database-cleaner'),
'transient_autoload' => __('Autoload','advanced-database-cleaner'),
'site_id' => __('Site id','advanced-database-cleaner')
);
return $columns;
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'transient_id':
case 'transient_name':
case 'transient_content':
case 'transient_timeout':
case 'transient_autoload':
case 'site_id':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
function get_sortable_columns() {
$sortable_columns = array(
'transient_id' => array('a.option_id', false), //true means it's already sorted
'transient_name' => array('a.option_name', false)
);
// Since order_by works directly with sql request, we will not order_by in mutlisite since it will not work
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return $sortable_columns;
}
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
if(!empty($_GET['per_page'])){
$per_page = absint($_GET['per_page']);
}
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice($this->aDBc_elements_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_elements_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('<input type="checkbox" name="aDBc_elements_to_process[]" value="%s" />', $item['site_id']."|".$item['transient_id']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'clean' => __('Clean','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
_e('No elements found!','advanced-database-cleaner');
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// Detect when a bulk action is being triggered.
$action = $this->current_action();
if ( ! $action )
return;
// security check!
check_admin_referer( 'bulk-' . $this->_args['plural'] );
// Check role
if ( ! current_user_can( 'administrator' ) )
wp_die( 'Security check failed!' );
if ( $action == 'clean' ) {
// If the user wants to clean the elements he/she selected
if(isset($_POST['aDBc_elements_to_process'])){
if(function_exists('is_multisite') && is_multisite()){
// Prepare feeds to delete
$feeds_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $aDBc_feed){
$feed_info = explode("|", $aDBc_feed);
$sanitized_site_id = sanitize_html_class($feed_info[0]);
$sanitized_item_id = sanitize_html_class($feed_info[1]);
// For security, we only proceed if both parts are clean and are numbers
if(is_numeric($sanitized_site_id) && is_numeric($sanitized_item_id)){
if(empty($feeds_to_delete[$sanitized_site_id])){
$feeds_to_delete[$sanitized_site_id] = array();
}
array_push($feeds_to_delete[$sanitized_site_id], $sanitized_item_id);
}
}
// Delete feeds
foreach($feeds_to_delete as $site_id => $feed_ids){
switch_to_blog($site_id);
global $wpdb;
$transients_to_delete = $wpdb->get_results("select option_name, option_id from $wpdb->options WHERE option_id IN (" . implode(',',$feed_ids) . ")");
foreach($transients_to_delete as $transient){
$site_wide = (strpos($transient->option_name, '_site_transient') !== false);
$name = str_replace($site_wide ? '_site_transient_' : '_transient_', '', $transient->option_name);
if(false !== $site_wide){
// We used a query directly here instead of delete_site_transient() because in MU, WP tries to delete the transient from sitemeta table, however, in our case, all results above are from options table. So, we need to delete them from options table
$name_timeout = '_site_transient_timeout_' . $name;
$wpdb->query("DELETE FROM $wpdb->options WHERE option_id = {$transient->option_id} OR option_name = '{$name_timeout}'");
}else{
delete_transient($name);
}
}
restore_current_blog();
}
}else{
global $wpdb;
$ids_to_delete = array();
foreach($_POST['aDBc_elements_to_process'] as $aDBc_feed){
$feed_info = explode("|", $aDBc_feed);
$sanitized_id = sanitize_html_class($feed_info[1]);
if(is_numeric($sanitized_id)){
array_push($ids_to_delete, $sanitized_id);
}
}
$names_to_delete = $wpdb->get_col("select option_name from $wpdb->options WHERE option_id IN (" . implode(',',$ids_to_delete) . ")");
foreach($names_to_delete as $transient_name){
$site_wide = (strpos($transient_name, '_site_transient') !== false);
$name = str_replace($site_wide ? '_site_transient_' : '_transient_', '', $transient_name);
if(false !== $site_wide){
// Here, we used delete_site_transient() instead of a query because on a single site, this function will delete the transient from options table
delete_site_transient($name);
}else{
delete_transient($name);
}
}
}
// Update the message to show to the user
$this->aDBc_message = __("Selected 'Transients' successfully cleaned!", "advanced-database-cleaner");
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
include_once 'page_custom_clean.php';
}
}
?>

View File

@@ -0,0 +1,160 @@
<!-- style et code ok -->
<div class="aDBc-float-left aDBc-margin-t-10">
<a href="?page=advanced_db_cleaner&aDBc_tab=general" style="text-decoration:none">
<span class="dashicons dashicons-controls-back aDBc-back-dashicon"></span>
<span style="vertical-align:middle"><?php echo __( 'Return', 'advanced-database-cleaner' ); ?></span>
</a>
</div>
<div>
<div class="aDBc-custom-clean-text">
<?php
echo __( 'Custom cleanup of', 'advanced-database-cleaner' ) . " ";
echo "<strong>" . $this->aDBc_plural_title . "</strong> - ";
echo __( 'Total Found', 'advanced-database-cleaner' ) . " : ";
echo "<b><span class='aDBc-custom-total'>" . count( $this->aDBc_elements_to_display ) . "</span></b>";
?>
</div>
<div class="aDBc-filter-container">
<div class="aDBc-filter-section">
<span class="aDBc-premium-tooltip">
<?php
$free_style = "";
if ( ADBC_PLUGIN_PLAN == "free" ) {
$free_style = "aDBc-filter-pro-only";
}
?>
<form class="<?php echo $free_style; ?>" method="get">
<?php
// Generate current parameters in URL
foreach ( $_GET as $name => $value ) {
if ( $name != "s" && $name != "in" && $name != "paged" ) {
$name = esc_attr( sanitize_text_field( $name ) );
$value = esc_attr( sanitize_text_field( $value ) );
echo "<input type='hidden' name='$name' value='$value'/>";
}
}
// Return paged to page 1
echo "<input type='hidden' name='paged' value='1'/>";
?>
<input class="aDBc-filter-search-input" type="search" placeholder="<?php _e( 'Search for', 'advanced-database-cleaner' ); ?>" name="s" value="<?php echo empty( $_GET['s'] ) ? '' : esc_attr( $_GET['s'] ); ?>"/>
<div class="aDBc-custom-filter-radio-section">
<span style="padding:0px 10px"><?php _e( 'Search in', 'advanced-database-cleaner' ); ?></span>
<?php
$in_checked = empty( $_GET['in'] ) || ( ! empty( $_GET['in'] ) && $_GET['in'] == "key" ) ? 'checked' : '';
$value_checked = ! empty( $_GET['in'] ) && $_GET['in'] == "value" ? 'checked' : '';
?>
<input type="radio" name="in" value="key" checked <?php echo $in_checked; ?>><?php _e( 'Name', 'advanced-database-cleaner' ); ?> &nbsp;
<input type="radio" name="in" value="value" <?php echo $value_checked; ?>><?php _e( 'Value', 'advanced-database-cleaner' ); ?>
</div>
<input class="button-secondary aDBc-filter-botton" type="submit" value="<?php _e( 'Filter', 'advanced-database-cleaner' ); ?>"/>
</form>
<?php
if ( ADBC_PLUGIN_PLAN == "free" ) {
?>
<span style="width:150px" class="aDBc-premium-tooltiptext">
<a href="https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner/" target="_blank">
<?php _e( 'Available in Pro version!', 'advanced-database-cleaner' ); ?>
</a>
</span>
<?php
}
?>
</span>
</div>
<!-- Items per page -->
<div class="aDBc-items-per-page">
<form method="get">
<?php
// Generate current parameters in URL
foreach ( $_GET as $name => $value ) {
if ( $name != "per_page" && $name != "paged" ) {
$name = esc_attr( sanitize_text_field( $name ) );
$value = esc_attr( sanitize_text_field( $value ) );
echo "<input type='hidden' name='$name' value='$value'/>";
}
}
// Return paged to page 1
echo "<input type='hidden' name='paged' value='1'/>";
?>
<span class="aDBc-items-per-page-label">
<?php _e( 'Items per page', 'advanced-database-cleaner' ); ?>
</span>
<input name="per_page" class="aDBc-items-per-page-input" type="number" value="<?php echo empty( $_GET['per_page'] ) ? '50' : esc_attr( $_GET['per_page'] ); ?>"/>
<input type="submit" class="button-secondary aDBc-show-botton" value="<?php _e( 'Show', 'advanced-database-cleaner' ); ?>"/>
</form>
</div>
<?php
if ( ( ! empty( $_GET['s'] ) && trim( $_GET['s'] ) != "" ) ||
! empty( $_GET['in'] )
) {
// Remove args to delete custom filter
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = remove_query_arg( array( 's', 'in' ), $aDBc_new_URI );
?>
<div class="aDBc-delete-custom-filter">
<a style="color:red" href="<?php echo esc_url( $aDBc_new_URI ); ?>">
<?php _e( 'Delete custom filter', 'advanced-database-cleaner' ); ?>
</a>
</div>
<?php
}
?>
</div>
</div>

View File

@@ -0,0 +1,22 @@
<?php
// Print a message if any
if($this->aDBc_message != ""){
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
?>
<div class="aDBc-content-max-width">
<?php include_once 'header_page_custom_clean.php'; ?>
<div>
<form id="aDBc_form" action="" method="post">
<?php
// Print the elements to clean
$this->display();
?>
</form>
</div>
</div>

View File

@@ -0,0 +1,396 @@
<?php
// style et code ok
class ADBC_SCHEDULE_CLEANUP extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_total_elements_to_clean = 0;
/**
* Constructor
*/
function __construct() {
parent::__construct( array(
'singular' => __( 'Element', 'advanced-database-cleaner' ),
'plural' => __( 'Elements', 'advanced-database-cleaner' ),
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean() {
// Test if user wants to save the scheduled task
if ( isset( $_POST['aDBc_schedule_name'] ) ) {
//Quick nonce security check!
if ( ! check_admin_referer( 'add_cleanup_schedule_nonce', 'add_cleanup_schedule_nonce' ) )
return; //get out if we didn't click the save_schedule button
if ( ! empty( $_POST['aDBc_elements_to_process'] ) ) {
$trim_schedule_name = trim( $_POST['aDBc_schedule_name'] );
if ( ! empty( $trim_schedule_name ) ) {
if ( preg_match( '/^[a-zA-Z0-9_]+$/', $_POST['aDBc_schedule_name'] ) ) {
// Test if the name is used by other schedules.
$clean_schedule_setting = get_option( 'aDBc_clean_schedule' );
$clean_schedule_setting = is_array( $clean_schedule_setting ) ? $clean_schedule_setting : array();
$optimize_schedule_setting = get_option( 'aDBc_optimize_schedule' );
$optimize_schedule_setting = is_array( $optimize_schedule_setting ) ? $optimize_schedule_setting : array();
if ( ! array_key_exists( $_POST['aDBc_schedule_name'], $clean_schedule_setting ) &&
! array_key_exists( $_POST['aDBc_schedule_name'], $optimize_schedule_setting ) ) {
if ( ! empty( $_POST['aDBc_date'] ) ) {
if ( ! empty( $_POST['aDBc_time'] ) ) {
// We will create the new schedule
$sanitized_elements_to_process = array();
foreach ( $_POST['aDBc_elements_to_process'] as $element ) {
array_push( $sanitized_elements_to_process, sanitize_html_class( $element ) );
}
$new_schedule_params['elements_to_clean'] = $sanitized_elements_to_process;
$new_schedule_params['repeat'] = sanitize_html_class( $_POST['aDBc_schedule_repeat'] );
$new_schedule_params['start_date'] = preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] );
$new_schedule_params['start_time'] = preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] );
$new_schedule_params['active'] = sanitize_html_class( $_POST['aDBc_status'] );
$clean_schedule_setting[$_POST['aDBc_schedule_name']] = $new_schedule_params;
update_option( 'aDBc_clean_schedule', $clean_schedule_setting, "no" );
list( $year, $month, $day ) = explode( '-', preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] ) );
list( $hours, $minutes ) = explode( ':', preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] ) );
$seconds = "0";
$timestamp = mktime( $hours, $minutes, $seconds, $month, $day, $year );
if ( $_POST['aDBc_status'] == "1" ) {
if ( $_POST['aDBc_schedule_repeat'] == "once" ) {
wp_schedule_single_event( $timestamp, "aDBc_clean_scheduler", array( $_POST['aDBc_schedule_name'] ) );
} else {
wp_schedule_event( $timestamp, sanitize_html_class( $_POST['aDBc_schedule_repeat'] ), "aDBc_clean_scheduler", array( $_POST['aDBc_schedule_name'] ) );
}
$this->aDBc_message = __( 'The clean-up schedule saved successfully!', 'advanced-database-cleaner' );
} else {
$this->aDBc_message = __( 'The clean-up schedule saved successfully but it is inactive!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide time!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide date!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'The name you have specified is already used by another schedule! Please change it!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please change the name! Only letters, numbers and underscores are allowed!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please give a name to your schedule!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please select at least one item to include in the schedule from the table below!', 'advanced-database-cleaner' );
}
}
// Get all unused elements
$aDBc_unused_elements = aDBc_return_array_all_elements_to_clean();
// Get settings from DB
$settings = get_option( 'aDBc_settings' );
foreach ( $aDBc_unused_elements as $element_type => $element_name ) {
// Get "keep_last" option. This option is added in ADBC version 3.0, so test if it is not empty before using it
if ( empty( $settings['keep_last'] ) ) {
$keep_number = '0';
} else {
$keep_setting = $settings['keep_last'];
if ( empty( $keep_setting[$element_type] ) ) {
$keep_number = '0';
} else {
$keep_number = $keep_setting[$element_type];
}
}
// If the item can have keep_last, then prepare it, otherwise echo N/A
if ( $element_type == "revision" ||
$element_type == "auto-draft" ||
$element_type == "trash-posts" ||
$element_type == "moderated-comments" ||
$element_type == "spam-comments" ||
$element_type == "trash-comments" ||
$element_type == "pingbacks" ||
$element_type == "trackbacks") {
$keep_info = "<span>" . $keep_number . " " . __( 'days', 'advanced-database-cleaner' );
} else {
$keep_info = __( 'N/A', 'advanced-database-cleaner' );
}
array_push( $this->aDBc_elements_to_display, array(
'element_to_schedule' => "<a href='" . $element_name['URL_blog'] . "' target='_blank' class='aDBc-info-icon'>&nbsp;</a>" . $element_name['name'],
'keep' => $keep_info,
'type' => $element_type
)
);
}
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns() {
$aDBc_keep_last_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __( 'Only data that is older than the number you have specified will be cleaned based on you schedule parameters. To change this value, click on "go back" button.', 'advanced-database-cleaner' ) ." </span>
</span>";
$columns = array(
'cb' => '<input type="checkbox" />',
'element_to_schedule' => __( 'Elements to include in the schedule', 'advanced-database-cleaner' ),
'keep' => __( 'Keep last', 'advanced-database-cleaner' ) . $aDBc_keep_last_toolip,
'type' => 'Type'
);
return $columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = array();
$this->_column_headers = array( $columns, $hidden, $sortable );
$per_page = 50;
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice( $this->aDBc_elements_to_display, ( ( $current_page-1 ) * $per_page ), $per_page );
$this->set_pagination_args( array(
'total_items' => count( $this->aDBc_elements_to_display ),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns() {
return array( 'type' );
}
/** WP: Column default */
function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'element_to_schedule':
case 'keep':
case 'type':
return $item[$column_name];
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb( $item ) {
$checked = "";
if ( isset( $_POST['aDBc_elements_to_process'] ) ) {
if ( in_array( $item['type'], $_POST['aDBc_elements_to_process'] ) ) {
$checked = "checked";
}
}
return sprintf( '<input type="checkbox" name="aDBc_elements_to_process[]" value="%s"' . $checked . '/>', $item['type'] );
}
/** WP: Get bulk actions */
function get_bulk_actions() {
return array();
}
/** WP: Message to display when no items found */
function no_items() {
_e( 'Your database is clean!', 'advanced-database-cleaner' );
}
/** Print the page content */
function aDBc_print_page_content() {
// Print a message if any
if ( $this->aDBc_message != "" ) {
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
?>
<div style="max-width:700px">
<div class="aDBc-float-left aDBc-margin-t-10">
<a href="?page=advanced_db_cleaner&aDBc_tab=general" style="text-decoration:none">
<span class="dashicons dashicons-controls-back aDBc-back-dashicon"></span>
<span style="vertical-align:middle"><?php echo __( 'Return', 'advanced-database-cleaner' ); ?></span>
</a>
</div>
<div class="aDBc-schedule-title">
<span class="dashicons dashicons-plus aDBc-schedule-dashicon"></span>
<?php echo __( 'Add cleanup schedule', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-clear-both"></div>
<form id="aDBc_form" action="" method="post">
<!-- Print the elements to clean -->
<div class="aDBc-schedule-table-elements">
<?php $this->display(); ?>
</div>
<div class="aDBc-right-box">
<div class="aDBc-right-box-content">
<div style="text-align:center">
<img width="60px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/alarm-clock.svg' ?>"/>
</div>
<div id="add_schedule" class="aDBc-schedule-info-container">
<div class="aDBc-margin-t-10"></div>
<div><?php _e( 'Schedule name', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_schedule_name" class="aDBc-schedule-input-field" type="text" value="<?php echo isset( $_POST['aDBc_schedule_name'] ) ? esc_attr( $_POST['aDBc_schedule_name'] ) : "" ?>" maxlength="25">
<div><?php _e( 'Frequency of execution', 'advanced-database-cleaner' ); ?></div>
<select name="aDBc_schedule_repeat" class="aDBc-schedule-input-field">
<?php
$schedules_repeat = array( 'once' => __( 'Once', 'advanced-database-cleaner' ),
'hourly' => __( 'Hourly', 'advanced-database-cleaner' ),
'twicedaily' => __( 'Twice a day', 'advanced-database-cleaner' ),
'daily' => __( 'Daily', 'advanced-database-cleaner' ),
'weekly' => __( 'Weekly', 'advanced-database-cleaner' ),
'monthly' => __( 'Monthly', 'advanced-database-cleaner' )
);
foreach ( $schedules_repeat as $code_repeat => $name_repeat ) {
if ( isset( $_POST['aDBc_schedule_repeat'] ) && $_POST['aDBc_schedule_repeat'] == $code_repeat ) {
echo "<option value='$code_repeat' selected='selected'>$name_repeat</option>";
} else {
echo "<option value='$code_repeat'>$name_repeat</option>";
}
}
?>
</select>
<div><?php _e( 'Start date', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_date" class="aDBc-schedule-input-field" type="date" value="<?php echo isset( $_POST['aDBc_date'] ) ? esc_attr( $_POST['aDBc_date'] ) : date( "Y-m-d" ); ?>" min="<?php echo date( "Y-m-d" ); ?>">
<div><?php _e( 'Start time (GMT)', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_time" class="aDBc-schedule-input-field" type="time" value="<?php echo isset( $_POST['aDBc_time'] ) ? esc_attr( $_POST['aDBc_time'] ) : date( "H:i", time() ); ?>">
<div><?php _e( 'Schedule status', 'advanced-database-cleaner' ); ?></div>
<div class="aDBc-schedule-radio-container">
<input name="aDBc_status" type="radio" value="1" checked>
<span style="margin-right:20px"><?php _e( 'Active', 'advanced-database-cleaner' ); ?></span>
<input name="aDBc_status" type="radio" value="0" <?php echo ( isset( $_POST['aDBc_status'] ) && $_POST['aDBc_status'] == "0" ) ? 'checked' : ''; ?>>
<?php _e( 'Inactive', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-schedule-save-btn-div">
<input class="button-primary" type="submit" value="<?php _e( 'Save the schedule', 'advanced-database-cleaner' ); ?>" style="width:100%"/>
</div>
</div>
</div>
</div>
<?php wp_nonce_field( 'add_cleanup_schedule_nonce', 'add_cleanup_schedule_nonce' ); ?>
</form>
<div class="aDBc-clear-both"></div>
</div>
<?php
}
}
?>

View File

@@ -0,0 +1,269 @@
<?php
// style et code ok
class ADBC_SCHEDULE_OPTIMIZE {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
/**
* Constructor
*/
function __construct() {
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean() {
// Test if user wants to save the scheduled task
if ( isset( $_POST['aDBc_schedule_name'] ) ) {
//Quick nonce security check!
if ( ! check_admin_referer( 'add_optimize_schedule_nonce', 'add_optimize_schedule_nonce' ) )
return; //get out if we didn't click the save_schedule button
$trim_schedule_name = trim( $_POST['aDBc_schedule_name'] );
if ( ! empty( $trim_schedule_name ) ) {
if ( preg_match( '/^[a-zA-Z0-9_]+$/', $_POST['aDBc_schedule_name'] ) ) {
// Test if the name is used by other schedules.
$clean_schedule_setting = get_option( 'aDBc_clean_schedule' );
$clean_schedule_setting = is_array( $clean_schedule_setting ) ? $clean_schedule_setting : array();
$optimize_schedule_setting = get_option( 'aDBc_optimize_schedule' );
$optimize_schedule_setting = is_array( $optimize_schedule_setting ) ? $optimize_schedule_setting : array();
if ( ! array_key_exists( $_POST['aDBc_schedule_name'], $clean_schedule_setting ) &&
! array_key_exists( $_POST['aDBc_schedule_name'], $optimize_schedule_setting ) ) {
if ( ! empty( $_POST['aDBc_date'] ) ) {
if ( ! empty( $_POST['aDBc_time'] ) ) {
if ( ! empty( $_POST['aDBc_operation1'] ) || ! empty( $_POST['aDBc_operation2'] ) ) {
// We will create the new schedule
$new_schedule_params['repeat'] = sanitize_html_class( $_POST['aDBc_schedule_repeat'] );
$new_schedule_params['start_date'] = preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] );
$new_schedule_params['start_time'] = preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] );
// Prepare operations to perform
$operations = array();
if ( ! empty( $_POST['aDBc_operation1'] ) )
array_push( $operations, sanitize_html_class( $_POST['aDBc_operation1'] ) );
if ( ! empty( $_POST['aDBc_operation2'] ) )
array_push( $operations, sanitize_html_class( $_POST['aDBc_operation2'] ) );
$new_schedule_params['operations'] = $operations;
$new_schedule_params['active'] = sanitize_html_class( $_POST['aDBc_status'] );
$optimize_schedule_setting[$_POST['aDBc_schedule_name']] = $new_schedule_params;
update_option( 'aDBc_optimize_schedule', $optimize_schedule_setting, "no" );
list( $year, $month, $day ) = explode( '-', preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] ) );
list( $hours, $minutes ) = explode( ':', preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] ) );
$seconds = "0";
$timestamp = mktime( $hours, $minutes, $seconds, $month, $day, $year );
if ( $_POST['aDBc_status'] == "1" ) {
if ( $_POST['aDBc_schedule_repeat'] == "once" ) {
wp_schedule_single_event( $timestamp, "aDBc_optimize_scheduler", array( $_POST['aDBc_schedule_name'] ) );
} else {
wp_schedule_event( $timestamp, sanitize_html_class( $_POST['aDBc_schedule_repeat'] ), "aDBc_optimize_scheduler", array( $_POST['aDBc_schedule_name'] ) );
}
$this->aDBc_message = __( 'The clean-up schedule saved successfully!', 'advanced-database-cleaner' );
} else {
$this->aDBc_message = __( 'The clean-up schedule saved successfully but it is inactive!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please choose at least one operation to perform!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide time!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide date!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'The name you have specified is already used by another schedule! Please change it!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please change the name! Only letters, numbers and underscores are allowed!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please give a name to your schedule!', 'advanced-database-cleaner' );
}
}
}
/** Print the page content */
function aDBc_print_page_content() {
// Print a message if any
if ( $this->aDBc_message != "" ) {
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
?>
<div style="max-width:700px">
<div class="aDBc-float-left aDBc-margin-t-10">
<a href="?page=advanced_db_cleaner&aDBc_tab=tables&aDBc_cat=all" style="text-decoration:none">
<span class="dashicons dashicons-controls-back aDBc-back-dashicon"></span>
<span style="vertical-align:middle"><?php echo __( 'Return', 'advanced-database-cleaner' ); ?></span>
</a>
</div>
<div class="aDBc-schedule-title">
<span class="dashicons dashicons-plus aDBc-schedule-dashicon"></span>
<?php echo __( 'Add optimize schedule', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-clear-both"></div>
<form id="aDBc_form" action="" method="post">
<!-- Print box info for tables that will be optimized -->
<div class="aDBc-schedule-table-elements aDBc-schedule-tables-box-info">
<div style="padding:40px 20px">
<?php echo __( 'By default, all your database tables will be optimized and/or repaired (if needed) according to your schedule settings', 'advanced-database-cleaner' ); ?>
</div>
</div>
<div class="aDBc-right-box">
<div class="aDBc-right-box-content">
<div style="text-align:center">
<img width="60px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/alarm-clock.svg' ?>"/>
</div>
<div id="add_schedule" class="aDBc-schedule-info-container">
<div class="aDBc-margin-t-10"></div>
<div><?php _e( 'Schedule name', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_schedule_name" class="aDBc-schedule-input-field" type="text" value="<?php echo isset( $_POST['aDBc_schedule_name'] ) ? esc_attr( $_POST['aDBc_schedule_name'] ) : "" ?>" maxlength="25">
<div><?php _e( 'Frequency of execution', 'advanced-database-cleaner' ); ?></div>
<select name="aDBc_schedule_repeat" class="aDBc-schedule-input-field">
<?php
$schedules_repeat = array( 'once' => __( 'Once', 'advanced-database-cleaner' ),
'hourly' => __( 'Hourly', 'advanced-database-cleaner' ),
'twicedaily' => __( 'Twice a day', 'advanced-database-cleaner' ),
'daily' => __( 'Daily', 'advanced-database-cleaner' ),
'weekly' => __( 'Weekly', 'advanced-database-cleaner' ),
'monthly' => __( 'Monthly', 'advanced-database-cleaner' )
);
foreach ( $schedules_repeat as $code_repeat => $name_repeat ) {
if ( isset( $_POST['aDBc_schedule_repeat'] ) && $_POST['aDBc_schedule_repeat'] == $code_repeat ) {
echo "<option value='$code_repeat' selected='selected'>$name_repeat</option>";
} else {
echo "<option value='$code_repeat'>$name_repeat</option>";
}
}
?>
</select>
<div><?php _e( 'Start date', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_date" class="aDBc-schedule-input-field" type="date" value="<?php echo isset( $_POST['aDBc_date'] ) ? esc_attr( $_POST['aDBc_date'] ) : date( "Y-m-d" ); ?>" min="<?php echo date( "Y-m-d" ); ?>">
<div><?php _e( 'Start time (GMT)', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_time" class="aDBc-schedule-input-field" type="time" value="<?php echo isset( $_POST['aDBc_time'] ) ? esc_attr( $_POST['aDBc_time'] ) : date( "H:i", time() ); ?>">
<div><?php _e( 'Perform operations', 'advanced-database-cleaner' ); ?></div>
<div class="aDBc-schedule-radio-container">
<?php
$optimize_checked = ( isset( $_POST['aDBc_operation1'] ) && $_POST['aDBc_operation1'] == "optimize" ) ? 'checked' : '';
$repair_checked = ( isset( $_POST['aDBc_operation2'] ) && $_POST['aDBc_operation2'] == "repair" ) ? 'checked' : '';
?>
<input name="aDBc_operation1" type="checkbox" value="optimize" <?php echo $optimize_checked; ?>>
<span style="margin-right:20px"><?php _e( 'Optimize', 'advanced-database-cleaner' ); ?></span>
<input name="aDBc_operation2" type="checkbox" value="repair" <?php echo $repair_checked; ?>>
<?php _e( 'Repair', 'advanced-database-cleaner' ); ?>
</div>
<div><?php _e( 'Schedule status', 'advanced-database-cleaner' ); ?></div>
<div class="aDBc-schedule-radio-container">
<input name="aDBc_status" type="radio" value="1" checked>
<span style="margin-right:20px"><?php _e( 'Active', 'advanced-database-cleaner' ); ?></span>
<input name="aDBc_status" type="radio" value="0" <?php echo ( isset( $_POST['aDBc_status'] ) && $_POST['aDBc_status'] == "0" ) ? 'checked' : ''; ?>>
<?php _e( 'Inactive', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-schedule-save-btn-div">
<input class="button-primary" type="submit" value="<?php _e( 'Save the schedule', 'advanced-database-cleaner' ); ?>" style="width:100%"/>
</div>
</div>
</div>
</div>
<?php wp_nonce_field( 'add_optimize_schedule_nonce', 'add_optimize_schedule_nonce' ); ?>
</form>
<div class="aDBc-clear-both"></div>
</div>
<?php
}
}
?>

View File

@@ -0,0 +1,451 @@
<?php
// style et code ok
class EDIT_SCHEDULE_CLEANUP extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
private $aDBc_elements_to_display = array();
private $aDBc_total_elements_to_clean = 0;
/**
* Constructor
*/
function __construct() {
parent::__construct( array(
'singular' => __( 'Element', 'advanced-database-cleaner' ),
'plural' => __( 'Elements', 'advanced-database-cleaner' ),
'ajax' => false
));
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean() {
// Test if user wants to save the edited scheduled task
if ( isset( $_POST['aDBc_schedule_name'] ) ) {
//Quick nonce security check!
if ( ! check_admin_referer( 'edit_cleanup_schedule_nonce', 'edit_cleanup_schedule_nonce' ) )
return; //get out if we didn't click the save_schedule button
if ( ! empty( $_POST['aDBc_elements_to_process'] ) ) {
$trim_schedule_name = trim( $_POST['aDBc_schedule_name'] );
if ( ! empty( $trim_schedule_name ) ) {
if ( preg_match( '/^[a-zA-Z0-9_]+$/', $_POST['aDBc_schedule_name'] ) ) {
// Test if the name is used by other schedules.
$clean_schedule_setting = get_option( 'aDBc_clean_schedule' );
$clean_schedule_setting = is_array( $clean_schedule_setting ) ? $clean_schedule_setting : array();
$optimize_schedule_setting = get_option( 'aDBc_optimize_schedule' );
$optimize_schedule_setting = is_array( $optimize_schedule_setting ) ? $optimize_schedule_setting : array();
if ( $_POST['aDBc_schedule_name'] == $_GET['hook_name'] ||
( $_POST['aDBc_schedule_name'] != $_GET['hook_name'] &&
! array_key_exists( $_POST['aDBc_schedule_name'], $clean_schedule_setting ) &&
! array_key_exists( $_POST['aDBc_schedule_name'], $optimize_schedule_setting ) )
) {
if ( ! empty( $_POST['aDBc_date'] ) ) {
if ( ! empty( $_POST['aDBc_time'] ) ) {
// Delete the old schedule and replace it with the new
// We will create the new schedule
$sanitized_elements_to_process = array();
foreach ( $_POST['aDBc_elements_to_process'] as $element ) {
array_push( $sanitized_elements_to_process, sanitize_html_class( $element ) );
}
$new_schedule_params['elements_to_clean'] = $sanitized_elements_to_process;
$new_schedule_params['repeat'] = sanitize_html_class( $_POST['aDBc_schedule_repeat'] );
$new_schedule_params['start_date'] = preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] );
$new_schedule_params['start_time'] = preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] );
$new_schedule_params['active'] = sanitize_html_class( $_POST['aDBc_status'] );
$clean_schedule_setting[$_POST['aDBc_schedule_name']] = $new_schedule_params;
update_option( 'aDBc_clean_schedule', $clean_schedule_setting, "no" );
list( $year, $month, $day ) = explode( '-', preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] ) );
list( $hours, $minutes ) = explode( ':', preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] ) );
$seconds = "0";
$timestamp = mktime( $hours, $minutes, $seconds, $month, $day, $year );
// Clear scheduled event
wp_clear_scheduled_hook( 'aDBc_clean_scheduler', array( $_POST['aDBc_schedule_name'] . '' ) );
if ( $_POST['aDBc_status'] == "1" ) {
if ( $_POST['aDBc_schedule_repeat'] == "once" ) {
wp_schedule_single_event( $timestamp, "aDBc_clean_scheduler", array( $_POST['aDBc_schedule_name'] ) );
} else {
wp_schedule_event( $timestamp, sanitize_html_class( $_POST['aDBc_schedule_repeat'] ), "aDBc_clean_scheduler", array( $_POST['aDBc_schedule_name'] ) );
}
$this->aDBc_message = __( 'The clean-up schedule saved successfully!', 'advanced-database-cleaner' );
} else {
$this->aDBc_message = __( 'The clean-up schedule saved successfully but it is inactive!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide time!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide date!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'The name you have specified is already used by another schedule! Please change it!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please change the name! Only letters, numbers and underscores are allowed!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please give a name to your schedule!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please select at least one item to include in the schedule from the table below!', 'advanced-database-cleaner' );
}
}
// Get all unused elements
$aDBc_unused_elements = aDBc_return_array_all_elements_to_clean();
// Get settings from DB
$settings = get_option( 'aDBc_settings' );
foreach ( $aDBc_unused_elements as $element_type => $element_name ) {
// Get "keep_last" option. This option is added in ADBC version 3.0, so test if it is not empty before using it
if ( empty( $settings['keep_last'] ) ) {
$keep_number = '0';
} else {
$keep_setting = $settings['keep_last'];
if ( empty( $keep_setting[$element_type] ) ) {
$keep_number = '0';
} else {
$keep_number = $keep_setting[$element_type];
}
}
// If the item can have keep_last, then prepare it, otherwise echo N/A
if ( $element_type == "revision" ||
$element_type == "auto-draft" ||
$element_type == "trash-posts" ||
$element_type == "moderated-comments" ||
$element_type == "spam-comments" ||
$element_type == "trash-comments" ||
$element_type == "pingbacks" ||
$element_type == "trackbacks") {
$keep_info = "<span>" . $keep_number . " " . __( 'days', 'advanced-database-cleaner' );
} else {
$keep_info = __( 'N/A', 'advanced-database-cleaner' );
}
array_push( $this->aDBc_elements_to_display, array(
'element_to_schedule' => "<a href='" . $element_name['URL_blog'] . "' target='_blank' class='aDBc-info-icon'>&nbsp;</a>" . $element_name['name'],
'keep' => $keep_info,
'type' => $element_type
)
);
}
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns() {
$aDBc_keep_last_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __( 'Only data that is older than the number you have specified will be cleaned based on you schedule parameters. To change this value, click on "go back" button.', 'advanced-database-cleaner' ) ." </span>
</span>";
$columns = array(
'cb' => '<input type="checkbox" />',
'element_to_schedule' => __( 'Elements to include in the schedule', 'advanced-database-cleaner' ),
'keep' => __( 'Keep last', 'advanced-database-cleaner' ) . $aDBc_keep_last_toolip,
'type' => 'Type'
);
return $columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = array();
$this->_column_headers = array( $columns, $hidden, $sortable );
$per_page = 50;
$current_page = $this->get_pagenum();
// Prepare sequence of elements to display
$display_data = array_slice( $this->aDBc_elements_to_display, ( ( $current_page-1 ) * $per_page ), $per_page );
$this->set_pagination_args( array(
'total_items' => count( $this->aDBc_elements_to_display ),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns() {
return array( 'type' );
}
/** WP: Column default */
function column_default( $item, $column_name ) {
switch ( $column_name ) {
case 'element_to_schedule':
case 'keep':
case 'type':
return $item[$column_name];
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb( $item ) {
$checked = "";
if ( isset( $_POST['aDBc_schedule_name'] ) && ! empty( $_POST['aDBc_elements_to_process'] ) ) {
if ( in_array( $item['type'], $_POST['aDBc_elements_to_process'] ) ) {
$checked = "checked";
}
} else {
$schedule_settings = get_option('aDBc_clean_schedule');
$schedule_params = $schedule_settings[sanitize_html_class($_GET['hook_name'])];
$schedule_elements_to_clean = $schedule_params['elements_to_clean'];
$schedule_elements_to_clean = is_array($schedule_elements_to_clean) ? $schedule_elements_to_clean : array();
if ( in_array($item['type'], $schedule_elements_to_clean ) ) {
$checked = "checked";
}
}
return sprintf( '<input type="checkbox" name="aDBc_elements_to_process[]" value="%s"' . $checked . '/>', $item['type'] );
}
/** WP: Get bulk actions */
function get_bulk_actions() {
return array();
}
/** WP: Message to display when no items found */
function no_items() {
_e( 'Your database is clean!', 'advanced-database-cleaner' );
}
/** Print the page content */
function aDBc_print_page_content() {
// Print a message if any
if ( $this->aDBc_message != "" ) {
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
?>
<div style="max-width:700px">
<div class="aDBc-float-left aDBc-margin-t-10">
<a href="?page=advanced_db_cleaner&aDBc_tab=general" style="text-decoration:none">
<span class="dashicons dashicons-controls-back aDBc-back-dashicon"></span>
<span style="vertical-align:middle"><?php echo __( 'Return', 'advanced-database-cleaner' ); ?></span>
</a>
</div>
<div class="aDBc-schedule-title">
<span class="dashicons dashicons-edit aDBc-schedule-dashicon"></span>
<?php echo __( 'Edit cleanup schedule', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-clear-both"></div>
<form id="aDBc_form" action="" method="post">
<!-- Print the elements to clean -->
<div class="aDBc-schedule-table-elements">
<?php $this->display(); ?>
</div>
<?php
// Prepare info of the original schedule to fill it into inputs...
if ( isset( $_POST['aDBc_schedule_name'] ) ) {
$hook_name = sanitize_html_class( $_POST['aDBc_schedule_name'] );
$schedule_repeat = sanitize_html_class( $_POST['aDBc_schedule_repeat'] );
$schedule_date = preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] );
$schedule_time = preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] );
$schedule_status = sanitize_html_class( $_POST['aDBc_status'] );
} else {
$schedule_settings = get_option( 'aDBc_clean_schedule' );
$schedule_params = $schedule_settings[sanitize_html_class( $_GET['hook_name'] )];
$hook_name = sanitize_html_class( $_GET['hook_name'] );
$schedule_repeat = $schedule_params['repeat'];
$timestamp = wp_next_scheduled( "aDBc_clean_scheduler", array( sanitize_html_class( $_GET['hook_name'] ) . '' ) );
if ( $timestamp ) {
$schedule_date = date( "Y-m-d", $timestamp );
$schedule_time = date( "H:i", $timestamp );
} else {
$schedule_date = date( "Y-m-d" );
$schedule_time = date( "H:i", time() );
}
$schedule_status = $schedule_params['active'];
}
?>
<div class="aDBc-right-box">
<div class="aDBc-right-box-content">
<div style="text-align:center">
<img width="60px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/alarm-clock.svg' ?>"/>
</div>
<div id="add_schedule" class="aDBc-schedule-info-container">
<div class="aDBc-margin-t-10"></div>
<div><?php _e( 'Schedule name', 'advanced-database-cleaner' ); ?></div>
<input class="aDBc-schedule-input-field" type="text" value="<?php echo $hook_name; ?>" maxlength="25" disabled>
<input type="hidden" name="aDBc_schedule_name" value="<?php echo $hook_name; ?>" maxlength="25">
<div><?php _e( 'Frequency of execution', 'advanced-database-cleaner' ); ?></div>
<select name="aDBc_schedule_repeat" class="aDBc-schedule-input-field">
<?php
$schedules_repeat = array( 'once' => __( 'Once', 'advanced-database-cleaner' ),
'hourly' => __( 'Hourly', 'advanced-database-cleaner' ),
'twicedaily' => __( 'Twice a day', 'advanced-database-cleaner' ),
'daily' => __( 'Daily', 'advanced-database-cleaner' ),
'weekly' => __( 'Weekly', 'advanced-database-cleaner' ),
'monthly' => __( 'Monthly', 'advanced-database-cleaner' )
);
foreach ( $schedules_repeat as $code_repeat => $name_repeat ) {
if ( $code_repeat == $schedule_repeat ) {
echo "<option value='$code_repeat' selected='selected'>$name_repeat</option>";
} else {
echo "<option value='$code_repeat'>$name_repeat</option>";
}
}
?>
</select>
<div><?php _e( 'Start date', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_date" class="aDBc-schedule-input-field" type="date" value="<?php echo $schedule_date; ?>" min="<?php echo date( "Y-m-d" ); ?>">
<div><?php _e( 'Start time (GMT)', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_time" class="aDBc-schedule-input-field" type="time" value="<?php echo $schedule_time; ?>">
<div><?php _e( 'Schedule status', 'advanced-database-cleaner' ); ?></div>
<div class="aDBc-schedule-radio-container">
<input name="aDBc_status" type="radio" value="1" checked>
<span style="margin-right:20px"><?php _e( 'Active', 'advanced-database-cleaner' ); ?></span>
<input name="aDBc_status" type="radio" value="0" <?php echo $schedule_status == "0" ? 'checked' : ''; ?>>
<?php _e( 'Inactive', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-schedule-save-btn-div">
<input class="button-primary" type="submit" value="<?php _e( 'Save the schedule', 'advanced-database-cleaner' ); ?>" style="width:100%"/>
</div>
</div>
</div>
</div>
<?php wp_nonce_field( 'edit_cleanup_schedule_nonce', 'edit_cleanup_schedule_nonce' ); ?>
</form>
<div class="aDBc-clear-both"></div>
</div>
<?php
}
}
?>

View File

@@ -0,0 +1,313 @@
<?php
// style et code ok
class EDIT_SCHEDULE_OPTIMIZE extends WP_List_Table {
private $aDBc_message = "";
private $aDBc_class_message = "updated";
/**
* Constructor
*/
function __construct() {
$this->aDBc_prepare_elements_to_clean();
$this->aDBc_print_page_content();
}
/** Prepare elements to display */
function aDBc_prepare_elements_to_clean() {
// Test if user wants to save the edited scheduled task
if ( isset( $_POST['aDBc_schedule_name'] ) ) {
//Quick nonce security check!
if ( ! check_admin_referer( 'edit_optimize_schedule_nonce', 'edit_optimize_schedule_nonce' ) )
return; //get out if we didn't click the save_schedule button
$trim_schedule_name = trim( $_POST['aDBc_schedule_name'] );
if ( ! empty( $trim_schedule_name ) ) {
if ( preg_match( '/^[a-zA-Z0-9_]+$/', $_POST['aDBc_schedule_name'] ) ) {
// Test if the name is used by other schedules.
$clean_schedule_setting = get_option( 'aDBc_clean_schedule' );
$clean_schedule_setting = is_array( $clean_schedule_setting ) ? $clean_schedule_setting : array();
$optimize_schedule_setting = get_option( 'aDBc_optimize_schedule' );
$optimize_schedule_setting = is_array( $optimize_schedule_setting ) ? $optimize_schedule_setting : array();
if ( $_POST['aDBc_schedule_name'] == $_GET['hook_name'] ||
( $_POST['aDBc_schedule_name'] != $_GET['hook_name'] &&
! array_key_exists( $_POST['aDBc_schedule_name'], $clean_schedule_setting ) &&
! array_key_exists( $_POST['aDBc_schedule_name'], $optimize_schedule_setting ) )
) {
if ( ! empty( $_POST['aDBc_date'] ) ) {
if ( ! empty( $_POST['aDBc_time'] ) ) {
if ( ! empty( $_POST['aDBc_operation1'] ) || ! empty( $_POST['aDBc_operation2'] ) ) {
// Delete the old schedule and replace it with the new
// We will create the new schedule
$new_schedule_params['repeat'] = sanitize_html_class( $_POST['aDBc_schedule_repeat'] );
$new_schedule_params['start_date'] = preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] );
$new_schedule_params['start_time'] = preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] );
// Prepare operations to perform
$operations = array();
if ( ! empty( $_POST['aDBc_operation1'] ) )
array_push( $operations, sanitize_html_class( $_POST['aDBc_operation1'] ) );
if ( ! empty( $_POST['aDBc_operation2'] ) )
array_push( $operations, sanitize_html_class( $_POST['aDBc_operation2'] ) );
$new_schedule_params['operations'] = $operations;
$new_schedule_params['active'] = sanitize_html_class( $_POST['aDBc_status'] );
$optimize_schedule_setting[$_POST['aDBc_schedule_name']] = $new_schedule_params;
update_option( 'aDBc_optimize_schedule', $optimize_schedule_setting, "no" );
list( $year, $month, $day ) = explode( '-', preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] ) );
list( $hours, $minutes ) = explode( ':', preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] ) );
$seconds = "0";
$timestamp = mktime( $hours, $minutes, $seconds, $month, $day, $year );
// Clear scheduled event
wp_clear_scheduled_hook( 'aDBc_optimize_scheduler', array( $_POST['aDBc_schedule_name'] . '') );
if ( $_POST['aDBc_status'] == "1" ) {
if ( $_POST['aDBc_schedule_repeat'] == "once" ) {
wp_schedule_single_event( $timestamp, "aDBc_optimize_scheduler", array( $_POST['aDBc_schedule_name'] ) );
} else {
wp_schedule_event( $timestamp, sanitize_html_class( $_POST['aDBc_schedule_repeat'] ), "aDBc_optimize_scheduler", array( $_POST['aDBc_schedule_name'] ) );
}
$this->aDBc_message = __( 'The clean-up schedule saved successfully!', 'advanced-database-cleaner' );
} else {
$this->aDBc_message = __( 'The clean-up schedule saved successfully but it is inactive!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please choose at least one operation to perform!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide time!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please specify a valide date!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'The name you have specified is already used by another schedule! Please change it!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please change the name! Only letters, numbers and underscores are allowed!', 'advanced-database-cleaner' );
}
} else {
$this->aDBc_class_message = "error";
$this->aDBc_message = __( 'Please give a name to your schedule!', 'advanced-database-cleaner' );
}
}
}
/** Print the page content */
function aDBc_print_page_content() {
// Print a message if any
if ( $this->aDBc_message != "" ) {
echo '<div id="aDBc_message" class="' . $this->aDBc_class_message . ' notice is-dismissible"><p>' . $this->aDBc_message . '</p></div>';
}
?>
<div style="max-width:700px">
<div class="aDBc-float-left aDBc-margin-t-10">
<a href="?page=advanced_db_cleaner&aDBc_tab=tables&aDBc_cat=all" style="text-decoration:none">
<span class="dashicons dashicons-controls-back aDBc-back-dashicon"></span>
<span style="vertical-align:middle"><?php echo __( 'Return', 'advanced-database-cleaner' ); ?></span>
</a>
</div>
<div class="aDBc-schedule-title">
<span class="dashicons dashicons-plus aDBc-schedule-dashicon"></span>
<?php echo __( 'Edit cleanup schedule', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-clear-both"></div>
<form id="aDBc_form" action="" method="post">
<!-- Print box info for tables that will be optimized -->
<div class="aDBc-schedule-table-elements aDBc-schedule-tables-box-info">
<div style="padding:40px 20px">
<?php echo __( 'By default, all your database tables will be optimized and/or repaired (if needed) according to your schedule settings', 'advanced-database-cleaner' ); ?>
</div>
</div>
<?php
// Prepare info of the original schedule to fill it into inputs...
if ( isset( $_POST['aDBc_schedule_name'] ) ) {
$hook_name = sanitize_html_class( $_POST['aDBc_schedule_name'] );
$schedule_repeat = sanitize_html_class( $_POST['aDBc_schedule_repeat'] );
$schedule_date = preg_replace( "/[^0-9-]/", '', $_POST['aDBc_date'] );
$schedule_time = preg_replace( "/[^0-9:]/", '', $_POST['aDBc_time'] );
$operation1 = isset( $_POST['aDBc_operation1'] ) ? sanitize_html_class( $_POST['aDBc_operation1'] ) : "";
$operation2 = isset( $_POST['aDBc_operation2'] ) ? sanitize_html_class( $_POST['aDBc_operation2'] ) : "";
$schedule_status = sanitize_html_class( $_POST['aDBc_status'] );
} else {
$schedule_settings = get_option( 'aDBc_optimize_schedule' );
$schedule_params = $schedule_settings[sanitize_html_class( $_GET['hook_name'] )];
$hook_name = sanitize_html_class( $_GET['hook_name'] );
$schedule_repeat = $schedule_params['repeat'];
$timestamp = wp_next_scheduled( "aDBc_optimize_scheduler", array( sanitize_html_class( $_GET['hook_name'] ) . '' ) );
if ( $timestamp ) {
$schedule_date = date( "Y-m-d", $timestamp );
$schedule_time = date( "H:i", $timestamp );
} else {
$schedule_date = date( "Y-m-d" );
$schedule_time = date( "H:i", time() );
}
$operation1 = in_array( 'optimize', $schedule_params['operations'] ) ? 'optimize' : '';
$operation2 = in_array( 'repair', $schedule_params['operations'] ) ? 'repair' : '';
$schedule_status = $schedule_params['active'];
}
?>
<div class="aDBc-right-box">
<div class="aDBc-right-box-content">
<div style="text-align:center">
<img width="60px" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/alarm-clock.svg' ?>"/>
</div>
<div id="add_schedule" class="aDBc-schedule-info-container">
<div class="aDBc-margin-t-10"></div>
<div><?php _e( 'Schedule name', 'advanced-database-cleaner' ); ?></div>
<input class="aDBc-schedule-input-field" type="text" value="<?php echo $hook_name; ?>" maxlength="25" disabled>
<input type="hidden" name="aDBc_schedule_name" value="<?php echo $hook_name; ?>" maxlength="25">
<div><?php _e( 'Frequency of execution', 'advanced-database-cleaner' ); ?></div>
<select name="aDBc_schedule_repeat" class="aDBc-schedule-input-field">
<?php
$schedules_repeat = array( 'once' => __( 'Once', 'advanced-database-cleaner' ),
'hourly' => __( 'Hourly', 'advanced-database-cleaner' ),
'twicedaily' => __( 'Twice a day', 'advanced-database-cleaner' ),
'daily' => __( 'Daily', 'advanced-database-cleaner' ),
'weekly' => __( 'Weekly', 'advanced-database-cleaner' ),
'monthly' => __( 'Monthly', 'advanced-database-cleaner' )
);
foreach ( $schedules_repeat as $code_repeat => $name_repeat ) {
if ( $code_repeat == $schedule_repeat ) {
echo "<option value='$code_repeat' selected='selected'>$name_repeat</option>";
} else {
echo "<option value='$code_repeat'>$name_repeat</option>";
}
}
?>
</select>
<div><?php _e( 'Start date', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_date" class="aDBc-schedule-input-field" type="date" value="<?php echo $schedule_date; ?>" min="<?php echo date( "Y-m-d" ); ?>">
<div><?php _e( 'Start time (GMT)', 'advanced-database-cleaner' ); ?></div>
<input name="aDBc_time" class="aDBc-schedule-input-field" type="time" value="<?php echo $schedule_time; ?>">
<div><?php _e( 'Perform operations', 'advanced-database-cleaner' ); ?></div>
<div class="aDBc-schedule-radio-container">
<input name="aDBc_operation1" type="checkbox" value="optimize" <?php echo $operation1 == "optimize" ? 'checked' : ''; ?>>
<span style="margin-right:20px"><?php _e( 'Optimize', 'advanced-database-cleaner' ); ?></span>
<input name="aDBc_operation2" type="checkbox" value="repair" <?php echo $operation2 == "repair" ? 'checked' : ''; ?>>
<?php _e( 'Repair', 'advanced-database-cleaner' ); ?>
</div>
<div><?php _e( 'Schedule status', 'advanced-database-cleaner' ); ?></div>
<div class="aDBc-schedule-radio-container">
<input name="aDBc_status" type="radio" value="1" checked>
<span style="margin-right:20px"><?php _e( 'Active', 'advanced-database-cleaner' ); ?></span>
<input name="aDBc_status" type="radio" value="0" <?php echo $schedule_status == "0" ? 'checked' : ''; ?>>
<?php _e( 'Inactive', 'advanced-database-cleaner' ); ?>
</div>
<div class="aDBc-schedule-save-btn-div">
<input class="button-primary" type="submit" value="<?php _e( 'Save the schedule', 'advanced-database-cleaner' ); ?>" style="width:100%"/>
</div>
</div>
</div>
</div>
<?php wp_nonce_field( 'edit_optimize_schedule_nonce', 'edit_optimize_schedule_nonce' ); ?>
</form>
<div class="aDBc-clear-both"></div>
</div>
<?php
}
}
?>

View File

@@ -0,0 +1,126 @@
<!-- style et code ok -->
<div style="max-width:700px">
<form id="aDBc_form" action="" method="post">
<div class="aDBc-edit-correction-title">
<?php echo __( 'Manual correction of the categorization', 'advanced-database-cleaner' ); ?>
</div>
<?php
// Get the current tab
$item_type = $_GET['aDBc_tab'];
// We change the cron tab name to tasks. No problem with tables and options
if ( $item_type == "cron" ) {
$item_type = "tasks";
}
// Open the file in which the items to edit have been saved
$path_items = @fopen( ADBC_UPLOAD_DIR_PATH_TO_ADBC . "/" . $item_type . "_manually_correction_temp.txt", "r" );
if ( $path_items ) {
echo "<div style='margin-top:30px'>";
$items_to_correct_array = array();
while ( ( $item = fgets( $path_items ) ) !== false ) {
$item = trim( $item );
if ( ! empty( $item ) ) {
array_push( $items_to_correct_array, $item );
echo "<span class='aDBc-correction-item'>" . esc_html($item) . "</span>";
}
}
echo "</div>";
fclose( $path_items );
}
?>
<div class="aDBc-clear-both"></div>
<div class="aDBc-correction-new-wrapper">
<div>
<?php
if ( $item_type == "tables" ) {
echo __( 'The tables above belong to:', 'advanced-database-cleaner' );
} elseif ( $item_type == "options" ) {
echo __( 'The options above belong to:', 'advanced-database-cleaner' );
} elseif ( $item_type == "tasks" ) {
echo __( 'The cron tasks above belong to:', 'advanced-database-cleaner' );
}
?>
</div>
<?php
$plugins_folders_names = aDBc_get_plugins_folder_names();
$themes_folders_names = aDBc_get_themes_folder_names();
?>
<select name="new_belongs_to" class="aDBc-correction-belongs-to">
<optgroup label="<?php echo __( 'Plugins', 'advanced-database-cleaner' ); ?>">
<?php
foreach ( $plugins_folders_names as $plugin ) {
echo "<option value='$plugin|p'>" . $plugin . "</option>";
}
?>
</optgroup>
<optgroup label="<?php echo __( 'Themes', 'advanced-database-cleaner' ); ?>">
<?php
foreach ( $themes_folders_names as $theme ) {
echo "<option value='$theme|t'>" . $theme . "</option>";
}
?>
</optgroup>
<optgroup label="<?php echo __( 'WordPress', 'advanced-database-cleaner' ); ?>">
<?php
echo "<option value='w|w'>" . __( 'WordPress core', 'advanced-database-cleaner' ) . "</option>";
?>
</optgroup>
</select>
</div>
<div class="aDBc-clear-both"></div>
<div class="aDBc-correction-btns-div">
<input name="aDBc_correct" class="button-primary aDBc-correction-btn" type="submit" value="<?php _e( 'Save', 'advanced-database-cleaner' ); ?>"/>
<input name="aDBc_cancel" class="button-secondary aDBc-correction-btn" type="submit" value="<?php _e( 'Cancel', 'advanced-database-cleaner' ); ?>"/>
</div>
</form>
</div>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,336 @@
<!-- style et code ok -->
<div class="aDBc-filter-container" style="border-radius:4px">
<div class="aDBc-filter-section">
<span class="aDBc-premium-tooltip">
<?php
$free_style = "";
if ( ADBC_PLUGIN_PLAN == "free" ) {
$free_style = "aDBc-filter-pro-only";
}
?>
<form class="<?php echo $free_style; ?>" method="get">
<?php
// Generate current parameters in URL
foreach ( $_GET as $name => $value ) {
if ( $name != "s" && $name != "paged" && $name != "aDBc_cat" ) {
$name = esc_attr( sanitize_text_field( $name ) );
$value = esc_attr( sanitize_text_field( $value ) );
echo "<input type='hidden' name='$name' value='$value'/>";
}
}
// Return paged to "1" and aDBc_cat to "all" after each filter
echo "<input type='hidden' name='paged' value='1'/>";
echo "<input type='hidden' name='aDBc_cat' value='all'/>";
?>
<div class="aDBc-filter-elements">
<div>
<label class="aDBc-filter-label">
<?php _e('Search for', 'advanced-database-cleaner' ); ?>
</label>
<input class="aDBc-filter-search-input" type="search" placeholder="<?php _e( 'Search for', 'advanced-database-cleaner' ); ?>" name="s" value="<?php echo empty( $_GET['s'] ) ? '' : esc_attr( $_GET['s'] ); ?>"/>
</div>
<?php
// Show this filter tables type only for tables
if ( isset( $_GET['aDBc_tab'] ) && $_GET['aDBc_tab'] == 'tables' ) {
$all_selected = ( isset( $_GET['t_type'] ) && $_GET['t_type'] == 'all' ) ? "selected='selected'" : "";
$optimize_selected = ( isset( $_GET['t_type'] ) && $_GET['t_type'] == 'optimize' ) ? "selected='selected'" : "";
$repair_selected = ( isset( $_GET['t_type'] ) && $_GET['t_type'] == 'repair' ) ? "selected='selected'" : "";
?>
<div>
<label class="aDBc-filter-label">
<?php _e('Table status', 'advanced-database-cleaner' ); ?>
</label>
<select name="t_type" class="aDBc-filter-dropdown-menu" style="width:100px">
<option value="all" <?php echo $all_selected; ?>>
<?php _e( 'All', 'advanced-database-cleaner' ) ?>
</option>
<option value="optimize" <?php echo $optimize_selected; ?>>
<?php
echo __( 'To optimize', 'advanced-database-cleaner' ) . " (" . count( $this->aDBc_tables_name_to_optimize ) . ")"
?>
</option>
<option value="repair" <?php echo $repair_selected; ?>>
<?php
echo __( 'To repair', 'advanced-database-cleaner' ) . " (" . count( $this->aDBc_tables_name_to_repair ) . ")"
?>
</option>
</select>
</div>
<?php
}
// Show autoload only for options
if ( isset( $_GET['aDBc_tab'] ) && $_GET['aDBc_tab'] == 'options' ) {
$all_autoload = ( isset( $_GET['autoload'] ) && $_GET['autoload'] == 'all' ) ? "selected='selected'" : "";
$autoload_yes = ( isset( $_GET['autoload'] ) && $_GET['autoload'] == 'yes' ) ? "selected='selected'" : "";
$autoload_no = ( isset( $_GET['autoload'] ) && $_GET['autoload'] == 'no' ) ? "selected='selected'" : "";
?>
<div>
<label class="aDBc-filter-label">
<?php _e('Autoload', 'advanced-database-cleaner' ); ?>
</label>
<select name="autoload" class="aDBc-filter-dropdown-menu" style="width:100px">
<option value="all" <?php echo $all_autoload; ?>>
<?php _e( 'All', 'advanced-database-cleaner' ); ?>
</option>
<option value="yes" <?php echo $autoload_yes; ?>>
<?php
echo __( 'Yes', 'advanced-database-cleaner' );
if(function_exists('wp_autoload_values_to_autoload')){
echo " [on, auto, auto-on]";
}
?>&nbsp;
</option>
<option value="no" <?php echo $autoload_no; ?>>
<?php
echo __( 'No', 'advanced-database-cleaner' );
if(function_exists('wp_autoload_values_to_autoload')){
echo " [off, auto-off]";
}
?>
</option>
</select>
</div>
<?php
}
?>
<div>
<label class="aDBc-filter-label">
<?php _e( 'Belongs to', 'advanced-database-cleaner' ); ?>
</label>
<select name="belongs_to" class="aDBc-filter-dropdown-menu" style="width:135px">
<option value="all">
<?php _e( 'All', 'advanced-database-cleaner' ); ?>
</option>
<?php
$total_plugins = 0;
$total_themes = 0;
foreach ( $this->array_belongs_to_counts as $name => $info ) {
if ( $info['type'] == "p" ) {
$total_plugins++;
} elseif ( $info['type'] == "t" ) {
$total_themes++;
}
}
?>
<optgroup label="<?php echo __( 'Plugins', 'advanced-database-cleaner' ) . " (" . $total_plugins . ")" ?>">
<?php
foreach ( $this->array_belongs_to_counts as $name => $info ) {
if ( $info['type'] == "p" ) {
$selected = isset( $_GET['belongs_to'] ) && $_GET['belongs_to'] == $name ? "selected='selected'" : "";
echo "<option value='$name'" . $selected . ">" . $name . " (" . $info['count'] .")" . "</option>";
}
}
?>
</optgroup>
<optgroup label="<?php echo __( 'Themes', 'advanced-database-cleaner' ) . " (" . $total_themes . ")" ?>">
<?php
foreach ( $this->array_belongs_to_counts as $name => $info ) {
if ( $info['type'] == "t" ) {
$selected = isset( $_GET['belongs_to'] ) && $_GET['belongs_to'] == $name ? "selected='selected'" : "";
echo "<option value='$name'" . $selected . ">" . $name . " (" . $info['count'] .")" . "</option>";
}
}
?>
</optgroup>
</select>
</div>
<?php
if ( function_exists( 'is_multisite' ) && is_multisite() ){
?>
<div>
<label class="aDBc-filter-label">
<?php _e( 'In site', 'advanced-database-cleaner' ); ?>
</label>
<select name="site" class="aDBc-filter-dropdown-menu" style="width:85px">
<option value=""> <?php _e( 'All', 'advanced-database-cleaner' ); ?> </option>
<?php
global $wpdb;
$blogs_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach ( $blogs_ids as $blog_id ) {
$blog_details = get_blog_details( $blog_id );
$selected = ( isset( $_GET['site'] ) && $_GET['site'] == $blog_id ) ? "selected='selected'" : "";
echo "<option value='$blog_id'". $selected .">" . __( 'Site', 'advanced-database-cleaner' ) . " ". $blog_id . " | " . $blog_details->blogname . "</option>";
}
?>
</select>
</div>
<?php
}
?>
<div>
<label class="aDBc-filter-label" style="visibility:hidden">
Submit
</label>
<input class="button-secondary aDBc-filter-botton" type="submit" value="<?php _e( 'Filter', 'advanced-database-cleaner' ); ?>"/>
</div>
</div>
</form>
<?php
if ( ADBC_PLUGIN_PLAN == "free" ) {
?>
<span style="width:150px" class="aDBc-premium-tooltiptext">
<a href="https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner/" target="_blank">
<?php _e( 'Available in Pro version!', 'advanced-database-cleaner' ); ?>
</a>
</span>
<?php
}
?>
</span>
</div>
<!-- Items per page -->
<div class="aDBc-items-per-page">
<form method="get">
<?php
// Generate current parameters in URL
foreach ( $_GET as $name => $value ) {
if ( $name != "per_page" && $name != "paged" ) {
$name = esc_attr( sanitize_text_field( $name ) );
$value = esc_attr( sanitize_text_field( $value ) );
echo "<input type='hidden' name='$name' value='$value'/>";
}
}
// Return paged to page 1
echo "<input type='hidden' name='paged' value='1'/>";
?>
<div>
<label class="aDBc-filter-label" style="font-weight:normal">
<?php _e( 'Items per page', 'advanced-database-cleaner' ); ?>
</label>
<input name="per_page" class="aDBc-items-per-page-input" type="number" value="<?php echo empty( $_GET['per_page'] ) ? '50' : esc_attr( $_GET['per_page'] ); ?>"/>
<input type="submit" class="button-secondary aDBc-show-botton" value="<?php _e( 'Show', 'advanced-database-cleaner' ); ?>"/>
</div>
</form>
</div>
<?php
if ( ( ! empty( $_GET['s'] ) && trim( $_GET['s'] ) != "" ) ||
! empty( $_GET['t_type'] ) ||
! empty( $_GET['belongs_to'] ) ||
! empty( $_GET['site'] )
) {
// Remove args to delete custom filter
$aDBc_new_URI = $_SERVER['REQUEST_URI'];
$aDBc_new_URI = remove_query_arg( array( 's', 't_type', 'belongs_to', 'site', 'autoload' ), $aDBc_new_URI );
$aDBc_new_URI = add_query_arg( 'aDBc_cat', 'all', $aDBc_new_URI );
?>
<div class="aDBc-delete-custom-filter">
<a style="color:red" href="<?php echo esc_url( $aDBc_new_URI ); ?>">
<?php _e( 'Delete custom filter', 'advanced-database-cleaner' ); ?>
</a>
</div>
<?php
}
?>
</div>

View File

@@ -0,0 +1,676 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Allows plugins to use their own update API.
*
* @author Easy Digital Downloads
* @version 1.9.2
*/
class ADBC_EDD_SL_Plugin_Updater {
private $api_url = '';
private $api_data = array();
private $plugin_file = '';
private $name = '';
private $slug = '';
private $version = '';
private $wp_override = false;
private $beta = false;
private $failed_request_cache_key;
/**
* Class constructor.
*
* @uses plugin_basename()
* @uses hook()
*
* @param string $_api_url The URL pointing to the custom API endpoint.
* @param string $_plugin_file Path to the plugin file.
* @param array $_api_data Optional data to send with API calls.
*/
public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
global $edd_plugin_data;
$this->api_url = trailingslashit( $_api_url );
$this->api_data = $_api_data;
$this->plugin_file = $_plugin_file;
$this->name = plugin_basename( $_plugin_file );
$this->slug = basename( $_plugin_file, '.php' );
$this->version = $_api_data['version'];
$this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
$this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
$this->failed_request_cache_key = 'edd_sl_failed_http_' . md5( $this->api_url );
$edd_plugin_data[ $this->slug ] = $this->api_data;
/**
* Fires after the $edd_plugin_data is setup.
*
* @since x.x.x
*
* @param array $edd_plugin_data Array of EDD SL plugin data.
*/
do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
// Set up hooks.
$this->init();
}
/**
* Set up WordPress filters to hook into WP's update process.
*
* @uses add_filter()
*
* @return void
*/
public function init() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
add_action( 'after_plugin_row', array( $this, 'show_update_notification' ), 10, 2 );
add_action( 'admin_init', array( $this, 'show_changelog' ) );
}
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
* This function dives into the update API just when WordPress creates its update array,
* then adds a custom API call and injects the custom plugin data retrieved from the API.
* It is reassembled from parts of the native WordPress plugin update code.
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
*
* @uses api_request()
*
* @param array $_transient_data Update array build by WordPress.
* @return array Modified update array with custom plugin data.
*/
public function check_update( $_transient_data ) {
global $pagenow;
if ( ! is_object( $_transient_data ) ) {
$_transient_data = new stdClass();
}
if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
return $_transient_data;
}
$current = $this->get_repo_api_data();
if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
if ( version_compare( $this->version, $current->new_version, '<' ) ) {
$_transient_data->response[ $this->name ] = $current;
} else {
// Populating the no_update information is required to support auto-updates in WordPress 5.5.
$_transient_data->no_update[ $this->name ] = $current;
}
}
$_transient_data->last_checked = time();
$_transient_data->checked[ $this->name ] = $this->version;
return $_transient_data;
}
/**
* Get repo API data from store.
* Save to cache.
*
* @return \stdClass
*/
public function get_repo_api_data() {
$version_info = $this->get_cached_version_info();
if ( false === $version_info ) {
$version_info = $this->api_request(
'plugin_latest_version',
array(
'slug' => $this->slug,
'beta' => $this->beta,
)
);
if ( ! $version_info ) {
return false;
}
// This is required for your plugin to support auto-updates in WordPress 5.5.
$version_info->plugin = $this->name;
$version_info->id = $this->name;
$version_info->tested = $this->get_tested_version( $version_info );
$this->set_version_info_cache( $version_info );
}
return $version_info;
}
/**
* Gets the plugin's tested version.
*
* @since 1.9.2
* @param object $version_info
* @return null|string
*/
private function get_tested_version( $version_info ) {
// There is no tested version.
if ( empty( $version_info->tested ) ) {
return null;
}
// Strip off extra version data so the result is x.y or x.y.z.
list( $current_wp_version ) = explode( '-', get_bloginfo( 'version' ) );
// The tested version is greater than or equal to the current WP version, no need to do anything.
if ( version_compare( $version_info->tested, $current_wp_version, '>=' ) ) {
return $version_info->tested;
}
$current_version_parts = explode( '.', $current_wp_version );
$tested_parts = explode( '.', $version_info->tested );
// The current WordPress version is x.y.z, so update the tested version to match it.
if ( isset( $current_version_parts[2] ) && $current_version_parts[0] === $tested_parts[0] && $current_version_parts[1] === $tested_parts[1] ) {
$tested_parts[2] = $current_version_parts[2];
}
return implode( '.', $tested_parts );
}
/**
* Show the update notification on multisite subsites.
*
* @param string $file
* @param array $plugin
*/
public function show_update_notification( $file, $plugin ) {
// Return early if in the network admin, or if this is not a multisite install.
if ( is_network_admin() || ! is_multisite() ) {
return;
}
// Allow single site admins to see that an update is available.
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
if ( $this->name !== $file ) {
return;
}
// Do not print any message if update does not exist.
$update_cache = get_site_transient( 'update_plugins' );
if ( ! isset( $update_cache->response[ $this->name ] ) ) {
if ( ! is_object( $update_cache ) ) {
$update_cache = new stdClass();
}
$update_cache->response[ $this->name ] = $this->get_repo_api_data();
}
// Return early if this plugin isn't in the transient->response or if the site is running the current or newer version of the plugin.
if ( empty( $update_cache->response[ $this->name ] ) || version_compare( $this->version, $update_cache->response[ $this->name ]->new_version, '>=' ) ) {
return;
}
printf(
'<tr class="plugin-update-tr %3$s" id="%1$s-update" data-slug="%1$s" data-plugin="%2$s">',
$this->slug,
$file,
in_array( $this->name, $this->get_active_plugins(), true ) ? 'active' : 'inactive'
);
echo '<td colspan="3" class="plugin-update colspanchange">';
echo '<div class="update-message notice inline notice-warning notice-alt"><p>';
$changelog_link = '';
if ( ! empty( $update_cache->response[ $this->name ]->sections->changelog ) ) {
$changelog_link = add_query_arg(
array(
'edd_sl_action' => 'view_plugin_changelog',
'plugin' => urlencode( $this->name ),
'slug' => urlencode( $this->slug ),
'TB_iframe' => 'true',
'width' => 77,
'height' => 911,
),
self_admin_url( 'index.php' )
);
}
$update_link = add_query_arg(
array(
'action' => 'upgrade-plugin',
'plugin' => urlencode( $this->name ),
),
self_admin_url( 'update.php' )
);
printf(
/* translators: the plugin name. */
esc_html__( 'There is a new version of %1$s available.', 'advanced-database-cleaner' ),
esc_html( $plugin['Name'] )
);
if ( ! current_user_can( 'update_plugins' ) ) {
echo ' ';
esc_html_e( 'Contact your network administrator to install the update.', 'advanced-database-cleaner' );
} elseif ( empty( $update_cache->response[ $this->name ]->package ) && ! empty( $changelog_link ) ) {
echo ' ';
printf(
/* translators: 1. opening anchor tag, do not translate 2. the new plugin version 3. closing anchor tag, do not translate. */
__( '%1$sView version %2$s details%3$s.', 'advanced-database-cleaner' ),
'<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
esc_html( $update_cache->response[ $this->name ]->new_version ),
'</a>'
);
} elseif ( ! empty( $changelog_link ) ) {
echo ' ';
printf(
__( '%1$sView version %2$s details%3$s or %4$supdate now%5$s.', 'advanced-database-cleaner' ),
'<a target="_blank" class="thickbox open-plugin-details-modal" href="' . esc_url( $changelog_link ) . '">',
esc_html( $update_cache->response[ $this->name ]->new_version ),
'</a>',
'<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
'</a>'
);
} else {
printf(
' %1$s%2$s%3$s',
'<a target="_blank" class="update-link" href="' . esc_url( wp_nonce_url( $update_link, 'upgrade-plugin_' . $file ) ) . '">',
esc_html__( 'Update now.', 'advanced-database-cleaner' ),
'</a>'
);
}
do_action( "in_plugin_update_message-{$file}", $plugin, $plugin );
echo '</p></div></td></tr>';
}
/**
* Gets the plugins active in a multisite network.
*
* @return array
*/
private function get_active_plugins() {
$active_plugins = (array) get_option( 'active_plugins' );
$active_network_plugins = (array) get_site_option( 'active_sitewide_plugins' );
return array_merge( $active_plugins, array_keys( $active_network_plugins ) );
}
/**
* Updates information on the "View version x.x details" page with custom data.
*
* @uses api_request()
*
* @param mixed $_data
* @param string $_action
* @param object $_args
* @return object $_data
*/
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
if ( 'plugin_information' !== $_action ) {
return $_data;
}
if ( ! isset( $_args->slug ) || ( $_args->slug !== $this->slug ) ) {
return $_data;
}
$to_send = array(
'slug' => $this->slug,
'is_ssl' => is_ssl(),
'fields' => array(
'banners' => array(),
'reviews' => false,
'icons' => array(),
),
);
// Get the transient where we store the api request for this plugin for 24 hours
$edd_api_request_transient = $this->get_cached_version_info();
//If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
if ( empty( $edd_api_request_transient ) ) {
$api_response = $this->api_request( 'plugin_information', $to_send );
// Expires in 3 hours
$this->set_version_info_cache( $api_response );
if ( false !== $api_response ) {
$_data = $api_response;
}
} else {
$_data = $edd_api_request_transient;
}
// Convert sections into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
$_data->sections = $this->convert_object_to_array( $_data->sections );
}
// Convert banners into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
$_data->banners = $this->convert_object_to_array( $_data->banners );
}
// Convert icons into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
$_data->icons = $this->convert_object_to_array( $_data->icons );
}
// Convert contributors into an associative array, since we're getting an object, but Core expects an array.
if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
$_data->contributors = $this->convert_object_to_array( $_data->contributors );
}
if ( ! isset( $_data->plugin ) ) {
$_data->plugin = $this->name;
}
return $_data;
}
/**
* Convert some objects to arrays when injecting data into the update API
*
* Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
* decoding, they are objects. This method allows us to pass in the object and return an associative array.
*
* @since 3.6.5
*
* @param stdClass $data
*
* @return array
*/
private function convert_object_to_array( $data ) {
if ( ! is_array( $data ) && ! is_object( $data ) ) {
return array();
}
$new_data = array();
foreach ( $data as $key => $value ) {
$new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
}
return $new_data;
}
/**
* Disable SSL verification in order to prevent download update failures
*
* @param array $args
* @param string $url
* @return object $array
*/
public function http_request_args( $args, $url ) {
if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
$args['sslverify'] = $this->verify_ssl();
}
return $args;
}
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @param string $_action The requested action.
* @param array $_data Parameters for the API action.
* @return false|object|void
*/
private function api_request( $_action, $_data ) {
$data = array_merge( $this->api_data, $_data );
if ( $data['slug'] !== $this->slug ) {
return;
}
// Don't allow a plugin to ping itself
if ( trailingslashit( home_url() ) === $this->api_url ) {
return false;
}
if ( $this->request_recently_failed() ) {
return false;
}
return $this->get_version_from_remote();
}
/**
* Determines if a request has recently failed.
*
* @since 1.9.1
*
* @return bool
*/
private function request_recently_failed() {
$failed_request_details = get_option( $this->failed_request_cache_key );
// Request has never failed.
if ( empty( $failed_request_details ) || ! is_numeric( $failed_request_details ) ) {
return false;
}
/*
* Request previously failed, but the timeout has expired.
* This means we're allowed to try again.
*/
if ( time() > $failed_request_details ) {
delete_option( $this->failed_request_cache_key );
return false;
}
return true;
}
/**
* Logs a failed HTTP request for this API URL.
* We set a timestamp for 1 hour from now. This prevents future API requests from being
* made to this domain for 1 hour. Once the timestamp is in the past, API requests
* will be allowed again. This way if the site is down for some reason we don't bombard
* it with failed API requests.
*
* @see EDD_SL_Plugin_Updater::request_recently_failed
*
* @since 1.9.1
*/
private function log_failed_request() {
update_option( $this->failed_request_cache_key, strtotime( '+1 hour' ) );
}
/**
* If available, show the changelog for sites in a multisite install.
*/
public function show_changelog() {
if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' !== $_REQUEST['edd_sl_action'] ) {
return;
}
if ( empty( $_REQUEST['plugin'] ) ) {
return;
}
if ( empty( $_REQUEST['slug'] ) || $this->slug !== $_REQUEST['slug'] ) {
return;
}
if ( ! current_user_can( 'update_plugins' ) ) {
wp_die( esc_html__( 'You do not have permission to install plugin updates', 'advanced-database-cleaner' ), esc_html__( 'Error', 'advanced-database-cleaner' ), array( 'response' => 403 ) );
}
$version_info = $this->get_repo_api_data();
if ( isset( $version_info->sections ) ) {
$sections = $this->convert_object_to_array( $version_info->sections );
if ( ! empty( $sections['changelog'] ) ) {
echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
}
}
exit;
}
/**
* Gets the current version information from the remote site.
*
* @return array|false
*/
private function get_version_from_remote() {
$api_params = array(
'edd_action' => 'get_version',
'license' => ! empty( $this->api_data['license'] ) ? $this->api_data['license'] : '',
'item_name' => isset( $this->api_data['item_name'] ) ? $this->api_data['item_name'] : false,
'item_id' => isset( $this->api_data['item_id'] ) ? $this->api_data['item_id'] : false,
'version' => isset( $this->api_data['version'] ) ? $this->api_data['version'] : false,
'slug' => $this->slug,
'author' => $this->api_data['author'],
'url' => home_url(),
'beta' => $this->beta,
'php_version' => phpversion(),
'wp_version' => get_bloginfo( 'version' ),
);
/**
* Filters the parameters sent in the API request.
*
* @param array $api_params The array of data sent in the request.
* @param array $this->api_data The array of data set up in the class constructor.
* @param string $this->plugin_file The full path and filename of the file.
*/
$api_params = apply_filters( 'edd_sl_plugin_updater_api_params', $api_params, $this->api_data, $this->plugin_file );
$request = wp_remote_post(
$this->api_url,
array(
'timeout' => 15,
'sslverify' => $this->verify_ssl(),
'body' => $api_params,
)
);
if ( is_wp_error( $request ) || ( 200 !== wp_remote_retrieve_response_code( $request ) ) ) {
$this->log_failed_request();
return false;
}
$request = json_decode( wp_remote_retrieve_body( $request ) );
if ( $request && isset( $request->sections ) ) {
$request->sections = maybe_unserialize( $request->sections );
} else {
$request = false;
}
if ( $request && isset( $request->banners ) ) {
$request->banners = maybe_unserialize( $request->banners );
}
if ( $request && isset( $request->icons ) ) {
$request->icons = maybe_unserialize( $request->icons );
}
if ( ! empty( $request->sections ) ) {
foreach ( $request->sections as $key => $section ) {
$request->$key = (array) $section;
}
}
return $request;
}
/**
* Get the version info from the cache, if it exists.
*
* @param string $cache_key
* @return object
*/
public function get_cached_version_info( $cache_key = '' ) {
if ( empty( $cache_key ) ) {
$cache_key = $this->get_cache_key();
}
$cache = get_option( $cache_key );
// Cache is expired
if ( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
return false;
}
// We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
$cache['value'] = json_decode( $cache['value'] );
if ( ! empty( $cache['value']->icons ) ) {
$cache['value']->icons = (array) $cache['value']->icons;
}
return $cache['value'];
}
/**
* Adds the plugin version information to the database.
*
* @param string $value
* @param string $cache_key
*/
public function set_version_info_cache( $value = '', $cache_key = '' ) {
if ( empty( $cache_key ) ) {
$cache_key = $this->get_cache_key();
}
$data = array(
'timeout' => strtotime( '+3 hours', time() ),
'value' => wp_json_encode( $value ),
);
update_option( $cache_key, $data, 'no' );
// Delete the duplicate option
delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
}
/**
* Returns if the SSL of the store should be verified.
*
* @since 1.6.13
* @return bool
*/
private function verify_ssl() {
return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
}
/**
* Gets the unique key (option name) for a plugin.
*
* @since 1.9.0
* @return string
*/
private function get_cache_key() {
$string = $this->slug . $this->api_data['license'] . $this->beta;
return 'edd_sl_' . md5( serialize( $string ) );
}
}

View File

@@ -0,0 +1,378 @@
<?php
/**
* For further details please visit:
* http://docs.easydigitaldownloads.com/article/383-automatic-upgrades-for-wordpress-plugins
*/
define( 'ADBC_EDD_STORE_URL', 'https://sigmaplugin.com' );
define( 'ADBC_EDD_ITEM_ID', 10 );
define( 'ADBC_EDD_ITEM_NAME', 'WordPress Advanced Database Cleaner' );
if ( ! class_exists( 'ADBC_EDD_SL_Plugin_Updater' ) ) {
// load our custom updater
include dirname( __FILE__ ) . '/ADBC_EDD_SL_Plugin_Updater.php';
}
/**
* Initialize the updater. Hooked into `init` to work with the
* wp_version_check cron job, which allows auto-updates.
*/
function aDBc_edd_sl_plugin_updater() {
// To support auto-updates, this needs to run during the wp_version_check cron job for privileged users.
$doing_cron = defined( 'DOING_CRON' ) && DOING_CRON;
if ( ! current_user_can( 'manage_options' ) && ! $doing_cron ) {
return;
}
// retrieve our license key from the DB
$license_key = trim( get_option( 'aDBc_edd_license_key' ) );
// setup the updater
$edd_updater = new ADBC_EDD_SL_Plugin_Updater( ADBC_EDD_STORE_URL, ADBC_MAIN_PLUGIN_FILE_PATH, array(
'version' => ADBC_PLUGIN_VERSION,
'license' => $license_key,
'item_id' => ADBC_EDD_ITEM_ID,
'author' => 'Younes JFR.',
'beta' => false,
)
);
}
add_action( 'init', 'aDBc_edd_sl_plugin_updater' );
/**
* License page
*
* @return void
*/
function aDBc_edd_license_page() {
$license = get_option('aDBc_edd_license_key');
$status = get_option('aDBc_edd_license_status');
if ( $status !== false && $status == 'valid' ) {
$license_key_hidden = substr( $license, 0, 4 ) . "************************" . substr( $license, -4 );
$license_status = __( 'Active', 'advanced-database-cleaner' );
$color = "color:green";
$activate_btn_style = "display:none";
$deactivate_btn_style = "";
$input_disabled = " disabled";
} else {
$license_key_hidden = "";
$license_status = __( 'Inactive', 'advanced-database-cleaner' );
$color = "color:red";
$activate_btn_style = "";
$deactivate_btn_style = "display:none";
$input_disabled = "";
}
?>
<div class="aDBc-content-max-width aDBc-padding-20">
<div class="aDBc-license-container">
<div class="aDBc-status-box">
<div class="aDBc-div-status">
<span class="aDBc-license-status-label"><?php _e( 'Status:', 'advanced-database-cleaner' ); ?></span>
<span id="aDBc_license_status" style="<?php echo $color; ?>" class="aDBc-license-status">
<?php echo $license_status ?>
</span>
</div>
<div id="aDBc_check_license_btn" style="<?php echo $deactivate_btn_style; ?>" class="aDBc-check-license-btn">
<a>
<span class="dashicons dashicons-update-alt"></span>
<?php _e( 'Check status', 'advanced-database-cleaner' ); ?>
</a>
</div>
<div class="aDBc-license-account">
<a href="https://sigmaplugin.com/login?utm_source=license_tab&utm_medium=adbc_plugin&utm_campaign=plugins" target="_blank">
<span class="dashicons dashicons-admin-users aDBc-license-icon"></span>
<?php _e( 'My account', 'advanced-database-cleaner' ); ?>
</a>
</div>
</div>
<div class="aDBc-license-box">
<input id="aDBc_license_key_input" class="aDBc-license-key-input" placeholder="<?php _e( 'License key', 'advanced-database-cleaner' ); ?>" type="text" value="<?php echo $license_key_hidden; ?>" <?php echo $input_disabled; ?>/>
<div id="aDBc_activate_license_btn" style="<?php echo $activate_btn_style; ?>" class="aDBc-license-btn">
<span class="dashicons dashicons-admin-links aDBc-license-icon"></span>
<?php _e( 'Activate license', 'advanced-database-cleaner' ); ?>
</div>
<div id="aDBc_deactivate_license_btn" style="<?php echo $deactivate_btn_style; ?>" class="aDBc-license-btn">
<span class="dashicons dashicons-editor-unlink aDBc-license-icon"></span>
<?php _e( 'Deactivate license', 'advanced-database-cleaner' ); ?>
</div>
</div>
</div>
</div>
<?php
}
/**
* Activate/deactivate/check the license key.
*
* @return void
*/
function aDBc_license_actions_callback() {
// Check nonce and user capabilities
if ( false === check_ajax_referer( 'aDBc_nonce', 'security', false ) || ! current_user_can( 'administrator' ) )
wp_send_json_error( __( 'Security check failed!', 'advanced-database-cleaner' ) );
// Get button action
$aDBc_edd_action = sanitize_text_field( $_REQUEST['aDBc_edd_action'] );
switch ( $aDBc_edd_action ) {
case 'aDBc_activate_license_btn':
$license = trim( sanitize_text_field( $_REQUEST['license_key'] ) );
$edd_action = "activate_license";
break;
case 'aDBc_deactivate_license_btn':
$license = trim( get_option( 'aDBc_edd_license_key' ) );
$edd_action = "deactivate_license";
break;
case 'aDBc_check_license_btn':
$license = trim( get_option( 'aDBc_edd_license_key' ) );
$edd_action = "check_license";
break;
default:
wp_send_json_error( __( 'Cannot proceed!', 'advanced-database-cleaner' ) );
break;
}
if ( false === $license || empty( $license ) )
wp_send_json_error( __( 'Empty license field!', 'advanced-database-cleaner' ) );
// Data to send in our API request
$api_params = array(
'edd_action' => $edd_action,
'license' => $license,
'item_id' => ADBC_EDD_ITEM_ID,
'item_name' => rawurlencode( ADBC_EDD_ITEM_NAME ),
'url' => home_url(),
'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
);
// Call the custom API
$response = wp_remote_post(
ADBC_EDD_STORE_URL,
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params,
)
);
// make sure the response came back okay
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
if ( is_wp_error( $response ) ) {
wp_send_json_error( $response->get_error_message() );
} else {
wp_send_json_error( __( 'An error occurred, please try again.', 'advanced-database-cleaner' ) );
}
}
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( $edd_action == "activate_license" ) {
if ( false === $license_data->success ) {
switch ( $license_data->error ) {
case 'expired':
$message = sprintf(
/* translators: the license key expiration date */
__( 'Your license key expired on %s.', 'advanced-database-cleaner' ),
date_i18n( get_option( 'date_format' ), strtotime( $license_data->expires, current_time( 'timestamp' ) ) )
);
break;
case 'disabled':
case 'revoked':
$message = __( 'Your license key has been disabled.', 'advanced-database-cleaner' );
break;
case 'missing':
$message = __( 'Invalid license.', 'advanced-database-cleaner' );
break;
case 'invalid':
case 'site_inactive':
$message = __( 'Your license is not active for this URL.', 'advanced-database-cleaner' );
break;
case 'item_name_mismatch':
/* translators: the plugin name */
$message = sprintf( __( 'This appears to be an invalid license key for %s.', 'advanced-database-cleaner' ), ADBC_EDD_ITEM_NAME );
break;
case 'no_activations_left':
$message = __( 'Your license key has reached its activation limit.', 'advanced-database-cleaner' );
break;
default:
$message = __( 'An error has occurred, please try again.', 'advanced-database-cleaner' );
break;
}
wp_send_json_error( sanitize_text_field( $message ) );
}
// $license_data->license will be either "valid" or "invalid"
if ( 'valid' === $license_data->license ) {
update_option( 'aDBc_edd_license_key', $license, 'no' );
update_option( 'aDBc_edd_license_status', $license_data->license, 'no' );
wp_send_json_success( __( 'Activated!', 'advanced-database-cleaner' ) );
} else {
wp_send_json_error( __( 'License cannot be activated.', 'advanced-database-cleaner' ) );
}
} else if ( $edd_action == "check_license" ) {
// $license_data->license will be either "valid" or "invalid"
if ( 'valid' === $license_data->license ) {
wp_send_json_success( __( 'Your license is valid.', 'advanced-database-cleaner' ) );
} else {
wp_send_json_error( __( 'Your license is no longer valid.', 'advanced-database-cleaner' ) );
}
} else if ( $edd_action == "deactivate_license" ) {
// $license_data->license will be either "deactivated" or "failed"
// if ( 'deactivated' === $license_data->license ) {
delete_option( 'aDBc_edd_license_key' );
delete_option( 'aDBc_edd_license_status' );
wp_send_json_success( __( 'Deactivated!', 'advanced-database-cleaner' ) );
// } else {
// wp_send_json_error( __( 'License cannot be deactivated, please try again.', 'advanced-database-cleaner' ) );
// }
}
// If we are here, maybe un unknown error occurred
wp_send_json_error( __( 'Unknown error occurred, please try again.', 'advanced-database-cleaner' ) );
}
/**
* Checks if a license has been activated
*
* @return bool true if activated, false if not
*/
function aDBc_edd_is_license_activated() {
$license_status = trim( get_option( 'aDBc_edd_license_status') );
if ( $license_status == 'valid' ) {
return true;
} else {
return false;
}
}
/**
* Deactivate a license key after uninstall. This will descrease the site count
*
* @return void
*/
function aDBc_edd_deactivate_license_after_uninstall() {
$license = trim( sanitize_text_field( get_option( 'aDBc_edd_license_key' ) ) );
// data to send in our API request
$api_params = array(
'edd_action' => 'deactivate_license',
'license' => $license,
'item_id' => ADBC_EDD_ITEM_ID,
'item_name' => rawurlencode( ADBC_EDD_ITEM_NAME ),
'url' => home_url(),
'environment' => function_exists( 'wp_get_environment_type' ) ? wp_get_environment_type() : 'production',
);
// Call the custom API.
$response = wp_remote_post(
ADBC_EDD_STORE_URL,
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params
)
);
}

View File

@@ -0,0 +1,22 @@
<?php
if(isset($_GET['aDBc_view'])){
if($_GET['aDBc_view'] == "add_optimize_schedule"){
include_once 'custom-schedule-view/class_add_optimize_schedule.php';
new ADBC_SCHEDULE_OPTIMIZE();
}else if($_GET['aDBc_view'] == "edit_optimize_schedule"){
include_once 'custom-schedule-view/class_edit_optimize_schedule.php';
new EDIT_SCHEDULE_OPTIMIZE();
}
}else{
// Else return the general clean-up page
include_once 'class_clean_tables.php';
}
?>

View File

@@ -0,0 +1,228 @@
<?php
global $wpdb, $wp_version;
// DB size
$aDBc_db_size = $wpdb->get_var("SELECT sum(round(((data_length + index_length) / 1024), 2)) FROM information_schema.tables WHERE table_schema = '" . DB_NAME . "'");
if($aDBc_db_size >= 1024){
$aDBc_db_size = round(($aDBc_db_size / 1024), 2) . " MB";
}else{
$aDBc_db_size = round($aDBc_db_size, 2) . " KB";
}
// Total tables
$aDBc_total_tables = $wpdb->get_var("SELECT count(*) FROM information_schema.tables WHERE table_schema = '" . DB_NAME . "'");
// Total options
if(function_exists('is_multisite') && is_multisite()){
$aDBc_options_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __('Indicates the total number of rows in your option tables of all your network sites, including transients...','advanced-database-cleaner') ." </span>
</span>";
}else{
$aDBc_options_toolip = "<span class='aDBc-tooltips-headers'>
<img class='aDBc-info-image' src='". ADBC_PLUGIN_DIR_PATH . '/images/information2.svg' . "'/>
<span>" . __('Indicates the total number of rows in your options table, including transients...','advanced-database-cleaner') ." </span>
</span>";
}
// Total options
$aDBc_total_options = 0;
if(function_exists('is_multisite') && is_multisite()){
$blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach($blogs_ids as $blog_id){
switch_to_blog($blog_id);
global $wpdb;
$aDBc_total_options += $wpdb->get_var("SELECT count(*) FROM $wpdb->options");
restore_current_blog();
}
}else{
// Count total options
$aDBc_total_options = $wpdb->get_var("SELECT count(*) FROM $wpdb->options");
}
// Total scheduled tasks
$aDBc_all_tasks = aDBc_get_all_scheduled_tasks();
$aDBc_total_tasks = 0;
if(function_exists('is_multisite') && is_multisite()){
foreach($aDBc_all_tasks as $hook => $task_info){
foreach($task_info['sites'] as $site => $info){
$aDBc_total_tasks += count($task_info['sites'][$site]['args']);
}
}
}else{
foreach($aDBc_all_tasks as $hook => $task_info){
$aDBc_total_tasks += count($task_info['sites'][1]['args']);
}
}
// Is MU?
if(function_exists('is_multisite') && is_multisite()){
$aDBc_is_mu = __('Yes', 'advanced-database-cleaner');
$aDBc_number_sites = $wpdb->get_var("SELECT count(*) FROM $wpdb->blogs");
}else{
$aDBc_is_mu = __('No', 'advanced-database-cleaner');
$aDBc_number_sites = "1";
}
?>
<div class="aDBc-content-max-width">
<div class="aDBc-overview-box">
<div class="aDBc-overview-box-head"><?php _e('Overview', 'advanced-database-cleaner'); ?></div>
<ul>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('WP Version', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo $wp_version ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('Database size', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo $aDBc_db_size ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('Total tables', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo $aDBc_total_tables ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php echo __('Total options', 'advanced-database-cleaner') . $aDBc_options_toolip ?> :
</div>
<div class="aDBc-float-left"><?php echo $aDBc_total_options ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('Total cron tasks', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo $aDBc_total_tasks ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('WP multisite Enabled ?', 'advanced-database-cleaner'); ?>
</div>
<div class="aDBc-float-left"><?php echo $aDBc_is_mu ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('Number of sites', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo $aDBc_number_sites ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('Script Max timeout', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo ADBC_ORIGINAL_TIMEOUT . " ". __('seconds', 'advanced-database-cleaner') ?></div>
</li>
<li>
<div class="aDBc-overview-text-left">
<span class="dashicons dashicons-yes aDBc-overview-dashicon"></span>
<?php _e('Local time', 'advanced-database-cleaner'); ?> :
</div>
<div class="aDBc-float-left"><?php echo date_i18n('Y-m-d H:i:s') ?></div>
</li>
</ul>
</div>
<div class="aDBc-overview-box">
<div class="aDBc-overview-box-head"><?php _e('Settings', 'advanced-database-cleaner') ?></div>
<form action="" method="post">
<ul>
<?php
$aDBc_settings = get_option('aDBc_settings');
$in_main_site_msg = "";
if(is_multisite()){
$in_main_site_msg = __('(In main site only)', 'advanced-database-cleaner');
?>
<li style="padding-top:10px;padding-bottom:10px">
<input type="checkbox" name="aDBc_network_menu" <?php echo (!empty($aDBc_settings['network_menu']) && $aDBc_settings['network_menu'] != "0") ? "checked='checked'" : "" ?>/>
<?php _e('Show network plugin menu', 'advanced-database-cleaner'); ?>
<div class="aDBc-overview-setting-desc">
<?php _e('Displays a menu at the left side of your network admin panel', 'advanced-database-cleaner'); ?>
</div>
</li>
<?php
}
?>
<li style="padding-top:10px;padding-bottom:10px">
<input type="checkbox" name="aDBc_left_menu" <?php echo (!empty($aDBc_settings['left_menu']) && $aDBc_settings['left_menu'] != "0") ? "checked='checked'" : "" ?>/>
<?php echo __('Show plugin left menu', 'advanced-database-cleaner') . ' ' . $in_main_site_msg; ?>
<div class="aDBc-overview-setting-desc">
<?php _e('Displays a menu at the left side of your WP admin', 'advanced-database-cleaner'); ?>
</div>
</li>
<li style="padding-top:10px;padding-bottom:10px">
<input type="checkbox" name="aDBc_menu_under_tools" <?php echo (!empty($aDBc_settings['menu_under_tools']) && $aDBc_settings['menu_under_tools'] != "0") ? "checked='checked'" : "" ?>/>
<?php echo __('Show plugin menu under tools', 'advanced-database-cleaner') . ' ' . $in_main_site_msg;; ?>
<div class="aDBc-overview-setting-desc">
<?php _e('Displays a menu under "tools" menu', 'advanced-database-cleaner'); ?>
</div>
</li>
<?php
if ( ADBC_PLUGIN_PLAN == "free" ) {
?>
<li>
<input type="checkbox" name="aDBc_hide_premium_tab" <?php echo (!empty($aDBc_settings['hide_premium_tab']) && $aDBc_settings['hide_premium_tab']) == '1' ? "checked='checked'" : ""?>/>
<?php _e('Hide premium tab', 'advanced-database-cleaner'); ?>
<div class="aDBc-overview-setting-desc">
<?php _e('If checked, it will hide the above premium tab', 'advanced-database-cleaner'); ?>
</div>
</li>
<?php
}
?>
</ul>
<div id="aDBc_save_settings" class="button-primary aDBc-save-settings">
<span id="aDBc_save_icon" class="dashicons dashicons-saved aDBc-button-icon"></span>
<?php _e( 'Save settings', 'advanced-database-cleaner' ); ?>
</div>
</form>
</div>
<div class="aDBc-clear-both"></div>
</div>

View File

@@ -0,0 +1,111 @@
<!-- style et code ok -->
<div class="aDBc-content-max-width aDBc-margin-t-20">
<div class="aDBc-vertical-box">
<div><?php _e( 'Need more features ?', 'advanced-database-cleaner' ); ?></div>
<div><?php _e( 'Find more advanced features!', 'advanced-database-cleaner' ); ?></div>
<div><img class="aDBc-premium-img" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/features.png'?>"/></div>
<div>
<ul>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Filter & search specific items', 'advanced-database-cleaner' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Detect orphaned options', 'advanced-database-cleaner' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Detect orphaned tables', 'advanced-database-cleaner' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Detect orphaned cron tasks', 'advanced-database-cleaner' ); ?>
</li>
</ul>
</div>
</div>
<div class="aDBc-vertical-box">
<div><?php _e( 'Need support as well ?', 'advanced-database-cleaner' ); ?></div>
<div><?php _e( 'We are available to support you!', 'advanced-database-cleaner' ); ?></div>
<div><img class="aDBc-premium-img" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/help.png'?>"/></div>
<div>
<ul>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Get quick support', 'advanced-database-cleaner' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Get technical support', 'advanced-database-cleaner' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'No additional fees', 'advanced-database-cleaner' ); ?>
</li>
<li>
<span class="dashicons dashicons-yes"></span>
<?php _e( 'Great support service!', 'advanced-database-cleaner' ); ?>
</li>
</ul>
</div>
</div>
<div class="aDBc-vertical-box">
<?php
$product_url = "https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner";
?>
<div>
<a href="<?php echo $product_url; ?>" target="_blank"><?php _e( 'Buy now!', 'advanced-database-cleaner' ); ?></a>
</div>
<div><?php _e( 'Buy now and get all pro features!', 'advanced-database-cleaner' ); ?></div>
<div>
<a href="<?php echo $product_url; ?>" target="_blank">
<img class="aDBc-premium-img" src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/premium_ok.png'?>"/>
</a>
</div>
<div>
<a href="<?php echo $product_url; ?>" target="_blank">
<div class="aDBc-purchase-btn">
<img src="<?php echo ADBC_PLUGIN_DIR_PATH . '/images/order_now.png'?>"/>
</div>
</a>
</div>
</div>
<div class="aDBc-clear-both"></div>
</div>

View File

@@ -0,0 +1,38 @@
<!-- style et code ok -->
<div class="aDBc-sidebar">
<div class="aDBc-upgrade">
<a target="_blank" href="https://sigmaplugin.com/downloads/wordpress-advanced-database-cleaner">
<img src="<?php echo ADBC_PLUGIN_DIR_PATH; ?>/images/premium.svg" />
<h3><?php _e( 'Upgrade to Pro', 'advanced-database-cleaner' ); ?></h3>
<ul>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Filter & search specific items', 'advanced-database-cleaner' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Detect orphaned options', 'advanced-database-cleaner' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Detect orphaned tables', 'advanced-database-cleaner' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Detect orphaned cron tasks', 'advanced-database-cleaner' ); ?></li>
<li><span class="dashicons dashicons-yes"></span> <?php _e( 'Premium & technical support', 'advanced-database-cleaner' ); ?></li>
</ul>
<div>
<?php echo __( 'The price will increase soon! Buy now at lower price!', 'advanced-database-cleaner' ); ?>
</div>
</a>
</div>
</div>