PluginProbe ʕ •ᴥ•ʔ
Daily Prayer Time / 2026.05.20
Daily Prayer Time v2026.05.20
2026.05.20 2026.05.11 2026.05.09 2026.05.05 2026.05.04 2026.05.03 2026.04.28 2026.04.28.1 trunk 2019.10.16 2019.11.19 2019.2.16 2019.3.1 2019.4.1 2019.4.5 2019.5.12 2019.5.13 2019.5.14 2019.5.19 2019.5.19.1 2019.5.21 2019.5.30 2019.5.5 2019.5.6 2019.5.7 2019.5.8 2019.5.9 2019.6.10 2019.6.2 2019.6.22 2019.7.10 2019.7.25 2019.8.1 2019.8.4 2019.9.16 2020.04.25 2020.04.26 2020.05.01 2020.05.04 2020.05.08 2020.05.17 2020.07.03 2021.01.10 2021.03.28 2021.07.20 2021.07.23 2021.07.24 2021.07.28 2021.08.01 2021.08.06 2021.08.07 2021.08.10 2021.09.12 2021.09.18 2021.09.23 2021.09.24 2021.10.01 2021.10.02 2021.10.10 2021.10.11 2021.10.15 2021.10.21 2021.10.27 2021.10.29 2022.03.24 2022.04.04 2022.04.14 2022.04.15 2022.04.21 2022.04.22 2022.05.04 2022.09.19 2022.11.14 2022.11.16 2022.12.18 2022.12.20 2023.01.27 2023.02.04 2023.02.09 2023.02.21 2023.03.08 2023.03.17 2023.03.18 2023.03.20 2023.05.04 2023.08.03 2023.08.08.16 2023.08.19 2023.08.19.1 2023.10.13 2023.10.21 2023.11.26 2023.12.28 2023.12.31 2024.03.28 2024.03.29 2024.03.30 2024.04.18 2024.04.20 2024.04.22 2024.04.26 2024.08.26 2024.09.12 2024.09.14 2024.09.17 2024.12.29 2024.12.30 2025.01.02 2025.01.17 2025.02.02 2025.03.04 2025.03.06 2025.03.08 2025.03.15 2025.03.20 2025.03.26 2025.03.27 2025.04.03 2025.06.16 2025.06.29 2025.07.15 2025.08.09 2025.10.26 2026.04.26
daily-prayer-time-for-mosques / Models / DailyShortCode.php
daily-prayer-time-for-mosques / Models Last commit date
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
DailyShortCode.php
616 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 bool */
38 private $showJumuah = false;
39
40 /** $var db */
41 protected $db;
42
43 /** $var bool */
44 protected $deactivateTomorrow = false;
45
46 /** @var bool */
47 protected $clsPrayerFinished = '';
48
49 /** @var DPTHelper */
50 protected $dptHelper;
51
52 public function __construct()
53 {
54 $this->db = new DatabaseConnection();
55 $this->row = $this->db->getPrayerTimeForToday();
56 $this->timetablePrinter = new DailyTimetablePrinter();
57 $this->deactivateTomorrow = get_option('tomorrow_time');
58 $this->dptHelper = new DPTHelper();
59
60 parent::__construct();
61 }
62
63 public function setDeactivateTomorrow()
64 {
65 $this->deactivateTomorrow = true;
66 }
67
68 public function setAnnouncement($text, $day)
69 {
70 $this->row['announcement'] = $this->getAnnouncement($day, $text);
71 }
72
73 public function setJamahOnly()
74 {
75 $this->isJamahOnly = true;
76 }
77
78 public function setAzanOnly()
79 {
80 $this->isAzanOnly = true;
81 }
82
83 public function setHanafiAsr()
84 {
85 if ($this->getAsrMethod() == 'asr_mithl_2') {
86 $this->isHanafiAsr = true;
87 }
88 }
89
90 public function hideRamadan()
91 {
92 $this->hideRamadan = true;
93 }
94
95 public function hideTimeRemaining()
96 {
97 $this->hideTimeRemaining = true;
98 }
99
100 public function displayHijriDate()
101 {
102 $this->displayHijriDate = true;
103 }
104
105 public function showJumuah()
106 {
107 $this->showJumuah = true;
108 }
109
110 /**
111 * @param array $attr
112 * @return string
113 */
114 public function verticalTime($attr=array())
115 {
116 $this->timetablePrinter->setVertical(true);
117
118 $row = $this->getRow($attr);
119
120 if ($this->isJamahOnly) {
121 return $this->timetablePrinter->verticalTimeJamahOnly($row);
122 }
123
124 if ($this->isAzanOnly) {
125 return $this->timetablePrinter->verticalTimeAzanOnly($row);
126 }
127
128 return $this->timetablePrinter->printVerticalTime($row);
129 }
130
131 /**
132 * @param array $attr
133 * @return string
134 */
135 public function horizontalTime($attr=array())
136 {
137 $this->timetablePrinter->setHorizontal(true);
138
139 $row = $this->getRow($attr);
140
141 if ($this->isJamahOnly) {
142 return $this->timetablePrinter->horizontalTimeJamahOnly($row);
143 }
144
145 if ($this->isAzanOnly) {
146 return $this->timetablePrinter->horizontalTimeAzanOnly($row);
147 }
148
149 if (isset($attr['use_div_layout'])) {
150 return $this->timetablePrinter->horizontalTimeDiv($row);
151 }
152
153 return $this->timetablePrinter->printHorizontalTime($row);
154 }
155
156 /**
157 * @param string $widgetNotice
158 * @return string
159 */
160 public function getAnnouncement($day, $widgetNotice="")
161 {
162 $widgetNotice = trim( $widgetNotice );
163 $day = trim($day);
164
165 if (empty($widgetNotice)) {
166 return "";
167 }
168
169 $today = date('l');
170 $announcement = "";
171 $exploded = explode(PHP_EOL, $widgetNotice);
172 foreach($exploded as $line) {
173 $announcement .= $line . "</br>";
174 }
175 if ( $today == ucfirst( $day ) || $day == 'everyday' ) {
176 return trim($announcement);
177 }
178 }
179
180 /**
181 * @param string $title
182 */
183 public function setTitle($title)
184 {
185 $this->title = $title;
186 }
187
188 public function scNextPrayer($attr)
189 {
190 $row = $this->getRow($attr);
191 $row['displayHijriDate'] = $this->displayHijriDate;
192 if (isset($attr['display_dates'])) {
193 return $this->getNextIqamahTime($row, true);
194 }
195 return $this->getNextIqamahTime($row);
196 }
197
198
199 public function scRamadanTime($attr)
200 {
201 $row = $this->getRow($attr);
202
203 return $this->timetablePrinter->displayRamadanTime($row);
204 }
205
206 public function scFajr($attr)
207 {
208 $jamah = $this->row['fajr_jamah'];
209 $begins = $this->row['fajr_begins'];
210
211 if (! $this->deactivateTomorrow) {
212
213 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) {
214 $jamah = $this->row['tomorrow']['fajr_jamah'];
215 $begins = $this->row['tomorrow']['fajr_begins'];
216 }
217 }
218
219 $result = "<span class='scFajr " . $this->dptHelper->getNextPrayerClass('fajr', $this->row, true) ."'>";
220
221 $start = '';
222 $jamah = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>";
223 if ( isset($attr['start_time']) ) {
224 $start = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>";
225 }
226
227 return $result . $start . $jamah . "</span>";
228 }
229
230 public function scFajrStart($attr)
231 {
232 $begins = $this->row['fajr_begins'];
233
234 if (! $this->deactivateTomorrow) {
235
236 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) {
237 $begins = $this->row['tomorrow']['fajr_begins'];
238 }
239 }
240
241 return "<span class='dpt_start " . $this->clsPrayerFinished . " " . $this->dptHelper->getNextPrayerClass('fajr', $this->row, true) ."'>" . $this->formatDateForPrayer($begins) . "</span>";
242 }
243
244 public function scSunrise($attr)
245 {
246 $sunrise = $this->row['sunrise'];
247
248 if (! $this->deactivateTomorrow) {
249
250 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($sunrise) ) {
251 $sunrise = $this->row['tomorrow']['sunrise'];
252 }
253 }
254
255 return "<span class='dpt_sunrise " . $this->clsPrayerFinished . " ". $this->getNextPrayerClass('sunrise', $this->row) ."'>" . $this->formatDateForPrayer($sunrise) . "</span>";
256 }
257
258 public function scZuhr($attr)
259 {
260 $jamah = $this->row['zuhr_jamah'];
261 $begins = $this->row['zuhr_begins'];
262
263 if (! $this->deactivateTomorrow) {
264
265 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) {
266 $jamah = $this->row['tomorrow']['zuhr_jamah'];
267 $begins = $this->row['tomorrow']['zuhr_begins'];
268 }
269 }
270
271 $result = "<span class='scZuhr " . $this->dptHelper->getNextPrayerClass('zuhr', $this->row) ."'>";
272 $start = '';
273 $jamah = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>";
274
275 if ( isset($attr['start_time']) ) {
276 $start = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>";
277 }
278
279 return $result . $start . $jamah . "</span>";
280
281 }
282
283 public function scZuhrStart($attr)
284 {
285 $begins = $this->row['zuhr_begins'];
286
287 if (! $this->deactivateTomorrow) {
288
289 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) {
290 $begins = $this->row['tomorrow']['zuhr_begins'];
291 }
292 }
293
294 return "<span class='dpt_start " . $this->clsPrayerFinished . " " . $this->dptHelper->getNextPrayerClass('zuhr', $this->row) ."'>" . $this->formatDateForPrayer($begins) . "</span>";
295 }
296
297 public function scAsr($attr)
298 {
299 $method = $this->getAsrMethod($attr);
300 $jamah = $this->row['asr_jamah'];
301 $begins = $this->row[$method];
302
303
304 if (! $this->deactivateTomorrow) {
305
306 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) {
307 $jamah = $this->row['tomorrow']['asr_jamah'];
308 $begins = $this->row['tomorrow'][$method];
309 }
310 }
311
312 $result = "<span class='scAsr " . $this->dptHelper->getNextPrayerClass('asr', $this->row) ."'>";
313 $start = '';
314 $jamah = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>";
315
316 if ( isset($attr['start_time']) ) {
317 $start = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>";
318 }
319
320 return $result . $start . $jamah . "</span>";
321 }
322
323 public function scAsrStart($attr)
324 {
325 $method = $this->getAsrMethod($attr);
326
327 $begins = $this->row[$method];
328
329 if (! $this->deactivateTomorrow) {
330
331 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) {
332 $begins = $this->row['tomorrow'][$method];
333 }
334 }
335
336 return "<span class='dpt_start " . $this->clsPrayerFinished . " " . $this->dptHelper->getNextPrayerClass('asr', $this->row) ."'>" . $this->formatDateForPrayer($begins) . "</span>";
337 }
338
339 private function getAsrMethod($attr=array())
340 {
341 if (isset($attr['asr'])) {
342 return 'asr_mithl_2';
343 }
344 return get_option('asrSelect') == 'hanafi' ? 'asr_mithl_2' : 'asr_mithl_1';
345
346 }
347
348 public function scMaghrib($attr)
349 {
350 $jamah = $this->row['maghrib_jamah'];
351 $begins = $this->row['maghrib_begins'];
352
353 if (! $this->deactivateTomorrow) {
354
355 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) {
356 $jamah = $this->row['tomorrow']['maghrib_jamah'];
357 $begins = $this->row['tomorrow']['maghrib_begins'];
358 }
359 }
360
361 $result = "<span class='scMaghrib " . $this->dptHelper->getNextPrayerClass('maghrib', $this->row) ."'>";
362 $start = '';
363 $jamah = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>";
364
365 if ( isset($attr['start_time']) ) {
366 $start = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>";
367 }
368
369 return $result . $start . $jamah . "</span>";
370 }
371
372 public function scMaghribStart($attr)
373 {
374 $begins = $this->row['maghrib_begins'];
375
376 if (! $this->deactivateTomorrow) {
377
378 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) {
379 $begins = $this->row['tomorrow']['maghrib_begins'];
380 }
381 }
382
383 return "<span class='dpt_start " . $this->clsPrayerFinished . " " . $this->dptHelper->getNextPrayerClass('maghrib', $this->row) ."'>" . $this->formatDateForPrayer($begins) . "</span>";
384 }
385
386 public function scIsha($attr)
387 {
388 $jamah = $this->row['isha_jamah'];
389 $begins = $this->row['isha_begins'];
390
391 if (! $this->deactivateTomorrow) {
392
393 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($jamah) ) {
394 $jamah = $this->row['tomorrow']['isha_jamah'];
395 $begins = $this->row['tomorrow']['isha_begins'];
396 }
397 }
398
399 $result = "<span class='scIsha " . $this->dptHelper->getNextPrayerClass('isha', $this->row) ."'>";
400 $start = '';
401 $jamah = "<span class='dpt_jamah " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($jamah) . "</span>";
402
403 if ( isset($attr['start_time']) ) {
404 $start = "<span class='dpt_start " . $this->clsPrayerFinished . "'>" . $this->formatDateForPrayer($begins) . "</span>";
405 }
406
407 return $result . $start . $jamah . "</span>";
408 }
409
410 public function scIshaStart($attr)
411 {
412 $begins = $this->row['isha_begins'];
413
414 if (! $this->deactivateTomorrow) {
415
416 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) {
417 $begins = $this->row['tomorrow']['isha_begins'];
418 }
419 }
420
421 return "<span class='dpt_start " . $this->clsPrayerFinished . " " . $this->dptHelper->getNextPrayerClass('isha', $this->row) ."'>" . $this->formatDateForPrayer($begins) . "</span>";
422 }
423
424 public function scJummahPrayer($attr)
425 {
426 return "
427 <span class='jummahShortcode'>
428 <span class='jummahHeading'>"
429 . stripslashes($this->getLocalHeaders()['jumuah']) . "
430 </span>
431 <span class='jummahPrayer'>"
432 . $this->getJumuahTimesArray() . "
433 </span>
434 </span>";
435 }
436
437 public function scZawal($attr)
438 {
439 $zuhrBegins = $this->row['zuhr_begins'];
440 if (isset($attr['zuhr_begins'])) {
441 $zuhrBegins = $attr['zuhr_begins'];
442 }
443 $zawal = $this->dptHelper->getZawalTime($zuhrBegins);
444
445 if (! $this->deactivateTomorrow) {
446
447 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($zuhrBegins) ) {
448 $zuhrBegins = $this->row['tomorrow']['zuhr_begins'];
449
450 $zawal = $this->dptHelper->getZawalTime($zuhrBegins);
451
452 }
453 }
454
455 return "<span class='dpt_sunrise "
456 . $this->clsPrayerFinished . " "
457 . $this->dptHelper->getNextPrayerClass('zawal', $this->row) ."'>"
458 . $this->formatDateForPrayer($zawal)
459 . "</span>";
460 }
461
462 public function scIshraq($attr)
463 {
464 $sunrise = $this->row['sunrise'];
465 if (isset($attr['sunrise'])) {
466 $sunrise = $attr['sunrise'];
467 }
468 $ishraq = $this->dptHelper->getIshraqTime($sunrise);
469
470 if (! $this->deactivateTomorrow) {
471
472 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($sunrise) ) {
473 $sunrise = $this->row['tomorrow']['sunrise'];
474 $ishraq = $this->dptHelper->getIshraqTime($sunrise);
475 }
476 }
477
478 return "<span class='dpt_ishraq "
479 . $this->clsPrayerFinished . " "
480 . $this->dptHelper->getNextPrayerClass('ishraq', $this->row) ."'>"
481 . $this->formatDateForPrayer($ishraq)
482 . "</span>";
483 }
484
485 private function isPrayerFinished($time)
486 {
487 $userTime = user_current_time( 'H:i');
488 $now = new DateTime();
489 $now->setTimestamp(strtotime($userTime));
490
491 $prayerTime = new DateTime();
492 $prayerTime->setTimestamp(strtotime($time));
493
494 if ($now > $prayerTime) {
495 $this->clsPrayerFinished = 'prayerFinished';
496 return true;
497 }
498
499 $this->clsPrayerFinished = '';
500 return false;
501 }
502
503 public function scIqamahUpdate($attr)
504 {
505 $min = isset($attr['threshold']) ? (int) $attr['threshold'] : 1;
506
507 $row['jamah_changes'] = $this->db->getJamahChanges($min);
508
509 if (empty($row['jamah_changes'])) { return; }
510
511 $orientation = isset($attr['orientation']) ? esc_attr($attr['orientation']) : '';
512
513 return $this->getJamahChange($row, true, $orientation);
514 }
515
516 public function scDigitalScreen($attr)
517 {
518 $ds = new DigitalScreen($attr);
519
520 return $ds->displayDigitalScreen();
521 }
522
523 public function scQuranVarse($attr)
524 {
525 $verse = new VersePrinter();
526
527 return $verse->printVerse($attr);
528 }
529
530 public function scHijriDate($attr)
531 {
532 return "<span class='scHijriDate'>" . $this->hijriDate->getToday() . "</span>";
533 }
534
535 protected function getRow($attr=array())
536 {
537 if (!$this->isAzanOnly && !$this->isJamahOnly) {
538 $this->setDisplayForShortCode($attr);
539 }
540
541 $this->isHanafiAsr = isset($attr['asr']) ? true : $this->setHanafiAsr();
542
543 if (isset($attr['heading'])) {
544 $this->setTitle(esc_attr($attr['heading']));
545 }
546
547 $row = $this->row;
548
549 if (isset($attr['announcement'])) {
550 $day = isset($attr['day']) ? esc_attr($attr['day']) : 'everyday';
551 $row['announcement'] = $this->getAnnouncement($day, esc_attr($attr['announcement']));
552 }
553
554 if ( $row['jamah_changes']) {
555 $row['announcement'] .= $this->timetablePrinter->getJamahChange($this->row);
556 }
557
558 $row['widgetTitle'] = $this->title;
559 $row['asr_begins'] = $this->isHanafiAsr ? $this->row['asr_mithl_2'] : $this->row['asr_mithl_1'];
560
561 $row['hideRamadan'] = $this->hideRamadan;
562 $row['hideTimeRemaining'] = $this->hideTimeRemaining;
563 $row['displayHijriDate'] = $this->displayHijriDate;
564 $row['showJumuah'] = $this->showJumuah;
565 $row['nextFajr'] = $this->db->getFajrJamahForTomorrow();
566
567 return $row;
568 }
569
570 /**
571 * @param array $attr
572 */
573 private function setDisplayForShortCode($attr)
574 {
575 if (isset($attr['display'])) {
576 if ( $attr['display'] === 'iqamah_only' ) {
577 $this->setJamahOnly();
578 $this->isAzanOnly = false;
579 } elseif ( $attr['display'] === 'azan_only' ) {
580 $this->setAzanOnly();
581 $this->isJamahOnly = false;
582 }
583 } else {
584 $this->isJamahOnly = false;
585 $this->isAzanOnly = false;
586 }
587
588 if (isset($attr['hide_time_remaining'])) {
589 $this->hideTimeRemaining();
590 }
591
592 if (isset($attr['hide_ramadan'])) {
593 $this->hideRamadan();
594 }
595
596 if (isset($attr['show_jumuah']) || isset($attr['showJumuah'])) {
597 $this->showJumuah();
598 } else {
599 $this->showJumuah = false;
600 }
601
602 $hijriCheckbox = get_option('hijri-chbox');
603 if (! empty($hijriCheckbox)) {
604 $this->displayHijriDate();
605 }
606 }
607
608 public function getFajrBegins()
609 {
610 $begins = $this->row['fajr_begins'];
611 if ( isset($this->row['tomorrow']) && $this->isPrayerFinished($begins) ) {
612 $begins = $this->row['tomorrow']['fajr_begins'];
613 }
614 return $begins;
615 }
616 }