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

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

224 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $category_ids = get_all_category_ids ();
41 /**/
42 return (array)$category_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 (isset ($child_ids)) ? (array)$child_ids : array ();
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 $tag_ids[] = $tag->term_id;
75 /**/
76 return (isset ($tag_ids)) ? (array)$tag_ids : array ();
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 $post_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)$post_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 $page_ids = $wpdb->get_col ("SELECT `ID` FROM `" . $wpdb->posts . "` WHERE `post_status` = 'publish' AND `post_type` = 'page'");
108 /**/
109 return (array)$page_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 $tag_ids[] = $tag;
126 /**/
127 else if ($tag && is_string ($tag))
128 {
129 if (is_object ($term = get_term_by ("name", $tag, "post_tag")))
130 $tag_ids[] = $term->term_id;
131 /**/
132 else if (is_object ($term = get_term_by ("slug", $tag, "post_tag")))
133 $tag_ids[] = $term->term_id;
134 }
135 }
136 /**/
137 return (isset ($tag_ids)) ? (array)$tag_ids : array ();
138 }
139 /**
140 * Retrieves a list of singular IDs from the database.
141 *
142 * Only returns singular IDs that require Custom Capabilities;
143 * and ONLY those which are NOT satisfied by ``$user``.
144 *
145 * @package s2Member\Utilities
146 * @since 3.5
147 *
148 * @param obj $user Optional. A `WP_User` object.
149 * @return array Array of all singular IDs not available to ``$user`` because of Custom Capability restrictions.
150 */
151 public static function get_singular_ids_with_ccaps_req ($user = FALSE)
152 {
153 global $wpdb; /* Need global DB obj. */
154 /**/
155 if (is_array ($results = $wpdb->get_results ("SELECT `post_id`, `meta_value` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = 's2member_ccaps_req' AND `meta_value` != ''")))
156 {
157 foreach ($results as $result) /* Now we need to check Custom Capabilities against $user. */
158 {
159 if (!is_object ($user) || !$user->ID) /* No ``$user``, not logged-in?. */
160 $singular_ids[] = $result->post_id; /* No way to satisfy. */
161 /**/
162 else if (is_array ($ccaps = @unserialize ($result->meta_value)))
163 /**/
164 foreach ($ccaps as $ccap) /* Test Capability requirements. */
165 /**/
166 if (strlen ($ccap)) /* Quick (empty) check here. */
167 if (!$user->has_cap ("access_s2member_ccap_" . $ccap))
168 {
169 $singular_ids[] = $result->post_id;
170 break;
171 }
172 }
173 }
174 /**/
175 return (isset ($singular_ids)) ? (array)$singular_ids : array ();
176 }
177 /**
178 * Retrieves a list of singular IDs from the database.
179 *
180 * Only returns singular IDs that require Specific Post/Page Access;
181 * and ONLY those which are NOT satisfied by the current Visitor.
182 *
183 * @package s2Member\Utilities
184 * @since 3.5
185 *
186 * @return array Array of all singular IDs not available to ``$user`` because of Specific Post/Page restrictions.
187 */
188 public static function get_singular_ids_with_sp_req ()
189 {
190 global $wpdb; /* Need global DB obj. */
191 /**/
192 if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"] && is_array ($sps = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"])))
193 {
194 foreach ($sps as $sp) /* Now check access against the current Visitor. */
195 if ($sp && !c_ws_plugin__s2member_sp_access::sp_access ($sp, "read-only"))
196 $singular_ids[] = $sp;
197 }
198 /**/
199 return (isset ($singular_ids)) ? (array)$singular_ids : array ();
200 }
201 /**
202 * Retrieves a list of singular IDs from the database.
203 *
204 * Only returns singular IDs that are within the ``$terms``;
205 * passed through the argument to this function.
206 *
207 * @package s2Member\Utilities
208 * @since 110912
209 *
210 * @param array $terms Required. An array of term IDs.
211 * @return array Array of all singular IDs not available to ``$user`` because of Specific Post/Page restrictions.
212 */
213 public static function get_singular_ids_in_terms ($terms = FALSE)
214 {
215 global $wpdb; /* Need global DB obj. */
216 /**/
217 if (is_array ($terms) && !empty ($terms))
218 $singular_ids = $wpdb->get_col ("SELECT `object_id` FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` IN (SELECT `term_taxonomy_id` FROM `" . $wpdb->term_taxonomy . "` WHERE `term_id` IN('" . implode ("','", $terms) . "'))");
219 /**/
220 return (isset ($singular_ids)) ? (array)$singular_ids : array ();
221 }
222 }
223 }
224 ?>