POC Cache) Author: Aaron Harun Version: 1.0 AWP Release: 1.0 Author URI: http://anthologyoi.com/ */ if(strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false){ add_action('awp_admin_other',array('AWP_Cache','admin')); add_filter('awp_get_options',array('AWP_Cache','awp_get_options')); add_action('awp_admin_update',array('AWP_Cache','delete')); }elseif($awpall['cache'] == 'Enabled'){ add_action('init', array('AWP_Cache','init')); } register_activation_hook(__file__,array('AWP_Cache','set_defaults')); class AWP_Cache { function init(){ global $awpall, $aWP; if(AWP::enabled('inlineposts')){ remove_action('awp_paginate', array('AWP_inlineposts', 'paginate')); add_action('awp_paginate', array('AWP_Cache', 'post_paginate')); // remove_action('awp_pages',array('AWP_inlineposts','pages')); // add_action('awp_pages',array('AWP_Cache','post_pages')); } if(AWP::enabled('inlinecomments')){ $aWP['basic_comments'] = 1; remove_action('awp_comments_do', array('AWP_inlinecomments','comments')); add_action('awp_comments_do', array('AWP_Cache','comments_comments')); } add_action('publish_post', array('AWP_Cache','remove_post_cache'), 1); add_action('edit_post', array('AWP_Cache','remove_post_cache'), 1); add_action('delete_post', array('AWP_Cache','remove_post_cache'), 1); add_action('publish_phone', array('AWP_Cache','remove_post_cache'), 1); add_action('delete_comment', array('AWP_Cache','delete_comment_cache'), 1); // these we check for validity before invalidating the cache add_action('trackback_post', array('AWP_Cache','remove_comment_cache'), 1); add_action('pingback_post', array('AWP_Cache','remove_comment_cache'), 1); add_action('comment_post', array('AWP_Cache','remove_comment_cache'), 1); add_action('edit_comment', array('AWP_Cache','remove_comment_cache'), 1); add_action('wp_set_comment_status', array('AWP_Cache','remove_comment_cache'), 1); do_action('awp_cache_init'); } function comments_comments(){ global $id; $cache = AWP_Cache::fetch('comments_'.$id); if(!$cache){ ob_start(); AWP_inlinecomments::comments(); $cache = ob_get_contents(); ob_end_clean(); AWP_Cache::store('comments_'.$id, $cache); } echo $cache; } function post_paginate(){ global $id,$pages; $cache = AWP_Cache::fetch('post_'.$id); if(!$cache){ $cache = AWP_inlineposts::paginate(); AWP_Cache::store('post_'.$id, $cache); } $pages = $cache; } function post_pages(){ global $id; $cache = AWP_Cache::fetch('post_pages_'.$id); if(!$cache){ $cache = AWP_inlineposts::pages(); AWP_Cache::store('post_pages_'.$id, $cache); } return $cache; } function clear_cache($id) { AWP_Cache::remove_cache('post_'.$id); AWP_Cache::remove_cache('post_'.$id); AWP_Cache::remove_cache('comments_'.$id); } function delete_comment_cache($comment_id) { $comment = get_commentdata($comment_id, 1, true); AWP_Cache::remove_cache('comments_'.$comment['comment_post_ID']); } function remove_post_cache($id) { AWP_Cache::remove_cache('post_'.$id); AWP_Cache::remove_cache('post_pages_'.$id); } function remove_comment_cache($comment_id) { global $id; $comment = get_commentdata($comment_id, 1, true); if( strpos($_SERVER['REQUEST_URI'], 'wp-admin/') == false && $comment['comment_approved'] != 1 ){ return; }else{ AWP_Cache::remove_cache('comments_'.$comment['comment_post_ID']); } } function remove_cache($cache_id) { global $awp_cached; if ($awp_cached[$cache_id]){ return; }else{ delete_option('AWP_CACHE_'.$cache_id); } } function fetch($cache_id) { $result = get_option('AWP_CACHE_'.$cache_id); if($result){ return $result; }else{ return false; } } function store($cache_id, $data) { update_option('AWP_CACHE_'.$cache_id, $data); } function delete($cache_id) { global $wpdb; $wpdb->query("DELETE FROM `" . $wpdb->options . "` WHERE `option_name` LIKE 'AWP_CACHE_%'"); } function admin(){ global $aWP, $awpall; ob_start(); ?>