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

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

116 lines 7.5 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 if ($starting_dir && is_dir ($starting_dir))
40 for ($i = 0, $dir = $starting_dir; $i <= 20; $i++)
41 {
42 for ($one_dir_up = 0; $one_dir_up < $i; $one_dir_up++)
43 $dir = dirname ($dir);
44 /**/
45 if (file_exists ($dir . "/wp-settings.php"))
46 return ($wp_dir = $dir);
47 }
48 /**/
49 if ($alt_starting_dir && is_dir ($alt_starting_dir))
50 for ($i = 0, $dir = $alt_starting_dir; $i <= 20; $i++)
51 {
52 for ($one_dir_up = 0; $one_dir_up < $i; $one_dir_up++)
53 $dir = dirname ($dir);
54 /**/
55 if (file_exists ($dir . "/wp-settings.php"))
56 return ($wp_dir = $dir);
57 }
58 /**/
59 header("Content-Type: text/plain; charset=utf-8") . eval ('while (@ob_end_clean ());');
60 header("HTTP/1.0 500 Error") . exit ("ERROR: s2Member® unable to locate WordPress® directory.");
61 }
62 /*
63 * WordPress® settings, after ``SHORTINIT`` section.
64 *
65 * @package s2Member\Utilities
66 * @since 110912
67 *
68 * @param str $wp_dir WordPress® directory path.
69 * @param str $o_file Location of calling `*-o.php` file.
70 * @return str|bool WordPress® settings, else false on failure.
71 */
72 public static function wp_settings_as ($wp_dir = FALSE, $o_file = FALSE)
73 {
74 if ($wp_dir && is_dir ($wp_dir) && file_exists ($wp_dir . "/wp-settings.php") && $o_file && file_exists ($o_file))
75 if (($wp_settings = $_wp_settings = trim (file_get_contents ($wp_dir . "/wp-settings.php"))))
76 {
77 $wp_shortinit_section = "/if *\( *SHORTINIT *\)[\r\n\t\s ]*\{?[\r\n\t\s ]*return false;[\r\n\t\s ]*\}?[\r\n\t\s ]*/";
78 if (($_wp_settings_parts = preg_split ($wp_shortinit_section, $_wp_settings, 2)) && ($_wp_settings = trim ($_wp_settings_parts[1])) && ($_wp_settings = "<?php\n" . $_wp_settings))
79 {
80 if (($_wp_settings = str_replace ("__FILE__", "'" . str_replace ("'", "\'", $wp_dir) . "/wp-settings.php'", $_wp_settings))) /* Eval compatible. Hard-code `../wp-settings.php`. */
81 {
82 $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 *\);/";
83 $mu_plugins_replace = "\nif (file_exists (WPMU_PLUGIN_DIR . \"/s2member-o.php\"))\n\tinclude_once WPMU_PLUGIN_DIR . \"/s2member-o.php\";"; /* Supports special file: `s2member-o.php`. */
84 if (($_wp_settings = preg_replace ($mu_plugins_section, $mu_plugins_replace, $_wp_settings, 1, $mu_plugins_replaced)) && $mu_plugins_replaced)
85 {
86 $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 *\);/";
87 $nw_plugins_replace = /* Not even in the plugins directory? » */ "\n\$ws_plugin__s2member_temp_s = preg_replace (\"/-o\\.php\$/\", \".php\", __FILE__);\n\nif (!file_exists (WP_PLUGIN_DIR . \"/\" . plugin_basename (\$ws_plugin__s2member_temp_s)) && file_exists (\$ws_plugin__s2member_temp_s))\n\tinclude_once \$ws_plugin__s2member_temp_s;\n";
88 $nw_plugins_replace .= "\n\$ws_plugin__s2member_temp_s = plugin_basename (preg_replace (\"/-o\\.php\$/\", \".php\", __FILE__));\n\$ws_plugin__s2member_temp_a = is_multisite () ? wp_get_active_network_plugins () : array ();\n\nif (in_array (WP_PLUGIN_DIR . \"/\" . \$ws_plugin__s2member_temp_s, \$ws_plugin__s2member_temp_a))\n\tinclude_once WP_PLUGIN_DIR . \"/\" . \$ws_plugin__s2member_temp_s;\n\nunset (\$ws_plugin__s2member_temp_s, \$ws_plugin__s2member_temp_a);";
89 if (($_wp_settings = preg_replace ($nw_plugins_section, $nw_plugins_replace, $_wp_settings, 1, $nw_plugins_replaced)) && $nw_plugins_replaced)
90 {
91 $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 *\);/";
92 $st_plugins_replace = /* Not even in the plugins directory? » */ "\n\$ws_plugin__s2member_temp_s = preg_replace (\"/-o\\.php\$/\", \".php\", __FILE__);\n\nif (!file_exists (WP_PLUGIN_DIR . \"/\" . plugin_basename (\$ws_plugin__s2member_temp_s)) && file_exists (\$ws_plugin__s2member_temp_s))\n\tinclude_once \$ws_plugin__s2member_temp_s;\n";
93 $st_plugins_replace .= "\n\$ws_plugin__s2member_temp_s = plugin_basename (preg_replace (\"/-o\\.php\$/\", \".php\", __FILE__));\n\$ws_plugin__s2member_temp_a = wp_get_active_and_valid_plugins ();\n\nif (in_array (WP_PLUGIN_DIR . \"/\" . \$ws_plugin__s2member_temp_s, \$ws_plugin__s2member_temp_a))\n\tinclude_once WP_PLUGIN_DIR . \"/\" . \$ws_plugin__s2member_temp_s;\n\nunset (\$ws_plugin__s2member_temp_s, \$ws_plugin__s2member_temp_a);";
94 if (($_wp_settings = preg_replace ($st_plugins_section, $st_plugins_replace, $_wp_settings, 1, $st_plugins_replaced)) && $st_plugins_replaced)
95 {
96 $theme_funcs_section = "/(?:[\r\n\t\s ]+\/\/ Load the functions for the active theme, for both parent and child theme if applicable\.)?[\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 ]*\}/";
97 if (($_wp_settings = preg_replace ($theme_funcs_section, "", $_wp_settings, 1, $theme_funcs_replaced)) && $theme_funcs_replaced)
98 {
99 if (($_wp_settings = str_replace ("__FILE__", '"' . str_replace ('"', '\"', $o_file) . '"', $_wp_settings)))
100 {
101 if (($_wp_settings = trim ($_wp_settings))) /* WordPress®, with s2Member only. */
102 return $_wp_settings;
103 }
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 /**/
112 return false; /* Default return. */
113 }
114 }
115 }
116 ?>