PluginProbe ʕ •ᴥ•ʔ
Daily Prayer Time / 2023.12.31
Daily Prayer Time v2023.12.31
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 / Views / TimetablePrinter.php
daily-prayer-time-for-mosques / Views Last commit date
Tabs 2 years ago DSTemplate.php 3 years ago DailyTimetablePrinter.php 3 years ago HelpsAndTips.php 3 years ago MonthlyTimetablePrinter.php 2 years ago TimetablePrinter.php 3 years ago dptWidgetForm.php 4 years ago horizontal-div.php 4 years ago widget-admin.php 3 years ago
TimetablePrinter.php
633 lines
1 <?php
2
3 require_once(__DIR__ . '/../Models/HijriDate.php');
4 require_once(__DIR__ . '/../Models/DPTHelper.php');
5
6 class TimetablePrinter
7 {
8 protected $prayerLocal = array(
9 "fajr" => "Fajr",
10 "sunrise" => "Sunrise",
11 "zuhr" => "Zuhr",
12 "asr" => "Asr",
13 "maghrib" => "Maghrib",
14 "isha" => "Isha"
15 );
16
17 protected $headersLocal = array(
18 "prayer" => "Prayer",
19 "begins" => "Begins",
20 "iqamah" => "Iqamah",
21 "standard" => "Standard",
22 "hanafi" => "Hanafi",
23 "fast_begins" => "Suhoor End",
24 "fast_ends" => "Iftar Start",
25 "jumuah" => "Jumuah"
26 );
27
28 protected $numbersLocal = array(
29 0 => '0',
30 1 => '1',
31 2 => '2',
32 3 => '3',
33 4 => '4',
34 5 => '5',
35 6 => '6',
36 7 => '7',
37 8 => '8',
38 9 => '9'
39 );
40
41 protected $monthsLocal = array(
42 'january' => 'January',
43 'february' => 'February',
44 'march' => 'March',
45 'april' => 'April',
46 'may' => 'May',
47 'june' => 'June',
48 'july' => 'July',
49 'august' => 'August',
50 'september' => 'September',
51 'october' => 'October',
52 'november' => 'November',
53 'december' => 'December'
54 );
55
56
57 /** @var array */
58 protected $timesLocal = array(
59 'date' => 'Date',
60 'day' => 'Day',
61 'minute' => 'Minutes',
62 'hours' => 'Hours',
63 'iqamah update' => 'IQAMAH CHANGES:',
64 'next prayer' => 'Next ...'
65 );
66
67 /** @var string */
68 protected $tableClass;
69
70 /** @var array */
71 protected $localPrayerNames;
72
73 /** @var array */
74 protected $localHeaders;
75
76 /** @var array */
77 protected $localNumbers;
78
79 /** @var array */
80 protected $localTimes;
81
82 /** @var HijriDate */
83 protected $hijriDate;
84
85 /** @var string */
86 protected $hijridateString;
87
88 /** $var bool */
89 protected $isVertical = false;
90
91 /** $var bool */
92 protected $isHorizontal = false;
93
94 /** @var DPTHelper */
95 private $dptHelper;
96
97 public function __construct()
98 {
99 $this->localPrayerNames = $this->getLocalPrayerNames();
100 $this->localHeaders = $this->getLocalHeaders();
101 $this->localNumbers = $this->getLocalNumbers();
102 $this->localTimes = $this->getLocalTimes();
103 $this->dptHelper = new DPTHelper();
104 $this->hijriDate = new HijriDate();
105 $this->hijridateString = $this->hijriDate->getDate(date("d"), date("m"), date("Y"), true);
106 }
107
108 public function getTableClass()
109 {
110 return get_option('hideTableBorder');
111 }
112
113 public function getLocalPrayerNames($forAdmin=false, $enableJumuah=false)
114 {
115 $prayers_local = get_option('prayersLocal');
116
117 $localPrayerName = $prayers_local;
118 if ( empty($prayers_local)) {
119 $localPrayerName = $this->prayerLocal;
120 } elseif (count($prayers_local) != count($this->prayerLocal)) {
121 delete_option( 'prayersLocal' );
122 $localPrayerName = $this->prayerLocal;
123 }
124
125 if (! $forAdmin && $enableJumuah){
126 if ($this->todayIsFriday()) {
127 $localPrayerName['zuhr'] = $this->getLocalHeaders()['jumuah'];
128 }
129 }
130
131 if (is_array($localPrayerName)) {
132 $localPrayerName = array_map( 'sanitize_text_field', $localPrayerName);
133 $localPrayerName = array_map('stripslashes', $localPrayerName);
134 }
135
136 return $localPrayerName;
137 }
138
139 public function getLocalHeaders()
140 {
141 $headers_local = get_option('headersLocal');
142
143 if ( empty($headers_local)) {
144 return $this->headersLocal;
145 } elseif (count($headers_local) != count($this->headersLocal)) {
146 delete_option( 'headersLocal' );
147 return $this->headersLocal;
148 }
149
150 if (is_array($headers_local)) {
151 $headers_local = array_map( 'sanitize_text_field', $headers_local);
152 $headers_local = array_map('stripslashes', $headers_local);
153 }
154
155 return $headers_local;
156 }
157
158 public function getLocalMonths()
159 {
160 $monthsLocal = get_option('monthsLocal');
161
162 if ( empty( $monthsLocal )) {
163 $monthsLocal = $this->monthsLocal;
164 }
165
166 if ( $this->isRamadan() ) {
167 $monthsLocal['ramadan'] = 'Ramadan';
168 } else {
169 unset( $monthsLocal['ramadan'] );
170 }
171
172 if (is_array($monthsLocal)) {
173 $monthsLocal = array_map( 'sanitize_text_field', $monthsLocal);
174 $monthsLocal = array_map('stripslashes', $monthsLocal);
175 }
176
177 return $monthsLocal;
178 }
179
180 public function getLocalNumbers()
181 {
182 $numbers_local = get_option('numbersLocal');
183 if (is_array($numbers_local)) {
184 $numbers_local = array_map( 'sanitize_text_field', $numbers_local);
185 }
186
187 return empty($numbers_local) ? $this->numbersLocal : $numbers_local;
188 }
189
190
191 public function getLocalTimes()
192 {
193 $times = get_option('timesLocal');
194 if (is_array($times)) {
195 $times = array_map( 'sanitize_text_field', $times);
196 }
197
198 if ( empty($times)) {
199 return $this->timesLocal;
200 } elseif (count($times) != count($this->timesLocal)) {
201 delete_option( 'timesLocal' );
202 return $this->timesLocal;
203 }
204
205 return $times;
206 }
207
208 public function setVertical($value=true)
209 {
210 $this->isVertical = $value;
211 }
212
213 public function setHorizontal($value=true)
214 {
215 $this->isHorizontal = $value;
216 }
217
218 /**
219 * @param string $mysqlDate
220 * @param string $format
221 * @return string
222 */
223 public function formatDate($mysqlDate, $format=null)
224 {
225 return $this->dptHelper->formatDate($mysqlDate, $format);
226 }
227
228 /**
229 * @param string $mysqlDate
230 * @return string
231 */
232 public function formatDateForPrayer($mysqlDate, $imsak=false)
233 {
234 $phpDate = strtotime($mysqlDate);
235 if ($imsak) {
236 $phpDate = $phpDate - ((int)get_option('imsaq') * 60);
237 }
238 $wpDate = date(get_option('time_format'), $phpDate);
239
240 $result = str_split($wpDate);
241 $intlDate = '';
242 $this->localNumbers = $this->getLocalNumbers();
243 foreach ($result as $number) {
244 if (in_array($number, $this->localNumbers)) {
245 $intlDate .= $this->localNumbers[$number];
246 if (empty($this->localNumbers[$number]) && $number !== '0') {
247 $intlDate .= $number;
248 }
249 } else {
250 $intlDate .= $number;
251 }
252 }
253
254 return $intlDate;
255 }
256
257 public function getIntlNumber($numbers)
258 {
259 $intlDate = '';
260
261 $this->localNumbers = $this->getLocalNumbers();
262 $result = str_split($numbers);
263 foreach ($result as $number) {
264 $intlDate .= $this->localNumbers[$number];
265 if (empty($this->localNumbers[$number]) && $number !== '0') {
266 $intlDate .= $number;
267 }
268 }
269
270 return $intlDate;
271 }
272
273 /**
274 * @param string $month
275 * @param string $day
276 * @return string
277 */
278 protected function getClass($month, $day)
279 {
280 if ($day == user_current_time('j') && $month == user_current_time('m')){
281 return "class = highlight";
282 }
283 }
284
285 /**
286 * @param bool $isRamadan
287 * @param array $data
288 * @param bool $azanOnly
289 * @return string|null
290 */
291 protected function getFastingTdWithData($isRamadan, $data, $azanOnly=null, $imsaq=false)
292 {
293 $html = "";
294
295 if ($this->isRamadan() && ! $azanOnly && $imsaq) {
296 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data, $imsaq) . "</td>";
297 } elseif ($this->isRamadan() && $imsaq) {
298 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data, $imsaq). "</td>";
299 $html .= "<td>" . $this->formatDateForPrayer($data). "</td>";
300
301 } elseif ($this->isRamadan() && ! $imsaq) {
302 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data). "</td>";
303 } elseif ($this->isRamadan() && ! $azanOnly && $imsaq) {
304 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data). "</td>";
305 } elseif ($azanOnly) {
306 $html = "<td>" . $this->formatDateForPrayer($data). "</td>";
307 }
308
309 return $html;
310 }
311
312 /**
313 * @param array $row
314 * @param bool $displayDates
315 * @param bool $apiCall
316 * @return string
317 */
318 public function getNextIqamahTime(array $row, $displayDates=false, $apiCall=false)
319 {
320 $diff = $this->getNextIqamahTimeDiff($row);
321 $nextPrayer = $this->getNextPrayer($row);
322
323 if ($apiCall) {
324 return [
325 'prayerName' => $nextPrayer,
326 'timeLeft' => $diff
327 ];
328 }
329
330 $hijriDate = '';
331 if($row['displayHijriDate']) {
332 $hijriDate = $this->hijriDate->getDate(date("d"), date("m"), date("Y"), true);
333 }
334
335 $printDates = '';
336 if ($displayDates) {
337 $printDates = '<div>
338 <span class="scDate">
339 ' . date_i18n( get_option( 'date_format' ) ) . '
340 </span>
341 <span class="scHijri">
342 ' . $hijriDate . '
343 </span>';
344 }
345
346 return
347 $printDates . '
348 <div class="dptScNextPrayer">
349 <span class="green">
350 <span class="nextPrayer">' . $this->getHeading($row, $nextPrayer). '</span> ' .
351 $this->getTimeLeftString($diff, $row);
352 }
353
354 protected function getTimeLeftString($nextIqamah, $row)
355 {
356 $timeLeftText = '';
357 $minLeftText = '';
358 if ($nextIqamah) {
359 $timeLeftText = $this->getLocalizedNumber( $nextIqamah ) .':00';
360 $minLeftText = $this->localTimes["minute"];
361 if ($nextIqamah > 60) {
362 $hours = $nextIqamah / 60;
363 $hours = (int)$hours;
364 $mins = $nextIqamah % 60;
365 $mins = (int)$mins;
366 $timeLeftText = $this->getLocalizedNumber( $hours ) .' '.$this->localTimes["hours"] .' '. $this->getLocalizedNumber( $mins );
367 }
368
369 }
370 return $this->getNextPrayerTime($row, $nextIqamah, $timeLeftText, $minLeftText);
371 }
372
373 protected function getNextIqamahTimeDiff(array $row)
374 {
375 $jamahTime = $this->getJamahTime( $row );
376 $now = current_time( 'H:i');
377 foreach ($jamahTime as $key=>$jamah) {
378 $this->localPrayerNames[lcfirst($key)] . ' ' . $this->localHeaders['iqamah'] . ':';
379 if ($jamah >$now ) {
380 if ($key == 'Sunrise') {
381 $this->localPrayerNames[lcfirst($key)] . ':';
382 }
383 if ($key == 'Zuhr' && $this->isJumahDisplay($row)) {
384 $this->localPrayerNames[lcfirst($key)] . ':';
385 }
386 $toTime = strtotime( $jamah );
387 $fromTime = strtotime( $now );
388 $diff = round(abs($toTime - $fromTime)/60,2);
389
390 return $diff;
391 }
392 }
393 }
394
395 /**
396 * @param $row
397 *
398 * @return string
399 */
400 protected function getNextPrayer($row)
401 {
402 $now = current_time( 'H:i');
403
404 $jamahTime = $this->dptHelper->getJamahTime( $row );
405 foreach ($jamahTime as $jamah) {
406 if ($jamah > $now ) {
407 $prayer = array_search( $jamah, $row ); // asr_jamah or asr_begins
408 $prayer = explode( '_', $prayer);
409 return $prayer[0]; // asr
410 }
411 }
412 }
413
414 protected function getHeading($dbRow, $nextPrayer)
415 {
416 $iqamah = ($nextPrayer == 'sunrise') ? '' : $this->localHeaders['iqamah'];
417 if ( is_null($nextPrayer)) {
418 return $this->localPrayerNames['fajr'].' '. $iqamah;
419 }
420 if ( $this->isJumahDisplay($dbRow) ) {
421 return $this->getLocalHeaders()['jumuah'];
422 }
423
424 return $this->localPrayerNames[$nextPrayer] .' '. $iqamah;
425 }
426
427 protected function getNextPrayerTime($dbRow, $nextIqamah, $timeLeftText, $minLeftText)
428 {
429 $nextPrayer = $this->getNextPrayer($dbRow);
430
431 $key = ($nextPrayer == 'sunrise') ? $nextPrayer : strtolower($nextPrayer.'_jamah');
432
433 if (isset($dbRow[$key])) {
434 $nextPrayerName = $dbRow[$key];
435 }
436
437 if ( is_null($nextPrayer) ) {
438 $nextPrayerName = $dbRow['nextFajr'];
439 }
440
441
442 return
443 '<h2 class="dptScTime">' .
444 $this->formatDateForPrayer($nextPrayerName). '
445 </h2>
446 <span class="timeLeftCountDown timeLeft '.$this->getIqamahClass( $nextIqamah ).'">
447 '. $timeLeftText .'
448 </span>
449 <span class="minLeftText"> ' . $minLeftText .'</span>
450 </div>';
451
452 }
453
454
455 /**
456 * @param array $row
457 *
458 * @return array
459 */
460 protected function getJamahTime(array $row)
461 {
462 $value = array( $row["fajr_jamah"], $row['sunrise'], $row["zuhr_jamah"], $row["asr_jamah"], $row["maghrib_jamah"], $row["isha_jamah"]);
463
464 return array_combine( array_keys($this->prayerLocal), $value );
465
466 }
467
468 /**
469 * @param array $row
470 *
471 * @return array
472 */
473 protected function getAzanTime(array $row)
474 {
475 $value = array( $row["fajr_begins"], $row['sunrise'], $row["zuhr_begins"], $row["asr_begins"], $row["maghrib_begins"], $row["isha_begins"]);
476
477 return array_combine( array_keys($this->prayerLocal), $value );
478 }
479
480 /**
481 * @param $numbers
482 *
483 * @return string
484 */
485 public function getLocalizedNumber($numbers)
486 {
487 $numbers = str_split( $numbers );
488 $localNumber = "";
489 foreach ($numbers as $number) {
490 $localNumber .= $this->localNumbers[$number];
491 }
492
493 return $localNumber;
494 }
495
496 /**
497 * @param $number
498 *
499 * @return string
500 */
501 protected function getIqamahClass($number)
502 {
503 return $this->dptHelper->getIqamahClass($number);
504 }
505
506 protected function getJamahChange(array $row, $isDigitalScreen=false, $orientation="")
507 {
508 $style = null;
509
510 if ($this->isVertical && ! $isDigitalScreen) {
511 $style = "style='display: block;'";
512 }
513
514 $timeClass = "";
515 $digitalScreenClass = "";
516
517 if ($isDigitalScreen) {
518 $timeClass = "class='x-time-change'";
519 $digitalScreenClass = "jamahChanges-" . $orientation;
520
521 }
522
523 $timeRelated = $this->getLocalTimes();
524
525 $print =
526 "<span class='jamahChanges " . $digitalScreenClass . "'>
527 <span class='x-time-text'>"
528 . stripslashes($timeRelated['iqamah update']) .
529 "</span>";
530
531 $prayerNames = $this->getLocalPrayerNames();
532
533 foreach($row['jamah_changes'] as $key=>$time) {
534 if (! empty($key) ){
535 $prayer = explode('_', $key);
536 if ( $this->tomorrowIsFriday() ) {
537 $prayerNames['zuhr'] = $this->getLocalHeaders()['jumuah'];
538 } else {
539 $prayerNames['zuhr'] = $this->prayerLocal['zuhr'];
540 }
541 $print .= "<span " . $style . $timeClass ." >" . $prayerNames[$prayer[0]] . ": " . $this->getTimeForIqamahUpdate($prayerNames[$prayer[0]], $time) . "</span>";
542 }
543 }
544 $print .= "</span>";
545
546 return $print;
547 }
548
549 private function getTimeForIqamahUpdate($key, $time)
550 {
551 $jumuahTime = get_option('jumuah1');
552 if ( $key === $this->getLocalHeaders()['jumuah'] && $jumuahTime) {
553 return $jumuahTime;
554 }
555 return $this->formatDateForPrayer($time);
556 }
557
558 protected function todayIsFriday()
559 {
560 return $this->dptHelper->todayIsFriday();
561 }
562
563 protected function tomorrowIsFriday()
564 {
565 return $this->dptHelper->tomorrowIsFriday();
566 }
567
568 public function getHijriDate($day, $month, $year, $dbRow, $forMonth=false)
569 {
570 return $this->dptHelper->getHijriDate($day, $month, $year, $dbRow, $forMonth);
571 }
572
573 public function isJumahDisplay($dbRow)
574 {
575 return $this->dptHelper->isJumahDisplay($dbRow);
576 }
577
578 private function isSunset($dbRow, $forMonth=false)
579 {
580 return $this->dptHelper->isSunset($dbRow, $forMonth);
581 }
582
583 /**
584 * dim display overnight between Isha and Fajr start
585 */
586 protected function canDimOvernight($dbRow, $disableOvernightDim=false)
587 {
588 return $this->dptHelper->canDimOvernight($dbRow, $disableOvernightDim);
589 }
590
591 /**
592 * set khutbah dimming time on friday between sunrise and Asr
593 */
594 protected function getKhutbahDim(array $dbRow): int
595 {
596 return $this->dptHelper->getKhutbahDim($dbRow);
597 }
598
599 /**
600 * get diming time for taraweeh during ramadan after isha and before fajr
601 */
602 protected function getTaraweehDim(array $dbRow): int
603 {
604 return $this->dptHelper->getTaraweehDim($dbRow);
605 }
606
607 protected function getNextPrayerClass($prayerName, $row, $isFajr=false)
608 {
609 return $this->dptHelper->getNextPrayerClass($prayerName, $row, $isFajr);
610 }
611
612 public function isRamadan()
613 {
614 return $this->dptHelper->isRamadan();
615 }
616
617 public function getJumuahTimesArray($isVertical=false)
618 {
619 $class = 'dsJumuah';
620 if ($isVertical) {
621 $class = 'dsJumuah-vertical';
622 }
623 $jumuahText = [];
624 $jumuahArray = [get_option('jumuah1'), get_option('jumuah2'), get_option('jumuah3')];
625 $jumuahArray = array_filter($jumuahArray);
626 foreach ($jumuahArray as $jumuah) {
627 $jumuahText[] = '<span class="' . $class . '">' . $this->formatDateForPrayer($jumuah) . '</span>';
628 }
629 return implode(' | ', $jumuahText);
630
631 }
632 }
633