/** * 缓存管理API * * @param Request $request * @param Setting $settingModel * @param SmpJsonView $view * * @return \Focus\MVC\View */ public function cacheAction(Request $request, Setting $settingModel, SmpJsonView $view) { // __tags__, __nav__, post_[id], list_[current], list_[cat]_[current], tag_[tagName]_[current] $key = $request->get('key'); $clear = $request->get('clear', 'false'); $token = $request->get('token', ''); $byprefix = $request->get('byprefix', false); if (empty($key)) { return $view->assign('status', false)->assign('info', 'key_required'); } $tokenEntity = $settingModel->getSetting('cache_token', 'system'); if (empty($tokenEntity) || !isset($tokenEntity['setting_value']) || $token !== $tokenEntity['setting_value']) { return $view->assign('status', false)->assign('info', 'token_invalid'); } // 通过前缀处理 if ($byprefix === 'true') { $res = $this->getCache()->all($key); $view->assign('original', $res); if ($clear == 'true') { foreach ($res as $_key => $_val) { $this->getCache()->delete($_key); } } return $view->assign('status', true)->assign('info', 'clear ' + count($res) + ' items'); } $res = $this->getCache()->get($key); if ($res !== false) { $this->assign('original', $res); if ($clear == 'true') { return $view->assign('status', $this->getCache()->delete($key)); } } return $view->assign('status', $res); }
/** * 根据标签名称获取相关文章 * * @param Request $request * @param Tags $tagModel * @param Post $postModel * @param SmpJsonView $jsonView * * @return SmpJsonView */ public function relatedPostsAction(Request $request, Tags $tagModel, Post $postModel, SmpJsonView $jsonView) { $tags = $tagModel->getTagsByNames(explode(',', $request->get('tags', ''))); $tag_ids = []; foreach ($tags as $tag) { $tag_ids[] = $tag['id']; } $posts = $postModel->getPostsInfoByTags($tag_ids, 10); $jsonView->assign('posts', $posts); $jsonView->assign('status', true); return $jsonView; }