vivio-swift-config-settings.php 9.97 KB
Newer Older
Jordan Michaels's avatar
Jordan Michaels committed
1 2 3
<?php

class Vivio_Swift_Config_Settings
Jordan Michaels's avatar
Jordan Michaels committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
{
    // environment vars
    var $has_apache;
    var $has_modrewrite;
    var $has_modheader;

    // functional vars
    var $can_cache;
    var $can_header;

    function __construct()
    {
        // perform environment tests to determine ability
        $this->has_apache = boolval($vivio_swift_global->util_apache->apache_version());
        $this->has_modrewrite = boolval($vivio_swift_global->util_apache->test_mod_rewrite());
        $this->has_modheader = boolval($vivio_swift_global->util_apache->test_mod_headers());

        // combine tests to determine functionality
        $this->can_cache = (($this->has_apache && $this->has_modrewrite)?true:false);
        $this->can_header = ($this->has_modheader?true:false);
Jordan Michaels's avatar
Jordan Michaels committed
24 25
    }
    
Jordan Michaels's avatar
Jordan Michaels committed
26
    static function add_value_configs()
Jordan Michaels's avatar
Jordan Michaels committed
27
    {
Jordan Michaels's avatar
Jordan Michaels committed
28
        global $vivio_swift_global;
Jordan Michaels's avatar
Jordan Michaels committed
29

30
        // Debug
Jordan Michaels's avatar
Jordan Michaels committed
31
        $vivio_swift_global->configs->add_value('vivio_swift_enable_debug','');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
32
        $vivio_swift_global->configs->add_value('vivio_swift_debug_level','3');//0-5 3=warn
Jordan Michaels's avatar
Jordan Michaels committed
33

34 35 36 37
        // Cache Response HTML comment
        $vivio_swift_global->configs->add_value('vivio_swift_enable_cache_comment','');//Checkbox

        // Query Strings
Jordan Michaels's avatar
Jordan Michaels committed
38
        $vivio_swift_global->configs->add_value('vivio_swift_remove_query_strings','1');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
39

Jordan Michaels's avatar
Jordan Michaels committed
40 41
        // On-Access Cache
        $vivio_swift_global->configs->add_value('vivio_swift_cache_enabled',$this->can_cache?'1':'');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
42

43
        // Preload Cache
Jordan Michaels's avatar
Jordan Michaels committed
44
        $vivio_swift_global->configs->add_value('vivio_swift_preload_cache_enabled',$this->can_cache?'1':'');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
45 46 47
        $vivio_swift_global->configs->add_value('vivio_swift_preload_cache_expire_hours','1');
        $vivio_swift_global->configs->add_value('vivio_swift_preload_last_run_date','');

48
        // htaccess rules
Jordan Michaels's avatar
Jordan Michaels committed
49
        $vivio_swift_global->configs->add_value('vivio_swift_cache_custom_rules_at_top','');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
50 51 52 53
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_posts','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_query_strings','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_cookie_contains','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_cookie_values',array('comment_author_','wordpress_logged_in','wp-postpass_'));//array list
54 55
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_user_agent','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_user_agent_values',array(VIVIO_SWIFT_CACHE_BOT_NAME));//array list
Jordan Michaels's avatar
Jordan Michaels committed
56 57 58
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_path_is','');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_path_is_values',array());//array list
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_path_ends_with','');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
59
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_path_ends_with_values',array('.html','.png','.jpg','.jpeg','.gif','.ico','.svg','.xml','.json'));//array list
Jordan Michaels's avatar
Jordan Michaels committed
60 61 62 63 64
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_path_contains','');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_exclude_path_contains_values',array());//array list
        $vivio_swift_global->configs->add_value('vivio_swift_cache_enable_custom_rules','');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_custom_rules_values',array());//array list

Jordan Michaels's avatar
Jordan Michaels committed
65 66 67 68
        // htaccess cache-control
        $vivio_swift_global->configs->add_value('vivio_swift_cache_control_headers_enable','0');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_cache_control_headers_values',Vivio_Swift_Config_Settings::default_cache_control_groups());

69
        // Compression options
Jordan Michaels's avatar
Jordan Michaels committed
70 71 72 73 74
        $vivio_swift_global->configs->add_value('vivio_swift_compress_minify_css','');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_compress_minify_js','');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_compress_minify_html','');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_compress_combine_css','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_compress_combine_js','1');//Checkbox
75

Jordan Michaels's avatar
Jordan Michaels committed
76 77 78
        // refresh events
        $vivio_swift_global->configs->add_value('vivio_swift_refresh_on_post_new','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_refresh_on_post_update','1');//Checkbox
79 80
        $vivio_swift_global->configs->add_value('vivio_swift_refresh_on_category_change','1');//Checkbox
        $vivio_swift_global->configs->add_value('vivio_swift_refresh_on_tag_change','1');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
81 82 83 84 85

	    //Done. Save it.
        $vivio_swift_global->configs->save_config();
    }
    
Jordan Michaels's avatar
Jordan Michaels committed
86
    static function reset_to_defaults()
