[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/ -> ezurltranslator.php (source)

   1  <?php
   2  //
   3  // Definition of eZURLTranslator class
   4  //
   5  // Created on: <25-Nov-2002 09:49:11 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezurltranslator.php
  30  */
  31  
  32  /*!
  33    \class eZURLTranslator ezurltranslator.php
  34    \brief Translation requested URLs into new URLs internally.
  35  
  36    Performs translation on supplied urls, currently only does tree node translation.
  37  */
  38  
  39  include_once ( 'lib/ezutils/classes/ezini.php' );
  40  include_once ( 'kernel/classes/ezurlalias.php' );
  41  
  42  class eZURLTranslator
  43  {
  44      /*!
  45       Constructor
  46      */
  47      function eZURLTranslator()
  48      {
  49      }
  50  
  51      /*!
  52       Adds a new URL alias.
  53      */
  54      function &addURLAlias( $source, $destination, $isInternal = true )
  55      {
  56          $alias = new eZURLAlias( array() );
  57          $alias->setAttribute( 'source_url', $source );
  58          $alias->setAttribute( 'destination_url', $destination );
  59          $alias->setAttribute( 'is_internal', $isInternal );
  60          $alias->store();
  61          return $alias;
  62      }
  63  
  64      /*!
  65       Translates the url found in the object \a $uri and returns the corrected url object.
  66       \return false if no url translation was done.
  67      */
  68      function &translate( &$uri )
  69      {
  70          $newURI = false;
  71          $functionList = array();
  72          $ini =& eZINI::instance();
  73          if ( $ini->variable( 'URLTranslator', 'NodeTranslation' ) == 'enabled' )
  74              $functionList[] = 'translateNodeTree';
  75          foreach ( $functionList as $functionName )
  76          {
  77              $uriResult =& $this->$functionName( $uri );
  78              if ( is_string( $uriResult ) )
  79              {
  80                  $newURI =& eZURI::instance( $uriResult );
  81                  return $newURI;
  82              }
  83          }
  84          return $newURI;
  85      }
  86  
  87      /*!
  88       Tries to find a node path which matches the uri \a $uri and returns a new uri string which views that node.
  89       \note This code should get a separate class/package.
  90      */
  91      function translateNodeTree( &$uri )
  92      {
  93          $nodePathString = $uri->elements();
  94          $nodePathString = preg_replace( "/\.\w*$/", "", $nodePathString );
  95          $nodePathString = preg_replace( "#\/$#", "", $nodePathString );
  96          print( "try to translate: $nodePathString<br>" );
  97  
  98          include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  99  
 100          $node = eZContentObjectTreeNode::fetchByCRC( $nodePathString );
 101  
 102          $uriResult = false;
 103          if ( get_class( $node ) == 'ezcontentobjecttreenode' )
 104          {
 105              $uriResult= 'content/view/full/' . $node->attribute( 'node_id' ) . '/';
 106          }
 107          return $uriResult;
 108      }
 109  
 110      /*!
 111       \return The only instance of the translator.
 112      */
 113      function &instance()
 114      {
 115          $instance =& $GLOBALS['eZURLTranslatorInstance'];
 116          if ( get_class( $instance ) != 'ezurltranslator' )
 117          {
 118              $instance = new eZURLTranslator();
 119          }
 120          return $instance;
 121      }
 122  }
 123  
 124  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7