PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110913
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110913
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / includes / classes / ssl-in.inc.php

ssl-in.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110913, at includes/classes/ssl-in.inc.php

178 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SSL routines ( inner processing routines ).
4 *
5 * Copyright: © 2009-2011
6 * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
7 * ( coded in the USA )
8 *
9 * Released under the terms of the GNU General Public License.
10 * You should have received a copy of the GNU General Public License,
11 * along with this software. In the main directory, see: /licensing/
12 * If not, see: {@link http://www.gnu.org/licenses/}.
13 *
14 * @package s2Member\SSL
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit ("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_ssl_in"))
21 {
22 /**
23 * SSL routines ( inner processing routines ).
24 *
25 * @package s2Member\SSL
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_ssl_in
29 {
30 /**
31 * Forces SSL on specific Posts/Pages, or any page for that matter.
32 *
33 * Triggered by Custom Field: `s2member_force_ssl = yes|port#`
34 *
35 * Triggered by: `?s2-ssl` or `?s2-ssl=yes|port#`.
36 *
37 * @package s2Member\SSL
38 * @since 3.5
39 *
40 * @attaches-to: ``add_action("init");``
41 * @attaches-to: ``add_action("template_redirect");``
42 *
43 * @return null Possibly exiting script execution after redirection to SSL variation.
44 */
45 public static function force_ssl ($vars = array ()) /* Phase 2 of ``c_ws_plugin__s2member_ssl::check_force_ssl()``. */
46 {
47 extract ($vars); /* Extract all vars passed in from: ``c_ws_plugin__s2member_ssl::check_force_ssl()``. */
48 /**/
49 $force_ssl = (!is_string ($force_ssl)) ? (string)(int)$force_ssl : $force_ssl; /* Force string. */
50 $force_ssl = (is_numeric ($force_ssl) && $force_ssl > 1) ? $force_ssl : "yes"; /* Use `yes`. */
51 /**/
52 $ssl_host = preg_replace ("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"]); /* Remove port here. */
53 $ssl_port = (is_numeric ($force_ssl) && $force_ssl > 1) ? $force_ssl : false; /* Port? */
54 $ssl_host_port = $ssl_host . (($ssl_port) ? ":" . $ssl_port : ""); /* Use port # ? */
55 /**/
56 if (!is_ssl () || !isset ($_GET[$s2_ssl_gv])) /* SSL must be enabled. */
57 {
58 $https = "https://" . $ssl_host_port . $_SERVER["REQUEST_URI"];
59 $https_with_s2_ssl_gv = add_query_arg ($s2_ssl_gv, urlencode ($force_ssl), $https);
60 /**/
61 wp_redirect ($https_with_s2_ssl_gv) . exit ();
62 }
63 else /* Otherwise, we buffer all output, and switch all content over to https. */
64 /* Also, we assume here that other links on the site should NOT be converted to https. */
65 {
66 add_filter ("redirect_canonical", "__return_false");
67 /**/
68 define ("_ws_plugin__s2member_force_ssl_host", $ssl_host);
69 define ("_ws_plugin__s2member_force_ssl_port", $ssl_port);
70 define ("_ws_plugin__s2member_force_ssl_host_port", $ssl_host_port);
71 /**/
72 /* Filter these. We do NOT want to create a sitewide https conversion! */
73 add_filter ("home_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
74 add_filter ("network_home_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
75 add_filter ("site_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
76 add_filter ("network_site_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
77 /*
78 These additional URLs are NOT Filtered by default; but can be if needed. Use these Filters. */
79 if (apply_filters ("_ws_plugin__s2member_force_non_ssl_scheme_plugins_url", false, get_defined_vars ()))
80 add_filter ("plugins_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 2);
81 /*
82 These additional URLs are NOT Filtered by default; but can be if needed. Use these Filters. */
83 if (apply_filters ("_ws_plugin__s2member_force_non_ssl_scheme_content_url", false, get_defined_vars ()))
84 add_filter ("content_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 2);
85 /**/
86 if (!function_exists ("_ws_plugin__s2member_force_ssl_buffer"))
87 {
88 function _ws_plugin__s2member_force_ssl_buffer ($buffer = FALSE)
89 {
90 $o_pcre = @ini_get ("pcre.backtrack_limit"); /* Current configuration. */
91 /**/
92 @ini_set ("pcre.backtrack_limit", 10000000); /* Expands abilities for this routine. */
93 /**/
94 $ssl_tags = array ("script", "style", "link", "img", "input", "iframe", "object", "embed");
95 $ssl_tags = apply_filters ("_ws_plugin__s2member_force_ssl_buffer_tags_array", $ssl_tags, get_defined_vars ());
96 $ssl_tags = array_unique (array_map ("strtolower", $ssl_tags)); /* This array should be lowercase / unique. */
97 /**/
98 $ssl_regex_tags = implode ("|", array_map ("preg_quote", $ssl_tags)); /* Prepare for regex. */
99 /**/
100 $buffer = ($ssl_regex_tags) ? preg_replace_callback ("/\<(" . $ssl_regex_tags . ")(?![a-z_0-9\-])[^\>]+\>/i", "_ws_plugin__s2member_force_ssl_buffer_callback", $buffer) : $buffer;
101 $buffer = (in_array ("object", $ssl_tags)) ? preg_replace_callback ("/\<object(?![a-z_0-9\-])[^\>]*\>.*?\<\/object\>/is", "_ws_plugin__s2member_force_ssl_buffer_callback", $buffer) : $buffer;
102 $buffer = (in_array ("script", $ssl_tags)) ? preg_replace_callback ("/\<script(?![a-z_0-9\-])[^\>]*\>.*?\<\/script\>/is", "_ws_plugin__s2member_force_ssl_buffer_callback", $buffer) : $buffer;
103 $buffer = (in_array ("style", $ssl_tags)) ? preg_replace_callback ("/\<style(?![a-z_0-9\-])[^\>]*\>.*?\<\/style\>/is", "_ws_plugin__s2member_force_ssl_buffer_callback", $buffer) : $buffer;
104 /**/
105 $non_ssl_tags = array ("a"); /* Tags that should NOT contain SSL-enabled links in them. Prevents site-wide conversions */
106 $non_ssl_tags = apply_filters ("_ws_plugin__s2member_force_non_ssl_buffer_tags_array", $non_ssl_tags, get_defined_vars ());
107 $non_ssl_tags = array_unique (array_map ("strtolower", $non_ssl_tags)); /* This array should be lowercase / unique. */
108 /**/
109 $non_ssl_regex_tags = implode ("|", array_map ("preg_quote", $non_ssl_tags)); /* Prepare for regex. */
110 /**/
111 $buffer = ($non_ssl_regex_tags) ? preg_replace_callback ("/\<(" . $non_ssl_regex_tags . ")(?![a-z_0-9\-])[^\>]+\>/i", "_ws_plugin__s2member_force_non_ssl_buffer_callback", $buffer) : $buffer;
112 /**/
113 @ini_set ("pcre.backtrack_limit", $o_pcre); /* Restores previous configuration value now. */
114 /**/
115 return apply_filters ("_ws_plugin__s2member_force_ssl_buffer", $buffer, get_defined_vars ());
116 }
117 }
118 /**/
119 if (!function_exists ("_ws_plugin__s2member_force_ssl_buffer_callback"))
120 {
121 function _ws_plugin__s2member_force_ssl_buffer_callback ($m = FALSE)
122 {
123 $s = preg_replace ("/http\:\/\//i", "https://", $m[0]); /* Conversion. */
124 /**/
125 if (_ws_plugin__s2member_force_ssl_port && _ws_plugin__s2member_force_ssl_host && _ws_plugin__s2member_force_ssl_host_port) /* Need port conversions? */
126 $s = preg_replace ("/\/" . preg_quote (_ws_plugin__s2member_force_ssl_host, "/") . "(\:[0-9]+)?\//i", "/" . _ws_plugin__s2member_force_ssl_host_port . "/", $s);
127 /**/
128 $s = (strtolower ($m[1]) === "link" && preg_match ("/['\"]alternate['\"]/i", $m[0])) ? $m[0] : $s; /* Alternates are fine to leave like they are. */
129 /**/
130 return $s; /* Return string with conversions. */
131 }
132 }
133 /**/
134 if (!function_exists ("_ws_plugin__s2member_force_non_ssl_buffer_callback"))
135 {
136 function _ws_plugin__s2member_force_non_ssl_buffer_callback ($m = FALSE)
137 {
138 $s = preg_replace ("/https\:\/\/" . preg_quote (_ws_plugin__s2member_force_ssl_host_port, "/") . "/i", "http://" . _ws_plugin__s2member_force_ssl_host, $m[0]);
139 /**/
140 $s = preg_replace ("/https\:\/\/" . preg_quote (_ws_plugin__s2member_force_ssl_host, "/") . "/i", "http://" . _ws_plugin__s2member_force_ssl_host, $s);
141 /*
142 Data gets converted to prevent a site-wide conversion over to SSL links.
143 */
144 return $s; /* Return string with conversions. */
145 }
146 }
147 /**/
148 if (!function_exists ("_ws_plugin__s2member_force_non_ssl_scheme"))
149 {
150 function _ws_plugin__s2member_force_non_ssl_scheme ($url = FALSE, $path = FALSE, $scheme = FALSE)
151 {
152 if (!in_array ($scheme, array ("http", "https"))) /* If NOT explicitly passed through. */
153 {
154 /* Allows for special exceptions to the rule of always forcing a non-SSL scheme. */
155 if (($scheme === "login_post" || $scheme === "rpc") && (force_ssl_login () || force_ssl_admin ()))
156 $scheme = "https";
157 else if ($scheme === "login" && force_ssl_admin ())
158 $scheme = "https";
159 else if ($scheme === "admin" && force_ssl_admin ())
160 $scheme = "https";
161 else /* Defaults to http. */
162 $scheme = "http";
163 }
164 /**/
165 $scheme = apply_filters ("_ws_plugin__s2member_force_non_ssl_scheme", $scheme, get_defined_vars ());
166 /**/
167 return preg_replace ("/^http(s)?\:\/\//i", $scheme . "://", $url);
168 }
169 }
170 /**/
171 ob_start ("_ws_plugin__s2member_force_ssl_buffer");
172 }
173 /**/
174 return; /* Return for uniformity. */
175 }
176 }
177 }
178 ?>