diff options
author | Christian Weiske <cweiske@cweiske.de> | 2012-01-20 22:10:30 +0100 |
---|---|---|
committer | Christian Weiske <cweiske@cweiske.de> | 2012-01-20 22:10:30 +0100 |
commit | 6ff4370a20e7da8d02239b387cc0db296d7bf466 (patch) | |
tree | 0166e5a7b78779675507086326efd67b4fef9eb3 /src/SemanticScuttle/functions.php | |
parent | d16ca9235157042604f23949f2fa6e479e882d7d (diff) | |
parent | d6d44c6cfa7e3e5cdb36d9e4abd3a62edad74eb9 (diff) | |
download | semanticscuttle-6ff4370a20e7da8d02239b387cc0db296d7bf466.tar.gz semanticscuttle-6ff4370a20e7da8d02239b387cc0db296d7bf466.tar.bz2 |
Merge branch '0.98'
Diffstat (limited to 'src/SemanticScuttle/functions.php')
-rw-r--r-- | src/SemanticScuttle/functions.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/SemanticScuttle/functions.php b/src/SemanticScuttle/functions.php index 84e9c5f..09f7cf3 100644 --- a/src/SemanticScuttle/functions.php +++ b/src/SemanticScuttle/functions.php @@ -118,6 +118,31 @@ function createURL($page = '', $ending = '') { return ROOT . $page; } } + +/** + * Adds the protocol to the URL if it's missing. + * If the current URL is served via HTTPS, https will be used as protocol. + * + * Useful to fix ROOT urls of SemanticScuttle when it's needed, e.g. + * in the bookmarklet or the feed. + * + * @param string $url Url with or without the protocol ("//example.org/foo") + * + * @return string URL with a HTTP protocol + */ +function addProtocolToUrl($url) +{ + if (substr($url, 0, 2) != '//') { + return $url; + } + + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) { + $protocol = 'https:'; + } else { + $protocol = 'http:'; + } + return $protocol . $url; +} /** * Creates a "vote for/against this bookmark" URL. * Also runs htmlspecialchars() on them to prevent XSS. |