123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- namespace Page\Lib;
- use Dever;
- class Data
- {
- # 直接获取某个页面的基本信息
- public function getPageInfo($key = false)
- {
- if (!$key) {
- $page = Dever::input('key');
- if ($page) {
- $key = $page;
- } else {
- $key = Dever::uri();
- }
- }
-
- if (!$key) {
- $key = 'home';
- }
-
- $where['key'] = $key;
- $data = Dever::db('page/page')->find($where);
- return $data;
- }
- # 直接获取某个页面的内容
- public function getPage($path = 'module', $cdate = 'Y-m-d H:i', $config = array())
- {
- $page = Dever::input('key');
- if ($page) {
- $uri = $page;
- } else {
- $uri = Dever::uri();
- }
- if (!$uri) {
- $uri = 'home';
- }
-
- $data = $this->getPageData($uri, $cdate);
- $result = array();
- if ($data && $path && $data['module']) {
- foreach ($data['module'] as $k => $v) {
- $v['config'] = $config;
- $result[] = Dever::render($path . '/' . $v['key'], $v);
- }
- return implode("\r\n", $result);
- } else {
- return $data;
- }
- }
- # 获取某个页面的数据
- public function getPageData($page_id, $cdate = 'Y-m-d H:i')
- {
- $where = array();
- if (is_numeric($page_id)) {
- $where['id'] = $page_id;
- } else {
- $where['key'] = $page_id;
- }
- $data = Dever::db('page/page')->find($where);
- if ($data) {
- $data['pdate_string'] = date('Y.m.d', $data['pdate']);
- unset($data['state']);
- unset($data['reorder']);
- unset($data['cdate']);
- $data['module'] = Dever::db('page/page_module')->getData(array('page_id' => $data['id']));
- if ($data['module']) {
- foreach ($data['module'] as $k => $v) {
- $where = array();
- $where['module_id'] = $v['id'];
- $page = Dever::input($v['key'] . '_page');
- if ($page) {
- $where['page'] = array($v['num'], 'list');
- $data['module'][$k]['data'] = Dever::db('page/data')->getAllPage($where);
- } else {
- $where['limit'] = '0,' . $v['num'];
- $data['module'][$k]['data'] = Dever::db('page/data')->getAll($where);
- }
- if ($data['module'][$k]['data']) {
- $result = $data['module'][$k]['data'];
- $data['module'][$k]['data'] = array();
- foreach ($result as $k1 => $v1) {
- $v1 = $this->getOne($v1, $v, $cdate);
- if ($v1) {
- $data['module'][$k]['data'][] = $v1;
- }
- }
- }
- }
- }
- }
- return $data;
- }
- # 获取某个推送位的所有数据
- public function get($key, $name, $total = 10, $col = '1,2,3', $func = '-1', $page = false, $limit = false, $cdate = 'Y-m-d H:i')
- {
- if (!$page) {
- $page = Dever::input($key . '_page');
- }
- $module = Dever::db('page/module')->one(array('key' => $key));
- if (!$module) {
- $module['content'] = 1;
- $module['key'] = $key;
- $module['name'] = $name;
- $module['num'] = $total;
- $module['col'] = $col;
- $module['func'] = $func;
- $module['page_id'] = 1;
- $module['id'] = Dever::db('page/module')->insert($module);
- }
- $result = array();
- if ($module) {
- if (!$module['num']) {
- $module['num'] = 20;
- }
- if ($limit > 0) {
- $module['num'] = $limit;
- }
- if ($module['content'] == 1 && $total > 0) {
- Dever::setInput('search_option_module_id', $module['id']);
- $where = array();
- $where['module_id'] = $module['id'];
- if ($page) {
- $where['page'] = array($module['num'], 'list');
- $data = Dever::db('page/data')->getAllPage($where);
- } else {
- $where['limit'] = '0,' . $module['num'];
- $data = Dever::db('page/data')->getAll($where);
- }
- if ($data) {
- foreach ($data as $k => $v) {
- $v = $this->getOne($v, $module, $cdate);
- if ($v) {
- $result[] = $v;
- }
- }
- }
- } else {
- $result = $module;
- }
- }
- return $result;
- }
- # 获取某条推送位的数据
- public function getOne($data, $module = false, $cdate = 'Y-m-d H:i')
- {
- $data = is_array($data) ? $data : Dever::db('page/data')->one($data);
- $source = array();
- $module = $module ? $module : Dever::db('page/module')->one($data['module_id']);
- $module['col'] = explode(',', $module['col']);
- $col = array();
- if ($data['type'] > 0) {
- $func = Dever::db('page/func')->one($data['type']);
- if ($func) {
- if ($func['type'] == 1) {
- $method = $func['api'];
- $col = Dever::array_decode($func['col']);
- $source = Dever::load($method, $data['type_id']);
- if (!$source) {
- return false;
- }
- } else {
- $data['type_id'] = $func['api'];
- }
- }
- }
- $result = array();
- $lang = Dever::getLang();
- if ($lang) {
- $key = $lang . '_col_';
- } else {
- $key = 'col_';
- }
- foreach ($data as $k => $v) {
- $s = strstr($k, $key);
- if (!$s && $lang && strstr($k, 'col_')) {
- $s = true;
- $key = 'col_';
- } elseif ($k == 'id' || $k == 'type' || $k == 'type_id') {
- $result[$k] = $v;
- } elseif ($k == 'cdate') {
- $result['cdate_string'] = date($cdate, $v);
- }
- if ($s) {
- $id = str_replace($key, '', $k);
- if (!in_array($id, $module['col'])) {
- continue;
- }
- $col_module = Dever::db('page/col')->one($id);
- if (!$col_module) {
- continue;
- }
- if (!$v && $source && $col) {
- foreach ($col as $k1 => $v1) {
- if ($v1['col_id'] == $id && isset($source[$v1['name']]) && $source[$v1['name']]) {
- $v = $source[$v1['name']];
- }
- }
- }
- if (strstr($v, "\n")) {
- //$v = str_replace("\n", '<br />', $v);
- }
- if (strstr($v, "font-size")) {
- $v = str_replace("font-size", 'font-sizes', $v);
- }
- if (strstr($k, 'pics')) {
- $v = explode(',', $v);
- }
- if (strstr($col_module['key'], 'link') && !strstr($v, 'pages/')) {
- $v = Dever::url($v, 'main');
- }
- $result[$col_module['key']] = $v;
- }
- }
- return $result;
- }
- }
|