123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace Article\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('article/info')->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('article/info')->insert($update);
- } else {
- $update['where_id'] = $info['id'];
- Dever::db('article/info')->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('article/info')->list($where);
- $data['cate'] = Dever::db('article/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 vod_info($id)
- {
- $data = Dever::db('article/info')->one($id);
- return $data;
- }
- # 根据文章id 获取文章信息
- public function get($data, $uid = false)
- {
- if (!is_array($data)) {
- $data = Dever::db('article/info')->one($data);
- }
-
- if (!$data) {
- Dever::alert('错误的文章信息');
- }
- if ($data['author_id']) {
- $data['author'] = Dever::db('article/author')->one($data['author_id']);
- }
-
- $data = $this->getContent($data, $uid);
- return $data;
- }
- public function getContent($data, $uid = false)
- {
- //embed
- $data['content_array'] = $data['content_pic'] = array();
- $data['content'] = Dever::filter($data['content']);
- $content = $data['content'];
- $replace = array();
- # 过滤宽度
- if (strstr($data['content'], 'width:')) {
- $content = preg_replace('/width:(.*?)px/', 'width:100%', $content);
- }
- # 图片
- if (strstr($data['content'], '<img')) {
- preg_match_all('/<img(.*?)src="(.*?)" (.*?)\/>/', $content, $matches);
- if (isset($matches[2])) {
- foreach ($matches[2] as $k => $v) {
- $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
- $pic = $v;
- $replace[] = array('type' => 'pic', 'content' => $pic);
- $data['content_pic'][] = $pic;
- }
- }
- }
- //$data['content'] = preg_replace('/<div class="dever-drop">([\s\S]*?)<\/div>/i', '', $data['content']);
- $content = explode('{replace}', $content);
- $data['content_array'] = array();
- //print_r($content);die;
- foreach ($content as $k => $v) {
- $v = trim($v);
- if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
- $data['content_array'][] = $replace[$v];
- } elseif ($v) {
- $data['content_array'][] = array
- (
- 'type' => 'html',
- 'content' => $v,
- );
- }
- }
- if (!$data['content_array']) {
- $data['content_array'][] = array
- (
- 'type' => 'html',
- 'content' => $data['content'],
- );
- }
- unset($data['content']);
- //print_r($data['content_array']);die;
- return $data;
- }
- # 获取相关推荐
- public function getRelation($info)
- {
- $where['noid'] = $info['id'];
- $where['cate_id'] = $info['cate_id'];
- return Dever::db('article/info')->getRelation($where);
- }
- # 增加浏览量
- public function addView($id)
- {
- Dever::db('article/info')->addView($id);
- }
- }
|