Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 115 | Revision 1375 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 115 Revision 1371
Zeile 4... Zeile 4...
4
    *
4
    *
5
    -------------------------------------------------------------
5
    -------------------------------------------------------------
6
    * File:     modifier.money_format.php
6
    * File:     modifier.money_format.php
7
    * Type:     modifier
7
    * Type:     modifier
8
    * Name:     money_format
8
    * Name:     money_format
9
    * Version:  1.0
9
    * Version:  1.1
10
    * Date:     Feb 8th, 2003
10
    * Date:     Oct 12th, 2022
11
    * Purpose:  pass value to PHP money_format() and return result
11
    * Purpose:  pass value to PHP money_format() and return result
12
    * Install:  Drop into the plugin directory.
12
    * Install:  Drop into the plugin directory.
13
    * Author:   Michael L. Fladischer <mfladischer@abis.co.at>
13
    * Author:   Michael L. Fladischer <mfladischer@abis.co.at>
-
 
14
    * Author:   Lars Tiefland Weban UG <l.tiefland@webn.de>
14
    *
15
    *
15
    -------------------------------------------------------------
16
    -------------------------------------------------------------
16
    */
17
    */
17
    function smarty_modifier_money_format_red( $string, $places = 2, $locale =
-
 
18
        "de_DE", $onlySymbol = false, $incSymbol = true, $shortSymbol = false )
18
    function smarty_modifier_money_format_red( $string, $places = 2, $locale = "de_DE", $onlySymbol = false, $incSymbol = true, $shortSymbol = false )
19
    {
19
    {
20
        if ( !$locale )
20
        if ( !$locale )
21
        {
21
        {
22
            $locale = "de_DE";
22
            $locale = "de_DE";
23
        }
23
        }
24
        setlocale( LC_MONETARY, $locale );
24
        if ( $_SESSION["charset"] == "utf8" && !str_ends_with( strtoupper( $locale ), ".UTF-8" ) )
25
        if ( $onlySymbol === true )
-
 
26
        {
25
        {
27
            $erg = money_format( "%.0i", $string );
-
 
28
            preg_match_all( "/[A-Z]/", $erg, $erg );
-
 
29
            $erg = implode( "", $erg[0] );
26
            $locale .= ".UTF-8";
30
        }
27
        }
-
 
28
 
-
 
29
        $fmt = new NumberFormatter( $locale, NumberFormatter::CURRENCY );
31
        else
30
        if ( $incSymbol === false )
32
        {
31
        {
33
            if ( $incSymbol === true )
32
            $fmt->setPattern( "#,##0.00" );
34
            {
-
 
35
                $erg = money_format( "%.{$places}i", $string );
-
 
36
            }
-
 
37
            else
-
 
38
            {
-
 
39
                $erg = money_format( "%!.{$places}i", $string );
-
 
40
            }
-
 
41
        }
33
        }
42
        if ( $shortSymbol === true || $onlySymbol === true )
34
        if ( $shortSymbol === false )
43
        {
35
        {
44
            preg_match_all( "/[A-Z]/", $erg, $symArr );
-
 
45
            $symbol = implode( "", $symArr[0] );
-
 
46
            switch ( $symbol )
-
 
47
            {
-
 
48
                case "EUR":
-
 
49
                    $erg = str_replace( "EUR", "&euro;", $erg );
36
            $fmt->setSymbol( NumberFormatter::CURRENCY_SYMBOL, NumberFormatter::CURRENCY_CODE );
50
                    break;
-
 
51
                case "USD":
-
 
52
                    $erg = str_replace( "USD", "$", $erg );
-
 
53
            }
-
 
54
        }
37
        }
-
 
38
        $fmt->setAttribute( NumberFormatter::FRACTION_DIGITS, $places );
55
        return $erg;
39
        return $fmt->format( $string );
56
    }
40
    }
-
 
41
 
57
    /* vim: set expandtab: */
42
    /* vim: set expandtab: */
58
?>
-
 
59
43