Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-05-01 23:42:49

scornflake
New Member
Registered: 2011-04-28
Posts: 4

Newbie help with http/https (using the right one - at the right time)

I’d like to create a link to a URL on the site (e.g: /store/store.php), but always force it to be https.

I can’t use txp:site_url, since it always generates an http link.
I’d rather not hardcode it – since I have multiple sites using different host names.

Is there some simple way I’ve missed to do this?

e.g (a fictional txp:site_host_name tag):

<txp:variable name=“login_link”>https://<txp:site_host_name/>/store/store.php</txp:variable>

Last edited by scornflake (2011-05-01 23:47:42)

Offline

#2 2011-05-06 08:13:09

geoff777
Plugin Author
From: Benarrabá Andalucía Spain
Registered: 2008-02-19
Posts: 282
Website

Re: Newbie help with http/https (using the right one - at the right time)

Hi scornflake,

This might work …
I’ve added a couple of operators to adi_calc to handle string concatenation – prefix – concat
I think there is a newer version but you can see where I added concat & prefix.

/*
	adi_calc - Calculator for TXP variables

	Written by Adi Gilbert

	Released under the GNU General Public License

	Version history:
	0.1		- initial release

*/

function adi_calc($atts) {

	extract(lAtts(array(
		'name'			=> '',	// TXP var name
		'add'			=> '',	// name = name + value
		'subtract'		=> '',	// name = name - value
		'multiply'		=> '',	// name = name * value
		'div'			=> '',	// name = name DIV value (integer division)
		'mod'			=> '',	// name = name MOD value (remainder)
                'concat'                => '',	// name = name . value
                'prefix'                => ''	// name = value . name
	), $atts));

	if ($name) { // TXP var supplied
		if (!array_key_exists($name,$GLOBALS['variable'])) // set var to zero if not already set
			$GLOBALS['variable'][$name] = 0;
		$value = $GLOBALS['variable'][$name];
		if ($add)
			$value = $value + $add;
		if ($subtract)
			$value = $value - $subtract;
		if ($multiply)
			$value = $value * $multiply;
		if ($div)
			$value = (int)($value / $div);
		if ($mod)
			$value = $value % $mod;
                if ($concat)
			$value = $value . $concat;
                if ($prefix)
			$value = $prefix . $value;
		$GLOBALS['variable'][$name] = $value;
	}
}
<txp:variable name="server_name" value="" />
<txp:php>
    variable(array('name' => 'server_name', 'value' => strtolower(preg_replace('/^www\./i', '', $_SERVER['SERVER_NAME']))));
</txp:php>
<txp:variable name="login_link" value='<txp:variable name="server_name" />/' />
<txp:adi_calc name="login_link" prefix="https://www." />
<txp:adi_calc name="login_link" concat="store/store.php" />

Last edited by geoff777 (2011-05-06 14:43:15)


There are 10 types of people in the world: those who understand binary, and those who don’t.

Offline

Board footer

Powered by FluxBB