Article.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace Article\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('article/info')->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('article/info')->insert($update);
  43. } else {
  44. $update['where_id'] = $info['id'];
  45. Dever::db('article/info')->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('article/info')->list($where);
  82. $data['cate'] = Dever::db('article/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. public function vod_info($id)
  93. {
  94. $data = Dever::db('article/info')->one($id);
  95. return $data;
  96. }
  97. # 根据文章id 获取文章信息
  98. public function get($data, $uid = false)
  99. {
  100. if (!is_array($data)) {
  101. $data = Dever::db('article/info')->one($data);
  102. }
  103. if (!$data) {
  104. Dever::alert('错误的文章信息');
  105. }
  106. if ($data['author_id']) {
  107. $data['author'] = Dever::db('article/author')->one($data['author_id']);
  108. }
  109. $data = $this->getContent($data, $uid);
  110. return $data;
  111. }
  112. public function getContent($data, $uid = false)
  113. {
  114. //embed
  115. $data['content_array'] = $data['content_pic'] = array();
  116. $data['content'] = Dever::filter($data['content']);
  117. $content = $data['content'];
  118. $replace = array();
  119. # 过滤宽度
  120. if (strstr($data['content'], 'width:')) {
  121. $content = preg_replace('/width:(.*?)px/', 'width:100%', $content);
  122. }
  123. # 图片
  124. if (strstr($data['content'], '<img')) {
  125. preg_match_all('/<img(.*?)src="(.*?)" (.*?)\/>/', $content, $matches);
  126. if (isset($matches[2])) {
  127. foreach ($matches[2] as $k => $v) {
  128. $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
  129. $pic = $v;
  130. $replace[] = array('type' => 'pic', 'content' => $pic);
  131. $data['content_pic'][] = $pic;
  132. }
  133. }
  134. }
  135. //$data['content'] = preg_replace('/<div class="dever-drop">([\s\S]*?)<\/div>/i', '', $data['content']);
  136. $content = explode('{replace}', $content);
  137. $data['content_array'] = array();
  138. //print_r($content);die;
  139. foreach ($content as $k => $v) {
  140. $v = trim($v);
  141. if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
  142. $data['content_array'][] = $replace[$v];
  143. } elseif ($v) {
  144. $data['content_array'][] = array
  145. (
  146. 'type' => 'html',
  147. 'content' => $v,
  148. );
  149. }
  150. }
  151. if (!$data['content_array']) {
  152. $data['content_array'][] = array
  153. (
  154. 'type' => 'html',
  155. 'content' => $data['content'],
  156. );
  157. }
  158. unset($data['content']);
  159. //print_r($data['content_array']);die;
  160. return $data;
  161. }
  162. # 获取相关推荐
  163. public function getRelation($info)
  164. {
  165. $where['noid'] = $info['id'];
  166. $where['cate_id'] = $info['cate_id'];
  167. return Dever::db('article/info')->getRelation($where);
  168. }
  169. # 增加浏览量
  170. public function addView($id)
  171. {
  172. Dever::db('article/info')->addView($id);
  173. }
  174. }