<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */


function hook_get_category($params) {
    if (!empty($params)) {
        @extract($params);
		$type = empty($params['type']) ? 'url' : trim($params['type']);
		$id = intval($params['id']);
		$name = empty($params['name']) ? '' : trim($params['name']);
		$class = empty($params['class']) ? '' : trim($params['class']);
		$target = empty($params['target']) ? '_self' : trim($params['target']);
		$title = empty($params['title']) ? '' : trim($params['title']);
        #catalog栏目URL路由
		if ($type == 'url') {
            #栏目标识
			if (true === XValid::isSpChar($name)) {
				$val = $name;
				$valtype = 2;
			}
            #栏目ID
			else {
				$val = $id;
				$valtype = 1;
			}
			$cat_model = X::model('category', 'im');
			return $cat_model->getCategoryUrl($val, $valtype, $title, $class, $target);
			unset($cat_model);
		}
    } 
}
TPL::regFunction('category', 'hook_get_category');


function vo_category($extracts) {
    $params = XHandle::buildTagArray($extracts);
    if (!empty($params)) {
        @extract($params);
		#钩子类型
		$type = strtolower(trim($params['type']));
        #参数组合
        $args = array();
        if (true === XValid::isSpChar($params['module'])) {
            
            $args['module'] = trim($params['module']);
        }
        if (true === XValid::isNumber($params['treeid'])) {
            $args['treeid'] = $params['treeid'];
        }
        if (true === XValid::isNumber($params['rootid'])) {
            $args['rootid'] = $params['rootid'];
        }
        if (true === XValid::isNumber($params['ismenu'])) {
            $args['ismenu'] = $params['ismenu'];
        }
        if (true === XValid::isNumber($params['isaccessory'])) {
            $args['isaccessory'] = $params['isaccessory'];
        }
		if (true === XValid::isNumber($params['num'])) {
			$args['num'] = $params['num'];
		}
		if (true == XValid::isNumber($params['adcatid'])) {
            $args['adcatid'] = $params['adcatid'];
		}
        #-----新参数 BeGIN 2013.09.25------#
		$where = XFilter::filterSql(trim($params['where']));
		$orderby = XFilter::filterSql(trim($params['orderby']));
		$num = intval($params['num']);
        $limit = empty($params['limit']) ? '' : XFilter::filterSql(trim($params['limit']));
        $device = $params['device'];
        #-----新参数 End 2013.09.25------#
        $cat_model = X::model('category', 'im');
        #一级导航
        if ($type == 'rootmenu') {
            return $cat_model->rootMenu();
        }
        #一级+二级导航
        elseif ($type == 'sedmenu') {
			return $cat_model->sedMenu();
        }
		#底部附加导航
		elseif ($type == 'submenu') {
			return $cat_model->subMenu($args);
		}
		#模块一级分类
		elseif ($type == 'rootcat') {
			return $cat_model->rootCategory($args);
		}
		#模块一级+二级分类
		elseif ($type == 'treecat') {
			return $cat_model->treeCategory($args);
		}
        #万能volist导航 2013.09.25
        elseif ($type == 'volist') {
           
            return $cat_model->volistAll($where, $orderby, $num, $limit);
        }
		#根据二级分类的 catid 返回对应的 广告图片URL 2019.05.23
		elseif ($type == 'adimg') {
			return $cat_model->geradimgurl($params['catid']);
		}
		unset($cat_model);
	}
}
?>
