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 include_once( 'lib/ezutils/classes/ezini.php' );
00042 include_once( 'kernel/classes/ezurlalias.php' );
00043
00044 class eZURLTranslator
00045 {
00046
00047
00048
00049 function eZURLTranslator()
00050 {
00051 }
00052
00053
00054
00055
00056 function &addURLAlias( $source, $destination, $isInternal = true )
00057 {
00058 $alias = new eZURLAlias( array() );
00059 $alias->setAttribute( 'source_url', $source );
00060 $alias->setAttribute( 'destination_url', $destination );
00061 $alias->setAttribute( 'is_internal', $isInternal );
00062 $alias->store();
00063 return $alias;
00064 }
00065
00066
00067
00068
00069
00070 function &translate( &$uri )
00071 {
00072 $newURI = false;
00073 $functionList = array();
00074 $ini =& eZINI::instance();
00075 if ( $ini->variable( 'URLTranslator', 'NodeTranslation' ) == 'enabled' )
00076 $functionList[] = 'translateNodeTree';
00077 foreach ( $functionList as $functionName )
00078 {
00079 $uriResult =& $this->$functionName( $uri );
00080 if ( is_string( $uriResult ) )
00081 {
00082 $newURI =& eZURI::instance( $uriResult );
00083 return $newURI;
00084 }
00085 }
00086 return $newURI;
00087 }
00088
00089
00090
00091
00092
00093 function translateNodeTree( &$uri )
00094 {
00095 $nodePathString = $uri->elements();
00096 $nodePathString = preg_replace( "/\.\w*$/", "", $nodePathString );
00097 $nodePathString = preg_replace( "#\/$#", "", $nodePathString );
00098 print( "try to translate: $nodePathString<br>" );
00099
00100 include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
00101
00102 $node = eZContentObjectTreeNode::fetchByCRC( $nodePathString );
00103
00104 $uriResult = false;
00105 if ( get_class( $node ) == 'ezcontentobjecttreenode' )
00106 {
00107 $uriResult= 'content/view/full/' . $node->attribute( 'node_id' ) . '/';
00108 }
00109 return $uriResult;
00110 }
00111
00112
00113
00114
00115 function &instance()
00116 {
00117 $instance =& $GLOBALS['eZURLTranslatorInstance'];
00118 if ( get_class( $instance ) != 'ezurltranslator' )
00119 {
00120 $instance = new eZURLTranslator();
00121 }
00122 return $instance;
00123 }
00124 }
00125
00126 ?>