/** * doExecute * * @return bool|string * * @throws \Exception */ protected function doExecute() { $view = new PostHtmlView($this->data); $model = new PostModel(); $id = $this->input->get('id'); $alias = $this->input->getString('alias'); $type = $this->input->get('type'); $view['type'] = $type; $view['post'] = $post = $model->getItem($id); $view['postAuthor'] = Author::getPostAuthor($post->author); $view['avatar'] = Author::getAvatar($view['postAuthor']->id, 200); if ($post->isNull()) { throw new \Exception('Post not found', 404); } if ($post->blog != $view['blog']->id) { throw new \Exception('Post not found', 404); } if (urldecode($alias) != $view['post']->alias) { $get = $this->input->get; $get->set('_rawRoute', null); $queries = $this->input->get->getArray(); $queries['alias'] = $view['post']->alias; $this->app->redirect(Router::buildHttp('front:post_default', $queries), true); return false; } return $view->render(); }
/** * prepareData * * @param \Windwalker\Data\Data $data * * @return void */ protected function prepareData($data) { $markdown = new MarkdownExtra(); foreach ($data['posts'] as $post) { $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]); $post->introtext = $markdown->defaultTransform($post->introtext); $post->author = Author::getPostAuthor($post->author); $post->created = new Date($post->created); $post->created = $post->created->format('F j, Y'); } foreach ($data['statics'] as $post) { $post->link = Router::buildHtml('front:static_default', ['id' => $post->id, 'alias' => $post->alias]); } // Title if ($data->type == 'home') { $title = $data->blog->title; $suffix = ''; $data->bodyClass = 'home posts page-' . $data->page; } else { $title = ''; $suffix = $data->blog->title; $data->bodyClass = 'home posts page-' . $data->page; } $data->pageTitle = $title; $data->pageTitle .= $data->page > 1 ? ' - Page ' . $data->page : ''; $data->pageTitle .= $suffix ? '|' . $suffix : ''; // Meta $desc = $data->blog->description; $desc = OutputFilter::cleanText($desc); $desc = Utf8String::substr($desc, 0, 200); $data->meta->desc = $desc; }
/** * prepareData * * @param \Windwalker\Data\Data $data * * @return void */ protected function prepareData($data) { $markdown = new MarkdownExtra(); foreach ($data['posts'] as $post) { $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]); $post->introtext = $markdown->defaultTransform($post->introtext); $post->author = Author::getPostAuthor($post->author); } }