123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace Push\Lib;
- use Dever;
- class Data
- {
- public function get($key, $name, $total = 10, $col = '1,2,3,4,5,6,7', $function = '10',$page = false, $limit = false)
- {
- $info = Dever::db('push/info')->one(array('key' => $key));
- if (!$info) {
- $insert['key'] = $key;
- $insert['name'] = $name;
- $insert['num'] = $total;
- $insert['col'] = $col;
- $insert['function'] = $function;
- $info['id'] = Dever::db('push/info')->insert($insert);
- $info['num'] = $insert['num'];
- }
- $data = array();
- if ($info) {
- if (!$info['num']) {
- $info['num'] = 20;
- }
- if ($limit > 0) {
- $info['num'] = $limit;
- }
- $where = array();
- $where['info_id'] = $info['id'];
- if ($page) {
- $where['page'] = array($info['num'], 'list');
- $data = Dever::db('push/data')->getAllPage($where);
- } else {
- $where['limit'] = '0,' . $info['num'];
- $data = Dever::db('push/data')->getAll($where);
- }
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k] = $this->getOne($v);
- }
- }
- }
- return $data;
- }
- private function getOne($info)
- {
- $info['id'] = 0;
- if ($info['type'] == 10) {
- $info['link'] = $info['olink'];
- }
- if ($info['type'] < 10) {
- $table = Dever::config('base')->table_name[$info['type']];
- $method = 'one';
- $id = $table[1];
- $id = $info[$id];
- unset($info[$id]);
- if ($id > 0) {
- if (!$info['link']) {
- if ($info['type'] >= 3) {
- $info['link'] = Dever::url('main/article?type='.($info['type']-2).'&id=' . $id);
- } elseif ($info['type'] == 1) {
- $info['link'] = Dever::url('main/zwz-detail?id=' . $id);
- } elseif ($info['type'] == 2) {
- $info['link'] = Dever::url('main/xnr-detail?id=' . $id);
- }
- }
- $info['id'] = $id;
- $data = Dever::db($table[0])->$method($id);
- if (isset($data) && $data) {
- if (isset($data['name']) && $data['name'] && !$info['name']) {
- $info['name'] = $data['name'];
- }
- if (isset($data['desc']) && $data['desc'] && !$info['desc']) {
- $info['desc'] = $data['desc'];
- }
- if (isset($data['info']) && $data['info'] && !$info['content']) {
- $info['content'] = $data['info'];
- }
- if (isset($data['author']) && $data['author'] && !$info['author']) {
- $info['author'] = $data['author'];
- }
- if (isset($data['pdate']) && $data['pdate'] && !$info['pdate']) {
- $info['pdate'] = $data['pdate'];
- }
- if (isset($data['pic']) && $data['pic'] && !$info['pic']) {
- $info['pic'] = $data['pic'];
- }
- if (isset($data['small_pic']) && $data['small_pic'] && !$info['pic']) {
- $info['pic'] = $data['small_pic'];
- }
- if (isset($data['link']) && $data['link'] && !$info['link']) {
- $info['link'] = $data['link'];
- }
- if (isset($data['video']) && $data['video']) {
- /*
- $info['video'] = $data['video'];
- $info['video_info'] = Dever::qqvideo($data['video']);
- $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
- */
- $info['video_link'] = Dever::url('main/content.video?id=' . $id);
- }
- }
- }
- }
- if ($info['link']) {
- if (!strstr($info['link'], 'http')) {
- $info['link'] = 'http://' . $info['link'];
- }
- }
- $info['small_pic'] = $info['pic'];
- if ($info['pdate']) {
- $info['pdate_string'] = date('M d, Y', $info['pdate']);
- if ($info['author']) {
- $info['pdate_string'] .= ' by ' . $info['author'];
- }
- }
- $info['info'] = $info['content'];
- $info['cdate'] = date('Y-m-d', $info['cdate']);
- if (isset($info['pic']) && $info['pic']) {
- $info['pic'] = Dever::load('main/lib/core')->replacePic($info['pic']);
- }
- if (isset($info['name']) && $info['name']) {
- $info['name'] = Dever::cut($info['name'], 20, '...');
- }
- return $info;
- }
- }
|