Article.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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'], 'font-family:" microsoft="" yahei","黑体",sans-serif')) {
  27. $data['content'] = str_replace('font-family:" microsoft="" yahei","黑体",sans-serif', '', $data['content']);
  28. }
  29. if (strstr($data['content'], '"="')) {
  30. $data['content'] = str_replace('"="', '', $data['content']);
  31. }
  32. if (strstr($data['content'], 'embed')) {
  33. //print_r($data['content']);die;
  34. # 音频
  35. preg_match_all('/<embed src="(.*?)"(.*?)\/>/i', $data['content'], $matches);
  36. if (isset($matches[1])) {
  37. foreach ($matches[1] as $k => $v) {
  38. }
  39. }
  40. }
  41. if (strstr($data['content'], 'data-id')) {
  42. # 视频
  43. preg_match_all('/<p(.*?)>(\s[^>]*)<img(.*?)data-id="(.*?)" data-key="(.*?)" \/>(\s[^>]*)<\/p>/is', $data['content'], $matches);
  44. $replace = array();
  45. $content = $data['content'];
  46. if (isset($matches[4][0]) && isset($matches[5][0])) {
  47. foreach ($matches[4] as $k => $v) {
  48. $content = str_replace($matches[0][$k], '{replace}'.$k.'{replace}', $content);
  49. if ($matches[5][$k] == 'video/lib/core.vod') {
  50. $method = 'video/lib/vod';
  51. $type = 2;
  52. } else {
  53. $type = 3;
  54. $method = 'video/lib/live';
  55. }
  56. $info = Dever::load($method)->get($v);
  57. if (isset($info['content'])) {
  58. unset($info['content']);
  59. }
  60. $replace[$k] = array('id' => $v, 'type' => $type, 'content' => $info);
  61. }
  62. }
  63. //$data['content'] = preg_replace('/<div class="dever-drop">([\s\S]*?)<\/div>/i', '', $data['content']);
  64. $content = explode('{replace}', $content);
  65. $data['content_array'] = array();
  66. foreach ($content as $k => $v) {
  67. $v = trim($v);
  68. if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
  69. $data['content_array'][] = $replace[$v];
  70. } elseif ($v) {
  71. $data['content_array'][] = array
  72. (
  73. 'type' => 1,
  74. 'content' => $v,
  75. );
  76. }
  77. }
  78. }
  79. if (!$data['content_array']) {
  80. $data['content_array'][] = array
  81. (
  82. 'type' => 1,
  83. 'content' => $data['content'],
  84. );
  85. }
  86. //unset($data['content']);
  87. return $data;
  88. }
  89. # 获取相关推荐
  90. public function getRelation($info)
  91. {
  92. $where['noid'] = $info['id'];
  93. $where['cate_id'] = $info['cate_id'];
  94. return Dever::db('content/article')->getRelation($where);
  95. }
  96. # 增加浏览量
  97. public function addView($id)
  98. {
  99. Dever::db('content/article')->addView($id);
  100. }
  101. }