vivio-swift-dashboard-menu.php 41.8 KB
Newer Older
Jordan Michaels's avatar
Jordan Michaels committed
1 2 3 4 5 6 7 8 9 10 11 12
<?php

class Vivio_Swift_Dashboard_Menu extends Vivio_Swift_Admin_Messages
{
    var $dashboard_menu_page_slug = VIVIO_SWIFT_MAIN_MENU_SLUG;

    var $menu_tabs;

    var $menu_tabs_handler = array(
        'tab1' => 'render_tab1',
        'tab2' => 'render_tab2',
        'tab3' => 'render_tab3',
Jordan Michaels's avatar
Jordan Michaels committed
13 14 15
        'tab4' => 'render_tab4',
        'tab5' => 'render_tab5',
        'tab6' => 'render_tab6'
Jordan Michaels's avatar
Jordan Michaels committed
16 17 18 19 20 21 22 23 24 25 26 27 28
    );

    function __construct()
    {
        $this->render_menu_page();
    }

    function set_menu_tabs()
    {
        $this->menu_tabs = array(
            'tab1' => __('Dashboard', 'vivio-swift'),
            'tab2' => __('System Info', 'vivio-swift'),
            'tab3' => __('Log Viewer', 'vivio-swift'),
Jordan Michaels's avatar
Jordan Michaels committed
29 30 31
            'tab4' => __('Cookie Viewer', 'vivio-swift'),
            'tab5' => __('htaccess Viewer', 'vivio-swift'),
            'tab6' => __('System Reset', 'vivio-swift')
Jordan Michaels's avatar
Jordan Michaels committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        );
    }

    function get_current_tab()
    {
        $tab_keys = array_keys($this->menu_tabs);
        $tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : $tab_keys[0];
        return $tab;
    }

    /*
     * Renders our tabs of this menu as nav items
     */
    function render_menu_tabs()
    {
        $current_tab = $this->get_current_tab();

        echo '<h2 class="nav-tab-wrapper">';
        foreach ($this->menu_tabs as $tab_key => $tab_caption) {
            $active = $current_tab == $tab_key ? 'nav-tab-active' : '';
            echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->dashboard_menu_page_slug . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
        }
        echo '</h2>';
    }

    /*
     * The menu rendering goes here
     */
    function render_menu_page()
    {
        echo '<div class="wrap">';
        echo '<h2>' . __('Vivio Swift Dashboard', 'vivio-swift') . '</h2>';//Interface title
        $this->set_menu_tabs();
        $tab = $this->get_current_tab();
        $this->render_menu_tabs();
        ?>        
        <div id="poststuff"><div id="post-body">
        <?php
        //$tab_keys = array_keys($this->menu_tabs);
        call_user_func(array(&$this, $this->menu_tabs_handler[$tab]));
        ?>
        </div></div>
        </div><!-- end of wrap -->
        <?php
    }

    function render_tab1()
    {
    
        echo '<div class="message_standard">';
82
        echo '<p>' . __('Thank you for trying Vivio Swift (beta). Please report bugs or issues <a href="https://viviotech.net/contactus.html" target="_blank">HERE</a>.', 'vivio-swift') . '</p>';
Jordan Michaels's avatar
Jordan Michaels committed
83 84 85 86 87
        echo '<p><a href="https://twitter.com/viviotech/" target="_blank">' . __('Follow us on Twitter', 'vivio-swift') . '</a> ' . __('to stay up to date on new and improved features of this plugin.', 'vivio-swift') . '</p>';
        echo '</div>';

        global $vivio_swift_global;

88 89 90 91 92 93 94 95 96 97 98 99
        $cache_expires_in_txt = '';
        $preload_cache_enabled = $vivio_swift_global->configs->get_value('vivio_swift_preload_cache_enabled');
        $preload_last_run_date = $vivio_swift_global->configs->get_value('vivio_swift_preload_last_run_date');
        $preload_last_run_datetime = new DateTime( $vivio_swift_global->configs->get_value('vivio_swift_preload_last_run_date') );

        // if preload is enabled, calc the expiration date
        if (($preload_cache_enabled=='1') && ($preload_last_run_date!='')){
            $cache_expires_in_txt = Vivio_Swift_Utility_Date::format_interval($preload_last_run_datetime);
        } else {
            $cache_expires_in_txt = "No Preload Cache on record.";
        }

Jordan Michaels's avatar
Jordan Michaels committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        if (isset($_POST['vivio_swift_clear_cache_submit']))
        {
            // verify nonce
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio_swift_clear_cache_dashboard_nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Vivio_Swift_Dashboard_Menu::render_tab1 - Nonce check failed in preload settings.", 4);
                wp_die("Error: Nonce check failed when attempting to clear cache.");
            }

            Vivio_Swift_Cache_Preload::clear();
            $this->show_msg_settings_updated();
        }

