From 9d24648607343a3f4d4ebcccc49da5d16b143829 Mon Sep 17 00:00:00 2001 From: "Florian Aders (EleRas)" Date: Mon, 13 Jun 2011 16:49:02 +0200 Subject: [PATCH] Added more flexibility and temporary fallback for the sessionid Signed-off-by: Florian Aders (EleRas) --- lib/classes/output/class.linker.php | 47 ++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/classes/output/class.linker.php b/lib/classes/output/class.linker.php index 85ef5f2e..ef08b177 100644 --- a/lib/classes/output/class.linker.php +++ b/lib/classes/output/class.linker.php @@ -17,7 +17,7 @@ class linker { - private $protocol = 'http'; + private $protocol = ''; private $username = ''; private $password = ''; private $hostname = ''; @@ -26,15 +26,29 @@ class linker private $args = array(); - public function __construct($hostname, $protocol = 'http', $port = 80, $file = 'index.php', $username = '', $password = '') + public function __construct($file = 'index.php', $sessionid = '', $hostname = '', $protocol = '', $port = '', $username = '', $password = '') { # Set the basic parts of our URL $this->protocol = $protocol; + $this->username = $username; + $this->password = $password; $this->hostname = $hostname; $this->port = $port; $this->filename = $file; - $this->username = $username; - $this->password = $password; + $this->args['s'] = $sessionid; + } + + public function __set($key, $value) + { + switch($key) + { + case 'protocol': $this->protocol = $value; break; + case 'username': $this->username = $value; break; + case 'password': $this->password = $value; break; + case 'hostname': $this->hostname = $value; break; + case 'port': $this->port = $value; break; + case 'filename': $this->filename = $value; break; + } } public function add($key, $value) @@ -55,7 +69,8 @@ class linker public function delAll() { # Just resetting the array - $this->args = array(); + # Until the sessionid can be removed: save it + $this->args = array('s' => $this->args['s']); } public function getLink() @@ -63,10 +78,14 @@ class linker $link = ''; # Build the basic URL - $link = $this->protocol . '://'; + if (strlen($this->protocol) > 0) + { + $link = $this->protocol . '://'; + } # Let's see if we shall use a username in the URL - if ($this->username != '') + # This is only available if a hostname is used as well + if (strlen($this->username) > 0 && strlen($this->hostname) > 0) { $link .= urlencode($this->username); @@ -81,7 +100,19 @@ class linker } # Add hostname, port and filename to the URL - $link .= $this->hostname . ':' . $this->port . '/' . $this->filename; + if (strlen($this->hostname) > 0) + { + $link .= $this->hostname; + + # A port may only be used if hostname is used as well + if (strlen($this->port) > 0) + { + $link .= ':' . $this->port; + } + $link .= '/'; + } + + $link .= $this->filename; # Overwrite $this->args with parameters of this function (if necessary) if(func_num_args() == 1 && is_arrray(func_get_arg(0)))