00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class eZURI
00047 {
00048
00049
00050
00051 function eZURI( $uri )
00052 {
00053 $this->setURIString( $uri );
00054 }
00055
00056
00057
00058
00059
00060 function setURIString( $uri, $fullInitialize = true )
00061 {
00062 if ( strlen( $uri ) > 0 and
00063 $uri[0] == '/' )
00064 $uri = substr( $uri, 1 );
00065
00066 $this->URI = $uri;
00067 $this->URIArray = explode( '/', $uri );
00068 $this->Index = 0;
00069
00070 if ( $fullInitialize )
00071 {
00072 $this->OriginalURI = $uri;
00073 $this->UserArray = array();
00074
00075 include_once( 'lib/ezutils/classes/ezini.php' );
00076 $ini =& eZINI::instance( 'template.ini' );
00077
00078 if ( $ini->variable( 'ControlSettings', 'OldStyleUserVariables' ) == 'enabled' )
00079 {
00080 foreach( array_keys( $this->URIArray ) as $key )
00081 {
00082 if ( isset( $this->URIArray[$key] ) && preg_match( "(^[\(][a-zA-Z0-9_]+[\)])", $this->URIArray[$key] ) )
00083 {
00084 $this->UserArray[substr( $this->URIArray[$key], 1, strlen( $this->URIArray[$key] ) - 2 )] = $this->URIArray[$key+1];
00085 unset( $this->URIArray[$key] );
00086 unset( $this->URIArray[$key+1] );
00087 }
00088 }
00089 }
00090 else
00091 {
00092 unset( $paramName );
00093 unset( $paramValue );
00094 foreach( array_keys( $this->URIArray ) as $key )
00095 {
00096 if ( isset( $this->URIArray[$key] ) )
00097 {
00098 if ( preg_match( "/^[\(][a-zA-Z0-9_]+[\)]/", $this->URIArray[$key] ) )
00099 {
00100 if ( isset( $paramName ) and isset( $paramValue ) )
00101 {
00102 $this->UserArray[ $paramName ] = $paramValue;
00103 unset( $paramName );
00104 unset( $paramValue );
00105 }
00106 $paramName = substr( $this->URIArray[$key], 1, strlen( $this->URIArray[$key] ) - 2 );
00107 if ( isset( $this->URIArray[$key+1] ) )
00108 {
00109 $this->UserArray[ $paramName ] = $this->URIArray[$key+1];
00110 unset( $this->URIArray[$key+1] );
00111 }
00112 else
00113 $this->UserArray[ $paramName ] = "";
00114 unset( $this->URIArray[$key] );
00115 }
00116 else
00117 {
00118 if ( isset( $paramName ) )
00119 {
00120 if ( !empty( $this->URIArray[$key] ) )
00121 $this->UserArray[ $paramName ] .= '/' . $this->URIArray[$key];
00122 unset( $this->URIArray[$key] );
00123 }
00124 }
00125 }
00126 }
00127 }
00128
00129
00130 $this->URI = implode( '/', $this->URIArray );
00131
00132 include_once( 'lib/ezutils/classes/ezini.php' );
00133 $ini =& eZINI::instance( 'template.ini' );
00134 if ( $ini->variable( 'ControlSettings', 'AllowUserVariables' ) == 'false' )
00135 {
00136 $this->UserArray = array();
00137 }
00138
00139 $this->convertFilterString();
00140 }
00141 }
00142
00143
00144
00145
00146
00147 function &uriString( $withLeadingSlash = false )
00148 {
00149 $uri = $this->URI;
00150 if ( $withLeadingSlash )
00151 $uri = "/$uri";
00152 return $uri;
00153 }
00154
00155
00156
00157
00158
00159 function &originalURIString( $withLeadingSlash = false )
00160 {
00161 $uri = $this->OriginalURI;
00162 if ( $withLeadingSlash )
00163 $uri = "/$uri";
00164 return $uri;
00165 }
00166
00167
00168
00169
00170 function isEmpty()
00171 {
00172 return $this->URI == '' or $this->URI == '/';
00173 }
00174
00175
00176
00177
00178
00179 function &element( $index = 0, $relative = true )
00180 {
00181 $pos = $index;
00182 if ( $relative )
00183 $pos += $this->Index;
00184 if ( isset( $this->URIArray[$pos] ) )
00185 return $this->URIArray[$pos];
00186 $ret = null;
00187 return $ret;
00188 }
00189
00190
00191
00192
00193
00194 function &elements( $as_text = true )
00195 {
00196 $elements = array_slice( $this->URIArray, $this->Index );
00197 if ( $as_text )
00198 {
00199 $retValue = implode( '/', $elements );
00200 return $retValue;
00201 }
00202 else
00203 return $elements;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 function convertFilterString()
00213 {
00214 foreach ( array_keys( $this->UserArray ) as $paramKey )
00215 {
00216 if ( $paramKey == 'namefilter' )
00217 {
00218 $char =& $this->UserArray[$paramKey];
00219 $char = urldecode( $char );
00220
00221 include_once( 'lib/ezi18n/classes/eztextcodec.php' );
00222 $codec =& eZTextCodec::instance( 'utf-8', false );
00223 if ( $codec )
00224 $char = $codec->convertString( $char );
00225 }
00226 }
00227 }
00228
00229
00230
00231
00232 function userParameters()
00233 {
00234 return $this->UserArray;
00235 }
00236
00237
00238
00239
00240 function toBeginning()
00241 {
00242 $this->Index = 0;
00243 }
00244
00245
00246
00247
00248 function toEnd()
00249 {
00250 $this->Index = count( $this->URIArray );
00251 }
00252
00253
00254
00255
00256 function increase( $num = 1 )
00257 {
00258 $this->Index += $num;
00259 if ( $this->Index < 0 )
00260 $this->Index = 0;
00261 }
00262
00263
00264
00265
00266
00267 function dropBase()
00268 {
00269 $elements = array_slice( $this->URIArray, $this->Index );
00270 $this->URIArray = $elements;
00271 $this->URI = implode( '/', $this->URIArray );
00272 $uri = $this->URI;
00273 foreach ( $this->UserArray as $name => $value )
00274 {
00275 $uri .= '/(' . $name . ')/' . $value;
00276 }
00277 $this->OriginalURI = $uri;
00278 $this->Index = 0;
00279 }
00280
00281
00282
00283
00284 function &index()
00285 {
00286 return $this->Index;
00287 }
00288
00289
00290
00291
00292
00293 function &base( $as_text = true )
00294 {
00295 $elements = array_slice( $this->URIArray, 0, $this->Index );
00296 if ( $as_text )
00297 {
00298 $baseAsText = '/' . implode( '/', $elements );
00299 return $baseAsText;
00300 }
00301 else
00302 return $elements;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312 function matchBase( &$uri )
00313 {
00314 if ( get_class( $uri ) != 'ezuri' )
00315 return false;
00316 if ( count( $this->URIArray ) == 0 or
00317 count( $uri->URIArray ) == 0 )
00318 return false;
00319 for ( $i = 0; $i < count( $this->URIArray ); ++$i )
00320 {
00321 if ( $this->URIArray[$i] != $uri->URIArray[$i] )
00322 return false;
00323 }
00324 return true;
00325 }
00326
00327
00328
00329
00330 function attributes()
00331 {
00332 return array( 'element',
00333 'base',
00334 'tail',
00335 'index',
00336 'uri',
00337 'original_uri' );
00338 }
00339
00340
00341
00342
00343 function hasAttribute( $attr )
00344 {
00345 return in_array( $attr, $this->attributes() );
00346 }
00347
00348
00349
00350
00351 function &attribute( $attr )
00352 {
00353 switch ( $attr )
00354 {
00355 case 'element':
00356 $retValue =& $this->element();
00357 break;
00358 case 'tail':
00359 $retValue =& $this->elements();
00360 break;
00361 case 'base':
00362 $retValue =& $this->base();
00363 break;
00364 case 'index':
00365 $retValue =& $this->index();
00366 break;
00367 case 'uri':
00368 $retValue =& $this->uriString();
00369 break;
00370 case 'original_uri':
00371 $retValue =& $this->originalURIString();
00372 break;
00373 default:
00374 {
00375 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZURI::attribute' );
00376 $retValue = null;
00377 } break;
00378 }
00379 return $retValue;
00380 }
00381
00382
00383
00384
00385 function &instance( $uri = false )
00386 {
00387 $uri_obj =& $GLOBALS['eZURIInstance'];
00388 if ( $uri )
00389 {
00390 $uri_obj = new eZURI( $uri );
00391 }
00392 if ( get_class( $uri_obj ) != 'ezuri' )
00393 {
00394 $uri_obj = new eZURI( $uri );
00395 }
00396 return $uri_obj;
00397 }
00398
00399
00400
00401
00402
00403 function transformURI( &$href, $ignoreIndexDir = false, $serverURL = 'relative' )
00404 {
00405 if ( preg_match( "#^[a-zA-Z0-9]+:#", $href ) || substr( $href, 0, 2 ) == '//' )
00406 return false;
00407
00408 if ( strlen( $href ) == 0 )
00409 $href = '/';
00410 else if ( $href[0] == '#' )
00411 {
00412 $href = htmlspecialchars( $href );
00413 return true;
00414 }
00415 else if ( $href[0] != '/' )
00416 {
00417 $href = '/' . $href;
00418 }
00419
00420 include_once( 'lib/ezutils/classes/ezsys.php' );
00421 $sys =& eZSys::instance();
00422 $dir = !$ignoreIndexDir ? $sys->indexDir() : $sys->wwwDir();
00423 $serverURL = $serverURL === 'full' ? $sys->serverURL() : '' ;
00424 $href = $serverURL . $dir . $href;
00425 if ( !$ignoreIndexDir )
00426 {
00427 $href = preg_replace( "#^(//)#", "/", $href );
00428 $href = preg_replace( "#(^.*)(/+)$#", "\$1", $href );
00429 }
00430 $href = htmlspecialchars( $href );
00431
00432 if ( $href == "" )
00433 $href = "/";
00434
00435 return true;
00436 }
00437
00438
00439 var $URI;
00440
00441 var $URIArray;
00442
00443 var $Index;
00444
00445 var $UserArray;
00446 };
00447
00448 ?>