/
ezpLanguageSwitcherFunctionCollection.php
48 lines (42 loc) · 1.56 KB
/
ezpLanguageSwitcherFunctionCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* File containing ezpLanguageSwitcherFunctionCollection class
*
* @copyright Copyright (C) 1999-2009 eZ Systems AS. All rights reserved.
* @license http://ez.no/licenses/gnu_gpl GNU GPLv2
*
*/
class ezpLanguageSwitcherFunctionCollection
{
public function fetchUrlAlias( $nodeId = null, $path = null, $locale )
{
if ( !$nodeId && !$path )
{
return array( 'result' => false );
}
if ( empty( $locale ) || !is_string( $locale ) )
{
return array( 'result' => false );
}
if ( is_numeric( $nodeId ) )
{
$destinationElement = eZURLAliasML::fetchByAction( 'eznode', $nodeId, $locale, false );
}
else if ( is_string( $path ) )
{
$nodeId = eZURLAliasML::fetchNodeIDByPath( $path );
$destinationElement = eZURLAliasML::fetchByAction( 'eznode', $nodeId, $locale, false );
}
if ( empty( $destinationElement ) || ( !isset( $destinationElement[0] ) && !( $destinationElement[0] instanceof eZURLAliasML ) ) )
{
// Either no translation exists for $locale or $path was not pointing to a node
return array( 'result' => false );
}
$currentLanguageCodes = eZContentLanguage::prioritizedLanguageCodes();
array_unshift( $currentLanguageCodes, $locale );
$currentLanguageCodes = array_unique( $currentLanguageCodes );
$urlAlias = $destinationElement[0]->getPath( $locale, $currentLanguageCodes );
return array( 'result' => $urlAlias );
}
}
?>