<?php
class Url {
	private $url;
	private $ssl;
	private $hook = array();
	
	public function __construct($url, $ssl) {
		$this->url = $url;
		$this->ssl = $ssl;
	}
	
	public function link($route, $args = '', $connection = 'NONSSL') {
    
        // This code replace link to the cart page, comment or delete this block if you want to use the standart cart instead off the simplecheckout page  
        if ($route == 'checkout/cart') {
            $route = 'checkout/simplecheckout';
        }
        
        // This code replace link to the checkout page, comment or delete this block if you want to use the standart checkout page instead off  the simplecheckout page 
        if ($route == 'checkout/checkout') {
            $route = 'checkout/simplecheckout';
        }
        
        // This code replace link to the register page, comment or delete this block if you want to use the standart register page instead of the simpleregister page  
        if ($route == 'account/register') {
            $route = 'account/simpleregister';
        }
        
		if ($connection ==  'NONSSL') {
			$url = $this->url;	
		} else {
			$url = $this->ssl;	
		}
		
		$url .= 'index.php?route=' . $route;
			
		if ($args) {
			$url .= str_replace('&', '&amp;', '&' . ltrim($args, '&')); 
		}
		
		return $this->rewrite($url);
	}
		
	public function addRewrite($hook) {
		$this->hook[] = $hook;
	}

	public function rewrite($url) {
		foreach ($this->hook as $hook) {
			$url = $hook->rewrite($url);
		}
		
		return $url;		
	}
}
?>