Show
Ignore:
Timestamp:
02/20/08 15:08:45 (9 months ago)
Author:
llaumgui
Message:

Ajoute d'opérateur

Files:
1 modified

Legend:

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

    r98 r99  
    4040        { 
    4141                /* Opérateurs */ 
    42                 $this->Operators = array(       'redirect', 
     42                $this->Operators = array(       'path_to_path_array', 
     43                                                                        'redirect', 
     44                                                                        'str_ireplace', 
     45                                                                        'str_replace'                                                                    
    4346                                                                 ); 
    4447        } 
     
    5861        function namedParameterList() 
    5962        { 
    60                  return array(  'redirect'                              => array(       'url' => array( 'url'   => 'string', 'required' => true, 'default' => '' ), 
    61                                                                                                                         'type' => array( 'type' => 'integer', 'required' => false, 'default' => '301' ) 
    62                                                                                                                 ) 
     63                 return array(  'redirect'                                              => array( 
     64                                                                'url'                   => array( 'url'         => 'string', 'required' => true, 'default' => ''  ), 
     65                                                                'type'                  => array( 'type' => 'integer', 'required' => false, 'default' => '301' ) 
     66                                                                                                        ), 
     67                                                                                                         
     68                                                'path_to_path_array'                    => array( 
     69                                                                'path'                  => array( 'url'         => 'array', 'required' => true, 'default' => ''  ), 
     70                                                                                                        ), 
     71                 
     72                                                'str_ireplace'                                  => array(        
     73                                                                'search'                => array( 'type' => 'string', 'required' => true, 'default' => '' ), 
     74                                                                'replace'               => array( 'type' => 'string', 'required' => true, 'default' => '' ), 
     75                                                                'subject'               => array( 'type' => 'string', 'required' => true, 'default' => '' ) 
     76                                                                                                        ), 
     77 
     78                                                'str_replace'                                   => array(        
     79                                                                'search'                => array( 'type' => 'string', 'required' => true, 'default' => '' ), 
     80                                                                'replace'               => array( 'type' => 'string', 'required' => true, 'default' => '' ), 
     81                                                                'subject'               => array( 'type' => 'string', 'required' => true, 'default' => '' ) 
     82                                                                                                                ), 
    6383                                        ); 
    6484        } 
     85 
     86 
    6587 
    6688        function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, 
    6789                          &$currentNamespace, &$operatorValue, &$namedParameters ) 
    6890        { 
    69                  
    7091            switch ( $operatorName ) 
    7192            { 
    7293                case 'redirect': 
    73                         $operatorValue = $this->redirect(  $namedParameters['url'], $namedParameters['type'] ); 
     94                        $operatorValue = $this->redirect(       $namedParameters['url'], 
     95                                                                                                $namedParameters['type'] ); 
     96                        break; 
     97                case 'path_to_path_array': 
     98                        $operatorValue = $this->path2PathArray(         $namedParameters['path'] ); 
     99                        break; 
     100                        case 'str_ireplace': 
     101                        $operatorValue = $this->strIReplace(    $namedParameters['search'], 
     102                                                                                                        $namedParameters['replace'], 
     103                                                                                                        $namedParameters['subject'] ); 
     104                        break; 
     105                        case 'str_replace': 
     106                        $operatorValue = $this->strReplace(     $namedParameters['search'], 
     107                                                                                                $namedParameters['replace'], 
     108                                                                                                $namedParameters['subject'] ); 
    74109                        break; 
    75110                } 
     
    77112 
    78113         
    79  
    80         /** 
    81          * Redirection par header. 
    82          * 
     114        /** ##################################################################### 
     115         *  
     116         * 
     117         * 
     118         * ###################################################################### */ 
     119        /** 
     120         * Converti un "path" en "path_array". 
     121         * Permet de retrouver un équivalent de $node.path_array là où il n'y a que 
     122         * les informations path, par exemple dans le pagelayout ($module_result.path). 
     123         *        
     124         * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
     125         * @since 1.0 
     126         * 
     127         * @param array $path 
     128         * @return array 
     129         */ 
     130        function path2PathArray( $path ) 
     131        { 
     132                $path_array     = array(); 
     133                foreach ( $path as $p ) 
     134                { 
     135                        $path_array[]=$p['node_id']; 
     136                } 
     137                return $path_array; 
     138        } 
     139 
     140 
     141 
     142        /** 
     143         * Fonction header() de php mise en forme pour faire des redirections. 
     144         * 
     145         * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
     146         * @since 1.0 
     147         *        
    83148         * @param string $url URL de redirection 
    84149         * @param integer $type Type de redirection 
     
    97162 
    98163 
     164 
     165        /** 
     166         * Fonction str_replace de php. 
     167         * 
     168         * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
     169         * @since 1.0 
     170         * 
     171         * @param string $search 
     172         * @param string $replace 
     173         * @param string $subject 
     174         * @return string 
     175         */ 
     176        function strIReplace( $search, $replace, $subject ) 
     177        { 
     178                return str_replace( $search, $replace, $subject ); 
     179        } 
     180 
     181 
     182 
     183        /** 
     184         * Fonction str_ireplace de php. 
     185         * 
     186         * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
     187         * @since 1.0 
     188         * 
     189         * @param string $search 
     190         * @param string $replace 
     191         * @param string $subject 
     192         * @return string 
     193         */ 
     194        function strReplace( $search, $replace, $subject ) 
     195        { 
     196                return str_ireplace( $search, $replace, $subject ); 
     197        }        
     198 
     199 
    99200} // EOC 
    100201