PluginProbe ʕ •ᴥ•ʔ
Daily Prayer Time / 2019.5.8
Daily Prayer Time v2019.5.8
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 / Validator.php
daily-prayer-time-for-mosques / Models Last commit date
Processors 7 years ago DSTemplateLoader.php 7 years ago DailyShortCode.php 7 years ago DailyTimeTable.php 8 years ago HijriDate.php 7 years ago Init.php 7 years ago MonthlyShortCode.php 7 years ago MonthlyTimeTable.php 10 years ago UpdateStyles.php 7 years ago Validator.php 7 years ago db.php 7 years ago dptWidget.php 7 years ago
Validator.php
208 lines
1 <?php
2
3 class Validator
4 {
5 /** @var array */
6 private $validData = array();
7
8 /** @var array */
9 private $headers = array (
10 0 => 'd_date',
11 1 => 'fajr_begins',
12 2 => 'fajr_jamah',
13 3 => 'sunrise',
14 4 => 'zuhr_begins',
15 5 => 'zuhr_jamah',
16 6 => 'asr_mithl_1',
17 7 => 'asr_mithl_2',
18 8 => 'asr_jamah',
19 9 => 'maghrib_begins',
20 10 => 'maghrib_jamah',
21 11 => 'isha_begins',
22 12 => 'isha_jamah',
23 13 => 'is_ramadan',
24 14 => 'hijri_date',
25 );
26
27 /**
28 * @param $file
29 * @return bool
30 */
31 public function isValidNumberOfRows($file)
32 {
33 $count = count($file);
34 $count -= 1; // Remove header count
35
36 if ($count == 0 || $count > 366 ) {
37 echo "<h3 class='ui-state-error dptCenter'>Invalid number of rows. Found $count days</h3>";
38 return false;
39 }
40
41 return true;
42 }
43
44 /**
45 * @param array $data [rows, containing date and each prayer times]
46 * @return bool
47 */
48 public function isValidData(array $data)
49 {
50 if (! $this->hasEmptyLines($data)) {
51 return false;
52 }
53
54 if (! $this->is24Hours($data)) {
55 return false;
56 }
57
58 $num = count($data);
59
60 for ($c=0; $c < $num - 2; $c++) { // exclude the last two columns
61 if ($c == 0) {
62 $date = $this->getDateAfterValidation($data[$c]);
63 if(! $date) {
64 echo "<h3 class='ui-state-error dptCenter'>Invalid Date format ($data[$c]). Please use one of the following:
65 <ul class='green'>
66 <li> YYYY-MM-DD <i class='smallFont'>(2023-10-20)</i></li>
67 <li> YY-MM-DD <i class='smallFont'>(23-10-20)</i></li>
68 <li> MM/DD/YYYY <i class='smallFont'>(10/20/2021)</i></li>
69 <li> DD-MM-YYYY <i class='smallFont'>(20-10-2023)</i></li>
70 <li> DD.MM.YYYY <i class='smallFont'>(13.10.2034)</i></li>
71 </ul>
72 </h3>";
73 return false;
74 } else {
75 $data[$c] = $date;
76 }
77 } else {
78 if(! $this->isValidateTimeFormat($data[$c])) {
79 echo "<h3 class='ui-state-error dptCenter'>Invalid Time format in " . $data[$c] . " for " . $this->headers[$c] .
80 " on ". $data[0] .", valid time format is <span class='green'>HH:MM[24 hours]</span> </h3>";
81 print_r('<pre>');
82 print_r(array_combine($this->headers, $data));
83 print_r('</pre>');
84 return false;
85 }
86 }
87 }
88
89 $this->setValidData($data);
90
91 return true;
92 }
93
94 /**
95 * @return array
96 */
97 public function getValidData()
98 {
99 $data = array_combine($this->headers, $this->validData);
100
101 return $data;
102 }
103
104 /**
105 * @param array $header
106 * @return bool
107 */
108 public function checkHeader(array $header)
109 {
110 if ( count($header) != count($this->headers)) {
111 echo "<h3 class='dptCenter ui-state-error'>Do not remove any column header";
112 return false;
113 }
114 return true;
115 }
116
117 /**
118 * @param string $date
119 * @return string|bool
120 */
121 private function getDateAfterValidation($date)
122 {
123 $date = trim($date);
124 if (preg_match("/^(\d{4})-(\d{1,2})-(\d{1,2})$/", $date, $matches)) {
125 if (checkdate($matches[2], $matches[3], $matches[1])) {
126 return $date;
127 }
128 } elseif (preg_match("/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/", $date, $matches)) {
129 if (checkdate($matches[1], $matches[2], $matches[3])) {
130 $mysqlDate = date('Y-m-d', strtotime($date));
131 return $mysqlDate;
132 }
133 } elseif (preg_match("/^(\d{1,2})-(\d{1,2})-(\d{4})$/", $date, $matches)) {
134 if (checkdate($matches[2], $matches[1], $matches[3])) {
135 $mysqlDate = date('Y-m-d', strtotime($date));
136 return $mysqlDate;
137 }
138 } elseif (preg_match("/^(\d{1,2}).(\d{1,2}).(\d{4})$/", $date, $matches)) {
139 if (checkdate($matches[2], $matches[1], $matches[3])) {
140 $mysqlDate = date('Y-m-d', strtotime($date));
141 return $mysqlDate;
142 }
143 } elseif (preg_match("/^(\d{1,2})-(\d{1,2})-(\d{2})$/", $date, $matches)) {
144 if (checkdate($matches[2], $matches[1], $matches[3])) {
145 $mysqlDate = date('Y-m-d', strtotime($date));
146 return $mysqlDate;
147 }
148 }
149
150 return false;
151 }
152
153 /**
154 * @param string $time
155 * @return bool
156 */
157 private function isValidateTimeFormat($time)
158 {
159 $time = trim($time);
160 $pattern1 = "/^([0-9]|[01][0-9]|2[0-3]):[0-5][0-9]$/"; // HH:MM or H:MM
161 $pattern2 = "/^([0-9]|[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/"; // HH:MM or H:MM
162
163 if ( preg_match($pattern1, $time, $matches) || preg_match($pattern2, $time, $matches) ) {
164 return true;
165 }
166
167 return false;
168 }
169
170 /**
171 * @param string $row
172 * @return bool
173 */
174 private function is24Hours($row)
175 {
176 $afternoonPrayers = array($row[6], $row[7], $row[8], $row[9], $row[10], $row[11], $row[12]);
177 foreach($afternoonPrayers as $time) {
178 $firstPart = explode(':', $time);
179 if ($firstPart[0] !== '00' && (int)$firstPart[0] < 12) {
180 echo "<h3 class='dptCenter ui-state-error'>$time is not in 24 hour time format for date: $row[0]
181 </br> You must follow 24 hours time format, valid time format is <span class='green'>HH:MM</span></h3>";
182 return false;
183 }
184 }
185
186 return true;
187 }
188
189 /**
190 * @param array $data
191 */
192 private function setValidData(array $data)
193 {
194 $this->validData = $data;
195 }
196
197 private function hasEmptyLines(array $data)
198 {
199 $data = trim($data[0]);
200 if (empty($data)) {
201 echo "<h3 class='ui-state-error dptCenter'>Please remove the empty lines between rows</h3>";
202 return false;
203 }
204
205 return true;
206 }
207 }
208