private function display($dow, $ext) { switch ($ext) { case 'json': header('Content-Type: application/json'); echo json_encode($dow); break; case 'csv': header('Content-Type: text/csv'); echo '"Date","Dow"' . "\r\n"; if (is_array($dow)) { foreach ($dow as $r) { echo $r->date . ',' . $r->dow . "\r\n"; } } else { echo $dow->date . ',' . $dow->dow . "\r\n"; } break; default: if (is_array($dow)) { \lib\Error::send(404, 'Display list not implemented'); } else { header('Content-Type: text/plain'); echo $dow->dow; } } }
public function view($url) { strtok($url, '/'); $file = strtok('/'); if (array_key_exists($file, $this->files)) { switch ($this->files[$file]) { case 'md': $parseDown = new \lib\external\parseDown\ParseDown(); $parseDown->setMarkupEscaped(true); $text = $parseDown->text(file_get_contents(dirname(__FILE__) . '/../' . strtoupper($file) . '.md')); preg_match('/^<h1?.*>(?P<title>.*)<\\/h1>\\n(?P<content>.*)$/ims', $text, $matches); $title = $matches['title']; $content = $matches['content']; break; case 'tpl': require_once dirname(__FILE__) . '/../template/' . strtolower($file) . '.tpl.php'; break; } } else { $output = \model\Page::get($file); $title = $output->title; $content = $output->content; } if (is_null($content)) { \lib\Error::send(404, 'Page not found'); } header('Content-type: text/json'); echo json_encode(['title' => $title, 'content' => $content]); }
private function getGpx() { if ($this->wk) { \lib\Error::send(404, 'Week view for GPX is not (yet) implemented'); } else { $this->doCalc(); if ($this->global) { if (is_null($this->output['global'])) { \lib\Error::send(404, 'Data not yet available'); } $this->lat = $this->output['global']->lat; $this->lng = $this->output['global']->lng; $filename = 'global'; } else { $hashData = $this->lng > -30 ? $this->output['east'] : $this->output['west']; if (is_null($hashData)) { \lib\Error::send(404, 'Data not yet available'); } $filename = $this->lat . '_' . $this->lng; $this->lat .= substr($hashData->lat, 1); $this->lng .= substr($hashData->lng, 1); } \lib\Cache::permanent(); header('Content-type: text/xml'); header('Content-type: application/force-download;charset=utf-8'); header('Content-Disposition: attachment; filename="geohash_' . $this->date->format('Y-m-d') . '_' . $filename . '.gpx"'); echo '<?xml version="1.0"?> <gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="geohashing.info"> <metadata> <name>Geohash ' . $this->date->format('Y-m-d') . '</name> </metadata> <wpt lat="' . $this->lat . '" lon="' . $this->lng . '"> <name>GH ' . $this->date->format('Y-m-d') . ' ' . $this->graticule . '</name> </wpt> </gpx>'; } }