        if (isset($_POST['vivio_swift_preload_force_refresh'])){
            // verify nonce
            $nonce = $_REQUEST['_wpnonce'];
116 117 118
            if (!wp_verify_nonce($nonce, 'vivio_swift_preload_dashboard_nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Vivio_Swift_Dashboard_Menu::render_tab1 - Nonce check failed in preload dashboard.", 4);
                wp_die("Error: Nonce check failed when attempting to update cache dashboard.");
Jordan Michaels's avatar
Jordan Michaels committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
            }

            // force a preload cache refresh
            $vivio_swift_global->cache_obj->cache_preload->create_preload_cache(1);
        }

        if (isset($_POST['vivio_swift_cache_dashboard_submit']))
        {
            // verify nonce
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio_swift_cache_dashboard_nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Vivio_Swift_Dashboard_Menu::render_tab1 - Nonce check failed in preload settings.", 4);
                wp_die("Error: Nonce check failed when attempting to update cache settings.");
            }

            // set and save submitted settings
            $vivio_swift_global->configs->set_value('vivio_swift_cache_enabled',isset($_POST["vivio_swift_cache_enabled"])?'1':'');
            $vivio_swift_global->configs->set_value('vivio_swift_preload_cache_enabled',isset($_POST["vivio_swift_preload_cache_enabled"])?'1':'');
            $vivio_swift_global->configs->save_config();

            $this->show_msg_settings_updated();
        }

Jordan Michaels's avatar
Jordan Michaels committed
142 143 144 145 146
        ?>
        <div id="vivio-swift-container">
            <div class="dashboard_box_small">
                <div class="postbox">
                    <h3 class="hndle">
Jordan Michaels's avatar
Jordan Michaels committed
147
                        <label for="title"><?php _e('Quick Cache', 'vivio-swift');?></label>
Jordan Michaels's avatar
Jordan Michaels committed
148 149 150
                    </h3>

                    <div class="inside">
Jordan Michaels's avatar
Jordan Michaels committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
                        <form action=""
                            id="vivio_swift_cache_dashboard"
                            method="POST">
                            <?php wp_nonce_field('vivio_swift_cache_dashboard_nonce'); ?>
                            <table class="form-table">
                                <tr valign="top">
                                    <th scope="row"><?php _e('On-Access Cache', 'vivio-swift')?>:</th>
                                    <td>
                                        <label class="switch">
                                            <input name="vivio_swift_cache_enabled" type="checkbox"<?php if($vivio_swift_global->configs->get_value('vivio_swift_cache_enabled')=='1') echo ' checked="checked"'; ?> value="1"/>
                                            <span class="slider round"></span>
                                        </label>
                                    </td>
                                </tr>
                                <tr valign="top">
                                    <th scope="row"><?php _e('Preload Cache', 'vivio-swift')?>:</th>                
                                    <td>
                                        <label class="switch">
                                            <input name="vivio_swift_preload_cache_enabled"
                                                id="vivio_swift_preload_cache_enabled"
                                                type="checkbox"<?php if($vivio_swift_global->configs->get_value('vivio_swift_preload_cache_enabled')=='1') echo ' checked="checked"'; ?> value="1"/>
                                            <span class="slider round"></span>
                                        </label>
                                    </td>
                                </tr>
                            </table>
                            <input type="submit" name="vivio_swift_cache_dashboard_submit" id="vivio_swift_cache_dashboard_submit" value="<?php _e('Save Settings', 'vivio-swift')?>" class="pure-button" />
                        </form>
Jordan Michaels's avatar
Jordan Michaels committed
179 180 181 182 183 184 185
                    </div>
                </div>
            </div>

            <div class="dashboard_box_small">
                <div class="postbox">
                    <h3 class="hndle">
Jordan Michaels's avatar
Jordan Michaels committed
186
                        <label for="title"><?php _e('Quick Clear', 'vivio-swift');?></label>
Jordan Michaels's avatar
Jordan Michaels committed
187 188 189
                    </h3>

                    <div class="inside">
Jordan Michaels's avatar
Jordan Michaels committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203
                        <form action=""
                            id="vivio_swift_clear_cache_dashboard"
                            method="POST">
                            <?php wp_nonce_field('vivio_swift_clear_cache_dashboard_nonce'); ?>
                            <table class="form-table">
                                <tr valign="top">
                                    <th scope="row"><?php _e('Current Cache', 'vivio-swift')?>:</th>
                                    <td>
                                    <span class="description"><?php echo Vivio_Swift_Utility_File::get_file_count().' Files ('.Vivio_Swift_Utility_File::get_directory_size().')'; ?></span>
                                    </td>
                                </tr>
                            </table>
                            <input type="submit" name="vivio_swift_clear_cache_submit" value="<?php _e('Clear Cache', 'vivio-swift')?>" class="pure-button button-error" />
                        </form>
Jordan Michaels's avatar
Jordan Michaels committed
204 205 206 207
                    </div>
                </div>
            </div>

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
            <div class="dashboard_box_small">
                <div class="postbox">
                    <h3 class="hndle">
                        <label for="title"><?php _e('Preload Cache', 'vivio-swift');?></label>
                    </h3>

