Posted
Filed under PHP

<?
//indexer.php 주소 체계
class indexer{
//config
 ///##아이디 길이 설정##///
 var $MaxLenId = 12;
 var $MinLenId = 6;
 ///###################///
 var $post;
 var $tb;
 var $id;
 var $url;
 var $_url;
 var $errType; //추후 Exception타입을 결정하기 위한 변수 나중에 확장성을 위해서 선언
 ///##모드 변수 action을 결정하는 변수 ##///
 var $mode;
 //mode type = nomal,post,tb,errType
 //nomal = domain/아이디 일 경우
 //post  = domain/아이디/글번호
 //tb    = domain/tb/아이디/글번호
 //errtype = 아이디가 존재 하지 않거나 주소 체계가 잘못 된 경우  
 
 function indexer($_url){
  $this->_url = $_url;
  $str = explode("/",$this->_url);
  $this->url = $str[1];
 }// end indexer

 function idChk($id){
  $strCount=0;  //문자의 개수
  $NumCount=0;  //숫자의 개수
 
  if($this->MinLenId<=strlen($id) && strlen($id)<=$this->MaxLenId){
   
   for($cnt=0; $cnt<strlen($id); $cnt++){
  //문자일 경우  
    if(is_numeric($id[$cnt])==1){
     $numCount++;
     
    }
    else{
     $strCount++;
    }
 
   }
  // echo $numCount ." numCount <br>";
  // echo $strCount ." strCount <br>";
  //합당한 아이디 인지 검사
 
   if($numCount==6 && $strCount==0){
    $this->mode="errType";
   }
   else{
    $result="ok";
   }//end if
     
  }else{
   $this->mode ="errType";
  }//end if
  return $result;
 }//end idChk

 function IsId(){
  $numCount=0;
  $strCount=0;
  // 아이디 인지 트랙백 주소인지 체크
  //트랙백 주소인경우
  $str = explode("/",$this->_url);
  $ctr=0;
 
  if($this->url == "tb"){
   if(indexer::idChk($str[2])=="ok" && is_numeric($str[3])==1){
    $this->post = $str[3];
    $this->id   = $str[2];
    $this->mode = "tb";
   }
   else{
    $this->mode = "errType";
   }
  }
  //아이디인 경우
  else{
   if(indexer::idChk($this->url)=="ok" && is_numeric($str[2])==1){
    $this->post=$str[2];
    $this->id = $str[1];
    $this->mode = "post";
   }
   else if(indexer::idChk($this->url)=="ok"){
    $this->id =$str[1];
    $this->mode="nomal";
   }
  }//end if    
 }//end Isid
 
 //페이지 경로 설정
 function go(){
  $redirect;
  switch($this->mode){
   case "nomal":
    $redirect="blog_index.html?id=".$this->id;
    header("Location: http://".$_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/" . $redirect);
   break;
   
   case "post":
    $redirect="blog_index.html?id=".$this->id."&post=".$this->post;
    header("Location: http://".$_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/" . $redirect);
   break;
   
   case "tb":
    $redirect="Module/TrackBack/TrackBack.html?id=".$this->id."&post=".$this->post;
   //트랙백 개발시 트랙백 모듈에 전송해야 함.
    header("Location: http://".$_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/" . $redirect);
   break;
   
   default:
    $redirect="Module/NotFound/NotFound.html";
    header("Location: http://".$_SERVER['HTTP_HOST']
                      . dirname($_SERVER['PHP_SELF'])
                      . "/" . $redirect);
   break;
  }
 }//end go
 
//###### 클래스 생성후 Load메소드 호출 ###########//  

 function Load(){
  indexer::IsId();
  indexer::go();
 }//end Load

//###### 클래스 생성후 Load메소드 호출 ###########//  
 
} //end class
?>

2009/07/17 20:43 2009/07/17 20:43