prefix . AmazonWishlist_For_WordPress::cache_table; $options = array( 'nonce' => array ( 'Type' => 'nonce', 'Value' => 'alx-cache-manage' ), 'hds1' => array ( 'Type' => 'section', 'Value' => __('Cache Settings', 'amazon-link'), 'Description' => __('Settings to control the Cache behaviour.','amazon-link'), 'Section_Class' => 'al_subhead1', 'Title_Class' => 'al_section_head'), 'cache_age' => array ( 'Name' => __('Cache Data Age', 'amazon-link'), 'Description' => __('Max age in hours of the data held in the Amazon Link Cache', 'amazon-link'), 'Type' => 'text', 'Default' => '48', 'Class' => 'al_border'), 'cache_enabled' => array ( 'Type' => 'backend', 'Default' => '0'), ); $options = alx_cache_option_list($options); $options['end1'] = array ( 'Type' => 'end' ); $options['update'] = array ( 'Type' => 'buttons', 'Buttons' => array ( __('Update Options', 'amazon-link') => array( 'Action' => 'alx-cache-action', 'Hint' => __( 'Update Settings', 'amazon-link'), 'Class' => 'button-primary') ) ); $options['hds2']= array ( 'Type' => 'section', 'Value' => __('Cache Info', 'amazon-link'), 'Description' => __('Cache Health Check Results.','amazon-link'), 'Section_Class' => 'al_subhead1', 'Title_Class' => 'al_section_head'); $options['info']= array ( 'Type' => 'title', 'Value' => __('', 'amazon-link'), 'Title_Class' => 'al_para'); $options['end2'] = array ( 'Type' => 'end' ); $options['hds3']= array ( 'Type' => 'section', 'Value' => __('Cache Control', 'amazon-link'), 'Description' => __('Actions to Perform Globally on the Cache.','amazon-link'), 'Section_Class' => 'al_subhead1', 'Title_Class' => 'al_section_head'); $options['cache_c'] = array ( 'Type' => 'buttons', 'Buttons' => array( __('Enable Cache', 'amazon-link' ) => array( 'Hint' => __('Install the sql database table to cache data retrieved from Amazon.', 'amazon-link'), 'Class' => 'button-secondary', 'Action' => 'alx-cache-action'), __('Disable Cache', 'amazon-link' ) => array( 'Hint' => __('Remove the Amazon Link cache database table.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'alx-cache-action'), __('Enable Refresh', 'amazon-link' ) => array( 'Hint' => __('Enable automatic Amazon Link Product cache refreshing.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'alx-cache-action'), __('Disable Refresh', 'amazon-link' ) => array( 'Hint' => __('Disable automatic Amazon Link Product cache refreshing.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'alx-cache-action'), __('Test Refresh', 'amazon-link' ) => array( 'Hint' => __('Test Run Cache Refresh Cron Task.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'alx-cache-action'), __('Flush Cache', 'amazon-link' ) => array( 'Hint' => __('Delete all data in the Amazon Link cache.', 'amazon-link'),'Class' => 'button-secondary', 'Action' => 'alx-cache-action') ) ); $options['end3'] = array ( 'Type' => 'end' ); $opts = $al->get_default_settings(); $age = $opts['cache_max_age']; $cache_table = $wpdb->prefix . AmazonWishlist_For_WordPress::cache_table; /*****************************************************************************************/ // See if the user has posted us some information // If they did, the admin Nonce should be set. $Action = (isset($_POST[ 'alx-cache-action' ]) && check_admin_referer( 'alx-cache-manage' )) ? $_POST[ 'alx-cache-action' ] : 'No Action'; if( $Action == __('Update Options', 'amazon-link') ) { /************************************************************************************/ /* * Process the options selected by the User */ foreach ($options as $optName => $optDetails) { if (isset($optDetails['Name'])) { if (!isset($_POST[$optName])) $_POST[$optName] = NULL; // Read their posted value $opts[$optName] = stripslashes($_POST[$optName]); } } $update = __('Options saved.', 'amazon-link' ); /************************************************************************************/ /* * Now process the actions */ // Cache Actions } else if ( $Action == __('Enable Cache', 'amazon-link')) { if ($al->cache_install()) { $update = __('Amazon Data Cache Enabled', 'amazon-link'); $opts['cache_enabled'] = 1; } } else if ( $Action == __('Disable Cache', 'amazon-link')) { if ($al->cache_remove()) { $update = __('Amazon Data Cache Disabled and Removed', 'amazon-link'); $opts['cache_enabled'] = 0; } } else if ( $Action == __('Flush Cache', 'amazon-link')) { if ($al->cache_empty()) { $update = __('Amazon Data Cache Emptied', 'amazon-link'); } } else if ( $Action == __('Enable Refresh', 'amazon-link')) { if (alx_cache_enable_cron($al)) { $opts['cache_cron'] = 1; $update = __('Amazon Background Refresh Task Enabled', 'amazon-link'); } } else if ( $Action == __('Disable Refresh', 'amazon-link')) { if (alx_cache_disable_cron($al)) { $opts['cache_cron'] = 0; $update = __('Amazon Background Refresh Task Disabled', 'amazon-link'); } } else if ( $Action == __('Test Refresh', 'amazon-link')) { alx_cache_refresh_entries(); $update = __('Amazon Data Cache Refresh Run', 'amazon-link'); } // If Enabled then take the opportunity to flush old data if (!empty($opts['cache_enabled'])) { $options ['cache_c']['Buttons'][__('Enable Cache', 'amazon-link' )]['Disabled'] = 1; } else { $options ['cache_c']['Buttons'][__('Disable Cache', 'amazon-link' )]['Disabled'] = 1; $options ['cache_c']['Buttons'][__('Flush Cache', 'amazon-link' )]['Disabled'] = 1; } if (!empty($opts['cache_cron'])) { $options ['cache_c']['Buttons'][__('Enable Refresh', 'amazon-link' )]['Disabled'] = 1; } else { $options ['cache_c']['Buttons'][__('Disable Refresh', 'amazon-link' )]['Disabled'] = 1; } if (isset($update)) { // ********************************************************** // Put an options updated message on the screen echo '
'. $update . '
Cache Refresh Scheduled for: $cache_date. Cache Items Expired: $cache_outofdate/$cache_total. Raw Times: Now=".microtime(true)." Scheduled=$timestamp
"; } $al->form->displayForm($options,$opts); } function alx_cache_show_entries_panel ($post, $args) { global $wpdb; $al = $args['args']; $cache_table = $wpdb->prefix . AmazonWishlist_For_WordPress::cache_table; $Action = (isset($_POST[ 'alx-cache-action' ]) && check_admin_referer( 'alx-cache-manage' )) ? $_POST[ 'alx-cache-action' ] : 'No Action'; /************************************************************************************/ /* * Process the actions selected by the User */ if (($Action == __('Remove Entry','amazon-link')) || ($Action == __('Refresh Entry','amazon-link'))) { /* Remove Entry from the Cache */ if (!empty($_POST['cc']) && !empty($_POST['asin'])) { $cc = $_POST['cc']; $asin = $_POST['asin']; $sql = "DELETE FROM $cache_table WHERE `asin` = '$asin' AND `cc` = '$cc';"; $wpdb->query($sql); $update = __('Entry for '. $asin .' in '. $cc . ' locale removed from Cache.','amazon-link'); } } if (($Action == __('Refresh Entry','amazon-link')) ) { /* Lookup the item again */ if (!empty($_POST['cc']) && !empty($_POST['asin'])) { $settings = $al->get_default_settings(); $cc = $_POST['cc']; $asin = $_POST['asin']; $settings['localise'] = 0; $settings['default_cc'] = $cc; $al->cached_query($asin, $settings); $update = __('Cache Data Refreshed for '. $asin. ' in '. $cc .' locale.','amazon-link'); } } if (isset($update)) { // ********************************************************** // Put an options updated message on the screen echo ''. $update . '
"; print_r($item); echo ""; $settings['default_cc'] = $item['cc']; $sql = "DELETE FROM $cache_table WHERE asin LIKE '".$item['asin']."' AND cc LIKE '".$item['cc']."'"; $wpdb->query($sql); $awlfw->cached_query($item['asin'], $settings); } } function alx_cache_display_row($data, $al) { $country = $al->get_country_data(); $settings = $al->get_default_settings(); $options = array( 'nonce' => array ( 'Type' => 'nonce', 'Value' => 'alx-cache-manage' ), 'asin' => array ( 'Type' => 'hidden'), 'cc' => array ( 'Type' => 'hidden'), 'details' => array ( 'Type' => 'title', 'Name' => 'Item Details', 'Buttons' => array ( __('Remove Entry', 'amazon-link') => array( 'Action' => 'alx-cache-action', 'Hint' => __( 'Remove this entry from the cache', 'amazon-link'), 'Class' => 'button-secondary'), __('Refresh Entry', 'amazon-link') => array( 'Action' => 'alx-cache-action', 'Hint' => __( 'Fetch latest data from Amazon for this entry.', 'amazon-link'), 'Class' => 'button-secondary') ) ) ); if (!empty($data['expired'])) { $expired = '
';
} else {
$expired = '';
}
if ( empty($data['found'])) {
$expired .= ' !';
}
$id = rand();
$raw_details="' .str_ireplace(array( "'"), array("\'"), trim(print_r($item,true))) . '';
$item = ''. addslashes($key).':' .$item. '