|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZi18nOperator class 00004 // 00005 // Created on: <15-Aug-2006 12:15:07 vd> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 //!! eZKernel 00032 //! The class eZAlphabetOperator does 00033 /*! 00034 00035 */ 00036 00037 00038 class eZAlphabetOperator 00039 { 00040 /*! 00041 */ 00042 function eZAlphabetOperator( $alphabet = 'alphabet' ) 00043 { 00044 $this->Operators = array( $alphabet ); 00045 $this->Alphabet = $alphabet; 00046 } 00047 00048 /*! 00049 Returns the operators in this class. 00050 */ 00051 function operatorList() 00052 { 00053 return $this->Operators; 00054 } 00055 00056 /*! 00057 \return true to tell the template engine that the parameter list exists per operator type. 00058 */ 00059 function namedParameterPerOperator() 00060 { 00061 return true; 00062 } 00063 00064 /*! 00065 \reimp 00066 */ 00067 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters ) 00068 { 00069 switch ( $operatorName ) 00070 { 00071 case $this->Alphabet: 00072 { 00073 $alphabet = eZAlphabetOperator::fetchAlphabet(); 00074 $value = $alphabet; 00075 } break; 00076 } 00077 } 00078 00079 /*! 00080 Static 00081 Returns alphabet. 00082 */ 00083 static function fetchAlphabet() 00084 { 00085 //include_once( "lib/ezutils/classes/ezini.php" ); 00086 $contentINI = eZINI::instance( 'content.ini' ); 00087 00088 $alphabetRangeList = $contentINI->hasVariable( 'AlphabeticalFilterSettings', 'AlphabetList' ) 00089 ? $contentINI->variable( 'AlphabeticalFilterSettings', 'AlphabetList' ) 00090 : array(); 00091 00092 $alphabetFromArray = $contentINI->hasVariable( 'AlphabeticalFilterSettings', 'ContentFilterList' ) 00093 ? $contentINI->variable( 'AlphabeticalFilterSettings', 'ContentFilterList' ) 00094 : array( 'default' ); 00095 00096 // If alphabet list is empty 00097 if ( count( $alphabetFromArray ) == 0 ) 00098 return false; 00099 00100 $alphabetRangeList = array_merge( $alphabetRangeList, array( 'default' => '97-122' ) ); 00101 $alphabet = array(); 00102 foreach ( $alphabetFromArray as $alphabetFrom ) 00103 { 00104 // If $alphabetFrom exists in range array $alphabetRangeList 00105 if ( isset( $alphabetRangeList[$alphabetFrom] ) ) 00106 { 00107 $lettersArray = explode( ',', $alphabetRangeList[$alphabetFrom] ); 00108 foreach ( $lettersArray as $letter ) 00109 { 00110 $rangeArray = explode( '-', $letter ); 00111 if ( isset( $rangeArray[1] ) ) 00112 { 00113 $alphabet = array_merge( $alphabet, range( trim( $rangeArray[0] ), trim( $rangeArray[1] ) ) ); 00114 } 00115 else 00116 $alphabet = array_merge( $alphabet, array( trim( $letter ) ) ); 00117 } 00118 } 00119 } 00120 // Get alphabet by default (eng-GB) 00121 if ( count( $alphabet ) == 0 ) 00122 { 00123 $rangeArray = explode( '-', $alphabetRangeList['default'] ); 00124 $alphabet = range( $rangeArray[0], $rangeArray[1] ); 00125 } 00126 $resAlphabet = array(); 00127 $i18nINI = eZINI::instance( 'i18n.ini' ); 00128 $charset = $i18nINI->variable( 'CharacterSettings', 'Charset' ); 00129 00130 //include_once( 'lib/ezi18n/classes/eztextcodec.php' ); 00131 $codec = eZTextCodec::instance( 'utf-8', $charset ); 00132 00133 //include_once( "lib/ezi18n/classes/ezutf8codec.php" ); 00134 $utf8_codec = eZUTF8Codec::instance(); 00135 // Convert all letters of alphabet from unicode to utf-8 and from utf-8 to current locale 00136 foreach ( $alphabet as $item ) 00137 { 00138 $utf8Letter = $utf8_codec->toUtf8( $item ); 00139 $resAlphabet[] = $codec ? $codec->convertString( $utf8Letter ) : $utf8Letter; 00140 } 00141 00142 return $resAlphabet; 00143 } 00144 00145 /// \privatesection 00146 public $Operators; 00147 public $Alphabet; 00148 }; 00149 00150 ?>