PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

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