category_tree']; } $this->data['category_tree'] = array(); $tmp = $this->get_category_db(); // 格式化为树状结构 (会舍弃不合格的结构) foreach($tmp as $v) { $tmp[$v['upid']]['son'][$v['cid']] = &$tmp[$v['cid']]; } $this->data['category_tree'] = isset($tmp['0']['son']) ? $tmp['0']['son'] : array(); // 格式化为树状结构 (不会舍弃不合格的结构) // foreach($tmp as $v) { // if(isset($tmp[$v['upid']])) $tmp[$v['upid']]['son'][] = &$tmp[$v['cid']]; // else $this->data['category_tree'][] = &$tmp[$v['cid']]; // } return $this->data['category_tree']; } // 获取分类 (二维数组) public function get_category() { if(isset($this->data['category_array'])) { return $this->data['category_array']; } $arr = $this->get_category_tree(); return $this->data['category_array'] = $this->to_array($arr); } // 递归转换为二维数组 public function to_array($data, $pre = 1) { static $arr = array(); foreach($data as $k => $v) { $v['pre'] = $pre; if(isset($v['son'])) { $arr[$v['mid']][] = $v; self::to_array($v['son'], $pre+1); }else{ $arr[$v['mid']][] = $v; } } return $arr; } // 获取模型下级所有列表分类的cid public function get_cids_by_mid($mid) { $k = 'cate_by_mid_'.$mid; if(isset($this->data[$k])) return $this->data[$k]; $arr = $this->runtime->xget($k); if(empty($arr)) { $arr = $this->get_cids_by_upid(0, $mid); $this->runtime->set($k, $arr); } $this->data[$k] = $arr; return $arr; } // 获取频道分类下级列表分类的cid public function get_cids_by_upid($upid, $mid) { $arr = array(); $tmp = $this->get_category_db(); if($upid != 0 && !isset($tmp[$upid])) return FALSE; foreach($tmp as $k => $v) { if($v['mid'] == $mid) { $tmp[$v['upid']]['son'][$v['cid']] = &$tmp[$v['cid']]; }else{ unset($tmp[$k]); } } if(isset($tmp[$upid]['son'])) { foreach($tmp[$upid]['son'] as $k => $v) { if($v['type'] == 1) { $arr[$k] = isset($v['son']) ? self::recursion_cid($v['son']) : array(); }elseif($v['type'] == 0) { $arr[$k] = 1; } } } return $arr; } // 递归获取下级分类全部 cid public function recursion_cid(&$data) { $arr = array(); foreach($data as $k => $v) { if(isset($v['son'])) { $arr2 = self::recursion_cid($v['son']); $arr = array_merge($arr, $arr2); }else{ if($v['type'] == 0) { $arr[] = intval($v['cid']); } } } return $arr; } // 获取分类下拉列表HTML (内容发布时使用) public function get_cidhtml_by_mid($_mid = 0, $cid = 0, $tips = '选择分类', $in_cid = array(), $other = '') { $category_arr = $this->get_category(); $s = ''; return $s; } // 获取上级分类的 HTML 代码 (只显示频道分类) public function get_category_upid($mid, $upid = 0, $noid = 0) { $category_arr = $this->get_category(); $s = ''; if(isset($category_arr[$mid])) { foreach($category_arr[$mid] as $v) { // 不显示列表的分类 if($mid> 1 && $v['type'] == 0) continue; // 当 $noid 有值时,排除等于它和它的下级分类 if($noid) { if(isset($pre)) { if($v['pre'] > $pre) continue; else unset($pre); } if($v['cid'] == $noid) { $pre = $v['pre']; continue; } } $s .= ''; } } return $s; } // 获取指定分类的 mid (如果 cid 为空,则读第一个分类的 mid) public function get_mid_by_cid($cid) { if($cid) { $arr = $this->get($cid); }else{ $arr = $this->get_category(); if(empty($arr)) return 2; $arr = current($arr); $arr = current($arr); } return $arr['mid']; } // 获取分类当前位置 public function get_place($cid) { $p = array(); $tmp = $this->get_category_db(); while(isset($tmp[$cid]) && $v = &$tmp[$cid]) { array_unshift($p, array( 'cid'=> $v['cid'], 'name'=> $v['name'], 'url'=> $this->category_url($v, 0, array('url_path'=>1)) )); $cid = $v['upid']; } return $p; } // 获取分类缓存合并数组 public function get_cache($cid) { $k = 'cate_'.$cid; if(isset($this->data[$k])) return $this->data[$k]; $arr = $this->runtime->xget($k); if(empty($arr)) { $arr = $this->update_cache($cid); } $this->data[$k] = $arr; return $arr; } // 更新分类缓存合并数组 public function update_cache($cid) { $k = 'cate_'.$cid; $arr = $this->get($cid); if(empty($arr)) return FALSE; $arr['place'] = $this->get_place($cid); // 分类当前位置 $arr['topcid'] = $arr['place'][0]['cid']; // 顶级分类CID $arr['table'] = $this->cfg['table_arr'][$arr['mid']]; // 分类模型表名 // 如果为频道,获取频道分类下级CID if($arr['type'] == 1) { $arr['son_list'] = $this->get_cids_by_upid($cid, $arr['mid']); $arr['son_cids'] = array(); if(!empty($arr['son_list'])) { foreach($arr['son_list'] as $c => $v) { if(is_array($v)) { $v && $arr['son_cids'] = array_merge($arr['son_cids'], $v); }else{ $arr['son_cids'][] = $c; } } } } $this->runtime->set($k, $arr); return $arr; } //删除指定的分类缓存 public function delete_cache_one($cid = 0){ $k = 'cate_'.$cid; $this->runtime->delete($k); return true; } // 删除所有分类缓存 (最多读取2000条,如果缓存太大,需要手工清除缓存) public function delete_cache() { $key_arr = $this->runtime->find_fetch_key(array(), array(), 0, 2000); foreach ($key_arr as $v) { if(substr($v, 10, 5) == 'cate_') { $this->runtime->delete(substr($v, 10)); } } return TRUE; } //内容列表获取分类信息 public function getCategoryInfoByList(&$v, $cate = array()){ (empty($cate) && isset($v['cid'])) AND $cate = $this->get_cache($v['cid']); if(isset($cate['cid']) && isset($v['cid']) && $cate['cid'] == $v['cid']){ $v['cate_name'] = isset($cate['name']) ? $cate['name'] : ''; $v['cate_url'] = $this->category_url($cate); $v['cate_alias'] = isset($cate['alias']) ? $cate['alias'] : ''; $v['cate_intro'] = isset($cate['intro']) ? $cate['intro'] : ''; } } // 分类链接格式化 public function category_url(&$cate, $page = FALSE, $extra = array()) { $url = ''; $cid = isset($cate['cid']) ? (int)$cate['cid'] : 0; $alias = isset($cate['alias']) ? $cate['alias'] : ''; //使用相对URL if( (isset($this->cfg['url_path']) && !empty($this->cfg['url_path'])) || isset($extra['url_path']) && !empty($extra['url_path']) ){ unset($extra['url_path']);//要去掉这个参数,不然会到下面的附加参数里面 $this->cfg['weburl'] = $this->cfg['webdir']; } if(empty($cid) || empty($alias)){ return ''; } $lecms_parseurl = empty($_ENV['_config']['lecms_parseurl']) ? 0 : 1; if(empty($lecms_parseurl)) { $url .= $this->cfg['weburl'].'index.php?cate--cid-'.$cid.($page ? '-page-{page}' : ''); }else{ if($page) { $url .= $this->cfg['weburl'].$alias.$this->cfg['link_cate_page_pre'].'{page}'; }else{ $url .= $this->cfg['weburl'].$alias; } } // 附加参数 if($extra) { foreach ($extra as $k=>$v){ if(empty($lecms_parseurl)) { $url .= '-'.$k.'-'.$v; }else{ $url .= '/'.$k.'-'.$v; } } } //后缀 if(empty($lecms_parseurl)) { $url .= $_ENV['_config']['url_suffix']; }else{ if($page) { $url .= $this->cfg['link_cate_page_end']; }else{ $url .= $this->cfg['link_cate_end']; } } return $url; } } Lecms 3.0.3 错误

错误信息

错误位置

基本信息

程序流程

SQL

$_GET

$_POST

$_COOKIE

包含文件

其他信息