| 1 |
<?php |
| 2 |
/** |
| 3 |
* Get 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_gets")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Get utilities. |
| 24 |
* |
| 25 |
* @package s2Member\Utilities |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_utils_gets |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Retrieves a list of all Category IDs in the database. |
| 32 |
* |
| 33 |
* @package s2Member\Utilities |
| 34 |
* @since 3.5 |
| 35 |
* |
| 36 |
* @return array Array of all Category IDs. |
| 37 |
*/ |
| 38 |
public static function get_all_category_ids () |
| 39 |
{ |
| 40 |
$ids = get_all_category_ids (); |
| 41 |
/**/ |
| 42 |
return (array)$ids; |
| 43 |
} |
| 44 |
/** |
| 45 |
* Retrieves a list of all child Category IDs from the database. |
| 46 |
* |
| 47 |
* @package s2Member\Utilities |
| 48 |
* @since 3.5 |
| 49 |
* |
| 50 |
* @param int|str $parent Expects a numeric Category ID. |
| 51 |
* @return array Array of all Category IDs under the ``$parent``. |
| 52 |
*/ |
| 53 |
public static function get_all_child_category_ids ($parent = FALSE) |
| 54 |
{ |
| 55 |
if (is_numeric ($parent) && is_array ($categories = get_categories ("child_of=" . $parent))) |
| 56 |
foreach ($categories as $child_category) |
| 57 |
$child_ids[] = $child_category->term_id; |
| 58 |
/**/ |
| 59 |
return (array)$child_ids; |
| 60 |
} |
| 61 |
/** |
| 62 |
* Retrieves a list of all Tag IDs in the database. |
| 63 |
* |
| 64 |
* @package s2Member\Utilities |
| 65 |
* @since 3.5 |
| 66 |
* |
| 67 |
* @return array Array of all Tag IDs. |
| 68 |
*/ |
| 69 |
public static function get_all_tag_ids () |
| 70 |
{ |
| 71 |
global $wpdb; /* Need global DB obj. */ |
| 72 |
/**/ |
| 73 |
foreach ((array)get_tags () as $tag) |
| 74 |
$ids[] = $tag->term_id; |
| 75 |
/**/ |
| 76 |
return (array)$ids; |
| 77 |
} |
| 78 |
/** |
| 79 |
* Retrieves a list of all Post IDs in the database. |
| 80 |
* |
| 81 |
* @package s2Member\Utilities |
| 82 |
* @since 3.5 |
| 83 |
* |
| 84 |
* @return array Array of all Post IDs. |
| 85 |
* Includes Custom Post Types. Excludes `page|attachment|revision`. |
| 86 |
*/ |
| 87 |
public static function get_all_post_ids () |
| 88 |
{ |
| 89 |
global $wpdb; /* Need global DB obj. */ |
| 90 |
/**/ |
| 91 |
$ids = $wpdb->get_col ("SELECT `ID` FROM `" . $wpdb->posts . "` WHERE `post_status` = 'publish' AND `post_type` NOT IN('page','attachment','revision')"); |
| 92 |
/**/ |
| 93 |
return (array)$ids; |
| 94 |
} |
| 95 |
/** |
| 96 |
* Retrieves a list of all Page IDs from the database. |
| 97 |
* |
| 98 |
* @package s2Member\Utilities |
| 99 |
* @since 3.5 |
| 100 |
* |
| 101 |
* @return array Array of all Page IDs. |
| 102 |
*/ |
| 103 |
public static function get_all_page_ids () |
| 104 |
{ |
| 105 |
global $wpdb; /* Need global DB obj. */ |
| 106 |
/**/ |
| 107 |
$ids = $wpdb->get_col ("SELECT `ID` FROM `" . $wpdb->posts . "` WHERE `post_status` = 'publish' AND `post_type` = 'page'"); |
| 108 |
/**/ |
| 109 |
return (array)$ids; |
| 110 |
} |
| 111 |
/** |
| 112 |
* Converts a comma-delimited list of: Tag slugs/names/ids - into all IDs. |
| 113 |
* |
| 114 |
* @package s2Member\Utilities |
| 115 |
* @since 3.5 |
| 116 |
* |
| 117 |
* @param str $tags Tag slugs/names/IDs, comma-delimited. |
| 118 |
* @return array Array of all Tag IDs. |
| 119 |
*/ |
| 120 |
public static function convert_tags_2_ids ($tags = FALSE) |
| 121 |
{ |
| 122 |
foreach (preg_split ("/[\r\n\t;,]+/", $tags) as $tag) |
| 123 |
{ |
| 124 |
if (($tag = trim ($tag)) && is_numeric ($tag)) |
| 125 |
{ |
| 126 |
$ids[] = $tag; |
| 127 |
} |
| 128 |
else if ($tag && is_string ($tag)) |
| 129 |
{ |
| 130 |
if (is_object ($term = get_term_by ("name", $tag, "post_tag"))) |
| 131 |
{ |
| 132 |
$ids[] = $term->term_id; |
| 133 |
} |
| 134 |
else if (is_object ($term = get_term_by ("slug", $tag, "post_tag"))) |
| 135 |
{ |
| 136 |
$ids[] = $term->term_id; |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
/**/ |
| 141 |
return (array)$ids; |
| 142 |
} |
| 143 |
/** |
| 144 |
* Retrieves a list of singular IDs from the database. |
| 145 |
* |
| 146 |
* Only returns Posts that require Custom Capabilities; |
| 147 |
* and ONLY those which are NOT satisfied by ``$user``. |
| 148 |
* |
| 149 |
* @package s2Member\Utilities |
| 150 |
* @since 3.5 |
| 151 |
* |
| 152 |
* @param obj $user Optional. A `WP_User` object. |
| 153 |
* @return array Array of all singular IDs not available to ``$user`` because of Custom Capability restrictions. |
| 154 |
*/ |
| 155 |
public static function get_singular_ids_with_ccaps_req ($user = FALSE) |
| 156 |
{ |
| 157 |
global $wpdb; /* Need global DB obj. */ |
| 158 |
/**/ |
| 159 |
if (is_array ($results = $wpdb->get_results ("SELECT `post_id`, `meta_value` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = 's2member_ccaps_req' AND `meta_value` != ''"))) |
| 160 |
{ |
| 161 |
foreach ($results as $result) /* Now we need to check Custom Capabilities against $user. */ |
| 162 |
{ |
| 163 |
if (!is_object ($user) || !$user->ID) /* No ``$user``? / not logged-in?. */ |
| 164 |
$ids[] = $result->post_id; /* There's no way to satisfy anything here. */ |
| 165 |
/**/ |
| 166 |
else if (is_array ($ccaps = @unserialize ($result->meta_value))) |
| 167 |
/**/ |
| 168 |
foreach ($ccaps as $ccap) /* Test all Custom Capability requirements. */ |
| 169 |
if (strlen ($ccap)) /* Quick (empty) check here. */ |
| 170 |
if (!$user->has_cap ("access_s2member_ccap_" . $ccap)) |
| 171 |
{ |
| 172 |
$ids[] = $result->post_id; |
| 173 |
break; |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
/**/ |
| 178 |
return (array)$ids; |
| 179 |
} |
| 180 |
/** |
| 181 |
* Retrieves a list of singular IDs from the database. |
| 182 |
* |
| 183 |
* Only returns Posts that require Specific Post/Page Access; |
| 184 |
* and ONLY those which are NOT satisfied by the current Visitor. |
| 185 |
* |
| 186 |
* @package s2Member\Utilities |
| 187 |
* @since 3.5 |
| 188 |
* |
| 189 |
* @return array Array of all singular IDs not available to ``$user`` because of Specific Post/Page restrictions. |
| 190 |
*/ |
| 191 |
public static function get_singular_ids_with_sp_req () |
| 192 |
{ |
| 193 |
global $wpdb; /* Need global DB obj. */ |
| 194 |
/**/ |
| 195 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"] && is_array ($sps = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"]))) |
| 196 |
{ |
| 197 |
foreach ($sps as $sp) /* Now we need to check access against the current Visitor. */ |
| 198 |
{ |
| 199 |
if ($sp && !c_ws_plugin__s2member_sp_access::sp_access ($sp, "read-only")) |
| 200 |
$ids[] = $sp; |
| 201 |
} |
| 202 |
} |
| 203 |
/**/ |
| 204 |
return (array)$ids; |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
?> |