Url.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ CXDHlInlrvmyqFCA1iYWVGyijIcOwxeEZp6enK5w9rc=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2015 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.5
  11. */
  12. /**
  13. * url view helper
  14. *
  15. * IMPORTANT: dynamic routes will be set by slugs
  16. */
  17. namespace Ppb\View\Helper;
  18. use Cube\Controller\Front,
  19. Cube\View\Helper\Url as UrlHelper;
  20. class Url extends UrlHelper
  21. {
  22. /**
  23. *
  24. * force all urls to redirect to the site
  25. *
  26. * @var string
  27. */
  28. private $_sitePath = null;
  29. public function __construct($sitePath)
  30. {
  31. $this->_sitePath = $sitePath;
  32. }
  33. /**
  34. *
  35. * create an url based on a set of params and the router object
  36. * 7.5: added workaround for key/value pairs for which the cleaned value results in an empty string
  37. *
  38. * @param string|array $params a string or an array of params
  39. * @param string $name the name of the specific route to use
  40. * @param bool $addGetParams whether to attach params resulted from a previous get operation to the url
  41. * @param array $skipParams an array of params to be omitted when constructing the url
  42. * @param bool $addBaseUrl flag to add the base url param to the assembled route
  43. * @param bool $cleanString if true, will clean values of get variables (only if params is an array)
  44. *
  45. * @return string the url of the link href attribute
  46. */
  47. public function url($params, $name = null, $addGetParams = false, array $skipParams = null, $addBaseUrl = true, $cleanString = true)
  48. {
  49. $router = Front::getInstance()->getRouter();
  50. if (is_array($params) &&
  51. $cleanString === true
  52. ) {
  53. foreach ($params as $key => $value) {
  54. $params[$key] = self::cleanString($value);
  55. }
  56. }
  57. return (($addBaseUrl) ? $this->_sitePath : '') . $router->assemble($params, $name, false, $addGetParams, $skipParams);
  58. }
  59. }