app->request->param(); $list = ArticleModel::queryPage($params); View::assign([ 'list' => $list, 'cid' => $params['cid'] ]); return View::fetch(); } /** * 阅读文章 */ public function read($id = null) { $data = ArticleModel::getOne($id); if (!$data) { throw new HttpException(404, '页面不存在'); } $prev_next = ArticleModel::getNextPrev($id, $data->cid); if ($data->content_type == 1) { $parsedownExtension = new ParsedownUtils(); // $parsedownExtension->setTocEnabled(true); $res = $parsedownExtension->text($data->content); // $data->toc = $res['toc']; $data->content = $res['content']; } View::assign('cid', $data->cid); View::assign('data', $data); View::assign('prev_next', $prev_next); $this->seo['title'] = $data->title; $this->seo['key'] = $data->keywords; $this->seo['des'] = $data->summary; View::assign('seo', $this->seo); return View::fetch(); } /** * 文章点赞 */ public function dolike() { $id = $this->request->post('id'); $ip = $this->request->ip(); $log = ArticleDolikeLog::where('aid', $id)->where('ip', $ip)->find(); if ($log) { return ['code' => 1, 'msg' => '多谢喜欢, 已经点过赞了']; } $res = ArticleModel::where('id', $id)->inc('likes')->update(); // 记录 dolike 日志 @ArticleDolikeLog::create([ 'aid' => $id, 'ip' => $this->request->ip() ]); if ($res === false) { return ['code' => 2, 'msg' => '未知错误']; } else { return ['code' => 0]; } } /** * 标签列表 */ public function tag($name = null) { if (!$name) { throw new HttpException(404, '标签不可为空'); } $tag = Tag::where('tagname', $name)->find(); if (!$tag) { throw new HttpException(404, '标签不存在'); } $list = TagArticle::queryList($tag->id); View::assign([ 'list' => $list, 'tag' => $name ]); return View::fetch(); } /** * 归档页面(时间) */ public function archive($year = 0, $month = 0) { if ($year == 0 || $month == 0) { throw new HttpException(404, '日期格式不正确'); } $yearMonth = $year . '-' . $month; $params = $this->app->request->param(); $list = ArticleModel::queryPage($params); View::assign([ 'list' => $list, 'yearMonth' => $yearMonth ]); return View::fetch(); } /** * 时光轴 */ public function time() { $params = $this->app->request->param(); $list = ArticleModel::queryPage($params); View::assign('list', $list); return View::fetch(); } /** * 文章搜索 */ public function search() { $key = $this->app->request->has('key') ? $this->app->request->param('key') : ""; if ($key != "") { $params = $this->app->request->param(); $list = ArticleModel::queryPage($params); View::assign('list', $list); } View::assign("key", $key); return View::fetch(); } }