Exemple #1
0
 /**
  * 创建栏目的html文件
  */
 protected function _create_category_file($catid, $page = 0)
 {
     if (!MODULE_HTML || !$catid) {
         return NULL;
     }
     $mod = $this->get_cache('module-' . SITE_ID . '-' . $this->dir);
     $cat = $mod['category'][$catid];
     // 当此栏目是外链时,不生成!
     if ($cat['setting']['linkurl']) {
         return NULL;
     }
     $url = $page > 1 ? dr_category_url($mod, $cat, $page) : $cat['url'];
     if (!$url) {
         return NULL;
     }
     $file = str_replace($mod['url'], '', $url);
     $_GET['page'] = $page;
     if (strpos($file, 'index.php?c=category') !== FALSE) {
         return NULL;
     }
     ob_start();
     $this->_category($catid, NULL, $page);
     $dir = dirname($file);
     $file = basename($file);
     $html = ob_get_clean();
     if (SITE_ID > 1) {
         $dir = trim('html/' . SITE_ID . '/' . trim($dir, '.'), '/');
     }
     if ($dir != '.' && !file_exists(APPPATH . $dir)) {
         dr_mkdirs(APPPATH . $dir, TRUE);
     }
     // 判断是否为目录形式
     if (strpos($file, '.html') === FALSE && strpos($file, '.htm') === FALSE && strpos($file, '.shtml') === FALSE) {
         dr_mkdirs(APPPATH . $dir . '/' . $file, TRUE);
     }
     // 如果是目录就生成一个index.html
     if (is_dir(APPPATH . $dir . '/' . $file)) {
         $dir .= '/' . $file;
         $file = 'index.html';
     }
     if (!file_put_contents(APPPATH . $dir . '/' . $file, $html, LOCK_EX)) {
         return NULL;
     }
     // 保存文件记录
     $this->content_model->set_html(3, 0, 0, $catid, $catid, array(APPPATH . $dir . '/' . $file));
     // 生成栏目的第一页
     if ($page <= 1) {
         $purl = dr_category_url($mod, $cat, '{page}');
         $pfile = basename(str_replace(array($mod['url'], '{page}'), array('', 1), $purl));
         // 判断是否为目录形式
         if (strpos($pfile, '.html') === FALSE && strpos($pfile, '.htm') === FALSE && strpos($pfile, '.shtml') === FALSE) {
             dr_mkdirs(APPPATH . $dir . '/' . $pfile, TRUE);
         }
         // 如果是目录就生成一个index.html
         if (is_dir(APPPATH . $dir . '/' . $pfile)) {
             $dir .= '/' . $pfile;
             $pfile = 'index.html';
         }
         file_put_contents(APPPATH . $dir . '/' . $pfile, $html, LOCK_EX);
         $this->content_model->set_html(3, 0, 0, $catid, $catid, array(APPPATH . $dir . '/' . $pfile));
     }
     return TRUE;
 }
 public function cache($site)
 {
     // 数据表
     $this->link = $this->site[$site];
     $this->tablename = $this->link->dbprefix($site . '_navigator');
     // 修复数据
     $this->repair($site);
     // 查询当前站点的导航数据
     $data = $this->link->where('show', 1)->order_by('displayorder ASC,id ASC')->get($this->tablename)->result_array();
     // 当前站点有数据时更新缓存
     $this->ci->clear_cache('navigator-' . $site);
     $this->ci->dcache->delete('navigator-' . $site);
     // 数据格式化
     if ($data) {
         // 加载单页模型类
         $this->load->model('page_model');
         $this->page_model->link = $this->site[$site];
         $this->page_model->tablename = $this->link->dbprefix($site . '_page');
         // 初始化数据
         $page = $cache = array();
         foreach ($data as $t) {
             $t['cids'] = $t['childids'] ? explode(',', $t['childids']) : array();
             if ($t['mark']) {
                 $url = NULL;
                 if (strpos($t['mark'], 'page') === 0) {
                     // 单页链接处理
                     list($a, $id) = explode('-', $t['mark']);
                     if (!$page) {
                         $page = $this->page_model->get_data_all();
                     }
                     if (isset($page[$id]) && $page[$id]) {
                         $url = $this->page_model->get_url($page[$id]);
                     }
                 } elseif (strpos($t['mark'], 'module') === 0) {
                     // 模块链接处理
                     list($a, $dir, $catid) = explode('-', $t['mark']);
                     $m = $this->ci->get_cache('module-' . $site . '-' . $dir);
                     if ($catid) {
                         $c = $m['category'][$catid];
                         if ($c) {
                             $url = isset($c['setting']['linkurl']) && $c['setting']['linkurl'] ? $c['setting']['linkurl'] : dr_category_url($m, $c);
                         }
                     } else {
                         $url = $m['url'];
                     }
                 }
                 // 更新URL到数据表
                 if ($url) {
                     $this->link->where('id', $t['id'])->update($this->tablename, array('url' => $url));
                     $t['url'] = $url;
                 }
             }
             $cache[(int) $t['type']][] = $t;
         }
         // 保存缓存到文本
         $this->ci->dcache->set('navigator-' . $site, $cache);
     }
     return $cache;
 }
 /**
  * 模块缓存
  *
  * @param	string	$dirname	模块名称
  * @param	intval	$update		是否更新数量
  * @return	NULL
  */
 public function cache($dirname, $update = 1)
 {
     if (!is_dir(FCPATH . $dirname . '/')) {
         return NULL;
     }
     $data = $this->db->where('disabled', 0)->where('dirname', $dirname)->order_by('displayorder ASC,id ASC')->get('module')->row_array();
     if (!$data) {
         return NULL;
     }
     $config = (require FCPATH . $dirname . '/config/module.php');
     // 配置信息
     $site_domain = (require FCPATH . 'config/domain.php');
     // 加载站点域名配置文件
     $data['site'] = dr_string2array($data['site']);
     $data['setting'] = dr_string2array($data['setting']);
     // 模块表单数据
     $form = array();
     $temp = $this->db->where('disabled', 0)->order_by('id ASC')->get('module_form')->result_array();
     if ($temp) {
         foreach ($temp as $t) {
             $t['field'] = array();
             // 模块表单的自定义字段
             $field = $this->db->where('disabled', 0)->where('relatedid', $t['id'])->where('relatedname', 'mform-' . $data['dirname'])->order_by('displayorder ASC, id ASC')->get('field')->result_array();
             if ($field) {
                 foreach ($field as $f) {
                     $t['field'][$f['fieldname']] = $this->get_field_value($f);
                 }
             }
             $t['setting'] = dr_string2array($t['setting']);
             $t['permission'] = dr_string2array($t['permission']);
             $form[$t['module']][$t['table']] = $t;
         }
     }
     // 按站点生成缓存
     foreach ($this->SITE as $siteid => $t) {
         $cache = $data;
         $this->cache->delete('module-' . $siteid . '-' . $dirname);
         $this->ci->clear_cache('module-' . $siteid . '-' . $dirname);
         if (isset($data['site'][$siteid]['use']) && $data['site'][$siteid]['use']) {
             // 模块域名
             $domain = $data['site'][$siteid]['domain'];
             if ($domain) {
                 $site_domain[$domain] = $siteid;
             }
             // 将站点保存至域名配置文件
             $cache['url'] = $domain ? 'http://' . $domain . '/' : $this->SITE[$siteid]['SITE_URL'] . $dirname . '/';
             // 模块的URL地址
             $cache['html'] = $data['site'][$siteid]['html'];
             $cache['theme'] = $data['site'][$siteid]['theme'];
             $cache['domain'] = $data['site'][$siteid]['domain'];
             $cache['template'] = $data['site'][$siteid]['template'];
             // 非主站开启静态生成时,创建新的入口文件
             if ($cache['html'] && $siteid > 1) {
                 $path = FCPATH . $cache['dirname'] . '/html/' . $siteid;
                 if (!file_exists($path)) {
                     dr_mkdirs($path, TRUE);
                 }
                 copy(FCPATH . $cache['dirname'] . '/html.php', $path . '/index.php');
             }
             // 系统模块格式
             if (!isset($config['mydb']) || !$config['mydb']) {
                 // 模块的自定义字段
                 $field = $this->db->where('disabled', 0)->where('relatedid', $data['id'])->where('relatedname', 'module')->order_by('displayorder ASC, id ASC')->get('field')->result_array();
                 if ($field) {
                     foreach ($field as $f) {
                         $cache['field'][$f['fieldname']] = $this->get_field_value($f);
                     }
                 } else {
                     $cache['field'] = array();
                 }
                 // 模块扩展的自定义字段
                 if ($data['extend']) {
                     $field = $this->db->where('disabled', 0)->where('relatedid', $data['id'])->where('relatedname', 'extend')->order_by('displayorder ASC, id ASC')->get('field')->result_array();
                     $cache['extend'] = array();
                     if ($field) {
                         foreach ($field as $f) {
                             $cache['extend'][$f['fieldname']] = $this->get_field_value($f);
                         }
                     }
                 } else {
                     $cache['extend'] = 0;
                 }
                 // 模块表单归类
                 $cache['form'] = isset($form[$dirname]) ? $form[$dirname] : array();
                 // 模块表创建统计字段
                 if ($cache['form']) {
                     foreach ($cache['form'] as $fm) {
                         $this->system_model->create_form_total_field($siteid, $dirname, $fm['table'], 1);
                     }
                 }
                 // 模块的栏目分类
                 $category = $this->site[$siteid]->order_by('displayorder ASC, id ASC')->get($siteid . '_' . $dirname . '_category')->result_array();
                 if ($category) {
                     $CAT = $CAT_DIR = $level = array();
                     foreach ($category as $c) {
                         if ($update == 1) {
                             if (!$c['child']) {
                                 $c['total'] = $this->site[$siteid]->where('status', 9)->where('catid', $c['id'])->count_all_results($siteid . '_' . $dirname . '_index');
                             } else {
                                 $c['total'] = 0;
                             }
                         } else {
                             $c['total'] = $this->ci->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'category', $c['id'], 'total');
                         }
                         $pid = explode(',', $c['pids']);
                         $level[] = substr_count($c['pids'], ',');
                         $c['topid'] = isset($pid[1]) ? $pid[1] : $c['id'];
                         $c['catids'] = explode(',', $c['childids']);
                         $c['setting'] = dr_string2array($c['setting']);
                         $c['permission'] = $c['child'] ? '' : dr_string2array($c['permission']);
                         $c['url'] = isset($c['setting']['linkurl']) && $c['setting']['linkurl'] ? $c['setting']['linkurl'] : dr_category_url($cache, $c);
                         // 删除过期的部分
                         unset($c['setting']['urlmode']);
                         unset($c['setting']['url']);
                         $CAT[$c['id']] = $c;
                         $CAT_DIR[$c['dirname']] = $c['id'];
                     }
                     // 更新父栏目数量
                     if ($update == 1) {
                         foreach ($category as $c) {
                             if ($c['child']) {
                                 $arr = explode(',', $c['childids']);
                                 $CAT[$c['id']]['total'] = 0;
                                 foreach ($arr as $i) {
                                     $CAT[$c['id']]['total'] += $CAT[$i]['total'];
                                 }
                             }
                         }
                     }
                     // 栏目自定义字段,把父级栏目的字段合并至当前栏目
                     $field = $this->db->where('disabled', 0)->where('relatedname', $dirname . '-' . $siteid)->order_by('displayorder ASC, id ASC')->get('field')->result_array();
                     if ($field) {
                         foreach ($field as $f) {
                             if (isset($CAT[$f['relatedid']]['childids']) && $CAT[$f['relatedid']]['childids']) {
                                 // 将该字段同时归类至其子栏目
                                 $child = explode(',', $CAT[$f['relatedid']]['childids']);
                                 foreach ($child as $catid) {
                                     if ($CAT[$catid]) {
                                         $CAT[$catid]['field'][$f['fieldname']] = $this->get_field_value($f);
                                     }
                                 }
                             }
                         }
                     }
                     $cache['category'] = $CAT;
                     $cache['category_dir'] = $CAT_DIR;
                     $cache['category_field'] = $field ? 1 : 0;
                     $cache['category_level'] = $level ? max($level) : 0;
                 } else {
                     $cache['category'] = array();
                     $cache['category_dir'] = array();
                     $cache['category_field'] = $cache['category_level'] = 0;
                 }
                 $cache['is_system'] = 1;
             } else {
                 $cache['is_system'] = 0;
             }
             // 模块名称
             $name = $this->db->select('name')->where('pid', 0)->where('mark', 'module-' . $dirname)->limit(1)->get('admin_menu')->row_array();
             $cache['name'] = $name['name'] ? $name['name'] : $config['name'];
             $this->dcache->set('module-' . $siteid . '-' . $dirname, $cache);
         }
     }
     $this->load->library('dconfig');
     $this->dconfig->file(FCPATH . 'config/domain.php')->note('站点域名文件')->space(32)->to_require_one($site_domain);
 }
