/** * 首页 * @param HttpRequest $request */ public function index(HttpRequest $request) { $articleService = Beans::get('article.article.service'); $mediaService = Beans::get('media.media.service'); $tagService = Beans::get('article.tags.service'); //获取文章 $condi = getArticleBasicConditions(); $fileds = 'id,title,tags,bcontent,chanel_id,media_id,thumb,add_time'; $items = $articleService->getItems($condi, $fileds, 'add_time DESC', 1, 20); //配置缓存 $cacheInfo = array('baseKey' => '__common', 'ftype' => 'ajax', 'factor' => 1, 'expr' => 300); $articles =& $this->loadArticleInfo($items, ART_INFO_DEFAULT, $cacheInfo); $this->assign('items', $articles); //获取热点排行文章 $hotRanks = $articleService->getHotRank(10, 'id,title'); $this->assign('hotRanks', $hotRanks); //获取周排行 $weekRanks = $articleService->getWeekRank(10, 'id,title'); $this->assign('weekRanks', $weekRanks); //获取编辑推荐的文章 $editorRec = $articleService->getEditorRecommend(10); $this->assign('editorRec', $editorRec); //获取推荐媒体信息 $niulanMedia = $mediaService->getRecommendMedia(4, 'niulan'); $this->assign('niulanMedia', $niulanMedia); //驼牛联盟 $tnlm = $mediaService->getRecommendMedia(8, 'tuoniulianmeng'); $this->assign('tnlm', $tnlm); //获取热门标签 $hotTags = $tagService->getHotTags(12); $this->assign('hotTags', $hotTags); //首页焦点图 $indexCarousel = $articleService->getIndexCarousel(4); $this->assign('indexRecommend', $indexCarousel); //注册seo信息 $appConfigs = $this->getTemplateVar('appConfigs'); $this->assign('seoTitle', $appConfigs['site_title']); $this->assign('seoKwords', $appConfigs['site_keywords']); $this->assign('seoDesc', $appConfigs['site_desc']); $this->setView('index'); }
/** * 用户收藏列表 * @param HttpRequest $request */ public function collection(HttpRequest $request) { $collectService = Beans::get('user.collect.service'); $articleService = Beans::get('article.article.service'); //查询用户收藏的文章id $articleOrderConditions = array('userid' => $this->loginUser['id']); $articleFields = 'aid'; $order = 'add_time DESC'; $articles = $collectService->getItems($articleOrderConditions, $articleFields, $order, $this->page, $this->pagesize); foreach ($articles as $value) { $ids[] = $value['aid']; } $ids = implode(",", $ids); if ($ids) { //查询订阅的文章 $conditions = getArticleBasicConditions(); $conditions['id'] = "#IN {$ids}"; $order = 'add_time desc'; $this->loadArticles($conditions, null, $order, $this->page, $this->pagesize); $this->getPageData($articleService->count($conditions)); } $this->setView('ucenter/collection'); }
/** * 频道页获取更多 * @param HttpRequest $request */ public function chanelJson(HttpRequest $request) { //获取所有子频道 $id = $request->getParameter('id', 'intval'); $sid = $request->getParameter('sid', 'intval'); $chanelService = Beans::get('admin.chanel.service'); if (!$sid) { $chanelsId = $chanelService->getItems("pid={$id}", 'id'); if ($chanelsId) { foreach ($chanelsId as $value) { $ids[] = $value['id']; } } } $ids = implode(',', $ids); $conditions = getArticleBasicConditions(); $conditions['chanel_id'] = $sid ? $sid : "#IN {$ids}"; $items = $this->getArticles($conditions, 'id,chanel_id,media_id,title,bcontent,add_time,thumb'); foreach ($items as $key => $value) { if ($value['thumb'] == '') { $items[$key]['thumb'] = '/res/global/images/reception/mobile_default_647.jpg'; } } if ($items) { AjaxResult::ajaxResult(1, 'success', $items); } else { AjaxResult::ajaxFailtureResult(); } }
/** * @see \article\service\interfaces\IArticleService::getEditorRecommend */ public function getEditorRecommend($rows = 10, $field = null) { //首先获取缓存,默认缓存有效期为5分钟 // $CACHER = CacheFactory::create('file'); // $CACHER->baseKey('article')->ftype('editorRecommend')->factor($rows); // $items = $CACHER->get(null, 300); // if ( $items ) { // return $items; // } if ($field == null) { $field = 'id, title, thumb'; } $result = array(); //1. 查看后台对应的推荐位是否有足够数量的文章 $recommendService = Beans::get('article.rec.service'); $recommend = $recommendService->getItem("position='editor_recommend'", 'aids'); if ($recommend['aids'] != '') { $items = $this->getItems("id in({$recommend['aids']})", $field, null, 1, $rows); if ($items) { $result = array_merge($result, $items); } } //2. 如果不够则直接从点击率最高的文章补上 if (count($items) < $rows) { $condi = getArticleBasicConditions(); if ($recommend['aids'] != '') { $condi['id'] = '#NI' . $recommend['aids']; } $__items = $this->getItems($condi, $field, 'hits DESC', 1, $rows - count($items)); if ($__items) { $result = array_merge($result, $__items); } } //添加缓存 //$CACHER->set(null, $result); return $result; }
/** * 媒体所包含的文章列表 * @param HttpRequest $request */ public function detail(HttpRequest $request) { $id = $request->getParameter('id', 'intval'); $page = $request->getParameter('page', 'intval'); if ($id <= 0) { page404(); } $this->setPage($page); //获取文章 $userService = Beans::get('user.user.service'); $articleService = Beans::get('article.article.service'); $mediaService = Beans::get('media.media.service'); $tagService = Beans::get('article.tags.service'); $baseCondi = getArticleBasicConditions(); $condi['media_id'] = $id; $condi = array_merge($condi, $baseCondi); $items = $articleService->getItems($condi, 'id,title,thumb,add_time,chanel_id, tags,media_id,bcontent', 'add_time DESC', $this->getPage(), $this->getPagesize()); $cacheInfo = array('baseKey' => 'article', 'ftype' => 'mediadetail', 'factor' => $id . '-' . $page, 'expr' => 300); $aricles =& $this->loadArticleInfo($items, ART_INFO_DEFAULT, $cacheInfo); $this->assign('items', $aricles); //获取分页 $count = $articleService->count($condi); $this->getPageData($count); //获取媒体信息 $mediaInfo = $mediaService->getItem($id, 'id,name,intro,logo'); $this->assign('mediaInfo', $mediaInfo); //获取媒体信息 $imageClass = 'logo'; $mediaInfo = $mediaService->getItem($id, "id, name, media_type, nickname, domain, logo, intro"); $mediaInfo['domain'] = trim($mediaInfo['domain']); if ($mediaInfo['domain'] != '') { $mediaInfo['domain'] = 'http://www.' . $mediaInfo['domain']; } else { $mediaInfo['domain'] = url('/site_index_index/?media_id=' . $id); } $mediaInfo['configs'] = cn_json_decode($mediaInfo['configs']); $this->assign('mediaInfo', $mediaInfo); //判断媒体类型 $mediaTypeService = Beans::get('media.type.service'); $type = $mediaTypeService->getItem($mediaInfo['media_type'], 'tkey'); if ($type['tkey'] != 'qunmei') { $imageClass = 'aside_publish_user'; } $this->assign('imageClass', $imageClass); //判断用户是否订阅此媒体 $loginUser = $userService->getLoginUser(); $mediaOrdered = 0; if ($loginUser) { $mediaOrderService = Beans::get('media.order.service'); $orderCondi = array('userid' => $loginUser['id'], 'media_id' => $id); if ($mediaOrderService->getItem($orderCondi)) { $mediaOrdered = 1; } } $this->assign('mediaOrdered', $mediaOrdered); //获取热点排行文章 $hotRanks = $articleService->getHotRank(10, 'id,title'); $this->assign('hotRanks', $hotRanks); //获取周排行 $weekRanks = $articleService->getWeekRank(10, 'id,title'); $this->assign('weekRanks', $weekRanks); //获取编辑推荐的文章 $editorRec = $articleService->getEditorRecommend(10); $this->assign('editorRec', $editorRec); //获取推荐媒体信息 $niulanMedia = $mediaService->getRecommendMedia(4, 'niulan'); $this->assign('niulanMedia', $niulanMedia); //获取热门标签 $hotTags = $tagService->getHotTags(12); $this->assign('hotTags', $hotTags); //注册页面seo信息 $this->assign('seoTitle', $mediaInfo['configs']['sitetitle'] . ' - 驼牛网牛媒体'); $this->assign('seoKwords', $mediaInfo['configs']['siteseo'] . '驼牛网,牛媒体'); $this->assign('seoDesc', $mediaInfo['configs']['sitedescription']); $this->setView('media_detail'); }
/** * 首页获取更多 * @param HttpRequest $request */ public function ajaxArticle(HttpRequest $request) { $page = $request->getParameter('page', 'intval'); $pagesize = $request->getParameter('pagesize', 'intval'); if ($page <= 0) { $page = $this->page; } if ($pagesize <= 0) { $pagesize = 20; } $articleService = Beans::get('article.article.service'); $condi = getArticleBasicConditions(); $items = $articleService->getItems($condi, 'id,chanel_id,title,kwords,bcontent,tags,media_id,add_time,thumb', 'id DESC', $page, $pagesize); $cacheInfo = array('baseKey' => '__common', 'ftype' => 'ajax', 'factor' => $page, 'expr' => 300); $articles =& $this->loadArticleInfo($items, ART_INFO_DEFAULT, $cacheInfo); foreach ($articles as $key => $value) { $articles[$key]['add_time'] = date('m-d H:i', $value['add_time']); } AjaxResult::ajaxResult('1', 'success', $articles); }