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