Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
3 lars 1
<?php
2
    /*
3
    * Smarty plugin
4
    * --------------------------------------------------------------------------
5
    * File:     modifier.numbertext.php
6
    * Type:     modifier
7
    * Name:     numbertext
8
    * Version:  1.01
9
    * Date:     April 21, 2002
10
    * Purpose:  Outputs alternative text to numeric variables.
11
    *           Example:
12
    *           {$number_of_records|numbertext:"no records":"one record":"%d records"}
13
    *           If $number_of_records==0 it outputs 'no records'
14
    *           If $number_of_records==1 it outputs 'one record'
15
    *           If $number_of_records==34 it outputs '34 records'
16
    * Install:  Drop into the plugin directory.
17
    * Author:   Andreas Heintze <andreas.heintze@home.se>
18
    * --------------------------------------------------------------------------
19
    */
20
 
21
    function smarty_modifier_numbertext()
22
    {
23
        $alt_array = func_get_args();
24
        if ( is_numeric($value = $index = $alt_array[0]) )
25
        {
26
            $index++;
27
            $n = count( $alt_array ) - 1;
28
            $index = $index > $n ? $n : $index;
29
            $index = $index < 1 ? 1 : $index;
30
            return str_replace( "%d", $value, $alt_array[$index] );
31
        }
32
        else
33
        {
34
            return $index;
35
        }
36
    }
37
 
38
?>