Data.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace Push\Lib;
  3. use Dever;
  4. class Data
  5. {
  6. public function get($key, $name, $total = 10, $page = false, $limit = false)
  7. {
  8. $info = Dever::db('push/info')->one(array('key' => $key));
  9. if (!$info) {
  10. $insert['key'] = $key;
  11. $insert['name'] = $name;
  12. $insert['num'] = $total;
  13. $insert['col'] = '1,3';
  14. $info['id'] = Dever::db('push/info')->insert($insert);
  15. $info['num'] = $insert['num'];
  16. }
  17. $data = array();
  18. if ($info) {
  19. if (!$info['num']) {
  20. $info['num'] = 20;
  21. }
  22. if ($limit > 0) {
  23. $info['num'] = $limit;
  24. }
  25. $where = array();
  26. $where['info_id'] = $info['id'];
  27. if (checkVersion()->video == 2) {
  28. $where['type_no'] = 2;
  29. }
  30. if ($page) {
  31. $where['page'] = array($info['num'], 'list');
  32. $data = Dever::db('push/data')->getAllPage($where);
  33. } else {
  34. $where['limit'] = '0,' . $info['num'];
  35. $data = Dever::db('push/data')->getAll($where);
  36. }
  37. if ($data) {
  38. foreach ($data as $k => $v) {
  39. $data[$k] = $this->getOne($v);
  40. }
  41. }
  42. }
  43. return $data;
  44. }
  45. private function getOne($info)
  46. {
  47. $info['id'] = 0;
  48. if ($info['type'] < 10 || $info['type'] == 13) {
  49. $table = Dever::config('base')->type_table[$info['type']];
  50. $method = 'one';
  51. if ($info['type'] == 1) {
  52. $id = $info['article_id'];
  53. } elseif ($info['type'] == 2) {
  54. $id = $info['vod_id'];
  55. } elseif ($info['type'] == 3) {
  56. $id = $info['live_id'];
  57. } elseif ($info['type'] == 4) {
  58. $id = $info['journal_id'];
  59. $method = 'getOne';
  60. } elseif ($info['type'] == 6) {
  61. $id = $info['feature_id'];
  62. } elseif ($info['type'] == 7) {
  63. $id = $info['applet_id'];
  64. } elseif ($info['type'] == 13) {
  65. $id = $info['journal_id'];
  66. }
  67. unset($info['article_id']);
  68. unset($info['vod_id']);
  69. unset($info['live_id']);
  70. unset($info['journal_id']);
  71. unset($info['feature_id']);
  72. unset($info['applet_id']);
  73. if ($id > 0) {
  74. $info['id'] = $id;
  75. $data = Dever::db($table)->$method($id);
  76. if (isset($data) && $data) {
  77. if (isset($data['name']) && $data['name'] && !$info['name']) {
  78. $info['name'] = $data['name'];
  79. }
  80. if (isset($data['pic_cover']) && $data['pic_cover'] && !$info['pic']) {
  81. $info['pic'] = $data['pic_cover'];
  82. }
  83. if (isset($data['pic_cover_169'])) {
  84. $info['pic_169'] = $data['pic_cover_169'];
  85. }
  86. if (isset($data['pic_view_cover']) && $data['pic_view_cover'] && !$info['pic']) {
  87. $info['pic'] = $data['pic_view_cover'];
  88. }
  89. if (isset($data['num_ding'])) {
  90. $info['num_ding'] = $data['num_ding'];
  91. }
  92. if (isset($data['buy'])) {
  93. $info['buy'] = $data['buy'];
  94. }
  95. if (isset($data['pdate']) && $data['pdate']) {
  96. $info['cdate'] = $data['pdate'];
  97. }
  98. if (isset($data['cate_id']) && $data['cate_id']) {
  99. $cate = Dever::db('content/cate')->one($data['cate_id']);
  100. $info['cate_name'] = $cate['name'];
  101. }
  102. if (isset($data['author_id']) && $data['author_id']) {
  103. $author = Dever::db('content/author')->one($data['author_id']);
  104. $info['author_name'] = $author['name'];
  105. }
  106. if (isset($data['appid']) && $data['appid']) {
  107. $info['appid'] = $data['appid'];
  108. }
  109. if (isset($data['link']) && $data['link']) {
  110. $info['link'] = $data['link'];
  111. }
  112. }
  113. }
  114. } else {
  115. unset($info['article_id']);
  116. unset($info['vod_id']);
  117. unset($info['live_id']);
  118. unset($info['journal_id']);
  119. unset($info['feature_id']);
  120. unset($info['applet_id']);
  121. }
  122. if ($info['link']) {
  123. if (!strstr($info['link'], 'http')) {
  124. $info['link'] = 'http://' . $info['link'];
  125. }
  126. }
  127. $info['cdate'] = date('Y-m-d', $info['cdate']);
  128. if (isset($info['pic']) && $info['pic']) {
  129. $info['pic'] = Dever::load('main/lib/core')->replacePic($info['pic']);
  130. }
  131. if (isset($info['name']) && $info['name']) {
  132. $info['name'] = Dever::cut($info['name'], 20, '...');
  133. }
  134. return $info;
  135. }
  136. }