| @@ -1,15 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ThemeAtelier\Darkify\Frontend; |
| 4 | 4 | |
| 5 | -use ThemeAtelier\Darkify\Includes\DarkifyExternalSupport; | |
| 6 | -use ThemeAtelier\Darkify\Includes\DarkifyUtils; | |
| 5 | +use ThemeAtelier\Darkify\Helpers\DarkifyExternalSupport; | |
| 6 | +use ThemeAtelier\Darkify\Helpers\DarkifyUtils; | |
| 7 | +use ThemeAtelier\Darkify\Helpers\Helpers; | |
| 7 | 8 | |
| 8 | -if (!defined('ABSPATH')) { | |
| 9 | - die; | |
| 10 | -} // Cannot access directly. | |
| 11 | - | |
| 12 | 9 | /** |
| 13 | 10 | * The public-facing functionality of the plugin. |
| 14 | 11 | * |
| 15 | 12 | * @link https://themeatelier.net |
| @@ -83,9 +80,9 @@ | ||
| 83 | 80 | if ($enable_switcher_in_menu) { |
| 84 | 81 | add_filter('wp_nav_menu_items', array($this, 'darkify_switch_in_menu'), 10, 2); |
| 85 | 82 | } |
| 86 | 83 | |
| 87 | - add_action('wp_enqueue_scripts', array($this, 'darkify_client_enqueue'), 100); | |
| 84 | + add_action('wp_enqueue_scripts', array($this, 'darkify_client_enqueue')); | |
| 88 | 85 | add_action('login_enqueue_scripts', array($this, 'darkify_client_enqueue')); |
| 89 | 86 | add_action('register_enqueue_scripts', array($this, 'darkify_client_enqueue')); |
| 90 | 87 | add_action('wp_head', array($this, 'darkify_client_header_script'), 1); |
| 91 | 88 | add_action('login_head', array($this, 'darkify_client_header_script'), 1); |
| @@ -92,49 +89,82 @@ | ||
| 92 | 89 | add_action('register_head', array($this, 'darkify_client_header_script'), 1); |
| 93 | 90 | add_action('wp_footer', array($this, 'darkify_client_footer_script')); |
| 94 | 91 | add_action('login_footer', array($this, 'darkify_client_footer_script')); |
| 95 | 92 | add_action('register_footer', array($this, 'darkify_client_footer_script')); |
| 96 | - | |
| 97 | - add_filter('autoptimize_filter_js_exclude', array($this, 'darkify_exclude_js_from_cache_plugins')); | |
| 98 | 93 | } |
| 99 | 94 | |
| 100 | 95 | |
| 101 | - public function darkify_exclude_js_from_cache_plugins($excludes) | |
| 96 | + public function darkify_client_enqueue() | |
| 102 | 97 | { |
| 103 | - $excludes .= ',client_main.js,client_main.min.js'; | |
| 104 | - return $excludes; | |
| 105 | - } | |
| 98 | + if ($this->darkify_is_dark_mode_allowed()) { | |
| 99 | + $options = get_option('darkify'); | |
| 100 | + $enable_dark_switcher = $options['enable_dark_switcher']; | |
| 101 | + $enable_time = $options['enable_time']; | |
| 106 | 102 | |
| 103 | + $enable_default_dark_mode = $options['enable_default_dark_mode']; | |
| 104 | + $enable_time = $options['enable_time']; | |
| 105 | + $enable_time_based_dark = isset($enable_time['enable_time_based_dark']) ? $enable_time['enable_time_based_dark'] : ""; | |
| 106 | + $time_based_dark_start = isset($enable_time['time_based_dark_start']['from']) ? $enable_time['time_based_dark_start']['from'] : ""; | |
| 107 | + $time_based_dark_stop = isset($enable_time['time_based_dark_start']['to']) ? $enable_time['time_based_dark_start']['to'] : ""; | |
| 108 | + $grayscale = $options['brightness']; | |
| 109 | + $enable_low_image_brightness = isset($grayscale['enable_low_image_brightness']) ? $grayscale['enable_low_image_brightness'] : ""; | |
| 110 | + $low_image_brightness_label = isset($grayscale['low_image_brightness_label']) ? $grayscale['low_image_brightness_label'] : ""; | |
| 111 | + $grayscale = isset($options['grayscale']); | |
| 112 | + $enable_image_grayscale = isset($grayscale['enable_image_grayscale']) ? $grayscale['enable_image_grayscale'] : ""; | |
| 113 | + $image_grayscale_label = isset($grayscale['image_grayscale_label']) ? $grayscale['image_grayscale_label'] : ""; | |
| 114 | + $disallowed_low_grayscale_images = isset($grayscale['disallowed_low_grayscale_images']) ? $grayscale['disallowed_low_grayscale_images'] : ""; | |
| 115 | + $darken_background = isset($options['darken_background']); | |
| 116 | + $enable_low_image_darken = isset($darken_background['enable_low_image_darken']) ? $darken_background['enable_low_image_darken'] : ""; | |
| 117 | + $low_image_darken_label = isset($darken_background['low_image_darken_label']) ? $darken_background['low_image_darken_label'] : ""; | |
| 118 | + $video_brightness = isset($options['video_brightness']); | |
| 119 | + $enable_low_video_brightness = isset($video_brightness['enable_low_video_brightness']) ? $video_brightness['enable_low_video_brightness'] : ""; | |
| 120 | + $low_video_brightness_label = isset($video_brightness['low_video_brightness_label']) ? $video_brightness['low_video_brightness_label'] : ""; | |
| 121 | + $video_grayscale = isset($options['video_grayscale']); | |
| 122 | + $enable_video_grayscale = isset($video_grayscale['enable_video_grayscale']) ? $video_grayscale['enable_video_grayscale'] : ""; | |
| 107 | 123 | |
| 108 | - function darkify_client_enqueue() | |
| 109 | - { | |
| 110 | - if ($this->darkify_is_dark_mode_allowed()) { | |
| 111 | 124 | |
| 112 | - $options = get_option('darkify'); | |
| 113 | - $enable_dark_switcher = isset($options['enable_dark_switcher']) ? $options['enable_dark_switcher'] : 'classic'; | |
| 114 | - $min = (apply_filters('darkify_dev_mode', false) || WP_DEBUG) ? '' : '.min'; | |
| 115 | - wp_enqueue_style('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/css/client_main' . $min . '.css', array(), DARKIFY_VERSION); | |
| 116 | 125 | |
| 117 | - // wp_enqueue_style("theme-{$enable_dark_switcher}", DARKIFY_DIR_URL . 'src/assets/css/switcher/' . $enable_dark_switcher . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); | |
| 126 | + wp_enqueue_style("theme-{$enable_dark_switcher}", DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/$enable_dark_switcher.css", array(), DARKIFY_VERSION, 'all'); | |
| 127 | + wp_register_style('theme-around', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/around.css", array(), DARKIFY_VERSION, 'all'); | |
| 128 | + wp_register_style('theme-classic', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/classic.css", array(), DARKIFY_VERSION, 'all'); | |
| 129 | + wp_register_style('theme-dark-inner', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/dark-inner.css", array(), DARKIFY_VERSION, 'all'); | |
| 130 | + wp_register_style('theme-dark-side', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/dark-side.css", array(), DARKIFY_VERSION, 'all'); | |
| 131 | + wp_register_style('theme-eclipse', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/eclipse.css", array(), DARKIFY_VERSION, 'all'); | |
| 132 | + wp_register_style('theme-expand', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/expand.css", array(), DARKIFY_VERSION, 'all'); | |
| 133 | + wp_register_style('theme-half-sun', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/half-sun.css", array(), DARKIFY_VERSION, 'all'); | |
| 134 | + wp_register_style('theme-horizon', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/horizon.css", array(), DARKIFY_VERSION, 'all'); | |
| 135 | + wp_register_style('theme-inner-moon', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/inner-moon.css", array(), DARKIFY_VERSION, 'all'); | |
| 136 | + wp_register_style('theme-lightbulb', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/lightbulb.css", array(), DARKIFY_VERSION, 'all'); | |
| 137 | + wp_register_style('theme-simple', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/simple.css", array(), DARKIFY_VERSION, 'all'); | |
| 138 | + wp_register_style('theme-within', DARKIFY_DIR_URL . "src/Frontend/assets/css/switcher/within.css", array(), DARKIFY_VERSION, 'all'); | |
| 139 | + wp_enqueue_style('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/css/client_main.css', array(), DARKIFY_VERSION); | |
| 140 | + wp_enqueue_style('ico-font', DARKIFY_DIR_URL . 'src/assets/css/icofont.css', array(), DARKIFY_VERSION); | |
| 141 | + wp_enqueue_script('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main.js', array('jquery'), DARKIFY_VERSION); | |
| 118 | 142 | |
| 119 | - wp_register_style('theme-around', DARKIFY_DIR_URL . 'src/assets/css/switcher/around' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); | |
| 120 | - wp_register_style('theme-classic', DARKIFY_DIR_URL . 'src/assets/css/switcher/classic' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); | |
| 121 | - wp_register_style('theme-dark-inner', DARKIFY_DIR_URL . 'src/assets/css/switcher/dark-inner' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 122 | - wp_register_style('theme-dark-side', DARKIFY_DIR_URL . 'src/assets/css/switcher/dark-side' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 123 | - wp_register_style('theme-eclipse', DARKIFY_DIR_URL . 'src/assets/css/switcher/eclipse' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 124 | - wp_register_style('theme-expand', DARKIFY_DIR_URL . 'src/assets/css/switcher/expand' . $min . '.css', array('darkify-client-main'), DARKIFY_VERSION, 'all'); | |
| 125 | - wp_register_style('theme-half-sun', DARKIFY_DIR_URL . 'src/assets/css/switcher/half-sun' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 126 | - wp_register_style('theme-horizon', DARKIFY_DIR_URL . 'src/assets/css/switcher/horizon' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 127 | - wp_register_style('theme-inner-moon', DARKIFY_DIR_URL . 'src/assets/css/switcher/inner-moon' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 128 | - wp_register_style('theme-lightbulb', DARKIFY_DIR_URL . 'src/assets/css/switcher/lightbulb' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 129 | - wp_register_style('theme-simple', DARKIFY_DIR_URL . 'src/assets/css/switcher/simple' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 130 | - wp_register_style('theme-orbit', DARKIFY_DIR_URL . 'src/assets/css/switcher/orbit' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 131 | - wp_register_style('theme-duality', DARKIFY_DIR_URL . 'src/assets/css/switcher/duality' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 132 | - wp_register_style('theme-dual', DARKIFY_DIR_URL . 'src/assets/css/switcher/dual' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 133 | - wp_register_style('theme-shift', DARKIFY_DIR_URL . 'src/assets/css/switcher/shift' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 134 | - wp_register_style('theme-within', DARKIFY_DIR_URL . 'src/assets/css/switcher/within' . $min . '.css', array(), DARKIFY_VERSION, 'all'); | |
| 135 | - | |
| 136 | - wp_enqueue_script('darkify-client-main', DARKIFY_DIR_URL . 'src/assets/js/client_main' . $min . '.js', array('jquery'), DARKIFY_VERSION); | |
| 143 | + $darkify_data = array( | |
| 144 | + 'darkify_switch_unique_id' => $this->unique_id, | |
| 145 | + 'darkify_is_this_admin_panel' => is_admin() ? "1" : "0", | |
| 146 | + 'darkify_enable_default_dark_mode' => $enable_default_dark_mode, | |
| 147 | + 'darkify_enable_os_aware' => $options["enable_os_aware"], | |
| 148 | + 'darkify_enable_keyboard_shortcut' => $options["enable_keyboard_shortcut"], | |
| 149 | + 'darkify_enable_time_based_dark' => $enable_time_based_dark, | |
| 150 | + 'darkify_time_based_dark_start' => $time_based_dark_start ? $time_based_dark_start : "19:00", | |
| 151 | + 'darkify_time_based_dark_stop' => $time_based_dark_stop ? $time_based_dark_stop : "07:00", | |
| 152 | + 'darkify_alternative_dark_mode_switch' => $options["alternative_dark_mode_switcher"], | |
| 153 | + 'darkify_enable_low_image_brightness' => $enable_low_image_brightness, | |
| 154 | + 'darkify_image_brightness_to' => $low_image_brightness_label, | |
| 155 | + 'darkify_enable_image_grayscale' => $enable_image_grayscale, | |
| 156 | + 'darkify_image_grayscale_to' => $image_grayscale_label, | |
| 157 | + 'darkify_disallowed_grayscale_images' => $disallowed_low_grayscale_images, | |
| 158 | + 'darkify_enable_bg_image_darken' => $enable_low_image_darken, | |
| 159 | + 'darkify_bg_image_darken_to' => $low_image_darken_label, | |
| 160 | + 'darkify_enable_invert_inline_svg' => $options["enable_invert_inline_svg"], | |
| 161 | + 'darkify_enable_low_video_brightness' => $enable_low_video_brightness, | |
| 162 | + 'darkify_video_brightness_to' => $low_video_brightness_label, | |
| 163 | + 'darkify_enable_video_grayscale' => $enable_video_grayscale, | |
| 164 | + // Add more variables as needed... | |
| 165 | + ); | |
| 166 | + wp_localize_script('darkify-client-main', 'darkify_data', $darkify_data); | |
| 137 | 167 | } |
| 138 | 168 | } |
| 139 | 169 | public function darkify_is_dark_mode_allowed() |
| 140 | 170 | { |
| @@ -154,9 +184,9 @@ | ||
| 154 | 184 | |
| 155 | 185 | public function darkify_client_header_script() |
| 156 | 186 | { |
| 157 | 187 | if ($this->darkify_is_dark_mode_allowed()) { |
| 158 | - include_once DarkifyUtils::darkify_locate_template('header_script.php'); | |
| 188 | + include_once Helpers::darkify_locate_template('header_script.php'); | |
| 159 | 189 | } |
| 160 | 190 | } |
| 161 | 191 | |
| 162 | 192 | public function darkify_client_footer_script() |
| @@ -161,34 +191,25 @@ | ||
| 161 | 191 | |
| 162 | 192 | public function darkify_client_footer_script() |
| 163 | 193 | { |
| 164 | 194 | if ($this->darkify_is_dark_mode_allowed()) { |
| 165 | - include_once DarkifyUtils::darkify_locate_template('footer_script.php'); | |
| 195 | + include_once Helpers::darkify_locate_template('footer_script.php'); | |
| 166 | 196 | } |
| 167 | 197 | } |
| 168 | 198 | |
| 169 | - function darkify_switch_in_menu($items, $args) | |
| 199 | + public function darkify_switch_in_menu($items, $args) | |
| 170 | 200 | { |
| 171 | 201 | $options = get_option('darkify'); |
| 172 | 202 | $show_in_menu = $options['show_in_menu']; |
| 173 | - $select_menus = isset($show_in_menu['select_menus']) ? $show_in_menu['select_menus'] : []; | |
| 203 | + $switch_in_menu_location = $show_in_menu['switch_in_menu_location']; | |
| 204 | + $darkify_menu_shortcode_helper = $show_in_menu['darkify_menu_shortcode_helper']; | |
| 174 | 205 | |
| 175 | - $last_shortcode = ''; | |
| 176 | - | |
| 177 | - if ($this->darkify_is_dark_mode_allowed() && isset($args->menu->term_id)) { | |
| 178 | - foreach ($select_menus as $select_menu) { | |
| 179 | - | |
| 180 | - $switch_in_menu_location = $select_menu['switch_in_menu_location'] ?? ''; | |
| 181 | - $darkify_menu_shortcode_helper = $select_menu['darkify_menu_shortcode_helper'] ?? ''; | |
| 182 | - $menu_position = isset($select_menu['select_menu_position']) ? $select_menu['select_menu_position'] : 'after'; | |
| 206 | + if ($this->darkify_is_dark_mode_allowed()) { | |
| 207 | + if (isset($args->menu->term_id)) { | |
| 183 | 208 | if ($args->menu->term_id == $switch_in_menu_location) { |
| 184 | - $last_shortcode = $darkify_menu_shortcode_helper; | |
| 209 | + $items .= '<li class="menu-item">' . do_shortcode($darkify_menu_shortcode_helper) . '</li>'; | |
| 185 | 210 | } |
| 186 | 211 | } |
| 187 | - if ($last_shortcode) { | |
| 188 | - $items = ($menu_position == 'before') ? '<li class="menu-item">' . do_shortcode($last_shortcode) . '</li>' . $items : $items . '<li class="menu-item">' . do_shortcode($last_shortcode) . '</li>'; | |
| 189 | - } | |
| 190 | 212 | } |
| 191 | - | |
| 192 | 213 | return $items; |
| 193 | 214 | } |
| 194 | 215 | } |