Changeset 212

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

Location:
ez_publish/myutils/trunk
Files:
5 added
4 modified

Legend:

Unmodified
Added
Removed
  • ez_publish/myutils/trunk/autoloads/eztemplateautoload.php

    r199 r212  
    4040                'path_to_path_array', 
    4141                'redirect', 
     42                'r_datetime', 
    4243                'str_ireplace', 
    4344                'str_replace' 
  • 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 
  • ez_publish/myutils/trunk/classes/myutilstemplateoperators.php

    r199 r212  
    3939        function __construct() 
    4040        { 
    41                 /* Opérateurs */ 
     41                /* Opérateurs */ 
    4242                $this->Operators = array(       'get_siteaccess', 
    4343                                                                        'gmdate', 
     
    4646                                                                        'path_to_path_array', 
    4747                                                                        'redirect', 
     48                                                                        'r_datetime', 
    4849                                                                        'str_ireplace', 
    4950                                                                        'str_replace' 
     
    7576 
    7677                                                'json_decode'                                   => array( 
    77                                                                 'json'                  => array(       'type' => 'string',     'required' => true, 'default' => '' ), 
    78                                                                 'assoc'                 => array(       'type' => 'bool',       'required' => false, 'default' => true ) 
     78                                                                'json'                  => array( 'type' => 'string',   'required' => true, 'default' => '' ), 
     79                                                                'assoc'                 => array( 'type' => 'bool',     'required' => false, 'default' => true ) 
    7980                                                                                                        ),                                               
    8081                                                                                                         
    8182                                                'path_to_path_array'                    => array( 
    82                                                                 'path'                  => array( 'type'        => 'array', 'required' => true, 'default' => ''  ), 
     83                                                                'path'                  => array( 'type' => 'array', 'required' => true, 'default' => ''  ), 
    8384                                                                                                        ), 
    8485 
    8586                                                'redirect'                                              => array( 
    86                                                                 'url'                   => array( 'type'        => 'string', 'required' => true, 'default' => ''  ), 
     87                                                                'url'                   => array( 'type' => 'string', 'required' => true, 'default' => ''  ), 
    8788                                                                'type'                  => array( 'type' => 'integer', 'required' => false, 'default' => '301' ) 
     89                                                                                                        ), 
     90                                                                                                         
     91                                                'r_datetime'                                    => array( 
     92                                                                'class'                 => array( 'type' => 'string', 'required' => true, 'default' => ''  ), 
     93                                                                'data'                  => array( 'type' => 'string', 'required' => false, 'default' => '' ) 
    8894                                                                                                        ), 
    8995                         
     
    132138                        $operatorValue = myUtilsFunctions::redirect( $namedParameters['url'], $namedParameters['type'] ); 
    133139                        break; 
     140                         
     141                        case 'r_datetime': 
     142                        myUtilsFunctions::relatedDatetime(      $operatorValue, 
     143                                                                                                $namedParameters['class'], 
     144                                                                                                $namedParameters['data'] ); 
     145                        break; 
    134146 
    135147                        case 'str_ireplace': 
  • ez_publish/myutils/trunk/settings/site.ini.append.php

    r104 r212  
    1414DefaultVersion=2.0 
    1515 
     16[RegionalSettings] 
     17TranslationExtensions[]=myutils 
     18 
    1619*/ ?>