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; if($awpall['inlineposts'] == 'Enabled'){ remove_action('awp_paginate', array('AWP_Post', 'paginate')); add_action('awp_paginate', array('AWP_Cache', 'post_paginate')); // remove_action('awp_pages',array('AWP_Post','pages')); // add_action('awp_pages',array('AWP_Cache','post_pages')); } if($awpall['inlinecomments'] == 'Enabled'){ remove_action('awp_comments_do', array('AWP_comments','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_comments::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_Post::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_Post::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);$comment['comment_approved'] = 0; 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; $menu = << Cache Options. Cache This module will cache the paginated post (just the paged content that AWP creates not the modifications other plugins do to it), the text of the post sho/hide links and the entire comment list with formatting. The module automatically removes the old cached items when they are out of date and recaches them the next time they are needed. This will speed up processing time exponentially. menu; AWP_admin::admin_panel($menu); } function awp_get_options($i){ $i[selects][] = 'cache'; return $i; } function set_defaults(){ global $awpall; $awpall[cache] = 'Enabled'; update_option('awp',$awpall); } } ?>