Show
Ignore:
Timestamp:
07/05/08 12:04:10 (6 months ago)
Author:
llaumgui
Message:

Opérateur r_datetime, clône de datetime mais relatif (Aujourd'hui, Hier). Mise en place de translation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ez_publish/myutils/trunk/classes/myutilsfunctions.php

    r197 r212  
    2222 * ###################### END LICENSE BLOCK #################### 
    2323 * 
    24  * myUtilsFunctions : Enssemble de fonctions utilisée pour l'extension myUtils 
     24 * myUtilsFunctions : Enssemble de fonctions utilisée pour l'extension myUtils 
    2525 *  
    2626 * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
    27  * @version 1.0.1 
     27 * @version 1.0.2 
    2828 */ 
    2929 
     
    6363        static function cleanRSSDescription( &$str ) { 
    6464                 
    65                 $str = preg_replace( '#<img src="/(.+?)" alt="(.?)" />#is',  '', $str );         
     65                $str = preg_replace( '#<img src="/(.+?)" alt="(.?)" />#is',  '', $str ); 
    6666        } 
    6767 
     
    160160        /** 
    161161         * Converti un "path" en "path_array". 
    162          * Permet de retrouver un équivalent de $node.path_array là où il n'y a que 
     162         * Permet de retrouver un équivalent de $node.path_array là où il n'y a que 
    163163         * les informations path, par exemple dans le pagelayout ($module_result.path). 
    164164         *        
     
    209209                eZExecution::cleanExit(); 
    210210        } 
     211 
     212 
     213 
     214        /** 
     215         * Fonction datetime relative (Aujourd'hui, hier, etc..) 
     216         *  
     217         * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
     218         * @since 1.0.2 
     219         *  
     220         * @param integer $operatorValue 
     221         * @param string $class 
     222         * @param string $data 
     223         */ 
     224        static function relatedDatetime( &$operatorValue, $class, $data ) 
     225        { 
     226                $locale                 = eZLocale::instance(); 
     227                $dateFormat             = '%d-%m-%Y'; 
     228                $date                   = $locale->formatDateTimeType( $dateFormat, $operatorValue); 
     229                $today                  = $locale->formatDateTimeType( $dateFormat); 
     230                $yesterday              = $locale->formatDateTimeType( $dateFormat, time()-86400); 
     231 
     232                if ( $class === null ) 
     233                { 
     234                        return; 
     235                } 
     236                 
     237                if ( $class == 'custom' ) 
     238                { 
     239                        $classFormat    = $data; 
     240                } 
     241                else 
     242                { 
     243                        $dtINI          = eZINI::instance( 'datetime.ini' ); 
     244                        $formats        = $dtINI->variable( 'ClassSettings', 'Formats' ); 
     245                        if ( array_key_exists( $class, $formats ) ) 
     246                        { 
     247                                $classFormat    = $formats[$class]; 
     248                        } 
     249                        else 
     250                        { 
     251                                $tpl->error( $operatorName, "DateTime class '$class' is not defined", $placement ); 
     252                                return; 
     253            } 
     254                } 
     255 
     256                if ( $date == $today ) 
     257                { 
     258                        $classFormat = preg_replace( '#\$\$(.+?)\$\$#',  ezi18n( 'myutils/date', 'Today' ), $classFormat ); 
     259                } 
     260                else if ( $date == $yesterday ) 
     261                { 
     262                        $classFormat = preg_replace( '#\$\$(.+?)\$\$#',  ezi18n( 'myutils/date', 'Yesterday' ), $classFormat ); 
     263                } 
     264                 
     265                $operatorValue  = $locale->formatDateTimeType(  str_replace('$$', '', $classFormat ), $operatorValue  ); 
     266        } 
    211267         
    212268} // EOC