root/ez_publish/myutils/trunk/classes/myutilsfunctions.php

Revision 316, 3.8 KB (checked in by llaumgui, 5 weeks ago)

Disparition des fonctions planet dans MyUtils?

Line 
1<?php
2//
3// Definition of myUtilsFunctions class
4//
5// Created on: <01-Sep-2008 19:00:00 bf>
6//
7// SOFTWARE NAME: MyUtils
8// SOFTWARE RELEASE: 1.0
9// BUILD VERSION:
10// COPYRIGHT NOTICE: Copyright (c) 2008 Guillaume Kulakowski and contributors
11// SOFTWARE LICENSE: GNU General Public License v2.0
12// NOTICE: >
13//   This program is free software; you can redistribute it and/or
14//   modify it under the terms of version 2.0  of the GNU General
15//   Public License as published by the Free Software Foundation.
16//
17//   This program is distributed in the hope that it will be useful,
18//   but WITHOUT ANY WARRANTY; without even the implied warranty of
19//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20//   GNU General Public License for more details.
21//
22//   You should have received a copy of version 2.0 of the GNU General
23//   Public License along with this program; if not, write to the Free
24//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25//   MA 02110-1301, USA.
26//
27//
28
29
30/*! \file myutilsfunctions.php
31*/
32
33/*!
34  \class myUtilsFunctions myutilsfunctions.php
35  \brief Ensemble de fonctions utilisée pour l'extension myUtils
36 */
37class myUtilsFunctions
38{
39
40    /*!
41     Converti un "path" en "path_array".
42     Permet de retrouver un équivalent de $node.path_array là où il n'y a que
43     les informations path, par exemple dans le pagelayout ($module_result.path).
44
45     \param $path array
46     \return array
47     */
48    static function path2PathArray( $path )
49    {
50        $path_array = array();
51        if ( !is_array( $path ) )
52        {
53            return array();
54        }
55
56        foreach ( $path as $p )
57        {
58            $path_array[]=$p['node_id'];
59        }
60        return $path_array;
61    }
62
63
64
65    /*!
66     Fonction header() de php mise en forme pour faire des redirections.
67
68     \param $url string URL de redirection
69     \param $type integer Type de redirection
70     */
71    static function redirect( $url, $type=0 )
72    {
73        switch( $type )
74        {
75            case 301:
76                header("HTTP/1.1 301 Moved Permanently");
77                break;
78            case 307:
79                header("HTTP/1.1 307 Temporary Redirect");
80                break;
81        }
82        header ('location: '.$url);
83        eZExecution::cleanExit();
84    }
85
86
87
88    /*!
89     Fonction datetime relative (Aujourd'hui, hier, etc..)
90
91     \param $operatorValue integer
92     \param $class string
93     \param $data string
94     */
95    static function relatedDatetime( &$operatorValue, $class, $data )
96    {
97        $locale = eZLocale::instance();
98        $dateFormat = '%d-%m-%Y';
99        $date = $locale->formatDateTimeType( $dateFormat, $operatorValue);
100        $today = $locale->formatDateTimeType( $dateFormat);
101        $yesterday = $locale->formatDateTimeType( $dateFormat, time()-86400);
102
103        if ( $class === null )
104        {
105            return;
106        }
107
108        if ( $class == 'custom' )
109        {
110            $classFormat = $data;
111        }
112        else
113        {
114            $dtINI = eZINI::instance( 'datetime.ini' );
115            $formats = $dtINI->variable( 'ClassSettings', 'Formats' );
116            if ( array_key_exists( $class, $formats ) )
117            {
118                $classFormat = $formats[$class];
119            }
120            else
121            {
122                $tpl->error( $operatorName, "DateTime class '$class' is not defined", $placement );
123                return;
124            }
125        }
126
127        if ( $date == $today )
128        {
129            $classFormat = preg_replace( '#\$\$(.+?)\$\$#'ezi18n( 'myutils/date', 'Today' ), $classFormat );
130        }
131        else if ( $date == $yesterday )
132        {
133            $classFormat = preg_replace( '#\$\$(.+?)\$\$#'ezi18n( 'myutils/date', 'Yesterday' ), $classFormat );
134        }
135
136        $operatorValue = $locale->formatDateTimeTypestr_replace('$$', '', $classFormat ), $operatorValue  );
137    }
138
139} // EOC
140
141?>
Note: See TracBrowser for help on using the browser.