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 / DPTHelper.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
DPTHelper.php
304 lines
1 <?php
2 class DPTHelper
3 {
4 /** @var HijriDate */
5 private $hijriDate;
6
7 function __construct()
8 {
9 $this->hijriDate = new HijriDate();
10 }
11
12 function todayIsFriday()
13 {
14 return date_i18n('D') == 'Fri';
15 }
16
17 function tomorrowIsFriday()
18 {
19 return date_i18n('D') == 'Thu';
20 }
21
22 function isRamadan()
23 {
24 return $this->hijriDate->isRamadan();
25 }
26
27 function getIqamahClass($number)
28 {
29 if ( $number > 30 ) {
30 return 'green';
31 } elseif ( $number > 15 ) {
32 return 'orange';
33 }
34
35 return 'red';
36 }
37
38 /**
39 * dim display overnight between Isha and Fajr start
40 */
41 function canDimOvernight($dbRow, $disableOvernightDim=false)
42 {
43 $minsAfterIsha = 30;
44 if($this->isRamadan()) {
45 $minsAfterIsha += (int)get_option('taraweehDim');
46 }
47 if ($disableOvernightDim) {
48 return 0;
49 }
50
51 $userTime = user_current_time( 'H:i');
52 $now = new DateTime();
53 $now->setTimestamp(strtotime($userTime));
54
55 $isha = new DateTime();
56 $isha->setTimestamp(strtotime($dbRow['isha_jamah']));
57 $isha->modify('+'.$minsAfterIsha. ' mins');
58
59 $fajr = new DateTime();
60 $fajr->setTimestamp(strtotime($dbRow['fajr_begins']));
61
62 if ($now < $fajr || $now > $isha) {
63 return 1;
64 }
65
66 return 0;
67 }
68
69 /**
70 * set khutbah dimming time on friday between sunrise and Asr
71 */
72 function getKhutbahDim(array $dbRow): int
73 {
74 if (! $this->todayIsFriday()) {
75 return 0;
76 }
77
78 $userTime = user_current_time( 'H:i');
79 $now = new DateTime();
80 $now->setTimestamp(strtotime($userTime));
81
82 $sunrise = new DateTime();
83 $sunrise->setTimestamp(strtotime($dbRow['sunrise']));
84
85 $asr = new DateTime();
86 $asr->setTimestamp(strtotime($dbRow['asr_begins']));
87
88 if ($now > $sunrise && $now < $asr) {
89 return (int)get_option('khutbahDim');
90
91 }
92
93 return 0;
94 }
95
96 /**
97 * get diming time for taraweeh during ramadan after isha and before fajr
98 */
99 function getTaraweehDim(array $dbRow): int
100 {
101 if (! $this->isRamadan()) {
102 return 0;
103 }
104
105 $userTime = user_current_time( 'H:i');
106 $now = new DateTime();
107 $now->setTimestamp(strtotime($userTime));
108
109 $maghrib = new DateTime();
110 $maghrib->setTimestamp(strtotime($dbRow['maghrib_jamah']));
111
112 if ($now > $maghrib) {
113 return (int)get_option('taraweehDim');
114
115 }
116
117 return 0;
118 }
119
120 /**
121 * @param string $mysqlDate
122 * @param string $format
123 * @return string
124 */
125 function formatDate($mysqlDate, $format=null)
126 {
127 $phpDate = strtotime($mysqlDate);
128
129 $date = date( get_option('date_format'), $phpDate );
130 if ($format) {
131 $date = date($format, $phpDate);
132 }
133
134 return $date;
135 }
136
137 public function getHijriDate($day, $month, $year, $dbRow, $forMonth=false)
138 {
139 $hijriCheckbox = get_option('hijri-chbox');
140 if ( ! empty($hijriCheckbox) ) {
141 if( ! empty($dbRow['hijri_date']) ) {
142 $hijriDate = $dbRow['hijri_date'];
143 } else {
144 $hijridateArray = $this->hijriDate->getDate($day, $month, $year, false, $this->isSunset($dbRow, $forMonth));
145 $hijriDate = $hijridateArray['day']. ' '. $hijridateArray['month'] . ' ' . $hijridateArray['year'];
146 }
147
148 return '<p class="hijriDate"> '. $hijriDate .'</p>';
149 }
150 return '';
151 }
152
153 public function isJumahDisplay($dbRow)
154 {
155 if ( date_i18n('D') == 'Fri' &&
156 current_time('timestamp') > strtotime($dbRow['sunrise']) &&
157 current_time('timestamp') <= strtotime($dbRow['zuhr_jamah']) + 60
158 ) {
159 return true;
160 }
161
162 return false;
163 }
164
165 public function isSunset($dbRow, $forMonth=false)
166 {
167 return !$forMonth && current_time('timestamp') > strtotime($dbRow['maghrib_begins']);
168 }
169
170 public function getNextPrayerClass($prayerName, $row, $isFajr=false)
171 {
172 $nextPrayerName = $this->getNextPrayer($row);
173 if ($this->todayIsFriday() && $nextPrayerName == 'zuhr') {
174 $nextPrayerName = 'jumuah';
175 }
176
177 if ($isFajr && is_null($nextPrayerName)) {
178 return 'nextPrayer';
179 }
180 if ($nextPrayerName && (strpos($nextPrayerName, $prayerName) !== false)) {
181 return 'nextPrayer';
182 }
183
184 return '';
185 }
186
187 /**
188 * @param $row
189 *
190 * @return string
191 */
192 public function getNextPrayer($row)
193 {
194 if ( get_option('zawal') && $this->isZawalTimeNext($row) ) {
195 return 'zawal';
196 }
197
198 $now = current_time( 'H:i');
199
200 $jamahTime = $this->getJamahTime( $row );
201 foreach ($jamahTime as $jamah) {
202 if ($jamah > $now ) {
203 $prayer = array_search( $jamah, $row ); // asr_jamah or asr_begins
204 $prayer = explode( '_', $prayer);
205 return $prayer[0]; // asr
206 }
207 }
208 }
209
210 public function getSunriseOrZawal($row)
211 {
212 if (get_option('zawal')) {
213 if($this->isZawalTimeNext($row)){
214 return 'zawal';
215 }
216 }
217 return 'sunrise';
218 }
219
220 public function getJamahTime(array $row)
221 {
222 $row = $this->updateZuhrWithJummahTimes($row);
223
224 $value = array( $row["fajr_jamah"], $row['sunrise'], $row["zuhr_jamah"], $row["asr_jamah"], $row["maghrib_jamah"], $row["isha_jamah"]);
225
226 $prayerName = ["fajr", "sunrise", "zuhr", "asr", "maghrib", "isha"];
227
228 return array_combine( $prayerName, $value );
229
230 }
231
232 public function getZawalTime($zuhrBegins)
233 {
234 $zawalMinutes = get_option('zawal');
235
236 return date( "H:i", strtotime( $zuhrBegins. "-$zawalMinutes minute") );
237 }
238
239 /**
240 * if today is friday
241 * and now is before zuhr then set zuhr to jummah 1
242 * if now is > jummah1 and now is < jummah 2, then set zuhr to jummah2
243 * if now is > jummah2 and now is < asr, then set zuhr to jummah3
244 *
245 * if tomorrow is friday, then set tomorrow zuhr to jummah1
246 */
247 public function updateZuhrWithJummahTimes(array $row)
248 {
249 $jumuah1 = get_option('jumuah1');
250 $jumuah2 = get_option('jumuah2');
251 $jumuah3 = get_option('jumuah3');
252
253 if($this->todayIsFriday()) {
254 $userTime = user_current_time( 'H:i');
255 $now = new DateTime();
256 $now->setTimestamp(strtotime($userTime));
257
258 $zuhr = new DateTime();
259 $zuhr->setTimestamp(strtotime($row['zuhr_begins']));
260
261 $asr = new DateTime();
262 $asr->setTimestamp(strtotime($row['asr_jamah']));
263
264 $jumuah1dt = new DateTime();
265 $jumuah1dt->setTimestamp(strtotime($jumuah1));
266
267 $jumuah2dt = new DateTime();
268 $jumuah2dt->setTimestamp(strtotime($jumuah2));
269
270 $jumuah3dt = new DateTime();
271 $jumuah3dt->setTimestamp(strtotime($jumuah3));
272
273 if (!empty($jumuah1) && $now < $jumuah1dt) {
274 $row['zuhr_jamah'] = $jumuah1dt->format('H:i:s');
275 } else if (!empty($jumuah2) && ($now > $jumuah1dt && $now < $jumuah2dt)) {
276 $row['zuhr_jamah'] = $jumuah2dt->format('H:i:s');
277 } else if (!empty($jumuah3) && ($now > $jumuah2dt && $now < $asr)) {
278 $row['zuhr_jamah'] = $jumuah3dt->format('H:i:s');
279 } else if (!empty($jumuah3) && ($now > $jumuah3dt)) {
280 $row['zuhr_jamah'] = $row['tomorrow']['zuhr_jamah'];
281 }
282 }
283
284 return $row;
285 }
286
287 public function isZawalTimeNext($row)
288 {
289 $userTime = user_current_time( 'H:i');
290 $now = new DateTime();
291 $now->setTimestamp(strtotime($userTime));
292
293 $sunrise = new DateTime();
294 $sunrise->setTimestamp(strtotime($row['sunrise']));
295
296 $zuhr = new DateTime();
297 $zuhr->setTimestamp(strtotime($row['zuhr_begins']));
298
299 if ($now > $sunrise && $now < $zuhr) {
300 return true;
301 }
302 return false;
303 }
304 }