Hijri
3 years ago
Processors
1 month ago
QuranADay
2 months ago
StartTime
1 year ago
design
1 month ago
AdminMenu.php
2 years ago
AssetsLoader.php
1 year ago
CustomPluginSettings.php
4 years ago
DPTAjaxHandler.php
4 years ago
DPTHelper.php
1 month ago
DSTemplateLoader.php
2 years ago
DailyShortCode.php
1 month ago
DigitalScreen.php
1 month ago
HijriDate.php
3 years ago
Init.php
4 years ago
MonthlyShortCode.php
2 years ago
MonthlyTimeTable.php
3 years ago
Shortcodes.php
2 months ago
Translator.php
4 years ago
UpdateStyles.php
1 month ago
Validator.php
3 years ago
db.php
2 months ago
dptWidget.php
4 years ago
DPTHelper.php
387 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 getIshraqTime($sunrise) |
| 171 | { |
| 172 | $ishraqMins = get_option('ishraq'); |
| 173 | if (!$ishraqMins || $ishraqMins == '0') { |
| 174 | return null; |
| 175 | } |
| 176 | return date("H:i", strtotime($sunrise . " +" . intval($ishraqMins) . " minutes")); |
| 177 | } |
| 178 | |
| 179 | public function isIshraqTimeNext($row) |
| 180 | { |
| 181 | $ishraqMins = get_option('ishraq'); |
| 182 | if (!$ishraqMins || $ishraqMins == '0') { |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | $fajrTs = strtotime($row['fajr_begins']); |
| 187 | $sunrise = $row['sunrise']; |
| 188 | $ishraqTime = $this->getIshraqTime($sunrise); |
| 189 | $now = user_current_time('H:i'); |
| 190 | |
| 191 | $nowTs = strtotime($now); |
| 192 | $ishraqTs = strtotime($ishraqTime); |
| 193 | |
| 194 | return $nowTs >= $fajrTs && $nowTs < $ishraqTs; |
| 195 | } |
| 196 | |
| 197 | public function getNextPrayerClass($prayerName, $row, $isFajr=false) |
| 198 | { |
| 199 | $nextPrayerName = $this->getNextPrayer($row); |
| 200 | |
| 201 | if ($this->todayIsFriday() && $nextPrayerName == 'zuhr') { |
| 202 | $nextPrayerName = 'jumuah'; |
| 203 | } |
| 204 | |
| 205 | // If ishraq is next, highlight sunrise row (which shows ishraq) |
| 206 | if ($nextPrayerName == 'ishraq' && ($prayerName == 'sunrise' || $prayerName == 'ishraq')) { |
| 207 | return 'nextPrayer'; |
| 208 | } |
| 209 | |
| 210 | // If zawal time is next, highlight zuhr row (not sunrise row) |
| 211 | // Do not highlight Zuhr for zawal on Fridays (Jumuah handling takes precedence) |
| 212 | if ($this->isZawalTimeNext($row) && $prayerName == 'zuhr' && ! $this->todayIsFriday()) { |
| 213 | return 'nextPrayer'; |
| 214 | } |
| 215 | |
| 216 | // If next prayer is zuhr or later, don't highlight sunrise/ishraq rows |
| 217 | if (in_array($prayerName, ['sunrise', 'ishraq']) && in_array($nextPrayerName, ['zuhr', 'asr', 'maghrib', 'isha', 'jumuah'])) { |
| 218 | return ''; |
| 219 | } |
| 220 | |
| 221 | if ($isFajr && is_null($nextPrayerName)) { |
| 222 | return 'nextPrayer'; |
| 223 | } |
| 224 | if ($nextPrayerName && (strpos($nextPrayerName, $prayerName) !== false)) { |
| 225 | return 'nextPrayer'; |
| 226 | } |
| 227 | |
| 228 | return ''; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @param $row |
| 233 | * |
| 234 | * @return string |
| 235 | */ |
| 236 | public function getNextPrayer($row) |
| 237 | { |
| 238 | $ishraqMins = get_option('ishraq'); |
| 239 | $now = current_time('H:i'); |
| 240 | |
| 241 | if ($ishraqMins && $ishraqMins != '0') { |
| 242 | $sunrise = $row['sunrise']; |
| 243 | $ishraqTime = $this->getIshraqTime($sunrise); |
| 244 | $zuhrTs = strtotime($row['zuhr_begins']); |
| 245 | |
| 246 | $nowTs = strtotime($now); |
| 247 | $ishraqTs = strtotime($ishraqTime); |
| 248 | |
| 249 | // Between ishraq and zuhr, next prayer is zuhr |
| 250 | if ($nowTs > $ishraqTs && $nowTs < $zuhrTs) { |
| 251 | return 'zuhr'; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if (get_option('zawal') && $this->isZawalTimeNext($row)) { |
| 256 | return 'zuhr'; |
| 257 | } |
| 258 | |
| 259 | $jamahTime = $this->getJamahTime( $row ); |
| 260 | $nowTs = strtotime($now); |
| 261 | foreach ($jamahTime as $key => $jamah) { |
| 262 | $jamahTs = strtotime($jamah); |
| 263 | if ($jamahTs > $nowTs) { |
| 264 | // If next would be sunrise and ishraq is set, show ishraq instead |
| 265 | if ($key === 'sunrise' && $ishraqMins && $ishraqMins != '0') { |
| 266 | return 'ishraq'; |
| 267 | } |
| 268 | $prayer = array_search( $jamah, $row ); |
| 269 | $prayer = explode( '_', $prayer); |
| 270 | $nextPrayer = $prayer[0]; |
| 271 | |
| 272 | // If today is Friday and next is Zuhr, return Jumuah |
| 273 | if ($this->todayIsFriday() && $nextPrayer == 'zuhr') { |
| 274 | return 'jumuah'; |
| 275 | } |
| 276 | return $nextPrayer; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | public function getSunriseOrZawalOrIshraq($row) |
| 282 | { |
| 283 | $ishraqMins = get_option('ishraq'); |
| 284 | $zawalEnabled = get_option('zawal'); |
| 285 | |
| 286 | // If ishraq time is next (between fajr and ishraq), show ishraq - check FIRST |
| 287 | if ($ishraqMins && $ishraqMins != '0' && $this->isIshraqTimeNext($row)) { |
| 288 | return 'ishraq'; |
| 289 | } |
| 290 | |
| 291 | // If zawal is enabled and zawal time is next (between sunrise and zuhr), show zawal |
| 292 | if ($zawalEnabled && $this->isZawalTimeNext($row)) { |
| 293 | return 'zawal'; |
| 294 | } |
| 295 | |
| 296 | // Otherwise show sunrise |
| 297 | return 'sunrise'; |
| 298 | } |
| 299 | |
| 300 | public function getJamahTime(array $row) |
| 301 | { |
| 302 | $row = $this->updateZuhrWithJummahTimes($row); |
| 303 | |
| 304 | $value = array( $row["fajr_jamah"], $row['sunrise'], $row["zuhr_jamah"], $row["asr_jamah"], $row["maghrib_jamah"], $row["isha_jamah"]); |
| 305 | |
| 306 | $prayerName = ["fajr", "sunrise", "zuhr", "asr", "maghrib", "isha"]; |
| 307 | |
| 308 | return array_combine( $prayerName, $value ); |
| 309 | |
| 310 | } |
| 311 | |
| 312 | public function getZawalTime($zuhrBegins) |
| 313 | { |
| 314 | $zawalMinutes = get_option('zawal'); |
| 315 | |
| 316 | return date( "H:i", strtotime( $zuhrBegins. "-$zawalMinutes minute") ); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * if today is friday |
| 321 | * and now is before zuhr then set zuhr to jummah 1 |
| 322 | * if now is > jummah1 and now is < jummah 2, then set zuhr to jummah2 |
| 323 | * if now is > jummah2 and now is < asr, then set zuhr to jummah3 |
| 324 | * |
| 325 | * if tomorrow is friday, then set tomorrow zuhr to jummah1 |
| 326 | */ |
| 327 | public function updateZuhrWithJummahTimes(array $row) |
| 328 | { |
| 329 | $jumuah1 = get_option('jumuah1'); |
| 330 | $jumuah2 = get_option('jumuah2'); |
| 331 | $jumuah3 = get_option('jumuah3'); |
| 332 | |
| 333 | if($this->todayIsFriday()) { |
| 334 | $userTime = user_current_time( 'H:i'); |
| 335 | $now = new DateTime(); |
| 336 | $now->setTimestamp(strtotime($userTime)); |
| 337 | |
| 338 | $zuhr = new DateTime(); |
| 339 | $zuhr->setTimestamp(strtotime($row['zuhr_begins'])); |
| 340 | |
| 341 | $asr = new DateTime(); |
| 342 | $asr->setTimestamp(strtotime($row['asr_jamah'])); |
| 343 | |
| 344 | $jumuah1dt = new DateTime(); |
| 345 | $jumuah1dt->setTimestamp(strtotime($jumuah1)); |
| 346 | |
| 347 | $jumuah2dt = new DateTime(); |
| 348 | $jumuah2dt->setTimestamp(strtotime($jumuah2)); |
| 349 | |
| 350 | $jumuah3dt = new DateTime(); |
| 351 | $jumuah3dt->setTimestamp(strtotime($jumuah3)); |
| 352 | |
| 353 | if (!empty($jumuah1) && $now < $jumuah1dt) { |
| 354 | $row['zuhr_jamah'] = $jumuah1dt->format('H:i:s'); |
| 355 | } else if (!empty($jumuah2) && ($now > $jumuah1dt && $now < $jumuah2dt)) { |
| 356 | $row['zuhr_jamah'] = $jumuah2dt->format('H:i:s'); |
| 357 | } else if (!empty($jumuah3) && ($now > $jumuah2dt && $now < $asr)) { |
| 358 | $row['zuhr_jamah'] = $jumuah3dt->format('H:i:s'); |
| 359 | } else if (!empty($jumuah3) && ($now > $jumuah3dt)) { |
| 360 | $row['zuhr_jamah'] = $row['tomorrow']['zuhr_jamah']; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | return $row; |
| 365 | } |
| 366 | |
| 367 | public function isZawalTimeNext($row) |
| 368 | { |
| 369 | $ishraqMins = get_option('ishraq'); |
| 370 | |
| 371 | // Determine zawal start time (sunrise or ishraq if enabled) |
| 372 | $zawalStart = $row['sunrise']; |
| 373 | if ($ishraqMins && $ishraqMins != '0') { |
| 374 | $zawalStart = $this->getIshraqTime($row['sunrise']); |
| 375 | } |
| 376 | |
| 377 | $zuhrBegins = $row['zuhr_begins']; |
| 378 | |
| 379 | // Use strtotime for consistent comparison (same as isIshraqTimeNext) |
| 380 | $nowStr = user_current_time('H:i'); |
| 381 | $nowTs = strtotime($nowStr); |
| 382 | $zawalStartTs = strtotime($zawalStart); |
| 383 | $zuhrTs = strtotime($zuhrBegins); |
| 384 | |
| 385 | return $nowTs >= $zawalStartTs && $nowTs < $zuhrTs; |
| 386 | } |
| 387 | } |