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
1 month 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
307 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 | 'digitalScreenGreenFont' => get_option('digitalScreenGreenFont') ?? 'white', |
| 36 | 'digitalScreenPrayerName' => get_option('digitalScreenPrayerName'), |
| 37 | 'digitalScreenSlideBg' => get_option('digitalScreenSlideBg') |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | private function setScript() |
| 42 | { |
| 43 | add_action('admin_enqueue_scripts', [$this, 'enqueueColorPicker']); |
| 44 | } |
| 45 | |
| 46 | public function enqueueColorPicker() |
| 47 | { |
| 48 | if (!is_admin()) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | wp_enqueue_style('wp-color-picker'); |
| 53 | wp_enqueue_script( |
| 54 | 'custom-script-handle', |
| 55 | plugins_url('/../Assets/js/wp-color-picker.js', __FILE__), |
| 56 | ['wp-color-picker'], |
| 57 | '4.0.0' |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | private function setStyles() |
| 62 | { |
| 63 | $css = ''; |
| 64 | $css .= $this->getTableBackgroundStyles(); |
| 65 | $css .= $this->getTableHeadingStyles(); |
| 66 | $css .= $this->getNotificationStyles(); |
| 67 | $css .= $this->getPrayerNameStyles(); |
| 68 | $css .= $this->getHighlightStyles(); |
| 69 | $css .= $this->getDigitalScreenStyles(); |
| 70 | |
| 71 | wp_add_inline_style($this->handle, $this->minifyCss($css)); |
| 72 | } |
| 73 | |
| 74 | private function getTableBackgroundStyles() |
| 75 | { |
| 76 | if (empty($this->options['tableBackground'])) { |
| 77 | return ''; |
| 78 | } |
| 79 | |
| 80 | $color = $this->options['tableBackground']; |
| 81 | |
| 82 | return " |
| 83 | .x-board-modern #time-table-section, |
| 84 | .x-board-modern .date-english-arabic, |
| 85 | .x-board-my-masjid .prayer-table-section, |
| 86 | .x-board-my-masjid .next-banner { |
| 87 | background: {$color} !important |
| 88 | } |
| 89 | .green, |
| 90 | .x-board-modern .mosque-name h2, |
| 91 | .x-board-modern .clock, |
| 92 | .x-board-my-masjid .highlight-text { |
| 93 | color: {$color} |
| 94 | } |
| 95 | .dpt-horizontal-wrapper.customStyles { |
| 96 | background-color: {$color} !important |
| 97 | } |
| 98 | "; |
| 99 | } |
| 100 | |
| 101 | private function getTableHeadingStyles() |
| 102 | { |
| 103 | if (empty($this->options['tableHeading'])) { |
| 104 | return ''; |
| 105 | } |
| 106 | |
| 107 | return " |
| 108 | table.customStyles th.tableHeading { |
| 109 | background: {$this->options['tableHeading']}; |
| 110 | color: {$this->options['tableHeadingFont']} |
| 111 | } |
| 112 | "; |
| 113 | } |
| 114 | |
| 115 | private function getNotificationStyles() |
| 116 | { |
| 117 | $styles = ''; |
| 118 | |
| 119 | if (!empty($this->options['notificationBackground'])) { |
| 120 | $styles .= " |
| 121 | table.customStyles th.notificationBackground, |
| 122 | .notificationBackground { |
| 123 | background: {$this->options['notificationBackground']}; |
| 124 | color: {$this->options['notificationFont']} |
| 125 | } |
| 126 | "; |
| 127 | } |
| 128 | |
| 129 | if (!empty($this->options['notificationFont'])) { |
| 130 | $styles .= " |
| 131 | table.customStyles th.notificationFont, |
| 132 | .notificationFont { |
| 133 | color: {$this->options['notificationFont']} |
| 134 | } |
| 135 | "; |
| 136 | } |
| 137 | |
| 138 | if (!empty($this->options['evenRow'])) { |
| 139 | $styles .= " |
| 140 | table.customStyles tr:nth-child(even) { |
| 141 | background: {$this->options['evenRow']} |
| 142 | } |
| 143 | "; |
| 144 | } |
| 145 | |
| 146 | if (!empty($this->options['fontColor'])) { |
| 147 | $styles .= " |
| 148 | table.customStyles { |
| 149 | color: {$this->options['fontColor']} |
| 150 | } |
| 151 | "; |
| 152 | } |
| 153 | |
| 154 | return $styles; |
| 155 | } |
| 156 | |
| 157 | private function getPrayerNameStyles() |
| 158 | { |
| 159 | $styles = ''; |
| 160 | |
| 161 | if (!empty($this->options['prayerName'])) { |
| 162 | $styles .= " |
| 163 | table.customStyles th.prayerName { |
| 164 | background: {$this->options['prayerName']} |
| 165 | } |
| 166 | "; |
| 167 | } |
| 168 | |
| 169 | if (!empty($this->options['prayerNameFont'])) { |
| 170 | $styles .= " |
| 171 | table.customStyles th.prayerName { |
| 172 | color: {$this->options['prayerNameFont']} |
| 173 | } |
| 174 | .x-board-modern #time-table-section h4 { |
| 175 | color: {$this->options['prayerNameFont']} |
| 176 | } |
| 177 | "; |
| 178 | } |
| 179 | |
| 180 | return $styles; |
| 181 | } |
| 182 | |
| 183 | private function getHighlightStyles() |
| 184 | { |
| 185 | $styles = ''; |
| 186 | |
| 187 | if (!empty($this->options['highlight'])) { |
| 188 | $highlightBackground = $this->options['highlight']; |
| 189 | |
| 190 | $styles .= " |
| 191 | :root { |
| 192 | --dpt-highlight: {$highlightBackground} !important; |
| 193 | } |
| 194 | table.customStyles tr.highlight, th.highlight, td.highlight { |
| 195 | background: {$highlightBackground} !important; |
| 196 | } |
| 197 | "; |
| 198 | } |
| 199 | |
| 200 | if (!empty($this->options['highlightFont'])) { |
| 201 | $highlightFont = $this->options['highlightFont']; |
| 202 | $styles .= " |
| 203 | :root { |
| 204 | --dpt-highlight-font: {$highlightFont} !important; |
| 205 | } |
| 206 | table.customStyles tr.highlight, th.highlight, td.highlight { |
| 207 | color: {$highlightFont} !important; |
| 208 | } |
| 209 | div.dptScNextPrayer { |
| 210 | color: {$highlightFont}; |
| 211 | } |
| 212 | "; |
| 213 | } |
| 214 | |
| 215 | return $styles; |
| 216 | } |
| 217 | |
| 218 | private function getDigitalScreenStyles() |
| 219 | { |
| 220 | $styles = ''; |
| 221 | |
| 222 | if (!empty($this->options['digitalScreenRed'])) { |
| 223 | $styles .= " |
| 224 | .x-board .bg-red { |
| 225 | background: {$this->options['digitalScreenRed']} !important |
| 226 | } |
| 227 | "; |
| 228 | } |
| 229 | |
| 230 | if (!empty($this->options['digitalScreenLightRed'])) { |
| 231 | $styles .= " |
| 232 | .x-board .l-red { |
| 233 | background: {$this->options['digitalScreenLightRed']} !important |
| 234 | } |
| 235 | "; |
| 236 | } |
| 237 | |
| 238 | if (!empty($this->options['digitalScreenGreen'])) { |
| 239 | $nextPrayerRowBg = $this->options['digitalScreenGreen']; |
| 240 | $styles .= " |
| 241 | #dsPrayerTimetable tr.nextPrayer td, |
| 242 | .x-board tr.nextPrayer td { |
| 243 | background: {$nextPrayerRowBg} !important; |
| 244 | } |
| 245 | "; |
| 246 | } |
| 247 | |
| 248 | if (!empty($this->options['digitalScreenSlideBg'])) { |
| 249 | $slideBg = $this->options['digitalScreenSlideBg']; |
| 250 | $styles .= " |
| 251 | .x-board .bg-green { |
| 252 | background-color: {$slideBg} !important |
| 253 | } |
| 254 | .x-board .nextPrayer .title, |
| 255 | .dpt-wrapper-container .prayer-time.highlight { |
| 256 | background-color: {$slideBg} !important; |
| 257 | } |
| 258 | "; |
| 259 | } |
| 260 | |
| 261 | if (!empty($this->options['digitalScreenGreenFont'])) { |
| 262 | $nextPrayerFont = $this->options['digitalScreenGreenFont']; |
| 263 | $styles .= " |
| 264 | .x-board .bg-green td, |
| 265 | .x-board .bg-green div, |
| 266 | .x-board .bg-green h2, |
| 267 | .x-board .bg-green h3, |
| 268 | .x-board .bg-green h4 { |
| 269 | color: {$nextPrayerFont} !important; |
| 270 | } |
| 271 | .x-board span.nextPrayer { |
| 272 | font-weight: bold; |
| 273 | color: {$nextPrayerFont}; |
| 274 | } |
| 275 | .x-board tr.nextPrayer td { |
| 276 | color: {$nextPrayerFont} !important; |
| 277 | } |
| 278 | .quranVerse { |
| 279 | color: {$nextPrayerFont}; |
| 280 | } |
| 281 | div.dptScNextPrayer { |
| 282 | color: {$nextPrayerFont}; |
| 283 | } |
| 284 | "; |
| 285 | } |
| 286 | |
| 287 | if (!empty($this->options['digitalScreenPrayerName'])) { |
| 288 | $styles .= " |
| 289 | .x-board td.prayerName { |
| 290 | background: {$this->options['digitalScreenPrayerName']} !important |
| 291 | } |
| 292 | "; |
| 293 | } |
| 294 | |
| 295 | return $styles; |
| 296 | } |
| 297 | |
| 298 | private function minifyCss($css) |
| 299 | { |
| 300 | // Remove comments |
| 301 | $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css); |
| 302 | // Remove space after colons and unnecessary whitespace |
| 303 | $css = str_replace([': ', "\r\n", "\r", "\n", "\t", ' ', ' '], [':', ' '], $css); |
| 304 | return trim($css); |
| 305 | } |
| 306 | } |
| 307 |