                    <div class="inside">
                        <form action=""
                            id="vivio_swift_preload_dashboard"
                            method="POST">
                            <?php wp_nonce_field('vivio_swift_preload_dashboard_nonce'); ?>
                            <table class="form-table">
                                <tr valign="top">
                                    <th scope="row"><?php _e('Current Preload Cache Age', 'vivio-swift')?>:</th>                
                                    <td>
                                    <span class="description"><?php echo $cache_expires_in_txt; //echo ' ('.$preload_last_run_date.')' ?></span>
                                    </td>
                                </tr>
                                <tr valign="top">
                                    <th scope="row"><?php _e('Force Preload Refresh', 'vivio-swift')?>:</th>                
                                    <td>
                                        <label>
                                            <input type="submit" name="vivio_swift_preload_force_refresh" value="<?php _e('Force Refresh', 'vivio-swift')?>"
                                                class="pure-button button-small"
                                                <?php if(!$vivio_swift_global->configs->get_value('vivio_swift_preload_cache_enabled')=='1') echo ' disabled'; ?> />
                                        </label>
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </div>
            </div>

Jordan Michaels's avatar
Jordan Michaels committed
242 243 244
            <div class="dashboard_box_small">
                <div class="postbox">
                    <h3 class="hndle">
Jordan Michaels's avatar
Jordan Michaels committed
245
                        <label for="title"><?php _e('Spread the Word', 'vivio-swift');?></label>
Jordan Michaels's avatar
Jordan Michaels committed
246 247
                    </h3>
                    <div class="inside">
248
                        <p><?php _e('Has this plugin helped you? Let others know!', 'vivio-swift');?></p>
Jordan Michaels's avatar
Jordan Michaels committed
249
                        <p><a href="https://www.facebook.com/viviotech" target="_blank">Like us on Facebook</a></p>
250
                        <p><a href="http://twitter.com/intent/tweet?url=https://viviotech.net/&text=Using the Vivio Swift Wordpress plugin from @viviotech has really helped speed up my site! Check it out!" target="_blank">Post to Twitter</a></p>
Jordan Michaels's avatar
Jordan Michaels committed
251
                        <p><a href="#" target="_blank">Give a Good Rating on Wordpress</a></p>
Jordan Michaels's avatar
Jordan Michaels committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
                    </div>
                </div>
            </div>

        </div>
        <!-- Masonry stuff -->
        
