示例#1
0
文件: functions.php 项目: jyht/v5
/**
 * 获得栏目
 * @param int $cid 栏目cid
 * @param int $type 1 子栏目  2 父栏目
 * @param int $returnType 1 只有cid  2 内容
 */
function getCategory($cid, $type = 1, $return = 1)
{
    $cache = cache('category');
    $cat = $catid = array();
    if ($type == 1) {
        //子栏目
        $cat = Data::channelList($cache, $cid);
    } else {
        if ($type == 2) {
            //父栏目
            $cat = parentChannel($cache, $cid);
        }
    }
    if ($return == 1) {
        //返回cid
        foreach ($cat as $c) {
            $catid[] = $c['cid'];
        }
        $catid[] = $cid;
        return $catid;
    } else {
        if ($return == 2) {
            //返回所有栏目数据
            $cat[] = $cache[$cid];
        }
    }
    return $cat;
}
 public function index()
 {
     $cache = S('category');
     $topCacegory = M('category')->where('pid=0')->all();
     $data = array();
     foreach ($topCacegory as $cat) {
         $cat['_data'] = Data::channelList($cache, $cat['cid']);
         $data[$cat['cid']] = $cat;
     }
     $this->assign('data', $data);
     $this->display();
 }
示例#3
0
文件: functions.php 项目: jyht/v5
function getCategory($cid)
{
    $categoryCache = cache('category');
    $catData = Data::channelList($categoryCache, $cid);
    $cids = array();
    if (!empty($catData)) {
        foreach ($catData as $cat) {
            $cids[] = $cat['cid'];
        }
    }
    $cids[] = $cid;
    return $cids;
}
示例#4
0
文件: Menu.php 项目: houdunwang/hdcms
 /**
  * 删除菜单
  */
 public function delMenu()
 {
     $db = new \system\model\Menu();
     $id = Request::post('id');
     if ($db->where('id', $id)->where('is_system', 1)->get()) {
         message('系统菜单不允许删除', 'back', 'error');
     }
     $data = Db::table('menu')->get();
     $menu = Data::channelList($data, $_POST['id'], " ", 'id', 'pid');
     $menu[]['id'] = $id;
     foreach ($menu as $m) {
         $db->where('id', $m['id'])->delete();
     }
     ajax(['valid' => TRUE, 'message' => '删除成功']);
 }
示例#5
0
 public function category()
 {
     $mid = Q('mid', 0, 'intval');
     $cid = Q('cid', 0, 'intval');
     if (!$mid || !$cid) {
         $this->error('参数错误');
     }
     $categoryCache = cache('category');
     if (!isset($categoryCache[$cid])) {
         $this->error('栏目不存在', __ROOT__);
     }
     if ($cid) {
         $category = $categoryCache[$cid];
         //外部链接,直接跳转
         if ($category['cattype'] == 3) {
             go($category['cat_redirecturl']);
         } else {
             $Model = ContentViewModel::getInstance($mid);
             $where = C('DB_PREFIX') . 'category.cid=' . $cid . " OR pid=" . $cid;
             $category['content_num'] = $Model->join('category')->where($where)->count();
             $childCategory = Data::channelList($categoryCache, $cid);
             $catWhere = array('cid' => array());
             if (!empty($childCategory)) {
                 foreach ($childCategory as $cat) {
                     $catWhere['cid'][] = $cat['cid'];
                 }
             }
             $catWhere['cid'][] = $cid;
             $category['comment_num'] = intval(M('comment')->where($catWhere)->sum());
             //栏目模板
             switch ($category['cattype']) {
                 case 1:
                     //普通栏目
                     $tpl = $category['list_tpl'];
                     break;
                 case 2:
                     //封面栏目
                     $tpl = $category['index_tpl'];
                     break;
             }
             $tpl = 'template/' . C("WEB_STYLE") . '/' . $tpl;
             $this->assign("hdcms", $category);
             $this->display($tpl);
         }
     }
 }
示例#6
0
                $where = ' pid=' . $pid;
                break;
        }
    }
}
$result = $db->where($where)->where("cat_show=1")->order()->order("catorder ASC")->limit(10)->all();
//无结果
if ($result) {
    //当前栏目,用于改变样式
    $_self_cid = isset($_REQUEST['cid']) ? $_REQUEST['cid'] : 0;
    $categoryCache = cache('category');
    foreach ($result as $field) {
        //当前栏目样式
        $field['class'] = $_self_cid == $field['cid'] ? "" : "";
        $field['caturl'] = Url::getCategoryUrl($field);
        $field['childcategory'] = Data::channelList($categoryCache, $field['cid']);
        ?>
							<li>
								<a href='<?php 
        echo $field['caturl'];
        ?>
'>
									<?php 
        echo $field['catname'];
        ?>
								</a>
							</li>
						<?php 
    }
}
?>
示例#7
0
 /**
  * 获得树状数据
  * @param $data 数据
  * @param $title 字段名
  * @param string $fieldPri 主键id
  * @param string $fieldPid 父id
  * @return array
  */
 public static function tree($data, $title, $fieldPri = 'id', $fieldPid = 'pid')
 {
     if (!is_array($data) || empty($data)) {
         return array();
     }
     $arr = Data::channelList($data, 0, '', $fieldPri, $fieldPid);
     foreach ($arr as $k => $v) {
         $str = "";
         if ($v['_level'] > 2) {
             for ($i = 1; $i < $v['_level'] - 1; $i++) {
                 $str .= "│&nbsp;&nbsp;&nbsp;&nbsp;";
             }
         }
         if ($v['_level'] != 1) {
             $t = $title ? $v[$title] : "";
             if (isset($arr[$k + 1]) && $arr[$k + 1]['_level'] >= $arr[$k]['_level']) {
                 $arr[$k]['_name'] = $str . "├─ " . $v['_html'] . $t;
             } else {
                 $arr[$k]['_name'] = $str . "└─ " . $v['_html'] . $t;
             }
         } else {
             $arr[$k]['_name'] = $v[$title];
         }
     }
     //设置主键为$fieldPri
     $data = array();
     foreach ($arr as $d) {
         $data[$d[$fieldPri]] = $d;
     }
     return $data;
 }
示例#8
0
 /**
  * 删除栏目
  * @param $cid
  * @return bool
  */
 public function delCategory($cid)
 {
     if (!$cid || !isset($this->category[$cid])) {
         $this->error = 'cid参数错误';
         return false;
     }
     /**
      * 获得子栏目
      */
     $category = Data::channelList($this->category, $cid);
     $category[]['cid'] = $cid;
     foreach ($category as $cat) {
         //删除栏目文章
         $ContentModel = ContentModel::getInstance($this->category[$cat['cid']]['mid']);
         $ContentModel->where("cid=" . $cat['cid'])->del();
         //删除栏目权限
         M("category_access")->where("cid=" . $cat['cid'])->del();
         //删除栏目
         $this->del($cat['cid']);
     }
     //        //生成所有栏目
     //        $this->html->all_category();
     //        //生成首页
     //        $this->html->index();
     //更新缓存
     return $this->updateCache();
 }