Plugin Directory

Changeset 2036979


Ignore:
Timestamp:
02/22/2019 12:20:54 PM (7 years ago)
Author:
preliot
Message:

Public release of 4.1.1

Location:
cache-control-by-cacholong
Files:
28 added
38 edited
44 copied
2 moved

Legend:

Unmodified
Added
Removed
  • cache-control-by-cacholong/trunk/CacholongCacheControl.php

    r1974788 r2036979  
    11<?php
     2
    23/*
    34  Plugin Name: Cache control by Cacholong
    45  Description: Automates purging of Nginx Pagespeed cache and Nginx FastCGI cache on your Nginx server(s).
    5   Version: 4.0.2
     6  Version: 4.1.1
    67  Author: Cacholong
    78  Author URI: http://www.cacholong.nl
     
    1112  Domain Path: /languages
    1213
    13   Copyright © 2016-2018, Cacholong <[email protected]>
    14  
     14  Copyright © 2016-2019, Cacholong <[email protected]>
     15
    1516  This file is part of Cache Control
    16  
     17
    1718  Cache Control is free software: you can redistribute it and/or modify
    1819  it under the terms of the GNU General Public License as published by
    1920  the Free Software Foundation, either version 3 of the License, or
    2021  (at your option) any later version.
    21  
     22
    2223  Cache Control is distributed in the hope that it will be useful,
    2324  but WITHOUT ANY WARRANTY; without even the implied warranty of
    2425  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2526  GNU General Public License for more details.
    26  
     27
    2728  You should have received a copy of the GNU General Public License
    2829  along with Cache Control.  If not, see <http://www.gnu.org/licenses/>.
    2930 */
     31
    3032namespace Cacholong;
    3133
     
    5153     * @return      CacholongCache        Instance of CacholongCacheControl
    5254     */
    53     public static function init()
    54     {
    55         if(is_null(self::$_instance))
    56         {
     55    public static function init() {
     56        if (is_null(self::$_instance)) {
    5757            self::$_instance = new self;
    5858        }
     
    7171     *
    7272     */
    73     protected function __construct()
    74     {
     73    protected function __construct() {
    7574        do_action('cacholong_cache_control_construct');
    7675
     
    9089     *
    9190     */
    92     private function define_constants()
    93     {
     91    private function define_constants() {
    9492        $dir = dirname(__FILE__);
    9593        $dir = str_replace('\\', '/', $dir);
     
    120118     * @return      void
    121119     */
    122     private function define($name, $value)
    123     {
     120    private function define($name, $value) {
    124121        $name_uppercase = strtoupper($name);
    125122
    126         if(!defined($name_uppercase))
    127         {
     123        if (!defined($name_uppercase)) {
    128124            define($name_uppercase, $value);
    129125        }
     
    138134     *
    139135     * @version     1.0.0     Created at 2015-10-21
    140      * @version     1.0.1     2016-09-07 Added entity PostType
    141      * @return      void
    142      */
    143     private function requires()
    144     {
     136     *
     137     * @return      void
     138     */
     139    private function requires() {
    145140        //entities
    146         require_once(CACHOLONG_CACHE_DIR . '/core/entities/CacheType.php');
    147141        require_once(CACHOLONG_CACHE_DIR . '/core/entities/Identifier.php');
    148142        require_once(CACHOLONG_CACHE_DIR . '/core/entities/AdminPostAction.php');
     
    151145        require_once(CACHOLONG_CACHE_DIR . '/core/entities/PostType.php');
    152146        require_once(CACHOLONG_CACHE_DIR . '/core/entities/HttpApiRequest.php');
     147        require_once(CACHOLONG_CACHE_DIR . '/core/entities/SchedulerRecurrence.php');
    153148
    154149        //libraries / helpers
     
    158153        require_once(CACHOLONG_CACHE_DIR . '/core/libraries/Json.php');
    159154        require_once(CACHOLONG_CACHE_DIR . '/core/libraries/Style.php');
     155        require_once(CACHOLONG_CACHE_DIR . '/core/libraries/Scheduler.php');
    160156
    161157        //setup
     
    176172     *
    177173     * @version     1.0.0     Created at 2015-10-21
    178      * @version     1.0.1     2015-11-16 Added parameters to save_post
    179      * @version     1.0.2     2015-11-25 enqueue_scripts_and_styles + wp_ajax_xxxxx
    180      * @version     1.1.0     2016-09-14 Delete post
    181      * @version     1.2.0     2017-12-15 Added optional style_loader_tag filter
    182      * @version     1.3.0     2017-12-15 Removed sessions
    183      * @version     1.4.0     2017-12-21 Most hooks only available for admin
    184      * @version     1.5.0     2017-12-22 Bugfix: style_loader_tag + parse_request out of is_admin if()
    185      * @version     1.6.0     2018-11-15 wp_uniquie_post_slug > 6 arguments
    186      * @return      void
    187      */
    188     private function init_hooks()
    189     {
    190         if(is_admin())
    191         {
     174     *
     175     * @return      void
     176     */
     177    private function init_hooks() {
     178        if (is_admin()) {
    192179            //hooks for setup
    193180            register_activation_hook(__FILE__, array('\Cacholong\Libraries\CacholongCacheControlSetup', 'on_activation'));
    194181            register_deactivation_hook(__FILE__, array('\Cacholong\Libraries\CacholongCacheControlSetup', 'on_deactivation'));
    195182            register_uninstall_hook(__FILE__, array('\Cacholong\Libraries\CacholongCacheControlSetup', 'on_uninstall'));  // test in development with register_deactivation_hook             
    196            
    197 
    198183            //actions and filters
    199184            add_action('init', array('\Cacholong\CacholongCacheControl', 'load_plugin_textdomain'));
    200             add_action('admin_bar_menu', array('\Cacholong\Controller\Admin\ToolbarController', 'create_toolbar_node_purge_all'), 999);
    201185
    202186            add_action('init', array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'init'));
    203            
     187
    204188            add_action('save_post', array('\Cacholong\Controller\Admin\PurgeCacheController', 'handle_purge_post_save'), 10, 3);                    //purge when new post and updating post
    205189            add_action('wp_trash_post', array('\Cacholong\Controller\Admin\PurgeCacheController', 'handle_purge_post_trash_and_untrash'), 10);      //purge when post is trashed
     
    210194            add_action('wp_update_nav_menu', array('\Cacholong\CacholongCacheControl', 'handle_nav_menu_update'), 10, 2);   //nav bar save
    211195
    212             add_action('admin_init', array('\Cacholong\CacholongCacheControl', 'handle_purge_from_admin_bar'), 999);
    213 
    214             add_action('admin_enqueue_scripts', array('\Cacholong\CacholongCacheControl', 'enqueue_scripts_and_styles'));
     196            add_action('admin_enqueue_scripts', array('\Cacholong\CacholongCacheControl', 'enqueue_scripts_and_styles_backend'));
    215197
    216198            //handle messages
     
    223205
    224206        //front- and back-end
    225         if(get_option(\Cacholong\Entities\Identifier::CC_FIELD_REMOVE_STYLE_ID) == 1)
    226         {
     207        add_action('wp_enqueue_scripts', array('\Cacholong\CacholongCacheControl', 'enqueue_scripts_and_styles_frontend'));
     208        add_action('admin_bar_menu', array('\Cacholong\Controller\Admin\ToolbarController', 'create_toolbar_node_purge_all'), 999);
     209        add_action('admin_bar_init', array('\Cacholong\CacholongCacheControl', 'handle_purge_from_admin_bar'), 999);
     210
     211        if (get_option(\Cacholong\Entities\Identifier::CC_FIELD_REMOVE_STYLE_ID) == 1) {
    227212            add_filter('style_loader_tag', array('\Cacholong\Libraries\Style', 'remove_id'));                            //remove style id (if allowed)
    228213        }
     
    232217        add_action('parse_request', array('\Cacholong\CacholongCacheControl', 'handle_custom_url_parsing'));
    233218        add_action('init', array('\Cacholong\Controller\Admin\PurgeCacheController', 'init'));
    234     }
    235 
    236     /**
    237      * Enqueu all scripts and styles
     219
     220        //Debug
     221        add_action('cc_debug_hook', array('\Cacholong\CacholongCacheControl', 'handle_debug_hook'));
     222
     223        self::init_hooks_cron();
     224    }
     225   
     226   
     227      /**
     228     * Init hooks cronjobs
     229     *
     230     * This function will hook into updating of cron settings. Whenever a cron option is updated, handle_update_options_for_cron_settings is called.
     231     * New cron settings must be added to this function in order to be caught.
     232     *
     233     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     234     * @copyright   Cacholong <[email protected]>
     235     * @todo        ok
     236     *
     237     * @version     1.0.0     Created at 2019-02-20
     238     *
     239     * @return      void
     240     */
     241    private function init_hooks_cron() {
     242       
     243        //collect all cron options
     244        $cronOptions[] = \Cacholong\Entities\Identifier::CC_FIELD_CRON_ENABLED;
     245        $cronOptions[] = \Cacholong\Entities\Identifier::CC_FIELD_CRON_TIME;
     246 
     247        $cronCacheSettings = cacholong_cc_get_cron_settings_caches_field_key_and_name();
     248        foreach ($cronCacheSettings as $cronSettingCacheKey => $cacheName) {
     249            $cronOptions[] = $cronSettingCacheKey;
     250        }
     251       
     252        //Add action to each option
     253        foreach ($cronOptions as $cronOption)
     254        {
     255           add_action('update_option_' . $cronOption, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'handle_update_options_for_cron_settings'), 10, 3); //Action called when option is saved
     256        }
     257    }
     258
     259    /**
     260     * Enqueu all scripts and styles backend
    238261     *
    239262     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     
    244267     * @version     1.1.0     2016-09-07    Some settingsSection* vars
    245268     * @version     1.2.0     2018-02-28    Cache busting with fingerprinting
    246      * @return      void
    247      */
    248     public static function enqueue_scripts_and_styles()
    249     {
     269     * @versopm     1.3.0     2019-02-21    Added style
     270     * @return      void
     271     */
     272    public static function enqueue_scripts_and_styles_backend() {
    250273        $cc_plugin_data['ajaxUrl'] = admin_url('admin-ajax.php');
    251274        $cc_plugin_data['ajaxResponseTypeSuccess'] = \Cacholong\Entities\AjaxResponseType::SUCCESS;
     
    264287        );
    265288
    266         wp_register_script("cachalong-cache-control", CACHOLONG_CACHE_URL . '/js/cachalong-cache-control.js', array('jquery'), Libraries\File::fingerprint(CACHOLONG_CACHE_DIR . '/js/cachalong-cache-control.js'));
    267         wp_localize_script('cachalong-cache-control', 'cacholong_cc_plugin_data', $cc_plugin_data);
    268 
    269         wp_enqueue_script('cachalong-cache-control');
    270     }
     289        wp_register_script("cacholong-cache-control", CACHOLONG_CACHE_URL . '/js/cacholong-cache-control.js', array('jquery'), Libraries\File::fingerprint(CACHOLONG_CACHE_DIR . '/js/cacholong-cache-control.js'));
     290        wp_localize_script('cacholong-cache-control', 'cacholong_cc_plugin_data', $cc_plugin_data);
     291
     292        wp_enqueue_script('cacholong-cache-control');
     293
     294        wp_enqueue_style("cacholong-cache-control-style", CACHOLONG_CACHE_URL . "/css/cacholong-cache-control.css", array(), Libraries\File::fingerprint(CACHOLONG_CACHE_DIR . '/css/cacholong-cache-control.css'));
     295    }
     296   
     297    /**
     298     * Enqueu all scripts and styles (frontend)
     299     *
     300     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     301     * @copyright   Cacholong <[email protected]>
     302     * @todo        ok
     303     *
     304     * @version     1.0.0     2019-02-21
     305     * @return      void
     306     */
     307    public static function enqueue_scripts_and_styles_frontend() {
     308        //on frontend because of adminbar
     309        wp_enqueue_style("cacholong-cache-control-style", CACHOLONG_CACHE_URL . "/css/cacholong-cache-control.css", array(), Libraries\File::fingerprint(CACHOLONG_CACHE_DIR . '/css/cacholong-cache-control.css'));
     310    }
     311   
    271312
    272313    /**
     
    281322     * @return      void
    282323     */
    283     public static function load_plugin_textdomain()
    284     {
     324    public static function load_plugin_textdomain() {
    285325        load_plugin_textdomain(\Cacholong\Entities\Identifier::CC_TEXT_DOMAIN, false, dirname(CACHOLONG_CACHE_BASENAME) . '/languages/');
    286326    }
     
    298338     * @return      void
    299339     */
    300     public static function handle_custom_url_parsing($query)
    301     {
    302         if($query->request == \Cacholong\Entities\Identifier::CC_CUSTOM_URL_PARSE)
    303         {
     340    public static function handle_custom_url_parsing($query) {
     341        if ($query->request == \Cacholong\Entities\Identifier::CC_CUSTOM_URL_PARSE) {
    304342            self::handle_nginx_fastcgi_full_purge();
    305343            exit();     //query is handled outside of wordpress logic
     
    321359     * @return      void
    322360     */
    323     public static function handle_purge_from_admin_bar()
    324     {
    325         if(isset($_GET[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY]) &&
    326             ($_GET[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY] == \Cacholong\Entities\Identifier::CC_REQUEST_ACTION_PURGE_ALL_ADMIN_BAR))
    327         {
     361    public static function handle_purge_from_admin_bar() {
     362        if (isset($_GET[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY]) &&
     363                ($_GET[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY] == \Cacholong\Entities\Identifier::CC_REQUEST_ACTION_PURGE_ALL_ADMIN_BAR)) {
    328364            $nonce = $_GET['_wpnonce'];
    329             if(wp_verify_nonce($nonce))
    330             {
     365            if (wp_verify_nonce($nonce)) {
    331366                \Cacholong\Controller\Admin\PurgeCacheController::handle_purge_all_from_admin_bar();
    332             }
    333             else
    334             {
     367            } else {
    335368                //silent fail
    336369                cacholong_cc_log_error(__('Purge from admin bar failed silently, because nonce was not valid', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), __FILE__);
     
    351384     * @return      void
    352385     */
    353     private static function handle_nginx_fastcgi_full_purge()
    354     {
    355         if(isset($_POST[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY]) && ($_POST[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY] == \Cacholong\Entities\Identifier::CC_REQUEST_ACTION_PURGE_ALL_NGINX_FASTCGI))
    356         {
     386    private static function handle_nginx_fastcgi_full_purge() {
     387        if (isset($_POST[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY]) && ($_POST[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY] == \Cacholong\Entities\Identifier::CC_REQUEST_ACTION_PURGE_ALL_NGINX_FASTCGI)) {
    357388            $httpResponseCode = \Cacholong\Controller\Admin\PurgeCacheController::handle_purge_nginx_fastcgi();
    358         }
    359         else
    360         {
     389        } else {
    361390            $httpResponseCode = 404;    //Error, not found
    362391        }
     
    364393
    365394        //Response
    366         if(!headers_sent())
    367         {
     395        if (!headers_sent()) {
    368396            http_response_code($httpResponseCode);
    369         }
    370         else
    371         {
     397        } else {
    372398            cacholong_cc_log_error(sprintf(__('Cannot sent http response code %s, because header is already send.', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), $httpResponseCode), __FILE__);
    373399        }
     
    385411     * @return      void
    386412     */
    387     public static function handle_ajax_messages()
    388     {
     413    public static function handle_ajax_messages() {
    389414        \Cacholong\Libraries\AdminMessage::handle_ajax_messages();
    390415    }
     
    404429     * @return      void
    405430     */
    406     public static function handle_nav_menu_update($menu_id, $menu_data = array())
    407     {
     431    public static function handle_nav_menu_update($menu_id, $menu_data = array()) {
    408432        \Cacholong\Controller\Admin\PurgeCacheController::handle_nav_bar_change($menu_id, $menu_data = array());
    409433    }
     
    421445     * @return      void
    422446     */
    423     public static function handle_shutdown()
    424     {
     447    public static function handle_shutdown() {
    425448        $ajax = defined('DOING_AJAX') && DOING_AJAX;
    426         if(!$ajax)
    427         {
     449        if (!$ajax) {
    428450            \Cacholong\Controller\Admin\PurgeCacheController::purge_navbar_changes();
    429451            \Cacholong\Controller\Admin\PurgeCacheController::purge_slug_changes();
     
    432454    }
    433455
     456    /**
     457     * Handle debug hook
     458     *
     459     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     460     * @copyright   Cacholong <[email protected]>
     461     * @todo        ok
     462     *
     463     * @version     1.0.0     Created at 2019-02-20
     464     *
     465     * @param       mixed     ...        Optional. Unlimited number of additional variables. Default none.
     466     *
     467     * @return      void
     468     */
     469    public static function handle_debug_hook() {
     470        $arguments = func_get_args();
     471        $argumentsList = cacholong_cc_itemlist_to_sentence($arguments);
     472
     473        cacholong_cc_log_error("Debug hook is called with following arguments: {$argumentsList}.");
     474    }
     475
    434476}
     477
    435478/**
    436479 * Start plugin
  • cache-control-by-cacholong/trunk/changelog.txt

    r1974795 r2036979  
    11== Changelog ==
    22All notable changes to this plugin will be documented in this file. Copy of all changes for last MAJOR version can also be found in readme.txt.
     3
     4= 4.1.1 - 2019-02-22 =
     5
     6* Added - When Wordpress cronjobs are disabled (DISABLE_WP_CRON = true), text with link to FAQ is shown underneath setting to activate cronjob purging
     7* Added - Current timezone underneath setting for cronjob time of day
     8
     9= 4.1.0 - 2019-02-21 =
     10* Added - Plugin is capable to purge with Wordpress cronjobs
     11* Added - Plugin is tested for usage with Wordpress 5.0.3
     12* Added - Icon for 'Purge all caches' on adminbar
     13* Fixed - Errors caused by empty 'File with hosts (JSON)' setting
     14* Changed - 'Purge all caches' also available on frontend adminbar
     15* Changed - Corrected a few spellerrors (cachalong -> cacholong)
     16* Changed - Updated copyright from 2015-2018 to 2015-2019
     17
    318
    419= 4.0.2 - 2018-11-15 =
  • cache-control-by-cacholong/trunk/core/controller/admin/AdminSettingsPageController.php

    r1834268 r2036979  
    11<?php
     2
    23/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    45 *
    56 * This file is part of Cache Control
     
    1819 * along with Cache Control.  If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022namespace Cacholong\Controller\Admin;
    2123
    2224defined('ABSPATH') OR exit;
     25
     26use Cacholong\Libraries\Scheduler;
    2327
    2428/**
     
    3135 */
    3236class AdminSettingsPageController {
     37    /*
     38     * @const     string         FLASHDATA_KEY_CRON_CACHE_SETTINGS_CHANGED       Updated cron cache settings on settings page (can't use bool, because of new UserOptions lib)
     39     */
     40
     41    const FLASHDATA_KEY_CRON_CACHE_SETTINGS_CHANGED = 'updated_cron_cache_settings';
    3342
    3443    /**
     
    4049     *
    4150     * @version     1.0.0     Created at 2015-10-21
    42      *
    43      */
    44     public static function init()
    45     {
     51     * @version     1.1.0     2019-02-21 Added action update_cron_cache_purging_if_needed
     52     */
     53    public static function init() {
    4654        do_action('cacholong_cache_control_admin_settings_before_init');
    4755
     
    5058        add_action('admin_init', array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'register_settings'));
    5159
     60        add_action('admin_init', array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'update_cron_cache_purging_if_needed'));
     61
    5262        do_action('cacholong_cache_control_admin_settings_after_init');
     63    }
     64
     65    /**
     66     * Handle updated options for cron settings on settings page
     67     * Note: will only set flash signal, cron handling in self::update_cron_cache_purging_if_needed().
     68     *
     69     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     70     * @copyright   Cacholong <[email protected]>
     71     * @todo        ok
     72     *
     73     * @version     1.0.0     2019-02-20
     74     *
     75     * @param       mixed     $oldValue     Old value
     76     * @param       mixed     $newValue     New value
     77     * @param       string    $optionName   Name of option
     78     *
     79     * @return      void
     80     */
     81    public static function handle_update_options_for_cron_settings($oldValue, $newValue, $optionName) {
     82        \Cacholong\Libraries\FlashData::set_flash([self::FLASHDATA_KEY_CRON_CACHE_SETTINGS_CHANGED => '1']);
     83    }
     84
     85    /**
     86     * Update cron cache purging if needed
     87     *
     88     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     89     * @copyright   Cacholong <[email protected]>
     90     * @todo        ok
     91     *
     92     * @version     1.0.0     2019-02-20
     93     *
     94     * @return      void
     95     */
     96    public static function update_cron_cache_purging_if_needed() {
     97
     98        $cronCacheSettingsChanged = \Cacholong\Libraries\FlashData::get_flash(self::FLASHDATA_KEY_CRON_CACHE_SETTINGS_CHANGED); //one or more cron cache settings changed
     99
     100        if ($cronCacheSettingsChanged[self::FLASHDATA_KEY_CRON_CACHE_SETTINGS_CHANGED] === '1') {
     101            $cronKeysAndHookPurgeNames = cacholong_cc_get_cron_settings_caches_field_key_and_hook_purge_name();
     102           
     103            $cronOptionEnabled = get_option(\Cacholong\Entities\Identifier::CC_FIELD_CRON_ENABLED);
     104            $cronOptionTime = cacholong_cc_get_option_cron_time();
     105            $cronOptionsCache = cacholong_cc_get_options_cron_caches();
     106
     107            //Set / unset all scheduled events
     108            foreach ($cronKeysAndHookPurgeNames as $cronCacheFieldKey => $cronCacheHookPurgeName) {
     109                if ($cronOptionEnabled) {
     110                    if ($cronOptionsCache[$cronCacheFieldKey] === '1') {
     111                        Scheduler::set_daily_event($cronOptionTime, $cronCacheHookPurgeName);
     112                    }
     113                    else
     114                    {
     115                        Scheduler::unset_event($cronCacheHookPurgeName);
     116                    }
     117                } else {    //ok
     118                    //Unsetting can be done for all, no need to check if event was there.
     119                    Scheduler::unset_event($cronCacheHookPurgeName);
     120                }
     121            }
     122        }
     123        //else do nop
    53124    }
    54125
     
    65136     * @return      void
    66137     */
    67     public static function create_settings_page()
    68     {
     138    public static function create_settings_page() {
    69139        add_options_page(
    70             _x('Cache control by Cacholong', 'Title of settings page', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), _x('Cache control', 'Menu title of settings page', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), 'manage_options', \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_page')
     140                _x('Cache control by Cacholong', 'Title of settings page', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), _x('Cache control', 'Menu title of settings page', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), 'manage_options', \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_page')
    71141        );
    72142    }
     
    83153     * @return      void
    84154     */
    85     public static function create_settings_page_sections()
    86     {
     155    public static function create_settings_page_sections() {
    87156        self::create_section_settings();
    88157    }
     
    98167     * @version     1.1.0     2016-09-07 Add purge settings
    99168     * @version     1.2.0     2017-12-15 Add CC_FIELD_REMOVE_STYLE_ID
    100      *
    101      * @return      void
    102      */
    103     private static function create_section_settings()
    104     {
    105         //create section on options page
     169     * @version     1.3.0     2019-02-19 Cronjob settings section + cronjob settings
     170     * @return      void
     171     */
     172    private static function create_section_settings() {
     173        //create sections on options page
    106174        add_settings_section(
    107             \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION, _x('Settings', 'Subtitle for settings section', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_section_settings'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID);
    108 
    109         //create fields in section on options page
    110         add_settings_field(
    111             \Cacholong\Entities\Identifier::CC_FIELD_HOSTS_FILE, _x('File with hosts (JSON)', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_location_json_hosts_file'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
    112 
    113         add_settings_field(
    114             \Cacholong\Entities\Identifier::CC_FIELD_REMOVE_STYLE_ID, _x('Pagespeed optimized CSS', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_remove_style_id'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
    115        
    116         add_settings_field(
    117             \Cacholong\Entities\Identifier::CC_FIELD_DEFAULT_POST_PURGE_SETTINGS, _x('Purge settings default post types', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_default_post_purge_settings'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
    118 
    119         if(\Cacholong\Entities\PostType::has_custom())
    120         {
     175                \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION, _x('Settings', 'Subtitle for settings section', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_section_settings'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID);
     176
     177        add_settings_section(
     178                \Cacholong\Entities\Identifier::CC_SETTINGS_CRONJOB_SECTION, _x('Cronjob settings', 'Subtitle for cronjob settings section', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_section_settings_cronjob'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID);
     179
     180
     181        //create fields in section CC_SETTINGS_SECTION on options page
     182        add_settings_field(
     183                \Cacholong\Entities\Identifier::CC_FIELD_HOSTS_FILE, _x('File with hosts (JSON)', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_location_json_hosts_file'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
     184
     185        add_settings_field(
     186                \Cacholong\Entities\Identifier::CC_FIELD_REMOVE_STYLE_ID, _x('Pagespeed optimized CSS', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_remove_style_id'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
     187
     188        add_settings_field(
     189                \Cacholong\Entities\Identifier::CC_FIELD_DEFAULT_POST_PURGE_SETTINGS, _x('Purge settings default post types', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_default_post_purge_settings'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
     190
     191        if (\Cacholong\Entities\PostType::has_custom()) {
    121192            add_settings_field(
    122                 \Cacholong\Entities\Identifier::CC_FIELD_CUSTOM_POST_PURGE_SETTINGS, _x('Purge settings custom post type(s)', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_custom_post_purge_settings'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
     193                    \Cacholong\Entities\Identifier::CC_FIELD_CUSTOM_POST_PURGE_SETTINGS, _x('Purge settings custom post type(s)', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_custom_post_purge_settings'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION);
    123194        }
     195
     196
     197        //create fields in section CC_SETTINGS_CRONJOB_SECTION on options page
     198        add_settings_field(
     199                \Cacholong\Entities\Identifier::CC_FIELD_CRON_ENABLED, _x('Cronjob purging', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_cron_enabled'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_CRONJOB_SECTION);
     200
     201
     202        add_settings_field(
     203                \Cacholong\Entities\Identifier::CC_FIELD_CRON_TIME, _x('Cronjob time of each day', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_cron_time'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_CRONJOB_SECTION);
     204
     205        add_settings_field(
     206                \Cacholong\Entities\Identifier::CC_FIELDSET_CRON_CACHE_HELPERS, _x('Purge caches', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'render_field_cron_cache_helpers'), \Cacholong\Entities\Identifier::CC_SETTINGS_PAGE_ID, \Cacholong\Entities\Identifier::CC_SETTINGS_CRONJOB_SECTION);
    124207    }
    125208
     
    135218     * @return      void
    136219     */
    137     public static function render_page()
    138     {
     220    public static function render_page() {
    139221        require(CACHOLONG_VIEW_DIR . '/admin/settings/page/cacholong_cache_control.phtml');
    140222    }
     
    151233     * @return      void
    152234     */
    153     public static function render_section_settings()
    154     {
     235    public static function render_section_settings() {
    155236        require(CACHOLONG_VIEW_DIR . '/admin/settings/section/cacholong_cache_control_settings.phtml');
    156237    }
    157238
    158    
    159      /**
     239    /**
     240     * Render section 'cacholong_cache_control_settings_cronjob'
     241     *
     242     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     243     * @copyright   Cacholong <[email protected]>
     244     * @todo        ok
     245     *
     246     * @version     1.0.0     2019-02-19
     247     *
     248     * @return      void
     249     */
     250    public static function render_section_settings_cronjob() {
     251        require(CACHOLONG_VIEW_DIR . '/admin/settings/section/cacholong_cache_control_settings_cronjob.phtml');
     252    }
     253
     254    /**
    160255     * Render field 'remove_style_id'
    161256     *
     
    168263     * @return      void
    169264     */
    170     public static function render_field_remove_style_id()
    171     {
     265    public static function render_field_remove_style_id() {
    172266        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/remove_style_id.phtml');
    173267    }
    174    
     268
    175269    /**
    176270     * Render field 'location_json_hosts_file'
     
    184278     * @return      void
    185279     */
    186     public static function render_field_location_json_hosts_file()
    187     {
     280    public static function render_field_location_json_hosts_file() {
    188281        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/location_json_hosts_file.phtml');
    189282    }
    190283
    191284    /**
     285     * Render field 'cacholong_cc_field_cron_enabled'
     286     *
     287     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     288     * @copyright   Cacholong <[email protected]>
     289     * @todo        ok
     290     *
     291     * @version     1.0.0     2019-02-19
     292     *
     293     * @return      void
     294     */
     295    public static function render_field_cron_enabled() {
     296        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/cron_enabled.phtml');
     297    }
     298
     299    /**
     300     * Render field 'cacholong_cc_field_cron_time'
     301     *
     302     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     303     * @copyright   Cacholong <[email protected]>
     304     * @todo        ok
     305     *
     306     * @version     1.0.0     2019-02-19
     307     *
     308     * @return      void
     309     */
     310    public static function render_field_cron_time() {
     311        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/cron_time.phtml');
     312    }
     313
     314    /**
     315     * Render field 'cacholong_cc_fieldset_cron_cache_helpers'
     316     *
     317     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     318     * @copyright   Cacholong <[email protected]>
     319     * @todo        ok
     320     *
     321     * @version     1.0.0     2019-02-19
     322     *
     323     * @return      void
     324     */
     325    public static function render_field_cron_cache_helpers() {
     326        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/cron_cache_helpers.phtml');
     327    }
     328
     329    /* Render field 'cc_field_custom_purge_settings'
     330     *
     331     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     332     * @copyright   Cacholong <[email protected]>
     333     * @todo        ok
     334     *
     335     * @version     1.0.0     2016-09-07
     336     *
     337     * @return      void
     338     */
     339
     340    public static function render_field_custom_post_purge_settings() {
     341        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/custom_post_purge_settings.phtml');
     342    }
     343
     344    /**
    192345     * Render field 'cc_field_default_post_purge_settings'
    193346     *
     
    200353     * @return      void
    201354     */
    202     public static function render_field_default_post_purge_settings()
    203     {
     355    public static function render_field_default_post_purge_settings() {
    204356        require(CACHOLONG_VIEW_DIR . '/admin/settings/field/default_post_purge_settings.phtml');
    205     }
    206 
    207     /* Render field 'cc_field_custom_purge_settings'
    208      *
    209      * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
    210      * @copyright   Cacholong <[email protected]>
    211      * @todo        ok
    212      *
    213      * @version     1.0.0     2016-09-07
    214      *
    215      * @return      void
    216      */
    217 
    218     public static function render_field_custom_post_purge_settings()
    219     {
    220         require(CACHOLONG_VIEW_DIR . '/admin/settings/field/custom_post_purge_settings.phtml');
    221357    }
    222358
     
    231367     * @version     1.1.0     2016-09-07 All purge settings
    232368     * @version     1.2.0     2017-12-15 Added CC_FIELD_REMOVE_STYLE_ID
    233      * @return      void
    234      */
    235     public static function register_settings()
    236     {
    237         register_setting(
    238             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_FIELD_HOSTS_FILE, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_location_json_hosts_file'));
    239 
    240         register_setting(
    241             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_FIELD_REMOVE_STYLE_ID, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    242        
     369     * @version     1.3.0     2019-02-19 Added cron settings
     370     * @return      void
     371     */
     372    public static function register_settings() {
     373        register_setting(
     374                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_FIELD_HOSTS_FILE, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_location_json_hosts_file'));
     375
     376        register_setting(
     377                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_FIELD_REMOVE_STYLE_ID, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     378
    243379        //default post types
    244380        register_setting(
    245             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_DEFAULT, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    246         register_setting(
    247             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_HOME, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    248         register_setting(
    249             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_CATEGORIES_WORDPRESS, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    250         register_setting(
    251             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_CATEGORIES_WOOCOMMERCE, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    252         register_setting(
    253             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_FLUSH_ALL, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     381                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_DEFAULT, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     382        register_setting(
     383                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_HOME, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     384        register_setting(
     385                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_CATEGORIES_WORDPRESS, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     386        register_setting(
     387                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_CATEGORIES_WOOCOMMERCE, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     388        register_setting(
     389                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_DEFAULT_POST_PURGE_SETTINGS_FLUSH_ALL, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    254390
    255391        //custom post types
    256392        register_setting(
    257             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_DEFAULT, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    258         register_setting(
    259             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_HOME, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    260         register_setting(
    261             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_CATEGORIES_WORDPRESS, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    262         register_setting(
    263             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_CATEGORIES_WOOCOMMERCE, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
    264         register_setting(
    265             \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_FLUSH_ALL, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     393                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_DEFAULT, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     394        register_setting(
     395                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_HOME, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     396        register_setting(
     397                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_CATEGORIES_WORDPRESS, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     398        register_setting(
     399                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_CATEGORIES_WOOCOMMERCE, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     400        register_setting(
     401                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_FLUSH_ALL, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     402
     403        //cronjob settings
     404        register_setting(
     405                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_FIELD_CRON_ENABLED, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     406        register_setting(
     407                \Cacholong\Entities\Identifier::CC_OPTIONS, \Cacholong\Entities\Identifier::CC_FIELD_CRON_TIME, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_hh_mm_24h'));
     408
     409        $cronCacheSettings = cacholong_cc_get_cron_settings_caches_field_key_and_name();
     410        foreach ($cronCacheSettings as $cronCacheFieldKey => $cronCacheName) {
     411            register_setting(
     412                    \Cacholong\Entities\Identifier::CC_OPTIONS, $cronCacheFieldKey, array('\Cacholong\Controller\Admin\AdminSettingsPageController', 'sanitize_field_boolean'));
     413        }
    266414    }
    267415
     
    275423     * @version     1.0.0     2015-10-26
    276424     * @version     1.0.1     2015-11-02    Replace slashes
     425     * @version     1.1.0     2019-02-21    Extra trim + safeguards
    277426     *
    278427     * @param       string    $unsafeInput  Unsafe input for location field
     
    280429     * @return      string    Sanatized location field
    281430     */
    282     public static function sanitize_field_location_json_hosts_file($unsafeInput)
    283     {
    284         if($unsafeInput)
    285         {
     431    public static function sanitize_field_location_json_hosts_file($unsafeInput) {
     432        $unsafeInput = trim($unsafeInput);
     433        $finalHostsFile = null;
     434       
     435        if ($unsafeInput) {
    286436            $input = str_replace('\\', '/', $unsafeInput);
    287437            $input = ltrim($input, '/');
    288             return $input;
     438            $finalHostsFile = $input;
     439        } elseif(defined('CACHOLONG_CACHE_DEFAULT_JSON_HOSTS_PATH'))
     440        {
     441            $finalHostsFile = CACHOLONG_CACHE_DEFAULT_JSON_HOSTS_PATH;
    289442        }
    290         else
    291         {
    292             return CACHOLONG_CACHE_DEFAULT_JSON_HOSTS_PATH;
    293         }
     443        //else default
     444       
     445        return $finalHostsFile;
    294446    }
    295447
     
    307459     * @return      bool        Sanatized boolean field
    308460     */
    309     public static function sanitize_field_boolean($unsafeInput)
    310     {
     461    public static function sanitize_field_boolean($unsafeInput) {
    311462        $activated = (bool) $unsafeInput;
    312463        return $activated ? '1' : '0';
    313464    }
    314465
     466    /**
     467     * Sanitize input for hh mm field (24hour format)
     468     *
     469     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     470     * @copyright   Cacholong <[email protected]>
     471     * @todo        ok
     472     *
     473     * @version     1.0.0     2019-02-19
     474     * @version     1.1.0     2019-02-20 abstracted to cacholong_cc_sanitize_time_hh_mm_24h()
     475     *
     476     * @param       string      $unsafeInput  Unsafe input for a hh:mm field
     477     *
     478     * @return      bool        Sanatized hh:mm field
     479     */
     480    public static function sanitize_field_hh_mm_24h($unsafeInput) {
     481
     482        return cacholong_cc_sanitize_time_hh_mm_24h($unsafeInput);
     483    }
     484
    315485}
  • cache-control-by-cacholong/trunk/core/controller/admin/PurgeCacheController.php

    r1974788 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
     
    4848
    4949    /*
    50      * @const     stromg         DEBUG_FAST_CGI_CACHE_PATH            Debug fast cgi cache path
     50     * @const     string         DEBUG_FAST_CGI_CACHE_PATH            Debug fast cgi cache path
    5151     */
    5252    const DEBUG_FAST_CGI_CACHE_PATH = 'd:/temp/nginx/';
     
    6060     *
    6161     * @version     1.0.0     Created at 2015-10-21
     62     * @version     1.1.0     2019-02-21 Cron cache settings
    6263     *
    6364     */
     
    6566        do_action('cacholong_cache_control_purge_cache_before_init');
    6667
     68        //purge all / single
    6769        add_action(\Cacholong\Entities\AdminPostAction::get_action_hook_name(\Cacholong\Entities\AdminPostAction::PURGE_ALL), array('\Cacholong\Controller\Admin\PurgeCacheController', 'handle_purge_all_settings_page'));
    6870        add_action(\Cacholong\Entities\AdminPostAction::get_action_hook_name(\Cacholong\Entities\AdminPostAction::PURGE_SINGLE), array('\Cacholong\Controller\Admin\PurgeCacheController', 'handle_purge_single_settings_page'));
     71
     72        //cron purge hook names
     73        $cronCacheKeyAndHooks = cacholong_cc_get_cron_settings_caches_field_key_and_hook_purge_name();
     74        foreach ($cronCacheKeyAndHooks as $cronCacheFieldKey => $cronCacheHookName) {
     75            add_action($cronCacheHookName, function() use ($cronCacheHookName) {
     76                self::handle_purge_all_specific($cronCacheHookName);
     77            });
     78        }
    6979
    7080        do_action('cacholong_cache_control_purge_cache_after_init');
     
    102112        $purgeCache = new \Cacholong\Libraries\PurgeCache();
    103113        $purgeCache->handle_purge_all();
     114    }
     115   
     116       /**
     117     * Handle purge all request for specific cache
     118     *
     119     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     120     * @copyright   Cacholong <[email protected]>
     121     * @todo        ok
     122     *
     123     * @param       string    $hookPurgeCache      Hook name of cache helper
     124     *
     125     * @return      void
     126     */
     127    public static function handle_purge_all_specific($hookPurgeCache) {
     128        $purgeCache = new \Cacholong\Libraries\PurgeCache();
     129        $purgeCache->handle_purge_all_specific($hookPurgeCache);
    104130    }
    105131
     
    210236        if ($is_update) {
    211237            //must be an update
    212            
     238
    213239            if (\Cacholong\Entities\PostType::get_purge_is_required($postID)) {
    214240                $post_status = get_post_status($postID);
     
    302328        }
    303329        //else no slug change, donop
    304      
    305330        //original filter
    306331        return $slug;
  • cache-control-by-cacholong/trunk/core/controller/admin/ToolbarController.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
     
    4343     * @version     1.0.0     2015-10-31
    4444     * @version     1.0.1     2016-02-16 cacholong_cc_get_settings_page_url($queryAction) removed, added current page + query vars + wp_nonce
     45     * @version     1.1.0     2019-02-21 ab-icon class added for icon
     46     *
     47     * @param       \WP_Admin_Bar   $wpAdminBar     Instance of wp_admin_bar
    4548     * @return      void
    4649     */
    47     public static function create_toolbar_node_purge_all($wpAdminBar)
     50    public static function create_toolbar_node_purge_all(\WP_Admin_Bar $wpAdminBar)
    4851    {
    4952        $queryAction[\Cacholong\Entities\Identifier::CC_REQUEST_ACTION_KEY] = \Cacholong\Entities\Identifier::CC_REQUEST_ACTION_PURGE_ALL_ADMIN_BAR;
     
    5457        $nodeArguments = array(
    5558            'id' => \Cacholong\Entities\Identifier::CC_TOOLBAR_NODE_PURGE_ALL,
    56             'title' => __('Purge all caches', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN),
     59            'title' =>'<span class="ab-icon"></span>' . __('Purge all caches', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN),
    5760            'href' => $href
    5861        );
  • cache-control-by-cacholong/trunk/core/designpattern/observer/CacheHelperObserver.php

    r1834268 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
     
    164164     */
    165165    abstract public function getCacheHelperName();
     166   
     167    /**
     168     * Required get method to get cache helper hook name
     169     *
     170     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     171     * @copyright   Cacholong <[email protected]>
     172     * @todo        ok
     173     *
     174     * @version     1.0.0     2019-02-21
     175     *
     176     * @return      string   Name of cache helper
     177     */
     178    abstract public function getCacheHelperHookName();
     179   
     180
     181    /**
     182     * Required get method to get cache helper cron setting cache field key
     183     *
     184     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     185     * @copyright   Cacholong <[email protected]>
     186     * @todo        ok
     187     *
     188     * @version     1.0.0     2019-02-19
     189     *
     190     * @return      string   cache helper cron setting cache field key
     191     */
     192    abstract public function getCacheHelperCronSettingCacheFieldKey();
    166193
    167194    /**
     
    317344     * @return      string    $url
    318345     */
    319     public function preparePurgeHostUrl($hostUrl, $relative_path = null)
    320     {
     346    public function preparePurgeHostUrl($hostUrl, $relative_path = null) {
    321347        //Prepare host (remove http(s) + add relative path)
    322348        $hostUrl = preg_replace('#^https?://#', '', $hostUrl);
     
    328354            $protocol = 'https://';
    329355        }
    330        
     356
    331357        $hostUrl = $protocol . $hostUrl;
    332358
     
    339365        return $hostUrl;
    340366    }
     367
    341368}
  • cache-control-by-cacholong/trunk/core/designpattern/observer/CacheHelperSubject.php

    r1834268 r2036979  
    11<?php
     2
    23/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    45 *
    56 * This file is part of Cache Control
     
    6768     * @return      void
    6869     */
    69     public function __construct()
    70     {
     70    public function __construct() {
    7171        $this->observers = array();
    7272        $this->hosts = array();
     
    8787     * @return      void
    8888     */
    89     public function attach(CacheHelperObserver $observer)
    90     {
     89    public function attach(CacheHelperObserver $observer) {
    9190        //prevent same object observing twice or more
    9291        $i = array_search($observer, $this->observers);
    93         if($i === false)
    94         {
     92        if ($i === false) {
    9593            $this->observers[] = $observer;
    9694        }
     
    108106     * @return      void
    109107     */
    110     public function detach(CacheHelperObserver $observer)
    111     {
    112         if(!empty($this->observers))
    113         {
     108    public function detach(CacheHelperObserver $observer) {
     109        if (!empty($this->observers)) {
    114110            $index = array_search($observer, $this->observers);
    115             if($index !== false)
    116             {
     111            if ($index !== false) {
    117112                unset($this->observers[$index]);
    118113            }
     
    131126     * @return      array     Array of CacheHelperObserver objects or empty array
    132127     */
    133     public function getObservers()
    134     {
     128    public function getObservers() {
    135129        return $this->observers;
    136130    }
     
    148142     * @return      void
    149143     */
    150     public function notifyPurgeAllRequest()
    151     {
     144    public function notifyPurgeAllRequest() {
    152145        $this->notify($this, 'purgeAll');
    153146        $this->handlePurgeResults();
     
    166159     * @return      void
    167160     */
    168     public function notifyPurgeSingleRequest()
    169     {
     161    public function notifyPurgeSingleRequest() {
    170162        $this->notify($this, 'purgeSingleURL');
    171163        $this->handlePurgeResults();
     
    183175     * @return      void
    184176     */
    185     public function notifyPurgeMultipleRequest()
    186     {
     177    public function notifyPurgeMultipleRequest() {
    187178        $this->notify($this, 'purgeMultipleURL');
    188179        $this->handlePurgeResults();
     
    205196     * @return      void
    206197     */
    207     private function handlePurgeResults()
    208     {
     198    private function handlePurgeResults() {
    209199        $purgeResults = $this->notify($this, 'getPurgeResults', true);
    210200
     
    212202        //Content of purgeResults -> [$adminNoticeClass][$cacheHelperName]['flushDelayPossible'] = bool
    213203
    214         foreach ($purgeResults as $adminNoticeClass => $cacheHelpers)
    215         {
     204        foreach ($purgeResults as $adminNoticeClass => $cacheHelpers) {
    216205            //cache helper sentences
    217206            $cacheHelperSentences = array();
     
    220209            $flushDelayPossible = false;
    221210
    222             foreach ($cacheHelpers as $cacheHelper => $cacheHelperResult)
    223             {
     211            foreach ($cacheHelpers as $cacheHelper => $cacheHelperResult) {
    224212                //host information per cache helper
    225213                $hostNames = array_keys($cacheHelperResult['hosts']);
     
    228216                $suffix = '</b>';
    229217
    230                 if($hostNames[0] == CacheHelperObserver::ALL_HOSTS && count($hostNames) == 1)
    231                 {
     218                if ($hostNames[0] == CacheHelperObserver::ALL_HOSTS && count($hostNames) == 1) {
    232219                    $hostNamesSentence = $prefix . __("all hosts", \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN) . $suffix;
    233                 }
    234                 else
    235                 {
     220                } else {
    236221                    $hostNamesSentence = cacholong_cc_itemlist_to_sentence($hostNames, $prefix, $suffix);
    237222                }
     
    248233            $finalCacheHelperSentence = cacholong_cc_itemlist_to_sentence($cacheHelperSentences);
    249234
    250             switch ($adminNoticeClass)
    251             {
     235            switch ($adminNoticeClass) {
    252236                case AdminNoticeClass::SUCCESS: //ok
    253237                    $message = sprintf(__("Succesfully purged %s.", \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), $finalCacheHelperSentence);
    254238
    255                     if($flushDelayPossible)
    256                     {
     239                    if ($flushDelayPossible) {
    257240                        $message .= ' ' . __("It could take a few minutes to be visible at the frontend.", \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN);
    258241                    }
    259242
    260                     if(is_admin())
    261                     {
     243                    if (is_admin()) {
    262244                        AdminMessage::set_message($message, AdminNoticeClass::SUCCESS, true);
    263                     }
    264                     else
    265                     {
     245                    } else {
    266246                        cacholong_cc_log_error($message);
    267247                    }
     
    270250                    $message = sprintf(__("Failed to purge %s.", \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), $finalCacheHelperSentence);
    271251
    272                     if(is_admin())
    273                     {
     252                    if (is_admin()) {
    274253                        AdminMessage::set_message($message, AdminNoticeClass::ERROR, true);
    275                     }
    276                     else
    277                     {
     254                    } else {
    278255                        cacholong_cc_log_error($message);
    279256                    }
     
    302279     * @return      mixed     Array with result of $customMethod or nothing (void)
    303280     */
    304     private function notify($subject, $customMethod, $returnResult = false)
    305     {
     281    private function notify($subject, $customMethod, $returnResult = false) {
    306282        $result = array();
    307283
    308         if(!empty($this->observers))
    309         {
    310             foreach ($this->observers as $observer)
    311             {
    312                 if(!empty($customMethod) && method_exists($observer, $customMethod))
    313                 {
    314                     if($returnResult)
    315                     {
     284        if (!empty($this->observers)) {
     285            foreach ($this->observers as $observer) {
     286                if (!empty($customMethod) && method_exists($observer, $customMethod)) {
     287                    if ($returnResult) {
    316288                        $observerResult = $observer->$customMethod($subject);
    317289                        $result = array_merge_recursive($result, $observerResult);   //will merge all non-numeric keys
    318                     }
    319                     else
    320                     {
     290                    } else {
    321291                        $observer->$customMethod($subject);
    322292                    }
    323                 }
    324                 else
    325                 {
     293                } else {
    326294                    $observer_name = get_class($observer);
    327295                    cacholong_cc_log_exception(
    328                         new \Exception(
    329                         sprintf(
    330                             _x("Custom method '%s' does not exist in observer class '%s'.", 'Internal exception message', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), $customMethod, $observer_name)
    331                         )
     296                            new \Exception(
     297                            sprintf(
     298                                    _x("Custom method '%s' does not exist in observer class '%s'.", 'Internal exception message', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN), $customMethod, $observer_name)
     299                            )
    332300                    );
    333301                }
    334302            }
    335303
    336             if($returnResult)
    337             {
     304            if ($returnResult) {
    338305                return $result;
    339306            }
     
    353320     * @return      void
    354321     */
    355     public function set_hosts_info($hosts)
    356     {
    357         if(is_array($hosts))
    358         {
     322    public function set_hosts_info($hosts) {
     323        if (is_array($hosts)) {
    359324            $this->hosts = $hosts;
    360325        }
     
    372337     * @return      array      Array of hosts info
    373338     */
    374     public function get_hosts_info()
    375     {
     339    public function get_hosts_info() {
    376340        return $this->hosts;
    377341    }
     
    389353     * @return      void
    390354     */
    391     public function set_single_relative_path_url($path)
    392     {
     355    public function set_single_relative_path_url($path) {
    393356        $path = ltrim($path, '/');
    394357        $this->relative_path = $path;
     
    407370     * @return      string    Relative url path
    408371     */
    409     public function get_single_relative_path_url()
    410     {
     372    public function get_single_relative_path_url() {
    411373        return $this->relative_path;
    412374    }
     
    425387     * @return      void
    426388     */
    427     public function set_multiple_relative_path_urls($paths)
    428     {
     389    public function set_multiple_relative_path_urls($paths) {
    429390        $relative_paths = is_array($paths) ? $paths : (array) $paths;
    430         array_walk($relative_paths, function(&$single_path)
    431         {
     391        array_walk($relative_paths, function(&$single_path) {
    432392            $single_path = ltrim($single_path, '/');
    433393        });
     
    447407     * @return      array     Multiple relative url paths
    448408     */
    449     public function get_multiple_relative_path_urls()
    450     {
     409    public function get_multiple_relative_path_urls() {
    451410        return $this->relative_paths;
    452411    }
    453412
     413    /**
     414     * Get cron settings field key for cache helper and cache helper name
     415     *
     416     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     417     * @copyright   Cacholong <[email protected]>
     418     * @todo        ok
     419     *
     420     * @version     1.0.0     2019-02-20
     421     *
     422     * @return      array     Multiple relative url paths
     423     */
     424    public function getCronSettingsFieldKeyAndName() {
     425        $cronSettings = array();
     426        $observers = $this->getObservers();
     427
     428        foreach ($observers as $observer) {
     429            $key = \Cacholong\Entities\Identifier::CC_FIELD_CRON_CACHE_PREFIX . $observer->getCacheHelperCronSettingCacheFieldKey();
     430            $name = $observer->getCacheHelperName();
     431            $cronSettings[$key] = $name;
     432        }
     433        return $cronSettings;
     434    }
     435
     436    /**
     437     * Get cron settings field key for cache helper and cache helper hook purge name
     438     *
     439     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     440     * @copyright   Cacholong <[email protected]>
     441     * @todo        ok
     442     *
     443     * @version     1.0.0     2019-02-21
     444     *
     445     * @return      array     Multiple relative url paths
     446     */
     447    public function getCronSettingsFieldKeyAndHookPurgeName() {
     448        $cronSettings = array();
     449        $observers = $this->getObservers();
     450
     451        foreach ($observers as $observer) {
     452            $key = \Cacholong\Entities\Identifier::CC_FIELD_CRON_CACHE_PREFIX . $observer->getCacheHelperCronSettingCacheFieldKey();
     453            $hookName = \Cacholong\Entities\Identifier::CC_HOOK_CRON_PURGE_CACHE_PREFIX . $observer->getCacheHelperHookName();
     454            $cronSettings[$key] = $hookName;
     455        }
     456        return $cronSettings;
     457    }
     458
    454459}
  • cache-control-by-cacholong/trunk/core/designpattern/observer/NginxFastCGICacheHelperObserver.php

    r1834268 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
     
    4545
    4646    /*
     47     * @const string   Cron setting field key for this cache helper
     48     */
     49    const CACHE_HELPER_CRON_SETTING_CACHE_FIELD_KEY = 'cron_fastCGI';
     50
     51    /*
     52     * @const string   Hook name for this cache helper (only use hook valid chars)
     53     */
     54    const CACHE_HELPER_HOOK_NAME = 'fastCGI';
     55
     56    /*
    4757     * @const bool      Cache flush could be delayed (true) or not (false)
    4858     */
     
    7787    public function getCacheHelperName() {
    7888        return self::CACHE_HELPER_NAME;
     89    }
     90
     91    /**
     92     * Get cache helper hook name
     93     *
     94     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     95     * @copyright   Cacholong <[email protected]>
     96     * @todo        ok
     97     *
     98     * @version     1.0.0     2016-09-09
     99     *
     100     * @return      string   Name of hook for cache helper
     101     */
     102    public function getCacheHelperHookName() {
     103        return self::CACHE_HELPER_HOOK_NAME;
     104    }
     105
     106    /**
     107     * Get cache helper cron setting cache field key
     108     *
     109     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     110     * @copyright   Cacholong <[email protected]>
     111     * @todo        ok
     112     *
     113     * @version     1.0.0     2019-02-19
     114     *
     115     * @return      string   cache helper cron setting cache field key
     116     */
     117    public function getCacheHelperCronSettingCacheFieldKey() {
     118        return self::CACHE_HELPER_CRON_SETTING_CACHE_FIELD_KEY;
    79119    }
    80120
     
    177217        $relative_path = self::PURGE_PREFIX_RELATIVE_URL . '/' . $subject->get_single_relative_path_url();
    178218
    179         $httpApiRequestOptions[HttpApiRequest::HTTP_METHOD] = HttpApiRequest::HTTP_METHOD_GET;       
     219        $httpApiRequestOptions[HttpApiRequest::HTTP_METHOD] = HttpApiRequest::HTTP_METHOD_GET;
    180220        $result = $this->purge($hosts_info, $relative_path, $httpApiRequestOptions);
    181221
     
    213253        $default_options[HttpApiRequest::TIME_OUT] = self::HTTP_API_TIMEOUT;
    214254        $default_options[HttpApiRequest::SSL_VERIFY] = false;       //Disabled to prevent issues with malformed SSL certificates in (shared) hosting environments
    215 
    216255        //which identical keys $options array overrules default
    217256        $final_options = $httpApiRequestOptions + $default_options;
  • cache-control-by-cacholong/trunk/core/designpattern/observer/NginxPageSpeedCacheHelperObserver.php

    r1834268 r2036979  
    11<?php
     2
    23/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    45 *
    56 * This file is part of Cache Control
     
    4445
    4546    /*
     47     * @const string   Cron setting field key for this cache helper
     48     */
     49    const CACHE_HELPER_CRON_SETTING_CACHE_FIELD_KEY = 'cron_pagespeed';
     50
     51    /*
     52     * @const string   Hook name for this cache helper (only use hook valid chars)
     53     */
     54    const CACHE_HELPER_HOOK_NAME = 'pagespeed';
     55
     56
     57    /*
    4658     * @const bool      Cache flush could be delayed (true) or not (false)
    4759     */
     
    6981     * @return      string   Name of cache helper
    7082     */
    71 
    72     public function getCacheHelperName()
    73     {
     83    public function getCacheHelperName() {
    7484        return self::CACHE_HELPER_NAME;
    7585    }
    7686
    77         /**
     87    /**
     88     * Get cache helper hook name
     89     *
     90     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     91     * @copyright   Cacholong <[email protected]>
     92     * @todo        ok
     93     *
     94     * @version     1.0.0     2016-09-09
     95     *
     96     * @return      string   Name of hook for cache helper
     97     */
     98    public function getCacheHelperHookName() {
     99        return self::CACHE_HELPER_HOOK_NAME;
     100    }
     101   
     102    /**
     103     * Get cache helper cron setting cache field key
     104     *
     105     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     106     * @copyright   Cacholong <[email protected]>
     107     * @todo        ok
     108     *
     109     * @version     1.0.0     2019-02-19
     110     *
     111     * @return      string   cache helper cron setting cache field key
     112     */
     113    public function getCacheHelperCronSettingCacheFieldKey() {
     114        return self::CACHE_HELPER_CRON_SETTING_CACHE_FIELD_KEY;
     115    }
     116
     117    /**
    78118     * Get cache flush could be delayed switch
    79119     *
     
    86126     * @return      bool     Cache flush could be delayed (true) or not (false)
    87127     */
    88     public function getFlushCouldBeDelayed()
    89     {
     128    public function getFlushCouldBeDelayed() {
    90129        return self::CACHE_FLUSH_COULD_BE_DELAYED;
    91130    }
     
    108147     * @return      void
    109148     */
    110     public function purgeAll($subject)
    111     {
     149    public function purgeAll($subject) {
    112150        $hosts_info = $subject->get_hosts_info();
    113151        $purge_all_suffix = '*';
     
    134172     * @return      void
    135173     */
    136     public function purgeSingleURL($subject)
    137     {
     174    public function purgeSingleURL($subject) {
    138175        $hosts_info = $subject->get_hosts_info();
    139176        $relative_path = $subject->get_single_relative_path_url();
     
    159196     * @return      void
    160197     */
    161     public function purgeMultipleURL($subject)
    162     {
     198    public function purgeMultipleURL($subject) {
    163199        $hosts_info = $subject->get_hosts_info();
    164200        $relative_paths = $subject->get_multiple_relative_path_urls();
    165201
    166         if(is_array($relative_paths) && $relative_paths)
    167         {
    168             foreach ($relative_paths as $relative_path)
    169             {
     202        if (is_array($relative_paths) && $relative_paths) {
     203            foreach ($relative_paths as $relative_path) {
    170204                $result = $this->purge($hosts_info, $relative_path);
    171205                $this->handlePurgeResult($hosts_info, $result, $this->get_http_response_codes_success(), $relative_path, \Cacholong\Libraries\Hosts::NGINX_PAGESPEED_KEY);
     
    196230     * @return      array     Original key as key, value true (succes) or false (failure).
    197231     */
    198     private function purge($hosts_info, $relative_path = null, $httpApiRequestOptions = array())
    199     {
     232    private function purge($hosts_info, $relative_path = null, $httpApiRequestOptions = array()) {
    200233        $result = array();
    201234
     
    204237        $default_options[HttpApiRequest::SSL_VERIFY] = false;           //Disabled to prevent issues with malformed SSL certificates in (shared) hosting environments
    205238        $default_options[HttpApiRequest::HTTP_METHOD] = HttpApiRequest::HTTP_METHOD_PURGE;
    206        
     239
    207240        //which identical keys $options array overrules default
    208241        $final_options = $httpApiRequestOptions + $default_options;
    209242
    210         foreach ($hosts_info as $key => $host)
    211         {
    212             if($host[\Cacholong\Libraries\Hosts::NGINX_PAGESPEED_KEY])
    213             {
     243        foreach ($hosts_info as $key => $host) {
     244            if ($host[\Cacholong\Libraries\Hosts::NGINX_PAGESPEED_KEY]) {
    214245                $purgeHost = $this->preparePurgeHostUrl($host[\Cacholong\Libraries\Hosts::HOST_KEY], $relative_path);
    215246                $result[$key] = \Cacholong\Libraries\HttpApiRequest::execute($purgeHost, $final_options);
     
    232263     * @return      array     HTTP response codes
    233264     */
    234     private function get_http_response_codes_success()
    235     {
     265    private function get_http_response_codes_success() {
    236266        $httpResponseCode[] = self::HTTP_RESPONSE_CODE_PURGE_SUCCESS;
    237267
  • cache-control-by-cacholong/trunk/core/entities/AdminNoticeClass.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/entities/AdminPostAction.php

    r1834268 r2036979  
    11<?php
     2
    23/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    45 *
    56 * This file is part of Cache Control
     
    3334
    3435    const WORDPRESS_ADMIN_POST_ACTION_PREFIX = 'admin_post_';
    35    
    3636    const PURGE_ALL = 'purge_all';
    3737    const PURGE_SINGLE = 'purge_single';
     
    4848     * @return      string    Action hook
    4949     */
    50     public static function get_action_hook_name($action)
    51     {
     50    public static function get_action_hook_name($action) {
    5251        return self::WORDPRESS_ADMIN_POST_ACTION_PREFIX . $action;
    5352    }
    5453
    5554}
     55
    5656/* End of file AdminPostAction.php */
  • cache-control-by-cacholong/trunk/core/entities/AjaxResponseType.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/entities/HttpApiRequest.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/entities/Identifier.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
     
    3434 * @version 1.1.0 2016-09-07 Added ID's
    3535 * @version 1.2.0 2018-02-23 All values > prefix from cc_ to cacholong_cc_
     36 * @version 1.3.0 2019-02-19 Cron fields
     37 *
    3638 */
    3739abstract class Identifier {
     
    4345    const CC_SETTINGS_PAGE_ID = 'cacholong-cache-control-settings-page';        //also visible in url
    4446    const CC_SETTINGS_SECTION = 'cacholong_cc_settings_section';
     47    const CC_SETTINGS_CRONJOB_SECTION = 'cacholong_cc_settings_cronjob_section';
    4548    const CC_SETTINGS_SECTION_FORM_ID = 'cacholong_cc_settings_form';
    4649   
     
    5457    const CC_FIELD_CUSTOM_POST_PURGE_SETTINGS = 'cacholong_cc_field_custom_purge_settings';           //field name used in javascript
    5558    const CC_FIELD_REMOVE_STYLE_ID = 'cacholong_cc_field_remove_style_id';
     59    const CC_FIELD_CRON_ENABLED = 'cacholong_cc_field_cron_enabled';
     60    const CC_FIELD_CRON_TIME = 'cacholong_cc_field_cron_time';
     61    const CC_FIELD_CRON_CACHE_PREFIX = 'cacholong_cc_field_';
     62    const CC_HOOK_CRON_PURGE_CACHE_PREFIX = 'cacholong_cc_purge_';
    5663   
    5764    //fieldsets
    58     const CC_FIELDSET_DEFAULT_POST_PURGE_SETTINGS = 'cacholong_cc_fieldset_default_purge_settings';   //field name used in javascript
    59     const CC_FIELDSET_CUSTOM_POST_PURGE_SETTINGS = 'cacholong_cc_fieldset_custom_purge_settings';   //field name used in javascript
     65    const CC_FIELDSET_DEFAULT_POST_PURGE_SETTINGS = 'cacholong_cc_fieldset_default_purge_settings';     //field name used in javascript
     66    const CC_FIELDSET_CUSTOM_POST_PURGE_SETTINGS = 'cacholong_cc_fieldset_custom_purge_settings';       //field name used in javascript
     67    const CC_FIELDSET_CRON_CACHE_HELPERS = 'cacholong_cc_fieldset_cron_cache_helpers';             
    6068       
    6169    //Radio options for default post purge settings
     
    8896    //ajax actions
    8997    const CC_AJAX_ACTION_GET_MESSAGES = 'cacholong_cc_action_get_messages';       //note: do not use wp_ajax_ prefix here   
     98   
     99    const DEFAULT_DATETIME = 'Y-m-d H:i:s';
     100   
     101    //Regex for time of day (24H)
     102    const TIME_OF_DAY_24H_REGEX = '/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/';
     103   
     104    const WORDPRESS_PLUGIN_PATH = 'https://wordpress.org/plugins/cache-control-by-cacholong';
     105    const WORDPRESS_PLUGIN_PATH_FAQ = 'https://wordpress.org/plugins/cache-control-by-cacholong#faq-header';
    90106}
    91107/* End of file Identifier.php */
  • cache-control-by-cacholong/trunk/core/entities/PostType.php

    r1974788 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/AdminMessage.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/CacholongCacheControlSetup.php

    r1834268 r2036979  
    11<?php
     2
    23/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    45 *
    56 * This file is part of Cache Control
     
    1819 * along with Cache Control.  If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022namespace Cacholong\Libraries;
    2123
     
    4648     * @version     1.2.0     2016-09-09 Bugfix: nonce check created are you sure question that got you nowhere in some cases. Removed.
    4749     * @version     1.3.0     2017-12-15 Added CC_FIELD_REMOVE_STYLE_ID
     50     * @version     1.4.0     2019-02-19 Added cron settings
     51     * @version     1.4.1     2019-02-21 Default value cache fields 0 -> 1
    4852     */
    49     public static function on_activation()
    50     {
     53    public static function on_activation() {
    5154        //security       
    52         if(!current_user_can('activate_plugins'))
    53         {
     55        if (!current_user_can('activate_plugins')) {
    5456            wp_die(__('You are not allowed to access this part of the site.', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN));
    5557        }
     
    7072        add_option(\Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_CATEGORIES_WOOCOMMERCE, 0);
    7173        add_option(\Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_FLUSH_ALL, 0);
     74
     75        add_option(\Cacholong\Entities\Identifier::CC_FIELD_CRON_ENABLED, 0);
     76        add_option(\Cacholong\Entities\Identifier::CC_FIELD_CRON_TIME, '00:00');
     77
     78        $cronCacheSettings = cacholong_cc_get_cron_settings_caches_field_key_and_name();
     79        foreach ($cronCacheSettings as $cronCacheFieldKey => $cronCacheName) {
     80            add_option($cronCacheFieldKey, 1);
     81        }
    7282    }
    7383
     
    8191     * @version     1.0.0     Created at 2015-10-21
    8292     */
    83     public static function on_deactivation()
    84     {
     93    public static function on_deactivation() {
    8594       
    8695    }
     
    98107     * @version     1.2.0     2017-12-15 Added CC_FIELD_REMOVE_STYLE_ID
    99108     * @version     1.3.0     2017-12-21 Removed check_admin_referer('bulk-plugins') + Also remove possible leftover flashData
     109     * @version     1.4.0     2019-02-19 Added cron settings
    100110     *
    101111     */
    102     public static function on_uninstall()
    103     {
    104         if(current_user_can('install_plugins'))
    105         {
     112    public static function on_uninstall() {
     113        if (current_user_can('install_plugins')) {
    106114            delete_option(\Cacholong\Entities\Identifier::CC_FIELD_HOSTS_FILE);
    107115
     
    119127            delete_option(\Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_CATEGORIES_WOOCOMMERCE);
    120128            delete_option(\Cacholong\Entities\Identifier::CC_CUSTOM_POST_PURGE_SETTINGS_FLUSH_ALL);
    121            
     129
     130            delete_option(\Cacholong\Entities\Identifier::CC_FIELD_CRON_ENABLED);
     131            delete_option(\Cacholong\Entities\Identifier::CC_FIELD_CRON_TIME);
     132
     133            $cronCacheSettings = cacholong_cc_get_cron_settings_caches_field_key_and_name();
     134            foreach ($cronCacheSettings as $cronCacheFieldKey => $cronCacheName) {
     135                delete_option($cronCacheFieldKey, 0);
     136            }
     137
    122138            //remove possible leftover flashData
    123139            \Cacholong\Libraries\FlashData::delete_all_flash_data();
    124         }
    125         else
    126         {
     140        } else {
    127141            wp_die(__('You are not allowed to access this part of the site.', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN));
    128142        }
  • cache-control-by-cacholong/trunk/core/libraries/File.php

    r1834268 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/FlashData.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/Helpers.php

    r1974788 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
     
    321321
    322322/**
     323 * Get cron settings cache(s) field key and name
     324 *
     325 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     326 * @copyright   Cacholong <[email protected]>
     327 * @todo        ok
     328 *
     329 * @version     1.0.0     2019-02-19    Original
     330 *
     331 * @return      array
     332 */
     333function cacholong_cc_get_cron_settings_caches_field_key_and_name() {
     334    $purgeCache = new \Cacholong\Libraries\PurgeCache();
     335    return $purgeCache->getCronSettingsFieldKeyAndName();
     336}
     337
     338/**
     339 * Get cron settings cache(s) field key and hook purge name
     340 *
     341 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     342 * @copyright   Cacholong <[email protected]>
     343 * @todo        ok
     344 *
     345 * @version     1.0.0     2019-02-21    Original
     346 *
     347 * @return      array
     348 */
     349function cacholong_cc_get_cron_settings_caches_field_key_and_hook_purge_name() {
     350    $purgeCache = new \Cacholong\Libraries\PurgeCache();
     351    return $purgeCache->getCronSettingsFieldKeyAndHookPurgeName();
     352}
     353
     354/**
     355 * Returns guaranteed string with hh:mm (24hour format) format or null in case of invalid input.
     356 *
     357 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     358 * @copyright   Cacholong <[email protected]>
     359 * @todo        ok
     360 *
     361 * @version     1.0.0     2019-02-19
     362 *
     363 * @param       string      $unsafeInput  Unsafe input for a hh:mm field
     364 *
     365 * @return      string|null Sanatized hh:mm field or null if not valid format.
     366 */
     367function cacholong_cc_sanitize_time_hh_mm_24h($unsafeInput) {
     368
     369    $sanitizedHHMM = null;
     370    $unsafeInput = trim($unsafeInput);
     371
     372    if (preg_match(Cacholong\Entities\Identifier::TIME_OF_DAY_24H_REGEX, $unsafeInput) == 1) {
     373        $sanitizedHHMM = $unsafeInput;
     374    }
     375
     376    return $sanitizedHHMM;
     377}
     378
     379/**
     380 * Returns option cron time (from db)
     381 * Note: because of sanitazion safe.
     382 *
     383 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     384 * @copyright   Cacholong <[email protected]>
     385 * @todo        ok
     386 *
     387 * @version     1.0.0     2019-02-20
     388 *
     389 * @return      string    Cron time or 00:00 (if was empty)
     390 */
     391function cacholong_cc_get_option_cron_time() {
     392    $value = get_option(\Cacholong\Entities\Identifier::CC_FIELD_CRON_TIME);
     393    return empty($value) ? '00:00' : $value;
     394}
     395
     396/**
     397 * Get cron options for purge caches
     398 *
     399 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     400 * @copyright   Cacholong <[email protected]>
     401 * @todo        ok
     402 *
     403 * @version     1.0.0     2019-02-19    Original
     404 *
     405 * @return      array     Key of setting and value of setting 
     406 */
     407function cacholong_cc_get_options_cron_caches() {
     408    $cronOptions = array();
     409
     410    $cronCacheSettings = cacholong_cc_get_cron_settings_caches_field_key_and_name();
     411    foreach ($cronCacheSettings as $cronCacheFieldKey => $cronCacheName) {
     412        $cronOptions[$cronCacheFieldKey] = get_option($cronCacheFieldKey);
     413    }
     414
     415    return $cronOptions;
     416}
     417
     418/**
     419 * Get current used timezone (wordpress or php fallback)
     420 *
     421 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     422 * @copyright   Cacholong <[email protected]>
     423 * @todo        ok
     424 *
     425 * @version     1.0.0     2019-02-22    Original
     426 *
     427 * @return      string    valid timezone
     428 */
     429function cacholong_cc_get_timezone() {
     430    $wordpressTimeZone = get_option('timezone_string');
     431    return $wordpressTimeZone ? $wordpressTimeZone : date_default_timezone_get();
     432}
     433
     434/**
    323435 * Does woocommerce exist?
    324436 *
  • cache-control-by-cacholong/trunk/core/libraries/Hosts.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
     
    8282    {
    8383        $fileContent = self::read_file($locationHostsFile, $isFilePath);
    84         if($fileContent !== FALSE)
     84        if($fileContent !== FALSE && $fileContent)
    8585        {
    8686            return self::convert_json_hosts_to_array($fileContent);
     
    142142     *
    143143     * @version     1.0.0     2015-11-02
     144     *
     145     * @param       string      $JSON       JSON string
    144146     *
    145147     * @return      array|false     Array with information about hosts or false in case of error
  • cache-control-by-cacholong/trunk/core/libraries/HttpApiRequest.php

    r1834268 r2036979  
    22
    33/**
    4  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    55 *
    66 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/Json.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
     
    3030 *
    3131 * @version     1.0.0     2011-06-09
    32  * @version     1.0.1     2015-10-28 Adjusted for Cachalong
     32 * @version     1.0.1     2015-10-28 Adjusted for Cacholong
    3333 */
    3434class Json {
  • cache-control-by-cacholong/trunk/core/libraries/PurgeCache.php

    r1834268 r2036979  
    11<?php
     2
    23/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     4 * Copyright © 2015-2019, Cacholong <[email protected]>
    45 *
    56 * This file is part of Cache Control
     
    6566     * @return      void
    6667     */
    67     public function __construct()
    68     {
     68    public function __construct() {
    6969       
    7070    }
     
    8181     * @return      void
    8282     */
    83     public function handle_purge_all()
    84     {
     83    public function handle_purge_all() {
    8584        $this->start_purge_all();
     85    }
     86
     87    /**
     88     * Handle purge all request for specific cache
     89     *
     90     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     91     * @copyright   Cacholong <[email protected]>
     92     * @todo        ok
     93     *
     94     * @version     1.0.0     2019-02-21
     95     *
     96     * @param       string    $hookPurgeCache      Hook name of cache helper
     97     *
     98     * @return      void
     99     */
     100    public function handle_purge_all_specific($hookPurgeCache) {
     101        try {
     102            $hosts = $this->get_hosts();
     103            if (is_array($hosts)) {
     104                $this->cacheHelperSubject = new \Cacholong\Designpattern\Observer\CacheHelperSubject();
     105                $this->cacheHelperSubject->set_hosts_info($hosts);
     106
     107                $this->create_all_observers($this->cacheHelperSubject);
     108
     109                foreach ($this->cacheHelperObservers as $cacheHelperObserver) {
     110                    $cacheHelperObserverHookName = \Cacholong\Entities\Identifier::CC_HOOK_CRON_PURGE_CACHE_PREFIX . $cacheHelperObserver->getCacheHelperHookName();
     111
     112                    if ($hookPurgeCache == $cacheHelperObserverHookName) {
     113                        $cacheHelperObserver->purgeAll($this->cacheHelperSubject);
     114                        break;
     115                    }
     116                }
     117            }
     118            //else do nop
     119        } catch (\Exception $ex) {
     120            cacholong_cc_log_exception($ex);
     121        }
    86122    }
    87123
     
    101137     * @return      void
    102138     */
    103     public function handle_purge_single($relative_path)
    104     {
     139    public function handle_purge_single($relative_path) {
    105140        $postId = url_to_postid($relative_path);
    106141
    107         if($postId !== 0)
    108         {
     142        if ($postId !== 0) {
    109143            $postType = get_post_type($postId);
    110144            $postTypeIsDefault = \Cacholong\Entities\PostType::is_wordpress_default_type($postType);
    111145
    112146            //Create correct purgeSetting object
    113             if($postTypeIsDefault)
    114             {
     147            if ($postTypeIsDefault) {
    115148                $purgeSetting = new \Cacholong\Libraries\PurgeSetting\DefaultPostPurgeSetting();
    116             }
    117             else
    118             {
     149            } else {
    119150                $purgeSetting = new \Cacholong\Libraries\PurgeSetting\CustomPostPurgeSetting();
    120151            }
     
    128159
    129160            //Decide which purge fits
    130             if($purgeSettingFlushAll && !($purgeSettingDefault || $purgeSettingHome || $purgeSettingCategoriesWordpress || $purgeSettingCategoriesWoocommerce))    //ok
    131             {
     161            if ($purgeSettingFlushAll && !($purgeSettingDefault || $purgeSettingHome || $purgeSettingCategoriesWordpress || $purgeSettingCategoriesWoocommerce)) {    //ok
    132162                //perform complete flush
    133163                $this->start_purge_all();
    134             }
    135             elseif($purgeSettingDefault && !($purgeSettingHome || $purgeSettingCategoriesWordpress || $purgeSettingCategoriesWoocommerce || $purgeSettingFlushAll ))    //ok
    136             {
     164            } elseif ($purgeSettingDefault && !($purgeSettingHome || $purgeSettingCategoriesWordpress || $purgeSettingCategoriesWoocommerce || $purgeSettingFlushAll )) {    //ok
    137165                //perform single purge
    138166                $this->start_purge_single($relative_path);
    139             }
    140             else
    141             {
     167            } else {
    142168                $multipleUrls = array();
    143169
    144170                //perform multiple purge
    145                 if($purgeSettingDefault)    //ok
    146                 {
     171                if ($purgeSettingDefault) {    //ok
    147172                    $multipleUrls[] = $relative_path;
    148173                }
    149174
    150                 if($purgeSettingHome)    //ok
    151                 {
     175                if ($purgeSettingHome) {    //ok
    152176                    $multipleUrls[] = WordpressURL::get_home();
    153177                }
    154178
    155                 if($purgeSettingCategoriesWordpress)    //ok
    156                 {
     179                if ($purgeSettingCategoriesWordpress) {    //ok
    157180                    $categoriesWordpress = WordpressURL::get_wordpress_categories_all($postId);
    158181                    $multipleUrls = array_merge($multipleUrls, $categoriesWordpress);
    159182                }
    160183
    161                 if($purgeSettingCategoriesWoocommerce)
    162                 {
     184                if ($purgeSettingCategoriesWoocommerce) {
    163185                    $categoriesWoocommerce = WordpressURL::get_woocommerce_categories();
    164186                    $multipleUrls = array_merge($multipleUrls, $categoriesWoocommerce);
     
    167189                $this->start_purge_multiple($multipleUrls);
    168190            }
    169         }
    170         else    //ok
    171         {
     191        } else {    //ok
    172192            // scenarios:
    173193            // - url has changed -> there is no post attached anymore -> nothing needs to happen -> ok
     
    187207     * @version     1.0.1     2015-11-10 Also url
    188208     * @version     1.0.2     2016-01-04 Bugfix with empty. Before php 5.5 empty does not work with temp result from function.
     209     * @version     1.0.3     2019-02-21 Extra check on empty hosts file field
    189210     *
    190211     * @return      array|false     Array of hosts or false in case of error
    191212     */
    192     private function get_hosts()
    193     {
     213    private function get_hosts() {
    194214        $pathToHostsFile = get_option(\Cacholong\Entities\Identifier::CC_FIELD_HOSTS_FILE);
    195215        $hosts = false;
    196216
    197         if(parse_url($pathToHostsFile, PHP_URL_SCHEME) && parse_url($pathToHostsFile, PHP_URL_HOST))
    198         {
    199             //url
    200             $fullPathHostsFile = $pathToHostsFile;
    201             $hosts = \Cacholong\Libraries\Hosts::get_hosts($fullPathHostsFile, false);
    202         }
    203         else
    204         {
    205             //file path
    206             $fullPathHostsFile = get_home_path() . "{$pathToHostsFile}";
    207             $hosts = \Cacholong\Libraries\Hosts::get_hosts($fullPathHostsFile, true);
    208         }
    209 
     217        if ($pathToHostsFile) {
     218            if (parse_url($pathToHostsFile, PHP_URL_SCHEME) && parse_url($pathToHostsFile, PHP_URL_HOST)) {
     219                //url
     220                $fullPathHostsFile = $pathToHostsFile;
     221                $hosts = \Cacholong\Libraries\Hosts::get_hosts($fullPathHostsFile, false);
     222            } else {
     223                //file path
     224                $fullPathHostsFile = get_home_path() . "{$pathToHostsFile}";
     225                $hosts = \Cacholong\Libraries\Hosts::get_hosts($fullPathHostsFile, true);
     226            }
     227        }
     228       
    210229        return $hosts;
    211230    }
     
    222241     * @return      string|null    Relative path or null when not present / error
    223242     */
    224     public function get_relative_path_from_form_field()
    225     {
    226         if(isset($_POST[\Cacholong\Entities\Identifier::CC_FIELD_SINGLE_PURGE]) &&
    227             !empty($_POST[\Cacholong\Entities\Identifier::CC_FIELD_SINGLE_PURGE]))
    228         {
     243    public function get_relative_path_from_form_field() {
     244        if (isset($_POST[\Cacholong\Entities\Identifier::CC_FIELD_SINGLE_PURGE]) &&
     245                !empty($_POST[\Cacholong\Entities\Identifier::CC_FIELD_SINGLE_PURGE])) {
    229246            $unsafeSingleField = $_POST[\Cacholong\Entities\Identifier::CC_FIELD_SINGLE_PURGE];
    230247            $unsafeSingleField = htmlspecialchars($unsafeSingleField);
     
    232249            $singleField = trim($unsafeSingleField);
    233250            return $singleField;
    234         }
    235         else
    236         {
     251        } else {
    237252            return null;
     253        }
     254    }
     255
     256    /**
     257     * Get cron settings field key and name
     258     *
     259     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     260     * @copyright   Cacholong <[email protected]>
     261     * @todo        ok
     262     *
     263     * @version     1.0.0     2019-02-19
     264     *
     265     * @return      array     Array of cron settings. Key is cache helper cron setting name, value is cache helper name.
     266     */
     267    public function getCronSettingsFieldKeyAndName() {
     268        try {
     269            $this->cacheHelperSubject = new \Cacholong\Designpattern\Observer\CacheHelperSubject();
     270            $this->create_all_observers($this->cacheHelperSubject);
     271            return $this->cacheHelperSubject->getCronSettingsFieldKeyAndName();
     272        } catch (\Exception $ex) {
     273            cacholong_cc_log_exception($ex);
     274        }
     275    }
     276
     277    /**
     278     * Get cron settings field key and hook purge name
     279     *
     280     * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
     281     * @copyright   Cacholong <[email protected]>
     282     * @todo        ok
     283     *
     284     * @version     1.0.0     2019-02-19
     285     *
     286     * @return      array     Array of cron settings. Key is cache helper cron setting name, value is cache helper hook name.
     287     */
     288    public function getCronSettingsFieldKeyAndHookPurgeName() {
     289        try {
     290            $this->cacheHelperSubject = new \Cacholong\Designpattern\Observer\CacheHelperSubject();
     291            $this->create_all_observers($this->cacheHelperSubject);
     292            return $this->cacheHelperSubject->getCronSettingsFieldKeyAndHookPurgeName();
     293        } catch (\Exception $ex) {
     294            cacholong_cc_log_exception($ex);
    238295        }
    239296    }
     
    251308     * @return      void
    252309     */
    253     public function create_all_observers($subject)
    254     {
     310    public function create_all_observers($subject) {
    255311        $this->cacheHelperObservers[] = new \Cacholong\Designpattern\Observer\NginxPageSpeedCacheHelperObserver($subject);
    256312        $this->cacheHelperObservers[] = new \Cacholong\Designpattern\Observer\NginxFastCGICacheHelperObserver($subject);
     
    273329     * @return      void
    274330     */
    275     private function start_purge_single($relative_path)
    276     {
    277         try
    278         {
     331    private function start_purge_single($relative_path) {
     332        try {
    279333            $hosts = $this->get_hosts();
    280             if(is_array($hosts))
    281             {
    282                 if(!empty($relative_path))
    283                 {
     334            if (is_array($hosts)) {
     335                if (!empty($relative_path)) {
    284336                    $this->cacheHelperSubject = new \Cacholong\Designpattern\Observer\CacheHelperSubject();
    285337                    $this->cacheHelperSubject->set_hosts_info($hosts);
     
    289341
    290342                    $this->cacheHelperSubject->notifyPurgeSingleRequest();
    291                 }
    292                 else
    293                 {
     343                } else {
    294344                    $message = __("Could not purge single file, because no valid path was given. Please try again.", \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN);
    295345                    \Cacholong\Libraries\AdminMessage::set_message($message, \Cacholong\Entities\AdminNoticeClass::ERROR);
     
    297347            }
    298348            //else do nop
    299         }
    300         catch (\Exception $ex)
    301         {
     349        } catch (\Exception $ex) {
    302350            cacholong_cc_log_exception($ex);
    303351        }
     
    319367     * @return      void
    320368     */
    321     private function start_purge_multiple($relative_paths)
    322     {
    323         try
    324         {
     369    private function start_purge_multiple($relative_paths) {
     370        try {
    325371            $hosts = $this->get_hosts();
    326             if(is_array($hosts))
    327             {
    328                 if(is_array($relative_paths) && $relative_paths)
    329                 {
     372            if (is_array($hosts)) {
     373                if (is_array($relative_paths) && $relative_paths) {
    330374                    $this->cacheHelperSubject = new \Cacholong\Designpattern\Observer\CacheHelperSubject();
    331375                    $this->cacheHelperSubject->set_hosts_info($hosts);
     
    335379
    336380                    $this->cacheHelperSubject->notifyPurgeMultipleRequest();
    337                 }
    338                 else
    339                 {                   
     381                } else {
    340382                    $message = __("Nothing is purged. If you expected a purge, please check settings page from Cache control by Cacholong plugin.", \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN);
    341383                    \Cacholong\Libraries\AdminMessage::set_message($message, \Cacholong\Entities\AdminNoticeClass::WARNING);
     
    343385            }
    344386            //else do nop
    345         }
    346         catch (\Exception $ex)
    347         {
     387        } catch (\Exception $ex) {
    348388            cacholong_cc_log_exception($ex);
    349389        }
     
    362402     * @return      void
    363403     */
    364     private function start_purge_all()
    365     {
    366         try
    367         {
     404    private function start_purge_all() {
     405        try {
    368406            $hosts = $this->get_hosts();
    369             if(is_array($hosts))
    370             {
     407            if (is_array($hosts)) {
    371408                $this->cacheHelperSubject = new \Cacholong\Designpattern\Observer\CacheHelperSubject();
    372409                $this->cacheHelperSubject->set_hosts_info($hosts);
     
    377414            }
    378415            //else do nop
    379         }
    380         catch (\Exception $ex)
    381         {
     416        } catch (\Exception $ex) {
    382417            cacholong_cc_log_exception($ex);
    383418        }
  • cache-control-by-cacholong/trunk/core/libraries/Style.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/UserOptions.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/WordpressURL.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/purgeSetting/CustomtPostPurgeSetting.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/purgeSetting/DefaultPostPurgeSetting.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/libraries/purgeSetting/PurgeSetting.php

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/view/admin/misc/admin_message.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/view/admin/settings/field/custom_post_purge_settings.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/view/admin/settings/field/default_post_purge_settings.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/view/admin/settings/field/location_json_hosts_file.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/view/admin/settings/field/remove_style_id.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
  • cache-control-by-cacholong/trunk/core/view/admin/settings/page/cacholong_cache_control.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
     
    2929 *
    3030 * @version     1.0.0     Created at 2015-10-21
     31 * @version     1.1.0     2019-02-20 Cron purging form
    3132 */
    3233?>
     
    5152        <?php echo submit_button(__('Purge single item', \Cacholong\Entities\Identifier::CC_TEXT_DOMAIN))?>
    5253    </form>
    53 
     54   
    5455    <form id="<?php echo \Cacholong\Entities\Identifier::CC_SETTINGS_SECTION_FORM_ID ?>" method="post" action="options.php">
    5556        <?php settings_fields(\Cacholong\Entities\Identifier::CC_OPTIONS);?>
  • cache-control-by-cacholong/trunk/core/view/admin/settings/section/cacholong_cache_control_settings.phtml

    r1834268 r2036979  
    11<?php
    22/**
    3  * Copyright © 2015-2018, Cacholong <[email protected]>
     3 * Copyright © 2015-2019, Cacholong <[email protected]>
    44 *
    55 * This file is part of Cache Control
     
    2222<?php
    2323/**
    24  * Template for section settings
     24 * Template for section settings (default)
    2525 *
    2626 * @author      Preliot, Piet Rol <[email protected]> (commissioned by Cacholong)
  • cache-control-by-cacholong/trunk/readme.txt

    r1974795 r2036979  
    11=== Cache control by Cacholong ===
    22Contributors: cacholong, preliot
    3 Tags: cache control, cache, caching, cacholong, pagespeed, fastcgi, nginx, nginx pagespeed, nginx fastcgi, cache
     3Tags: cache control, cache, caching, cacholong, pagespeed, fastcgi, nginx, nginx pagespeed, nginx fastcgi, cache, cronjob, cronjobs, schedule
    44Requires at least: 4.3.1
    5 Tested up to: 5.0.0
     5Tested up to: 5.0.3
    66Requires PHP: 5.6
    77Stable tag: trunk
     
    1919
    2020* Purge Nginx Pagespeed cache and/or Nginx FastCGI cache.
     21* Purging automatically, manually and with Wordpress cronjobs.
    2122* Purge caches on one or more servers (See hosts.json section for more details).
    2223* Remove id tag from stylesheet link tags, in order to allow Nginx Pagespeed to combine stylesheets.
     
    2930There is one caveat: When the user uses “Quick edit” and “Updates” the post, no messages will be displayed, because there's no page refresh. Those messages will be shown on the next request.
    3031
     32It is possible to purge with Wordpress cronjobs. Adjust the 'Crojob settings' to perform a daily purge of caches.
     33
    3134You can also purge items manually. Go to the WordPress dashboard and navigate to:
    3235
     
    4144* Purge settings default post types:      Select one or more options when purging a default post type. Possible to purge post url (default), home page, all connected Wordpress categories or all caches.
    4245* Purge settings default custom type(s):  Select one or more options when purging a custom post type. Possible to purge post url (default), home page, all connected Wordpress categories or all caches.
     46
     47= Cronjob Settings =
     48
     49* Cronjob purging:                        Enable or disable cronjob purging.
     50* Cronjob time of each day:               Enter HH:MM in 24 hour notation for cronjob time of day. Will fallback to 00:00 when wrong format is given.
     51* Purge caches                            Select caches to purge on given cronjob time.
    4352
    4453= hosts.json =
     
    130139Although no message is displayed, the purge was activated! You can see the purge message when you refresh the page. This is a technical limitation.
    131140
    132 
     141= Why do my cronjobs execute later then I expect? =
     142
     143Wordpress cronjobs are not the same as real cronjobs. Wordpress cronjobs will start if someone visits your website after (or on the) scheduled time. This might be later then expected.
     144It is possible to disable Wordpress cronjobs and use a real cronjob that polls wp-cron.php on a regular base.
     145
     146= Why does my cronjob execute immediately? =
     147
     148If you enter a time of day that has already passed, the first cronjob is set to this time of day and is executed the first time the site is loaded (or wp-cron.php is called).
     149
     150 = What should I do Wordpress cronjobs are disabled? =
     151
     152Wordpress cronjobs are disabled ('DISABLE_WP_CRON' = true). Please use a different type of cronjob to poll wp-cron.php on a regular base.
     153If purging of the cache fails through the cron mechanism make sure the hosts.json file is in place with the proper settings. See hosts.json section on the plugins page for more details.
    133154
    134155== Screenshots ==
     
    139160
    140161== Changelog ==
     162
     163= 4.1.1 - 2019-02-22 =
     164
     165* Added - When Wordpress cronjobs are disabled (DISABLE_WP_CRON = true), text with link to FAQ is shown underneath setting to activate cronjob purging
     166* Added - Current timezone underneath setting for cronjob time of day
     167
     168= 4.1.0 - 2019-02-21 =
     169* Added - Plugin is capable to purge with Wordpress cronjobs
     170* Added - Plugin is tested for usage with Wordpress 5.0.3
     171* Added - Icon for 'Purge all caches' on adminbar
     172* Fixed - Errors caused by empty 'File with hosts (JSON)' setting
     173* Changed - 'Purge all caches' also available on frontend adminbar
     174* Changed - Corrected a few spellerrors (cachalong -> cacholong)
     175* Changed - Updated copyright from 2015-2018 to 2015-2019
    141176
    142177= 4.0.2 - 2018-11-15 =
     
    163198* Deprecated - Curl class.
    164199
    165 = 3.2.1 - 2018-01-25 =
    166 * Fixed - Small fix for showing 'delay text'.
    167 
    168 = 3.2.0 - 2018-01-24 =
    169 * Changed - Only show 'delay text' for pagespeed when purge was succesful, instead of always.
    170 
    171 = 3.1.1 - 2016-09-14 =
    172 * Fixed - Removed a few purge hooks from is_admin() to work again.
    173 
    174 = 3.1.0 - 2017-12-22 =
    175 * Added - Delay text message for all purges.
    176 * Fixed - Handle non-array admin messages.
    177 * Changed - userOptions table is now used to handle session flash data, session handling is removed.
    178 * Changed - is_admin() to optimize performance frontend.
    179 * Changed - Removed log message for missing hosts json file, not needed anymore.
    180 * Changed - Language files updated.
    181 * Changed - Improvements in messages, phpDoc and debugging.
    182 * Deprecated - Sessions class.
    183 
    184 = 3.0.0 - 2017-12-15 =
    185 * Added - Setting to enable or disable removing id attribute from stylesheet link tag. Nginx pagespeed needs css id removed to combine stylesheets.
    186 
    187200See changelog.txt for all versions.
    188201
Note: See TracChangeset for help on using the changeset viewer.