We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32963
    • 1,732 Posts
    Hi,

    I would like to recommend the following change to makeURL which allows a user to change the scheme used when generating fully qualified urls.

    $modx->makeUrl(1,’’,’’,’http’); // displays http://domain.com/index.php?id=1
    $modx->makeUrl(1,’’,’’,’https’); // displays https://domain.com/index.php?id=1
    $modx->makeUrl(1,’’,’’,1); // for backward compatibility - displays either https or http for the url.

    $modx->makeUrl(1,’’,’’,’full’); // will use site_url to render the fully path
    $modx->makeUrl(1); // normal output.

    <?php
    function makeUrl($id, $alias='', $args='', $scheme= '') {
    	$url= '';
    	$virtualDir= '';
    	if(!is_numeric($id)) {
    		$this->messageQuit('`'.$id.'` is not numeric and may not be passed to makeUrl()');
    	}
    	if($args!='' && $this->config['friendly_urls']==1) {
    		// add ? to $args if missing
    		$c = substr($args,0,1);
    		if ($c=='&') $args = '?'.substr($args,1);
    		elseif ($c!='?') $args = '?'.$args; 
    	}
    	elseif($args!='') {
    		// add & to $args if missing
    		$c = substr($args,0,1);
    		if ($c=='?') $args = '&'.substr($args,1);
    		elseif ($c!='&') $args = '&'.$args; 
    	}
    	if($this->config['friendly_urls']==1 && $alias!='') {
    		$url= $this->config['friendly_url_prefix'].$alias.$this->config['friendly_url_suffix'].$args;
    	} elseif($this->config['friendly_urls']==1 && $alias=='') {
    		$alias = $id;
    		if($this->config['friendly_alias_urls']==1) {
    			$al = $this->aliasListing[$id];
    			$alPath = !empty($al['path'])? $al['path'] . '/': '';
    			if($al && $al['alias']) $alias = $al['alias'];
    		}
    		$alias = $alPath . $this->config['friendly_url_prefix'].$alias.$this->config['friendly_url_suffix'];
    		$url= $alias.$args;
    	} else {
    		$url= 'index.php?id='.$id.$args;
    	}
    
    	$host = $this->config['base_url'];
    	// check if scheme argument has been set
    	if($scheme!='') {
    		// for backward compatibility - check if the desired scheme is different than the current scheme
    		if (is_numeric($scheme) && $scheme != $_SERVER['HTTPS']) { 
    			$scheme = ($_SERVER['HTTPS'] ? 'http' : 'https');
    		}
    
    		$host = $scheme=='full' ? $this->config['site_url']: $scheme.'://'.$_SERVER['HTTP_HOST'].$this->config['base_url'];
    	}
    
    	return $host . $virtualDir . $url;
    }
    ?>
    

      xWisdom
      www.xwisdomhtml.com
      The fear of the Lord is the beginning of wisdom:
      MODx Co-Founder - Create and do more with less.
      • 22303 MODX Staff
      • 10,725 Posts
      Good additions Raymond.
        • 32963
        • 1,732 Posts
        Quote from: OpenGeek at Aug 02, 2006, 12:06 PM

        Good additions Raymond.

        Thanks Jaon. I’ll check it into SVN soon
          xWisdom
          www.xwisdomhtml.com
          The fear of the Lord is the beginning of wisdom:
          MODx Co-Founder - Create and do more with less.