        <?php
        echo '<script type="text/javascript" src="' . VIVIO_SWIFT_URL . '/js/masonry.pkgd.min.js"></script>';
        ?>
        <script type="text/javascript">
            window.onload = function () {
                var container = document.querySelector('#vivio-swift-container');
                var msnry = new Masonry(container, {
                    // options
                    columnWidth: 100,
                    itemSelector: '.dashboard_box_small'
                });
            }
        </script>
    <?php
    }


    function render_tab2()
    {
    
        echo '<div class="message_standard">';
        echo '<p>' . __('The following information is useful when reporting bugs or issues regarding Vivio Swift.', 'vivio-swift') . '</p>';
        echo '</div>';

        global $wpdb;
        global $vivio_swift_global;

        ?>
        <div class="postbox">
            <h3 class="hndle">
Jordan Michaels's avatar
Jordan Michaels committed
289
                <label for="title"><?php _e('Vivio Swift Environment', 'vivio-swift');?></label>
Jordan Michaels's avatar
Jordan Michaels committed
290 291 292
            </h3>

            <div class="inside">
Jordan Michaels's avatar
Jordan Michaels committed
293
                <strong><?php _e('VERSION', 'vivio-swift');?>
Jordan Michaels's avatar
Jordan Michaels committed
294
                    : </strong><code><?php echo VIVIO_SWIFT_VERSION;?></code><br/>
Jordan Michaels's avatar
Jordan Michaels committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
                <strong><?php _e('URL', 'vivio-swift');?>
                    : </strong><code><?php echo VIVIO_SWIFT_URL; ?></code><br/>
                <strong><?php _e('PATH', 'vivio-swift');?>
                    : </strong><code><?php echo VIVIO_SWIFT_PATH; ?></code><br/>
                <strong><?php _e('CACHE URL', 'vivio-swift');?>
                    : </strong><code><?php echo VIVIO_SWIFT_CACHE_URL; ?></code><br/>
                <strong><?php _e('CACHE PATH', 'vivio-swift');?>
                    : </strong><code><?php echo VIVIO_SWIFT_CACHE_PATH; ?></code><br/>
                <strong><?php _e('BOT NAME', 'vivio-swift');?>
                    : </strong><code><?php echo VIVIO_SWIFT_CACHE_BOT_NAME; ?></code><br/>

            </div>
        </div><!-- End of Site Info -->

        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('WordPress Environment', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
Jordan Michaels's avatar
Jordan Michaels committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
                <strong><?php _e('WP Version', 'vivio-swift');?>
                    : </strong><code><?php echo get_bloginfo("version"); ?></code><br/>
                <strong>WPMU: </strong><code><?php echo (!defined('MULTISITE') || !MULTISITE) ? "No" : "Yes"; ?></code><br/>
                <strong>MySQL <?php _e('Version', 'vivio-swift');?>
                    : </strong><code><?php echo $wpdb->db_version();?></code><br/>
                <strong>WP <?php _e('Table Prefix', 'vivio-swift');?>
                    : </strong><code><?php echo $wpdb->prefix; ?></code><br/>
                <strong>PHP <?php _e('Version', 'vivio-swift');?>
                    : </strong><code><?php echo phpversion(); ?></code><br/>
                <strong><?php _e('Session Save Path', 'vivio-swift');?>
                    : </strong><code><?php echo ini_get("session.save_path"); ?></code><br/>
                <strong>WP URL: </strong><code><?php echo get_bloginfo('wpurl'); ?></code><br/>
                <strong><?php _e('Server Name', 'vivio-swift');?>
                    : </strong><code><?php echo $_SERVER['SERVER_NAME']; ?></code><br/>
                <strong><?php _e('Cookie Domain', 'vivio-swift');?>
                    : </strong><code><?php $cookieDomain = parse_url(strtolower(get_bloginfo('wpurl')));
                    echo $cookieDomain['host']; ?></code><br/>
                <strong>CURL <?php _e('Library Present', 'vivio-swift');?>
                    : </strong><code><?php echo (function_exists('curl_init')) ? "Yes" : "No"; ?></code><br/>
                <strong><?php _e('Debug File Write Permissions', 'vivio-swift');?>
                    : </strong><code><?php echo (is_writable(VIVIO_SWIFT_PATH)) ? "Writable" : "Not Writable"; ?></code><br/>
Jordan Michaels's avatar
Jordan Michaels committed
336

Jordan Michaels's avatar
Jordan Michaels committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
            </div>
        </div><!-- End of Site Info -->

        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('PHP Info', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
                <strong><?php _e('PHP Version', 'vivio-swift'); ?>
                    : </strong><code><?php echo PHP_VERSION; ?></code><br/>
                <strong><?php _e('PHP Memory Usage', 'vivio-swift'); ?>:
                </strong><code><?php echo round(memory_get_usage() / 1024 / 1024, 2) . __(' MB', 'vivio-swift'); ?></code>
                <br/>
                <?php
                if (ini_get('memory_limit')) {
                    $memory_limit = filter_var(ini_get('memory_limit'), FILTER_SANITIZE_STRING);
                } else {
                    $memory_limit = __('N/A', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Memory Limit', 'vivio-swift'); ?>
                    : </strong><code><?php echo $memory_limit; ?></code><br/>
                <?php
                if (ini_get('upload_max_filesize')) {
                    $upload_max = filter_var(ini_get('upload_max_filesize'), FILTER_SANITIZE_STRING);
                } else {
                    $upload_max = __('N/A', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Max Upload Size', 'vivio-swift'); ?>
                    : </strong><code><?php echo $upload_max; ?></code><br/>
                <?php
                if (ini_get('post_max_size')) {
                    $post_max = filter_var(ini_get('post_max_size'), FILTER_SANITIZE_STRING);
                } else {
                    $post_max = __('N/A', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Max Post Size', 'vivio-swift'); ?>
                    : </strong><code><?php echo $post_max; ?></code><br/>
                <?php
                if (ini_get('allow_url_fopen')) {
                    $allow_url_fopen = __('On', 'vivio-swift');
                } else {
                    $allow_url_fopen = __('Off', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Allow URL fopen', 'vivio-swift'); ?>
                    : </strong><code><?php echo $allow_url_fopen; ?></code>
                <br/>
                <?php
                if (ini_get('allow_url_include')) {
                    $allow_url_include = __('On', 'vivio-swift');
                } else {
                    $allow_url_include = __('Off', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Allow URL Include'); ?>
                    : </strong><code><?php echo $allow_url_include; ?></code><br/>
                <?php
                if (ini_get('display_errors')) {
                    $display_errors = __('On', 'vivio-swift');
                } else {
                    $display_errors = __('Off', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Display Errors', 'vivio-swift'); ?>
                    : </strong><code><?php echo $display_errors; ?></code>
                <br/>
                <?php
                if (ini_get('max_execution_time')) {
                    $max_execute = filter_var(ini_get('max_execution_time'));
                } else {
                    $max_execute = __('N/A', 'vivio-swift');
                }
                ?>
                <strong><?php _e('PHP Max Script Execution Time', 'vivio-swift'); ?>
                    : </strong><code><?php echo $max_execute; ?> <?php _e('Seconds'); ?></code><br/>
            </div>
        </div><!-- End of PHP Info -->

        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('Active Plugins', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
                <?php
                $all_plugins = get_plugins();
                $active_plugins = get_option('active_plugins');
                //var_dump($all_plugins);
                ?>
                <table class="widefat margin_10_0">
                    <thead>
                    <tr>
                        <th><?php _e('Name', 'vivio-swift') ?></th>
                        <th><?php _e('Version', 'vivio-swift') ?></th>
                        <th><?php _e('Plugin URL', 'vivio-swift') ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                    foreach ($active_plugins as $plugin_key) {
                        $plugin_details = $all_plugins[$plugin_key];
                        echo '<tr><td>' . $plugin_details['Name'] . '</td><td>' . $plugin_details['Version'] . '</td><td>' . $plugin_details['PluginURI'] . '</td></tr>';
                    }
                    ?>
                    </tbody>
                </table>
            </div>
        </div><!-- End of Active Plugins -->
    <?php
    }

    function render_tab3()
    {
        global $vivio_swift_global;

Jordan Michaels's avatar
Jordan Michaels committed
456 457 458
        // $file_selected = filter_input(INPUT_POST, 'vivio_swift_log_file'); // Get the selected file
        $file_selected = VIVIO_SWIFT_LOG_FILE;
        $loglevel_selected = $vivio_swift_global->configs->get_value('vivio_swift_debug_level');
Jordan Michaels's avatar
Jordan Michaels committed
459 460 461 462 463 464 465 466 467

        // process enable/disable debugging logging
        if (isset($_POST['vivio_swift_save_debug_settings']))
        {
            $error = '';

            // verify nonce
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio-swift-debug-settings-nonce')) {
Jordan Michaels's avatar
Jordan Michaels committed
468
                $vivio_swift_global->debug_logger->log_debug("Vivio_Swift_Dashboard_Menu::render_tab3 - Nonce check failed in debug logging.", 4);
Jordan Michaels's avatar
Jordan Michaels committed
469 470 471
                wp_die("Error: Nonce check failed while attempting enable/disable debug logging.");
            }

Jordan Michaels's avatar
Jordan Michaels committed
472 473 474 475 476 477 478 479 480 481
            if (isset($_POST['vivio_swift_log_level'])){
                $loglevel_selected = intval($_POST['vivio_swift_log_level']);
            }

            if ($loglevel_selected >5) {
                $error .= '<br />'.__('You entered an invalid value for the log level field. It has been set to the default value.','vivio-swift');
                $loglevel_selected = 3;
            }
            $vivio_swift_global->configs->save_config();

Jordan Michaels's avatar
Jordan Michaels committed
482
            // set and save debug settings
483
            $vivio_swift_global->configs->set_value('vivio_swift_enable_cache_comment',isset($_POST["vivio_swift_enable_cache_comment"])?'1':'');
Jordan Michaels's avatar
Jordan Michaels committed
484
            $vivio_swift_global->configs->set_value('vivio_swift_enable_debug',isset($_POST["vivio_swift_enable_debug"])?'1':'');
Jordan Michaels's avatar
Jordan Michaels committed
485
            $vivio_swift_global->configs->set_value('vivio_swift_debug_level',$loglevel_selected);
Jordan Michaels's avatar
Jordan Michaels committed
486
            $vivio_swift_global->configs->save_config();
Jordan Michaels's avatar
Jordan Michaels committed
487

Jordan Michaels's avatar
Jordan Michaels committed
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
            // process user feedback
            if($error)
            {
                $this->show_msg_error(__('Attention!','vivio-swift').$error);
            }

            $this->show_msg_settings_updated();
        }

        // reset logs
        if (isset($_POST['vivio_swift_reset_logs']))
        {
            // verify nonce
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio_swift_reset_logs_nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Nonce check failed while attempting to reset logs.", 4);
                wp_die("Error: Nonce check failed while attempting to reset logs.");
            }

            $vivio_swift_global->debug_logger->reset_log_file('vivio-swift-log.txt');
            $vivio_swift_global->debug_logger->reset_log_file('vivio-swift-log-cron-job.txt');

            $this->show_msg_settings_updated();
Jordan Michaels's avatar
Jordan Michaels committed
511 512 513 514 515 516 517 518 519 520 521
        }

        ?>
        
        <!-- enable debugging option -->
        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('Debug Logging', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
Jordan Michaels's avatar
Jordan Michaels committed
522 523 524
                <form action=""
                    id="vivio_swift_dashboard_debug_settings"
                    method="POST">
Jordan Michaels's avatar
Jordan Michaels committed
525
                    <?php wp_nonce_field('vivio-swift-debug-settings-nonce'); ?>
Jordan Michaels's avatar
Jordan Michaels committed
526
                    <table class="form-table">
527 528 529 530 531 532 533 534 535 536 537 538
                        <tr valign="top">
                            <th scope="row"><?php _e('Enable HTML Comment', 'vivio-swift')?>:</th>
                            <td>
                                <label class="switch">
                                    <input name="vivio_swift_enable_cache_comment"
                                        id="vivio_swift_enable_cache_comment"
                                        type="checkbox"<?php if($vivio_swift_global->configs->get_value('vivio_swift_enable_cache_comment')=='1') echo ' checked="checked"'; ?> value="1"/>
                                    <span class="slider round"></span>
                                </label>
                                <span class="description"><?php _e('Adds a cache timestamp or other information to an HTML comment at the bottom of processed requests.', 'vivio-swift'); ?></span>
                            </td>
                        </tr>
Jordan Michaels's avatar
Jordan Michaels committed
539
                        <tr valign="top">
Jordan Michaels's avatar
Jordan Michaels committed
540
                            <th scope="row"><?php _e('Enable Debug Logging', 'vivio-swift')?>:</th>
Jordan Michaels's avatar
Jordan Michaels committed
541
                            <td>
Jordan Michaels's avatar
Jordan Michaels committed
542 543 544 545 546 547 548
                                <label class="switch">
                                    <input name="vivio_swift_enable_debug"
                                        id="vivio_swift_enable_debug"
                                        type="checkbox"<?php if($vivio_swift_global->configs->get_value('vivio_swift_enable_debug')=='1') echo ' checked="checked"'; ?> value="1"/>
                                    <span class="slider round"></span>
                                </label>
                                <span class="description"><?php _e('Enable certain actions to be logged and viewable in the Vivio Swift Log Viewer.', 'vivio-swift'); ?></span>
Jordan Michaels's avatar
Jordan Michaels committed
549 550
                            </td>
                        </tr>
Jordan Michaels's avatar
Jordan Michaels committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
                        <tr>
                            <th scope="row"><?php _e('Select Debug Log Level', 'vivio-swift')?>:</th>
                            <td>
                                <select
                                    id="vivio_swift_log_level"
                                    name="vivio_swift_log_level"
                                    <?php if(!$vivio_swift_global->configs->get_value('vivio_swift_enable_debug')=='1') echo 'disabled'; ?>
                                    >
                                    <option
                                        value="0"<?php selected($loglevel_selected, '0'); ?>>
                                        <?php _e('0 - DEBUG', 'vivio-swift')?>
                                    </option>
                                    <option
                                        value="1"<?php selected($loglevel_selected, '1'); ?>>
                                        <?php _e('1 - STATUS', 'vivio-swift')?>
                                    </option>
                                    <option
                                        value="2"<?php selected($loglevel_selected, '2'); ?>>
                                        <?php _e('2 - NOTICE', 'vivio-swift')?>
                                    </option>
                                    <option
                                        value="3"<?php selected($loglevel_selected, '3'); ?>>
                                        <?php _e('3 - WARNING', 'vivio-swift')?>
                                    </option>
                                    <option
                                        value="4"<?php selected($loglevel_selected, '4'); ?>>
                                        <?php _e('4 - FAILURE', 'vivio-swift')?>
                                    </option>
                                    <option
                                        value="5"<?php selected($loglevel_selected, '5'); ?>>
                                        <?php _e('5 - CRITICAL', 'vivio-swift')?>
                                    </option>
                                </select>
                                <span class="description"><span class="dashicons dashicons-info info-icon" id="log_level_info"></span> <?php _e('Your selected level and everything higher will be logged. For example, with "WARNING" selected, all warnings, failures, and critical errors will be logged.', 'vivio-swift'); ?></span>
                            </td>
                        </tr>
                        <tr valign="top" id="log_level_info_row">
                            <th></th>
                            <td>
                                <table class="widefat">
                                    <tr valign="top">
                                        <td width="10%">DEBUG</td>
                                        <td width="90%"><?php _e('intended to be used by devs for information needed for development', 'vivio-swift')?></td>
                                    </tr>
                                    <tr valign="top">
                                        <td>STATUS</td>
                                        <td><?php _e('logs when/where things happen within the plugin', 'vivio-swift')?></td>
                                    </tr>
                                    <tr valign="top">
                                        <td>NOTICE</td>
                                        <td><?php _e('logs when things do/don\'t happen for specific reasons', 'vivio-swift')?></td>
                                    </tr>
                                    <tr valign="top">
                                        <td>WARNING</td>
                                        <td><?php _e('logs non-blocking errors (like when a variable isn\'t created yet)', 'vivio-swift')?></td>
                                    </tr>
                                    <tr valign="top">
                                        <td>FAILURE</td>
                                        <td><?php _e('logs function-blocking errors (may or may not be blocking)', 'vivio-swift')?></td>
                                    </tr>
                                    <tr valign="top">
                                        <td>CRITICAL</td>
                                        <td><?php _e('logs blocking errors that prevent functionality', 'vivio-swift')?></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
Jordan Michaels's avatar
Jordan Michaels committed
618
                    </table>
Jordan Michaels's avatar
Jordan Michaels committed
619
                    <input type="submit" name="vivio_swift_save_debug_settings" value="<?php _e('Save Settings', 'vivio-swift')?>" class="pure-button" />
Jordan Michaels's avatar
Jordan Michaels committed
620 621
                </form>
            </div>
Jordan Michaels's avatar
Jordan Michaels committed
622
        </div>
Jordan Michaels's avatar
Jordan Michaels committed
623

Jordan Michaels's avatar
Jordan Michaels committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
        <?php /*
        <!-- view logs option -->
        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('View Logs for the Vivio Swift Plugin', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
                <form action=""
                    id="vivio_swift_dashboard_logs"
                    method="POST">
                    <?php wp_nonce_field('vivio-swift-logs-nonce'); ?>
                    <table class="form-table">
                        <tr valign="top">
                            <th scope="row"><?php _e('Log File', 'vivio-swift')?>:</th>
                            <td>
                                <select id="vivio_swift_log_file" name="vivio_swift_log_file">
                                    <option
                                        value=""><?php _e('--Select a file--', 'vivio-swift')?></option>
                                    <option
                                        value="vivio-swift-log.txt" <?php selected($file_selected, 'vivio-swift-log.txt'); ?>>
                                        vivio-swift-log
                                    </option>
                                    <option
                                        value="vivio-swift-log-cron-job.txt" <?php selected($file_selected, 'vivio-swift-log-cron-job.txt'); ?>>
                                        vivio-swift-log-cron-job
                                    </option>
                                </select>
                                <span class="description"><?php _e('Select one of the log files to view the contents', 'vivio-swift'); ?></span>
                            </td>
                        </tr>
                    </table>
                    <input type="submit" name="vivio_swift_view_logs"
                           value="<?php _e('View Logs', 'vivio-swift')?>"
                           class="pure-button"/>
                </form>
Jordan Michaels's avatar
Jordan Michaels committed
660
            </div>
Jordan Michaels's avatar
Jordan Michaels committed
661 662
        </div>
        ?>
Jordan Michaels's avatar
Jordan Michaels committed
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
        <?php
        if (isset($_POST['vivio_swift_view_logs']) && $file_selected)//Do form submission tasks
        {
            //Check nonce before doing anything
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio-swift-logs-nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Nonce check failed while attempting to view logs.", 4);
                wp_die("Error: Nonce check failed while attempting to view logs.");
            }

            //Let's make sure that the file selected can only ever be the correct log file of this plugin.
            $vivio_swift_valid_log_files = array('vivio-swift-log.txt', 'vivio-swift-log-cron-job.txt');
            if(!in_array($file_selected, $vivio_swift_valid_log_files)){
                $file_selected = '';
                unset($_POST['vivio_swift_view_logs']);
                wp_die(__('Error: The selected file is not a Vivio Swift log file.','vivio-swift'));
            }
Jordan Michaels's avatar
Jordan Michaels committed
680 681
            */

Jordan Michaels's avatar
Jordan Michaels committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
            if (!empty($file_selected)) {
                ?>
                <div class="postbox">
                    <h3 class="hndle"><label
                            for="title"><?php echo __('Log File Contents For', 'vivio-swift') . ': ' . $file_selected;?></label>
                    </h3>

                    <div class="inside">
                        <?php
                        $vivio_swift_log_dir = VIVIO_SWIFT_PATH . '/logs';
                        $log_file = $vivio_swift_log_dir . '/' . $file_selected;
                        if (file_exists($log_file)) {
                            $log_contents = Vivio_Swift_Utility_File::get_file_contents($log_file);
                        } else {
                            $log_contents = '';
                        }

                        if (empty($log_contents)) {
                            $log_contents = $file_selected . ': ' . __('Log file is empty!', 'vivio-swift');
                        }
                        ?>
Jordan Michaels's avatar
Jordan Michaels committed
703 704 705 706 707 708 709 710 711 712
                        <textarea class="text_area_file_output width_full margin_10_0" rows="20" readonly><?php echo esc_textarea($log_contents); ?></textarea>
                        <form action=""
                            id="vivio_swift_reset_logs_form"
                            method="POST"
                            onsubmit="return confirm('<?php _e('Are you sure you want to reset the logs? This cannot be undone.', 'vivio-swift')?>');">
                            <?php wp_nonce_field('vivio_swift_reset_logs_nonce'); ?>
                        <input type="submit" name="vivio_swift_reset_logs"
                           value="<?php _e('Reset Logs', 'vivio-swift')?>"
                           class="pure-button button-error" />
                        </form>
Jordan Michaels's avatar
Jordan Michaels committed
713 714 715 716 717 718
                    </div>
                </div>

            <?php

            }
Jordan Michaels's avatar
Jordan Michaels committed
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
        // }
    }

    function render_tab4()
    {
        echo '<div class="message_standard">';
        echo '<p>' . __('This page shows you your current cookies. This can be helpful when testing your \'Exclude Cookie\' rules.', 'vivio-swift') . '</p>';
        echo '</div>';

        global $vivio_swift_global;

        if(isset($_POST['vivio_swift_delete_cookie']))
        {
            $error = '';

            // verify nonce
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio_swift_cookie_viewer_nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Nonce check failed on cookie viewer.", 4);
                wp_die("Error: Nonce check failed on cookie viewer.");
            }
            
            foreach ((array)$_COOKIE as $cookie_key => $cookie_value){
                if($_REQUEST['vivio_swift_delete_cookie']==sanitize_text_field($cookie_key)){
                    setcookie($cookie_key, "", time()-3600);
                }
            }
Jordan Michaels's avatar
Jordan Michaels committed
746
        }
Jordan Michaels's avatar
Jordan Michaels committed
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
        
        ?>

        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('Cookie Viewer', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
                <form action="" method="POST">
                    <?php wp_nonce_field('vivio_swift_cookie_viewer_nonce'); ?>    
                    <table class="widefat">
                        <thead>
                            <tr>
                                <th><?php _e('Cookie Name (sanitized)', 'vivio-swift') ?></th>
                                <!-- <th><?php _e('Delete', 'vivio-swift') ?></th> -->
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            foreach ((array)$_COOKIE as $cookie_key => $cookie_value){
                                echo '<tr>';
                                echo '<td class="pattern_cell">' . sanitize_text_field($cookie_key) . "</td>";
                                //echo '<td class="action_cell"><button name="vivio_swift_delete_cookie" class="pure-button button-error" type="submit"';
                                //echo 'value="'.sanitize_text_field($cookie_key).'"';
                                //echo '>';
                                //echo '<span class="dashicons dashicons-no"></span></button></td>';
                                echo '</tr>';
                            }
                            ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th><?php _e('Cookie Name (sanitized)', 'vivio-swift') ?></th>
                                <!-- <th><?php _e('Delete', 'vivio-swift') ?></th> -->
                            </tr>
                        </tfoot>
                    </table>
                </form>
            </div>
        </div>
    <?php
    }

    function render_tab5()
    {

        global $vivio_swift_global;

        echo '<div class="message_standard">';
        echo '<p>' . __('This page displays what Vivio Swift is writing to your .htaccess file. This can be helpful to ensure your rules are doing what you expect.', 'vivio-swift') . '</p>';
        echo '</div>';

        ?>

        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('.htaccess File Viewer', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
                <textarea class="text_area_file_output width_full margin_10_0" rows="20" readonly><?php
                $htaccess_contents = Vivio_Swift_Utility_Htaccess::display_htaccess();

                if (empty($htaccess_contents)){
                    echo __('Vivio Swift has nothing to write to .htaccess', 'vivio-swift');
                } else {
                    echo $htaccess_contents;
                }
                ?></textarea>
                <?php echo ABSPATH . '.htaccess' ?>
            </div>
        </div>
    <?php
    }

    function render_tab6()
    {
    
        echo '<div class="message_error">';
        echo '<p>' . __('WARNING: Performing a system reset on the Vivio Swift plugin will clear all caches, clear all logs, and reset all of Vivio Swift\'s settings back to their defaults.', 'vivio-swift') . '</p>';
        echo '</div>';

        global $vivio_swift_global;

        if (isset($_POST['vivio_swift_system_reset']))//Do form submission tasks
        {
            error_log('[Vivio Swift] System reset called...');
            //Check nonce before doing anything
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'vivio_swift_system_reset_nonce')) {
                $vivio_swift_global->debug_logger->log_debug("Nonce check failed on system reset.", 4);
                wp_die("Error: Nonce check failed on system reset.");
            }

            // reset options
            Vivio_Swift_Config_Settings::reset_to_defaults();
            // clear cache directory
            Vivio_Swift_Utility_File::clear_cache_dir();
            // reset .htaccess
            Vivio_Swift_Utility_Htaccess::delete_from_htaccess();
            Vivio_Swift_Utility_Htaccess::write_to_htaccess();
            // reset logs
            $vivio_swift_global->debug_logger->reset_log_file('1');
            $vivio_swift_global->debug_logger->reset_log_file('2');//cron

            $this->show_msg_settings_updated();
        }

        ?>

        <div class="postbox">
            <h3 class="hndle">
                <label for="title"><?php _e('Perform System Reset', 'vivio-swift');?></label>
            </h3>

            <div class="inside">
                <form action=""
                    id="vivio_swift_system_reset_form"
                    method="POST"
                    onsubmit="return confirm('<?php _e('Are you absolutely sure you want to perform a system reset?', 'vivio-swift')?>');">
                    <?php wp_nonce_field('vivio_swift_system_reset_nonce'); ?>
                <input type="submit" name="vivio_swift_system_reset"
                   value="<?php _e('System Reset', 'vivio-swift')?>"
                   class="pure-button button-error" />
                </form>
            </div>
        </div>
    <?php
Jordan Michaels's avatar
Jordan Michaels committed
876 877 878
    }

} //end class