From f8f3b387082d9a68c0a092b45d76da178b2f92b1 Mon Sep 17 00:00:00 2001 From: Pepijn Over Date: Fri, 14 Mar 2014 15:12:00 +0100 Subject: [PATCH] adding new psm_build_url() function to create clean urls with params --- src/includes/functions.inc.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index a972c412..5c7273f7 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -339,6 +339,36 @@ function psm_build_mail($from_name = null, $from_email = null) { return $phpmailer; } +/** + * Generate a new link to the current monitor + * @param array $params key value pairs + * @param boolean $urlencode urlencode all params? + * @return string + */ +function psm_build_url($params = array(), $urlencode = true) { + $defports = array(80, 443); + $url = + ($_SERVER['SERVER_PORT']==80 ? 'http' : 'https').'://'. + $_SERVER['HTTP_HOST']; + if(!in_array($_SERVER['SERVER_PORT'], $defports)) { + $url .= ':' . $_SERVER['SERVER_PORT']; + } + $url .= dirname($_SERVER['SCRIPT_NAME']) . '/'; + + if($params != null) { + $url .= '?'; + + foreach($params as $k => $v) { + if($urlencode) { + $v = urlencode($v); + } + $url .= '&' . $k . '=' . $v; + } + } + + return $url; +} + ############################################### # # Debug functions