XoopsCore25 icon indicating copy to clipboard operation
XoopsCore25 copied to clipboard

./include/functions.php - formatURL :: Add ability to set secure URL

Open zyspec opened this issue 8 years ago • 0 comments

Enhancement Add a 2nd parameter to formatURL() function to allow requesting a secure url. For backward compatibility function should return http as the default.

/**
 * formatURL()
 *
 * @param mixed $url
 * @param bool $secure true to return https, else return http
 * @return mixed|string
 */
function formatURL($url, $secure=false)
{
    $url = trim($url);
    if ($url != '') {
        if ((!preg_match('/^http[s]*:\/\//i', $url)) && (!preg_match('/^ftp*:\/\//i', $url)) && (!preg_match('/^ed2k*:\/\//i', $url))) {
            $url = (bool)$secure ? 'https://' . $url : 'http://' . $url;
        }
    }

    return $url;
}

zyspec avatar Jul 24 '17 20:07 zyspec