| 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") |
| 41 |
/* And loaded? */ && did_action ("ws_plugin__s2member_pro_after_loaded")); |
| 42 |
} |
| 43 |
/** |
| 44 |
* Determines whether or not BuddyPress is installed. |
| 45 |
* |
| 46 |
* @package s2Member\Utilities |
| 47 |
* @since 110720 |
| 48 |
* |
| 49 |
* @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. |
| 50 |
* @return bool True if BuddyPress is installed, else false. |
| 51 |
*/ |
| 52 |
public static function bp_is_installed ($query_active_plugins = NULL) |
| 53 |
{ |
| 54 |
if (defined ("BP_VERSION") && did_action ("bp_core_loaded")) |
| 55 |
return true; /* Quickest/easiest way to determine. */ |
| 56 |
/**/ |
| 57 |
$s2o = (defined ("WS_PLUGIN__S2MEMBER_ONLY") && WS_PLUGIN__S2MEMBER_ONLY) ? true : false; |
| 58 |
/**/ |
| 59 |
if (($query_active_plugins = (!isset ($query_active_plugins) && $s2o) ? true : $query_active_plugins)) |
| 60 |
{ |
| 61 |
$buddypress = "buddypress/bp-loader.php"; /* BuddyPress. */ |
| 62 |
/**/ |
| 63 |
$active_plugins = (is_multisite ()) ? wp_get_active_network_plugins () : array (); |
| 64 |
$active_plugins = array_unique (array_merge ($active_plugins, wp_get_active_and_valid_plugins ())); |
| 65 |
/**/ |
| 66 |
foreach ($active_plugins as $active_plugin) /* Search. */ |
| 67 |
if (plugin_basename ($active_plugin) === $buddypress) |
| 68 |
return true; /* BuddyPress active. */ |
| 69 |
} |
| 70 |
/**/ |
| 71 |
return false; /* Default return false. */ |
| 72 |
} |
| 73 |
/** |
| 74 |
* Determines whether or not this is a Multisite Farm; |
| 75 |
* *( i.e. if ``MULTISITE_FARM == true`` inside `/wp-config.php` )*. |
| 76 |
* |
| 77 |
* With s2Member, this option may also indicate a Multisite Blog Farm. |
| 78 |
* ``$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_file"] === "wp-signup"``. |
| 79 |
* |
| 80 |
* @package s2Member\Utilities |
| 81 |
* @since 3.5 |
| 82 |
* |
| 83 |
* @return bool True if this is a Multisite Farm, else false. |
| 84 |
*/ |
| 85 |
public static function is_multisite_farm () |
| 86 |
{ |
| 87 |
return (is_multisite () && ((is_main_site () && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mms_registration_file"] === "wp-signup") || (defined ("MULTISITE_FARM") && MULTISITE_FARM))); |
| 88 |
} |
| 89 |
/** |
| 90 |
* Checks if a Post is in a child Category. |
| 91 |
* |
| 92 |
* @package s2Member\Utilities |
| 93 |
* @since 3.5 |
| 94 |
* |
| 95 |
* @param array $cats An array of Category IDs. |
| 96 |
* @param int|str $post_id A numeric WordPress® Post ID. |
| 97 |
* @return bool True if the Post is inside a desendant of at least one of the specified Categories; else false. |
| 98 |
*/ |
| 99 |
public static function in_descendant_category ($cats = FALSE, $post_id = FALSE) |
| 100 |
{ |
| 101 |
foreach ((array)$cats as $cat) |
| 102 |
{ |
| 103 |
$descendants = get_term_children ((int)$cat, "category"); |
| 104 |
if ($descendants && in_category ($descendants, $post_id)) |
| 105 |
return true; |
| 106 |
} |
| 107 |
/**/ |
| 108 |
return false; |
| 109 |
} |
| 110 |
/** |
| 111 |
* Checks to see if a URL/URI leads to the site root. |
| 112 |
* |
| 113 |
* @package s2Member\Utilities |
| 114 |
* @since 3.5 |
| 115 |
* |
| 116 |
* @param str $url_or_uri Either a full URL, or a URI to test against. |
| 117 |
* @return bool True if the URL or URI leads to the site root, else false. |
| 118 |
*/ |
| 119 |
public static function is_site_root ($url_or_uri = FALSE) |
| 120 |
{ |
| 121 |
if (is_array ($parse = c_ws_plugin__s2member_utils_urls::parse_url ($url_or_uri))) |
| 122 |
{ |
| 123 |
$parse["path"] = (!empty ($parse["path"])) ? ((strpos ($parse["path"], "/") === 0) ? $parse["path"] : "/" . $parse["path"]) : "/"; |
| 124 |
/**/ |
| 125 |
if (empty ($parse["host"]) || strcasecmp ($parse["host"], c_ws_plugin__s2member_utils_urls::parse_url (site_url (), PHP_URL_HOST)) === 0) |
| 126 |
if ($parse["path"] === "/" || rtrim ($parse["path"], "/") === rtrim (c_ws_plugin__s2member_utils_urls::parse_url (site_url (), PHP_URL_PATH), "/")) |
| 127 |
return true; |
| 128 |
} |
| 129 |
/**/ |
| 130 |
return false; |
| 131 |
} |
| 132 |
/** |
| 133 |
* Checks to see if we're using Amazon® S3. |
| 134 |
* |
| 135 |
* @package s2Member\Utilities |
| 136 |
* @since 110926 |
| 137 |
* |
| 138 |
* @return bool True if using Amazon® S3, else false. |
| 139 |
*/ |
| 140 |
public static function using_amazon_s3_storage () |
| 141 |
{ |
| 142 |
if (!c_ws_plugin__s2member_utils_conds::using_amazon_cf_storage ()) |
| 143 |
{ |
| 144 |
foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value) |
| 145 |
if (preg_match ("/^amazon_s3_files_/", $option) && ($option = preg_replace ("/^amazon_s3_files_/", "", $option))) |
| 146 |
$s3c[$option] = $option_value; |
| 147 |
/**/ |
| 148 |
if ($s3c["bucket"] && $s3c["access_key"] && $s3c["secret_key"]) |
| 149 |
return true; |
| 150 |
} |
| 151 |
/**/ |
| 152 |
return false; |
| 153 |
} |
| 154 |
/** |
| 155 |
* Checks to see if we're using Amazon® CloudFront. |
| 156 |
* |
| 157 |
* @package s2Member\Utilities |
| 158 |
* @since 110926 |
| 159 |
* |
| 160 |
* @return bool True if using Amazon® CloudFront, else false. |
| 161 |
*/ |
| 162 |
public static function using_amazon_cf_storage () |
| 163 |
{ |
| 164 |
foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value) |
| 165 |
if (preg_match ("/^amazon_s3_files_/", $option) && ($option = preg_replace ("/^amazon_s3_files_/", "", $option))) |
| 166 |
$s3c[$option] = $option_value; |
| 167 |
/**/ |
| 168 |
foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value) |
| 169 |
if (preg_match ("/^amazon_cf_files_/", $option) && ($option = preg_replace ("/^amazon_cf_files_/", "", $option))) |
| 170 |
$cfc[$option] = $option_value; |
| 171 |
/**/ |
| 172 |
if ($s3c["bucket"] && $s3c["access_key"] && $s3c["secret_key"]) |
| 173 |
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"]) |
| 174 |
return true; |
| 175 |
/**/ |
| 176 |
return false; |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
?> |