From a23b886888add23229b870693d101eb19b4471eb Mon Sep 17 00:00:00 2001
From: lucha <lucha@paranoici.org>
Date: Sat, 5 Nov 2016 15:12:46 +0100
Subject: [PATCH] noblogs-wp-ssl plugin

---
 wp-content/mu-plugins/noblogs-wp-ssl.php | 43 ++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 wp-content/mu-plugins/noblogs-wp-ssl.php

diff --git a/wp-content/mu-plugins/noblogs-wp-ssl.php b/wp-content/mu-plugins/noblogs-wp-ssl.php
new file mode 100644
index 000000000..0c0d46949
--- /dev/null
+++ b/wp-content/mu-plugins/noblogs-wp-ssl.php
@@ -0,0 +1,43 @@
+<?php
+/*
+Plugin Name: Noblogs Wp SSL
+Plugin URI: https://git.autistici.org/ai/noblogs-wp-ssl
+Description: Rewrite internal URLS to use HTTPS.
+Version: 0.1
+Author: Cloudflare, sand
+License: GPLv2
+ */
+
+/*
+  Heavily copied from: https://wordpress.org/plugins/cloudflare/
+ */
+
+if ( !function_exists('add_action') ) {
+    echo "This is a Wordpress plugin and should not be called directly";
+    exit;
+}
+
+function rewrite_links($buffer) {
+        // replace href or src attributes within script, link, base, and img tags with just "//" for protocol
+        $re     = "#(<(?:script|link|base|img|form|a)(?:[^>]*)(?:href|src|action)=[\"'])http://([^.]+\.noblogs\.org)#i";
+        $subst  = "$1https://$2";
+        return preg_replace($re, $subst, $buffer);
+}
+
+
+// This is a filter function that act on the post $content
+function noblogs_wp_ssl_content_filter($content) {
+    // skip rewrite if not on HTTPS
+    if (empty($_SERVER['HTTPS'])) {
+        return $content;
+    }
+
+    $return = rewrite_links($content);
+    if ($return) {
+        $content = $return;
+    }
+
+    return $content;
+}
+
+add_filter('the_content', 'noblogs_wp_ssl_content_filter');
-- 
GitLab