Changeset 1583453 for https-redirection/trunk/https-redirection.php
- Timestamp:
- 01/27/2017 12:00:59 PM (9 years ago)
- File:
-
- 1 edited
-
https-redirection/trunk/https-redirection.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
https-redirection/trunk/https-redirection.php
r1455885 r1583453 1 1 <?php 2 2 3 /* 3 4 Plugin Name: Easy HTTPS (SSL) Redirection 4 Plugin URI: 5 Plugin URI: https://www.tipsandtricks-hq.com/development-center 5 6 Description: The plugin HTTPS Redirection allows an automatic redirection to the "HTTPS" version/URL of the site. 6 7 Author: Tips and Tricks HQ 7 Version: 1. 58 Version: 1.6 8 9 Author URI: https://www.tipsandtricks-hq.com/ 9 10 License: GPLv2 or later 10 11 */ 11 12 12 if (!defined('ABSPATH'))exit; //Exit if accessed directly 13 if (!defined('ABSPATH')) { 14 exit; //Exit if accessed directly 15 } 13 16 14 17 include_once('https-rules-helper.php'); 15 18 include_once('https-redirection-settings.php'); 16 19 17 function add_httpsrdrctn_admin_menu() {18 add_submenu_page('options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page', plugins_url("images/px.png", __FILE__), 1001);19 }20 21 20 function httpsrdrctn_plugin_init() { 22 21 global $httpsrdrctn_options; 23 /* Internationalization, first(!) */24 load_plugin_textdomain('https_redirection', false, dirname(plugin_basename(__FILE__)) . '/languages/');25 22 if (empty($httpsrdrctn_options)) { 26 23 $httpsrdrctn_options = get_option('httpsrdrctn_options'); … … 30 27 if (isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1') { 31 28 //Handle the appropriate content filters to force the static resources to use HTTPS URL 32 //TODO 1 33 add_filter( 'the_content', 'httpsrdrctn_the_content' ); 34 add_filter( 'get_the_content', 'httpsrdrctn_the_content' ); 35 add_filter( 'the_excerpt', 'httpsrdrctn_the_content' ); 36 add_filter( 'get_the_excerpt', 'httpsrdrctn_the_content' ); 37 } 38 29 if (is_admin()) { 30 add_action("admin_init", "httpsrdrctn_start_buffer"); 31 } else { 32 add_action("init", "httpsrdrctn_start_buffer"); 33 add_action("init", "httpsrdrctn_init_time_tasks"); 34 } 35 add_action("shutdown", "httpsrdrctn_end_buffer"); 36 } 37 } 38 39 function httpsrdrctn_start_buffer() { 40 ob_start("httpsrdrctn_the_content"); 41 } 42 43 function httpsrdrctn_end_buffer() { 44 if (ob_get_length()) 45 ob_end_flush(); 46 } 47 48 function httpsrdrctn_init_time_tasks() { 49 httpsrdrctn_load_language(); 50 } 51 52 function httpsrdrctn_load_language() { 53 /* Internationalization */ 54 load_plugin_textdomain('https_redirection', false, dirname(plugin_basename(__FILE__)) . '/languages/'); 39 55 } 40 56 … … 45 61 46 62 /* Call register settings function */ 47 if (isset($_GET['page']) && "https-redirection" == $_GET['page']) {63 if (isset($_GET['page']) && "https-redirection" == $_GET['page']) { 48 64 register_httpsrdrctn_settings(); 49 65 } 50 66 } 51 67 52 /* register settings function */68 /* Register settings function */ 53 69 function register_httpsrdrctn_settings() { 54 70 global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info; … … 98 114 } 99 115 100 101 if (!function_exists('httpsrdrctn_register_plugin_links')) { 102 103 function httpsrdrctn_register_plugin_links($links, $file) { 104 $base = plugin_basename(__FILE__); 105 if ($file == $base) { 106 $links[] = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>'; 107 } 108 return $links; 109 } 110 111 } 112 113 /* 116 function httpsrdrctn_register_plugin_links($links, $file) { 117 $base = plugin_basename(__FILE__); 118 if ($file == $base) { 119 $links[] = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>'; 120 } 121 return $links; 122 } 123 124 /* 114 125 * Function that changes "http" embeds to "https" 115 126 * TODO - Need to make it better so it only does it for static resources like JS, CSS and Images 116 127 */ 128 function httpsrdrctn_filter_content($content) { 129 //filter buffer 130 $home_no_www = str_replace("://www.", "://", get_option('home')); 131 $home_yes_www = str_replace("://", "://www.", $home_no_www); 132 133 $http_urls = array( 134 str_replace("https://", "http://", $home_yes_www), 135 str_replace("https://", "http://", $home_no_www), 136 "src='http://", 137 'src="http://', 138 ); 139 $ssl_array = str_replace("http://", "https://", $http_urls); 140 //now replace these links 141 $str = str_replace($http_urls, $ssl_array, $content); 142 143 //replace all http links except hyperlinks 144 //all tags with src attr are already fixed by str_replace 145 $pattern = array( 146 '/url\([\'"]?\K(http:\/\/)(?=[^)]+)/i', 147 '/<link .*?href=[\'"]\K(http:\/\/)(?=[^\'"]+)/i', 148 '/<meta property="og:image" .*?content=[\'"]\K(http:\/\/)(?=[^\'"]+)/i', 149 '/<form [^>]*?action=[\'"]\K(http:\/\/)(?=[^\'"]+)/i', 150 ); 151 $str = preg_replace($pattern, 'https://', $str); 152 return $str; 153 } 154 117 155 function httpsrdrctn_the_content($content) { 118 156 global $httpsrdrctn_options; … … 120 158 $httpsrdrctn_options = get_option('httpsrdrctn_options'); 121 159 } 160 161 $current_page = sanitize_post($GLOBALS['wp_the_query']->get_queried_object()); 162 // Get the page slug 163 $slug =str_replace(home_url().'/','',get_permalink($current_page)); 164 122 165 if ($httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1) { 123 166 if ($httpsrdrctn_options['https_domain'] == 1) { 124 if (strpos(home_url(), 'https') !== false) { 125 $http_domain = str_replace('https', 'http', home_url()); 126 $https_domain = home_url(); 127 } else { 128 $http_domain = home_url(); 129 $https_domain = str_replace('http', 'https', home_url()); 130 } 131 $content = str_replace($http_domain, $https_domain, $content); 167 $content = httpsrdrctn_filter_content($content); 132 168 } else if (!empty($httpsrdrctn_options['https_pages_array'])) { 133 169 foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) { 134 if (strpos(home_url(), 'https') !== false) { 135 $http_domain = str_replace('https', 'http', home_url()); 136 $https_domain = home_url(); 137 } else { 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); 172 } else { //if not - let's replace all links to that page only to https 138 173 $http_domain = home_url(); 139 $https_domain = str_replace('http', 'https', home_url()); 174 $https_domain = str_replace('http://', 'https://', home_url()); 175 $content = str_replace($http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content); 140 176 } 141 $content = str_replace($http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content);142 177 } 143 178 } … … 167 202 } 168 203 204 function add_httpsrdrctn_admin_menu() { 205 add_submenu_page('options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page', plugins_url("images/px.png", __FILE__), 1001); 206 } 207 169 208 add_action('admin_menu', 'add_httpsrdrctn_admin_menu'); 170 add_action('init', 'httpsrdrctn_plugin_init');171 209 add_action('admin_init', 'httpsrdrctn_plugin_admin_init'); 172 210 add_action('admin_enqueue_scripts', 'httpsrdrctn_admin_head'); … … 179 217 180 218 register_uninstall_hook(__FILE__, 'httpsrdrctn_delete_options'); 219 220 httpsrdrctn_plugin_init();
Note: See TracChangeset
for help on using the changeset viewer.