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-conds.inc.php

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

193 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Conditional 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 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_utils_conds"))
21 {
22 /**
23 * Conditional utilities.
24 *
25 * @package s2Member\Utilities
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_utils_conds
29 {
30 /**
31 * Determines whether or not s2Member Pro is installed.
32 *
33 * @package s2Member\Utilities
34 * @since 110720
35 *
36 * @return bool True if s2Member Pro is installed, else false.
37 */
38 public static function pro_is_installed ()
39 {
40 return (defined ("WS_PLUGIN__S2MEMBER_PRO_VERSION") && did_action ("ws_plugin__s2member_pro_loaded"));
41 }
42 /**
43 * Determines whether or not BuddyPress is installed.
44 *
45 * @package s2Member\Utilities
46 * @since 110720
47 *
48 * @param bool $query_active_plugins Optional. If true, this conditional will query active plugins too. Defaults to true if {@link s2Member\WS_PLUGIN__S2MEMBER_ONLY} is true, else false.
49 * @return bool True if BuddyPress is installed, else false.
50 */
51 public static function bp_is_installed ($query_active_plugins = NULL)
52 {
53 if (defined ("BP_VERSION") && did_action ("bp_core_loaded"))
54 return true; /* Quickest/easiest way to determine. */
55 /**/
56 $s2o = (defined ("WS_PLUGIN__S2MEMBER_ONLY") && WS_PLUGIN__S2MEMBER_ONLY) ? true : false;
57 /**/
58 if (($query_active_plugins = (!isset ($query_active_plugins) && $s2o) ? true : $query_active_plugins))
59 {
60 $buddypress = "buddypress/bp-loader.php"; /* BuddyPress. */
61 /**/
62 $active_plugins = (is_multisite ()) ? wp_get_active_network_plugins () : array ();
63 $active_plugins = array_unique (array_merge ($active_plugins, wp_get_active_and_valid_plugins ()));
64 /**/
65 foreach ($active_plugins as $active_plugin) /* Search. */
66 if (plugin_basename ($active_plugin) === $buddypress)
67 return true; /* BuddyPress active. */
68 }
69 return false; /* Default return false. */
70 }
71 /**
72 * Determines whether or not this is a Multisite Farm;
73 * *( i.e. if ``MULTISITE_FARM == true`` inside `/wp-config.php` )*.
74 *
75 * With s2Member, this option may also indicate a Multisite Blog Farm.
76 * ``$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_file"] === "wp-signup"``.
77 *
78 * @package s2Member\Utilities
79 * @since 3.5
80 *
81 * @return bool True if this is a Multisite Farm, else false.
82 */
83 public static function is_multisite_farm ()
84 {
85 return (is_multisite () && ((is_main_site () && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_file"] === "wp-signup") || (defined ("MULTISITE_FARM") && MULTISITE_FARM)));
86 }
87 /**
88 * Checks if a Post is in a child Category.
89 *
90 * @package s2Member\Utilities
91 * @since 3.5
92 *
93 * @param array $cats An array of Category IDs.
94 * @param int|str $post_id A numeric WordPress® Post ID.
95 * @return bool True if the Post is inside a desendant of at least one of the specified Categories; else false.
96 */
97 public static function in_descendant_category ($cats = FALSE, $post_id = FALSE)
98 {
99 foreach ((array)$cats as $cat)
100 {
101 $descendants = get_term_children ((int)$cat, "category");
102
103 if ($descendants && in_category ($descendants, $post_id))
104 return true;
105 }
106
107 return false; /* Default return false. */
108 }
109 /**
110 * Checks to see if a URL/URI leads to the site root.
111 *
112 * @package s2Member\Utilities
113 * @since 3.5
114 *
115 * @param str $url_uri Either a full URL, or a partial URI to test.
116 * @return bool True if the URL or URI leads to the site root, else false.
117 */
118 public static function is_site_root ($url_uri = FALSE)
119 {
120 if (is_array ($parse = c_ws_plugin__s2member_utils_urls::parse_url ($url_uri)))
121 {
122 $parse["path"] = (!empty ($parse["path"])) ? ((strpos ($parse["path"], "/") === 0) ? $parse["path"] : "/" . $parse["path"]) : "/";
123 /**/
124 if (empty ($parse["host"]) || strcasecmp ($parse["host"], c_ws_plugin__s2member_utils_urls::parse_url (site_url (), PHP_URL_HOST)) === 0)
125 if ($parse["path"] === "/" || rtrim ($parse["path"], "/") === rtrim (c_ws_plugin__s2member_utils_urls::parse_url (site_url (), PHP_URL_PATH), "/"))
126 return true;
127 }
128
129 return false; /* Default return false. */
130 }
131 /**
132 * Checks to see if we're in a localhost environment.
133 *
134 * @package s2Member\Utilities
135 * @since 111101
136 *
137 * @return bool True if we're in a localhost environment, else false.
138 */
139 public static function is_localhost ()
140 {
141 if ((defined ("LOCALHOST") && LOCALHOST) || stripos ($_SERVER["HTTP_HOST"], "localhost") !== false || strpos ($_SERVER["HTTP_HOST"], "127.0.0.1") !== false)
142 return true;
143 /**/
144 return /* Default return false. */ false;
145 }
146 /**
147 * Checks to see if we're using Amazon® S3.
148 *
149 * @package s2Member\Utilities
150 * @since 110926
151 *
152 * @return bool True if using Amazon® S3, else false.
153 */
154 public static function using_amazon_s3_storage ()
155 {
156 if (!c_ws_plugin__s2member_utils_conds::using_amazon_cf_storage ())
157 {
158 foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
159 if (preg_match ("/^amazon_s3_files_/", $option) && ($option = preg_replace ("/^amazon_s3_files_/", "", $option)))
160 $s3c[$option] = $option_value;
161 /**/
162 if ($s3c["bucket"] && $s3c["access_key"] && $s3c["secret_key"])
163 return true;
164 }
165 return false; /* Default return false. */
166 }
167 /**
168 * Checks to see if we're using Amazon® CloudFront.
169 *
170 * @package s2Member\Utilities
171 * @since 110926
172 *
173 * @return bool True if using Amazon® CloudFront, else false.
174 */
175 public static function using_amazon_cf_storage ()
176 {
177 foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
178 if (preg_match ("/^amazon_s3_files_/", $option) && ($option = preg_replace ("/^amazon_s3_files_/", "", $option)))
179 $s3c[$option] = $option_value;
180 /**/
181 foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
182 if (preg_match ("/^amazon_cf_files_/", $option) && ($option = preg_replace ("/^amazon_cf_files_/", "", $option)))
183 $cfc[$option] = $option_value;
184 /**/
185 if ($s3c["bucket"] && $s3c["access_key"] && $s3c["secret_key"])
186 if ($cfc["private_key"] && $cfc["private_key_id"] && $cfc["distros_access_id"] && $cfc["distros_s3_access_id"] && $cfc["distro_downloads_id"] && $cfc["distro_downloads_dname"] && $cfc["distro_streaming_id"] && $cfc["distro_streaming_dname"])
187 return true;
188 /**/
189 return false; /* Default return false. */
190 }
191 }
192 }
193 ?>