PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.3.2
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.3.2
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Frontend / Frontend.php

Frontend.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.3.2, at src/Frontend/Frontend.php

216 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ThemeAtelier\Darkify\Frontend;
4
5 use ThemeAtelier\Darkify\Helpers\DarkifyExternalSupport;
6 use ThemeAtelier\Darkify\Helpers\DarkifyUtils;
7 use ThemeAtelier\Darkify\Helpers\Helpers;
8
9 /**
10 * The public-facing functionality of the plugin.
11 *
12 * @link https://themeatelier.net
13 * @since 1.0.0
14 *
15 * @package Darkify
16 * @subpackage Darkify/public
17 */
18
19 /**
20 * The public-facing functionality of the plugin.
21 *
22 * Defines the plugin name, version, and two examples hooks for how to
23 * enqueue the public-facing stylesheet and JavaScript.
24 *
25 * @package Darkify
26 * @subpackage Darkify/public
27 * @author ThemeAtelier <themeatelierbd@gmail.com>
28 */
29 class Frontend
30 {
31
32 /**
33 * The ID of this plugin.
34 *
35 * @since 1.0.0
36 * @access private
37 * @var string $plugin_name The ID of this plugin.
38 */
39 private $plugin_name;
40
41 /**
42 * The version of this plugin.
43 *
44 * @since 1.0.0
45 * @access private
46 * @var string $version The current version of this plugin.
47 */
48 private $version;
49
50 public $utils;
51 public $settings;
52 public $external_support;
53 public $unique_id;
54
55 /**
56 * Initialize the class and set its properties.
57 *
58 * @since 1.0.0
59 * @param string $plugin_name The name of the plugin.
60 * @param string $version The version of this plugin.
61 */
62 public function __construct($plugin_name, $version)
63 {
64 $this->plugin_name = $plugin_name;
65 $this->version = $version;
66
67 $this->utils = new DarkifyUtils($this);
68 $this->external_support = new DarkifyExternalSupport($this);
69
70 new DarkifyShortcode($this);
71
72 if (function_exists('wp_rand')) {
73 $this->unique_id = wp_rand();
74 }
75
76 $options = get_option('darkify');
77 $show_in_menu = isset($options['show_in_menu']) ? $options['show_in_menu'] : "";
78 $enable_switcher_in_menu = isset($show_in_menu["enable_switch_in_menu"]) ? $show_in_menu["enable_switch_in_menu"] : false;
79
80 if ($enable_switcher_in_menu) {
81 add_filter('wp_nav_menu_items', array($this, 'darkify_switch_in_menu'), 10, 2);
82 }
83
84 add_action('wp_enqueue_scripts', array($this, 'darkify_client_enqueue'));
85 add_action('login_enqueue_scripts', array($this, 'darkify_client_enqueue'));
86 add_action('register_enqueue_scripts', array($this, 'darkify_client_enqueue'));
87 add_action('wp_head', array($this, 'darkify_client_header_script'), 1);
88 add_action('login_head', array($this, 'darkify_client_header_script'), 1);
89 add_action('register_head', array($this, 'darkify_client_header_script'), 1);
90 add_action('wp_footer', array($this, 'darkify_client_footer_script'));
91 add_action('login_footer', array($this, 'darkify_client_footer_script'));
92 add_action('register_footer', array($this, 'darkify_client_footer_script'));
93 }
94
95
96 public function darkify_client_enqueue()
97 {
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'];
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'] : "";
123
124
125
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);
142
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);
167 }
168 }
169 public function darkify_is_dark_mode_allowed()
170 {
171 $options = get_option('darkify');
172 /* Disable if Oxygen Builder is Opened */
173 if (isset($_GET['ct_builder'])) {
174 if ($_GET['ct_builder'] == "true") {
175 if (!isset($_GET['oxygen_iframe'])) {
176 return False;
177 }
178 }
179 }
180
181 return True;
182 }
183
184
185 public function darkify_client_header_script()
186 {
187 if ($this->darkify_is_dark_mode_allowed()) {
188 include_once Helpers::darkify_locate_template('header_script.php');
189 }
190 }
191
192 public function darkify_client_footer_script()
193 {
194 if ($this->darkify_is_dark_mode_allowed()) {
195 include_once Helpers::darkify_locate_template('footer_script.php');
196 }
197 }
198
199 public function darkify_switch_in_menu($items, $args)
200 {
201 $options = get_option('darkify');
202 $show_in_menu = $options['show_in_menu'];
203 $switch_in_menu_location = $show_in_menu['switch_in_menu_location'];
204 $darkify_menu_shortcode_helper = $show_in_menu['darkify_menu_shortcode_helper'];
205
206 if ($this->darkify_is_dark_mode_allowed()) {
207 if (isset($args->menu->term_id)) {
208 if ($args->menu->term_id == $switch_in_menu_location) {
209 $items .= '<li class="menu-item">' . do_shortcode($darkify_menu_shortcode_helper) . '</li>';
210 }
211 }
212 }
213 return $items;
214 }
215 }
216