|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing ezpLanguageSwitcherFunctionCollection class 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 class ezpLanguageSwitcherFunctionCollection 00012 { 00013 public function fetchUrlAlias( $nodeId = null, $path = null, $locale ) 00014 { 00015 if ( !$nodeId && !$path ) 00016 { 00017 return array( 'result' => false ); 00018 } 00019 00020 if ( empty( $locale ) || !is_string( $locale ) ) 00021 { 00022 return array( 'result' => false ); 00023 } 00024 00025 if ( is_numeric( $nodeId ) ) 00026 { 00027 $destinationElement = eZURLAliasML::fetchByAction( 'eznode', $nodeId, $locale, false ); 00028 } 00029 else if ( is_string( $path ) ) 00030 { 00031 $nodeId = eZURLAliasML::fetchNodeIDByPath( $path ); 00032 $destinationElement = eZURLAliasML::fetchByAction( 'eznode', $nodeId, $locale, false ); 00033 } 00034 00035 if ( empty( $destinationElement ) || ( !isset( $destinationElement[0] ) && !( $destinationElement[0] instanceof eZURLAliasML ) ) ) 00036 { 00037 // Either no translation exists for $locale or $path was not pointing to a node 00038 return array( 'result' => false ); 00039 } 00040 00041 $currentLanguageCodes = eZContentLanguage::prioritizedLanguageCodes(); 00042 array_unshift( $currentLanguageCodes, $locale ); 00043 $currentLanguageCodes = array_unique( $currentLanguageCodes ); 00044 $urlAlias = $destinationElement[0]->getPath( $locale, $currentLanguageCodes ); 00045 return array( 'result' => $urlAlias ); 00046 } 00047 } 00048 00049 ?>