PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 120213
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v120213
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 120213, at includes/classes/ssl-in.inc.php

170 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 * @also-attaches-to ``add_action("wp");``
42 *
43 * @return null Possibly exiting script execution after redirection to SSL variation.
44 *
45 * @todo Add `form` to the array ``$non_ssl_attr_only_tags``?
46 * @todo Cleanup this routine and convert callback functions to static class methods?
47 */
48 public static function force_ssl($vars = array()) /* Phase 2 of ``c_ws_plugin__s2member_ssl::check_force_ssl()``. */
49 {
50 extract /* Extract all vars passed in from: ``c_ws_plugin__s2member_ssl::check_force_ssl()``. */($vars);
51 /**/
52 $force_ssl = (!is_string($force_ssl)) ? /* Force string. */ (string)(int)$force_ssl : $force_ssl;
53 $force_ssl = (is_numeric($force_ssl) && $force_ssl > 1) ? $force_ssl : /* Use `yes`. */ "yes";
54 /**/
55 $ssl_host = /* Remove port here. */ preg_replace("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"]);
56 $ssl_port = /* Port? */ (is_numeric($force_ssl) && $force_ssl > 1) ? $force_ssl : false;
57 $ssl_host_port = /* Use port #? */ $ssl_host.(($ssl_port) ? ":".$ssl_port : "");
58 /**/
59 if(!is_ssl() || !isset($_GET[$s2_ssl_gv]) /* SSL must be enabled. */)
60 {
61 $https = "https://".$ssl_host_port.$_SERVER["REQUEST_URI"];
62 $https_with_s2_ssl_gv = add_query_arg($s2_ssl_gv, urlencode($force_ssl), $https);
63 wp_redirect($https_with_s2_ssl_gv).exit();
64 }
65 else /* Otherwise, we buffer all output, and switch all content over to `https`. */
66 /* Assume here that other links on the site should NOT be converted to `https`. */
67 {
68 add_filter("redirect_canonical", "__return_false");
69 /**/
70 define("_ws_plugin__s2member_force_ssl_host", $ssl_host);
71 define("_ws_plugin__s2member_force_ssl_port", $ssl_port);
72 define("_ws_plugin__s2member_force_ssl_host_port", $ssl_host_port);
73 /**/
74 /* Filter these. Do NOT create a sitewide conversion to `https`. */
75 add_filter("home_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
76 add_filter("network_home_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
77 /**/
78 /* Filter these. Do NOT create a sitewide conversion to `https`. */
79 add_filter("site_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
80 add_filter("network_site_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
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_plugins_url", false, get_defined_vars()))
84 add_filter("plugins_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 2);
85 /*
86 These additional URLs are NOT Filtered by default; but can be if needed. Use these Filters. */
87 if(apply_filters("_ws_plugin__s2member_force_non_ssl_scheme_content_url", false, get_defined_vars()))
88 add_filter("content_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 2);
89 /*
90 Now we create various callback functions associated with SSL and non-SSL buffering.
91 */
92 if(!function_exists("_ws_plugin__s2member_force_ssl_buffer_callback"))
93 {
94 function _ws_plugin__s2member_force_ssl_buffer_callback($m = FALSE)
95 {
96 $s = /* Conversion to SSL mode via `https`. */ preg_replace("/http\:\/\//i", "https://", $m[0]);
97 /**/
98 if(_ws_plugin__s2member_force_ssl_host && /* Convert port? */ _ws_plugin__s2member_force_ssl_port && _ws_plugin__s2member_force_ssl_host_port)
99 $s = preg_replace("/(?:https?\:)?\/\/".preg_quote(_ws_plugin__s2member_force_ssl_host, "/")."(?:\:[0-9]+)?/i", "https://"._ws_plugin__s2member_force_ssl_host_port, $s);
100 /**/
101 $s = (strtolower($m[1]) === "link" && preg_match /* These are fine to leave like they are. */("/['\"](?:alternate|profile|pingback|EditURI|wlwmanifest|prev|next)['\"]/i", $m[0])) ? $m[0] : $s;
102 /**/
103 return /* Return string with conversions. */ $s;
104 }
105 }
106 /**/
107 if(!function_exists("_ws_plugin__s2member_force_non_ssl_buffer_callback"))
108 {
109 function _ws_plugin__s2member_force_non_ssl_buffer_callback($m = FALSE)
110 {
111 $s = preg_replace("/(?:https?\:)?\/\/".preg_quote(_ws_plugin__s2member_force_ssl_host_port, "/")."/i", "http://"._ws_plugin__s2member_force_ssl_host, $m[0]);
112 /**/
113 $s = preg_replace("/(?:https?\:)?\/\/".preg_quote(_ws_plugin__s2member_force_ssl_host, "/")."/i", "http://"._ws_plugin__s2member_force_ssl_host, $s);
114 /**/
115 return /* Return string with conversions. */ $s;
116 }
117 }
118 /**/
119 if(!function_exists("_ws_plugin__s2member_force_non_ssl_scheme"))
120 {
121 function _ws_plugin__s2member_force_non_ssl_scheme($url = FALSE, $path = FALSE, $scheme = FALSE)
122 {
123 if(!in_array /* If NOT explicitly passed through. */($scheme, array("http", "https"), true))
124 {
125 if(($scheme === "login_post" || $scheme === "rpc") && (force_ssl_login() || force_ssl_admin()))
126 $scheme = "https";
127 /**/
128 else if(($scheme === "login" || $scheme === "admin") && force_ssl_admin())
129 $scheme = "https";
130 /**/
131 else /* Default to non-SSL: `http`. */
132 $scheme = "http";
133 }
134 return preg_replace("/^(?:https?\:)?\/\//i", $scheme."://", $url);
135 }
136 }
137 /**/
138 if(!function_exists("_ws_plugin__s2member_force_ssl_buffer"))
139 {
140 function _ws_plugin__s2member_force_ssl_buffer($buffer = FALSE)
141 {
142 $o_pcre = /* Record existing PCRE backtrack limit. */ @ini_get("pcre.backtrack_limit");
143 @ini_set /* Increase PCRE backtrack limit for this routine. */("pcre.backtrack_limit", 10000000);
144 /**/
145 $ssl_entire_tags = array_unique(array_map("strtolower", apply_filters("_ws_plugin__s2member_force_ssl_buffer_entire_tags", array("script", "style", "iframe", "object", "embed", "video"), get_defined_vars())));
146 $non_ssl_entire_tags = array_unique(array_map("strtolower", apply_filters("_ws_plugin__s2member_force_non_ssl_buffer_entire_tags", array(), get_defined_vars())));
147 /**/
148 $ssl_attr_only_tags = array_unique( /* Diff here. No need to re-run entire tags. */array_diff(array_map("strtolower", apply_filters("_ws_plugin__s2member_force_ssl_buffer_attr_only_tags", array("link", "img", "input"), get_defined_vars())), $ssl_entire_tags));
149 $non_ssl_attr_only_tags = array_unique( /* No need to re-run entire tags. */array_diff(array_map("strtolower", apply_filters("_ws_plugin__s2member_force_non_ssl_buffer_attr_only_tags", array("a"), get_defined_vars())), $non_ssl_entire_tags));
150 /**/
151 $buffer = ($ssl_entire_tags) ? preg_replace_callback("/\<(".implode("|", c_ws_plugin__s2member_utils_strings::preg_quote_deep($ssl_entire_tags, "/")).")(?![a-z_0-9\-])[^\>]*?\>.*?\<\/\\1\>/is", "_ws_plugin__s2member_force_ssl_buffer_callback", $buffer) : $buffer;
152 $buffer = ($ssl_attr_only_tags) ? preg_replace_callback("/\<(".implode("|", c_ws_plugin__s2member_utils_strings::preg_quote_deep($ssl_attr_only_tags, "/")).")(?![a-z_0-9\-])[^\>]+?\>/i", "_ws_plugin__s2member_force_ssl_buffer_callback", $buffer) : $buffer;
153 /**/
154 $buffer = ($non_ssl_entire_tags) ? preg_replace_callback("/\<(".implode("|", c_ws_plugin__s2member_utils_strings::preg_quote_deep($non_ssl_entire_tags, "/")).")(?![a-z_0-9\-])[^\>]*?\>.*?\<\/\\1\>/is", "_ws_plugin__s2member_force_non_ssl_buffer_callback", $buffer) : $buffer;
155 $buffer = ($non_ssl_attr_only_tags) ? preg_replace_callback("/\<(".implode("|", c_ws_plugin__s2member_utils_strings::preg_quote_deep($non_ssl_attr_only_tags, "/")).")(?![a-z_0-9\-])[^\>]+?\>/i", "_ws_plugin__s2member_force_non_ssl_buffer_callback", $buffer) : $buffer;
156 /**/
157 @ini_set /* Restore original PCRE backtrack limit. This just keeps things tidy; probably NOT necessary. */("pcre.backtrack_limit", $o_pcre);
158 /**/
159 return apply_filters("_ws_plugin__s2member_force_ssl_buffer", $buffer, get_defined_vars());
160 }
161 }
162 /**/
163 ob_start("_ws_plugin__s2member_force_ssl_buffer");
164 }
165 /**/
166 return; /* Return for uniformity. */
167 }
168 }
169 }
170 ?>