From 4ec569d6e7ce5f114796d2a9e9f27fc945f0e61c Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 25 Dec 2013 02:45:22 -0800 Subject: sslify http links in media elements if you're on an https server --- include/text.php | 32 ++++++++++++++++++++++++++++++++ mod/sslify.php | 6 ++++++ 2 files changed, 38 insertions(+) create mode 100644 mod/sslify.php diff --git a/include/text.php b/include/text.php index b3154d23e..8b71fbddf 100755 --- a/include/text.php +++ b/include/text.php @@ -781,6 +781,34 @@ function linkify($s) { return($s); } +/** + * @function sslify($s) + * Replace media element using http url with https to a local redirector if using https locally + * @param string $s + * + * Looks for HTML tags containing src elements that are http when we're viewing an https page + * Typically this throws an insecure content violation in the browser. So we redirect them + * to a local redirector which uses https and which redirects to the selected content + * + * @returns string + */ + + +function sslify($s) { + if(strpos(z_root(),'https:') === false) + return $s; + $matches = null; + $cnt = preg_match_all("/\<(.*?)src=\"(http\:.*?)\"(.*?)\>/",$s,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $match) { + $s = str_replace($match[2],z_root() . '/sslify?f=&url=' . urlencode($match[2]),$s); + } + } + return $s; +} + + + function get_poke_verbs() { // index is present tense verb @@ -1166,6 +1194,10 @@ function prepare_body(&$item,$attach = false) { if(local_user() == $item['uid']) $s .= format_filer($item); + + $s = sslify($s); + + // Look for spoiler $spoilersearch = '
'; diff --git a/mod/sslify.php b/mod/sslify.php new file mode 100644 index 000000000..951a201ea --- /dev/null +++ b/mod/sslify.php @@ -0,0 +1,6 @@ +