[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/net/ -> prettyrequestparser.class.php (source)

   1  <?php
   2  
   3      /**
   4       * @package net
   5       */
   6  
   7  
   8      
   9  
  10      class PrettyRequestParser  {
  11  
  12      	function PrettyRequestParser( $function, $path_info )
  13          {
  14              $len = strlen($path_info);
  15              if($len && $path_info[$len-1] == '/')
  16                 $this->_path_info = substr($path_info, 0, -1);
  17              else
  18                 $this->_path_info = $path_info;
  19  
  20              $this->_function  = $function;
  21          }
  22          
  23          /** 
  24           * @private
  25           * Retrieves the page from the request
  26           */
  27  		function getPageValue( $request )
  28          {
  29              if( preg_match( "/\/page\/([0-9]*)/", $request, $matches ))
  30                  $page = $matches[1];
  31              else
  32                  $page = "";
  33              
  34              return( $page );
  35          }
  36  
  37          function parse()
  38          {
  39              // remove the page from the string, if any and then remove the string itself so that
  40              // it doesn't interfere with the old parsing code
  41              $page = $this->getPageValue( $this->_path_info );
  42              $this->_path_info = preg_replace( "/\/page\/[0-9]*/", "", $this->_path_info );        
  43          
  44              // get the blog id and the post id
  45              $params = explode( "/", $this->_path_info );
  46  
  47              // the blog id always comes after the name of the operation
  48              $blogId = $params[count($params)-2];
  49  
  50              $result = Array();
  51              $result["blogId"] = $blogId;
  52  
  53              switch( $this->_function ) {
  54                  case "post":
  55                      $articleId = $params[count($params)-1];
  56                      $result["articleId"] = $articleId;
  57                      $result["op"] = "ViewArticle";
  58                      break;
  59                  case "album":
  60                      $albumId = $params[count($params)-1];
  61                      $result["albumId"] = $albumId;
  62                      $result["op"] = "ViewAlbum";
  63                      break;
  64                  case "comment":
  65                      $articleId = $params[count($params)-1];
  66                      $result["articleId"] = $articleId;
  67                      $result["op"] = "Comment";
  68                      break;
  69                  case "rss":
  70                      if( count($params) == 3 ) {
  71                          $param1 = $params[count($params)-2];
  72                          $param2 = $params[count($params)-1];
  73                          // this is a bit trickier because if we only have two parameters
  74                          // it can either be the profile or the category identifier so we
  75                          // we have to check for that...Of course it we ever have a profile
  76                          // that is a number then we'll have a problem here. Till then,
  77                          // it's all fine and dandy :)
  78                          if( is_numeric($param1)) {
  79                              $result["categoryId"] = $param2;
  80                              $result["blogId"] = $param1;
  81                          }
  82                          else {
  83                              $result["profile"] = $param1;
  84                              $result["blogId"] = $param2;
  85                          }
  86                      }
  87                      elseif( count($params) == 4 ) {
  88                          $result["categoryId"] = $params[count($params)-1];
  89                          $result["blogId"] = $params[count($params)-2];
  90                          $result["profile"] = $params[count($params)-3];
  91                      }
  92                      $result["op"] = "RssAction";
  93                      break;
  94                  case "archives":
  95                      $date = $params[count($params)-1];
  96                      $result["op"] = "Default";
  97                      $result["Date"] = $date;
  98                      break;
  99                  case "user":
 100                      $userId = $params[count($params)-1];
 101                      $result["userId"] = $userId;
 102                      $result["op"] = "Default";
 103                      break;                    
 104                  case "category":
 105                      $categoryId = $params[count($params)-1];
 106                      $result["postCategoryId"] = $categoryId;
 107                      $result["op"] = "Default";
 108                      break;
 109                  case "static":
 110                      $templateName = $params[count($params)-1];
 111                      $result["show"] = $templateName;
 112                      $result["op"] = "Template";
 113                      break;
 114                   case "resource":
 115                       $resParam = $params[count($params)-1];
 116                      if( is_numeric( $resParam )) {
 117                          $result["resId"] = $resParam;
 118                      }
 119                      else {
 120                          $result["resource"] = $resParam;
 121                      }
 122                      $result["op"] = "ViewResource";
 123                      break;
 124                   case "get":
 125                       $resFile = $params[count($params)-1];
 126                      $result["resource"] = $resFile;
 127                      break;
 128                   case "trackbacks":
 129                       $postId = $params[count($params)-1];
 130                      $result["op"] = "Trackbacks";
 131                      $result["articleId"] = $postId;
 132                      break;
 133                   default:
 134                       $result["op"] = "Default";
 135                      $userParam=$params[count($params)-1];
 136                      if( is_numeric($userParam))
 137                          $result["blogId"] = $userParam;
 138                      else
 139                          $result["blogUserName"] = $userParam;
 140               }
 141               
 142               $result["page"] = $page;
 143  
 144               return $result;
 145          }
 146      }
 147  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics