/www/shop/engine/Library/Enlight/Template/Plugins/modifier.currency.php

https://bitbucket.org/weberlars/sot-shopware · PHP · 66 lines · 31 code · 4 blank · 31 comment · 10 complexity · ab3867579ead890d02901b19c80d5ecd MD5 · raw file

  1. <?php
  2. /**
  3. * Enlight
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://enlight.de/license
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@shopware.de so we can send you a copy immediately.
  14. *
  15. * @category Enlight
  16. * @package Enlight_Template_Plugins
  17. * @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de)
  18. * @license http://enlight.de/license New BSD License
  19. * @version $Id$
  20. * @author Heiner Lohaus
  21. * @author $Author$
  22. */
  23. /**
  24. * Formats a given decimal value to a local aware currency value
  25. *
  26. *
  27. * @link http://framework.zend.com/manual/de/zend.currency.options.html
  28. * @param float $value Value can have a coma as a decimal separator
  29. * @param array $config
  30. * @param string $position where the currency symbol should be displayed
  31. * @return float|string
  32. */
  33. function smarty_modifier_currency($value, $config = null, $position = null)
  34. {
  35. if (!Enlight_Application::Instance()->Bootstrap()->hasResource('Currency')) {
  36. return $value;
  37. }
  38. if (!empty($config) && is_string($config)) {
  39. $config = strtoupper($config);
  40. if (defined('Zend_Currency::' . $config)) {
  41. $config = array('display' => constant('Zend_Currency::' . $config));
  42. } else {
  43. $config = array();
  44. }
  45. } else {
  46. $config = array();
  47. }
  48. if (!empty($position) && is_string($position)) {
  49. $position = strtoupper($position);
  50. if (defined('Zend_Currency::' . $position)) {
  51. $config['position'] = constant('Zend_Currency::' . $position);
  52. }
  53. }
  54. $currency = Enlight_Application::Instance()->Currency();
  55. $value = floatval(str_replace(',', '.', $value));
  56. $value = $currency->toCurrency($value, $config);
  57. if (function_exists('mb_convert_encoding')) {
  58. $value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
  59. }
  60. $value = htmlentities($value, ENT_COMPAT, 'UTF-8', false);
  61. return $value;
  62. }