Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

shared.literal_compiler_param.php 1010B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsShared
  7. */
  8. /**
  9. * evaluate compiler parameter
  10. *
  11. * @param array $params parameter array as given to the compiler function
  12. * @param integer $index array index of the parameter to convert
  13. * @param mixed $default value to be returned if the parameter is not present
  14. *
  15. * @return mixed evaluated value of parameter or $default
  16. * @throws SmartyException if parameter is not a literal (but an expression, variable, …)
  17. * @author Rodney Rehm
  18. */
  19. function smarty_literal_compiler_param($params, $index, $default = null)
  20. {
  21. // not set, go default
  22. if (!isset($params[$index])) {
  23. return $default;
  24. }
  25. // test if param is a literal
  26. if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[$index])) {
  27. throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time');
  28. }
  29. $t = null;
  30. eval("\$t = " . $params[$index] . ";");
  31. return $t;
  32. }