| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if (!defined('WPINC')) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
if (!class_exists('DarkifyClient')) { |
| 9 |
class DarkifyClient |
| 10 |
{ |
| 11 |
public $utils; |
| 12 |
public $settings; |
| 13 |
public $external_support; |
| 14 |
public $unique_id; |
| 15 |
|
| 16 |
|
| 17 |
public function __construct() |
| 18 |
{ |
| 19 |
|
| 20 |
$this->utils = new DarkifyUtils($this); |
| 21 |
$this->external_support = new DarkifyExternalSupport($this); |
| 22 |
|
| 23 |
new DarkifyShortcodeParser($this); |
| 24 |
|
| 25 |
if ( function_exists( 'wp_rand' ) ) { |
| 26 |
$this->unique_id = wp_rand(); |
| 27 |
} |
| 28 |
|
| 29 |
$options = get_option('darkify'); |
| 30 |
$show_in_menu = isset($options['show_in_menu']) ? $options['show_in_menu'] : ""; |
| 31 |
$enable_switcher_in_menu = isset($show_in_menu["enable_switch_in_menu"]) ? $show_in_menu["enable_switch_in_menu"] : false; |
| 32 |
|
| 33 |
if($enable_switcher_in_menu){ |
| 34 |
add_filter('wp_nav_menu_items',array($this, 'darkify_switch_in_menu'), 10, 2); |
| 35 |
} |
| 36 |
|
| 37 |
add_action( 'wp_enqueue_scripts', array( $this, 'darkify_client_enqueue' ) ); |
| 38 |
add_action( 'login_enqueue_scripts', array( $this, 'darkify_client_enqueue' ) ); |
| 39 |
add_action( 'register_enqueue_scripts', array( $this, 'darkify_client_enqueue' ) ); |
| 40 |
add_action( 'wp_head', array( $this, 'darkify_client_header_script' ), 1); |
| 41 |
add_action( 'login_head', array( $this, 'darkify_client_header_script' ), 1 ); |
| 42 |
add_action( 'register_head', array( $this, 'darkify_client_header_script' ), 1 ); |
| 43 |
add_action( 'wp_footer', array( $this, 'darkify_client_footer_script' ) ); |
| 44 |
add_action( 'login_footer', array( $this, 'darkify_client_footer_script' ) ); |
| 45 |
add_action( 'register_footer', array( $this, 'darkify_client_footer_script' ) ); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
function darkify_client_enqueue() { |
| 50 |
if($this->darkify_is_dark_mode_allowed()){ |
| 51 |
$options = get_option('darkify'); |
| 52 |
$enable_dark_switcher = $options['enable_dark_switcher']; |
| 53 |
$enable_time = $options['enable_time']; |
| 54 |
|
| 55 |
$enable_default_dark_mode = $options['enable_default_dark_mode']; |
| 56 |
$enable_time = $options['enable_time']; |
| 57 |
$enable_time_based_dark = isset($enable_time['enable_time_based_dark']) ? $enable_time['enable_time_based_dark'] : ""; |
| 58 |
$time_based_dark_start = isset($enable_time['time_based_dark_start']['from']) ? $enable_time['time_based_dark_start']['from'] : ""; |
| 59 |
$time_based_dark_stop = isset($enable_time['time_based_dark_start']['to']) ? $enable_time['time_based_dark_start']['to'] : ""; |
| 60 |
$grayscale = $options['brightness']; |
| 61 |
$enable_low_image_brightness = isset($grayscale['enable_low_image_brightness']) ? $grayscale['enable_low_image_brightness'] : ""; |
| 62 |
$low_image_brightness_label = isset($grayscale['low_image_brightness_label']) ? $grayscale['low_image_brightness_label'] : ""; |
| 63 |
$grayscale = isset($options['grayscale']); |
| 64 |
$enable_image_grayscale = isset($grayscale['enable_image_grayscale']) ? $grayscale['enable_image_grayscale'] : ""; |
| 65 |
$image_grayscale_label = isset($grayscale['image_grayscale_label']) ? $grayscale['image_grayscale_label'] : ""; |
| 66 |
$disallowed_low_grayscale_images = isset($grayscale['disallowed_low_grayscale_images']) ? $grayscale['disallowed_low_grayscale_images'] : ""; |
| 67 |
$darken_background = isset($options['darken_background']); |
| 68 |
$enable_low_image_darken = isset($darken_background['enable_low_image_darken']) ? $darken_background['enable_low_image_darken'] : ""; |
| 69 |
$low_image_darken_label = isset($darken_background['low_image_darken_label']) ? $darken_background['low_image_darken_label'] : ""; |
| 70 |
$video_brightness = isset($options['video_brightness']); |
| 71 |
$enable_low_video_brightness = isset($video_brightness['enable_low_video_brightness']) ? $video_brightness['enable_low_video_brightness'] : ""; |
| 72 |
$low_video_brightness_label = isset($video_brightness['low_video_brightness_label']) ? $video_brightness['low_video_brightness_label'] : ""; |
| 73 |
$video_grayscale = isset($options['video_grayscale']); |
| 74 |
$enable_video_grayscale = isset($video_grayscale['enable_video_grayscale']) ? $video_grayscale['enable_video_grayscale'] : ""; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
wp_enqueue_style("theme-{$enable_dark_switcher}", DRK_LITE_DIR_URL . "public/css/switcher/$enable_dark_switcher.css", array(), DRK_LITE_VERSION, 'all'); |
| 79 |
wp_register_style('theme-around', DRK_LITE_DIR_URL . "public/css/switcher/around.css", array(), DRK_LITE_VERSION, 'all'); |
| 80 |
wp_register_style('theme-classic', DRK_LITE_DIR_URL . "public/css/switcher/classic.css", array(), DRK_LITE_VERSION, 'all'); |
| 81 |
wp_register_style('theme-dark-inner', DRK_LITE_DIR_URL . "public/css/switcher/dark-inner.css", array(), DRK_LITE_VERSION, 'all'); |
| 82 |
wp_register_style('theme-dark-side', DRK_LITE_DIR_URL . "public/css/switcher/dark-side.css", array(), DRK_LITE_VERSION, 'all'); |
| 83 |
wp_register_style('theme-eclipse', DRK_LITE_DIR_URL . "public/css/switcher/eclipse.css", array(), DRK_LITE_VERSION, 'all'); |
| 84 |
wp_register_style('theme-expand', DRK_LITE_DIR_URL . "public/css/switcher/expand.css", array(), DRK_LITE_VERSION, 'all'); |
| 85 |
wp_register_style('theme-half-sun', DRK_LITE_DIR_URL . "public/css/switcher/half-sun.css", array(), DRK_LITE_VERSION, 'all'); |
| 86 |
wp_register_style('theme-horizon', DRK_LITE_DIR_URL . "public/css/switcher/horizon.css", array(), DRK_LITE_VERSION, 'all'); |
| 87 |
wp_register_style('theme-inner-moon', DRK_LITE_DIR_URL . "public/css/switcher/inner-moon.css", array(), DRK_LITE_VERSION, 'all'); |
| 88 |
wp_register_style('theme-lightbulb', DRK_LITE_DIR_URL . "public/css/switcher/lightbulb.css", array(), DRK_LITE_VERSION, 'all'); |
| 89 |
wp_register_style('theme-simple', DRK_LITE_DIR_URL . "public/css/switcher/simple.css", array(), DRK_LITE_VERSION, 'all'); |
| 90 |
wp_register_style('theme-within', DRK_LITE_DIR_URL . "public/css/switcher/within.css", array(), DRK_LITE_VERSION, 'all'); |
| 91 |
wp_enqueue_style('darkify-client-main', DRK_LITE_DIR_URL . 'assets/css/client_main.css', array(), DRK_LITE_VERSION); |
| 92 |
wp_enqueue_script( 'darkify-client-main', DRK_LITE_DIR_URL . 'assets/js/client_main.js', array('jquery'), DRK_LITE_VERSION, true); |
| 93 |
|
| 94 |
$darkify_data = array( |
| 95 |
'darkify_switch_unique_id' => $this->unique_id, |
| 96 |
'darkify_is_this_admin_panel' => is_admin() ? "1" : "0", |
| 97 |
'darkify_enable_default_dark_mode' => $enable_default_dark_mode, |
| 98 |
'darkify_enable_os_aware' => $options["enable_os_aware"], |
| 99 |
'darkify_enable_keyboard_shortcut' => $options["enable_keyboard_shortcut"], |
| 100 |
'darkify_enable_time_based_dark' => $enable_time_based_dark, |
| 101 |
'darkify_time_based_dark_start' => $time_based_dark_start ? $time_based_dark_start : "19:00", |
| 102 |
'darkify_time_based_dark_stop' => $time_based_dark_stop ? $time_based_dark_stop : "07:00", |
| 103 |
'darkify_alternative_dark_mode_switch' => $options["alternative_dark_mode_switcher"], |
| 104 |
'darkify_enable_low_image_brightness' => $enable_low_image_brightness, |
| 105 |
'darkify_image_brightness_to' => $low_image_brightness_label, |
| 106 |
'darkify_enable_image_grayscale' => $enable_image_grayscale, |
| 107 |
'darkify_image_grayscale_to' => $image_grayscale_label, |
| 108 |
'darkify_disallowed_grayscale_images' => $disallowed_low_grayscale_images, |
| 109 |
'darkify_enable_bg_image_darken' => $enable_low_image_darken, |
| 110 |
'darkify_bg_image_darken_to' => $low_image_darken_label, |
| 111 |
'darkify_enable_invert_inline_svg' => $options["enable_invert_inline_svg"], |
| 112 |
'darkify_enable_low_video_brightness' => $enable_low_video_brightness, |
| 113 |
'darkify_video_brightness_to' => $low_video_brightness_label, |
| 114 |
'darkify_enable_video_grayscale' => $enable_video_grayscale, |
| 115 |
// Add more variables as needed... |
| 116 |
); |
| 117 |
wp_localize_script('darkify-client-main', 'darkify_data', $darkify_data); |
| 118 |
} |
| 119 |
} |
| 120 |
function darkify_is_dark_mode_allowed() { |
| 121 |
$options = get_option('darkify'); |
| 122 |
/* Disable if Oxygen Builder is Opened */ |
| 123 |
if (isset( $_GET['ct_builder'] )) { |
| 124 |
if($_GET['ct_builder'] == "true"){ |
| 125 |
if (!isset( $_GET['oxygen_iframe'] )) { |
| 126 |
return False; |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
return True; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
function darkify_client_header_script() |
| 136 |
{ |
| 137 |
if($this->darkify_is_dark_mode_allowed()){ |
| 138 |
include_once DRK_LITE_PATH . "public/templates/header_script.php"; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
function darkify_client_footer_script() |
| 143 |
{ |
| 144 |
if($this->darkify_is_dark_mode_allowed()){ |
| 145 |
include_once DRK_LITE_PATH . "public/templates/footer_script.php"; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
function darkify_switch_in_menu( $items, $args ) { |
| 150 |
$options = get_option('darkify'); |
| 151 |
$show_in_menu = $options['show_in_menu']; |
| 152 |
$switch_in_menu_location = $show_in_menu['switch_in_menu_location']; |
| 153 |
$darkify_menu_shortcode_helper = $show_in_menu['darkify_menu_shortcode_helper']; |
| 154 |
|
| 155 |
if($this->darkify_is_dark_mode_allowed()){ |
| 156 |
if(isset($args->menu->term_id)){ |
| 157 |
if($args->menu->term_id == $switch_in_menu_location){ |
| 158 |
$items .= '<li class="menu-item">'.do_shortcode($darkify_menu_shortcode_helper).'</li>'; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
return $items; |
| 163 |
} |
| 164 |
|
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
new DarkifyClient(); |
| 169 |
|
| 170 |
|
| 171 |
|