PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 2.0.3
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v2.0.3
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 / Templates / footer_script.php

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

230 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ThemeAtelier\Darkify\Includes\DarkifyUtils;
4
5 // don't call the file directly.
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 $options = get_option('darkify');
11 $enable_dark_mode_switch = isset($options["enable_dark_mode_switch"]) ? $options["enable_dark_mode_switch"] : true;
12 $hide_on_desktop = isset($options["hide_on_desktop"]) ? $options["hide_on_desktop"] : '';
13 $hide_on_mobile = isset($options["hide_on_mobile"]) ? $options["hide_on_mobile"] : '';
14 $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : '';
15 $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false;
16 $hide_dark_mode_on_mobile = isset($hide_on_mobile["hide_dark_mode_on_mobile"]) ? $hide_on_mobile["hide_dark_mode_on_mobile"] : 0;
17 $type_of_hide_by = isset($hide_on_mobile["type_of_hide_by"]) ? $hide_on_mobile["type_of_hide_by"] : 0;
18
19 $normal_custom_css = isset($options["normal_custom_css"]) ? $options["normal_custom_css"] : "";
20 $custom_css = isset($options["custom_css"]) ? $options["custom_css"] : "";
21 $admin_custom_css = isset($options['admin_custom_css']) ? $options['admin_custom_css'] : "";
22
23 if (!is_admin()) {
24 if ($enable_dark_mode_switch) {
25 if (!$this->utils->is_hidden_by_user_agent($hide_on_desktop, $hide_dark_mode_on_mobile, $type_of_hide_by)) {
26 include_once DarkifyUtils::darkify_locate_template('views/switch.php');
27 }
28 }
29 }
30 ?>
31
32 <style type="text/css" class="darkify_inline_css">
33 <?php
34 // CSS body, not HTML: no core output-escaping function applies. The rules
35 // are assembled by parseAndProcessNormalCustomCSS() and wp_strip_all_tags()
36 // removes any tag-based `</style>` breakout, so the string is safe to print.
37 echo wp_strip_all_tags(DarkifyUtils::parseAndProcessNormalCustomCSS($normal_custom_css)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
38 ?>
39 </style>
40 <style type="text/css" class="darkify_inline_css">
41 <?php
42 echo wp_strip_all_tags(DarkifyUtils::parseAndProcessCustomCSS($custom_css, false)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
43 ?>
44 </style>
45
46 <?php if (!is_admin()) { ?>
47 <script type="text/javascript" class="darkify_inline_js">
48 document.addEventListener("DOMContentLoaded", function(event) {
49 darkify_init_alternative_dark_mode_switch();
50 darkify_init_attention_effect();
51 if (typeof darkify_init_draggable_floating_switch === "function") {
52 darkify_init_draggable_floating_switch();
53 }
54 });
55 </script>
56 <?php }
57
58 if (is_admin() && $block_editor_dark_mode) {
59 ?><style type="text/css" class="darkify_inline_css">
60 <?php echo esc_html(DarkifyUtils::parseAndProcessCustomCSS($admin_custom_css, 'yes')); ?>
61 </style>
62 <?php
63 /* Block editor dark switch — injected whenever Block Editor Dark Mode is on,
64 independently of Admin Panel Dark Mode. */
65 if (class_exists('WP_Block_Type_Registry')) {
66
67 if (get_current_screen() && 'post' === get_current_screen()->base && ('post' === get_current_screen()->post_type || 'page' === get_current_screen()->post_type)) { ?>
68 <script type="text/javascript" class="darkify_inline_js">
69 (function checkForWP() {
70 if (
71 typeof wp === 'undefined' ||
72 typeof wp.domReady === 'undefined' ||
73 typeof wp.plugins === 'undefined' ||
74 typeof wp.element === 'undefined'
75 ) {
76 return setTimeout(checkForWP, 200);
77 }
78
79 wp.domReady(function() {
80
81 function injectDarkify() {
82 // Target the LEFT side toolbar
83 const target =
84 document.querySelector('.editor-header__toolbar') ||
85 document.querySelector('.edit-post-header-toolbar') ||
86 document.querySelector('.editor-document-tools');
87
88 if (!target) return false;
89 if (target.querySelector('.darkify-dropdown')) return true;
90
91 const themes = [{
92 value: 'set1',
93 label: 'Carbon Mist',
94 cls: 'carbon_mist'
95 },
96 {
97 value: 'set3',
98 label: 'Midnight Reverie',
99 cls: 'midnight_reverie'
100 },
101 {
102 value: 'set9',
103 label: 'Verdant Depths',
104 cls: 'verdant_depths'
105 },
106 {
107 value: 'set6',
108 label: 'Celestial Tide',
109 cls: 'celestial_tide'
110 },
111 {
112 value: 'set10',
113 label: 'Emberwood',
114 cls: 'emberwood'
115 },
116 {
117 value: 'set2',
118 label: 'Glacier Drift',
119 cls: 'glacier_drift',
120 pro: true
121 },
122 {
123 value: 'set4',
124 label: 'Indigo Veil',
125 cls: 'indigo_veil',
126 pro: true
127 },
128 {
129 value: 'set5',
130 label: 'Duskmire',
131 cls: 'duskmire',
132 pro: true
133 },
134 {
135 value: 'set7',
136 label: 'Tidal Frost',
137 cls: 'tidal_frost',
138 pro: true
139 },
140 {
141 value: 'set8',
142 label: 'Blue Bastion',
143 cls: 'blue_bastion',
144 pro: true
145 },
146 {
147 value: 'set11',
148 label: 'Crimson Veil',
149 cls: 'crimson_veil',
150 pro: true
151 },
152 ];
153
154 // Dark mode toggle button
155 const button = document.createElement('button');
156 button.className = 'darkify_block_editor_switch darkify_ignore';
157 button.innerHTML = '<div class="icon"></div>';
158 button.onclick = function() {
159 darkify_switch_trigger();
160 };
161
162 // Dropdown wrapper
163 const wrapper = document.createElement('div');
164 wrapper.className = 'darkify-dropdown';
165 wrapper.style.cssText = 'position:relative;display:inline-flex;align-items:center;';
166
167 const selected = document.createElement('div');
168 selected.className = 'darkify-selected';
169
170 const list = document.createElement('div');
171 list.className = 'darkify-options';
172
173 themes.forEach(t => {
174 const item = document.createElement('div');
175 if (t.pro) {
176 item.className = 'darkify-option darkify-pro-option';
177 item.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}<span class="darkify-option-pro-badge">PRO</span>`;
178 item.title = 'Upgrade to Pro to unlock this theme';
179 } else {
180 item.className = 'darkify-option';
181 item.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}`;
182 item.onclick = () => {
183 selected.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}`;
184 localStorage.darkify_selected_theme = t.value;
185 darkify_theme_select(t.value);
186 list.classList.remove('show');
187 };
188 }
189 list.appendChild(item);
190 });
191
192 // Load saved theme — fall back to first free theme if saved value is pro-only
193 const savedVal = localStorage.darkify_selected_theme || 'set1';
194 const savedTheme = themes.find(t => t.value === savedVal && !t.pro) || themes[0];
195 selected.innerHTML = `<span class="theme_color ${savedTheme.cls}"></span> ${savedTheme.label}`;
196
197 selected.onclick = (e) => {
198 e.stopPropagation();
199 list.classList.toggle('show');
200 };
201
202 document.addEventListener('click', function(e) {
203 if (!wrapper.contains(e.target)) list.classList.remove('show');
204 });
205
206 wrapper.appendChild(selected);
207 wrapper.appendChild(list);
208
209 // Append to END of left toolbar
210 target.appendChild(button);
211 target.appendChild(wrapper);
212
213 return true;
214 }
215
216 if (!injectDarkify()) {
217 const interval = setInterval(function() {
218 if (injectDarkify()) clearInterval(interval);
219 }, 300);
220 setTimeout(function() {
221 clearInterval(interval);
222 }, 10000);
223 }
224 });
225 })();
226 </script>
227 <?php }
228 }
229 }
230