diff options
Diffstat (limited to 'public/system/library/url.php')
-rw-r--r-- | public/system/library/url.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/public/system/library/url.php b/public/system/library/url.php new file mode 100644 index 0000000..92dae5a --- /dev/null +++ b/public/system/library/url.php @@ -0,0 +1,69 @@ +<?php +/** + * @package OpenCart + * @author Daniel Kerr + * @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/) + * @license https://opensource.org/licenses/GPL-3.0 + * @link https://www.opencart.com +*/ + +/** +* URL class +*/ +class Url { + private $url; + private $ssl; + private $rewrite = array(); + + /** + * Constructor + * + * @param string $url + * @param string $ssl + * + */ + public function __construct($url, $ssl = '') { + $this->url = $url; + $this->ssl = $ssl; + } + + /** + * + * + * @param object $rewrite + */ + public function addRewrite($rewrite) { + $this->rewrite[] = $rewrite; + } + + /** + * + * + * @param string $route + * @param mixed $args + * @param bool $secure + * + * @return string + */ + public function link($route, $args = '', $secure = false) { + if ($this->ssl && $secure) { + $url = $this->ssl . 'index.php?route=' . $route; + } else { + $url = $this->url . 'index.php?route=' . $route; + } + + if ($args) { + if (is_array($args)) { + $url .= '&' . http_build_query($args); + } else { + $url .= str_replace('&', '&', '&' . ltrim($args, '&')); + } + } + + foreach ($this->rewrite as $rewrite) { + $url = $rewrite->rewrite($url); + } + + return $url; + } +}
\ No newline at end of file |