public function view($url) { if (preg_match('/^\\/hash(.php)?(?P<wk>\\/wk)?\\/' . \lib\RegExp::date() . '(\\/(?P<graticule>' . \lib\RegExp::graticule() . '))?' . \lib\RegExp::ext(true) . '$/i', $url, $this->matches)) { $y = $this->matches['y']; $m = $this->matches['m']; $d = $this->matches['d']; if (checkdate($m, $d, $y)) { $this->date = new \DateTime($y . '-' . $m . '-' . $d); $this->ext = array_key_exists('ext', $this->matches) ? $this->matches['ext'] : null; $this->wk = strlen($this->matches['wk']) > 0; $this->get(); } else { \lib\Error::send(400, 'This date is not a valid date'); } } else { \lib\Error::send(404, 'No valid url'); } }
public function view($url) { if (preg_match('/^\\/dow(.php)?\\/' . \lib\RegExp::date(true, true) . \lib\RegExp::ext(true) . '$/', $url, $matches)) { if (\lib\RegExp::partExists('d', $matches)) { $dt_start = new \DateTime($matches['y'] . '-' . $matches['m'] . '-' . $matches['d']); $dt_end = null; } elseif (\lib\RegExp::partExists('m', $matches)) { $dt_start = new \DateTime($matches['y'] . '-' . $matches['m'] . '-01'); $dt_end = new \DateTime($matches['y'] . '-' . $matches['m'] . '-' . cal_days_in_month(CAL_GREGORIAN, $matches['m'], $matches['y'])); } else { $dt_start = new \DateTime($matches['y'] . '-01-01'); $dt_end = new \DateTime($matches['y'] . '-12-31'); } $ext = \lib\RegExp::partExists('ext', $matches) ? $matches['ext'] : null; $dow = \model\Dow::get($dt_start, $dt_end); if ($dow === false) { \lib\Error::send(404, 'This dow is not available'); } else { $this->display($dow, $ext); } } else { \lib\Error::send(404, 'No valid url, use <u>/dow/<yyyy>[/<mm>[/<dd>]]</u>'); } }