PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.5.5
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.5.5
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) 1.5.5, at src/Frontend/Templates/footer_script.php

224 lines 11.1 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 echo wp_strip_all_tags(DarkifyUtils::parseAndProcessNormalCustomCSS($normal_custom_css)); ?>
34 </style>
35 <style type="text/css" class="darkify_inline_css">
36 <?php echo wp_strip_all_tags(DarkifyUtils::parseAndProcessCustomCSS($custom_css, false)); ?>
37 </style>
38
39 <?php if (!is_admin()) { ?>
40 <script type="text/javascript" class="darkify_inline_js">
41 document.addEventListener("DOMContentLoaded", function(event) {
42 darkify_init_alternative_dark_mode_switch();
43 darkify_init_attention_effect();
44 if (typeof darkify_init_draggable_floating_switch === "function") {
45 darkify_init_draggable_floating_switch();
46 }
47 });
48 </script>
49 <?php }
50
51 if (is_admin() && $block_editor_dark_mode) {
52 ?><style type="text/css" class="darkify_inline_css">
53 <?php echo esc_html(DarkifyUtils::parseAndProcessCustomCSS($admin_custom_css, 'yes')); ?>
54 </style>
55 <?php
56 /* Check if block editor is on, then add the dark mode button there */
57 if ($enable_admin_panel_dark_mode) {
58 if (class_exists('WP_Block_Type_Registry')) {
59
60 if (get_current_screen() && 'post' === get_current_screen()->base && ('post' === get_current_screen()->post_type || 'page' === get_current_screen()->post_type)) { ?>
61 <script type="text/javascript" class="darkify_inline_js">
62 (function checkForWP() {
63 if (
64 typeof wp === 'undefined' ||
65 typeof wp.domReady === 'undefined' ||
66 typeof wp.plugins === 'undefined' ||
67 typeof wp.element === 'undefined'
68 ) {
69 return setTimeout(checkForWP, 200);
70 }
71
72 wp.domReady(function() {
73
74 function injectDarkify() {
75 // Target the LEFT side toolbar
76 const target =
77 document.querySelector('.editor-header__toolbar') ||
78 document.querySelector('.edit-post-header-toolbar') ||
79 document.querySelector('.editor-document-tools');
80
81 if (!target) return false;
82 if (target.querySelector('.darkify-dropdown')) return true;
83
84 const themes = [{
85 value: 'set1',
86 label: 'Carbon Mist',
87 cls: 'carbon_mist'
88 },
89 {
90 value: 'set3',
91 label: 'Midnight Reverie',
92 cls: 'midnight_reverie'
93 },
94 {
95 value: 'set9',
96 label: 'Verdant Depths',
97 cls: 'verdant_depths'
98 },
99 {
100 value: 'set6',
101 label: 'Celestial Tide',
102 cls: 'celestial_tide'
103 },
104 {
105 value: 'set10',
106 label: 'Emberwood',
107 cls: 'emberwood'
108 },
109 {
110 value: 'set2',
111 label: 'Glacier Drift',
112 cls: 'glacier_drift',
113 pro: true
114 },
115 {
116 value: 'set4',
117 label: 'Indigo Veil',
118 cls: 'indigo_veil',
119 pro: true
120 },
121 {
122 value: 'set5',
123 label: 'Duskmire',
124 cls: 'duskmire',
125 pro: true
126 },
127 {
128 value: 'set7',
129 label: 'Tidal Frost',
130 cls: 'tidal_frost',
131 pro: true
132 },
133 {
134 value: 'set8',
135 label: 'Blue Bastion',
136 cls: 'blue_bastion',
137 pro: true
138 },
139 {
140 value: 'set11',
141 label: 'Crimson Veil',
142 cls: 'crimson_veil',
143 pro: true
144 },
145 ];
146
147 // Dark mode toggle button
148 const button = document.createElement('button');
149 button.className = 'darkify_block_editor_switch darkify_ignore';
150 button.innerHTML = '<div class="icon"></div>';
151 button.onclick = function() {
152 darkify_switch_trigger();
153 };
154
155 // Dropdown wrapper
156 const wrapper = document.createElement('div');
157 wrapper.className = 'darkify-dropdown';
158 wrapper.style.cssText = 'position:relative;display:inline-flex;align-items:center;';
159
160 const selected = document.createElement('div');
161 selected.className = 'darkify-selected';
162
163 const list = document.createElement('div');
164 list.className = 'darkify-options';
165
166 themes.forEach(t => {
167 const item = document.createElement('div');
168 if (t.pro) {
169 item.className = 'darkify-option darkify-pro-option';
170 item.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}<span class="darkify-option-pro-badge">PRO</span>`;
171 item.title = 'Upgrade to Pro to unlock this theme';
172 } else {
173 item.className = 'darkify-option';
174 item.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}`;
175 item.onclick = () => {
176 selected.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}`;
177 localStorage.darkify_selected_theme = t.value;
178 darkify_theme_select(t.value);
179 list.classList.remove('show');
180 };
181 }
182 list.appendChild(item);
183 });
184
185 // Load saved theme — fall back to first free theme if saved value is pro-only
186 const savedVal = localStorage.darkify_selected_theme || 'set1';
187 const savedTheme = themes.find(t => t.value === savedVal && !t.pro) || themes[0];
188 selected.innerHTML = `<span class="theme_color ${savedTheme.cls}"></span> ${savedTheme.label}`;
189
190 selected.onclick = (e) => {
191 e.stopPropagation();
192 list.classList.toggle('show');
193 };
194
195 document.addEventListener('click', function(e) {
196 if (!wrapper.contains(e.target)) list.classList.remove('show');
197 });
198
199 wrapper.appendChild(selected);
200 wrapper.appendChild(list);
201
202 // Append to END of left toolbar
203 target.appendChild(button);
204 target.appendChild(wrapper);
205
206 return true;
207 }
208
209 if (!injectDarkify()) {
210 const interval = setInterval(function() {
211 if (injectDarkify()) clearInterval(interval);
212 }, 300);
213 setTimeout(function() {
214 clearInterval(interval);
215 }, 10000);
216 }
217 });
218 })();
219 </script>
220 <?php }
221 }
222 }
223 }
224