add comment to cron.d-template; fix linker class to void double-slash after redirectTo, fixes #1372

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2014-01-30 11:42:16 +01:00
parent 658a9288f1
commit c5cb91a882
7 changed files with 60 additions and 66 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
@@ -15,8 +16,8 @@
*
*/
class linker
{
class linker {
private $protocol = '';
private $username = '';
private $password = '';
@@ -26,23 +27,21 @@ class linker
private $args = array();
public function __construct($file = 'index.php', $sessionid = '', $hostname = '', $protocol = '', $port = '', $username = '', $password = '')
{
# Set the basic parts of our URL
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;
# @TODO: Remove this
// @TODO: Remove this
$this->args['s'] = $sessionid;
}
public function __set($key, $value)
{
switch(strtolower($key))
{
public function __set($key, $value) {
switch (strtolower($key)) {
case 'protocol': $this->protocol = $value; break;
case 'username': $this->username = $value; break;
case 'password': $this->password = $value; break;
@@ -54,111 +53,94 @@ class linker
return true;
}
public function add($key, $value)
{
# Add a new value to our parameters (overwrite = enabled)
public function add($key, $value) {
// Add a new value to our parameters (overwrite = enabled)
$this->args[$key] = $value;
}
public function del($key)
{
# If the key exists in our array -> delete it
if (isset($this->args[$key]))
{
public function del($key) {
// If the key exists in our array -> delete it
if (isset($this->args[$key])) {
unset($this->args[$key]);
}
}
public function delAll()
{
# Just resetting the array
# Until the sessionid can be removed: save it
# @TODO: Remove this
public function delAll() {
// Just resetting the array
// Until the sessionid can be removed: save it
// @TODO: Remove this
$this->args = array('s' => $this->args['s']);
}
public function getLink()
{
public function getLink() {
$link = '';
# Build the basic URL
if (strlen($this->protocol) > 0 && strlen($this->hostname) > 0)
{
// Build the basic URL
if (strlen($this->protocol) > 0 && strlen($this->hostname) > 0) {
$link = $this->protocol . '://';
}
# Let's see if we shall use a username in the URL
# This is only available if a hostname is used as well
if (strlen($this->username) > 0 && strlen($this->hostname) > 0)
{
// Let's see if we shall use a username in the URL
// This is only available if a hostname is used as well
if (strlen($this->username) > 0 && strlen($this->hostname) > 0) {
$link .= urlencode($this->username);
# Maybe we even have to append a password?
if ($this->password != '')
{
// Maybe we even have to append a password?
if ($this->password != '') {
$link .= ':' . urlencode($this->password);
}
# At least a username was given, add the @ to allow appending the hostname
// At least a username was given, add the @ to allow appending the hostname
$link .= '@';
}
# Add hostname, port and filename to the URL
if (strlen($this->hostname) > 0)
{
// Add hostname, port and filename to the URL
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)
{
// A port may only be used if hostname is used as well
if (strlen($this->port) > 0) {
$link .= ':' . $this->port;
}
$link .= '/';
}
# Overwrite $this->args with parameters of this function (if necessary)
if(func_num_args() == 1 && is_array(func_get_arg(0)))
{
// Overwrite $this->args with parameters of this function (if necessary)
if (func_num_args() == 1 && is_array(func_get_arg(0))) {
$arguments = func_get_arg(0);
$this->args = array_merge($this->args, $arguments);
}
# temporary until frontcontroller exists
# We got a section in the URL -> morph AREA and section into filename
# @TODO: Remove this
if (isset($this->args['section']) && strlen($this->args['section']) > 0)
{
// temporary until frontcontroller exists
// We got a section in the URL -> morph AREA and section into filename
// @TODO: Remove this
if (isset($this->args['section']) && strlen($this->args['section']) > 0) {
$link .= AREA . '_' . $this->args['section'] . '.php';
unset($this->args['section']);
}
else
{
} else {
// filename has a prefixed slash
$link .= $this->filename;
}
# Let's see if we are done (no arguments in query)
if (count($this->args) == 0)
{
// Let's see if we are done (no arguments in query)
if (count($this->args) == 0) {
return $link;
}
# We have parameters, add them with a "?"
// We have parameters, add them with a "?"
$link .= "?";
# Loop through arguments and add them to the link
foreach ($this->args as $key => $value)
{
# For all but the first argument, prepend "&amp;"
if (substr($link, -1) != "?")
{
// Loop through arguments and add them to the link
foreach ($this->args as $key => $value) {
// For all but the first argument, prepend "&amp;"
if (substr($link, -1) != "?") {
$link .= "&";
}
# Encode parameters and add them to the link
// Encode parameters and add them to the link
$link .= urlencode($key) . '=' . urlencode($value);
}
# Reset our class for further use
// Reset our class for further use
$this->delAll();
return $link;
}