<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_URI extends CI_URI
{
// 记录被调用过的最大 segment 序号，默认=2 (1=Controller, 2=action)
var $_goodseg = 2;
 
// HOOK: 记录曾经使用过的 segment 的最大序号，用来过滤垃圾 seg
function segment($n, $no_result = FALSE)
{
  if ($n > $this->_goodseg)
  {
   $this->_goodseg = $n;
  }
  return parent::segment($n, $no_result);
}
 
// EXTEND: 只获取曾经被 ::segment() 方法调用过的最大序号之内的 segment 数组集合
function good_rsegment_array() 
{
   return array_slice($this->rsegments, 0, $this->_goodseg);
}

function _set_uri_string($str){

		$str = remove_invisible_characters($str, FALSE);
		$this->uri_string = ($str == '/') ? '' : $str;

		//判断后台域名,不给进入前台
		if(strpos(@$_SERVER['REQUEST_URI'],'admin') === FALSE && $_SERVER['HTTP_HOST']==Admin_Url){
                      header("Location: http://".Web_Url."");
		      exit;
		}
                $UYM=$_SERVER['HTTP_HOST'];
                if(file_exists(CSCMSPATH.'lib/Cs_Domain.php')){
		      $_CS_Domain = require_once(CSCMSPATH.'lib/Cs_Domain.php');
                      foreach ($_CS_Domain as $key => $host) {
                              if($key!='home'){
                                   if($UYM==$host){
                                        $this->uri_string = $key . '/' . $this->uri_string;
                                   }
                              }
		      }
                }
		if(Home_Ym==1){
			$serverName = explode('.', $_SERVER['HTTP_HOST']);
			$uyms=str_replace($serverName[0].'.', "",$_SERVER['HTTP_HOST']);
			if($serverName[0]==$serverName[1]) $uyms=$serverName[1].'.'.$uyms;
			if($serverName[0]!='www' && $uyms==Home_YmUrl && strpos(@$_SERVER['REQUEST_URI'],'discuss') === FALSE && strpos(@$_SERVER['REQUEST_URI'],'ulog') === FALSE && strpos(@$_SERVER['REQUEST_URI'],'login') === FALSE && strpos(@$_SERVER['REQUEST_URI'],'logout') === FALSE){
                               $this->uri_string = "home/" . $this->uri_string;
			}
		}
        if (defined('IS_ADMIN')){
             $this->uri_string = 'admin/' . $this->uri_string;
			 $this->uri_string = str_replace("admin/admin", "admin", $this->uri_string);
		}else{
			if(strpos($_SERVER['REQUEST_URI'],'index.php/admin')){
				show_404();
			}
		}
                $this->uri_string = str_replace('home/m/', 'm/',$this->uri_string);
                //exit($this->uri_string);
}

} // END class MY_URI
