Skip to content

Commit 7a1bc5b

Browse files
committed
Implemented custom constants for HTTPS control.
1 parent b2fe5d3 commit 7a1bc5b

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

force/filters.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,34 @@ public function content($content) {
7272

7373

7474
/**
75-
* Replace HTTP by HTTPS for images,
76-
* URLs in object and embed tags, and internal links.
75+
* Replace URL HTTP protocol by HTTPS
7776
*/
7877
public function contentURL($matches) {
79-
$tag = (3 == count($matches))? $matches[1] : null;
78+
79+
// Extract tag from matches
80+
$tag = (3 == count($matches))? $matches[1] : null;
81+
82+
// Check internal link
83+
$internal = $this->isInternalLink($matches[0]);
84+
85+
// Exceptions by tag and internal/external URL's
86+
if ((isset($tag) && 'a' == $tag && $internal && !$this->plugin->enabled('FORCE_HTTPS_INTERNAL_LINKS')) || // Prevent internal links to be altered
87+
((!isset($tag) || 'a' != $tag) && $internal && !$this->plugin->enabled('FORCE_HTTPS_INTERNAL_RESOURCES')) || // Prevent internal resources to be altered
88+
(isset($tag) && 'a' == $tag && !$internal && !$this->plugin->enabled('FORCE_HTTPS_EXTERNAL_LINKS', false)) || // Prevent external links to be altered
89+
((!isset($tag) || 'a' != $tag) && !$internal && !$this->plugin->enabled('FORCE_HTTPS_EXTERNAL_RESOURCES'))) { // Prevent external resources to be altered
90+
91+
// Original URL
92+
return $matches[0];
93+
}
94+
95+
// Prepare protocol
8096
$protocol = isset($matches[2])? $matches[2] : $matches[1];
81-
return (!isset($tag) || in_array($tag, ['img', 'url']) || $this->isInternalLink($matches[0]))? 'https://'.substr($matches[0], strlen($protocol)) : $matches[0];
97+
98+
// Compose new URL
99+
$url = 'https://'.substr($matches[0], strlen($protocol));
100+
101+
// Done
102+
return $url;
82103
}
83104

84105

0 commit comments

Comments
 (0)