Jordan Michaels's avatar
Jordan Michaels committed
87 88 89
    {
        global $vivio_swift_global;

Jordan Michaels's avatar
Jordan Michaels committed
90 91
        $vivio_swift_global->configs->reset_config();

Jordan Michaels's avatar
Jordan Michaels committed
92
        // Debug
Jordan Michaels's avatar
Jordan Michaels committed
93
        $vivio_swift_global->configs->set_value('vivio_swift_enable_debug','');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
94
        $vivio_swift_global->configs->set_value('vivio_swift_debug_level','3');//0-5 3=warn
Jordan Michaels's avatar
Jordan Michaels committed
95

Jordan Michaels's avatar
Jordan Michaels committed
96
        // Cache Response HTML comment
97 98
        $vivio_swift_global->configs->set_value('vivio_swift_enable_cache_comment','');//Checkbox

Jordan Michaels's avatar
Jordan Michaels committed
99
        // Query Strings
Jordan Michaels's avatar
Jordan Michaels committed
100
        $vivio_swift_global->configs->set_value('vivio_swift_remove_query_strings','1');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
101

Jordan Michaels's avatar
Jordan Michaels committed
102 103
        // On-Access Cache
        $vivio_swift_global->configs->set_value('vivio_swift_cache_enabled',$this->can_cache?'1':'');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
104

Jordan Michaels's avatar
Jordan Michaels committed
105 106
        // Preload Cache
        $vivio_swift_global->configs->set_value('vivio_swift_preload_cache_enabled',$this->can_cache?'1':'');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
107 108 109
        $vivio_swift_global->configs->set_value('vivio_swift_preload_cache_expire_hours','1');
        $vivio_swift_global->configs->set_value('vivio_swift_preload_last_run_date','');

Jordan Michaels's avatar
Jordan Michaels committed
110
        // htaccess rules
Jordan Michaels's avatar
Jordan Michaels committed
111
        $vivio_swift_global->configs->set_value('vivio_swift_cache_custom_rules_at_top','');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
112 113 114 115
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_posts','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_query_strings','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_cookie_contains','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_cookie_values',array('comment_author_','wordpress_logged_in','wp-postpass_'));//array list
116 117
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_user_agent','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_user_agent_values',array(VIVIO_SWIFT_CACHE_BOT_NAME));//array list
Jordan Michaels's avatar
Jordan Michaels committed
118 119 120
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_path_is','');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_path_is_values',array());//array list
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_path_ends_with','');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
121
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_path_ends_with_values',array('.html','.png','.jpg','.jpeg','.gif','.ico','.svg','.xml','.json'));//array list
Jordan Michaels's avatar
Jordan Michaels committed
122 123 124 125 126
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_path_contains','');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_exclude_path_contains_values',array());//array list
        $vivio_swift_global->configs->set_value('vivio_swift_cache_enable_custom_rules','');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_custom_rules_values',array());//array list

Jordan Michaels's avatar
Jordan Michaels committed
127 128 129 130
        // htaccess cache-control
        $vivio_swift_global->configs->set_value('vivio_swift_cache_control_headers_enable','0');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_cache_control_headers_values',Vivio_Swift_Config_Settings::default_cache_control_groups());

131
        // Compression options
Jordan Michaels's avatar
Jordan Michaels committed
132 133 134 135 136
        $vivio_swift_global->configs->set_value('vivio_swift_compress_minify_css','');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_compress_minify_js','');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_compress_minify_html','');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_compress_combine_css','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_compress_combine_js','1');//Checkbox
137

Jordan Michaels's avatar
Jordan Michaels committed
138 139 140
        // refresh events
        $vivio_swift_global->configs->set_value('vivio_swift_refresh_on_post_new','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_refresh_on_post_update','1');//Checkbox
141 142
        $vivio_swift_global->configs->set_value('vivio_swift_refresh_on_category_change','1');//Checkbox
        $vivio_swift_global->configs->set_value('vivio_swift_refresh_on_tag_change','1');//Checkbox
Jordan Michaels's avatar
Jordan Michaels committed
143

Jordan Michaels's avatar
Jordan Michaels committed
144
        // Done. Save it.
Jordan Michaels's avatar
Jordan Michaels committed
145
        $vivio_swift_global->configs->save_config();
Jordan Michaels's avatar
Jordan Michaels committed
146
    }
Jordan Michaels's avatar
Jordan Michaels committed
147

Jordan Michaels's avatar
Jordan Michaels committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    static function default_cache_control_groups()
    {
        $groups = array(
            0 => [  'name'          => 'Image Files',
                    'max-age'       => '2419200', // 1 month
                    'enable-cache'  => '1', 
                    'extensions'    => array('png','jpg','jpeg','gif','ico','svg')
            ],
            1 => [  'name'          => 'Static Files',
                    'max-age'       => '604800', // 1 week
                    'enable-cache'  => '1', 
                    'extensions'    => array('css','js','pdf','txt','csv')
            ],
            2 => [  'name'          => 'HTML Files',
                    'max-age'       => '86400', // 1 day
                    'enable-cache'  => '1', 
                    'extensions'    => array('html','htm')
            ],
            3 => [  'name'          => 'Dynamic Files',
                    'max-age'       => '0', // no cache
                    'enable-cache'  => '0', 
                    'extensions'    => array('php')
            ]
        );
        return $groups;
    }

Jordan Michaels's avatar
Jordan Michaels committed
175
}