shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

url.php (1297B)


      1 <?php
      2 /**
      3  * @package		OpenCart
      4  * @author		Daniel Kerr
      5  * @copyright	Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
      6  * @license		https://opensource.org/licenses/GPL-3.0
      7  * @link		https://www.opencart.com
      8 */
      9 
     10 /**
     11 * URL class
     12 */
     13 class Url {
     14 	private $url;
     15 	private $ssl;
     16 	private $rewrite = array();
     17 	
     18 	/**
     19 	 * Constructor
     20 	 *
     21 	 * @param	string	$url
     22 	 * @param	string	$ssl
     23 	 *
     24  	*/
     25 	public function __construct($url, $ssl = '') {
     26 		$this->url = $url;
     27 		$this->ssl = $ssl;
     28 	}
     29 
     30 	/**
     31 	 *
     32 	 *
     33 	 * @param	object	$rewrite
     34  	*/	
     35 	public function addRewrite($rewrite) {
     36 		$this->rewrite[] = $rewrite;
     37 	}
     38 
     39 	/**
     40 	 * 
     41 	 *
     42 	 * @param	string		$route
     43 	 * @param	mixed		$args
     44 	 * @param	bool		$secure
     45 	 *
     46 	 * @return	string
     47  	*/
     48 	public function link($route, $args = '', $secure = false) {
     49 		if ($this->ssl && $secure) {
     50 			$url = $this->ssl . 'index.php?route=' . $route;
     51 		} else {
     52 			$url = $this->url . 'index.php?route=' . $route;
     53 		}
     54 		
     55 		if ($args) {
     56 			if (is_array($args)) {
     57 				$url .= '&amp;' . http_build_query($args);
     58 			} else {
     59 				$url .= str_replace('&', '&amp;', '&' . ltrim($args, '&'));
     60 			}
     61 		}
     62 		
     63 		foreach ($this->rewrite as $rewrite) {
     64 			$url = $rewrite->rewrite($url);
     65 		}
     66 		
     67 		return $url; 
     68 	}
     69 }