/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. * Smarty plugin
  4. * -------------------------------------------------------------
  5. * Type: function
  6. * Name: letter_counter
  7. * Purpose: print out a counter value
  8. * -------------------------------------------------------------
  9. */
  10. function smarty_function_letter_counter($params, &$smarty)
  11. {
  12. static $count = array();
  13. static $skipval = array();
  14. static $dir = array();
  15. static $id = "default";
  16. static $printval = array();
  17. static $assign = "";
  18. extract($params);
  19. if (!isset($id))
  20. $id = "default";
  21. if (isset($start))
  22. $count[$id] = $start;
  23. else if (!isset($count[$id]))
  24. $count[$id]=1;
  25. if (!isset($print))
  26. $printval[$id]=true;
  27. else
  28. $printval[$id]=$print;
  29. if (!empty($assign)) {
  30. $printval[$id] = false;
  31. $smarty->assign($assign, $count[$id]);
  32. }
  33. if ($printval[$id])
  34. echo chr(ord('a') + $count[$id] - 1);
  35. if (isset($skip))
  36. $skipval[$id] = $skip;
  37. else if (empty($skipval[$id]))
  38. $skipval[$id] = 1;
  39. if (isset($direction))
  40. $dir[$id] = $direction;
  41. else if (!isset($dir[$id]))
  42. $dir[$id] = "up";
  43. if ($dir[$id] == "down")
  44. $count[$id] -= $skipval[$id];
  45. else
  46. $count[$id] += $skipval[$id];
  47. }
  48. /* vim: set expandtab: */
  49. ?>