Article.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Article
  5. {
  6. # 同步信息接口
  7. public function up_api()
  8. {
  9. $name = Dever::input('name');
  10. $desc = Dever::input('desc');
  11. $pic_cover = Dever::input('pic_cover');
  12. $pic_index = Dever::input('pic_index');
  13. $content = Dever::input('content');
  14. $template = Dever::input('template');
  15. if ($template == 2) {
  16. $video = Dever::input('video');
  17. }
  18. $cate_id = Dever::input('cate_id');
  19. $cate_id = $this->getCate($cate_id);
  20. $pdate = Dever::input('pdate');
  21. $source_id = Dever::input('source_id');
  22. $update['template'] = $template;
  23. $update['source_id'] = $source_id;
  24. $info = Dever::db('content/article')->one($update);
  25. //$parse = $this->parseContent($content);
  26. //print_r($parse);die;
  27. if ($content) {
  28. $content = Dever::json_decode($content);
  29. $content = $this->getContentHtml($content);
  30. }
  31. $update['name'] = $name;
  32. $update['desc'] = $desc;
  33. $update['pic_cover'] = $pic_cover;
  34. $update['pic_index'] = $pic_index;
  35. $update['content'] = $content;
  36. $update['cate_id'] = $cate_id;
  37. if (isset($video) && $video) {
  38. $update['video'] = $video;
  39. }
  40. if (!$info) {
  41. $update['pdate'] = $pdate;
  42. Dever::db('content/article')->insert($update);
  43. } else {
  44. $update['where_id'] = $info['id'];
  45. Dever::db('content/article')->update($update);
  46. }
  47. return 'ok';
  48. }
  49. public function getCate($id)
  50. {
  51. $config = array
  52. (
  53. 1 => 6,
  54. 2 => 4,
  55. 3 => 1,
  56. 4 => 2,
  57. 5 => 3,
  58. 6 => 6,
  59. 7 => 6,
  60. 9 => 5,
  61. 12 => 6,
  62. );
  63. if (isset($config[$id])) {
  64. return $config[$id];
  65. }
  66. return $id;
  67. }
  68. public function vod_api()
  69. {
  70. $data['name'] = '视频';
  71. $where = array();
  72. $name = Dever::input('search_name');
  73. $cate = Dever::input('search_cate');
  74. if ($name) {
  75. $where['name'] = $name;
  76. }
  77. if ($cate > 0) {
  78. $where['cate_id'] = $cate;
  79. }
  80. $where['template'] = 2;
  81. $data['file'] = Dever::db('content/article')->list($where);
  82. $data['cate'] = Dever::db('content/cate')->state();
  83. if ($data['file']) {
  84. foreach ($data['file'] as $k => $v) {
  85. $data['file'][$k]['source_name'] = $v['name'];
  86. $data['file'][$k]['file'] = $v['pic_cover'];
  87. $data['file'][$k]['pic'] = $v['pic_cover'];
  88. }
  89. }
  90. return $data;
  91. }
  92. # 获取人气点击列表
  93. public function getDataByNum()
  94. {
  95. $data = Dever::db('content/article')->getDataByNum();
  96. return $data;
  97. }
  98. # 获取最新列表
  99. public function getList()
  100. {
  101. $data = Dever::db('content/article')->getList();
  102. if ($data) {
  103. foreach ($data as $k => $v) {
  104. $cate = Dever::db('content/cate')->one($v['cate_id']);
  105. $data[$k]['cate_name'] = $cate['name'];
  106. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
  107. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  108. }
  109. }
  110. return $data;
  111. }
  112. # 获取最新列表
  113. public function getAll()
  114. {
  115. $where = array();
  116. $cate_id = Dever::input('cid');
  117. if ($cate_id > 0) {
  118. $where['cate_id'] = $cate_id;
  119. }
  120. $data = Dever::db('content/article')->getAll($where);
  121. if ($data) {
  122. foreach ($data as $k => $v) {
  123. $cate = Dever::db('content/cate')->one($v['cate_id']);
  124. $data[$k]['cate_name'] = $cate['name'];
  125. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
  126. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  127. }
  128. }
  129. return $data;
  130. }
  131. # 获取文章信息
  132. public function getInfo()
  133. {
  134. $id = Dever::input('id');
  135. $data = Dever::db('content/article')->getOne($id);
  136. if (!$data) {
  137. Dever::alert('错误的文章信息');
  138. }
  139. if ($data['author_id']) {
  140. $data['author'] = Dever::db('content/author')->one($data['author_id']);
  141. }
  142. $data['cdate'] = date('Y-m-d', $data['pdate']);
  143. $data['tag_html'] = '';
  144. if ($data['tag']) {
  145. $tag_data = Dever::load('tag/api')->tag_content($data['author_id']);
  146. if ($tag_data) {
  147. $data['tag_html'] = '标签:';
  148. foreach ($tag_data as $k => $v) {
  149. $link = Dever::url('search_list?tid=' . $v['id']);
  150. $data['tag_html'] .= '<a href="'.$link.'" target="_blank">'.$v['name'].'</a>';
  151. }
  152. }
  153. }
  154. # 获取上一篇和下一篇
  155. $where['id'] = $id;
  156. $where['cate_id'] = $data['cate_id'];
  157. $data['prev'] = Dever::db('content/article')->findPrev($where);
  158. if ($data['prev']) {
  159. $data['prev']['link'] = Dever::load('content/lib/common')->getInfoLink(1, $data['prev']['id']);
  160. }
  161. $data['next'] = Dever::db('content/article')->findNext($where);
  162. if ($data['next']) {
  163. $data['next']['link'] = Dever::load('content/lib/common')->getInfoLink(1, $data['next']['id']);
  164. }
  165. //print_r($data);die;
  166. $this->addView($id);
  167. return $data;
  168. }
  169. # 获取相关推荐
  170. public function getRelation()
  171. {
  172. $where['noid'] = Dever::input('id');
  173. $data = Dever::db('content/article')->getOne($where['noid']);
  174. $where['cate_id'] = $data['cate_id'];
  175. $data = Dever::db('content/article')->getRelation($where);
  176. if ($data) {
  177. foreach ($data as $k => $v) {
  178. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
  179. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  180. }
  181. }
  182. return $data;
  183. }
  184. # 增加浏览量
  185. public function addView($id)
  186. {
  187. Dever::db('content/article')->addView(array('where_id' => $id, 'set_num_view' => 1));
  188. }
  189. # 获取精彩推荐
  190. public function getTop($cate_id = false)
  191. {
  192. $where = array();
  193. if ($cate_id) {
  194. $where['cate_id'] = $cate_id;
  195. }
  196. $data = Dever::db('content/article')->getTop($where);
  197. if ($data) {
  198. foreach ($data as $k => $v) {
  199. $cate = Dever::db('content/cate')->one($v['cate_id']);
  200. $data[$k]['cate_name'] = $cate['name'];
  201. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(1, $v['id']);
  202. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  203. }
  204. }
  205. return $data;
  206. }
  207. }