<?php
/**
 * 获取未分类id
 * @param string $categoryId['id']
 */
function getCategory()
{
    $Category = M('acategory');
    $categoryId = $Category->where(" category ='未分类' ")->find();
    return $categoryId['id'];
}



/**
 * 获取当前页面完整URL地址
 */
function getURL() {
    $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
    $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
    $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
    $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
    return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
}


function RU($url){

    // 兼容 index/:category\d 路由
    if(preg_match('/\/index\/index\/category\/\d+/', $url)){
        $url=str_replace(array('/index/index',''), '', $url);
    }
    // 兼容 index/'Index/index
    if(preg_match('/\/index\/index/', $url)){
        $url='/';

    }
    //兼容兼容 detail/:id\d 路由
    if(preg_match('/\/index\/detail\/id\/\d+/', $url)){
        $url=str_replace(array('/index',''), '', $url);
    }
    if(preg_match('/\/index\/taglist\/tag\/\d+/', $url)){
        $url=str_replace(array('/index/taglist',''), '', $url);
    }
    return $url;
}

/**
 * 获取后台栏目的父类名称
 */
function parent_name($action_name){
    $Auth=M('auth');
    $info=$Auth->where(array('key'=>$action_name))->find();
    $parentInfo=$Auth->where(array('id'=>$info['parent_id']))->find();
    return $parentInfo['auth_name'];
}
/*
 * 获取后台栏目名称
 */
function category_name($action_name){
    $Auth=M('auth');
    $info=$Auth->where(array('key'=>$action_name))->find();

    return $info['auth_name'];
}

/*
    * linkurl底部连接
    */
function getLinkUrl(){
    $model=M('about');
    $where['is_del']='0';
    $list=$model->where($where)->order('sort asc')->select();
    foreach ($list as $k=>$v){
        $str .= "<a href=\"/Static/page/name/".$v['name']."\">".$v['title']."</a>|";
    }
    // $str=substr($str,0,-1);
    $str .= '<a href="https://www.zhuige.com" target="_blank">微信小程序</a>';
    return $str;

}



/*
 *获取网站配置信息
 */
function getWebSetting($name){
    $model=M('config');
    $info=$model->where(array('name'=>$name))->find();
    return $info['value'];

}

