Changeset 1584125 for https-redirection/trunk/https-redirection.php
- Timestamp:
- 01/28/2017 12:18:45 PM (9 years ago)
- File:
-
- 1 edited
-
https-redirection/trunk/https-redirection.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
https-redirection/trunk/https-redirection.php
r1583453 r1584125 67 67 68 68 /* Register settings function */ 69 69 70 function register_httpsrdrctn_settings() { 70 71 global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info; … … 126 127 * TODO - Need to make it better so it only does it for static resources like JS, CSS and Images 127 128 */ 129 128 130 function httpsrdrctn_filter_content($content) { 129 131 //filter buffer 130 132 $home_no_www = str_replace("://www.", "://", get_option('home')); 131 133 $home_yes_www = str_replace("://", "://www.", $home_no_www); 132 133 134 $http_urls = array( 134 135 str_replace("https://", "http://", $home_yes_www), … … 143 144 //replace all http links except hyperlinks 144 145 //all tags with src attr are already fixed by str_replace 146 145 147 $pattern = array( 146 148 '/url\([\'"]?\K(http:\/\/)(?=[^)]+)/i', … … 161 163 $current_page = sanitize_post($GLOBALS['wp_the_query']->get_queried_object()); 162 164 // Get the page slug 163 $slug =str_replace(home_url().'/','',get_permalink($current_page)); 165 $slug = str_replace(home_url() . '/', '', get_permalink($current_page)); 166 $slug = rtrim($slug, "/"); //remove trailing slash if it's there 167 168 $content.=$slug; 164 169 165 170 if ($httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1) { … … 167 172 $content = httpsrdrctn_filter_content($content); 168 173 } else if (!empty($httpsrdrctn_options['https_pages_array'])) { 174 $pages_str = ''; 175 $on_https_page = false; 169 176 foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) { 170 if ($https_page == $slug) { //if we are on the page that is in the array, let's replace all contents to https 171 $content = httpsrdrctn_filter_content($content); 177 $pages_str.=preg_quote($https_page, '/') . '[\/|][\'"]|'; //let's add page to the preg expression string in case we'd need it later 178 if ($https_page == $slug) { //if we are on the page that is in the array, let's set the var to true 179 $on_https_page = true; 172 180 } else { //if not - let's replace all links to that page only to https 173 181 $http_domain = home_url(); … … 176 184 } 177 185 } 186 if ($on_https_page) { //we are on one of the https pages 187 $pages_str = substr($pages_str, 0, strlen($pages_str) - 1); //remove last '|' 188 $content = httpsrdrctn_filter_content($content); //let's change everything to https first 189 $http_domain = str_replace('https://', 'http://', home_url()); 190 $https_domain = str_replace('http://', 'https://', home_url()); 191 //now let's change all inner links to http, excluding those that user sets to be https in plugin settings 192 $content = preg_replace('/<a .*?href=[\'"]\K' . preg_quote($https_domain, '/') . '\/((?!' . $pages_str . ').)(?=[^\'"]+)/i', $http_domain . '/$1', $content); 193 $content = preg_replace('/' . preg_quote($https_domain, '/') . '([\'"])/i', $http_domain . '$1', $content); 194 } 178 195 } 179 196 }
Note: See TracChangeset
for help on using the changeset viewer.