PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / trunk
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions vtrunk
260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 120301 All 187 releases
s2member / src / includes / classes / utils-conds.inc.php

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

246 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreFile
3 /**
4 * Conditional utilities.
5 *
6 * Copyright: © 2009-2011
7 * {@link http://websharks-inc.com/ WebSharks, Inc.}
8 * (coded in the USA)
9 *
10 * Released under the terms of the GNU General Public License.
11 * You should have received a copy of the GNU General Public License,
12 * along with this software. In the main directory, see: /licensing/
13 * If not, see: {@link http://www.gnu.org/licenses/}.
14 *
15 * @package s2Member\Utilities
16 * @since 3.5
17 */
18 if(!defined('WPINC')) // MUST have WordPress.
19 exit('Do not access this file directly.');
20
21 if(!class_exists('c_ws_plugin__s2member_utils_conds'))
22 {
23 /**
24 * Conditional utilities.
25 *
26 * @package s2Member\Utilities
27 * @since 3.5
28 */
29 class c_ws_plugin__s2member_utils_conds
30 {
31 /**
32 * Determines whether or not s2Member Pro is installed.
33 *
34 * @package s2Member\Utilities
35 * @since 110720
36 *
37 * @return bool True if s2Member Pro is installed, else false.
38 */
39 public static function pro_is_installed()
40 {
41 return (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION') && did_action('ws_plugin__s2member_pro_loaded'));
42 }
43
44 /**
45 * Determines whether or not bbPress is installed.
46 *
47 * @package s2Member\Utilities
48 * @since 140807
49 *
50 * @param bool $query_active_plugins Optional. If true, this conditional will query active plugins too.
51 * Defaults to true if {@link s2Member\WS_PLUGIN__S2MEMBER_ONLY} is true, else false.
52 *
53 * @return bool True if bbPress is installed, else false.
54 */
55 public static function bbp_is_installed($query_active_plugins = NULL)
56 {
57 if(function_exists('bbpress'))
58 return TRUE; // Quickest/easiest way to determine.
59
60 $s2o = (defined('WS_PLUGIN__S2MEMBER_ONLY') && WS_PLUGIN__S2MEMBER_ONLY) ? TRUE : FALSE;
61
62 if(($query_active_plugins = (!isset($query_active_plugins) && $s2o) ? TRUE : $query_active_plugins))
63 {
64 $bbpress = 'bbpress/bbpress.php'; // bbPress.
65
66 $active_plugins = (is_multisite()) ? wp_get_active_network_plugins() : array();
67 $active_plugins = array_unique(array_merge($active_plugins, wp_get_active_and_valid_plugins()));
68
69 foreach($active_plugins as $active_plugin) // Search.
70 if(plugin_basename($active_plugin) === $bbpress)
71 return TRUE; // bbPress active.
72 }
73 return FALSE; // Default return false.
74 }
75
76 /**
77 * Determines whether or not BuddyPress is installed.
78 *
79 * @package s2Member\Utilities
80 * @since 110720
81 *
82 * @param bool $query_active_plugins Optional. If true, this conditional will query active plugins too.
83 * Defaults to true if {@link s2Member\WS_PLUGIN__S2MEMBER_ONLY} is true, else false.
84 *
85 * @return bool True if BuddyPress is installed, else false.
86 */
87 public static function bp_is_installed($query_active_plugins = NULL)
88 {
89 if(defined('BP_VERSION') && did_action('bp_core_loaded'))
90 return TRUE; // Quickest/easiest way to determine.
91
92 $s2o = (defined('WS_PLUGIN__S2MEMBER_ONLY') && WS_PLUGIN__S2MEMBER_ONLY) ? TRUE : FALSE;
93
94 if(($query_active_plugins = (!isset($query_active_plugins) && $s2o) ? TRUE : $query_active_plugins))
95 {
96 $buddypress = 'buddypress/bp-loader.php'; // BuddyPress.
97
98 $active_plugins = (is_multisite()) ? wp_get_active_network_plugins() : array();
99 $active_plugins = array_unique(array_merge($active_plugins, wp_get_active_and_valid_plugins()));
100
101 foreach($active_plugins as $active_plugin) // Search.
102 if(plugin_basename($active_plugin) === $buddypress)
103 return TRUE; // BuddyPress active.
104 }
105 return FALSE; // Default return false.
106 }
107
108 /**
109 * Determines whether or not this is a Multisite Farm;
110 * *( i.e., if ``MULTISITE_FARM == true`` inside `/wp-config.php` )*.
111 *
112 * With s2Member, this option may also indicate a Multisite Blog Farm.
113 * ``$GLOBALS['WS_PLUGIN__']['s2member']['o']['mms_registration_file'] === 'wp-signup'``.
114 *
115 * @package s2Member\Utilities
116 * @since 3.5
117 *
118 * @return bool True if this is a Multisite Farm, else false.
119 */
120 public static function is_multisite_farm()
121 {
122 return is_multisite()
123 && ((is_main_site() && $GLOBALS['WS_PLUGIN__']['s2member']['o']['mms_registration_file'] === 'wp-signup')
124 || (defined('MULTISITE_FARM') && MULTISITE_FARM));
125 }
126
127 /**
128 * Checks if a Post is in a child Category.
129 *
130 * @package s2Member\Utilities
131 * @since 3.5
132 *
133 * @param array $cats An array of Category IDs.
134 * @param int|string $post_id A numeric WordPress Post ID.
135 *
136 * @return bool True if the Post is inside a desendant of at least one of the specified Categories; else false.
137 */
138 public static function in_descendant_category($cats = array(), $post_id = '')
139 {
140 foreach((array)$cats as $cat)
141 {
142 $descendants = get_term_children((int)$cat, 'category');
143 if($descendants && in_category($descendants, $post_id))
144 return TRUE;
145 }
146 return FALSE; // Default return false.
147 }
148
149 /**
150 * Checks to see if a URL/URI leads to the site root.
151 *
152 * @package s2Member\Utilities
153 * @since 3.5
154 *
155 * @param string $url_uri Either a full URL, or a partial URI to test.
156 *
157 * @return bool True if the URL or URI leads to the site root, else false.
158 */
159 public static function is_site_root($url_uri = '')
160 {
161 if(is_array($parse = c_ws_plugin__s2member_utils_urls::parse_url($url_uri)))
162 {
163 $ci = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ruris_case_sensitive'] ? '' : 'i';
164 $parse['path'] = !empty($parse['path']) ? (strpos($parse['path'], '/') === 0 ? $parse['path'] : '/'.$parse['path']) : '/';
165 $parse['query'] = !empty($parse['query']) ? $parse['query'] : ''; // Has a query string?
166
167 if(empty($parse['host']) || strcasecmp($parse['host'], c_ws_plugin__s2member_utils_urls::parse_url(home_url(), PHP_URL_HOST)) === 0)
168 if($parse['path'] === '/' || preg_match('/^'.preg_quote(rtrim($parse['path'], '/'), '/').'$/'.$ci, rtrim(c_ws_plugin__s2member_utils_urls::parse_url(home_url(), PHP_URL_PATH), '/')))
169 if(get_option('permalink_structure') || (empty($_REQUEST['post_id']) && empty($_REQUEST['page_id']) && empty($_REQUEST['p']) && empty($_REQUEST['s'])))
170 return TRUE;
171
172 if(empty($parse['host']) || strcasecmp($parse['host'], c_ws_plugin__s2member_utils_urls::parse_url(site_url(), PHP_URL_HOST)) === 0)
173 if($parse['path'] === '/' || preg_match('/^'.preg_quote(rtrim($parse['path'], '/'), '/').'$/'.$ci, rtrim(c_ws_plugin__s2member_utils_urls::parse_url(site_url(), PHP_URL_PATH), '/')))
174 if(get_option('permalink_structure') || (empty($_REQUEST['post_id']) && empty($_REQUEST['page_id']) && empty($_REQUEST['p']) && empty($_REQUEST['s'])))
175 return TRUE;
176 }
177 return FALSE; // Default return false.
178 }
179
180 /**
181 * Checks to see if we're in a localhost environment.
182 *
183 * @package s2Member\Utilities
184 * @since 111101
185 *
186 * @return bool True if we're in a localhost environment, else false.
187 */
188 public static function is_localhost()
189 {
190 if((defined('LOCALHOST') && LOCALHOST)
191 || stripos($_SERVER['HTTP_HOST'], 'localhost') !== FALSE
192 || strpos($_SERVER['HTTP_HOST'], '127.0.0.1') !== FALSE
193 ) return TRUE;
194
195 return FALSE; // Default return false.
196 }
197
198 /**
199 * Checks to see if we're using Amazon S3.
200 *
201 * @package s2Member\Utilities
202 * @since 110926
203 *
204 * @return bool True if using Amazon S3, else false.
205 */
206 public static function using_amazon_s3_storage()
207 {
208 foreach($GLOBALS['WS_PLUGIN__']['s2member']['o'] as $option => $option_value)
209 if(preg_match('/^amazon_s3_files_/', $option) && ($option = preg_replace('/^amazon_s3_files_/', '', $option)))
210 $s3c[$option] = $option_value;
211
212 if(!empty($s3c['bucket']) && !empty($s3c['access_key']) && !empty($s3c['secret_key']))
213 return TRUE;
214
215 return FALSE; // Default return false.
216 }
217
218 /**
219 * Checks to see if we're using Amazon CloudFront.
220 *
221 * @package s2Member\Utilities
222 * @since 110926
223 *
224 * @return bool True if using Amazon CloudFront, else false.
225 */
226 public static function using_amazon_cf_storage()
227 {
228 foreach($GLOBALS['WS_PLUGIN__']['s2member']['o'] as $option => $option_value)
229 if(preg_match('/^amazon_s3_files_/', $option) && ($option = preg_replace('/^amazon_s3_files_/', '', $option)))
230 $s3c[$option] = $option_value;
231
232 foreach($GLOBALS['WS_PLUGIN__']['s2member']['o'] as $option => $option_value)
233 if(preg_match('/^amazon_cf_files_/', $option) && ($option = preg_replace('/^amazon_cf_files_/', '', $option)))
234 $cfc[$option] = $option_value;
235
236 if(!empty($s3c['bucket']) && !empty($s3c['access_key']) && !empty($s3c['secret_key']))
237 if(!empty($cfc['private_key']) && !empty($cfc['private_key_id']) && !empty($cfc['distros_access_id'])
238 && !empty($cfc['distros_s3_access_id']) && !empty($cfc['distro_downloads_id']) && !empty($cfc['distro_downloads_dname'])
239 && !empty($cfc['distro_streaming_id']) && !empty($cfc['distro_streaming_dname'])
240 ) return TRUE;
241
242 return FALSE; // Default return false.
243 }
244 }
245 }
246