<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied'); class category_mod extends module { public function get_one($cid){ return $this->db->get_one("select * from ".table("category")." where cid = ".$cid); } public function get_one_list($cid){ return $this->db->get_all("select * from ".table("category")." where pcid = ".$cid); } public function get_top_list(){ return $this->db->get_all("select * from ".table('category')." where pcid = 0 and status = 1 order by px_asc desc"); } public function get_list(){ $content = cache::get("config/category_index"); if(!$content){ $catsQuery = $this->db->get_all("select cid,pcid,name,images,px_hot,px_asc,status from ".table('category')." where status = 1 order by px_asc asc"); foreach($catsQuery as $k=>$v){ if($v['pcid'] == '0'){ foreach($catsQuery as $kk=>$vv){ if($vv['pcid'] == $v['cid']){ foreach($catsQuery as $kkk=>$vvv){ if($vvv['pcid'] == $vv['cid']){ $vv['pparent'][] = $vvv; if($vvv['px_hot'] == '1'){ $ccc[] = $vvv; } } } $v['parent'][] = $vv; } $v['px_hot'] = $ccc; } $all_cats[] = $v; unset($ccc); } } cache::add("config/category_index", $all_cats); return $all_cats; }else{ return $content; } } public function get_parents_cid($cid){ if($cid){ $result = $this->get_parents_in($cid); if($result){ foreach($result as $k=>$v){ $pcats[] = $v['cid']; } sort($pcats); return $pcats; }else{ return false; } }else{ return false; } } public function get_parents_name($cid){ if($cid){ $result = $this->get_parents_in($cid); if($result){ foreach($result as $k=>$v){ $pcats[$v['cid']] = $v['name']; } ksort($pcats); return $pcats; } }else{ return false; } } private function get_parents_in($cid, &$result_arr = array()){ $crow = $this->db->get_one("select cid,pcid,name from ".table('category')." where cid = ".$cid." limit 1"); if($crow['cid']){ $result_arr[] = $crow; $result_arr = $this->get_parents_in($crow['pcid'], $result_arr); } return $result_arr; } function get_parents_list($cid_arr){ $last_cid = $cid_arr[count($cid_arr)-1]; $clresult = $this->db->get_all("select cid,pcid,name from ".table('category')." where pcid = 0 and status = 1"); $clist_arr['cid'] = $cid_arr[0]; $clist_arr['list'] = $clresult; $clist[] = $clist_arr; foreach($cid_arr as $k=>$v){ if($v != $last_cid){ $clresult = $this->db->get_all("select cid,pcid,name from ".table('category')." where pcid = ".$v." and status = 1"); if($clresult){ $clist_arr['cid'] = $cid_arr[$k+1]; $clist_arr['list'] = $clresult; $clist[] = $clist_arr; } } } return $clist; } public function get_child_cid($cid){ $result = $this->get_child_in($cid); if($result){ return $result; }else{ return false; } } private function get_child_in($cid){ static $cresult = array(); $crow = $this->db->get_all("select cid,pcid,status from ".table('category')." where pcid in(".$cid.") and status = 1"); if($crow){ foreach($crow as $k=>$v){ $list[] = $v['cid']; $cresult[] = $v['cid']; } $cid_in = implode(',', $list); $this->get_child_in($cid_in); } return $cresult; } function common($name){ if($name){ $filename = UQCMS_PATH.'temp/config/category_com_'.$name.'.php'; if(file_exists($filename)){ $comArr = include $filename; }else{ $row = $this->db->get_one("select * from ".table('category_com')." where alias = '".$name."' and status = 1"); if($row['cid']){ $gall = $this->db->get_all("select cid,pcid,name,alias,px,status from ".table('category_com')." where pcid = '".$row['cid']."' and status = 1 order by px desc"); if($gall){ foreach($gall as $k=>$v){ $comArr[$k] = $v['name']; } } file_put_contents($filename, "<?php \r\n return ".var_export($comArr, true).";"); }else{ return false; } } return $comArr; }else{ return false; } } } 