Exemple #4
0
 public function list_tag($_params)
 {
     if (!$this->ci) {
         return NULL;
     }
     $system = array('num' => '', 'form' => '', 'page' => '', 'site' => '', 'flag' => '', 'more' => '', 'catid' => '', 'field' => '', 'order' => '', 'space' => '', 'cache' => (int) SITE_QUERY_CACHE, 'action' => '', 'return' => '', 'module' => APP_DIR, 'modelid' => '', 'keyword' => '', 'urlrule' => '', 'pagesize' => '');
     $param = $where = array();
     $params = explode(' ', $_params);
     $sysadj = array('IN', 'BEWTEEN', 'BETWEEN', 'LIKE', 'NOTIN', 'NOT', 'BW');
     foreach ($params as $t) {
         $var = substr($t, 0, strpos($t, '='));
         $val = substr($t, strpos($t, '=') + 1);
         if (!$var) {
             continue;
         }
         if (isset($system[$var])) {
             // 系统参数,只能出现一次,不能添加修饰符
             $system[$var] = $val;
         } else {
             if (preg_match('/^([A-Z_]+)(.+)/', $var, $match)) {
                 // 筛选修饰符参数
                 $_pre = explode('_', $match[1]);
                 $_adj = '';
                 foreach ($_pre as $p) {
                     if (in_array($p, $sysadj)) {
                         $_adj = $p;
                     }
                 }
                 $where[] = array('adj' => $_adj, 'name' => $match[2], 'value' => $val);
             } else {
                 $where[] = array('adj' => '', 'name' => $var, 'value' => $val);
             }
             $param[$var] = $val;
             // 用于特殊action
         }
     }
     // 替换order中的非法字符
     if (isset($system['order']) && $system['order']) {
         $system['order'] = str_ireplace(array('"', "'", ')', '(', ';', 'select', 'insert'), '', $system['order']);
     }
     // action
     switch ($system['action']) {
         case 'cache':
             // 系统缓存数据
             if (!isset($param['name'])) {
                 return $this->_return($system['return'], 'name参数不存在');
             }
             $pos = strpos($param['name'], '.');
             if ($pos !== FALSE) {
                 $_name = substr($param['name'], 0, $pos);
                 $_param = substr($param['name'], $pos + 1);
             } else {
                 $_name = $param['name'];
                 $_param = NULL;
             }
             $cache = $this->_cache_var($_name, !$system['site'] ? SITE_ID : $system['site']);
             if (!$cache) {
                 return $this->_return($system['return'], "缓存({$_name})不存在,请在后台更新缓存");
             }
             if ($_param) {
                 @eval('$data=$cache' . $this->_get_var($_param) . ';');
                 if (!$data) {
                     return $this->_return($system['return'], "缓存({$_name})参数不存在!!");
                 }
             } else {
                 $data = $cache;
             }
             return $this->_return($system['return'], $data, '');
             break;
         case 'content':
             // 模块文档内容
             if (!isset($param['id'])) {
                 return $this->_return($system['return'], 'id参数不存在');
             }
             $dirname = $system['module'] ? $system['module'] : APP_DIR;
             if (!$dirname) {
                 return $this->_return($system['return'], 'module参数不能为空');
             }
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($dirname, $system['site']);
             if (!$module) {
                 return $this->_return($system['return'], "模块({$system['module']})未安装");
             }
             // 定义的模块内容模型类
             $file = FCPATH . $module['dirname'] . '/models/Content_model.php';
             if (!is_file($file)) {
                 return $this->_return($system['return'], "模块({$system['module']})文件models/Content_model.php不存在");
             }
             require_once $file;
             $db = new Content_model();
             $db->link = $this->ci->site[$system['site']];
             $db->prefix = $this->ci->db->dbprefix($system['site'] . '_' . $module['dirname']);
             // 缓存查询结果
             $data = $db->get($param['id']);
             $page = max(1, (int) $_GET['page']);
             $name = 'list-action-content-' . md5(dr_array2string($param)) . '-' . $page;
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 $fields = $module['field'];
                 $fields = $module['category'][$data['catid']]['field'] ? array_merge($fields, $module['category'][$data['catid']]['field']) : $fields;
                 // 模块表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 $fields['updatetime'] = array('fieldtype' => 'Date');
                 // 格式化数据
                 $data = $this->ci->field_format_value($fields, $data, $page, $module['dirname']);
                 if ($system['field'] && $data) {
                     $_field = explode(',', $system['field']);
                     foreach ($data as $i => $t) {
                         if (strpos($i, '_') !== 0 && !in_array($i, $_field)) {
                             unset($data[$i]);
                         }
                     }
                 }
                 // 格式化显示自定义字段内容
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], array($cache), '');
             break;
         case 'category':
             // 栏目
             $dirname = $system['module'] ? $system['module'] : APP_DIR;
             if (!$dirname) {
                 return $this->_return($system['return'], 'module参数不能为空');
             }
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($dirname, $system['site']);
             if (!$module || count($module['category']) == 0) {
                 return $this->_return($system['return'], "模块({$system['module']})尚未安装");
             }
             $i = 0;
             $show = isset($param['show']) ? 1 : 0;
             // 有show参数表示显示隐藏栏目
             $return = array();
             foreach ($module['category'] as $t) {
                 if ($system['num'] && $i >= $system['num']) {
                     break;
                 }
                 if (!$t['show'] && !$show) {
                     continue;
                 }
                 if (isset($param['pid']) && $t['pid'] != (int) $param['pid']) {
                     continue;
                 }
                 if (isset($param['letter']) && $t['letter'] != $param['letter']) {
                     continue;
                 }
                 if (isset($param['id']) && !in_array($t['id'], explode(',', $param['id']))) {
                     continue;
                 }
                 if (isset($system['more']) && !$system['more']) {
                     unset($t['field'], $t['setting']);
                 }
                 $return[] = $t;
                 $i++;
             }
             if (!$return) {
                 return $this->_return($system['return'], '没有匹配到内容');
             }
             return $this->_return($system['return'], $return, '');
             break;
         case 'linkage':
             // 联动菜单
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $linkage = $this->ci->get_cache('linkage-' . $system['site'] . '-' . $param['code']);
             if (!$linkage) {
                 return $this->_return($system['return'], "联动菜单{$param['code']}不存在,请在后台更新缓存");
             }
             $i = 0;
             $return = array();
             foreach ($linkage as $t) {
                 if ($system['num'] && $i >= $system['num']) {
                     break;
                 }
                 if (isset($param['pid']) && $t['pid'] != (int) $param['pid']) {
                     continue;
                 }
                 if (isset($param['id']) && !in_array($t['id'], explode(',', $param['id']))) {
                     continue;
                 }
                 $return[] = $t;
                 $i++;
             }
             if (!$return) {
                 foreach ($linkage as $t) {
                     if ($t['pid'] == (int) $linkage[$param['pid']]['pid']) {
                         if ($system['num'] && $i >= $system['num']) {
                             break;
                         }
                         if (isset($param['id']) && !in_array($t['id'], explode(',', $param['id']))) {
                             continue;
                         }
                         $return[] = $t;
                         $i++;
                     }
                 }
                 if (!$return) {
                     return $this->_return($system['return'], '没有匹配到内容');
                 }
             }
             return $this->_return($system['return'], isset($param['call']) && $param['call'] ? @array_reverse($return) : $return, '');
             break;
         case 'search_field':
             // 搜索字段筛选
             $catid = $system['catid'];
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($system['module'] ? $system['module'] : APP_DIR, $system['site']);
             if (!$module || count($module['category'][$catid]['field']) == 0) {
                 return $this->_return($system['return'], '模块未安装或者此栏目无附加字段');
             }
             $return = array();
             foreach ($module['category'][$catid]['field'] as $t) {
                 if ($t['issearch'] && $t['ismain'] && ($t['fieldtype'] == 'Select' || $t['fieldtype'] == 'Radio')) {
                     $data = @explode(PHP_EOL, $t['setting']['option']['options']);
                     if ($data) {
                         $list = array();
                         foreach ($data as $c) {
                             list($name, $value) = @explode('|', $c);
                             if ($name && !is_null($value)) {
                                 $list[] = array('name' => trim($name), 'value' => trim($value));
                             }
                         }
                         if ($list) {
                             $return[] = array('name' => $t['name'], 'field' => $t['fieldname'], 'data' => $list);
                         }
                     }
                 }
             }
             return $this->_return($system['return'], $return, '');
             break;
         case 'navigator':
             // 网站导航
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $navigator = $this->ci->get_cache('navigator-' . $system['site']);
             // 导航缓存
             if (!$navigator) {
                 return $this->_return($system['return'], '导航数据为空');
             }
             $i = 0;
             $show = isset($param['show']) ? 1 : 0;
             // 有show参数表示显示隐藏栏目
             $data = $navigator[(int) $param['type']];
             if (!$data) {
                 // 没有查询到内容
                 return $this->_return($system['return'], '没有查询到内容');
             }
             $return = array();
             foreach ($data as $t) {
                 if ($system['num'] && $i >= $system['num']) {
                     break;
                 }
                 if (isset($param['pid']) && $t['pid'] != (int) $param['pid']) {
                     continue;
                 }
                 if (isset($param['id']) && $t['id'] != (int) $param['id']) {
                     continue;
                 }
                 if (!$t['show'] && !$show) {
                     continue;
                 }
                 $return[] = $t;
                 $i++;
             }
             if (!$return) {
                 return $this->_return($system['return'], '没有匹配到内容');
             }
             return $this->_return($system['return'], $return, '');
             break;
         case 'page':
             // 单页调用
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $name = $system['module'] ? $system['module'] : 'index';
             $data = $this->ci->get_cache('page-' . $system['site'], 'data', $name);
             // 单页缓存
             if (!$data) {
                 return $this->_return($system['return'], '没有查询到内容');
             }
             $i = 0;
             $show = isset($param['show']) ? 1 : 0;
             // 有show参数表示显示隐藏栏目
             $field = $this->ci->dcache->get('page-field-' . $system['site']);
             $return = array();
             foreach ($data as $id => $t) {
                 if (!is_numeric($id)) {
                     continue;
                 }
                 if ($system['num'] && $i >= $system['num']) {
                     break;
                 }
                 if (!$t['show'] && !$show) {
                     continue;
                 }
                 if (isset($param['pid']) && $t['pid'] != (int) $param['pid']) {
                     continue;
                 }
                 if (isset($param['id']) && !in_array($t['id'], explode(',', $param['id']))) {
                     continue;
                 }
                 $t['setting'] = dr_string2array($t['setting']);
                 $return[] = $this->ci->field_format_value($field, $t, 1);
                 $i++;
             }
             if (!$return) {
                 return $this->_return($system['return'], '没有匹配到内容');
             }
             return $this->_return($system['return'], $return, $sql);
             break;
         case 'related':
             // 相关文章
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($system['module'] ? $system['module'] : APP_DIR, $system['site']);
             if (!$module) {
                 return $this->_return($system['return'], "模块({$system['module']})未安装");
                 // 没有模块数据时返回空
             }
             if (!$param['tag']) {
                 return $this->_return($system['return'], '没有查询到内容');
                 // 没有查询到内容
             } else {
                 $where = array();
                 $array = explode(',', $param['tag']);
                 foreach ($array as $name) {
                     if ($name) {
                         $where[] = '(`title` LIKE "%' . $this->ci->db->escape_str($name) . '%" OR `keywords` LIKE "%' . $this->ci->db->escape_str($name) . '%")';
                     }
                 }
                 $where = implode(' OR ', $where);
             }
             $table = $this->ci->db->dbprefix($system['site'] . '_' . $module['dirname']);
             // 模块主表
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$table} WHERE {$where} ORDER BY updatetime DESC LIMIT " . ($system['num'] ? $system['num'] : 10);
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 缓存查询结果
             $name = 'list-action-sql-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 $fields = $module['field'];
                 // 模块表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 $fields['updatetime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t, 1, $module['dirname']);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql);
             break;
         case 'tag':
             // 调用tag
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($system['module'] ? $system['module'] : APP_DIR, $system['site']);
             if (!$module) {
                 // 没有模块数据时返回空
                 return $this->_return($system['return'], "模块({$system['module']})未安装");
             }
             $table = $this->ci->db->dbprefix($system['site'] . '_' . $module['dirname'] . '_tag');
             // tag表
             $sql = "SELECT id,name,code,hits FROM {$table} ORDER BY hits DESC LIMIT " . ($system['num'] ? $system['num'] : 10);
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 没有查询到内容
             if (!$data) {
                 return $this->_return($system['return'], '没有查询到内容');
             }
             // 缓存查询结果
             $name = 'list-action-tag-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 foreach ($data as $i => $t) {
                     $data[$i]['url'] = dr_tag_url($module, $t['name'], 1, $module['dirname']);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql);
             break;
         case 'sql':
             // 直接sql查询
             if (preg_match('/sql=\'(.+)\'/sU', $_params, $sql)) {
                 $db = !$system['site'] ? $system['module'] ? $this->ci->site[SITE_ID] : $this->ci->db : $this->ci->site[$system['site']];
                 // 数据库对象
                 $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
                 // 默认站点参数
                 $sql = str_replace('@#', $db->dbprefix, trim($sql[1]));
                 if (stripos($sql, 'SELECT') !== 0) {
                     return $this->_return($system['return'], 'SQL语句只能是SELECT查询语句');
                 }
                 $total = 0;
                 $pages = '';
                 // 如存在分页条件才进行分页查询
                 if ($system['page'] && $system['urlrule']) {
                     $page = max(1, (int) $_GET['page']);
                     $row = $this->_query(preg_replace('/select(.*)from/iUs', 'SELECT count(*) as c FROM', $sql), $system['site'], $system['cache'], FALSE);
                     $total = (int) $row['c'];
                     $pagesize = $system['pagesize'] ? $system['pagesize'] : 10;
                     // 没有数据时返回空
                     if (!$total) {
                         return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                     }
                     $sql .= ' LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                     $pages = $this->_get_pagination(str_replace('[page]', '{page}', urldecode($system['urlrule'])), $pagesize, $total);
                 }
                 $data = $this->_query($sql, $system['site'], $system['cache']);
                 $fields = NULL;
                 if ($system['module'] && ($module = get_module($system['module'], $system['site']))) {
                     $fields = $module['field'];
                     // 模块主表的字段
                 } elseif ($system['modelid'] && ($model = $this->ci->get_cache('space-model', $system['modelid']))) {
                     $fields = $model['field'];
                     // 空间模型的字段
                 }
                 if ($fields) {
                     // 缓存查询结果
                     $name = 'list-action-sql-' . md5($sql);
                     $cache = $this->ci->get_cache_data($name);
                     if (!$cache) {
                         // 模块表的系统字段
                         $fields['inputtime'] = array('fieldtype' => 'Date');
                         $fields['updatetime'] = array('fieldtype' => 'Date');
                         // 格式化显示自定义字段内容
                         foreach ($data as $i => $t) {
                             $data[$i] = $this->ci->field_format_value($fields, $t, 1, isset($module['dirname']) && $module['dirname'] ? $module['dirname'] : '');
                         }
                         $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
                     }
                     $data = $cache;
                 }
                 return $this->_return($system['return'], $data, $sql, $total, $pages);
             } else {
                 return $this->_return($system['return'], '参数不正确,SQL语句必须用单引号包起来');
                 // 没有查询到内容
             }
             break;
         case 'model':
             // 空间模型
             $uid = (int) $system['space'];
             $mid = (int) $system['modelid'];
             if (!$mid) {
                 return $this->_return($system['return'], 'modelid参数必须存在,请在后台更新缓存');
                 // 参数判断
             }
             $model = $this->ci->get_cache('space-model', $mid);
             if (!$model) {
                 return $this->_return($system['return'], "空间模型({$system['modelid']})未安装");
                 // 没有模型数据时返回空
             }
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
                 // 没有表结构缓存时返回空
             }
             $system['order'] = !$system['order'] ? 'updatetime' : $system['order'];
             // 默认排序参数
             if ($uid) {
                 $where[] = array('adj' => '', 'name' => 'space_id', 'value' => $uid);
                 if (isset($system['catid']) && $system['catid']) {
                     $this->ci->load->model('space_category_model');
                     $category = $this->ci->space_category_model->get_data(0, $uid, 1);
                     // 栏目id集合不存在时则重新修复栏目数据
                     if (!$category[$system['catid']]['childids']) {
                         $this->ci->space_category_model->repair($uid);
                     }
                     $where[] = array('adj' => $category[$system['catid']]['child'] ? 'IN' : '', 'name' => 'catid', 'value' => $category[$system['catid']]['child'] ? $category[$system['catid']]['childids'] : $system['catid']);
                 }
             }
             $table = $this->ci->db->dbprefix('space_' . $model['table']);
             // 模块主表
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $total = 0;
             $fields = $model['field'];
             // 主表的字段
             $sql_from = $table;
             // sql的from子句
             $sql_limit = $pages = '';
             $sql_where = $this->_get_where($where);
             // sql的where子句
             // 当前作者不缓存
             if ($this->ci->uid == $uid) {
                 $system['cache'] = 0;
             }
             if ($system['page'] && $system['urlrule']) {
                 $page = max(1, (int) $_GET['page']);
                 $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                 $pagesize = (int) $system['pagesize'];
                 $pagesize = $pagesize ? $pagesize : 10;
                 $sql = "SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL";
                 $row = $this->_query($sql, 0, $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 // 没有数据时返回空
                 if (!$total) {
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = 'LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination($urlrule, $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " " . ($system['order'] ? "ORDER BY {$system['order']}" : "") . " {$sql_limit}";
             $data = $this->_query($sql, 0, $system['cache']);
             // 缓存查询结果
             $name = 'list-action-space-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 模块表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 $fields['updatetime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         case 'space_content':
             // 空间模型文档内容
             $id = (int) $param['id'];
             $mid = (int) $system['modelid'];
             if (!$id) {
                 return $this->_return($system['return'], 'id参数不存在');
             }
             if (!$mid) {
                 return $this->_return($system['return'], 'modelid参数必须存在,请在后台更新缓存');
                 // 参数判断
             }
             // 模型缓存
             $model = $this->ci->get_cache('space-model', $mid);
             if (!$model) {
                 return $this->_return($system['return'], "空间模型({$system['modelid']})未安装");
                 // 没有模型数据时返回空
             }
             // 模型表名称和缓存
             $name = $this->ci->db->dbprefix('space_' . $model['table']) . '-space-show-' . $id;
             $data = $this->ci->get_cache_data($name);
             $time = $system['cache'] ? $system['cache'] : 36000;
             if ($time && !$data) {
                 $data = $this->ci->db->where('id', $id)->get('space_' . $model['table'])->row_array();
                 $this->ci->set_cache_data($name, $data, $time);
             }
             // 格式化输出自定义字段
             $fields = $model['field'];
             $fields['inputtime'] = array('fieldtype' => 'Date');
             $fields['updatetime'] = array('fieldtype' => 'Date');
             $data = $this->ci->field_format_value($fields, $data, max(1, (int) $_GET['page']));
             // 输出返回字段
             $field = $system['field'] ? explode(',', $system['field']) : NULL;
             if ($field) {
                 $temp = $data;
                 $data = array();
                 foreach ($field as $i) {
                     $data[$i] = isset($temp[$i]) ? $temp[$i] : '';
                 }
             }
             return $this->_return($system['return'], array($data), '');
             break;
         case 'extend':
             // 子内容调用
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $dirname = $system['module'] ? $system['module'] : APP_DIR;
             if (!$dirname) {
                 return $this->_return($system['return'], 'module参数不能为空');
             }
             $module = get_module($dirname, $system['site']);
             if (!$module) {
                 return $this->_return($system['return'], "模块({$dirname})未安装");
                 // 没有模块数据时返回空
             }
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
                 // 没有表结构缓存时返回空
             }
             $system['order'] = !$system['order'] ? 'displayorder desc,inputtime asc' : $system['order'];
             // 默认排序参数
             $table = $this->ci->db->dbprefix($system['site'] . '_' . $module['dirname'] . '_extend');
             // 表名称
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $total = 0;
             $fields = $module['extend'];
             // 主表的字段
             $sql_from = $table;
             // sql的from子句
             $sql_limit = $pages = '';
             $sql_where = $this->_get_where($where);
             // sql的where子句
             if (defined('MODULE_HTML') && MODULE_HTML) {
                 $system['cache'] = 0;
             }
             if ($system['page'] && $system['urlrule']) {
                 $page = max(1, (int) $_GET['page']);
                 $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                 $pagesize = (int) $system['pagesize'];
                 $pagesize = $pagesize ? $pagesize : 10;
                 $sql = "SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL";
                 $row = $this->_query($sql, 0, $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 // 没有数据时返回空
                 if (!$total) {
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = 'LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination($urlrule, $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " " . ($system['order'] ? "ORDER BY {$system['order']}" : "") . " {$sql_limit}";
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 缓存查询结果
             $name = 'list-action-extend-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t, 1, $module['dirname']);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         case 'form':
             // 表单调用
             $mid = $system['form'];
             $site = $system['site'] ? $system['site'] : SITE_ID;
             // 表单参数为数字时按id读取
             if (is_numeric($mid)) {
                 $form = $this->ci->get_cache('form-' . $site, $mid);
             } else {
                 $form = $this->ci->get_cache('form-name-' . $site, $mid);
             }
             // 判断是否存在
             if (!$form) {
                 return $this->_return($system['return'], "表单({$mid})不存在");
                 // 参数判断
             }
             // 表结构缓存
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
             }
             if (!$tableinfo) {
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
                 // 没有表结构缓存时返回空
             }
             // 将catid作为普通字段
             if (isset($system['catid']) && $system['catid']) {
                 $where[] = array('adj' => '', 'name' => 'catid', 'value' => $system['catid']);
             }
             $system['order'] = !$system['order'] ? 'inputtime' : $system['order'];
             // 默认排序参数
             $table = $this->ci->db->dbprefix($site . '_form_' . $form['table']);
             // 表单表名称
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $total = 0;
             $fields = $form['field'];
             // 主表的字段
             $sql_from = $table;
             // sql的from子句
             $sql_limit = $pages = '';
             $sql_where = $this->_get_where($where);
             // sql的where子句
             if ($system['page'] && $system['urlrule']) {
                 $page = max(1, (int) $_GET['page']);
                 $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                 $pagesize = (int) $system['pagesize'];
                 $pagesize = $pagesize ? $pagesize : 10;
                 $sql = "SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL";
                 $row = $this->_query($sql, $site, $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 // 没有数据时返回空
                 if (!$total) {
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = 'LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination($urlrule, $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " " . ($system['order'] ? "ORDER BY {$system['order']}" : "") . " {$sql_limit}";
             $data = $this->_query($sql, 0, $system['cache']);
             // 缓存查询结果
             $name = 'list-action-form-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         case 'mform':
             // 模块表单调用
             $site = $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $dirname = $system['module'] ? $system['module'] : APP_DIR;
             if (!$dirname) {
                 return $this->_return($system['return'], 'module参数不能为空');
             }
             $module = get_module($dirname, $system['site']);
             if (!$module) {
                 return $this->_return($system['return'], "模块({$dirname})未安装");
                 // 没有模块数据时返回空
             }
             $fid = $system['form'];
             $form = $module['form'][$fid];
             if (!$form) {
                 return $this->_return($system['return'], "模块表单({$fid})不存在");
                 // 参数判断
             }
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
                 // 没有表结构缓存时返回空
             }
             $system['order'] = !$system['order'] ? 'inputtime' : $system['order'];
             // 默认排序参数
             $table = $this->ci->db->dbprefix($site . '_' . $module['dirname'] . '_form_' . $fid);
             // 表单表名称
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $total = NULL;
             $fields = $form['field'];
             // 主表的字段
             $sql_from = $table;
             // sql的from子句
             $sql_where = $this->_get_where($where);
             // sql的where子句
             $sql_limit = $pages = '';
             if ($system['page'] && $system['urlrule']) {
                 $page = max(1, (int) $_GET['page']);
                 $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                 $pagesize = (int) $system['pagesize'];
                 $pagesize = $pagesize ? $pagesize : 10;
                 $sql = "SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL";
                 $row = $this->_query($sql, $site, $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 // 没有数据时返回空
                 if (!$total) {
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = 'LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination($urlrule, $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " " . ($system['order'] ? "ORDER BY {$system['order']}" : "") . " {$sql_limit}";
             $data = $this->_query($sql, $site, $system['cache']);
             // 缓存查询结果
             $name = 'list-action-mform-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t, 1, $module['dirname']);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         case 'member':
             // 会员信息
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 // 没有表结构缓存时返回空
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
             }
             $table = $this->ci->db->dbprefix('member');
             // 主表
             $system['order'] = !$system['order'] ? 'uid' : $system['order'];
             // 默认排序参数
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $sql_from = $table;
             // sql的from子句
             if ($system['more']) {
                 // 会员附表
                 $more = $this->ci->db->dbprefix('member_data');
                 // 附表
                 $where = $this->_set_where_field_prefix($where, $tableinfo[$more]['field'], $more);
                 // 给条件字段加上表前缀
                 $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$more]['field'], $more);
                 // 给显示字段加上表前缀
                 $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$more]['field'], $more);
                 // 给排序字段加上表前缀
                 $sql_from .= " LEFT JOIN {$more} ON `{$table}`.`uid`=`{$more}`.`uid`";
                 // sql的from子句
             }
             $total = 0;
             $sql_limit = '';
             $sql_where = $this->_get_where($where);
             // sql的where子句
             if ($system['page'] && $system['urlrule']) {
                 // 如存在分页条件才进行分页查询
                 $page = max(1, (int) $_GET['page']);
                 $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                 $pagesize = (int) $system['pagesize'];
                 $pagesize = $pagesize ? $pagesize : 10;
                 $row = $this->_query("SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL", $system['site'], $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 if (!$total) {
                     // 没有数据时返回空
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = ' LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination(str_replace('[page]', '{page}', $urlrule), $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " " . ($system['order'] == "null" ? "" : " ORDER BY {$system['order']}") . " {$sql_limit}";
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 缓存查询结果
             $name = 'list-action-member-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 系统字段
                 $fields['regtime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         case 'space':
             // 空间数据
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
                 // 没有表结构缓存时返回空
             }
             $table = $this->ci->db->dbprefix('space');
             // 空间主表
             $system['order'] = !$system['order'] ? 'displayorder' : $system['order'];
             // 默认排序参数
             if ($system['keyword']) {
                 $where[] = array('adj' => 'LIKE', 'name' => 'name', 'value' => '%' . $system['keyword'] . '%');
             }
             $where[] = array('adj' => '', 'name' => 'status', 'value' => 1);
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $sql_from = $table;
             // sql的from子句
             if ($system['more']) {
                 // 会员附表
                 $more = $this->ci->db->dbprefix('member_data');
                 // 附表
                 $where = $this->_set_where_field_prefix($where, $tableinfo[$more]['field'], $more);
                 // 给条件字段加上表前缀
                 $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$more]['field'], $more);
                 // 给显示字段加上表前缀
                 $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$more]['field'], $more);
                 // 给排序字段加上表前缀
                 $sql_from .= " LEFT JOIN {$more} ON `{$table}`.`uid`=`{$more}`.`uid`";
                 // sql的from子句
             }
             if ($system['more'] == 2) {
                 // 会员主表
                 $more2 = $this->ci->db->dbprefix('member');
                 // 附表
                 $where = $this->_set_where_field_prefix($where, $tableinfo[$more2]['field'], $more2);
                 // 给条件字段加上表前缀
                 if ($system['field']) {
                     $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$more2]['field'], $more2);
                     // 给显示字段加上表前缀
                 } else {
                     $system['field'] = "`{$table}`.*" . ($more ? ",`{$more}`.*" : "") . ",`{$more2}`.`username`,`{$more2}`.`groupid`,`{$more2}`.`uid`";
                 }
                 $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$more2]['field'], $more2);
                 // 给排序字段加上表前缀
                 $sql_from .= " LEFT JOIN {$more2} ON `{$table}`.`uid`=`{$more2}`.`uid`";
                 // sql的from子句
             }
             $total = 0;
             $sql_limit = '';
             $sql_where = $this->_get_where($where);
             // sql的where子句
             if ($system['flag']) {
                 // 推荐位调用
                 $_ids = $this->_query("select uid from {$table}_flag where `flag`=" . (int) $system['flag'], $system['site'], $system['cache']);
                 $in = array();
                 foreach ($_ids as $t) {
                     $in[] = $t['uid'];
                 }
                 if (!$in) {
                     // 没有查询到内容
                     return $this->_return($system['return'], '没有查询到推荐位内容');
                 }
                 $sql_where = ($sql_where ? $sql_where . ' AND' : '') . " `{$table}`.`uid` IN (" . implode(',', $in) . ")";
             }
             if ($system['page'] && $system['urlrule']) {
                 // 如存在分页条件才进行分页查询
                 $page = max(1, (int) $_GET['page']);
                 $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                 $pagesize = (int) $system['pagesize'];
                 $pagesize = $pagesize ? $pagesize : 10;
                 $sql = "SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL";
                 $row = $this->_query($sql, $system['site'], $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 if (!$total) {
                     // 没有数据时返回空
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = ' LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination(str_replace('[page]', '{page}', $urlrule), $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : "*") . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " " . ($system['order'] == "null" ? "" : " ORDER BY {$system['order']}") . " {$sql_limit}";
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 缓存查询结果
             $name = 'list-action-space-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 系统字段
                 $fields['regtime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         case 'module':
             // 模块数据
             $dirname = $system['module'] ? $system['module'] : APP_DIR;
             if (!$dirname) {
                 return $this->_return($system['return'], 'module参数不能为空');
             }
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($dirname, $system['site']);
             if (!$module) {
                 // 没有模块数据时返回空
                 return $this->_return($system['return'], "模块({$dirname})未安装");
             }
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 // 没有表结构缓存时返回空
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
             }
             $table = $this->ci->db->dbprefix($system['site'] . '_' . $module['dirname']);
             // 模块主表
             if (!isset($tableinfo[$table]['field'])) {
                 return $this->_return($system['return'], '表(' . $table . ')结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
             }
             // 排序操作
             if (!$system['order'] && $where[0]['adj'] == 'IN' && $where[0]['name'] == 'id') {
                 // 按id序列来排序
                 $system['order'] = strlen($where[0]['value']) < 10000 ? 'instr("' . $where[0]['value'] . '", `' . $table . '`.`id`)' : 'NULL';
             } else {
                 if (!$system['order']) {
                     if ($system['flag']) {
                         $system['order'] = 'displayorder_desc,updatetime_desc';
                         // 默认排序参数
                     } else {
                         $system['order'] = 'updatetime';
                         // 默认排序参数
                     }
                 }
             }
             // 栏目筛选
             if ($system['catid']) {
                 if (strpos($system['catid'], ',') !== FALSE) {
                     $where[] = array('adj' => 'IN', 'name' => 'catid', 'value' => $system['catid']);
                 } elseif ($module['category'][$system['catid']]['child']) {
                     $where[] = array('adj' => 'IN', 'name' => 'catid', 'value' => $module['category'][$system['catid']]['childids']);
                 } else {
                     $where[] = array('adj' => '', 'name' => 'catid', 'value' => (int) $system['catid']);
                 }
             }
             $fields = $module['field'];
             // 主表的字段
             $where = $this->_set_where_field_prefix($where, $tableinfo[$table]['field'], $table);
             // 给条件字段加上表前缀
             $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table]['field'], $table);
             // 给显示字段加上表前缀
             $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             $sql_from = $table;
             // sql的from子句
             // 关联栏目附加表
             if ($system['more']) {
                 $_catid = (int) $system['catid'];
                 if (isset($module['category'][$_catid]['field']) && $module['category'][$_catid]['field']) {
                     $fields = array_merge($fields, $module['category'][$_catid]['field']);
                     $table_more = $table . '_category_data';
                     // 栏目附加表
                     $where = $this->_set_where_field_prefix($where, $tableinfo[$table_more]['field'], $table_more);
                     // 给条件字段加上表前缀
                     $system['field'] = $this->_set_select_field_prefix($system['field'], $tableinfo[$table_more]['field'], $table_more);
                     // 给显示字段加上表前缀
                     $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table_more]['field'], $table_more);
                     // 给排序字段加上表前缀
                     $sql_from .= " LEFT JOIN {$table_more} ON `{$table_more}`.`id`=`{$table}`.`id`";
                     // sql的from子句
                 }
             }
             $total = 0;
             $sql_limit = $pages = '';
             $sql_where = $this->_get_where($where);
             // sql的where子句
             // 推荐位调用
             if ($system['flag']) {
                 $_w = strpos($sytem['flag'], ',') ? '`flag` IN (' . $sytem['flag'] . ')' : '`flag`=' . (int) $system['flag'];
                 $_i = $this->_query("select id from {$table}_flag where " . $_w, $system['site'], $system['cache']);
                 $in = array();
                 foreach ($_i as $t) {
                     $in[] = $t['id'];
                 }
                 // 没有查询到内容
                 if (!$in) {
                     return $this->_return($system['return'], '没有查询到内容');
                 }
                 $sql_where = ($sql_where ? $sql_where . ' AND' : '') . "`{$table}`.`id` IN (" . implode(',', $in) . ")";
                 unset($_w, $_i, $in);
             }
             if ($system['page']) {
                 $page = max(1, (int) $_GET['page']);
                 if (is_numeric($system['catid'])) {
                     $urlrule = dr_category_url($module, $module['category'][$system['catid']], '{page}');
                     $pagesize = $system['pagesize'] ? (int) $system['pagesize'] : (int) $module['category'][$system['catid']]['setting']['template']['pagesize'];
                 } else {
                     $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
                     $pagesize = (int) $system['pagesize'];
                 }
                 $pagesize = $pagesize ? $pagesize : 10;
                 $sql = "SELECT count(*) as c FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . " ORDER BY NULL";
                 $row = $this->_query($sql, $system['site'], $system['cache'], FALSE);
                 $total = (int) $row['c'];
                 // 没有数据时返回空
                 if (!$total) {
                     return $this->_return($system['return'], '没有查询到内容', $sql, 0);
                 }
                 $sql_limit = 'LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
                 $pages = $this->_get_pagination($urlrule, $pagesize, $total);
             } elseif ($system['num']) {
                 $sql_limit = "LIMIT {$system['num']}";
             }
             $sql = "SELECT " . ($system['field'] ? $system['field'] : '*') . " FROM {$sql_from} " . ($sql_where ? "WHERE {$sql_where}" : "") . ($system['order'] == "null" ? "" : " ORDER BY {$system['order']}") . " {$sql_limit}";
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 缓存查询结果
             $name = 'list-action-module-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache && is_array($data)) {
                 // 模块表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 $fields['updatetime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t, 1, $module['dirname']);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache ? $cache : $data, $sql, $total, $pages);
             break;
         case 'search':
             // 模块的搜索
             $total = (int) $param['total'];
             // 没有数据时返回空
             if (!$total) {
                 return $this->_return($system['return'], 'total参数为空', $sql, 0);
             }
             $dirname = $system['module'] ? $system['module'] : APP_DIR;
             if (!$dirname) {
                 return $this->_return($system['return'], 'module参数不能为空');
             }
             // 没有id时返回空
             if (!$param['id']) {
                 return $this->_return($system['return'], 'id参数为空', $sql, 0);
             }
             $system['site'] = !$system['site'] ? SITE_ID : $system['site'];
             // 默认站点参数
             $module = get_module($dirname, $system['site']);
             if (!$module) {
                 // 没有模块数据时返回空
                 return $this->_return($system['return'], "模块({$dirname})未安装");
             }
             $tableinfo = $this->ci->get_cache('table');
             if (!$tableinfo) {
                 $this->ci->load->model('system_model');
                 $tableinfo = $this->ci->system_model->cache();
                 // 表结构缓存
             }
             if (!$tableinfo) {
                 // 没有表结构缓存时返回空
                 return $this->_return($system['return'], '表结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
             }
             $table = $this->ci->db->dbprefix($system['site'] . '_' . $module['dirname']);
             // 模块主表
             if (!isset($tableinfo[$table]['field'])) {
                 return $this->_return($system['return'], '表(' . $table . ')结构缓存不存在(排查方式:后台-系统-数据备份,查看是否显示正常的表结构)');
             }
             $fields = $module['field'];
             // 主表的字段
             $sql_from = $table;
             // sql的from子句
             $system['catid'] = intval($system['catid']);
             // 排序操作
             $system['order'] = $this->_set_order_field_prefix($system['order'] ? $system['order'] : 'updatetime', $tableinfo[$table]['field'], $table);
             // 给排序字段加上表前缀
             // 关联栏目附加表
             if ($system['more'] && isset($module['category'][$system['catid']]['field']) && $module['category'][$system['catid']]['field']) {
                 $fields = array_merge($fields, $module['category'][$system['catid']]['field']);
                 $table_more = $table . '_category_data';
                 // 栏目附加表
                 $sql_from .= " LEFT JOIN {$table_more} ON `{$table_more}`.`id`=`{$table}`.`id`";
                 // sql的from子句
                 $system['order'] = $this->_set_order_field_prefix($system['order'], $tableinfo[$table_more]['field'], $table_more);
                 // 给排序字段加上表前缀
             }
             $sql_limit = $pages = '';
             $sql_where = '`id` IN(SELECT `cid` FROM `' . $table . '_search_index` WHERE `id`="' . $param['id'] . '")';
             // sql的where子句
             // 搜索分页
             $page = max(1, (int) $_GET['page']);
             $urlrule = str_replace('[page]', '{page}', urldecode($system['urlrule']));
             $pagesize = (int) $system['pagesize'];
             $pagesize = $pagesize ? $pagesize : 10;
             $sql_limit = 'LIMIT ' . $pagesize * ($page - 1) . ',' . $pagesize;
             $pages = $this->_get_pagination($urlrule, $pagesize, $total);
             $sql = "SELECT " . ($system['field'] ? $system['field'] : '*') . " FROM {$sql_from} WHERE {$sql_where} ORDER BY {$system['order']} {$sql_limit}";
             $data = $this->_query($sql, $system['site'], $system['cache']);
             // 缓存查询结果
             $name = 'list-action-search-' . md5($sql);
             $cache = $this->ci->get_cache_data($name);
             if (!$cache) {
                 // 模块表的系统字段
                 $fields['inputtime'] = array('fieldtype' => 'Date');
                 $fields['updatetime'] = array('fieldtype' => 'Date');
                 // 格式化显示自定义字段内容
                 foreach ($data as $i => $t) {
                     $data[$i] = $this->ci->field_format_value($fields, $t, 1, $module['dirname']);
                 }
                 $cache = $this->ci->set_cache_data($name, $data, $system['cache']);
             }
             return $this->_return($system['return'], $cache, $sql, $total, $pages);
             break;
         default:
             return $this->_return($system['return'], 'list标签必须含有参数action或者action参数错误');
             break;
     }
 }