PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/classes/utils-conds.inc.php

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