Hijri
3 years ago
Processors
1 year ago
QuranADay
2 years ago
StartTime
4 years ago
design
1 year ago
AdminMenu.php
2 years ago
AssetsLoader.php
1 year ago
CustomPluginSettings.php
4 years ago
DPTAjaxHandler.php
4 years ago
DPTHelper.php
2 years ago
DSTemplateLoader.php
2 years ago
DailyShortCode.php
2 years ago
DigitalScreen.php
1 year ago
HijriDate.php
3 years ago
Init.php
4 years ago
MonthlyShortCode.php
2 years ago
MonthlyTimeTable.php
3 years ago
Shortcodes.php
2 years ago
Translator.php
4 years ago
UpdateStyles.php
2 years ago
Validator.php
3 years ago
db.php
3 years ago
dptWidget.php
4 years ago
DailyShortCode.php
548 lines
| 1 | <?php |
| 2 | require_once('db.php'); |
| 3 | require_once(__DIR__ .'/../Views/DailyTimetablePrinter.php'); |
| 4 | require_once(__DIR__ .'/../Views/TimetablePrinter.php' ); |
| 5 | require_once(__DIR__ .'/QuranADay/VersePrinter.php'); |
| 6 | require_once(__DIR__ .'/DPTHelper.php'); |
| 7 | |
| 8 | class DailyShortCode extends TimetablePrinter |
| 9 | { |
| 10 | /** @var boolean */ |
| 11 | private $isJamahOnly = false; |
| 12 | |
| 13 | /** @var boolean */ |
| 14 | private $isAzanOnly = false; |
| 15 | |
| 16 | /** @var boolean */ |
| 17 | private $isHanafiAsr = false; |
| 18 | |
| 19 | /** @var array */ |
| 20 | protected $row = array(); |
| 21 | |
| 22 | /** @var DailyTimetablePrinter */ |
| 23 | private $timetablePrinter; |
| 24 | |
| 25 | /** @var string */ |
| 26 | private $title; |
| 27 | |
| 28 | /** @var bool */ |
| 29 | private $hideRamadan = false; |
| 30 | |
| 31 | /** @var bool */ |
| 32 | private $hideTimeRemaining = false; |
| 33 | |
| 34 | /** @var bool */ |
| 35 | private $displayHijriDate = false; |
| 36 | |
| 37 | /** $var db */ |
| 38 | protected $db; |
| 39 | |
| 40 | /** $var bool */ |
| 41 | protected $deactivateTomorrow = false; |
| 42 | |
| 43 | /** @var bool */ |
| 44 | protected $clsPrayerFinished = ''; |
| 45 | |
| 46 | /** @var DPTHelper */ |
| 47 | protected $dptHelper; |
| 48 | |
| 49 | public function __construct() |
| 50 | { |
| 51 | $this->db = new DatabaseConnection(); |
| 52 | $this->row = $this->db->getPrayerTimeForToday(); |
| 53 | $this->timetablePrinter = new DailyTimetablePrinter(); |
| 54 | $this->deactivateTomorrow = get_option('tomorrow_time'); |
| 55 | $this->dptHelper = new DPTHelper(); |
| 56 | |
| 57 | parent::__construct(); |
| 58 | } |
| 59 | |
| 60 | public function setDeactivateTomorrow() |
| 61 | { |
| 62 | $this->deactivateTomorrow = true; |
| 63 | } |
| 64 | |
| 65 | public function setAnnouncement($text, $day) |
| 66 | { |
| 67 | $this->row['announcement'] = $this->getAnnouncement($day, $text); |
| 68 | } |
| 69 | |
| 70 | public function setJamahOnly() |
| 71 | { |
| 72 | $this->isJamahOnly = true; |
| 73 | } |
| 74 | |
| 75 | public function setAzanOnly() |
| 76 | { |
| 77 | $this->isAzanOnly = true; |
| 78 | } |
| 79 | |
| 80 | public function setHanafiAsr() |
| 81 | { |
| 82 | $this->isHanafiAsr = true; |
| 83 | } |
| 84 | |
| 85 | public function hideRamadan() |
| 86 | { |
| 87 | $this->hideRamadan = true; |
| 88 | } |
| 89 | |
| 90 | public function hideTimeRemaining() |
| 91 | { |
| 92 | $this->hideTimeRemaining = true; |
| 93 | } |
| 94 | |
| 95 | public function displayHijriDate() |
| 96 | { |
| 97 | $this->displayHijriDate = true; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @param array $attr |
| 102 | * @return string |
| 103 | */ |
| 104 | public function verticalTime($attr=array()) |
| 105 | { |
| 106 | $this->timetablePrinter->setVertical(true); |
| 107 | |
| 108 | $row = $this->getRow($attr); |
| 109 | |
| 110 | if ($this->isJamahOnly) { |
| 111 | return $this->timetablePrinter->verticalTimeJamahOnly($row); |
| 112 | } |
| 113 | |
| 114 | if ($this->isAzanOnly) { |
| 115 | return $this->timetablePrinter->verticalTimeAzanOnly($row); |
| 116 | } |
| 117 | |
| 118 | return $this->timetablePrinter->printVerticalTime($row); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @param array $attr |
| 123 | * @return string |
| 124 | */ |
| 125 | public function horizontalTime($attr=array()) |
| 126 | { |
| 127 | $this->timetablePrinter->setHorizontal(true); |
| 128 | |
| 129 | $row = $this->getRow($attr); |
| 130 | |
| 131 | if ($this->isJamahOnly) { |
| 132 | return $this->timetablePrinter->horizontalTimeJamahOnly($row); |
| 133 | } |
| 134 | |
| 135 | if ($this->isAzanOnly) { |
| 136 | return $this->timetablePrinter->horizontalTimeAzanOnly($row); |
| 137 | } |
| 138 | |
| 139 | if (isset($attr['use_div_layout'])) { |
| 140 | return $this->timetablePrinter->horizontalTimeDiv($row); |
| 141 | } |
| 142 | |
| 143 | return $this->timetablePrinter->printHorizontalTime($row); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @param string $widgetNotice |
| 148 | * @return string |
| 149 | */ |
| 150 | public function getAnnouncement($day, $widgetNotice="") |
| 151 | { |
| 152 | $widgetNotice = trim( $widgetNotice ); |
| 153 | $day = trim($day); |
| 154 | |
| 155 | if (empty($widgetNotice)) { |
| 156 | return ""; |
| 157 | } |
| 158 | |
| 159 | $today = date('l'); |
| 160 | $announcement = ""; |
| 161 | $exploded = explode(PHP_EOL, $widgetNotice); |
| 162 | foreach($exploded as $line) { |
| 163 | $announcement .= $line . "</br>"; |
| 164 | } |
| 165 | if ( $today == ucfirst( $day ) || $day == 'everyday' ) { |
| 166 | return trim($announcement); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @param string $title |
| 172 | */ |
| 173 | public function setTitle($title) |
| 174 | { |
| 175 | $this->title = $title; |
| 176 | } |
| 177 | |
| 178 | public function scNextPrayer($attr) |
| 179 | { |
| 180 | $row = $this->getRow($attr); |
| 181 | $row['displayHijriDate'] = $this->displayHijriDate; |
| 182 | if (isset($attr['display_dates'])) { |
| 183 | return $this->getNextIqamahTime($row, true); |
| 184 | } |
| 185 | return $this->getNextIqamahTime($row); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | public function scRamadanTime($attr) |
| 190 | { |
| 191 | $row = $this->getRow($attr); |
| 192 | |
| 193 | return $this->timetablePrinter->displayRamadanTime($row); |
| 194 | } |
| 195 | |
| 196 | public function scFajr($attr) |
| 197 | { |
| 198 | $jamah = $this->row['fajr_jamah']; |
| 199 | $begins = $this->row['fajr_begins']; |
| 200 | |
| 201 | if (! $this->deactivateTomorrow) { |
| 202 | |
| 203 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) { |
| 204 | $jamah = $this->row['tomorrow']['fajr_jamah']; |
| 205 | $begins = $this->row['tomorrow']['fajr_begins']; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | $result = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>"; |
| 210 | if ( isset($attr['start_time']) ) { |
| 211 | $result = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>" . $result; |
| 212 | } |
| 213 | return $result; |
| 214 | } |
| 215 | |
| 216 | public function scFajrStart($attr) |
| 217 | { |
| 218 | $begins = $this->row['fajr_begins']; |
| 219 | |
| 220 | if (! $this->deactivateTomorrow) { |
| 221 | |
| 222 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) { |
| 223 | $begins = $this->row['tomorrow']['fajr_begins']; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>"; |
| 228 | } |
| 229 | |
| 230 | public function scSunrise($attr) |
| 231 | { |
| 232 | $sunrise = $this->row['sunrise']; |
| 233 | |
| 234 | if (! $this->deactivateTomorrow) { |
| 235 | |
| 236 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($sunrise) ) { |
| 237 | $sunrise = $this->row['tomorrow']['sunrise']; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | return "<span class='dpt_sunrise " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($sunrise) . "</span>"; |
| 242 | } |
| 243 | |
| 244 | public function scZuhr($attr) |
| 245 | { |
| 246 | $jamah = $this->row['zuhr_jamah']; |
| 247 | $begins = $this->row['zuhr_begins']; |
| 248 | |
| 249 | if (! $this->deactivateTomorrow) { |
| 250 | |
| 251 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) { |
| 252 | $jamah = $this->row['tomorrow']['zuhr_jamah']; |
| 253 | $begins = $this->row['tomorrow']['zuhr_begins']; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | $result = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>"; |
| 258 | |
| 259 | if ( isset($attr['start_time']) ) { |
| 260 | $result = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>" . $result; |
| 261 | } |
| 262 | |
| 263 | return $result; |
| 264 | } |
| 265 | |
| 266 | public function scZuhrStart($attr) |
| 267 | { |
| 268 | $begins = $this->row['zuhr_begins']; |
| 269 | |
| 270 | if (! $this->deactivateTomorrow) { |
| 271 | |
| 272 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) { |
| 273 | $begins = $this->row['tomorrow']['zuhr_begins']; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | return "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>"; |
| 278 | } |
| 279 | |
| 280 | public function scAsr($attr) |
| 281 | { |
| 282 | $jamah = $this->row['asr_jamah']; |
| 283 | $begins = $this->row['asr_mithl_1']; |
| 284 | |
| 285 | |
| 286 | if (! $this->deactivateTomorrow) { |
| 287 | |
| 288 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) { |
| 289 | $jamah = $this->row['tomorrow']['asr_jamah']; |
| 290 | $begins = $this->row['tomorrow']['asr_mithl_1']; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | $result = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>"; |
| 295 | |
| 296 | if ( isset($attr['start_time']) ) { |
| 297 | $result = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>" . $result; |
| 298 | } |
| 299 | |
| 300 | return $result; |
| 301 | } |
| 302 | |
| 303 | public function scAsrStart($attr) |
| 304 | { |
| 305 | $begins = $this->row['asr_mithl_1']; |
| 306 | |
| 307 | if (! $this->deactivateTomorrow) { |
| 308 | |
| 309 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) { |
| 310 | $begins = $this->row['tomorrow']['asr_mithl_1']; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>"; |
| 315 | } |
| 316 | |
| 317 | public function scMaghrib($attr) |
| 318 | { |
| 319 | $jamah = $this->row['maghrib_jamah']; |
| 320 | $begins = $this->row['maghrib_begins']; |
| 321 | |
| 322 | if (! $this->deactivateTomorrow) { |
| 323 | |
| 324 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) { |
| 325 | $jamah = $this->row['tomorrow']['maghrib_jamah']; |
| 326 | $begins = $this->row['tomorrow']['maghrib_begins']; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | $result = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>"; |
| 331 | |
| 332 | if ( isset($attr['start_time']) ) { |
| 333 | $result = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>" . $result; |
| 334 | } |
| 335 | |
| 336 | return $result; |
| 337 | } |
| 338 | |
| 339 | public function scMaghribStart($attr) |
| 340 | { |
| 341 | $begins = $this->row['maghrib_begins']; |
| 342 | |
| 343 | if (! $this->deactivateTomorrow) { |
| 344 | |
| 345 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) { |
| 346 | $begins = $this->row['tomorrow']['maghrib_begins']; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | return "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>"; |
| 351 | } |
| 352 | |
| 353 | public function scIsha($attr) |
| 354 | { |
| 355 | $jamah = $this->row['isha_jamah']; |
| 356 | $begins = $this->row['isha_begins']; |
| 357 | |
| 358 | if (! $this->deactivateTomorrow) { |
| 359 | |
| 360 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) { |
| 361 | $jamah = $this->row['tomorrow']['isha_jamah']; |
| 362 | $begins = $this->row['tomorrow']['isha_begins']; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | $result = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>"; |
| 367 | |
| 368 | if ( isset($attr['start_time']) ) { |
| 369 | $result = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>" . $result; |
| 370 | } |
| 371 | |
| 372 | return $result; |
| 373 | } |
| 374 | |
| 375 | public function scIshaStart($attr) |
| 376 | { |
| 377 | $begins = $this->row['isha_begins']; |
| 378 | |
| 379 | if (! $this->deactivateTomorrow) { |
| 380 | |
| 381 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) { |
| 382 | $begins = $this->row['tomorrow']['isha_begins']; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | return "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>"; |
| 387 | } |
| 388 | |
| 389 | public function scJummahPrayer($attr) |
| 390 | { |
| 391 | return " |
| 392 | <span class='jummahShortcode'> |
| 393 | <span class='jummahHeading'>" |
| 394 | . stripslashes($this->getLocalHeaders()['jumuah']) . " |
| 395 | </span> |
| 396 | <span class='jummahPrayer'>" |
| 397 | . $this->getJumuahTimesArray() . " |
| 398 | </span> |
| 399 | </span>"; |
| 400 | } |
| 401 | |
| 402 | public function scZawal($attr) |
| 403 | { |
| 404 | $zuhrBegins = $this->row['zuhr_begins']; |
| 405 | if (isset($attr['zuhr_begins'])) { |
| 406 | $zuhrBegins = $attr['zuhr_begins']; |
| 407 | } |
| 408 | $zawal = $this->dptHelper->getZawalTime($zuhrBegins); |
| 409 | |
| 410 | if (! $this->deactivateTomorrow) { |
| 411 | |
| 412 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($zuhrBegins) ) { |
| 413 | $zuhrBegins = $this->row['tomorrow']['zuhr_begins']; |
| 414 | |
| 415 | $zawal = $this->dptHelper->getZawalTime($zuhrBegins); |
| 416 | |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | return "<span class='dpt_sunrise " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($zawal) . "</span>"; |
| 421 | } |
| 422 | |
| 423 | private function isPrayerFinished($time) |
| 424 | { |
| 425 | $userTime = user_current_time( 'H:i'); |
| 426 | $now = new DateTime(); |
| 427 | $now->setTimestamp(strtotime($userTime)); |
| 428 | |
| 429 | $prayerTime = new DateTime(); |
| 430 | $prayerTime->setTimestamp(strtotime($time)); |
| 431 | |
| 432 | if ($now > $prayerTime) { |
| 433 | $this->clsPrayerFinished = 'prayerFinished'; |
| 434 | return true; |
| 435 | } |
| 436 | |
| 437 | $this->clsPrayerFinished = ''; |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | public function scIqamahUpdate($attr) |
| 442 | { |
| 443 | $min = isset($attr['threshold']) ? (int) $attr['threshold'] : 1; |
| 444 | |
| 445 | $row['jamah_changes'] = $this->db->getJamahChanges($min); |
| 446 | |
| 447 | if (empty($row['jamah_changes'])) { return; } |
| 448 | |
| 449 | $orientation = isset($attr['orientation']) ? esc_attr($attr['orientation']) : ''; |
| 450 | |
| 451 | return $this->getJamahChange($row, true, $orientation); |
| 452 | } |
| 453 | |
| 454 | public function scDigitalScreen($attr) |
| 455 | { |
| 456 | $ds = new DigitalScreen($attr); |
| 457 | |
| 458 | return $ds->displayDigitalScreen(); |
| 459 | } |
| 460 | |
| 461 | public function scQuranVarse($attr) |
| 462 | { |
| 463 | $verse = new VersePrinter(); |
| 464 | |
| 465 | return $verse->printVerse($attr); |
| 466 | } |
| 467 | |
| 468 | public function scHijriDate($attr) |
| 469 | { |
| 470 | return "<span class='scHijriDate'>" . $this->hijriDate->getToday() . "</span>"; |
| 471 | } |
| 472 | |
| 473 | protected function getRow($attr=array()) |
| 474 | { |
| 475 | |
| 476 | $this->setDisplayForShortCode($attr); |
| 477 | |
| 478 | if (isset($attr['asr'])) { |
| 479 | $this->setHanafiAsr(); |
| 480 | } |
| 481 | |
| 482 | if (isset($attr['heading'])) { |
| 483 | $this->setTitle(esc_attr($attr['heading'])); |
| 484 | } |
| 485 | |
| 486 | $row = $this->row; |
| 487 | |
| 488 | if (isset($attr['announcement'])) { |
| 489 | $day = isset($attr['day']) ? esc_attr($attr['day']) : 'everyday'; |
| 490 | $row['announcement'] = $this->getAnnouncement($day, esc_attr($attr['announcement'])); |
| 491 | } |
| 492 | |
| 493 | if ( $row['jamah_changes']) { |
| 494 | $row['announcement'] .= $this->timetablePrinter->getJamahChange($this->row); |
| 495 | } |
| 496 | |
| 497 | $row['widgetTitle'] = $this->title; |
| 498 | $row['asr_begins'] = $this->isHanafiAsr ? $this->row['asr_mithl_2'] : $this->row['asr_mithl_1']; |
| 499 | |
| 500 | $row['hideRamadan'] = $this->hideRamadan; |
| 501 | $row['hideTimeRemaining'] = $this->hideTimeRemaining; |
| 502 | $row['displayHijriDate'] = $this->displayHijriDate; |
| 503 | $row['nextFajr'] = $this->db->getFajrJamahForTomorrow(); |
| 504 | |
| 505 | return $row; |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * @param array $attr |
| 510 | */ |
| 511 | private function setDisplayForShortCode($attr) |
| 512 | { |
| 513 | if (isset($attr['display'])) { |
| 514 | if ( $attr['display'] === 'iqamah_only' ) { |
| 515 | $this->setJamahOnly(); |
| 516 | $this->isAzanOnly = false; |
| 517 | } elseif ( $attr['display'] === 'azan_only' ) { |
| 518 | $this->setAzanOnly(); |
| 519 | $this->isJamahOnly = false; |
| 520 | } |
| 521 | } else { |
| 522 | $this->isJamahOnly = false; |
| 523 | $this->isAzanOnly = false; |
| 524 | } |
| 525 | |
| 526 | if (isset($attr['hide_time_remaining'])) { |
| 527 | $this->hideTimeRemaining(); |
| 528 | } |
| 529 | |
| 530 | if (isset($attr['hide_ramadan'])) { |
| 531 | $this->hideRamadan(); |
| 532 | } |
| 533 | |
| 534 | $hijriCheckbox = get_option('hijri-chbox'); |
| 535 | if (! empty($hijriCheckbox)) { |
| 536 | $this->displayHijriDate(); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | public function getFajrBegins() |
| 541 | { |
| 542 | $begins = $this->row['fajr_begins']; |
| 543 | if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) { |
| 544 | $begins = $this->row['tomorrow']['fajr_begins']; |
| 545 | } |
| 546 | return $begins; |
| 547 | } |
| 548 | } |