diff --git a/includes/File.php b/includes/File.php index 289e29b0bdd794a4f60f70670cca8d7716431a50..445ce8a1e906192c7e2964a7eea112a85e0be02f 100644 --- a/includes/File.php +++ b/includes/File.php @@ -6,118 +6,154 @@ defined('ABSPATH') || exit; final class File { - protected static $cache_dir = WP_CONTENT_DIR . '/advanced-cache'; - - public static function is_available() - { - return get_option('permalink_structure'); - } - - public static function store_timeout($cache_expires = 0) + /** + * [protected description] + * @var string + */ + protected static $cacheDir = WP_CONTENT_DIR . '/advanced-cache'; + + /** + * [storeTimeout description] + * @param integer $cacheExpires [description] + */ + public static function storeTimeout($cacheExpires = 0) { - $cache_expires = absint($cache_expires) ? absint($cache_expires) : 1; - self::_create_timeout_file($cache_expires); + $cacheExpires = absint($cacheExpires) ? absint($cacheExpires) : 1; + self::createTimeoutFile($cacheExpires); } - public static function store_item($data = '') + /** + * [storeItem description] + * @param string $data [description] + * @return [type] [description] + */ + public static function storeItem($data = '') { if (empty($data)) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => 'store_item()', 'message' => 'The Data is empty.']); + do_action('rrze.log.error', __('{plugin}: Can not save cache item. The data is empty.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__]); return false; } - self::_create_files($data . self::_cache_signatur()); + self::createFiles($data . self::cacheSignatur()); } - public static function get_item($cache_expires = 0) + /** + * [getItem description] + * @param integer $cacheExpires [description] + * @return boolean [description] + */ + public static function getItem($cacheExpires = 0) { - $cache_expires = absint($cache_expires) ? absint($cache_expires) : 1; - $expires_seconds = $cache_expires * HOUR_IN_SECONDS; - if (is_readable(self::_file_html()) && ((filemtime(self::_file_html()) + $expires_seconds) > time())) { + $cacheExpires = absint($cacheExpires) ? absint($cacheExpires) : 1; + $expires_seconds = $cacheExpires * HOUR_IN_SECONDS; + if (is_readable(self::fileHtml()) && ((filemtime(self::fileHtml()) + $expires_seconds) > time())) { return true; } return false; } - public static function delete_item($url = '') + /** + * [deleteItem description] + * @param string $url [description] + * @return mixed [description] + */ + public static function deleteItem($url = '') { if (! filter_var($url, FILTER_VALIDATE_URL)) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => 'delete_item()', 'message' => 'The URL is not valid.']); + do_action('rrze.log.error', __('{pluginn}: The URL is not valid.'), ['plugin' =>'rrze-cache', 'method' => __METHOD__]); return false; } $url_path = parse_url(($url ? $url : $_SERVER['REQUEST_URI']), PHP_URL_PATH); $recursive = untrailingslashit($url_path) ? true : false; - self::_clear_dir(self::_file_path($url), $recursive); - } - - public static function clear_cache($clear_all = false) - { - if ($clear_all === false) { - self::_clear_dir(self::_dir_path()); - } else { - self::_clear_dir(self::$cache_dir); - } + self::clearDir(self::filePath($url), $recursive); } - public static function get_stats($all_stats = false) + /** + * [clearData description] + * @param boolean $clearAll [description] + */ + public static function clearData($clearAll = false) { - if ($all_stats === false) { - return self::_dir_size(self::_dir_path()); + if ($clearAll === false) { + self::clearDir(self::dirPath()); } else { - return self::_dir_size(self::$cache_dir); + self::clearDir(self::$cacheDir); } } - protected static function _cache_signatur() + /** + * [cacheSignatur description] + * @return string [description] + */ + protected static function cacheSignatur() { return sprintf("\n\n<!-- %s -->", date_i18n(__('Y-m-d H:i:s', 'rrze-cache'), current_time('timestamp'))); } - protected static function _create_files($data) + /** + * [createFiles description] + * @param string $data [description] + * @return boolean + */ + protected static function createFiles($data) { - $file_path = self::_file_path(); - if (! wp_mkdir_p($file_path)) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => '_create_files()', '$file_path' => $file_path, 'message' => 'Das Verzeichnis konnte nicht erstellt werden.']); + $filePath = self::filePath(); + if (! wp_mkdir_p($filePath)) { + do_action('rrze.log.error', __('{plugin}: Das Verzeichnis konnte nicht erstellt werden.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$filePath' => $filePath]); return false; } - self::_create_file(self::_file_html(), $data); - self::_create_file(self::_file_gzip(), gzencode($data, 9)); + self::writeFile(self::fileHtml(), $data); + self::writeFile(self::fileGzip(), gzencode($data, 9)); + return true; } - protected static function _create_timeout_file($cache_expires) + /** + * [createTimeoutFile description] + * @param integer $cacheExpires [description] + * @return boolean [description] + */ + protected static function createTimeoutFile($cacheExpires) { - if (! wp_mkdir_p(self::$cache_dir)) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => '_create_timeout_file()', 'File::$cache_dir' => self::$cache_dir, 'message' => 'Das Verzeichnis konnte nicht erstellt werden.']); + if (! wp_mkdir_p(self::$cacheDir)) { + do_action('rrze.log.error', __('{plugin}: The directory could not be created.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, 'File::$cacheDir' => self::$cacheDir]); return false; } $file = sprintf( '%s%s%s', - self::$cache_dir, + self::$cacheDir, DIRECTORY_SEPARATOR, 'timeout' ); if (! $handle = @fopen($file, 'wb')) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => '_create_timeout_file()', '$file' => $file, 'message' => 'Die Datei konnte nicht geschrieben werden.']); + do_action('rrze.log.error', __('{plugin}: The timeout cache file could not be written.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$file' => $file]); return false; } - fwrite($handle, $cache_expires); + fwrite($handle, $cacheExpires); fclose($handle); clearstatcache(); - self::_file_perms($file); + self::fileChmod($file); + + return true; } - protected static function _create_file($file, $data) + /** + * [writeFile description] + * @param string $file [description] + * @param string $data [description] + * @return boolean [description] + */ + protected static function writeFile($file, $data) { if (! $handle = @fopen($file, 'wb')) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => '_create_file()', '$file' => $file, 'message' => 'Die Datei konnte nicht geschrieben werden.']); + do_action('rrze.log.error', __('{plugin}: The cache file could not be written.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$file' => $file]); return false; } @@ -125,10 +161,16 @@ final class File fclose($handle); clearstatcache(); - self::_file_perms($file); + self::fileChmod($file); + + return true; } - protected static function _file_perms($file) + /** + * [fileChmod description] + * @param string $file [description] + */ + protected static function fileChmod($file) { $stat = @stat(dirname($file)); $perms = $stat['mode'] & 0007777; @@ -137,7 +179,13 @@ final class File clearstatcache(); } - protected static function _clear_dir($dir, $recursive = true) + /** + * [clearDir description] + * @param string $dir [description] + * @param boolean $recursive [description] + * @return void + */ + protected static function clearDir($dir, $recursive = true) { $dir = untrailingslashit($dir); @@ -145,19 +193,19 @@ final class File return; } - $objects = array_diff(scandir($dir), array('..', '.')); + $filenames = array_diff(scandir($dir), ['..', '.']); - if (empty($objects)) { + if (empty($filenames)) { return; } - foreach ($objects as $object) { - $object = $dir . DIRECTORY_SEPARATOR . $object; + foreach ($filenames as $filename) { + $filename = $dir . DIRECTORY_SEPARATOR . $filename; - if (is_dir($object) && $recursive) { - self::_clear_dir($object, $recursive); + if (is_dir($filename) && $recursive) { + self::clearDir($filename, $recursive); } else { - unlink($object); + unlink($filename); } } @@ -166,75 +214,65 @@ final class File clearstatcache(); } - public static function _dir_size($dir = '.') - { - if (! is_dir($dir)) { - return; - } - - $objects = array_diff(scandir($dir), array('..', '.')); - - if (empty($objects)) { - return; - } - - $size = 0; - - foreach ($objects as $object) { - $object = $dir . DIRECTORY_SEPARATOR . $object; - - if (is_dir($object)) { - $size += self::_dir_size($object); - } else { - $size += filesize($object); - } - } - - return $size; - } - - protected static function _dir_path() + /** + * [dirPath description] + * @return mixed [description] + */ + protected static function dirPath() { $path = sprintf( '%s%s%s', - self::$cache_dir, + self::$cacheDir, DIRECTORY_SEPARATOR, parse_url('http://' . strtolower($_SERVER['HTTP_HOST']), PHP_URL_HOST) ); if (validate_file($path) > 0) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => '_dir_path()', '$path' => $path, 'message' => 'Ungültige Dateipfad.']); + do_action('rrze.log.error', __('{plugin}: Invalid file path.'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$path' => $path]); return false; } return trailingslashit($path); } - protected static function _file_path($path = null) + /** + * [filePath description] + * @param string $path [description] + * @return mixed [description] + */ + protected static function filePath($path = '') { $path = sprintf( '%s%s%s%s', - self::$cache_dir, + self::$cacheDir, DIRECTORY_SEPARATOR, parse_url('http://' . strtolower($_SERVER['HTTP_HOST']), PHP_URL_HOST), parse_url(($path ? $path : $_SERVER['REQUEST_URI']), PHP_URL_PATH) ); if (validate_file($path) > 0) { - do_action('rrze.log.error', ['plugin' =>'rrze-cache', 'File' => '_file_path()', '$path' => $path, 'message' => 'Ungültige Dateipfad.']); + do_action('rrze.log.error', __('{plugin}: Invalid file path.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$path' => $path]); return false; } return trailingslashit($path); } - protected static function _file_html() + /** + * [fileHtml description] + * @return string [description] + */ + protected static function fileHtml() { - return self::_file_path() . 'index.html'; + return self::filePath() . 'index.html'; } - protected static function _file_gzip() + /** + * [fileGzip description] + * @return string [description] + */ + protected static function fileGzip() { - return self::_file_path() . 'index.html.gz'; + return self::filePath() . 'index.html.gz'; } } diff --git a/includes/Flush.php b/includes/Flush.php index 3215bd9e400d6abd272cbc781550e2661e3034e9..a639f8008ff1fd25564b54d894a76fdbbff6986e 100644 --- a/includes/Flush.php +++ b/includes/Flush.php @@ -6,32 +6,47 @@ defined('ABSPATH') || exit; class Flush { - public static function flush_cache_by_post_id($post_ID) + /** + * [flushCacheByPostId description] + * @param integer $postId [description] + */ + public static function flushCacheByPostId($postId) { - if (! $post_ID = absint($post_ID)) { + if (! $postId = absint($postId)) { return; } - self::flush_cache_by_url(get_permalink($post_ID)); + self::flushCacheByUrl(get_permalink($postId)); } - public static function flush_cache_by_url($url) + /** + * [flushCacheByUrl description] + * @param string $url [description] + * @return void + */ + public static function flushCacheByUrl($url) { if (! $url = (string) $url) { return; } - File::delete_item($url); + File::deleteItem($url); } - public static function flush_cache() + /** + * [flushCache description] + */ + public static function flushCache() { - File::clear_cache(); + File::clearData(); } - public static function flush_cache_all() + /** + * [flushAllCache description] + */ + public static function flushAllCache() { - File::clear_cache(true); + File::clearData(true); } } diff --git a/includes/Main.php b/includes/Main.php index 3ba33ec13afea50d37089c8718930df6fcfdb9fc..263d71a6ac079c5a5cd3a50197d613a1df9185cf 100644 --- a/includes/Main.php +++ b/includes/Main.php @@ -6,48 +6,57 @@ defined('ABSPATH') || exit; class Main { - const cache_meta_key = '_rrze_cache'; - - // rrze-ac plugin - const access_permission_meta_key = '_access_permission'; - + /** + * [protected description] + * @var string + */ + protected $pluginFile; + + /** + * [protected description] + * @var object + */ protected $options; - protected $site_options; + /** + * [protected description] + * @var object + */ + protected $siteOptions; - public function __construct() + public function __construct($pluginFile) { - $this->options = Options::get_options(); - $this->site_options = Options::get_site_options(); - - new Settings(); - - $this->add_hooks(); + $this->pluginFile = $pluginFile; + $this->options = Options::getOptions(); + $this->siteOptions = Options::getSiteOptions(); } - protected function add_hooks() + public function onLoaded() { + $settings = new Settings($this->pluginFile); + $settings->onLoaded(); + add_action('init', [$this, 'add_publish_hooks'], 99); - add_action('rrzecache_flush_cache_post_id', [__NAMESPACE__ . '\Flush', 'flush_cache_by_post_id']); + add_action('rrzecache_flush_cache_post_id', [__NAMESPACE__ . '\Flush', 'flushCacheByPostId']); - add_action('rrzecache_flush_cache_url', [__NAMESPACE__ . '\Flush', 'flush_cache_by_url']); + add_action('rrzecache_flush_cache_url', [__NAMESPACE__ . '\Flush', 'flushCacheByUrl']); - add_action('rrzecache_flush_cache', [__NAMESPACE__ . '\Flush', 'flush_cache']); + add_action('rrzecache_flush_cache', [__NAMESPACE__ . '\Flush', 'flushCache']); - add_action('_core_updated_successfully', [__NAMESPACE__ . '\Flush', 'flush_cache_all']); + add_action('_core_updated_successfully', [__NAMESPACE__ . '\Flush', 'flushAllCache']); - add_action('switch_theme', [__NAMESPACE__ . '\Flush', 'flush_cache']); + add_action('switch_theme', [__NAMESPACE__ . '\Flush', 'flushCache']); - add_action('customize_save_after', [__NAMESPACE__ . '\Flush', 'flush_cache']); + add_action('customize_save_after', [__NAMESPACE__ . '\Flush', 'flushCache']); - add_action('wp_update_nav_menu', [__NAMESPACE__ . '\Flush', 'flush_cache']); + add_action('wp_update_nav_menu', [__NAMESPACE__ . '\Flush', 'flushCache']); - add_action('wp_trash_post', [__NAMESPACE__ . '\Flush', 'flush_cache']); + add_action('wp_trash_post', [__NAMESPACE__ . '\Flush', 'flushCache']); add_action('pre_comment_approved', [$this, 'pre_comment_approved'], 99, 2); - if (! is_multisite() || (is_multisite() && $this->site_options->cache_enabled)) { + if (! is_multisite() || (is_multisite() && $this->siteOptions->cache_enabled)) { add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); add_action('transition_comment_status', [$this, 'transition_comment_status'], 10, 3); @@ -65,23 +74,58 @@ class Main public function admin_enqueue_scripts($hook) { if ($hook == 'settings_page_rrze-cache') { - $plugin_data = get_plugin_data(RRZE_PLUGIN_FILE); - - wp_enqueue_style('jquery-listfilterizer', plugins_url('assets/css/jquery.listfilterizer.min.css', plugin_basename(RRZE_PLUGIN_FILE)), [], '1.0'); - wp_enqueue_script('jquery-listfilterizer', plugins_url('assets/js/jquery.listfilterizer.min.js', plugin_basename(RRZE_PLUGIN_FILE)), ['jquery'], '1.0', true); - - wp_enqueue_style('rrze-cache-settings', plugins_url('assets/css/settings.min.css', plugin_basename(RRZE_PLUGIN_FILE)), [], $plugin_data['Version']); - wp_enqueue_script('jquery-listfilterizer'); - wp_enqueue_script('rrze-cache-settings', plugins_url('assets/js/settings.min.js', plugin_basename(RRZE_PLUGIN_FILE)), ['jquery', 'jquery-listfilterizer'], $plugin_data['Version'], true); - wp_localize_script('rrze-cache-settings', 'rrze_cache_vars', [ - 'filters_label_1' => __('All', 'rrze-cache'), - 'filters_label_2' => __('Selected', 'rrze-cache'), - 'placeholder' => __('Search...', 'rrze-cache'), - ]); + $plugin_data = get_plugin_data($this->pluginFile); + + wp_enqueue_style( + 'jquery-listfilterizer', + plugins_url('assets/css/jquery.listfilterizer.min.css', $this->pluginFile), + [], + '1.0' + ); + wp_enqueue_script( + 'jquery-listfilterizer', + plugins_url('assets/js/jquery.listfilterizer.min.js', $this->pluginFile), + ['jquery'], + '1.0', + true + ); + wp_enqueue_style( + 'rrze-cache-settings', + plugins_url('assets/css/settings.min.css', $this->pluginFile), + [], + $plugin_data['Version'] + ); + wp_enqueue_script( + 'rrze-cache-settings', + plugins_url('assets/js/settings.min.js', $this->pluginFile), + ['jquery', 'jquery-listfilterizer'], + $plugin_data['Version'], + true + ); + wp_localize_script( + 'rrze-cache-settings', 'rrze_cache_vars', + [ + 'filters_label_1' => __('All', 'rrze-cache'), + 'filters_label_2' => __('Selected', 'rrze-cache'), + 'placeholder' => __('Search...', 'rrze-cache') + ] + ); } elseif ($hook === 'post.php') { - $plugin_data = get_plugin_data(RRZE_PLUGIN_FILE); - wp_enqueue_style('rrze-cache-post-edit', plugins_url('assets/css/post-edit.min.css', plugin_basename(RRZE_PLUGIN_FILE)), [], $plugin_data['Version']); - wp_enqueue_script('rrze-cache-post-edit', plugins_url('assets/js/post-edit.min.js', plugin_basename(RRZE_PLUGIN_FILE)), ['jquery'], $plugin_data['Version'], true); + $plugin_data = get_plugin_data($this->pluginFile); + + wp_enqueue_style( + 'rrze-cache-post-edit', + plugins_url('assets/css/post-edit.min.css', $this->pluginFile), + [], + $plugin_data['Version'] + ); + wp_enqueue_script( + 'rrze-cache-post-edit', + plugins_url('assets/js/post-edit.min.js', $this->pluginFile), + ['jquery'], + $plugin_data['Version'], + true + ); } } @@ -95,7 +139,7 @@ class Main foreach ($post_types as $post_type) { add_action('publish_' . $post_type, [$this, 'publish_post_types'], 10, 2); - add_action('publish_future_' . $post_type, [__NAMESPACE__ . '\Flush', 'flush_cache']); + add_action('publish_future_' . $post_type, [__NAMESPACE__ . '\Flush', 'flushCache']); } } @@ -114,9 +158,9 @@ class Main } if ($this->options->reset_on_publish) { - Flush::flush_cache(); + Flush::flushCache(); } else { - Flush::flush_cache_by_post_id($post_ID); + Flush::flushCacheByPostId($post_ID); } if (isset($_POST['post_cache_submitbox_nonce']) && wp_verify_nonce($_POST['post_cache_submitbox_nonce'], 'post_cache_submitbox')) { @@ -141,9 +185,9 @@ class Main { if ($approved === 1) { if ($this->options->reset_on_comment) { - Flush::flush_cache(); + Flush::flushCache(); } else { - Flush::flush_cache_by_post_id($comment['comment_post_ID']); + Flush::flushCacheByPostId($comment['comment_post_ID']); } } @@ -154,9 +198,9 @@ class Main { if ($new_status != $old_status) { if ($this->options->reset_on_comment) { - Flush::flush_cache(); + Flush::flushCache(); } else { - Flush::flush_cache_by_post_id($comment->comment_post_ID); + Flush::flushCacheByPostId($comment->comment_post_ID); } } } @@ -164,9 +208,9 @@ class Main public function edit_comment($id) { if ($this->options->reset_on_comment) { - Flush::flush_cache(); + Flush::flushCache(); } else { - Flush::flush_cache_by_post_id(get_comment($id)->comment_post_ID); + Flush::flushCacheByPostId(get_comment($id)->comment_post_ID); } } @@ -222,7 +266,7 @@ class Main return; } - $cached = File::get_item($this->get_cache_expires()); + $cached = File::getItem($this->get_cache_expires()); if (! $cached) { ob_start([$this, 'set_cache']); @@ -232,7 +276,7 @@ class Main public function get_cache_expires() { if (is_multisite()) { - return $this->site_options->cache_expires; + return $this->siteOptions->cache_expires; } return $this->options->cache_expires; @@ -244,7 +288,7 @@ class Main return ''; } - File::store_item($data); + File::storeItem($data); return $data; } @@ -287,7 +331,7 @@ class Main protected function skip_cache() { - if (is_multisite() && ! $this->site_options->cache_enabled) { + if (is_multisite() && ! $this->siteOptions->cache_enabled) { return true; } diff --git a/includes/Options.php b/includes/Options.php index be2516c02341396afd34ca86ef9262022b809a72..bca9160003f13cce69ba6de797d82c28df6cbcfc 100644 --- a/includes/Options.php +++ b/includes/Options.php @@ -6,11 +6,23 @@ defined('ABSPATH') || exit; class Options { - protected static $option_name = 'rrze_cache'; - - protected static $site_option_name = 'rrze_cache_site'; - - protected static function default_options() + /** + * [protected description] + * @var string + */ + protected static $optionName = 'rrze_cache'; + + /** + * [protected description] + * @var string + */ + protected static $siteOptionName = 'rrze_cache_site'; + + /** + * [defaultOptions description] + * @return array [description] + */ + protected static function defaultOptions() { $options = [ 'cache_expires' => 1, // [hour] @@ -21,7 +33,11 @@ class Options return $options; } - protected static function default_site_options() + /** + * [defaultSiteOptions description] + * @return array] [description] + */ + protected static function defaultSiteOptions() { $options = [ 'cache_enabled' => 0, @@ -31,35 +47,51 @@ class Options return $options; } - public static function get_options() + /** + * [getOptions description] + * @return object [description] + */ + public static function getOptions() { - $defaults = self::default_options(); + $defaults = self::defaultOptions(); - $options = (array) get_option(self::$option_name); + $options = (array) get_option(self::$optionName); $options = wp_parse_args($options, $defaults); $options = array_intersect_key($options, $defaults); return (object) $options; } - public static function get_site_options() + /** + * [getSiteOptions description] + * @return object [description] + */ + public static function getSiteOptions() { - $defaults = self::default_site_options(); + $defaults = self::defaultSiteOptions(); - $options = (array) get_site_option(self::$site_option_name); + $options = (array) get_site_option(self::$siteOptionName); $options = wp_parse_args($options, $defaults); $options = array_intersect_key($options, $defaults); return (object) $options; } - public static function get_option_name() + /** + * [getOptionName description] + * @return string [description] + */ + public static function getOptionName() { - return self::$option_name; + return self::$optionName; } - public static function get_site_option_name() + /** + * [getSiteOptionName description] + * @return string [description] + */ + public static function getSiteOptionName() { - return self::$site_option_name; + return self::$siteOptionName; } } diff --git a/includes/Settings.php b/includes/Settings.php index 213b130cbcedb17692c910055334ffef9456b306..ab4f1984a7f3c52f8119aeb761d3db92367a8cf8 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -2,46 +2,74 @@ namespace RRZE\Cache; -use WP_Error; - defined('ABSPATH') || exit; class Settings { + /** + * [protected description] + * @var string + */ + protected $pluginFile; + + /** + * [protected description] + * @var object + */ protected $options; - protected $site_options; - - protected $wpconfig; - - public function __construct() + /** + * [protected description] + * @var string + */ + protected $siteOptionName; + + /** + * [protected description] + * @var object + */ + protected $siteOptions; + + /** + * [__construct description] + * @param string $pluginFile [description] + */ + public function __construct($pluginFile) { - $this->options = Options::get_options(); - $this->site_options = Options::get_site_options(); - - $this->add_hooks(); + $this->pluginFile = $pluginFile; + $this->options = Options::getOptions(); + $this->siteOptionName = Options::getSiteOptionName(); + $this->siteOptions = Options::getSiteOptions(); } - protected function add_hooks() + /** + * [onLoaded description] + */ + public function onLoaded() { - if (!is_multisite() || (is_multisite() && $this->site_options->cache_enabled)) { - add_action('admin_init', [$this, 'register_settings']); - add_action('admin_menu', [$this, 'admin_menu']); + if (!is_multisite() || (is_multisite() && $this->siteOptions->cache_enabled)) { + add_action('admin_init', [$this, 'registerSettings']); + add_action('admin_menu', [$this, 'adminMenu']); } if (is_multisite()) { - add_action('network_admin_menu', [$this, 'network_admin_menu']); - add_action('admin_init', [$this, 'network_admin_settings']); - add_filter('network_admin_plugin_action_links_' . plugin_basename(RRZE_PLUGIN_FILE), [$this, 'network_admin_plugin_action_link']); + add_action('network_admin_menu', [$this, 'networkAdminMenu']); + add_action('admin_init', [$this, 'networkAdminSettings']); + add_filter('network_admin_plugin_action_links_' . plugin_basename($this->pluginFile), [$this, 'networkAdminPluginActionLinks']); } else { - add_filter('plugin_action_links_' . plugin_basename(RRZE_PLUGIN_FILE), [$this, 'plugin_action_link']); + add_filter('plugin_action_links_' . plugin_basename($this->pluginFile), [$this, 'pluginActionLinks']); } - add_action('admin_bar_menu', [$this, 'admin_bar_flush_icon'], 90); - add_action('init', [$this, 'admin_bar_flush_request']); + add_action('admin_bar_menu', [$this, 'adminBarFlushIcon'], 90); + add_action('init', [$this, 'adminBarFlushRequest']); } - public function network_admin_plugin_action_link($links) + /** + * [networkAdminPluginActionLinks description] + * @param array $links [description] + * @return array [description] + */ + public function networkAdminPluginActionLinks($links) { if (!current_user_can('manage_network_options')) { return $links; @@ -49,7 +77,12 @@ class Settings return array_merge($links, array(sprintf('<a href="%s">%s</a>', add_query_arg(['page' => 'rrzecache-network'], network_admin_url('settings.php')), __('Settings', 'rrze-cache')))); } - public function plugin_action_link($links) + /** + * [pluginActionLinks description] + * @param array $links [description] + * @return array [description] + */ + public function pluginActionLinks($links) { if (!current_user_can('manage_options')) { return $links; @@ -57,38 +90,49 @@ class Settings return array_merge($links, array(sprintf('<a href="%s">%s</a>', add_query_arg(['page' => 'rrze-cache'], admin_url('options-general.php')), __('Settings', 'rrze-cache')))); } - public function admin_menu() + /** + * [adminMenu description] + */ + public function adminMenu() { if (!isset($_GET['settings-updated']) && isset($_GET['update']) && $_GET['update'] == 'flushed') { - $this->admin_notice_flush_cache(); + $this->adminNoticeFlushCache(); } - add_options_page(__('Cache', 'rrze-cache'), __('Cache', 'rrze-cache'), 'manage_options', 'rrze-cache', array($this, 'options_page')); + add_options_page(__('Cache', 'rrze-cache'), __('Cache', 'rrze-cache'), 'manage_options', 'rrze-cache', [$this, 'optionsPage']); } - public function register_settings() + /** + * [registerSettings description] + */ + public function registerSettings() { - register_setting('rrze-cache', 'rrze_cache', array($this, 'validate_options')); + register_setting('rrze-cache', 'rrze_cache', array($this, 'validateOptions')); } - public function validate_options($input) + /** + * [validateOptions description] + * @param array $input [description] + * @return array [description] + */ + public function validateOptions($input) { if (isset($_POST['rrze-cache-flush'])) { - Flush::flush_cache(); + Flush::flushCache(); wp_redirect(add_query_arg(array('page' => 'rrze-cache', 'update' => 'flushed'), admin_url('options-general.php'))); exit; } - $cache_exceptions = !empty($_POST['rrze_cache_selected']) ? $_POST['rrze_cache_selected'] : ''; - if (is_array($cache_exceptions)) { - foreach ($cache_exceptions as $post_ID) { + $cacheExceptions = !empty($_POST['rrze_cache_selected']) ? $_POST['rrze_cache_selected'] : ''; + if (is_array($cacheExceptions)) { + foreach ($cacheExceptions as $post_ID) { delete_post_meta($post_ID, RRZECACHE_META_KEY); } } if (!is_multisite()) { $input['cache_expires'] = !empty($input['cache_expires']) && absint($input['cache_expires']) >= 1 ? absint($input['cache_expires']) : $this->options->cache_expires; - File::store_timeout($input['cache_expires']); + File::storeTimeout($input['cache_expires']); } $input['reset_on_comment'] = isset($input['reset_on_comment']) ? 1 : 0; @@ -97,8 +141,10 @@ class Settings return $input; } - - protected function cache_disabled_list() + /** + * [cacheDisabledList description] + */ + protected function cacheDisabledList() { global $wpdb; @@ -111,16 +157,16 @@ class Settings " ); - $post_types = get_post_types(array('public' => true), 'objects'); + $postTypes = get_post_types(array('public' => true), 'objects'); // rrze-ac plugin - $rrze_ac_plugin = is_plugin_active('rrze-ac/rrze-ac.php'); ?> + $rrzeAcPlugin = is_plugin_active('rrze-ac/rrze-ac.php'); ?> <?php if ($posts) : ?> <ul class="rrze-cache-select-list"> <?php foreach ($posts as $p) : ?> - <?php $post_type_label = $post_types[$p->post_type]->labels->singular_name ?> - <?php $disabled = $rrze_ac_plugin && get_post_meta($p->ID, ACCESS_PERMISSION_META_KEY, true) ? ' disabled' : '' ?> - <?php $subtitle = $disabled ? sprintf(__('%s (Access protection activated)', 'rrze-cache'), $post_type_label) : $post_type_label ?> + <?php $postTypeLabel = $postTypes[$p->post_type]->labels->singular_name ?> + <?php $disabled = $rrzeAcPlugin && get_post_meta($p->ID, ACCESS_PERMISSION_META_KEY, true) ? ' disabled' : '' ?> + <?php $subtitle = $disabled ? sprintf(__('%s (Access protection activated)', 'rrze-cache'), $postTypeLabel) : $postTypeLabel ?> <li> <label for="rrze-cache-selected"> <input type="checkbox" id="<?php echo esc_attr('rrze-cache-selected-' . $p->ID) ?>" name="rrze_cache_selected[]" value="<?php echo esc_attr($p->ID); ?>" <?php echo $disabled; ?>> @@ -137,8 +183,10 @@ class Settings <?php } - - public function options_page() + /** + * [optionsPage description] + */ + public function optionsPage() { ?> <style> @@ -165,7 +213,7 @@ class Settings <input type="number" min="1" step="1" name="rrze_cache[cache_expires]" id="rrze-cache-expires" value="<?php echo esc_attr($this->options->cache_expires) ?>" class="small-text"> <?php echo esc_html(_nx('Hour', 'Hours', $this->options->cache_expires, 'rrze-cache-expires', 'rrze-cache')) ?> <?php else: ?> - <?php echo esc_html(sprintf(_nx('%s hour.', '%s hours.', $this->site_options->cache_expires, 'rrze-cache-expires', 'rrze-cache'), number_format_i18n($this->site_options->cache_expires))) ?> + <?php echo esc_html(sprintf(_nx('%s hour.', '%s hours.', $this->siteOptions->cache_expires, 'rrze-cache-expires', 'rrze-cache'), number_format_i18n($this->siteOptions->cache_expires))) ?> <?php endif ?> </label> </td> @@ -192,7 +240,7 @@ class Settings <?php esc_html_e('Exemptions', 'rrze-cache') ?> </th> <td> - <?php $this->cache_disabled_list() ?> + <?php $this->cacheDisabledList() ?> </td> </tr> </table> @@ -202,66 +250,70 @@ class Settings </div><?php } - public function enable_cache() + /** + * [enableCache description] + * @return boolean [description] + */ + protected function enableCache() { - if (!file_exists($wp_cache_file = WP_CONTENT_DIR . '/advanced-cache.php') && function_exists('symlink')) { - $rrze_cache_file = dirname(RRZE_PLUGIN_FILE) . '/advanced-cache.php'; - @symlink($rrze_cache_file, $wp_cache_file); + if (!file_exists($wpCacheFile = WP_CONTENT_DIR . '/advanced-cache.php')) { + $rrzeCacheFile = dirname($this->pluginFile) . '/advanced-cache.php'; + if (function_exists('symlink')) { + return symlink($rrzeCacheFile, $wpCacheFile); + } + return false; } - return true; } - public function disable_cache() + /** + * [disableCache description] + */ + protected function disableCache() { @unlink(WP_CONTENT_DIR . '/advanced-cache.php'); - - return true; } - public function network_admin_menu() + /** + * [networkAdminMenu description] + */ + public function networkAdminMenu() { if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'rrze_cache_network-options') && current_user_can('manage_network_options')) { if (isset($_POST['rrze-cache-site-submit'])) { - $rrze_cache_site = isset($_POST['rrze_cache_site']) ? $_POST['rrze_cache_site'] : []; + $siteCache = isset($_POST['rrze_cache_site']) ? $_POST['rrze_cache_site'] : []; - $cache_error = null; + $cacheError = false; - $cache_enabled = !empty($rrze_cache_site['cache_enabled']) ? 1 : 0; - $cache_expires = !empty($rrze_cache_site['cache_expires']) && absint($rrze_cache_site['cache_expires']) >= 1 ? absint($rrze_cache_site['cache_expires']) : $this->site_options->cache_expires; + $cacheEnabled = !empty($siteCache['cache_enabled']) ? 1 : 0; + $cacheExpires = !empty($siteCache['cache_expires']) && absint($siteCache['cache_expires']) >= 1 ? absint($siteCache['cache_expires']) : $this->siteOptions->cache_expires; - $return = $this->enable_cache(); - if ($cache_enabled && (!defined('WP_CACHE') || !WP_CACHE)) { - if (is_wp_error($return)) { - $cache_enabled = 0; - $cache_error = $return->get_error_message(); - } - } elseif (!$cache_enabled) { - $return = $this->disable_cache(); - if (is_wp_error($return)) { - $cache_enabled = 1; - $cache_error = $return->get_error_message(); + $enableCache = $this->enableCache(); + if ($cacheEnabled && (! defined('WP_CACHE') || ! WP_CACHE)) { + if (! $enableCache) { + $cacheEnabled = 0; + $cacheError = true; } + } elseif (! $cacheEnabled) { + $this->disableCache(); } else { - $cache_enabled = $this->site_options->cache_enabled = $cache_enabled; + $cacheEnabled = $this->siteOptions->cache_enabled = $cacheEnabled; } - if (is_null($cache_error)) { - $this->site_options->cache_enabled = $cache_enabled; - $this->site_options->cache_expires = $cache_expires; - - File::store_timeout($cache_expires); - - update_site_option(Options::get_site_option_name(), $this->site_options); + if (! $cacheError) { + $this->siteOptions->cache_enabled = $cacheEnabled; + $this->siteOptions->cache_expires = $cacheExpires; + File::storeTimeout($cacheExpires); + update_site_option($this->siteOptionName, $this->siteOptions); } - $query_val = 'updated'; + $queryVal = 'updated'; } elseif (isset($_POST['rrze-cache-site-flush'])) { - Flush::flush_cache_all(); - $query_val = 'flushed'; + Flush::flushAllCache(); + $queryVal = 'flushed'; } - wp_redirect(add_query_arg(array('page' => 'rrzecache-network', 'update' => $query_val), network_admin_url('settings.php'))); + wp_redirect(add_query_arg(array('page' => 'rrzecache-network', 'update' => $queryVal), network_admin_url('settings.php'))); exit; } @@ -272,40 +324,52 @@ class Settings }); } - add_submenu_page('settings.php', __('Cache', 'rrze-cache'), __('Cache', 'rrze-cache'), 'manage_network_options', 'rrzecache-network', array($this, 'network_page_settings')); + add_submenu_page('settings.php', __('Cache', 'rrze-cache'), __('Cache', 'rrze-cache'), 'manage_network_options', 'rrzecache-network', [$this, 'networkPageSettings']); } - public function network_admin_settings() + /** + * [networkAdminSettings description] + */ + public function networkAdminSettings() { add_settings_section('rrze_advanced_cache_section', __('Page Cache (Advanced Cache)', 'rrze-cache'), '__return_false', 'rrze_cache_network'); - add_settings_field('rrze-cache-enable', __('Enable Cache', 'rrze-cache'), array($this, 'cache_enabled_field'), 'rrze_cache_network', 'rrze_advanced_cache_section'); - add_settings_field('rrze-cache-expires', __('Lifetime', 'rrze-cache'), array($this, 'cache_expires_field'), 'rrze_cache_network', 'rrze_advanced_cache_section'); + add_settings_field('rrze-cache-enable', __('Enable Cache', 'rrze-cache'), [$this, 'cacheEnabledField'], 'rrze_cache_network', 'rrze_advanced_cache_section'); + add_settings_field('rrze-cache-expires', __('Lifetime', 'rrze-cache'), [$this, 'cacheExpiresField'], 'rrze_cache_network', 'rrze_advanced_cache_section'); } - public function cache_enabled_field() + /** + * [cacheEnabledField description] + */ + public function cacheEnabledField() { ?> <label> - <input type="radio" name="rrze_cache_site[cache_enabled]" value="1" <?php checked('1', $this->site_options->cache_enabled); ?>><?php esc_html_e('Cache is enabled.', 'rrze-cache') ?> + <input type="radio" name="rrze_cache_site[cache_enabled]" value="1" <?php checked('1', $this->siteOptions->cache_enabled); ?>><?php esc_html_e('Cache is enabled.', 'rrze-cache') ?> </label><br> <label> - <input type="radio" name="rrze_cache_site[cache_enabled]" value="0" <?php checked('0', $this->site_options->cache_enabled); ?>><?php esc_html_e('Cache is disabled.', 'rrze-cache') ?> + <input type="radio" name="rrze_cache_site[cache_enabled]" value="0" <?php checked('0', $this->siteOptions->cache_enabled); ?>><?php esc_html_e('Cache is disabled.', 'rrze-cache') ?> </label> <?php } - public function cache_expires_field() + /** + * [cacheExpiresField description] + */ + public function cacheExpiresField() { ?> <label for="rrze-cache-expires"> - <input type="number" min="1" step="1" name="rrze_cache_site[cache_expires]" value="<?php echo esc_attr($this->site_options->cache_expires) ?>" class="small-text"> - <?php echo esc_html(_nx('Hour', 'Hours', $this->site_options->cache_expires, 'rrze-cache-expires', 'rrze-cache')) ?> + <input type="number" min="1" step="1" name="rrze_cache_site[cache_expires]" value="<?php echo esc_attr($this->siteOptions->cache_expires) ?>" class="small-text"> + <?php echo esc_html(_nx('Hour', 'Hours', $this->siteOptions->cache_expires, 'rrze-cache-expires', 'rrze-cache')) ?> </label> <?php } - public function network_page_settings() + /** + * [networkPageSettings description] + */ + public function networkPageSettings() { ?> <div class="wrap"> @@ -315,7 +379,7 @@ class Settings <?php settings_fields('rrze_cache_network'); do_settings_sections('rrze_cache_network'); ?> - <?php if ($this->site_options->cache_enabled) : ?> + <?php if ($this->siteOptions->cache_enabled) : ?> <?php submit_button(esc_html__('Save Changes', 'rrze-cache'), 'primary', 'rrze-cache-site-submit') ?> <?php else: ?> <?php submit_button(esc_html__('Save Changes', 'rrze-cache'), 'primary', 'rrze-cache-site-submit', false) ?> <?php submit_button(esc_html__('Delete Page Cache', 'rrze-cache'), 'secondary', 'rrze-cache-site-flush', false) ?> @@ -326,7 +390,12 @@ class Settings <?php } - public function admin_bar_flush_icon($wp_admin_bar) + /** + * [adminBarFlushIcon description] + * @param object $wpAdminBar [description] + * @return void + */ + public function adminBarFlushIcon($wpAdminBar) { if (!is_admin_bar_showing() || !current_user_can('manage_options')) { return; @@ -351,7 +420,7 @@ class Settings echo '<style>#wp-admin-bar-rrzecache{display:list-item !important} #wp-admin-bar-rrzecache .ab-icon{margin:0 !important} #wp-admin-bar-rrzecache .ab-icon:before{content:"\f182";top:2px;margin:0}</style>'; - $wp_admin_bar->add_menu( + $wpAdminBar->add_menu( array( 'id' => 'rrzecache', 'href' => wp_nonce_url(add_query_arg('rrzecache_flush_post', $post_ID), 'rrzecache_flush_post_nonce'), // esc_url in /wp-includes/class-wp-admin-bar.php#L438 @@ -362,7 +431,11 @@ class Settings ); } - public function admin_bar_flush_request() + /** + * [adminBarFlushRequest description] + * @return void + */ + public function adminBarFlushRequest() { if (!current_user_can('manage_options')) { return; @@ -381,17 +454,20 @@ class Settings return; } - Flush::flush_cache_by_post_id($post_ID); + Flush::flushCacheByPostId($post_ID); if (is_admin()) { - $this->admin_notice_flush_cache(); + $this->adminNoticeFlushCache(); } else { wp_safe_redirect(remove_query_arg('rrzecache_flush_post', wp_get_referer())); exit(); } } - protected function admin_notice_flush_cache() + /** + * [adminNoticeFlushCache description] + */ + protected function adminNoticeFlushCache() { add_action('admin_notices', function () { echo sprintf('<div class="updated settings-error notice is-dismissible"><p><strong>%s</strong></p></div>', esc_html__(__('Cache is empty.', 'rrze-cache'))); diff --git a/languages/rrze-cache-de_DE.mo b/languages/rrze-cache-de_DE.mo index ac0ccc8a33384b4eefcdbbefd3adfdb0f308c640..f9fa02787a583afdd7a158cf401c9536a3043ba5 100644 Binary files a/languages/rrze-cache-de_DE.mo and b/languages/rrze-cache-de_DE.mo differ diff --git a/languages/rrze-cache-de_DE.po b/languages/rrze-cache-de_DE.po index 9d6661c246a1e63a35c5b88409589e4e52e06ebc..94be295e9644fae7c5c510bbb3d195189dec77e7 100644 --- a/languages/rrze-cache-de_DE.po +++ b/languages/rrze-cache-de_DE.po @@ -2,8 +2,8 @@ msgid "" msgstr "" "Project-Id-Version: RRZE Cache\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-07 13:17+0000\n" -"PO-Revision-Date: 2020-02-07 13:19+0000\n" +"POT-Creation-Date: 2020-03-27 13:00+0000\n" +"PO-Revision-Date: 2020-03-27 13:04+0000\n" "Last-Translator: RRZE Webteam <webmaster@fau.de>\n" "Language-Team: Deutsch\n" "Language: de_DE\n" @@ -15,7 +15,7 @@ msgstr "" "X-Loco-Version: 2.3.1; wp-5.3.2\n" "X-Loco-Template: languages/rrze-cache-de_DE_formal.po" -#: rrze-cache.php:63 +#: rrze-cache.php:66 #, php-format msgid "" "The server is running PHP version %1$s. The Plugin requires at least PHP " @@ -24,7 +24,7 @@ msgstr "" "Auf dem Server läuft PHP Version %1$s. Das Plugin benötigt mindestens PHP " "Version %2$s." -#: rrze-cache.php:65 +#: rrze-cache.php:68 #, php-format msgid "" "The server is running WordPress version %1$s. The Plugin requires at least " @@ -33,48 +33,53 @@ msgstr "" "Auf dem Server läuft WordPress Version %1$s. Das Plugin benötigt mindestens " "WordPress Version %2$s." -#: rrze-cache.php:67 +#: rrze-cache.php:70 msgid "The constant WP_CACHE is not defined or is set to false." msgstr "Die Konstante WP_CACHE ist nicht definiert oder auf false gesetzt." -#: includes/Settings.php:49 includes/Settings.php:57 +#: rrze-cache.php:84 rrze-cache.php:113 +#, php-format +msgid "Plugins: %1$s: %2$s" +msgstr "Plugins: %1$s: %2$s" + +#: includes/Settings.php:77 includes/Settings.php:90 msgid "Settings" msgstr "Einstellungen" -#: includes/Settings.php:66 includes/Settings.php:275 includes/Settings.php:275 -#: includes/Settings.php:312 +#: includes/Settings.php:102 includes/Settings.php:332 +#: includes/Settings.php:332 includes/Settings.php:381 msgid "Cache" msgstr "Cache" -#: includes/Settings.php:123 +#: includes/Settings.php:169 #, php-format msgid "%s (Access protection activated)" msgstr "%s (Zugriffsschutz aktiviert)" -#: includes/Settings.php:133 +#: includes/Settings.php:179 msgid "Select the checkbox to remove an item from the list." msgstr "Checkbox markieren, um ein Element aus der Liste zu entfernen." -#: includes/Settings.php:135 +#: includes/Settings.php:181 msgid "No items found." msgstr "Keine Elemente gefunden." -#: includes/Settings.php:152 +#: includes/Settings.php:200 msgid "Cache Settings" msgstr "Einstellungen › Cache" -#: includes/Settings.php:160 includes/Settings.php:283 +#: includes/Settings.php:208 includes/Settings.php:343 msgid "Lifetime" msgstr "Laufzeit" -#: includes/Settings.php:166 includes/Settings.php:303 +#: includes/Settings.php:214 includes/Settings.php:369 msgctxt "rrze-cache-expires" msgid "Hour" msgid_plural "Hours" msgstr[0] "Stunde" msgstr[1] "Stunden" -#: includes/Settings.php:168 +#: includes/Settings.php:216 #, php-format msgctxt "rrze-cache-expires" msgid "%s hour." @@ -82,112 +87,133 @@ msgid_plural "%s hours." msgstr[0] "%s Stunde." msgstr[1] "%s Stunden." -#: includes/Settings.php:175 +#: includes/Settings.php:223 msgid "Rules" msgstr "Regeln" -#: includes/Settings.php:181 +#: includes/Settings.php:229 msgid "Clear the cache when publishing or updating." msgstr "Cache leeren beim Veröffentlichen oder Aktualisieren." -#: includes/Settings.php:185 +#: includes/Settings.php:233 msgid "New comments clear the cache." msgstr "Neue Kommentare löschen den Cache." -#: includes/Settings.php:192 +#: includes/Settings.php:240 msgid "Exemptions" msgstr "Ausnahmen" -#: includes/Settings.php:200 includes/Settings.php:319 -#: includes/Settings.php:321 +#: includes/Settings.php:248 includes/Settings.php:388 +#: includes/Settings.php:390 msgid "Save Changes" msgstr "Änderungen speichern" -#: includes/Settings.php:200 includes/Settings.php:359 -#: includes/Settings.php:360 +#: includes/Settings.php:248 includes/Settings.php:433 +#: includes/Settings.php:434 msgid "Clear cache" msgstr "Cache löschen" -#: includes/Settings.php:270 +#: includes/Settings.php:327 msgid "Settings saved." msgstr "Einstellungen gespeichert." -#: includes/Settings.php:270 +#: includes/Settings.php:327 msgid "Cache is empty." msgstr "Cache ist leer." -#: includes/Settings.php:280 +#: includes/Settings.php:340 msgid "Page Cache (Advanced Cache)" msgstr "Seiten-Cache (Advanced-Cache)" -#: includes/Settings.php:282 +#: includes/Settings.php:342 msgid "Enable Cache" msgstr "Cache aktivieren" -#: includes/Settings.php:290 +#: includes/Settings.php:353 msgid "Cache is enabled." msgstr "Cache ist aktiviert." -#: includes/Settings.php:293 +#: includes/Settings.php:356 msgid "Cache is disabled." msgstr "Cache ist deaktiviert." -#: includes/Settings.php:321 +#: includes/Settings.php:390 msgid "Delete Page Cache" msgstr "Seiten-Cache löschen" -#: includes/Main.php:77 +#: includes/Main.php:108 msgid "All" msgstr "Alle" -#: includes/Main.php:78 +#: includes/Main.php:109 msgid "Selected" msgstr "Ausgewählt" -#: includes/Main.php:79 +#: includes/Main.php:110 msgid "Search..." msgstr "Suche..." -#: includes/Main.php:189 +#: includes/Main.php:233 msgid "Disabled" msgstr "Deaktiviert" -#: includes/Main.php:189 +#: includes/Main.php:233 msgid "Enabled" msgstr "Aktiviert" -#: includes/Main.php:194 +#: includes/Main.php:238 msgid "Cache:" msgstr "Cache:" -#: includes/Main.php:199 +#: includes/Main.php:243 msgid "Edit" msgstr "Bearbeiten" -#: includes/Main.php:200 +#: includes/Main.php:244 msgid "Edit Cache" msgstr "Cache bearbeiten" -#: includes/Main.php:205 +#: includes/Main.php:249 msgid "Enable" msgstr "Aktivieren" -#: includes/Main.php:208 +#: includes/Main.php:252 msgid "Disable" msgstr "Deaktivieren" -#: includes/Main.php:211 +#: includes/Main.php:255 msgid "OK" msgstr "OK" -#: includes/Main.php:212 +#: includes/Main.php:256 msgid "Cancel" msgstr "Abbrechen" -#: includes/File.php:76 +#: includes/File.php:33 +msgid "{plugin}: Can not save cache item. The data is empty." +msgstr "" +"{plugin}: Cache-Element kann nicht gespeichert werden. Die Daten sind leer." + +#: includes/File.php:93 msgid "Y-m-d H:i:s" msgstr "d.m.Y H:i:s" +#: includes/File.php:105 +msgid "{plugin}: Das Verzeichnis konnte nicht erstellt werden." +msgstr "{plugin}: Das Verzeichnis konnte nicht erstellt werden." + +#: includes/File.php:122 +msgid "{plugin}: The directory could not be created." +msgstr "{plugin}: Das Verzeichnis konnte nicht erstellt werden." + +#: includes/File.php:134 +msgid "{plugin}: The timeout cache file could not be written." +msgstr "{plugin}: Die Timeout-Cache-Datei konnte nicht geschrieben werden." + +#: includes/File.php:156 +msgid "{plugin}: The cache file could not be written." +msgstr "{plugin}: Die Cache-Datei konnte nicht geschrieben werden." + #. Name of the plugin msgid "RRZE Cache" msgstr "RRZE Cache" diff --git a/languages/rrze-cache-de_DE_formal.mo b/languages/rrze-cache-de_DE_formal.mo index eef0d7bb431106d8ccc3ee143a5fd821fbab7637..9fc3aee93dc67fa0d65a5f326bea327d3f412be7 100644 Binary files a/languages/rrze-cache-de_DE_formal.mo and b/languages/rrze-cache-de_DE_formal.mo differ diff --git a/languages/rrze-cache-de_DE_formal.po b/languages/rrze-cache-de_DE_formal.po index 1e3c997757a36d757b4bfcc170a52a8c9099aa71..02d3db5b3882f1b0d58515919933a1a45c206729 100644 --- a/languages/rrze-cache-de_DE_formal.po +++ b/languages/rrze-cache-de_DE_formal.po @@ -2,8 +2,8 @@ msgid "" msgstr "" "Project-Id-Version: RRZE Cache\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-07 13:17+0000\n" -"PO-Revision-Date: 2020-02-07 13:19+0000\n" +"POT-Creation-Date: 2020-03-27 13:00+0000\n" +"PO-Revision-Date: 2020-03-27 13:04+0000\n" "Last-Translator: RRZE Webteam <webmaster@fau.de>\n" "Language-Team: Deutsch (Sie)\n" "Language: de_DE_formal\n" @@ -14,7 +14,7 @@ msgstr "" "X-Generator: Loco https://localise.biz/\n" "X-Loco-Version: 2.3.1; wp-5.3.2" -#: rrze-cache.php:63 +#: rrze-cache.php:66 #, php-format msgid "" "The server is running PHP version %1$s. The Plugin requires at least PHP " @@ -23,7 +23,7 @@ msgstr "" "Auf dem Server läuft PHP Version %1$s. Das Plugin benötigt mindestens PHP " "Version %2$s." -#: rrze-cache.php:65 +#: rrze-cache.php:68 #, php-format msgid "" "The server is running WordPress version %1$s. The Plugin requires at least " @@ -32,48 +32,53 @@ msgstr "" "Auf dem Server läuft WordPress Version %1$s. Das Plugin benötigt mindestens " "WordPress Version %2$s." -#: rrze-cache.php:67 +#: rrze-cache.php:70 msgid "The constant WP_CACHE is not defined or is set to false." msgstr "Die Konstante WP_CACHE ist nicht definiert oder auf false gesetzt." -#: includes/Settings.php:49 includes/Settings.php:57 +#: rrze-cache.php:84 rrze-cache.php:113 +#, php-format +msgid "Plugins: %1$s: %2$s" +msgstr "Plugins: %1$s: %2$s" + +#: includes/Settings.php:77 includes/Settings.php:90 msgid "Settings" msgstr "Einstellungen" -#: includes/Settings.php:66 includes/Settings.php:275 includes/Settings.php:275 -#: includes/Settings.php:312 +#: includes/Settings.php:102 includes/Settings.php:332 +#: includes/Settings.php:332 includes/Settings.php:381 msgid "Cache" msgstr "Cache" -#: includes/Settings.php:123 +#: includes/Settings.php:169 #, php-format msgid "%s (Access protection activated)" msgstr "%s (Zugriffsschutz aktiviert)" -#: includes/Settings.php:133 +#: includes/Settings.php:179 msgid "Select the checkbox to remove an item from the list." msgstr "Checkbox markieren, um ein Element aus der Liste zu entfernen." -#: includes/Settings.php:135 +#: includes/Settings.php:181 msgid "No items found." msgstr "Keine Elemente gefunden." -#: includes/Settings.php:152 +#: includes/Settings.php:200 msgid "Cache Settings" msgstr "Einstellungen › Cache" -#: includes/Settings.php:160 includes/Settings.php:283 +#: includes/Settings.php:208 includes/Settings.php:343 msgid "Lifetime" msgstr "Laufzeit" -#: includes/Settings.php:166 includes/Settings.php:303 +#: includes/Settings.php:214 includes/Settings.php:369 msgctxt "rrze-cache-expires" msgid "Hour" msgid_plural "Hours" msgstr[0] "Stunde" msgstr[1] "Stunden" -#: includes/Settings.php:168 +#: includes/Settings.php:216 #, php-format msgctxt "rrze-cache-expires" msgid "%s hour." @@ -81,112 +86,133 @@ msgid_plural "%s hours." msgstr[0] "%s Stunde." msgstr[1] "%s Stunden." -#: includes/Settings.php:175 +#: includes/Settings.php:223 msgid "Rules" msgstr "Regeln" -#: includes/Settings.php:181 +#: includes/Settings.php:229 msgid "Clear the cache when publishing or updating." msgstr "Cache leeren beim Veröffentlichen oder Aktualisieren." -#: includes/Settings.php:185 +#: includes/Settings.php:233 msgid "New comments clear the cache." msgstr "Neue Kommentare löschen den Cache." -#: includes/Settings.php:192 +#: includes/Settings.php:240 msgid "Exemptions" msgstr "Ausnahmen" -#: includes/Settings.php:200 includes/Settings.php:319 -#: includes/Settings.php:321 +#: includes/Settings.php:248 includes/Settings.php:388 +#: includes/Settings.php:390 msgid "Save Changes" msgstr "Änderungen speichern" -#: includes/Settings.php:200 includes/Settings.php:359 -#: includes/Settings.php:360 +#: includes/Settings.php:248 includes/Settings.php:433 +#: includes/Settings.php:434 msgid "Clear cache" msgstr "Cache löschen" -#: includes/Settings.php:270 +#: includes/Settings.php:327 msgid "Settings saved." msgstr "Einstellungen gespeichert." -#: includes/Settings.php:270 +#: includes/Settings.php:327 msgid "Cache is empty." msgstr "Cache ist leer." -#: includes/Settings.php:280 +#: includes/Settings.php:340 msgid "Page Cache (Advanced Cache)" msgstr "Seiten-Cache (Advanced-Cache)" -#: includes/Settings.php:282 +#: includes/Settings.php:342 msgid "Enable Cache" msgstr "Cache aktivieren" -#: includes/Settings.php:290 +#: includes/Settings.php:353 msgid "Cache is enabled." msgstr "Cache ist aktiviert." -#: includes/Settings.php:293 +#: includes/Settings.php:356 msgid "Cache is disabled." msgstr "Cache ist deaktiviert." -#: includes/Settings.php:321 +#: includes/Settings.php:390 msgid "Delete Page Cache" msgstr "Seiten-Cache löschen" -#: includes/Main.php:77 +#: includes/Main.php:108 msgid "All" msgstr "Alle" -#: includes/Main.php:78 +#: includes/Main.php:109 msgid "Selected" msgstr "Ausgewählt" -#: includes/Main.php:79 +#: includes/Main.php:110 msgid "Search..." msgstr "Suche..." -#: includes/Main.php:189 +#: includes/Main.php:233 msgid "Disabled" msgstr "Deaktiviert" -#: includes/Main.php:189 +#: includes/Main.php:233 msgid "Enabled" msgstr "Aktiviert" -#: includes/Main.php:194 +#: includes/Main.php:238 msgid "Cache:" msgstr "Cache:" -#: includes/Main.php:199 +#: includes/Main.php:243 msgid "Edit" msgstr "Bearbeiten" -#: includes/Main.php:200 +#: includes/Main.php:244 msgid "Edit Cache" msgstr "Cache bearbeiten" -#: includes/Main.php:205 +#: includes/Main.php:249 msgid "Enable" msgstr "Aktivieren" -#: includes/Main.php:208 +#: includes/Main.php:252 msgid "Disable" msgstr "Deaktivieren" -#: includes/Main.php:211 +#: includes/Main.php:255 msgid "OK" msgstr "OK" -#: includes/Main.php:212 +#: includes/Main.php:256 msgid "Cancel" msgstr "Abbrechen" -#: includes/File.php:76 +#: includes/File.php:33 +msgid "{plugin}: Can not save cache item. The data is empty." +msgstr "" +"{plugin}: Cache-Element kann nicht gespeichert werden. Die Daten sind leer." + +#: includes/File.php:93 msgid "Y-m-d H:i:s" msgstr "d.m.Y H:i:s" +#: includes/File.php:105 +msgid "{plugin}: Das Verzeichnis konnte nicht erstellt werden." +msgstr "{plugin}: Das Verzeichnis konnte nicht erstellt werden." + +#: includes/File.php:122 +msgid "{plugin}: The directory could not be created." +msgstr "{plugin}: Das Verzeichnis konnte nicht erstellt werden." + +#: includes/File.php:134 +msgid "{plugin}: The timeout cache file could not be written." +msgstr "{plugin}: Die Timeout-Cache-Datei konnte nicht geschrieben werden." + +#: includes/File.php:156 +msgid "{plugin}: The cache file could not be written." +msgstr "{plugin}: Die Cache-Datei konnte nicht geschrieben werden." + #. Name of the plugin msgid "RRZE Cache" msgstr "RRZE Cache" diff --git a/languages/rrze-cache.pot b/languages/rrze-cache.pot index 76fdfd016531c21ed7160c51b76a858378052b9e..b40efbe889bea26dc0c396805eb56cc5fddd3c6e 100644 --- a/languages/rrze-cache.pot +++ b/languages/rrze-cache.pot @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: RRZE Cache\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-02-07 13:17+0000\n" +"POT-Creation-Date: 2020-03-27 13:00+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: \n" @@ -14,62 +14,67 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Loco https://localise.biz/" -#: rrze-cache.php:63 +#: rrze-cache.php:66 #, php-format msgid "" "The server is running PHP version %1$s. The Plugin requires at least PHP " "version %2$s." msgstr "" -#: rrze-cache.php:65 +#: rrze-cache.php:68 #, php-format msgid "" "The server is running WordPress version %1$s. The Plugin requires at least " "WordPress version %2$s." msgstr "" -#: rrze-cache.php:67 +#: rrze-cache.php:70 msgid "The constant WP_CACHE is not defined or is set to false." msgstr "" -#: includes/Settings.php:49 includes/Settings.php:57 +#: rrze-cache.php:84 rrze-cache.php:113 +#, php-format +msgid "Plugins: %1$s: %2$s" +msgstr "" + +#: includes/Settings.php:77 includes/Settings.php:90 msgid "Settings" msgstr "" -#: includes/Settings.php:66 includes/Settings.php:275 includes/Settings.php:275 -#: includes/Settings.php:312 +#: includes/Settings.php:102 includes/Settings.php:332 +#: includes/Settings.php:332 includes/Settings.php:381 msgid "Cache" msgstr "" -#: includes/Settings.php:123 +#: includes/Settings.php:169 #, php-format msgid "%s (Access protection activated)" msgstr "" -#: includes/Settings.php:133 +#: includes/Settings.php:179 msgid "Select the checkbox to remove an item from the list." msgstr "" -#: includes/Settings.php:135 +#: includes/Settings.php:181 msgid "No items found." msgstr "" -#: includes/Settings.php:152 +#: includes/Settings.php:200 msgid "Cache Settings" msgstr "" -#: includes/Settings.php:160 includes/Settings.php:283 +#: includes/Settings.php:208 includes/Settings.php:343 msgid "Lifetime" msgstr "" -#: includes/Settings.php:166 includes/Settings.php:303 +#: includes/Settings.php:214 includes/Settings.php:369 msgctxt "rrze-cache-expires" msgid "Hour" msgid_plural "Hours" msgstr[0] "" msgstr[1] "" -#: includes/Settings.php:168 +#: includes/Settings.php:216 #, php-format msgctxt "rrze-cache-expires" msgid "%s hour." @@ -77,112 +82,132 @@ msgid_plural "%s hours." msgstr[0] "" msgstr[1] "" -#: includes/Settings.php:175 +#: includes/Settings.php:223 msgid "Rules" msgstr "" -#: includes/Settings.php:181 +#: includes/Settings.php:229 msgid "Clear the cache when publishing or updating." msgstr "" -#: includes/Settings.php:185 +#: includes/Settings.php:233 msgid "New comments clear the cache." msgstr "" -#: includes/Settings.php:192 +#: includes/Settings.php:240 msgid "Exemptions" msgstr "" -#: includes/Settings.php:200 includes/Settings.php:319 -#: includes/Settings.php:321 +#: includes/Settings.php:248 includes/Settings.php:388 +#: includes/Settings.php:390 msgid "Save Changes" msgstr "" -#: includes/Settings.php:200 includes/Settings.php:359 -#: includes/Settings.php:360 +#: includes/Settings.php:248 includes/Settings.php:433 +#: includes/Settings.php:434 msgid "Clear cache" msgstr "" -#: includes/Settings.php:270 +#: includes/Settings.php:327 msgid "Settings saved." msgstr "" -#: includes/Settings.php:270 +#: includes/Settings.php:327 msgid "Cache is empty." msgstr "" -#: includes/Settings.php:280 +#: includes/Settings.php:340 msgid "Page Cache (Advanced Cache)" msgstr "" -#: includes/Settings.php:282 +#: includes/Settings.php:342 msgid "Enable Cache" msgstr "" -#: includes/Settings.php:290 +#: includes/Settings.php:353 msgid "Cache is enabled." msgstr "" -#: includes/Settings.php:293 +#: includes/Settings.php:356 msgid "Cache is disabled." msgstr "" -#: includes/Settings.php:321 +#: includes/Settings.php:390 msgid "Delete Page Cache" msgstr "" -#: includes/Main.php:77 +#: includes/Main.php:108 msgid "All" msgstr "" -#: includes/Main.php:78 +#: includes/Main.php:109 msgid "Selected" msgstr "" -#: includes/Main.php:79 +#: includes/Main.php:110 msgid "Search..." msgstr "" -#: includes/Main.php:189 +#: includes/Main.php:233 msgid "Disabled" msgstr "" -#: includes/Main.php:189 +#: includes/Main.php:233 msgid "Enabled" msgstr "" -#: includes/Main.php:194 +#: includes/Main.php:238 msgid "Cache:" msgstr "" -#: includes/Main.php:199 +#: includes/Main.php:243 msgid "Edit" msgstr "" -#: includes/Main.php:200 +#: includes/Main.php:244 msgid "Edit Cache" msgstr "" -#: includes/Main.php:205 +#: includes/Main.php:249 msgid "Enable" msgstr "" -#: includes/Main.php:208 +#: includes/Main.php:252 msgid "Disable" msgstr "" -#: includes/Main.php:211 +#: includes/Main.php:255 msgid "OK" msgstr "" -#: includes/Main.php:212 +#: includes/Main.php:256 msgid "Cancel" msgstr "" -#: includes/File.php:76 +#: includes/File.php:33 +msgid "{plugin}: Can not save cache item. The data is empty." +msgstr "" + +#: includes/File.php:93 msgid "Y-m-d H:i:s" msgstr "" +#: includes/File.php:105 +msgid "{plugin}: Das Verzeichnis konnte nicht erstellt werden." +msgstr "" + +#: includes/File.php:122 +msgid "{plugin}: The directory could not be created." +msgstr "" + +#: includes/File.php:134 +msgid "{plugin}: The timeout cache file could not be written." +msgstr "" + +#: includes/File.php:156 +msgid "{plugin}: The cache file could not be written." +msgstr "" + #. Name of the plugin msgid "RRZE Cache" msgstr "" diff --git a/rrze-cache.php b/rrze-cache.php index a80254b146d7e72fa14b6f2610fc7e0e3ac91251..fb7f8c3228e5a688b0556d81e1c3bd596f89a33c 100644 --- a/rrze-cache.php +++ b/rrze-cache.php @@ -4,7 +4,7 @@ Plugin Name: RRZE Cache Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-cache Description: Advanced cache management. -Version: 2.1.0 +Version: 2.2.0 Author: RRZE-Webteam Author URI: https://blogs.fau.de/webworking/ License: GNU General Public License v2 @@ -18,17 +18,13 @@ namespace RRZE\Cache; defined('ABSPATH') || exit; -use RRZE\Cache\Options; -use RRZE\Cache\Main; - -const RRZE_PHP_VERSION = '7.3'; +const RRZE_PHP_VERSION = '7.4'; const RRZE_WP_VERSION = '5.3'; -const RRZE_PLUGIN_FILE = __FILE__; - const RRZECACHE_META_KEY = '_rrze_cache'; const ACCESS_PERMISSION_META_KEY = '_access_permission'; // rrze-ac plugin +// Autoloader (PSR-4) spl_autoload_register(function ($class) { $prefix = __NAMESPACE__; $base_dir = __DIR__ . '/includes/'; @@ -38,8 +34,8 @@ spl_autoload_register(function ($class) { return; } - $relative_class = substr($class, $len); - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; + $relativeClass = substr($class, $len); + $file = $base_dir . str_replace('\\', '/', $relativeClass) . '.php'; if (file_exists($file)) { require $file; @@ -51,12 +47,19 @@ register_deactivation_hook(__FILE__, __NAMESPACE__ . '\deactivation'); add_action('plugins_loaded', __NAMESPACE__ . '\loaded'); -function load_textdomain() +/** + * [loadTextdomain description] + */ +function loadTextdomain() { load_plugin_textdomain('rrze-cache', false, sprintf('%s/languages/', dirname(plugin_basename(__FILE__)))); } -function system_requirements() +/** + * [systemRequirements description] + * @return string [description] + */ +function systemRequirements() { $error = ''; if (version_compare(PHP_VERSION, RRZE_PHP_VERSION, '<')) { @@ -69,36 +72,53 @@ function system_requirements() return $error; } +/** + * [activation description] + */ function activation() { - load_textdomain(); + loadTextdomain(); - if ($error = system_requirements()) { - deactivate_plugins(plugin_basename(__FILE__), false, true); - wp_die($error); + if ($error = systemRequirements()) { + deactivate_plugins(plugin_basename(__FILE__)); + wp_die(sprintf(__('Plugins: %1$s: %2$s', 'rrze-cache'), plugin_basename(__FILE__), $error)); } } +/** + * [deactivation description] + */ function deactivation() { @unlink(WP_CONTENT_DIR . '/advanced-cache.php'); - delete_site_option(Options::get_site_option_name()); + delete_site_option(Options::getSiteOptionName()); } -function loaded() -{ - load_textdomain(); - - if ($error = system_requirements()) { - deactivation(); - include_once(ABSPATH . 'wp-admin/includes/plugin.php'); - $plugin_data = get_plugin_data(__FILE__); - $plugin_name = $plugin_data['Name']; - $tag = is_network_admin() ? 'network_admin_notices' : 'admin_notices'; - add_action($tag, function () use ($plugin_name, $error) { - printf('<div class="notice notice-error"><p>%1$s: %2$s</p></div>', esc_html($plugin_name), esc_html($error)); - }); - } else { - new Main(); - } -} +/** + * [loaded description] + * @return void + */ + function loaded() + { + loadTextDomain(); + + if ($error = systemRequirements()) { + deactivation(); + add_action('admin_init', function () use ($error) { + $pluginData = get_plugin_data(__FILE__); + $pluginName = $pluginData['Name']; + $tag = is_plugin_active_for_network(plugin_basename(__FILE__)) ? 'network_admin_notices' : 'admin_notices'; + add_action($tag, function () use ($pluginName, $error) { + printf( + '<div class="notice notice-error"><p>' . __('Plugins: %1$s: %2$s', 'rrze-cache') . '</p></div>', + esc_html($pluginName), + esc_html($error) + ); + }); + }); + return; + } + + $main = new Main(__FILE__); + $main->onLoaded(); + }