PluginProbe ʕ •ᴥ•ʔ
Daily Prayer Time / 2021.09.24
Daily Prayer Time v2021.09.24
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
576 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 UPDATE FOR TOMORROW',
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 /**
260 * @param string $month
261 * @param string $day
262 * @return string
263 */
264 protected function getClass($month, $day)
265 {
266 if ($day == user_current_time('j') && $month == user_current_time('m')){
267 return "class = highlight";
268 }
269 }
270
271 /**
272 * @param bool $isRamadan
273 * @param array $data
274 * @param bool $azanOnly
275 * @return string|null
276 */
277 protected function getFastingTdWithData($isRamadan, $data, $azanOnly=null, $imsaq=false)
278 {
279 $html = "";
280
281 if ($isRamadan && ! $azanOnly && $imsaq) {
282 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data, $imsaq) . "</td>";
283 } elseif ($isRamadan && $imsaq) {
284 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data, $imsaq). "</td>";
285 $html .= "<td>" . $this->formatDateForPrayer($data). "</td>";
286
287 } elseif ($isRamadan && ! $imsaq) {
288 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data). "</td>";
289 } elseif ($isRamadan && ! $azanOnly && $imsaq) {
290 $html = "<td class='fasting'>" . $this->formatDateForPrayer($data). "</td>";
291 } elseif ($azanOnly) {
292 $html = "<td>" . $this->formatDateForPrayer($data). "</td>";
293 }
294
295 return $html;
296 }
297
298 /**
299 * @param array $row
300 * @param bool $displayDates
301 * @return string
302 */
303 protected function getNextIqamahTime(array $row, $displayDates=false)
304 {
305 $diff = $this->getNextIqamahTimeDiff($row);
306 $nextPrayer = $this->getNextPrayer($row);
307 if($row['displayHijriDate']) {
308 $hijriDate = $this->hijriDate->getDate(date("d"), date("m"), date("Y"), true);
309 }
310
311 $printDates = '';
312 if ($displayDates) {
313 $printDates = '<div>
314 <span class="scDate">
315 ' . date_i18n( get_option( 'date_format' ) ) . '
316 </span>
317 <span class="scHijri">
318 ' . $hijriDate . '
319 </span>';
320 }
321
322 return
323 $printDates . '
324 <div class="dptScNextPrayer">
325 <span class="green">
326 <span class="nextPrayer">' . $this->getHeading($row, $nextPrayer). '</span> ' .
327 $this->getTimeLeftString($diff, $row);
328 }
329
330 protected function getTimeLeftString($nextIqamah, $row)
331 {
332 if ($nextIqamah) {
333 $timeLeftText = $this->getLocalizedNumber( $nextIqamah ) .':00';
334 $minLeftText = $this->localTimes["minute"];
335 if ($nextIqamah > 60) {
336 $hours = $nextIqamah / 60;
337 $hours = (int)$hours;
338 $mins = $nextIqamah % 60;
339 $mins = (int)$mins;
340 $timeLeftText = $this->getLocalizedNumber( $hours ) .' '.$this->localTimes["hours"] .' '. $this->getLocalizedNumber( $mins );
341 }
342
343 }
344 return $this->getNextPrayerTime($row, $nextIqamah, $timeLeftText, $minLeftText);
345 }
346
347 protected function getNextIqamahTimeDiff(array $row)
348 {
349 $jamahTime = $this->getJamahTime( $row );
350 $now = current_time( 'H:i');
351 foreach ($jamahTime as $key=>$jamah) {
352 $this->nextIqamah = $this->localPrayerNames[lcfirst($key)] . ' ' . $this->localHeaders['iqamah'] . ':';
353 if ($jamah >$now ) {
354 if ($key == 'Sunrise') {
355 $this->nextIqamah = $this->localPrayerNames[lcfirst($key)] . ':';
356 }
357 if ($key == 'Zuhr' && $this->isJumahDisplay($row)) {
358 $this->nextIqamah = $this->localPrayerNames[lcfirst($key)] . ':';
359 }
360 $toTime = strtotime( $jamah );
361 $fromTime = strtotime( $now );
362 $diff = round(abs($toTime - $fromTime)/60,2);
363
364 return $diff;
365 }
366 }
367 }
368
369 /**
370 * @param $row
371 *
372 * @return string
373 */
374 protected function getNextPrayer($row)
375 {
376 $now = current_time( 'H:i');
377
378 $jamahTime = $this->getJamahTime( $row );
379 foreach ($jamahTime as $jamah) {
380 if ($jamah > $now ) {
381 $prayer = array_search( $jamah, $row ); // asr_jamah or asr_begins
382 $prayer = explode( '_', $prayer);
383 return $prayer[0]; // asr
384 }
385 }
386 }
387
388 protected function getHeading($dbRow, $nextPrayer)
389 {
390 $iqamah = ($nextPrayer == 'sunrise') ? '' : $this->localHeaders['iqamah'];
391 if ( is_null($nextPrayer)) {
392 return $this->localPrayerNames['fajr'].' '. $iqamah;
393 }
394 if ( $this->isJumahDisplay($dbRow) ) {
395 return $this->getLocalHeaders()['jumuah'];
396 }
397
398 return $this->localPrayerNames[$nextPrayer] .' '. $iqamah;
399 }
400
401 protected function getNextPrayerTime($dbRow, $nextIqamah, $timeLeftText, $minLeftText)
402 {
403 $nextPrayer = $this->getNextPrayer($dbRow);
404
405 $key = ($nextPrayer == 'sunrise') ? $nextPrayer : strtolower($nextPrayer.'_jamah');
406 $nextPrayerName = $dbRow[$key];
407 if ( is_null($nextPrayer) ) {
408 $nextPrayerName = $dbRow['nextFajr'];
409 }
410
411 if ( $this->isJumahDisplay($dbRow) ) {
412 return '<p class="jumuah">' . get_option('jumuah') . '</span>';
413 } else {
414 return
415 '<h2 class="dptScTime">' .
416 $this->formatDateForPrayer($nextPrayerName). '
417 </h2>
418 <span class="timeLeftCountDown timeLeft '.$this->getIqamahClass( $nextIqamah ).'">
419 '. $timeLeftText .'
420 </span><span class="minLeftText"> ' . $minLeftText .'</span>
421 </div>';
422 }
423 }
424
425
426 /**
427 * @param array $row
428 *
429 * @return array
430 */
431 protected function getJamahTime(array $row)
432 {
433 $value = array( $row["fajr_jamah"], $row['sunrise'], $row["zuhr_jamah"], $row["asr_jamah"], $row["maghrib_jamah"], $row["isha_jamah"]);
434
435 return array_combine( array_keys($this->prayerLocal), $value );
436
437 }
438
439 /**
440 * @param array $row
441 *
442 * @return array
443 */
444 protected function getAzanTime(array $row)
445 {
446 $value = array( $row["fajr_begins"], $row['sunrise'], $row["zuhr_begins"], $row["asr_begins"], $row["maghrib_begins"], $row["isha_begins"]);
447
448 return array_combine( array_keys($this->prayerLocal), $value );
449 }
450
451 /**
452 * @param $numbers
453 *
454 * @return string
455 */
456 public function getLocalizedNumber($numbers)
457 {
458 $numbers = str_split( $numbers );
459 $localNumber = "";
460 foreach ($numbers as $number) {
461 $localNumber .= $this->localNumbers[$number];
462 }
463
464 return $localNumber;
465 }
466
467 /**
468 * @param $number
469 *
470 * @return string
471 */
472 protected function getIqamahClass($number)
473 {
474 if ( $number > 30 ) {
475 return 'green';
476 } elseif ( $number > 15 ) {
477 return 'orange';
478 }
479
480 return 'red';
481 }
482
483 protected function getJamahChange(array $row, $isDigitalScreen=false, $orientation="")
484 {
485 $style = null;
486 if ($this->isVertical && ! $isDigitalScreen) {
487 $style = "style='display: block;'";
488 }
489 $timeClass = "";
490 $digitalScreenClass = "";
491 if ($isDigitalScreen) {
492 $timeClass = "class='x-time-change'";
493 $digitalScreenClass = "jamahChanges-" . $orientation;
494
495 }
496 $timeRelated = $this->getLocalTimes();
497 $print = "<div class='jamahChanges " . $digitalScreenClass . "'>
498 <span class='x-time-text'>" . stripslashes($timeRelated['iqamah update']) . "</span>";
499 $prayerNames = $this->getLocalPrayerNames();
500
501 foreach($row['jamah_changes'] as $key=>$time) {
502 if (! empty($key) ){
503 $prayer = explode('_', $key);
504 if ( $this->tomorrowIsFriday() ) {
505 $prayerNames['zuhr'] = $this->getLocalHeaders()['jumuah'];
506 } else {
507 $prayerNames['zuhr'] = $this->prayerLocal['zuhr'];
508 }
509 $print .= "<span " . $style . $timeClass ." >" . $prayerNames[$prayer[0]] . ": " . $this->getTimeForIqamahUpdate($prayerNames[$prayer[0]], $time) . "</span>";
510 }
511 }
512 $print .= "</div>";
513
514 return $print;
515 }
516
517 private function getTimeForIqamahUpdate($key, $time)
518 {
519 $jumuahTime = get_option('jumuah');
520 if ( $key === $this->getLocalHeaders()['jumuah'] && $jumuahTime) {
521 return $jumuahTime;
522 }
523 return $this->formatDateForPrayer($time);
524 }
525
526 protected function todayIsFriday()
527 {
528 return date_i18n('D') == 'Fri';
529 }
530
531 protected function tomorrowIsFriday()
532 {
533 return date_i18n('D') == 'Thu';
534 }
535
536 /**
537 * @param $day
538 * @param $month
539 * @param $year
540 * @param array $dbRow
541 * @param bool $forMonth
542 * @return string
543 */
544 public function getHijriDate($day, $month, $year, $dbRow, $forMonth=false)
545 {
546 $hijriCheckbox = get_option('hijri-chbox');
547 if ( ! empty($hijriCheckbox) ) {
548 if( ! empty($dbRow['hijri_date']) ) {
549 $hijriDate = $dbRow['hijri_date'];
550 } else {
551 $hijridateArray = $this->hijriDate->getDate($day, $month, $year, false, $this->isSunset($dbRow, $forMonth));
552 $hijriDate = $hijridateArray['day']. ' '. $hijridateArray['month'] . ' ' . $hijridateArray['year'];
553 }
554
555 return '<p class="hijriDate"> '. $hijriDate .'</p>';
556 }
557 return;
558 }
559
560 public function isJumahDisplay($dbRow)
561 {
562 if ( date_i18n('D') == 'Fri' &&
563 current_time('timestamp') > strtotime($dbRow['sunrise']) &&
564 current_time('timestamp') <= strtotime($dbRow['zuhr_jamah']) + 60
565 ) {
566 return true;
567 }
568
569 return false;
570 }
571
572 private function isSunset($dbRow, $forMonth=false)
573 {
574 return !$forMonth && current_time('timestamp') > strtotime($dbRow['maghrib_begins']);
575 }
576 }