Processors
5 years ago
StartTime
5 years ago
AdminMenu.php
5 years ago
AssetsLoader.php
5 years ago
DPTAjaxHandler.php
5 years ago
DSTemplateLoader.php
7 years ago
DailyShortCode.php
5 years ago
DigitalScreen.php
4 years ago
HijriDate.php
7 years ago
Init.php
5 years ago
MonthlyShortCode.php
7 years ago
MonthlyTimeTable.php
6 years ago
Shortcodes.php
5 years ago
UpdateStyles.php
7 years ago
Validator.php
7 years ago
db.php
5 years ago
dptWidget.php
7 years ago
DailyShortCode.php
334 lines
| 1 | <?php |
| 2 | require_once('db.php'); |
| 3 | require_once(__DIR__.'/../Views/DailyTimetablePrinter.php'); |
| 4 | require_once(__DIR__.'/../Views/TimetablePrinter.php' ); |
| 5 | |
| 6 | |
| 7 | class DailyShortCode extends TimetablePrinter |
| 8 | { |
| 9 | /** @var boolean */ |
| 10 | private $isJamahOnly = false; |
| 11 | |
| 12 | /** @var boolean */ |
| 13 | private $isAzanOnly = false; |
| 14 | |
| 15 | /** @var boolean */ |
| 16 | private $isHanafiAsr = false; |
| 17 | |
| 18 | /** @var array */ |
| 19 | protected $row = array(); |
| 20 | |
| 21 | /** @var DailyTimetablePrinter */ |
| 22 | private $timetablePrinter; |
| 23 | |
| 24 | /** @var string */ |
| 25 | private $title; |
| 26 | |
| 27 | /** @var bool */ |
| 28 | private $hideRamadan = false; |
| 29 | |
| 30 | /** @var bool */ |
| 31 | private $hideTimeRemaining = false; |
| 32 | |
| 33 | /** @var bool */ |
| 34 | private $displayHijriDate = false; |
| 35 | |
| 36 | /** $var db */ |
| 37 | protected $db; |
| 38 | |
| 39 | public function __construct() |
| 40 | { |
| 41 | $this->db = new DatabaseConnection(); |
| 42 | $this->row = $this->db->getPrayerTimeForToday(); |
| 43 | $this->timetablePrinter = new DailyTimetablePrinter(); |
| 44 | parent::__construct(); |
| 45 | } |
| 46 | |
| 47 | public function setAnnouncement($text, $day) |
| 48 | { |
| 49 | $this->row['announcement'] = $this->getAnnouncement( $text, $day); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | public function setJamahOnly() |
| 54 | { |
| 55 | $this->isJamahOnly = true; |
| 56 | } |
| 57 | |
| 58 | public function setAzanOnly() |
| 59 | { |
| 60 | $this->isAzanOnly = true; |
| 61 | } |
| 62 | |
| 63 | public function setHanafiAsr() |
| 64 | { |
| 65 | $this->isHanafiAsr = true; |
| 66 | } |
| 67 | |
| 68 | public function hideRamadan() |
| 69 | { |
| 70 | $this->hideRamadan = true; |
| 71 | } |
| 72 | |
| 73 | public function hideTimeRemaining() |
| 74 | { |
| 75 | $this->hideTimeRemaining = true; |
| 76 | } |
| 77 | |
| 78 | public function displayHijriDate() |
| 79 | { |
| 80 | $this->displayHijriDate = true; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @param array $attr |
| 85 | * @return string |
| 86 | */ |
| 87 | public function verticalTime($attr=array()) |
| 88 | { |
| 89 | $this->timetablePrinter->setVertical(true); |
| 90 | |
| 91 | $row = $this->getRow($attr); |
| 92 | |
| 93 | if ($this->isJamahOnly) { |
| 94 | return $this->timetablePrinter->verticalTimeJamahOnly($row); |
| 95 | } |
| 96 | |
| 97 | if ($this->isAzanOnly) { |
| 98 | return $this->timetablePrinter->verticalTimeAzanOnly($row); |
| 99 | } |
| 100 | |
| 101 | return $this->timetablePrinter->printVerticalTime($row); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @param array $attr |
| 106 | * @return string |
| 107 | */ |
| 108 | public function horizontalTime($attr=array()) |
| 109 | { |
| 110 | $this->timetablePrinter->setHorizontal(true); |
| 111 | |
| 112 | $row = $this->getRow($attr); |
| 113 | |
| 114 | if ($this->isJamahOnly) { |
| 115 | return $this->timetablePrinter->horizontalTimeJamahOnly($row); |
| 116 | } |
| 117 | |
| 118 | if ($this->isAzanOnly) { |
| 119 | return $this->timetablePrinter->horizontalTimeAzanOnly($row); |
| 120 | } |
| 121 | |
| 122 | if (isset($attr['use_div_layout'])) { |
| 123 | return $this->timetablePrinter->horizontalTimeDiv($row); |
| 124 | } |
| 125 | |
| 126 | return $this->timetablePrinter->printHorizontalTime($row); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @param string $widgetNotice |
| 131 | * @return string |
| 132 | */ |
| 133 | public function getAnnouncement($widgetNotice="", $day) |
| 134 | { |
| 135 | $widgetNotice = trim( $widgetNotice ); |
| 136 | $day = trim($day); |
| 137 | |
| 138 | if (empty($widgetNotice)) { |
| 139 | return ""; |
| 140 | } |
| 141 | |
| 142 | $today = date('l'); |
| 143 | $announcement = ""; |
| 144 | $exploded = explode(PHP_EOL, $widgetNotice); |
| 145 | foreach($exploded as $line) { |
| 146 | $announcement .= $line . "</br>"; |
| 147 | } |
| 148 | if ( $today == ucfirst( $day ) || $day == 'everyday' ) { |
| 149 | return trim($announcement); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @param string $title |
| 155 | */ |
| 156 | public function setTitle($title) |
| 157 | { |
| 158 | $this->title = $title; |
| 159 | } |
| 160 | |
| 161 | public function scNextPrayer($attr) |
| 162 | { |
| 163 | $row = $this->getRow($attr); |
| 164 | $nextFajr = $this->db->getFajrJamahForTomorrow(); |
| 165 | $row['displayHijriDate'] = $this->displayHijriDate; |
| 166 | $row['nextFajr'] = $nextFajr; |
| 167 | if (isset($attr['display_dates'])) { |
| 168 | return $this->getNextIqamahTime($row, true); |
| 169 | } |
| 170 | return $this->getNextIqamahTime($row); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | public function scRamadanTime($attr) |
| 175 | { |
| 176 | $row = $this->getRow($attr); |
| 177 | |
| 178 | return $this->timetablePrinter->displayRamadanTime($row); |
| 179 | } |
| 180 | |
| 181 | public function scFajr($attr) |
| 182 | { |
| 183 | $result = "<span class='dpt_jamah'>" . $this->formatDateForPrayer($this->row['fajr_jamah']) . "</span>"; |
| 184 | if ( isset($attr['start_time']) ) { |
| 185 | $result = "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['fajr_begins']) . "</span>" . $result; |
| 186 | } |
| 187 | return $result; |
| 188 | } |
| 189 | |
| 190 | public function scFajrStart($attr) |
| 191 | { |
| 192 | return "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['fajr_begins']) . "</span>"; |
| 193 | } |
| 194 | |
| 195 | public function scSunrise($attr) |
| 196 | { |
| 197 | return "<span class='dpt_sunrise'>" . $this->formatDateForPrayer($this->row['sunrise']) . "</span>"; |
| 198 | } |
| 199 | |
| 200 | public function scZuhr($attr) |
| 201 | { |
| 202 | $result = "<span class='dpt_jamah'>" . $this->formatDateForPrayer($this->row['zuhr_jamah']) . "</span>"; |
| 203 | if ( isset($attr['start_time']) ) { |
| 204 | $result = "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['zuhr_begins']) . "</span>" . $result; |
| 205 | } |
| 206 | return $result; |
| 207 | } |
| 208 | |
| 209 | public function scZuhrStart($attr) |
| 210 | { |
| 211 | return "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['zuhr_begins']) . "</span>"; |
| 212 | } |
| 213 | |
| 214 | public function scAsr($attr) |
| 215 | { |
| 216 | $result = "<span class='dpt_jamah'>" . $this->formatDateForPrayer($this->row['asr_jamah']) . "</span>"; |
| 217 | if ( isset($attr['start_time']) ) { |
| 218 | $result = "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['asr_mithl_1']) . "</span>" . $result; |
| 219 | } |
| 220 | return $result; |
| 221 | } |
| 222 | |
| 223 | public function scAsrStart($attr) |
| 224 | { |
| 225 | return "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['asr_mithl_1']) . "</span>"; |
| 226 | } |
| 227 | |
| 228 | public function scMaghrib($attr) |
| 229 | { |
| 230 | $result = "<span class='dpt_jamah'>" . $this->formatDateForPrayer($this->row['maghrib_jamah']) . "</span>"; |
| 231 | if ( isset($attr['start_time']) ) { |
| 232 | $result = "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['maghrib_begins']) . "</span>" . $result; |
| 233 | } |
| 234 | return $result; |
| 235 | } |
| 236 | |
| 237 | public function scMaghribStart($attr) |
| 238 | { |
| 239 | return "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['maghrib_begins']) . "</span>"; |
| 240 | } |
| 241 | |
| 242 | public function scIsha($attr) |
| 243 | { |
| 244 | $result = "<span class='dpt_jamah'>" . $this->formatDateForPrayer($this->row['isha_jamah']) . "</span>"; |
| 245 | if ( isset($attr['start_time']) ) { |
| 246 | $result = "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['isha_begins']) . "</span>" . $result; |
| 247 | } |
| 248 | return $result; |
| 249 | } |
| 250 | |
| 251 | public function scIshaStart($attr) |
| 252 | { |
| 253 | return "<span class='dpt_start'>" . $this->formatDateForPrayer($this->row['isha_begins']) . "</span>"; |
| 254 | } |
| 255 | |
| 256 | public function scIqamahUpdate($attr) |
| 257 | { |
| 258 | $min = isset($attr['threshold']) ? (int) $attr['threshold'] : 1; |
| 259 | $row['jamah_changes'] = $this->db->getJamahChanges($min); |
| 260 | if (empty($row['jamah_changes'])) { return; } |
| 261 | |
| 262 | $orientation = isset($attr['orientation']) ? $attr['orientation'] : ''; |
| 263 | return $this->getJamahChange($row, true, $orientation); |
| 264 | } |
| 265 | |
| 266 | public function scDigitalScreen($attr) |
| 267 | { |
| 268 | $ds = new DigitalScreen($attr); |
| 269 | |
| 270 | return $ds->displayDigitalScreen(); |
| 271 | } |
| 272 | |
| 273 | protected function getRow($attr=array()) |
| 274 | { |
| 275 | |
| 276 | $this->setDisplayForShortCode($attr); |
| 277 | |
| 278 | if (isset($attr['asr'])) { |
| 279 | $this->setHanafiAsr(); |
| 280 | } |
| 281 | |
| 282 | if (isset($attr['heading'])) { |
| 283 | $this->setTitle($attr['heading']); |
| 284 | } |
| 285 | |
| 286 | $row = $this->row; |
| 287 | |
| 288 | if (isset($attr['announcement'])) { |
| 289 | $day = isset($attr['day']) ? $attr['day'] : 'everyday'; |
| 290 | $row['announcement'] = $this->getAnnouncement($attr['announcement'], $day); |
| 291 | } |
| 292 | |
| 293 | if ( $row['jamah_changes']) { |
| 294 | $row['announcement'] .= $this->timetablePrinter->getJamahChange($this->row); |
| 295 | } |
| 296 | |
| 297 | $row['widgetTitle'] = $this->title; |
| 298 | $row['asr_begins'] = $this->isHanafiAsr ? $this->row['asr_mithl_2'] : $this->row['asr_mithl_1']; |
| 299 | |
| 300 | $row['hideRamadan'] = $this->hideRamadan; |
| 301 | $row['hideTimeRemaining'] = $this->hideTimeRemaining; |
| 302 | $row['displayHijriDate'] = $this->displayHijriDate; |
| 303 | $row['nextFajr'] = $this->db->getFajrJamahForTomorrow(); |
| 304 | |
| 305 | return $row; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * @param array $attr |
| 310 | */ |
| 311 | private function setDisplayForShortCode($attr) |
| 312 | { |
| 313 | if (isset($attr['display'])) { |
| 314 | if ( $attr['display'] === 'iqamah_only' ) { |
| 315 | $this->setJamahOnly(); |
| 316 | } elseif ( $attr['display'] === 'azan_only' ) { |
| 317 | $this->setAzanOnly(); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | if (isset($attr['hide_time_remaining'])) { |
| 322 | $this->hideTimeRemaining(); |
| 323 | } |
| 324 | |
| 325 | if (isset($attr['hide_ramadan'])) { |
| 326 | $this->hideRamadan(); |
| 327 | } |
| 328 | |
| 329 | $hijriCheckbox = get_option('hijri-chbox'); |
| 330 | if (! empty($hijriCheckbox)) { |
| 331 | $this->displayHijriDate(); |
| 332 | } |
| 333 | } |
| 334 | } |