Article.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Article
  5. {
  6. # 根据文章id 获取文章信息
  7. public function get($data)
  8. {
  9. if (!is_array($data)) {
  10. $data = Dever::db('content/article')->getOne($data);
  11. }
  12. if (!$data) {
  13. Dever::alert('错误的文章信息');
  14. }
  15. //embed
  16. $data['content_array'] = array();
  17. if (strstr($data['content'], 'font-family:" gb","microsoft="" sans="" hiragino="" yahei","simsun";')) {
  18. $data['content'] = str_replace('font-family:" gb","microsoft="" sans="" hiragino="" yahei","simsun";', '', $data['content']);
  19. }
  20. if (strstr($data['content'], 'font-family:" yahei","simsun";')) {
  21. $data['content'] = str_replace('font-family:" yahei","simsun";', '', $data['content']);
  22. }
  23. if (strstr($data['content'], '"="" gb","microsoft="" sans="" hiragino="')) {
  24. $data['content'] = str_replace('"="" gb","microsoft="" sans="" hiragino="', '', $data['content']);
  25. }
  26. if (strstr($data['content'], '"="')) {
  27. $data['content'] = str_replace('"="', '', $data['content']);
  28. }
  29. if (strstr($data['content'], 'embed')) {
  30. //print_r($data['content']);die;
  31. # 音频
  32. preg_match_all('/<embed src="(.*?)"(.*?)\/>/i', $data['content'], $matches);
  33. if (isset($matches[1])) {
  34. foreach ($matches[1] as $k => $v) {
  35. }
  36. }
  37. }
  38. if (strstr($data['content'], 'data-id')) {
  39. # 视频
  40. preg_match_all('/<p>(\s[^>]*)<img(.*?)data-id="(.*?)" data-key="(.*?)" \/>(\s[^>]*)<\/p>/is', $data['content'], $matches);
  41. $replace = array();
  42. $content = $data['content'];
  43. if (isset($matches[3][0]) && isset($matches[4][0])) {
  44. foreach ($matches[3] as $k => $v) {
  45. $content = str_replace($matches[0][$k], '{replace}'.$k.'{replace}', $content);
  46. if ($matches[4][$k] == 'video/lib/core.vod') {
  47. $method = 'video/lib/vod';
  48. $type = 2;
  49. } else {
  50. $type = 3;
  51. $method = 'video/lib/live';
  52. }
  53. $info = Dever::load($method)->get($v);
  54. $replace[$k] = array('id' => $v, 'type' => $type, 'content' => $info);
  55. }
  56. }
  57. //$data['content'] = preg_replace('/<div class="dever-drop">([\s\S]*?)<\/div>/i', '', $data['content']);
  58. $content = explode('{replace}', $content);
  59. $data['content_array'] = array();
  60. foreach ($content as $k => $v) {
  61. if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
  62. $data['content_array'][] = $replace[$v];
  63. } elseif ($content[$k]) {
  64. $data['content_array'][] = array
  65. (
  66. 'type' => 1,
  67. 'content' => $v,
  68. );
  69. }
  70. }
  71. }
  72. if (!$data['content_array']) {
  73. $data['content_array'][] = array
  74. (
  75. 'type' => 1,
  76. 'content' => $data['content'],
  77. );
  78. }
  79. unset($data['content']);
  80. print_r($data);die;
  81. return $data;
  82. }
  83. # 获取相关推荐
  84. public function getRelation($info)
  85. {
  86. $where['noid'] = $info['id'];
  87. $where['cate_id'] = $info['cate_id'];
  88. return Dever::db('content/article')->getRelation($where);
  89. }
  90. # 增加浏览量
  91. public function addView($id)
  92. {
  93. Dever::db('content/article')->addView($id);
  94. }
  95. }