<?php
/**
 * Clearfy quick start options
 *
 * @author Alex Kovalev <alex.kovalevv@gmail.com>
 * @copyright (c) 03.06.2020, Webcraftic
 * @version 1.0
 */

add_filter("wbcr_clearfy_group_options", function ($options) {
	$options[] = array(
		'name' => 'enable_cache',
		'title' => __('Enable cache', 'clearfy'),
		'tags' => array('optimize_performance')
	);

	$options[] = array(
		'name' => 'dont_cache_for_logged_in_users',
		'title' => __('Don\'t cache for logged-in users', 'clearfy'),
		'tags' => array('optimize_performance')
	);

	$options[] = array(
		'name' => 'gzip',
		'title' => __('Gzip', 'clearfy'),
		'tags' => array('optimize_performance')
	);

	$options[] = array(
		'name' => 'browser_caching',
		'title' => __('Browser Caching', 'clearfy'),
		'tags' => array('optimize_performance')
	);

	$options[] = array(
		'name' => 'cache_reject_uri',
		'title' => __('Never Cache URL(s)', 'clearfy'),
		'tags' => array()
	);

	$options[] = array(
		'name' => 'cache_mobile',
		'title' => __('Mobile', 'clearfy'),
		'tags' => array()
	);

	$options[] = array(
		'name' => 'cache_mobile_theme',
		'title' => __('Create cache for mobile theme', 'clearfy'),
		'tags' => array()
	);

	$options[] = array(
		'name' => 'widget_cache',
		'title' => __('Widget Cache', 'clearfy'),
		'tags' => array('optimize_performance')
	);

	$options[] = array(
		'name' => 'preload_cache',
		'title' => __('Preload cache', 'clearfy'),
		'tags' => array()
	);

	$options[] = array(
		'name' => 'clear_cache_for_newpost',
		'title' => __('Clear cache for new post', 'clearfy'),
		'tags' => array('optimize_performance')
	);

	$options[] = array(
		'name' => 'exclude_files',
		'title' => __('Filenames that can be cached', 'clearfy'),
		'tags' => array()
	);

	$options[] = array(
		'name' => 'exclude_pages',
		'title' => __('Rejected User Agents', 'clearfy'),
		'tags' => array()
	);

	return $options;
});

add_filter('wclearfy/setup_wizard/speed_optimize_step/form_options', function ($options) {
	array_unshift($options, [
		'type' => 'checkbox',
		'way' => 'buttons',
		'name' => 'enable_cache',
		'title' => __('Enable cache', 'clearfy'),
		'layout' => ['hint-type' => 'icon', 'hint-icon-color' => 'green'],
		'hint' => __('This option enable cache to generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.', 'clearfy'),
		'default' => true
	], [
		'type' => 'checkbox',
		'way' => 'buttons',
		'name' => 'gzip',
		'title' => __('Gzip', 'clearfy'),
		'layout' => ['hint-type' => 'icon', 'hint-icon-color' => 'green'],
		'hint' => __('Reduce the size of page decrease the page load time a lot. You can reduce the size of page with GZIP compression feature.

If the size of requested files are big, loading takes time so in this case there is needed to reduce the size of files. Gzip Compression feature compresses the pages and resources before sending so the transfer time is reduced.', 'clearfy'),
		'default' => false
	], [
		'type' => 'checkbox',
		'way' => 'buttons',
		'name' => 'browser_caching',
		'title' => __('Browser Caching', 'clearfy'),
		'layout' => ['hint-type' => 'icon', 'hint-icon-color' => 'green'],
		'hint' => __('Reduce the load times of pages by storing commonly used files from your website on your visitors browser.

A browser loads the css, js, images resources to display the web page to the visitors. This process is always performed.

If the commonly used files are cached by browser, the visitors’ browsers do not have to load them evert time so the load times of pages are reduced.', 'clearfy'),
		'default' => false
	]);

	return $options;
});

add_action('wclearfy/setup_wizard/speed_optimize_step/continue_step', function () {
	require_once WCLEARFY_CACHEPRO_PLUGIN_DIR . '/includes/includes/helpers.php';
	try {
		\WCL_Cache_Helpers::modifyHtaccess();
	} catch( \Exception $e ) {

	}
});

add_action('wfactory/activated_' . WCL_Plugin::app()->getPluginName() . '_component', function ($component_name) {
	//todo: Проверить совместимость с плагинами, включить или отключить компонент в зависимсти от результатов
});