PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/vendor/smarty2/plugins/function.letter_counter.php

http://zoop.googlecode.com/
PHP | 61 lines | 40 code | 12 blank | 9 comment | 15 complexity | 6df9abb4e3dab93f9e7724043df60bf2 MD5 | raw file
 1<?php
 2
 3/*
 4 * Smarty plugin
 5 * -------------------------------------------------------------
 6 * Type:     function
 7 * Name:     letter_counter
 8 * Purpose:  print out a counter value
 9 * -------------------------------------------------------------
10 */
11function smarty_function_letter_counter($params, &$smarty)
12{
13    static $count = array();
14    static $skipval = array();
15    static $dir = array();
16    static $id = "default";
17    static $printval = array();
18    static $assign = "";
19
20    extract($params);
21
22    if (!isset($id))
23        $id = "default";
24
25    if (isset($start))
26        $count[$id] = $start;
27    else if (!isset($count[$id]))
28        $count[$id]=1;
29
30    if (!isset($print))
31        $printval[$id]=true;
32    else
33        $printval[$id]=$print;
34    
35    if (!empty($assign)) {
36        $printval[$id] = false;
37        $smarty->assign($assign, $count[$id]);
38    }
39
40    if ($printval[$id])
41        echo chr(ord('a') + $count[$id] - 1);
42
43    if (isset($skip))
44        $skipval[$id] = $skip;
45    else if (empty($skipval[$id]))
46        $skipval[$id] = 1;
47    
48    if (isset($direction))
49        $dir[$id] = $direction;
50    else if (!isset($dir[$id]))
51        $dir[$id] = "up";
52
53    if ($dir[$id] == "down")
54        $count[$id] -= $skipval[$id];
55    else
56        $count[$id] += $skipval[$id];
57}
58
59/* vim: set expandtab: */
60
61?>