PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/library/XenForo/Template/Compiler/Function/Link.php

https://github.com/hanguyenhuu/DTUI_201105
PHP | 56 lines | 34 code | 7 blank | 15 comment | 5 complexity | 85af31ef63308afcfcd8931f6fc54a26 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * Class to handle compiling template function calls for "link" and "adminlink".
  4. *
  5. * @package XenForo_Template
  6. */
  7. class XenForo_Template_Compiler_Function_Link implements XenForo_Template_Compiler_Function_Interface
  8. {
  9. /**
  10. * Compiles the function call.
  11. *
  12. * @param XenForo_Template_Compiler The invoking compiler
  13. * @param string Name of the function called
  14. * @param array Arguments to the function (should have at least 1)
  15. * @param array Compilation options
  16. *
  17. * @return string
  18. */
  19. public function compile(XenForo_Template_Compiler $compiler, $function, array $arguments, array $options)
  20. {
  21. $argc = count($arguments);
  22. if ($argc < 1)
  23. {
  24. throw $compiler->getNewCompilerArgumentException();
  25. }
  26. $type = array_shift($arguments);
  27. $data = 'false';
  28. if (isset($arguments[0]))
  29. {
  30. $dataRef = array_shift($arguments);
  31. $data = $compiler->compileAndCombineSegments($dataRef, array_merge($options, array('varEscape' => false)));
  32. }
  33. $params = $compiler->getNamedParamsAsPhpCode(
  34. $compiler->parseNamedArguments($arguments),
  35. array_merge($options, array('varEscape' => false))
  36. );
  37. $phpFunction = ($function == 'adminlink' ? 'adminLink' : 'link');
  38. if ($options['varEscape'] != 'htmlspecialchars')
  39. {
  40. $varEscapeParam = ', ' . ($options['varEscape'] ? "'$options[varEscape]'" : 'false');
  41. }
  42. else
  43. {
  44. $varEscapeParam = '';
  45. }
  46. return 'XenForo_Template_Helper_Core::' . $phpFunction . "("
  47. . $compiler->compileAndCombineSegments($type, $options) . ', ' . $data . ', ' . $params . $varEscapeParam . ')';
  48. }
  49. }