/** * Check if the given blog cache directory is ready for operation * * @param mixed blog ID, or NULL to check the general cache * @param boolean true if function should try to repair the corresponding cache folder, false otherwise * @return mixed false if the corresponding setting is disabled, or array( status, message ). */ function system_check_blog_cache($blog_ID = NULL, $repair = false) { global $Settings; load_class('_core/model/_pagecache.class.php', 'PageCache'); $Blog = NULL; $result = NULL; if ($blog_ID == NULL) { if ($Settings->get('general_cache_enabled')) { $result = system_check_dir('cache', 'general/'); $before_msg = T_('General cache') . ': '; } } else { $BlogCache =& get_BlogCache(); $Blog = $BlogCache->get_by_ID($blog_ID); if ($Blog->get_setting('cache_enabled')) { $result = system_check_dir('cache', 'c' . $blog_ID . '/'); $before_msg = sprintf(T_('%s cache') . ': ', $Blog->get('shortname')); } } if (!isset($result)) { return false; } if (!$repair || $result == 0) { return system_get_result($result); } // try to repair the corresponding cache folder $PageCache = new PageCache($Blog); $PageCache->cache_delete(); $PageCache->cache_create(); return system_check_blog_cache($blog_ID, false); }
/** * Enable/Disable the given cache * * @param string cache key name, 'general_cache_enabled', blogs 'cache_enabled' * @param boolean status to set * @param integer the id of the blog, if we want to set a blog's cache. Let it NULL to set general caching. * @param boolean true to save db changes, false if db update will be called outside from this function */ function set_cache_enabled($cache_key, $new_status, $coll_ID = NULL, $save_setting = true) { load_class('_core/model/_pagecache.class.php', 'PageCache'); global $Settings; if (empty($coll_ID)) { // general cache $Blog = NULL; $old_cache_status = $Settings->get($cache_key); } else { // blog page cache $BlogCache =& get_BlogCache(); $Blog = $BlogCache->get_by_ID($coll_ID); $old_cache_status = $Blog->get_setting($cache_key); } $PageCache = new PageCache($Blog); if ($old_cache_status == false && $new_status == true) { // Caching has been turned ON: if ($PageCache->cache_create(false)) { // corresponding cache folder was created if (empty($coll_ID)) { // general cache $result = array('success', T_('General caching has been enabled.')); } else { // blog page cache $result = array('success', T_('Page caching has been enabled.')); } } else { // error creating cache folder if (empty($coll_ID)) { // general cache $result = array('error', T_('General caching could not be enabled. Check /cache/ folder file permissions.')); } else { // blog page cache $result = array('error', T_('Page caching could not be enabled. Check /cache/ folder file permissions.')); } $new_status = false; } } elseif ($old_cache_status == true && $new_status == false) { // Caching has been turned OFF: $PageCache->cache_delete(); if (empty($coll_ID)) { // general cache $result = array('note', T_('General caching has been disabled. Cache contents have been purged.')); } else { // blog page cache $result = array('note', T_('Page caching has been disabled. Cache contents have been purged.')); } } else { // nothing was changed // check if ajax_form_enabled has correct state after b2evo upgrade if ($Blog != NULL && $new_status && !$Blog->get_setting('ajax_form_enabled')) { // if page cache is enabled, ajax form must be enabled to $Blog->set_setting('ajax_form_enabled', true); $Blog->dbupdate(); } return NULL; } // set db changes if ($Blog == NULL) { $Settings->set('general_cache_enabled', $new_status); if ($save_setting) { // save $Settings->dbupdate(); } } else { $Blog->set_setting($cache_key, $new_status); if ($cache_key == 'cache_enabled' && $new_status) { // if page cache is enabled, ajax form must be enabled to $Blog->set_setting('ajax_form_enabled', true); } if ($save_setting) { // save $Blog->dbupdate(); } } return $result; }