wpforo)) $this->wpforo = $wpForo; $this->init(); } public function init(){ $wp_upload_dir = wp_upload_dir(); $uplds_dir = $wp_upload_dir['basedir']."/wpforo"; $cache_dir = $uplds_dir . "/cache"; if(!is_dir($uplds_dir)) wp_mkdir_p($uplds_dir); if(!is_dir($cache_dir)) $this->dir($cache_dir); $this->dir = $cache_dir; $this->lang = get_locale(); } public function get_key( $type = 'html' ){ if($type == 'html'){ $ug = $this->wpforo->current_user_groupid; return md5( preg_replace('|(.+)\#.+?$|is', '$1', $_SERVER['REQUEST_URI']) . $ug ); } } private function dir( $cache_dir ){ $dirs = array( $cache_dir, $cache_dir . '/forum', $cache_dir . '/topic', $cache_dir . '/post', $cache_dir . '/item', $cache_dir . '/item/forum', $cache_dir . '/item/topic', $cache_dir . '/item/post'); $this->mkdir( $dirs ); } private function mkdir( $dirs ){ foreach( $dirs as $dir ){ wp_mkdir_p($dir); wpforo_write_file( $dir . '/index.html' , '' ); wpforo_write_file( $dir . '/.htaccess' , 'deny from all' ); } } public function on( $type = 'object_cashe' ){ if( $type == 'html_cashe' ){ if( wpforo_feature('output-buffer') && function_exists('ob_start') ){ return wpforo_feature('html_cashe', $this->wpforo); } else{ return false; } } else{ return wpforo_feature($type, $this->wpforo); } } public function get( $key, $type = 'loop' ){ $template = $this->wpforo->current_object['template']; $loop_templates = array('forum', 'topic', 'post'); if( $type == 'loop' && $template ){ if( $this->exists($key, $template) ){ if( in_array( $template, $loop_templates) ){ $cache_file = $this->dir . '/' . $template . '/' . $key; $array = wpforo_get_file_content( $cache_file ); return @unserialize( $array ); } } } } public function get_item( $id, $type = 'post' ){ if( $id ){ $key = $id . '_' . $this->lang; if( $this->exists( $key, 'item', $type )){ $cache_file = $this->dir . '/item/' . $type . '/' . $key; $array = wpforo_get_file_content( $cache_file ); return @unserialize( $array ); } } } public function get_html(){ $template = $this->wpforo->current_object['template']; if( $template == 'forum' ){ $key = $this->get_key(); if( $this->exists($key, $template) ){ $cache_file = $this->dir . '/' . $template . '/' . $key; $html = wpforo_get_file_content( $cache_file ); return $this->filter($html); } } return false; } public function html( $content ){ if(!$this->on('html_cashe')) return false; $template = $this->wpforo->current_object['template']; if( $template == 'forum' ){ $key = $this->get_key(); $this->create_html( $content, $template, $key ); } } public function create( $mode = 'loop', $cache = array(), $type = 'post' ){ if(!$this->on('object_cashe')) return false; $template = $this->wpforo->current_object['template']; if( $template == 'forum' ) { $this->check( $this->dir . '/item/post' ); } if( $mode == 'loop' && $template ){ if( $template == 'forum' || $template == 'topic' || $template == 'post'){ $cache = $this->wpforo->forum->get_cache('forums'); $this->create_files( $cache, $template ); $cache = $this->wpforo->topic->get_cache('topics'); $this->create_files( $cache, $template ); $cache = $this->wpforo->post->get_cache('posts'); $this->create_files( $cache, $template ); } } elseif( $mode == 'item' && !empty($cache) ){ $this->create_files( $cache, 'item', $type ); } } public function create_files( $cache = array(), $template = '', $type = '' ){ if( !empty($cache) ){ $type = ( $type ) ? $type . '/' : '' ; foreach( $cache as $key => $object ){ if($template == 'item') $key = $key . '_' . $this->lang; if( !$this->exists($key, $template) ){ $object = serialize($object); wpforo_write_file( $this->dir . '/' . $template . '/' . $type . $key , $object ); } } } } public function create_html( $content, $template = '', $key = '' ){ if( $content ){ if( !$this->exists($key, $template) ){ wpforo_write_file( $this->dir . '/' . $template . '/' . $key , $content ); } } } public function filter( $html = '' ){ //exit(); $html = preg_replace('|