123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- namespace Content\Lib;
- use Dever;
- class Article
- {
- # 同步信息接口
- public function up_api()
- {
- $name = Dever::input('name');
- $desc = Dever::input('desc');
- $pic_cover = Dever::input('pic_cover');
- $pic_index = Dever::input('pic_index');
- $content = Dever::input('content');
- $template = Dever::input('template');
- if ($template == 2) {
- $video = Dever::input('video');
- }
- $cate_id = Dever::input('cate_id');
- $cate_id = $this->getCate($cate_id);
- $pdate = Dever::input('pdate');
- $source_id = Dever::input('source_id');
- $update['template'] = $template;
- $update['source_id'] = $source_id;
- $info = Dever::db('content/article')->one($update);
- //$parse = $this->parseContent($content);
- //print_r($parse);die;
- if ($content) {
- $content = Dever::json_decode($content);
- $content = $this->getContentHtml($content);
- }
- $update['name'] = $name;
- $update['desc'] = $desc;
- $update['pic_cover'] = $pic_cover;
- $update['pic_index'] = $pic_index;
- $update['content'] = $content;
- $update['cate_id'] = $cate_id;
- if (isset($video) && $video) {
- $update['video'] = $video;
- }
- if (!$info) {
- $update['pdate'] = $pdate;
- Dever::db('content/article')->insert($update);
- } else {
- $update['where_id'] = $info['id'];
- Dever::db('content/article')->update($update);
- }
- return 'ok';
- }
- public function getCate($id)
- {
- $config = array
- (
- 1 => 6,
- 2 => 4,
- 3 => 1,
- 4 => 2,
- 5 => 3,
- 6 => 6,
- 7 => 6,
- 9 => 5,
- 12 => 6,
- );
- if (isset($config[$id])) {
- return $config[$id];
- }
- return $id;
- }
- public function vod_api()
- {
- $data['name'] = '视频';
- $where = array();
- $name = Dever::input('search_name');
- $cate = Dever::input('search_cate');
- if ($name) {
- $where['name'] = $name;
- }
- if ($cate > 0) {
- $where['cate_id'] = $cate;
- }
- $where['template'] = 2;
- $data['file'] = Dever::db('content/article')->list($where);
- $data['cate'] = Dever::db('content/cate')->state();
- if ($data['file']) {
- foreach ($data['file'] as $k => $v) {
- $data['file'][$k]['source_name'] = $v['name'];
- $data['file'][$k]['file'] = $v['pic_cover'];
- $data['file'][$k]['pic'] = $v['pic_cover'];
- }
- }
- return $data;
- }
- # 获取人气点击列表
- public function getDataByNum()
- {
- $data = Dever::db('content/article')->getDataByNum();
- return $data;
- }
- # 获取最新列表
- public function getList()
- {
- $data = Dever::db('content/article')->getList();
- if ($data) {
- foreach ($data as $k => $v) {
- $cate = Dever::db('content/cate')->one($v['cate_id']);
- $data[$k]['cate_name'] = $cate['name'];
- $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
- $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
- }
- }
- return $data;
- }
- # 获取最新列表
- public function getAll()
- {
- $where = array();
- $cate_id = Dever::input('cid');
- if ($cate_id > 0) {
- $where['cate_id'] = $cate_id;
- }
- $data = Dever::db('content/article')->getAll($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $cate = Dever::db('content/cate')->one($v['cate_id']);
- $data[$k]['cate_name'] = $cate['name'];
- $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
- $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
- }
- }
- return $data;
- }
- # 获取文章信息
- public function getInfo()
- {
- $id = Dever::input('id');
- $data = Dever::db('content/article')->getOne($id);
- if (!$data) {
- Dever::alert('错误的文章信息');
- }
- if ($data['author_id']) {
- $data['author'] = Dever::db('content/author')->one($data['author_id']);
- }
- $data['cdate'] = date('Y-m-d', $data['pdate']);
- $data['tag_html'] = '';
- if ($data['tag']) {
- $tag_data = Dever::load('tag/api')->tag_content($data['author_id']);
- if ($tag_data) {
- $data['tag_html'] = '标签:';
- foreach ($tag_data as $k => $v) {
- $link = Dever::url('search_list?tid=' . $v['id']);
- $data['tag_html'] .= '<a href="'.$link.'" target="_blank">'.$v['name'].'</a>';
- }
- }
- }
- # 获取上一篇和下一篇
- $where['id'] = $id;
- $where['cate_id'] = $data['cate_id'];
- $data['prev'] = Dever::db('content/article')->findPrev($where);
- if ($data['prev']) {
- $data['prev']['link'] = Dever::load('content/lib/common')->getInfoLink(1, $data['prev']['id']);
- }
- $data['next'] = Dever::db('content/article')->findNext($where);
- if ($data['next']) {
- $data['next']['link'] = Dever::load('content/lib/common')->getInfoLink(1, $data['next']['id']);
- }
- //print_r($data);die;
- $this->addView($id);
- return $data;
- }
- # 获取相关推荐
- public function getRelation()
- {
- $where['noid'] = Dever::input('id');
- $data = Dever::db('content/article')->getOne($where['noid']);
- $where['cate_id'] = $data['cate_id'];
- $data = Dever::db('content/article')->getRelation($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
- $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
- }
- }
- return $data;
- }
- # 增加浏览量
- public function addView($id)
- {
- Dever::db('content/article')->addView(array('where_id' => $id, 'set_num_view' => 1));
- }
- # 获取精彩推荐
- public function getTop($cate_id = false)
- {
- $where = array();
- if ($cate_id) {
- $where['cate_id'] = $cate_id;
- }
-
- $data = Dever::db('content/article')->getTop($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $cate = Dever::db('content/cate')->one($v['cate_id']);
- $data[$k]['cate_name'] = $cate['name'];
- $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
- $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
- }
- }
- return $data;
- }
- }
|