PluginProbe ʕ •ᴥ•ʔ
Daily Prayer Time / 2026.05.04
Daily Prayer Time v2026.05.04
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 / Processors / StartTimeProcessor.php
daily-prayer-time-for-mosques / Models / Processors Last commit date
AdhanProcessor.php 1 year ago CsvProcessor.php 2 months ago DebugProcessor.php 1 year ago DigitalScreenProcessor.php 1 month ago HijriProcessor.php 3 years ago LanguageProcessor.php 4 years ago OtherProcessor.php 2 months ago QuickUpdateProcessor.php 3 years ago StartTimeProcessor.php 1 year ago ThemeSettingsProcessor.php 1 year ago
StartTimeProcessor.php
179 lines
1 <?php
2 use IslamicNetwork\PrayerTimes\PrayerTimes;
3 use IslamicNetwork\PrayerTimes\Method as PrayerTimesMethod;
4 require_once(__DIR__. '/../db.php');
5
6 if ( ! class_exists('DPTStartTimeProcessor')) {
7 class DPTStartTimeProcessor
8 {
9 /** @var DatabaseConnection */
10 private $db;
11
12 /** @var string[] */
13 private $prayerNames = array('fajr', 'sunrise', 'zuhr', 'asr', 'sunset', 'maghrib', 'isha' );
14
15 private PrayerTimes $islamicNetworkPrayerTimes;
16
17 /** @var array */
18 private $data;
19
20 /** @var string */
21 private $dbTable;
22
23 public function __construct(array $data)
24 {
25 global $wpdb;
26 $tableName = $wpdb->prefix . "timetable_cities";
27 $this->dbTable = "`".DB_NAME ."`.`" .$tableName."`";
28
29 $this->db = new DatabaseConnection();
30 if (is_array($data)) {
31 $this->data = array_map( 'sanitize_text_field', $data);
32 }
33 }
34
35 public function process()
36 {
37 set_transient('nearest_city', $this->data['city']);
38 $calcMethod = $this->data['method'];
39 $asrMethod = $this->data['asr-method'];
40 $latLong = $this->getLatLong($this->data['city']);
41 $higherLatMethod = (int)$this->data['higher-lat'];
42
43 $this->islamicNetworkPrayerTimes = new PrayerTimes($calcMethod);
44 if ($calcMethod == 23) { // custom settings
45 $method = new PrayerTimesMethod('My Custom Method');
46 $fajrAngle = (int)$this->data['fajr-angle'];
47 $ishaAngle = (int)$this->data['isha-angle'];
48
49 $method->setFajrAngle((int)$this->data['fajr-angle']);
50 $method->setIshaAngleOrMins((int)$this->data['isha-angle']);
51
52 $this->islamicNetworkPrayerTimes->setMethod($method);
53
54
55 delete_option('fajr-angle');
56 delete_option('isha-angle');
57
58 add_option('fajr-angle', $fajrAngle);
59 add_option('isha-angle', $ishaAngle);
60 }
61 $this->islamicNetworkPrayerTimes->setAsrJuristicMethod($asrMethod);
62 $this->islamicNetworkPrayerTimes->setSchool($asrMethod);
63 $this->islamicNetworkPrayerTimes->setLatitudeAdjustmentMethod($higherLatMethod);
64
65
66 delete_option('fajr-delay');
67 delete_option('zuhr-delay');
68 delete_option('asr-delay');
69 delete_option('maghrib-delay');
70 delete_option('isha-delay');
71 delete_option('higher-lat');
72 delete_option('calc-method');
73 delete_option('asr-method');
74
75 add_option('fajr-delay', $this->data['fajr-delay']);
76 add_option('zuhr-delay', $this->data['zuhr-delay']);
77 add_option('asr-delay', $this->data['asr-delay']);
78 add_option('maghrib-delay', $this->data['maghrib-delay']);
79 add_option('isha-delay', $this->data['isha-delay']);
80 add_option('higher-lat', $higherLatMethod);
81 add_option('calc-method', $calcMethod);
82 add_option('asr-method', $asrMethod);
83
84 $year = date('Y');
85 $date = new DateTime($year . '-1-1');
86 $endDate = new DateTime(($year + 1) . '-1-1');
87
88 while ($date < $endDate)
89 {
90 $day = date('Y-m-d');
91 $times = $this->islamicNetworkPrayerTimes->getTimes($date, $latLong['lat'], $latLong['lng']);
92 $this->setTimezone($date);
93 $times = [
94 'fajr' => $times['Fajr'],
95 'sunrise' => $times['Sunrise'],
96 'zuhr' => $times['Dhuhr'],
97 'asr' => $times['Asr'],
98 'sunset' => $times['Sunset'],
99 'maghrib' => $times['Maghrib'],
100 'isha' => $times['Isha']
101 ];
102
103 $times = array_combine($this->prayerNames, $times);
104
105 $row = array (
106 'd_date' => $date->format('Y-m-d'),
107 'fajr_begins' => $times['fajr'],
108 'fajr_jamah' => $this->getJamahTime($day, $times['fajr'], $this->data['fajr-delay']),
109 'sunrise' => $times['sunrise'],
110 'zuhr_begins' => $times['zuhr'],
111 'zuhr_jamah' => $this->getJamahTime($day, $times['zuhr'], $this->data['zuhr-delay']),
112 'asr_mithl_1' => $times['asr'],
113 'asr_mithl_2' => $times['asr'],
114 'asr_jamah' => $this->getJamahTime($day, $times['asr'], $this->data['asr-delay']),
115 'maghrib_begins' => $times['maghrib'],
116 'maghrib_jamah' => $this->getJamahTime($day, $times['maghrib'], $this->data['maghrib-delay']),
117 'isha_begins' => $times['isha'],
118 'isha_jamah' => $this->getJamahTime($day, $times['isha'], $this->data['isha-delay']),
119 'is_ramadan' => 0,
120 'hijri_date' => 0
121 );
122 $this->db->insertRow($row);
123 $date->modify('+1 day'); // next day
124 }
125 }
126
127 /**
128 * @throws DateInvalidTimeZoneException
129 */
130 private function setTimezone(DateTime $date): void
131 {
132 $timezone_string = get_option('timezone_string');
133
134 if ($timezone_string) {
135 $timezone = new DateTimeZone($timezone_string);
136 } else {
137 // Fallback to the offset if timezone string is not set
138 $offset = get_option('gmt_offset');
139 $timezone = timezone_name_from_abbr('', $offset * 3600, 0);
140 if ($timezone === false) {
141 $timezone = 'UTC';
142 }
143 $timezone = new DateTimeZone($timezone);
144 }
145 $date->setTimezone($timezone);
146 }
147
148 private function getJamahTime($date, $time, $mins)
149 {
150 $mins = empty($mins) ? 3 : $mins;
151 try{
152 $dt = new DateTime($date . ' ' . $time);
153 $dt->add(new DateInterval('PT' . $mins . 'M'));
154
155 return $dt->format('H:i');
156 } catch(\Exception $e) {
157 error_log('!Failed to Set Prayer Times Automatically - : ' . $e->getMessage());
158 }
159 return '';
160 }
161
162 private function getLatLong($cityId)
163 {
164 $cityId = sanitize_text_field( $cityId );
165 $cityId = empty($cityId) ? 26 : $cityId; // DEFAULT LONDON
166
167 global $wpdb;
168 $sql = "SELECT lat, lng FROM $this->dbTable WHERE id = " . $cityId;
169 $row = $wpdb->get_row($sql, ARRAY_A);
170
171 return array(
172 'lat' => $row['lat'],
173 'lng' => $row['lng']
174 );
175 }
176 }
177
178 }
179