]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Part of bug #3463481: Add HTTP protocol to self URL in feed
authorChristian Weiske <cweiske@cweiske.de>
Fri, 20 Jan 2012 13:52:36 +0000 (14:52 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 20 Jan 2012 13:52:36 +0000 (14:52 +0100)
src/SemanticScuttle/functions.php
www/rss.php

index 84e9c5f67b3ef0b5cd95ced054c627e55e7c7a12..09f7cf32445e8eedbfbc92eff1f1717b4cb9c577 100644 (file)
@@ -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.
index d888726eda12bb9ca98248e3447e553f10106457..46c0ffd6b9de016f48084d20c636237246503f6f 100644 (file)
@@ -124,7 +124,7 @@ if ($cat) {
 }
 
 $tplVars['feedtitle'] = filter($GLOBALS['sitename'] . (isset($pagetitle) ? $pagetitle : ''));
-$tplVars['feedlink'] = ROOT;
+$tplVars['feedlink'] = addProtocolToUrl(ROOT);
 $tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOBALS['sitename']);
 
 $bookmarks = $bookmarkservice->getBookmarks(