/** * Where all of the parsing and setting of data is handled. * Switches on type of page request, and sets various properties * accordingly. * * @return void * @uses \shgsyk8zer0\Template */ private function getContent() { $login = Core\Login::load(); $DB = Core\PDO::load('connect.json'); switch ($this->type) { case 'posts': $data = get_object_vars($this->data); array_map(function ($name, $value) { $this->{$name} = $value; }, array_keys($data), array_values($data)); unset($data); $post = Core\Template::load('posts'); $comments = Core\Template::load('comments'); $comments_section = Core\Template::load('comments_section'); $comments_section->title($this->data->title)->home(URL)->comments(null); $results = $DB->prepare('SELECT `comment`, `author`, `author_url`, `time` FROM `comments` WHERE `post` = :post;')->execute(['post' => end($this->request_path)])->getResults(); if (is_array($results)) { foreach ($results as $comment) { $time = strtotime($comment->time); $comments->comment($comment->comment)->author(strlen($comment->author_url) ? "<a href=\"{$comment->author_url}\" target=\"_blank\">{$comment->author}</a>" : $comment->author)->time(date('l, F jS Y h:i A', $time)); $comments_section->comments .= "{$comments}"; } } foreach (explode(',', $this->data->keywords) as $tag) { $post->tags .= '<a href="' . URL . 'tags/' . urlencode(trim($tag)) . '" rel="tag">' . trim($tag) . "</a>"; } $license = new Core\Creative_Commons_License(); $license->title = $this->data->title; $license->author = $this->data->author; $license->author_url = "{$this->data->author_url}?rel=author"; $license->time = $this->data->created; $license->use_svg = true; $license->share_alike = true; $post->title($this->data->title)->content($this->data->content)->home(URL)->comments("{$comments_section}")->url($this->data->url)->license($license); $this->content = "{$post}"; break; case 'tags': $this->title = 'Tags'; $this->description = "Tags search results for {$this->request_path[1]}"; $this->keywords = "Keywords, tags, search, {$this->request_path[1]}"; $this->content = '<div class="tags">'; $template = Core\Template::load('tags'); array_map(function (\stdClass $post) use(&$template) { if (!isset($post->title)) { return; } $template->title($post->title)->description($post->description)->author($post->author)->author_url($post->author_url)->url($post->url === '' ? URL : URL . 'posts/' . $post->url)->date(date('D M jS, Y \\a\\t h:iA', strtotime($post->created))); $this->content .= "{$template}"; }, array_filter($this->data, 'is_object')); $this->content .= '</div>'; break; } }
$URL->host = substr($URL->host, 4); $redirect = true; } elseif (array_key_exists('tags', $_REQUEST)) { $URL->path .= 'tags/' . urlencode($_REQUEST['tags']); $redirect = true; } if ($redirect) { unset($URL->user, $URL->pass, $URL->query, $URL->fragment); http_response_code(301); $headers->Location = "{$URL}"; exit; } unset($redirect); $session = \shgysk8zer0\Core\Session::load(); $cookie = \shgysk8zer0\Core\Cookies::load($URL->host); $cookie->path = $URL->path; $cookie->secure = https(); $cookie->httponly = true; if (isset($session->logged_in) and $session->logged_in) { //Check login if session \shgysk8zer0\Core\Login::load()->setUser($session->user)->setPassword($session->password)->setRole($session->role)->setLogged_In($session->logged_in); } require_once __DIR__ . DIRECTORY_SEPARATOR . 'std-php-functions' . DIRECTORY_SEPARATOR . 'error_handler.php'; if (in_array('application/json', explode(',', $headers->accept))) { require_once __DIR__ . DIRECTORY_SEPARATOR . 'ajax.php'; exit; } unset($URL, $login, $session, $cookie, $headers); CSP(); //Do this here to avoid CSP being set on ajax requests. load('html');