Data.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace Push\Lib;
  3. use Dever;
  4. class Data
  5. {
  6. public function get($key, $name, $total = 10, $col = '1,2,3,4,5,6,7', $function = '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'] = $col;
  14. $insert['function'] = $function;
  15. $info['id'] = Dever::db('push/info')->insert($insert);
  16. $info['num'] = $insert['num'];
  17. }
  18. $data = array();
  19. if ($info) {
  20. if (!$info['num']) {
  21. $info['num'] = 20;
  22. }
  23. if ($limit > 0) {
  24. $info['num'] = $limit;
  25. }
  26. $where = array();
  27. $where['info_id'] = $info['id'];
  28. if ($page) {
  29. $where['page'] = array($info['num'], 'list');
  30. $data = Dever::db('push/data')->getAllPage($where);
  31. } else {
  32. $where['limit'] = '0,' . $info['num'];
  33. $data = Dever::db('push/data')->getAll($where);
  34. }
  35. if ($data) {
  36. foreach ($data as $k => $v) {
  37. $data[$k] = $this->getOne($v);
  38. }
  39. }
  40. }
  41. return $data;
  42. }
  43. private function getOne($info)
  44. {
  45. $info['id'] = 0;
  46. if ($info['type'] == 10) {
  47. $info['link'] = $info['olink'];
  48. }
  49. if ($info['type'] < 10) {
  50. $table = Dever::config('base')->table_name[$info['type']];
  51. $method = 'one';
  52. $id = $table[1];
  53. $id = $info[$id];
  54. unset($info[$id]);
  55. if ($id > 0) {
  56. if (!$info['link']) {
  57. if ($info['type'] >= 3) {
  58. $info['link'] = Dever::url('main/article?type='.($info['type']-2).'&id=' . $id);
  59. } elseif ($info['type'] == 1) {
  60. $info['link'] = Dever::url('main/zwz-detail?id=' . $id);
  61. } elseif ($info['type'] == 2) {
  62. $info['link'] = Dever::url('main/xnr-detail?id=' . $id);
  63. }
  64. }
  65. $info['id'] = $id;
  66. $data = Dever::db($table[0])->$method($id);
  67. if (isset($data) && $data) {
  68. if (isset($data['name']) && $data['name'] && !$info['name']) {
  69. $info['name'] = $data['name'];
  70. }
  71. if (isset($data['desc']) && $data['desc'] && !$info['desc']) {
  72. $info['desc'] = $data['desc'];
  73. }
  74. if (isset($data['info']) && $data['info'] && !$info['content']) {
  75. $info['content'] = $data['info'];
  76. }
  77. if (isset($data['author']) && $data['author'] && !$info['author']) {
  78. $info['author'] = $data['author'];
  79. }
  80. if (isset($data['pdate']) && $data['pdate'] && !$info['pdate']) {
  81. $info['pdate'] = $data['pdate'];
  82. }
  83. if (isset($data['pic']) && $data['pic'] && !$info['pic']) {
  84. $info['pic'] = $data['pic'];
  85. }
  86. if (isset($data['small_pic']) && $data['small_pic'] && !$info['pic']) {
  87. $info['pic'] = $data['small_pic'];
  88. }
  89. if (isset($data['link']) && $data['link'] && !$info['link']) {
  90. $info['link'] = $data['link'];
  91. }
  92. if (isset($data['video']) && $data['video']) {
  93. /*
  94. $info['video'] = $data['video'];
  95. $info['video_info'] = Dever::qqvideo($data['video']);
  96. $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
  97. */
  98. $info['video_link'] = Dever::url('main/content.video?id=' . $id);
  99. }
  100. }
  101. }
  102. }
  103. if ($info['link']) {
  104. if (!strstr($info['link'], 'http')) {
  105. $info['link'] = 'http://' . $info['link'];
  106. }
  107. }
  108. $info['small_pic'] = $info['pic'];
  109. if ($info['pdate']) {
  110. $info['pdate_string'] = date('M d, Y', $info['pdate']);
  111. if ($info['author']) {
  112. $info['pdate_string'] .= ' by ' . $info['author'];
  113. }
  114. }
  115. $info['info'] = $info['content'];
  116. $info['cdate'] = date('Y-m-d', $info['cdate']);
  117. if (isset($info['pic']) && $info['pic']) {
  118. $info['pic'] = Dever::load('main/lib/core')->replacePic($info['pic']);
  119. }
  120. if (isset($info['name']) && $info['name']) {
  121. $info['name'] = Dever::cut($info['name'], 20, '...');
  122. }
  123. return $info;
  124. }
  125. }