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

168 lines 9.5 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($vars); /* Extract all vars passed in from: ``c_ws_plugin__s2member_ssl::check_force_ssl()``. */
51 /**/
52 $force_ssl = (!is_string ($force_ssl)) ? (string)(int)$force_ssl : $force_ssl; /* Force string. */
53 $force_ssl = (is_numeric ($force_ssl) && $force_ssl > 1) ? $force_ssl : "yes"; /* Use `yes`. */
54 /**/
55 $ssl_host = preg_replace ("/\:[0-9]+$/", "", $_SERVER["HTTP_HOST"]); /* Remove port here. */
56 $ssl_port = (is_numeric ($force_ssl) && $force_ssl > 1) ? $force_ssl : false; /* Port? */
57 $ssl_host_port = $ssl_host . (($ssl_port) ? ":" . $ssl_port : ""); /* Use 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 add_filter ("site_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
78 add_filter ("network_site_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 3);
79 /*
80 These additional URLs are NOT Filtered by default; but can be if needed. Use these Filters. */
81 if (apply_filters ("_ws_plugin__s2member_force_non_ssl_scheme_plugins_url", false, get_defined_vars ()))
82 add_filter ("plugins_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 2);
83 /*
84 These additional URLs are NOT Filtered by default; but can be if needed. Use these Filters. */
85 if (apply_filters ("_ws_plugin__s2member_force_non_ssl_scheme_content_url", false, get_defined_vars ()))
86 add_filter ("content_url", "_ws_plugin__s2member_force_non_ssl_scheme", 10, 2);
87 /*
88 Now we create various callback functions associated with SSL and non-SSL buffering.
89 */
90 if (!function_exists ("_ws_plugin__s2member_force_ssl_buffer_callback")) /* Pluggable? */
91 {
92 function _ws_plugin__s2member_force_ssl_buffer_callback ($m = FALSE) /* Callback function. */
93 {
94 $s = preg_replace ("/http\:\/\//i", "https://", $m[0]); /* Conversion to SSL mode via `https`. */
95 /**/
96 if (_ws_plugin__s2member_force_ssl_host && _ws_plugin__s2member_force_ssl_port && _ws_plugin__s2member_force_ssl_host_port) /* Convert port? */
97 $s = preg_replace ("/(?:https?\:)?\/\/" . preg_quote (_ws_plugin__s2member_force_ssl_host, "/") . "(?:\:[0-9]+)?/i", "https://" . _ws_plugin__s2member_force_ssl_host_port, $s);
98 /**/
99 $s = (strtolower ($m[1]) === "link" && preg_match ("/['\"]alternate['\"]/i", $m[0])) ? $m[0] : $s; /* Alternates are fine to leave like they are. */
100 /**/
101 return $s; /* Return string with conversions. */
102 }
103 }
104 /**/
105 if (!function_exists ("_ws_plugin__s2member_force_non_ssl_buffer_callback")) /* Pluggable? */
106 {
107 function _ws_plugin__s2member_force_non_ssl_buffer_callback ($m = FALSE) /* Callback function. */
108 {
109 $s = preg_replace ("/(?:https?\:)?\/\/" . preg_quote (_ws_plugin__s2member_force_ssl_host_port, "/") . "/i", "http://" . _ws_plugin__s2member_force_ssl_host, $m[0]);
110 /**/
111 $s = preg_replace ("/(?:https?\:)?\/\/" . preg_quote (_ws_plugin__s2member_force_ssl_host, "/") . "/i", "http://" . _ws_plugin__s2member_force_ssl_host, $s);
112 /**/
113 return $s; /* Return string with conversions. */
114 }
115 }
116 /**/
117 if (!function_exists ("_ws_plugin__s2member_force_non_ssl_scheme")) /* Pluggable? */
118 {
119 function _ws_plugin__s2member_force_non_ssl_scheme ($url = FALSE, $path = FALSE, $scheme = FALSE)
120 {
121 if (!in_array ($scheme, array ("http", "https"))) /* If NOT explicitly passed through. */
122 {
123 if (($scheme === "login_post" || $scheme === "rpc") && (force_ssl_login () || force_ssl_admin ()))
124 $scheme = "https";
125 /**/
126 else if (($scheme === "login" || $scheme === "admin") && force_ssl_admin ())
127 $scheme = "https";
128 /**/
129 else /* Default to non-SSL: `http`. */
130 $scheme = "http";
131 }
132 return preg_replace ("/^(?:https?\:)?\/\//i", $scheme . "://", $url);
133 }
134 }
135 /**/
136 if (!function_exists ("_ws_plugin__s2member_force_ssl_buffer")) /* Pluggable? */
137 {
138 function _ws_plugin__s2member_force_ssl_buffer ($buffer = FALSE) /* Output handler. */
139 {
140 $o_pcre = @ini_get ("pcre.backtrack_limit"); /* Record existing PCRE backtrack limit. */
141 @ini_set ("pcre.backtrack_limit", 10000000); /* Increase PCRE backtrack limit for this routine. */
142 /**/
143 $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 ())));
144 $non_ssl_entire_tags = array_unique (array_map ("strtolower", apply_filters ("_ws_plugin__s2member_force_non_ssl_buffer_entire_tags", array (), get_defined_vars ())));
145 /**/
146 $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));
147 $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));
148 /**/
149 $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;
150 $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;
151 /**/
152 $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;
153 $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;
154 /**/
155 @ini_set ("pcre.backtrack_limit", $o_pcre); /* Restore original PCRE backtrack limit. This just keeps things tidy; probably NOT necessary. */
156 /**/
157 return apply_filters ("_ws_plugin__s2member_force_ssl_buffer", $buffer, get_defined_vars ());
158 }
159 }
160 /**/
161 ob_start("_ws_plugin__s2member_force_ssl_buffer");
162 }
163 /**/
164 return; /* Return for uniformity. */
165 }
166 }
167 }
168 ?>