[ 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/ -> linkparser.class.php (source)

   1  <?php
   2  
   3      /**
   4       * \ingroup Net
   5       *
   6       * Given a link format (like all the *_link_format configuration settings) and a valid incoming
   7       * request, determine if the URL matches the format and if so, fill in an array with the information
   8       * extracted from the link (according to the format)
   9       *
  10       * This class is used by LinkFormatMatched and generally there is no need to use this class
  11       * by plugin developers.
  12       *
  13       * @see LinkFormatMatcher
  14       */
  15      class LinkParser 
  16      {
  17  
  18          // list of tags that can be used to generate valid urls, and its
  19          // corresponding format
  20          var $urlRewriteTags = array(
  21                    '{blogname}' => '([_0-9a-zA-Z-]+)?',
  22                    '{blogid}' => '([0-9]+)?',
  23                    '{blogowner}' => '([_0-9a-zA-Z-]+)?', 
  24                    '{blogdomain}' => '([0-9a-zA-Z.-]+)?',
  25                    '{op}' => '([_0-9a-z-]+)?',
  26                    '{year}' => '([0-9]{4})?',
  27                    '{month}' => '([0-9]{2})?',
  28                    '{day}' => '([0-9]{2})?',
  29                    '{hours}' => '([0-9]{2})?',
  30                    '{minutes}' => '([0-9]{2})?',
  31                    '{postname}' => '([_0-9a-zA-Z.-]+)?',
  32                    '{postid}' => '([0-9]+)?',
  33                    '{catname}' => '([_0-9a-zA-Z-]+)?',
  34                    '{catid}' => '([0-9]+)?',
  35                    '{username}' => '([_0-9a-zA-Z-]+)?',
  36                    '{userid}' => '([0-9]+)?',
  37                    '{templatename}' => '([_0-9a-zA-Z.-]+)?',
  38                    '{resourceid}' => '([0-9]+)?',
  39                    '{resourcename}' => '([^/*\n\r]+)?',
  40                    '{albumid}' => '([0-9]+)?',
  41                    '{albumname}' => '([_0-9a-zA-Z -]*)?'
  42                );
  43  
  44          var $_linkFormat;
  45  
  46          function LinkParser( $linkFormat )
  47          {
  48              
  49  
  50              $this->_linkFormat = $linkFormat;
  51          }
  52  
  53          function parseLink( $url )
  54          {
  55              $uri = $url;
  56  
  57              //global $urlRewriteTags;
  58              $rewritecode = array_keys( $this->urlRewriteTags );
  59              $rewritereplace = array_values( $this->urlRewriteTags );
  60          
  61              // Turn the structure into a regular expression
  62              $matchre = str_replace( "$", "\$", $this->_linkFormat );
  63              $matchre = str_replace( $rewritecode, $rewritereplace, $matchre );
  64              $matchre = "^".$matchre;
  65          
  66              // Extract the key values from the uri:
  67              $count = preg_match("#$matchre#",$uri,$values);
  68              
  69              if( $count == 0 )
  70                  return false;
  71          
  72              // Extract the token names from the structure:
  73              preg_match_all("#\{(.+?)\}#", $this->_linkFormat, $tokens);
  74          
  75              $result = array();
  76              for($i = 0, $elements = count($tokens[1]); $i < $elements; $i++) {
  77                  $name = $tokens[1][$i];
  78                  if(isset($values[$i+1])){
  79                      $result["$name"] = $values[$i+1];
  80                  }
  81              }
  82              
  83              return $result;
  84          }
  85  
  86          function getValidTag($tagName){
  87              if(isset($this->urlRewriteTags[$tagName])){
  88                  return $this->urlRewriteTags[$tagName];
  89              }
  90              else{
  91                  return false;
  92              }
  93          }
  94      }
  95  ?>


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