public static function breadcrumbs($cid = '')
 {
     if (!$cid) {
         $cid = I('get.cid');
     }
     $crumbs = S('crumbs_' . $cid);
     if (!$crumbs) {
         $catemod = DD('Category');
         $nowlang = nowlang();
         $catelist = $catemod->selectbylang($nowlang['id']);
         $new_arr = array();
         foreach ($catelist as $key => $cate) {
             $new_arr[$cate['id']] = $cate;
         }
         $crumbs = self::getparentcate($new_arr, $cid);
         $crumbs = array_reverse($crumbs);
         foreach ($crumbs as $key => $c) {
             if ($c['mid'] == 3) {
                 $c['href'] = ROU('Content/Content/page', array('id' => $c['id']));
             } else {
                 if ($c['isleaf'] == 1) {
                     $c['href'] = ROU('Content/Content/newslist', array('cid' => $c['id']));
                 } else {
                     $c['href'] = ROU('Content/Content/category', array('cid' => $c['id']));
                 }
             }
             $crumbs[$key] = $c;
         }
         S('crumbs_' . $cid, $crumbs);
     }
     return $crumbs;
 }
Exemple #2
0
/**
 * 自动生成路由地址
 * @param string $url
 * @param string $arr
 * @param string $module
 */
function ROU($url, $arr)
{
    if (C('URL_MODEL') != 2) {
        return U($url, $arr);
    }
    if (!key_exists(C('VAR_LANGUAGE'), $arr)) {
        $nl = nowlang();
        $fl = defaultlang();
        if ($nl['id'] != $fl['id']) {
            $arr[C('VAR_LANGUAGE')] = $nl['lang'];
        }
    }
    ksort($arr);
    $url_parse = explode('/', $url);
    foreach ($url_parse as $key => $u_p) {
        if ($key == 0) {
            continue;
        }
        $true_rul .= $u_p . '/';
    }
    $true_rul = rtrim($true_rul, '/');
    $key_array = array_keys($arr);
    $org_url_group = $true_rul . '_' . implode('_', $key_array);
    $param_str = '';
    foreach ($arr as $key => $a) {
        $param_str .= $key . '=' . $a . '&';
    }
    $C_org_url_group = $true_rul . '?' . rtrim($param_str, '&');
    $module = $url_parse[0];
    $rou_file = getcwd() . '/Config/Router/Site/' . $module . '.php';
    if (is_file($rou_file)) {
        $router = (include $rou_file);
        if (!S($module . '_router')) {
            $rou_handle = array();
            foreach ($router['URL_ROUTE_RULES'] as $key => $rules) {
                preg_match_all('/(.*)(\\?|&)(.*)=:(\\d)(.*)/U', $rules, $matches);
                if (!$matches[3]) {
                    //$rules = str_replace(array('?', '='), '/', $rules);
                }
                $temp_arr = array();
                foreach ($matches[3] as $param) {
                    $temp_arr[] = $param;
                }
                ksort($temp_arr);
                $rules_param_arr = array();
                foreach ($matches[4] as $k => $param) {
                    $rules_param_arr[$param] = $matches[3][$k];
                }
                ksort($rules_param_arr);
                //防止绝对匹配
                $v = $rules . '_';
                if ($matches[1][0]) {
                    $v = $matches[1][0] . '_' . implode('_', $temp_arr);
                }
                $v = rtrim($v, '_');
                $rou_handle[$v] = array('reg' => $key, 'rule' => $rules, 'param' => $rules_param_arr);
                S($module . '_router', $rou_handle);
            }
        } else {
            $rou_handle = S($module . '_router');
        }
        $rou_handle_key = array_keys($rou_handle);
        $index1 = -1;
        if (in_array($org_url_group, $rou_handle_key)) {
            $index1 = array_search($org_url_group, $rou_handle_key);
        }
        $index2 = -1;
        if (in_array($C_org_url_group, $rou_handle_key)) {
            $index2 = array_search($C_org_url_group, $rou_handle_key);
        }
        if ($index1 == -1 && $index2 != -1 || $index1 > $index2 && $index1 != -1 && $index2 != -1) {
            $org_url_group = $C_org_url_group;
        }
        if (key_exists($org_url_group, $rou_handle)) {
            $reg_rule = $rou_handle[$org_url_group];
            $rou_text = preg_split("/\\((.*)\\)/U", $reg_rule['reg']);
            $reg_rule['param'] = array_values($reg_rule['param']);
            //重建索引
            $rou_url = '';
            foreach ($rou_text as $key => $r_t) {
                if (count($rou_text) - 1 == $key) {
                    $rou_url .= $r_t;
                } else {
                    $rou_url .= $r_t . $arr[$reg_rule['param'][$key]];
                }
            }
        }
    }
    if ($rou_url != '') {
        $rou_url = str_replace(array('\\', '/^', '$/'), '', $rou_url);
        $suffix = '';
        if (C('URL_HTML_SUFFIX')) {
            $suffix = '.' . C('URL_HTML_SUFFIX');
        }
        $bfix = '';
        if (C('DEFAULT_MODULE') != $module) {
            $bfix = $module . '/';
        }
        if (C('URL_MODEL') == 0) {
            return __APP__ . '/' . $bfix . $rou_url . $suffix;
        } else {
            return __ROOT__ . '/' . $bfix . $rou_url . $suffix;
        }
    }
    return U($url, $arr);
}
Exemple #3
0
 public function _Get($tag)
 {
     $sql = $tag['sql'];
     $lang = nowlang();
     $def_lang = defaultlang();
     $lid = $lang['id'];
     $article = M('Article');
     //组装where条件
     $condition = array();
     //判断语言1,2,3/zh-cn|4,5,6/en-us
     $sql_param = explode('|', $sql);
     foreach ($sql_param as $s) {
         $sqls_lang = explode('/', $s);
         $c_l = '';
         if (count($sqls_lang) == 2) {
             $c_l = $sqls_lang[0];
         } else {
             $c_l = $def_lang['lang'];
         }
         if ($c_l == $lang['lang']) {
             $sql = $sqls_lang[1];
             break;
         }
     }
     $return = $tag['return'];
     $parseStr = '<?php ';
     $parseStr .= '$m=new \\Think\\Model();';
     $return = '$' . $return;
     $parseStr .= $return . '=$m->cache(3600,true)->query("' . $sql . '")';
     $parseStr .= ' ?>';
     return $parseStr;
 }