Hijri
3 years ago
Processors
1 month ago
QuranADay
2 months ago
StartTime
1 year ago
design
1 month ago
AdminMenu.php
2 years ago
AssetsLoader.php
1 year ago
CustomPluginSettings.php
4 years ago
DPTAjaxHandler.php
4 years ago
DPTHelper.php
1 month ago
DSTemplateLoader.php
2 years ago
DailyShortCode.php
2 months ago
DigitalScreen.php
1 month ago
HijriDate.php
3 years ago
Init.php
4 years ago
MonthlyShortCode.php
2 years ago
MonthlyTimeTable.php
3 years ago
Shortcodes.php
2 months ago
Translator.php
4 years ago
UpdateStyles.php
1 month ago
Validator.php
3 years ago
db.php
2 months ago
dptWidget.php
4 years ago
UpdateStyles.php
268 lines
| 1 | <?php |
| 2 | class UpdateStyles |
| 3 | { |
| 4 | /** @var string */ |
| 5 | private $handle; |
| 6 | |
| 7 | /** @var array */ |
| 8 | private $options; |
| 9 | |
| 10 | public function __construct($handle) |
| 11 | { |
| 12 | $this->handle = $handle; |
| 13 | $this->loadOptions(); |
| 14 | $this->setScript(); |
| 15 | $this->setStyles(); |
| 16 | } |
| 17 | |
| 18 | private function loadOptions() |
| 19 | { |
| 20 | $this->options = [ |
| 21 | 'tableBackground' => get_option('tableBackground'), |
| 22 | 'tableHeading' => get_option('tableHeading'), |
| 23 | 'tableHeadingFont' => get_option('tableHeadingFont'), |
| 24 | 'notificationBackground' => get_option('notificationBackground'), |
| 25 | 'notificationFont' => get_option('notificationFont'), |
| 26 | 'evenRow' => get_option('evenRow'), |
| 27 | 'fontColor' => get_option('fontColor'), |
| 28 | 'prayerName' => get_option('prayerName'), |
| 29 | 'prayerNameFont' => get_option('prayerNameFont'), |
| 30 | 'highlight' => get_option('highlight') ?? 'red', |
| 31 | 'highlightFont' => get_option('highlightFont') ?? 'white', |
| 32 | 'digitalScreenRed' => get_option('digitalScreenRed'), |
| 33 | 'digitalScreenLightRed' => get_option('digitalScreenLightRed'), |
| 34 | 'digitalScreenGreen' => get_option('digitalScreenGreen'), |
| 35 | 'digitalScreenPrayerName' => get_option('digitalScreenPrayerName') |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | private function setScript() |
| 40 | { |
| 41 | add_action('admin_enqueue_scripts', [$this, 'enqueueColorPicker']); |
| 42 | } |
| 43 | |
| 44 | public function enqueueColorPicker() |
| 45 | { |
| 46 | if (!is_admin()) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | wp_enqueue_style('wp-color-picker'); |
| 51 | wp_enqueue_script( |
| 52 | 'custom-script-handle', |
| 53 | plugins_url('/../Assets/js/wp-color-picker.js', __FILE__), |
| 54 | ['wp-color-picker'], |
| 55 | '4.0.0' |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | private function setStyles() |
| 60 | { |
| 61 | $css = ''; |
| 62 | $css .= $this->getTableBackgroundStyles(); |
| 63 | $css .= $this->getTableHeadingStyles(); |
| 64 | $css .= $this->getNotificationStyles(); |
| 65 | $css .= $this->getPrayerNameStyles(); |
| 66 | $css .= $this->getHighlightStyles(); |
| 67 | $css .= $this->getDigitalScreenStyles(); |
| 68 | |
| 69 | wp_add_inline_style($this->handle, $this->minifyCss($css)); |
| 70 | } |
| 71 | |
| 72 | private function getTableBackgroundStyles() |
| 73 | { |
| 74 | if (empty($this->options['tableBackground'])) { |
| 75 | return ''; |
| 76 | } |
| 77 | |
| 78 | return " |
| 79 | .x-board-modern #time-table-section, |
| 80 | .x-board-modern .date-english-arabic { |
| 81 | background: {$this->options['tableBackground'] } !important |
| 82 | } |
| 83 | .green, |
| 84 | .x-board-modern .mosque-name h2, |
| 85 | .x-board-modern .clock { |
| 86 | color: {$this->options['tableBackground']} |
| 87 | } |
| 88 | .dpt-horizontal-wrapper.customStyles { |
| 89 | background-color: {$this->options['tableBackground']} !important |
| 90 | } |
| 91 | "; |
| 92 | } |
| 93 | |
| 94 | private function getTableHeadingStyles() |
| 95 | { |
| 96 | if (empty($this->options['tableHeading'])) { |
| 97 | return ''; |
| 98 | } |
| 99 | |
| 100 | return " |
| 101 | table.customStyles th.tableHeading { |
| 102 | background: {$this->options['tableHeading']}; |
| 103 | color: {$this->options['tableHeadingFont']} |
| 104 | } |
| 105 | "; |
| 106 | } |
| 107 | |
| 108 | private function getNotificationStyles() |
| 109 | { |
| 110 | $styles = ''; |
| 111 | |
| 112 | if (!empty($this->options['notificationBackground'])) { |
| 113 | $styles .= " |
| 114 | table.customStyles th.notificationBackground, |
| 115 | .notificationBackground { |
| 116 | background: {$this->options['notificationBackground']}; |
| 117 | color: {$this->options['notificationFont']} |
| 118 | } |
| 119 | "; |
| 120 | } |
| 121 | |
| 122 | if (!empty($this->options['notificationFont'])) { |
| 123 | $styles .= " |
| 124 | table.customStyles th.notificationFont, |
| 125 | .notificationFont { |
| 126 | color: {$this->options['notificationFont']} |
| 127 | } |
| 128 | "; |
| 129 | } |
| 130 | |
| 131 | if (!empty($this->options['evenRow'])) { |
| 132 | $styles .= " |
| 133 | table.customStyles tr:nth-child(even) { |
| 134 | background: {$this->options['evenRow']} |
| 135 | } |
| 136 | "; |
| 137 | } |
| 138 | |
| 139 | if (!empty($this->options['fontColor'])) { |
| 140 | $styles .= " |
| 141 | table.customStyles { |
| 142 | color: {$this->options['fontColor']} |
| 143 | } |
| 144 | "; |
| 145 | } |
| 146 | |
| 147 | return $styles; |
| 148 | } |
| 149 | |
| 150 | private function getPrayerNameStyles() |
| 151 | { |
| 152 | $styles = ''; |
| 153 | |
| 154 | if (!empty($this->options['prayerName'])) { |
| 155 | $styles .= " |
| 156 | table.customStyles th.prayerName { |
| 157 | background: {$this->options['prayerName']} |
| 158 | } |
| 159 | "; |
| 160 | } |
| 161 | |
| 162 | if (!empty($this->options['prayerNameFont'])) { |
| 163 | $styles .= " |
| 164 | table.customStyles th.prayerName { |
| 165 | color: {$this->options['prayerNameFont']} |
| 166 | } |
| 167 | .x-board-modern #time-table-section h4 { |
| 168 | color: {$this->options['prayerNameFont']} |
| 169 | } |
| 170 | "; |
| 171 | } |
| 172 | |
| 173 | return $styles; |
| 174 | } |
| 175 | |
| 176 | private function getHighlightStyles() |
| 177 | { |
| 178 | return " |
| 179 | table.customStyles tr.highlight, th.highlight, td.highlight { |
| 180 | font-weight: bold; |
| 181 | background: {$this->options['highlight']} !important; |
| 182 | color: {$this->options['highlightFont']} !important; |
| 183 | } |
| 184 | span.nextPrayer { |
| 185 | font-weight: bold; |
| 186 | color: {$this->options['highlight']} |
| 187 | } |
| 188 | .x-board tr.nextPrayer td { |
| 189 | background-color: {$this->options['highlight']} !important; |
| 190 | color: {$this->options['highlightFont']} !important; |
| 191 | } |
| 192 | .x-board-modern h4.nextPrayer, p.nextPrayer { |
| 193 | background: {$this->options['highlight']} !important; |
| 194 | color: {$this->options['highlightFont']} !important; |
| 195 | } |
| 196 | .d-masjid-e-usman .nextPrayer h3, |
| 197 | .nextPrayer .title, |
| 198 | tr.nextPrayer, |
| 199 | td span.nextPrayer, |
| 200 | .dpt-wrapper-container .prayer-time.highlight { |
| 201 | background: {$this->options['highlight']} !important; |
| 202 | color: {$this->options['highlightFont']} !important; |
| 203 | } |
| 204 | .d-masjid-e-usman .left-main-col-sun-times h4, |
| 205 | .left-main-col-sun-times p { |
| 206 | color: {$this->options['highlight']} !important; |
| 207 | } |
| 208 | .dptPrayerIcon { |
| 209 | color: {$this->options['highlightFont']} !important; |
| 210 | } |
| 211 | span.nextPrayer { |
| 212 | color: {$this->options['highlightFont']} !important; |
| 213 | } |
| 214 | .d-masjid-e-usman .nextPrayer h3, .nextPrayer .title, .d-masjid-e-usman .nextPrayer .dsJumuah { |
| 215 | color: {$this->options['highlightFont']} !important; |
| 216 | } |
| 217 | "; |
| 218 | } |
| 219 | |
| 220 | private function getDigitalScreenStyles() |
| 221 | { |
| 222 | $styles = ''; |
| 223 | |
| 224 | if (!empty($this->options['digitalScreenRed'])) { |
| 225 | $styles .= " |
| 226 | .x-board .bg-red { |
| 227 | background: {$this->options['digitalScreenRed']} !important |
| 228 | } |
| 229 | "; |
| 230 | } |
| 231 | |
| 232 | if (!empty($this->options['digitalScreenLightRed'])) { |
| 233 | $styles .= " |
| 234 | .x-board .l-red { |
| 235 | background: {$this->options['digitalScreenLightRed']} !important |
| 236 | } |
| 237 | "; |
| 238 | } |
| 239 | |
| 240 | if (!empty($this->options['digitalScreenGreen'])) { |
| 241 | $styles .= " |
| 242 | .x-board .bg-green { |
| 243 | background: {$this->options['digitalScreenGreen']} !important |
| 244 | } |
| 245 | "; |
| 246 | } |
| 247 | |
| 248 | if (!empty($this->options['digitalScreenPrayerName'])) { |
| 249 | $styles .= " |
| 250 | .x-board td.prayerName { |
| 251 | background: {$this->options['digitalScreenPrayerName']} !important |
| 252 | } |
| 253 | "; |
| 254 | } |
| 255 | |
| 256 | return $styles; |
| 257 | } |
| 258 | |
| 259 | private function minifyCss($css) |
| 260 | { |
| 261 | // Remove comments |
| 262 | $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css); |
| 263 | // Remove space after colons and unnecessary whitespace |
| 264 | $css = str_replace([': ', "\r\n", "\r", "\n", "\t", ' ', ' '], [':', ' '], $css); |
| 265 | return trim($css); |
| 266 | } |
| 267 | } |
| 268 |