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