Feature.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Feature
  5. {
  6. # 根据文章id 获取文章信息
  7. public function get($data, $uid = false)
  8. {
  9. if (!is_array($data)) {
  10. $data = Dever::db('content/feature')->find($data);
  11. }
  12. if (!$data) {
  13. Dever::alert('错误的专题信息');
  14. }
  15. $data = $this->getContent($data, $uid);
  16. return $data;
  17. }
  18. public function getContent($data, $uid = false)
  19. {
  20. //embed
  21. $data['content_array'] = array();
  22. $data['content'] = Dever::filter($data['content']);
  23. $content = $data['content'];
  24. $replace = array();
  25. if (strstr($data['content'], 'data-id')) {
  26. # 商品
  27. preg_match_all('/<img(.*?)data-id="(.*?)" data-key="(.*?)" \/>/', $content, $matches);
  28. if (!isset($matches[2][0])) {
  29. preg_match_all('/<img(.*?)data-key="(.*?)" data-id="(.*?)" \/>/', $content, $matches);
  30. $temp = array();
  31. if (isset($matches[2][0]) && isset($matches[3][0])) {
  32. $temp = $matches;
  33. $matches[2] = $temp[3];
  34. $matches[3] = $temp[2];
  35. unset($temp);
  36. }
  37. }
  38. if (isset($matches[2][0]) && isset($matches[3][0])) {
  39. foreach ($matches[2] as $k => $v) {
  40. $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
  41. if ($matches[3][$k] == 'goods/lib/manage.editor') {
  42. $method = 'goods/lib/info';
  43. $type = 3;
  44. $info = Dever::load($method)->getInfo($v);
  45. if (isset($info['content'])) {
  46. unset($info['content']);
  47. }
  48. $replace[] = array('id' => $v, 'type' => $type, 'content' => $info);
  49. }
  50. }
  51. }
  52. }
  53. /*
  54. elseif (strstr($data['content'], 'jpg')) {
  55. # gif
  56. preg_match_all('/<img(.*?)src="(.*?)\.jpg" (.*?)\/>/', $content, $matches);
  57. if (isset($matches[2])) {
  58. foreach ($matches[2] as $k => $v) {
  59. $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
  60. $pic = $v;
  61. $replace[] = array('type' => 2, 'pic' => $pic . '.jpg');
  62. }
  63. }
  64. }
  65. elseif (strstr($data['content'], 'gif')) {
  66. # gif
  67. preg_match_all('/<img(.*?)src="(.*?)\.gif" (.*?)\/>/', $content, $matches);
  68. if (isset($matches[2])) {
  69. foreach ($matches[2] as $k => $v) {
  70. $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
  71. $pic = $v;
  72. $replace[] = array('type' => 2, 'pic' => $pic . '.gif');
  73. }
  74. }
  75. }
  76. elseif (strstr($data['content'], 'png')) {
  77. # gif
  78. preg_match_all('/<img(.*?)src="(.*?)\.png" (.*?)\/>/', $content, $matches);
  79. if (isset($matches[2])) {
  80. foreach ($matches[2] as $k => $v) {
  81. $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
  82. $pic = $v;
  83. $replace[] = array('type' => 2, 'pic' => $pic . '.png');
  84. }
  85. }
  86. }
  87. */
  88. //$data['content'] = preg_replace('/<div class="dever-drop">([\s\S]*?)<\/div>/i', '', $data['content']);
  89. $content = explode('{replace}', $content);
  90. $data['content_array'] = array();
  91. //print_r($content);die;
  92. foreach ($content as $k => $v) {
  93. $v = trim($v);
  94. if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
  95. $data['content_array'][] = $replace[$v];
  96. } elseif ($v) {
  97. $data['content_array'][] = array
  98. (
  99. 'type' => 1,
  100. 'content' => $v,
  101. );
  102. }
  103. }
  104. if (!$data['content_array']) {
  105. $data['content_array'][] = array
  106. (
  107. 'type' => 1,
  108. 'content' => $data['content'],
  109. );
  110. }
  111. unset($data['content']);
  112. return $data;
  113. }
  114. }