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 / utils-s2o.inc.php

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

137 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * s2Member-only utilities.
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\Utilities
15 * @since 110912
16 */
17 if (!class_exists ("c_ws_plugin__s2member_utils_s2o"))
18 {
19 /**
20 * s2Member-only utilities.
21 *
22 * @package s2Member\Utilities
23 * @since 110912
24 */
25 class c_ws_plugin__s2member_utils_s2o
26 {
27 /*
28 * WordPress® directory.
29 *
30 * @package s2Member\Utilities
31 * @since 110912
32 *
33 * @param str $starting_dir A directory to start searching from.
34 * @param str $alt_starting_dir An alternate directory to search from.
35 * @return str|null WordPress® directory, else exits script execution on failure.
36 */
37 public static function wp_dir ($starting_dir = FALSE, $alt_starting_dir = FALSE)
38 {
39 foreach (array ($starting_dir, $alt_starting_dir) as $directory)
40 if ($directory && is_string ($directory) && is_dir ($directory))
41 for ($i = 0, $dir = $directory; $i <= 20; $i++)
42 {
43 for ($one_dir_up = 0; $one_dir_up < $i; $one_dir_up++)
44 $dir = dirname ($dir);
45 /**/
46 if (file_exists ($dir . "/wp-settings.php"))
47 return ($wp_dir = $dir);
48 }
49 /**/
50 header ("Content-Type: text/plain; charset=utf-8") . eval ('while (@ob_end_clean ());');
51 header ("HTTP/1.0 500 Error") . exit ("ERROR: s2Member® unable to locate WordPress® directory.");
52 }
53 /*
54 * WordPress® settings, after ``SHORTINIT`` section.
55 *
56 * @package s2Member\Utilities
57 * @since 110912
58 *
59 * @param str $wp_dir WordPress® directory path.
60 * @param str $o_file Location of calling `*-o.php` file.
61 * @return str|bool WordPress® settings, else false on failure.
62 */
63 public static function wp_settings_as ($wp_dir = FALSE, $o_file = FALSE)
64 {
65 if ($wp_dir && is_dir ($wp_dir) && is_readable (($wp_settings = $wp_dir . "/wp-settings.php")) && $o_file && file_exists ($o_file) && ($_wp_settings = trim (file_get_contents ($wp_settings))))
66 {
67 $wp_shortinit_section /* Run ``preg_match()`` to confirm existence. */ = "/if *\( *SHORTINIT *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*return false;[\r\n\t\s ]*\}?[\r\n\t\s ]*/";
68 if (preg_match ($wp_shortinit_section, $_wp_settings) && ($_wp_settings_parts = preg_split ($wp_shortinit_section, $_wp_settings, 2)) && ($_wp_settings = trim ($_wp_settings_parts[1])) && ($_wp_settings = "<?php\n" . $_wp_settings))
69 {
70 if (($_wp_settings = str_replace ("__FILE__", "'" . str_replace ("'", "\'", $wp_settings) . "'", $_wp_settings))) /* Eval compatible. Hard-code the ``__FILE__`` location here. */
71 {
72 $mu_plugins_section = "/[\r\n\t\s ]+foreach *\( *wp_get_mu_plugins *\( *\) *as *\\\$mu_plugin *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*include_once *\( *\\\$mu_plugin *\);[\r\n\t\s ]*\}?[\r\n\t\s ]*unset *\( *\\\$mu_plugin *\);/";
73 $mu_plugins_replace = "\n\n" . c_ws_plugin__s2member_utils_s2o::esc_ds (trim (c_ws_plugin__s2member_utils_s2o::evl (file_get_contents (dirname (dirname (__FILE__)) . "/templates/cfg-files/s2o-mu-plugins.php")))) . "\n";
74 if (($_wp_settings = preg_replace ($mu_plugins_section, $mu_plugins_replace, $_wp_settings, 1, $mu_plugins_replaced)) && $mu_plugins_replaced)
75 {
76 $nw_plugins_section = "/[\r\n\t\s ]+foreach *\( *wp_get_active_network_plugins *\( *\) *as *\\\$network_plugin *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*include_once *\( *\\\$network_plugin *\);[\r\n\t\s ]*\}?[\r\n\t\s ]*unset *\( *\\\$network_plugin *\);/";
77 $nw_plugins_replace = "\n\n" . c_ws_plugin__s2member_utils_s2o::esc_ds (trim (c_ws_plugin__s2member_utils_s2o::evl (file_get_contents (dirname (dirname (__FILE__)) . "/templates/cfg-files/s2o-nw-plugins.php")))) . "\n";
78 if (($_wp_settings = preg_replace ($nw_plugins_section, $nw_plugins_replace, $_wp_settings, 1, $nw_plugins_replaced)) && $nw_plugins_replaced)
79 {
80 $st_plugins_section = "/[\r\n\t\s ]+foreach *\( *wp_get_active_and_valid_plugins *\( *\) *as *\\\$plugin *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*include_once *\( *\\\$plugin *\);[\r\n\t\s ]*\}?[\r\n\t\s ]*unset *\( *\\\$plugin *\);/";
81 $st_plugins_replace = "\n\n" . c_ws_plugin__s2member_utils_s2o::esc_ds (trim (c_ws_plugin__s2member_utils_s2o::evl (file_get_contents (dirname (dirname (__FILE__)) . "/templates/cfg-files/s2o-st-plugins.php")))) . "\n";
82 if (($_wp_settings = preg_replace ($st_plugins_section, $st_plugins_replace, $_wp_settings, 1, $st_plugins_replaced)) && $st_plugins_replaced)
83 {
84 $th_funcs_section = "/[\r\n\t\s ]+if *\( *\! *defined *\( *['\"]WP_INSTALLING['\"] *\) *\|\| *['\"]wp-activate.php['\"] *\=\=\= *\\\$pagenow *\)[\r\n\t\s ]*\{[\r\n\t\s ]*if *\( *TEMPLATEPATH *\!\=\= *STYLESHEETPATH *&& *file_exists *\( *STYLESHEETPATH *\. *['\"]\/functions\.php['\"] *\) *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*include *\( *STYLESHEETPATH *\. *['\"]\/functions\.php['\"] *\);[\r\n\t\s ]*\}?[\r\n\t\s ]*if *\( *file_exists *\( *TEMPLATEPATH *\. *['\"]\/functions\.php['\"] *\) *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*include *\( *TEMPLATEPATH *\. *['\"]\/functions\.php['\"] *\);[\r\n\t\s ]*\}?[\r\n\t\s ]*\}/";
85 $th_funcs_replace = "\n\n" . c_ws_plugin__s2member_utils_s2o::esc_ds (trim (c_ws_plugin__s2member_utils_s2o::evl (file_get_contents (dirname (dirname (__FILE__)) . "/templates/cfg-files/s2o-th-funcs.php")))) . "\n";
86 if (($_wp_settings = preg_replace ($th_funcs_section, $th_funcs_replace, $_wp_settings, 1, $th_funcs_replaced)) && $th_funcs_replaced)
87 {
88 if (($_wp_settings = str_replace ("__FILE__", '"' . str_replace ('"', '\"', $o_file) . '"', $_wp_settings))) /* Eval compatible. */
89 {
90 if (($_wp_settings = trim ($_wp_settings))) /* WordPress®, with s2Member only. */
91 return ($wp_settings_as = $_wp_settings); /* After ``SHORTINIT``. */
92 }
93 }
94 }
95 }
96 }
97 }
98 }
99 }
100 /**/
101 return false;
102 }
103 /**
104 * Escapes dollars signs ( for regex patterns ).
105 *
106 * @package s2Member\Utilities
107 * @since 110917
108 *
109 * @param str $string Input string.
110 * @param int $times Mumber of escapes. Defaults to 1.
111 * @return str Output string after dollar signs are escaped.
112 */
113 public static function esc_ds ($string = FALSE, $times = FALSE)
114 {
115 $times = (is_numeric ($times) && $times >= 0) ? (int)$times : 1;
116 return str_replace ('$', str_repeat ("\\", $times) . '$', (string)$string);
117 }
118 /**
119 * Evaluates PHP code, and "returns" output.
120 *
121 * @package s2Member\Utilities
122 * @since 110917
123 *
124 * @param str $code A string of data, possibly with embedded PHP code.
125 * @return str Output after PHP evaluation.
126 */
127 public static function evl ($code = FALSE)
128 {
129 ob_start (); /* Output buffer. */
130 /**/
131 eval ("?>" . trim ($code));
132 /**/
133 return ob_get_clean ();
134 }
135 }
136 }
137 ?>