PluginProbe
Cornerstone / 0.7.8
Cornerstone v0.7.8
trunk 0.7.7 0.7.8 0.8.0 0.8.1
cornerstone / functions.php

functions.php in Cornerstone 0.7.8, at functions.php

256 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 * Provides global access to specific functionality
5 * @package Cornerstone
6 * @author Archetyped
7 */
8
9 /* Template tags */
10
11 /**
12 * Outputs feed links based on current page
13 * @return void
14 */
15 function cnr_the_feed_links() {
16 global $cnr;
17 $cnr->feeds->the_links();
18 }
19
20 /*-** Child Content **-*/
21
22 function cnr_is_section() {
23 return ( is_page() && cnr_have_children() ) ? true : false;
24 }
25
26 /**
27 * Checks if current post/page has children elements
28 * @return bool TRUE if post/page has children, FALSE otherwise
29 */
30 function cnr_have_children() {
31 global $cnr;
32 return $cnr->post_children_collection->has();
33 }
34
35 /**
36 * Prepares next child post for output to page
37 *
38 * @return void
39 */
40 function cnr_next_child() {
41 global $cnr;
42 $cnr->post_children_collection->next();
43 }
44
45 /**
46 * Returns number of children in current request
47 * May not return total number of existing children (e.g. if output is paged, etc.)
48 * @return int Number of children returned in current request
49 */
50 function cnr_children_count() {
51 global $cnr;
52 return $cnr->post_children_collection->count();
53 }
54
55 /**
56 * Returns total number of existing children
57 * @return int Total number of children
58 */
59 function cnr_children_found() {
60 global $cnr;
61 return $cnr->post_children_collection->found();
62 }
63
64 /**
65 * Returns total number of pages of children
66 * Based on 'posts_per_page' option
67 * @return int Maximum number of pages
68 */
69 function cnr_children_max_num_pages() {
70 global $cnr;
71 return $cnr->post_children_collection->max_num_pages();
72 }
73
74 /**
75 * Checks if current child item is the first child item
76 * @return bool TRUE if current item is first, FALSE otherwise
77 */
78 function cnr_is_first_child() {
79 global $cnr;
80 return $cnr->post_children_collection->is_first();
81 }
82
83 /**
84 * Checks if current child item is the last child item
85 * @return bool TRUE if current item is last, FALSE otherwise
86 */
87 function cnr_is_last_child() {
88 global $cnr;
89 return $cnr->post_children_collection->is_last();
90 }
91
92 /*-** Featured Content **-*/
93
94 /**
95 * Retrieves featured posts
96 * @return array Featured posts matching criteria
97 * @param int $limit (optional) Maximum number of featured posts to retrieve
98 * @param int|bool $parent (optional) Section to get featured posts of (Defaults to current section). FALSE if latest featured posts should be retrieved regardless of section
99 */
100 function cnr_get_featured($limit = 0, $parent = null) {
101 global $cnr;
102 return $cnr->posts_featured->get($limit, $parent);
103 }
104
105 function cnr_in_featured($post_id = null) {
106 global $cnr;
107 return $cnr->posts_featured->contains($post_id);
108 }
109
110 function cnr_have_featured() {
111 global $cnr;
112 return $cnr->posts_featured->has();
113 }
114
115 function cnr_next_featured() {
116 global $cnr;
117 return $cnr->posts_featured->next();
118
119 }
120
121 function cnr_current_featured() {
122 global $cnr;
123 return $cnr->posts_featured->current();
124 }
125
126 function cnr_is_first_featured() {
127 global $cnr;
128 return $cnr->posts_featured->is_first();
129 }
130
131 function cnr_is_last_featured() {
132 global $cnr;
133 return $cnr->posts_featured->is_last();
134 }
135
136 function cnr_featured_count() {
137 global $cnr;
138 return $cnr->posts_featured->count();
139 }
140
141 /**
142 * Returns total number of found posts
143 * @return int Total number of posts
144 */
145 function cnr_featured_found() {
146 global $cnr;
147 return $cnr->posts_featured->found();
148 }
149
150 /*-** Post-Specific **-*/
151
152 /**
153 * Checks if post has content to display
154 * @param object $post (optional) Post object
155 * @return bool TRUE if post has content, FALSE otherwise
156 */
157 function cnr_has_content($post = null) {
158 global $cnr;
159 return $cnr->post_has_content($post);
160 }
161
162 /* Images */
163
164 function cnr_get_attachments($post = null) {
165 $m = new CNR_Media();
166 return $m->post_get_attachments($post);
167 }
168
169 function cnr_get_filesize($post = null, $formatted = true) {
170 $m = new CNR_Media();
171 return $m->get_attachment_filesize($post, $formatted);
172 }
173
174 /* Section */
175
176 /**
177 * Retrieves the post's section data
178 * @uses CNR_Post::get_section()
179 * @param string $data (optional) Type of data to return (Default: ID)
180 * Possible values:
181 * NULL Full section post object
182 * Column name Post column data (if exists)
183 *
184 * @param int $id (optional) Post ID (Default: current post)
185 * @return mixed post's section (or column data if specified via $data parameter)
186 */
187 function cnr_get_the_section($data = 'ID', $id = null) {
188 return CNR_Post::get_section($id, $data);
189 }
190
191 /**
192 * Prints the post's section data
193 * @uses CNR_Post::the_section()
194 * @param string $data (optional) Type of data to return (Default: ID)
195 */
196 function cnr_the_section($data = 'ID') {
197 CNR_Post::the_section(null, $data);
198 }
199
200 /* Content Types */
201
202 /**
203 * Register handler for a placeholder in a content type template
204 * Placeholders allow templates to be populated with dynamic content at runtime
205 * Multiple handlers can be registered for a placeholder,
206 * thus allowing custom handlers to override default processing, etc.
207 * @uses CNR_Field_Type::register_placeholder_handler() to register placeholder
208 * @param string $placeholder Placeholder identifier
209 * @param callback $handler Callback function to use as handler for placeholder
210 * @param int $priority (optional) Priority of registered handler (Default: 10)
211 */
212 function cnr_register_placeholder_handler($placeholder, $handler, $priority = 10) {
213 CNR_Field_Type::register_placeholder_handler($placeholder, $handler, $priority);
214 }
215
216 /**
217 * Checks if data exists for specified field
218 * @global $cnr_content_utilities
219 * @param string $field_id ID of field to check for data
220 * @param int|obj $item (optional) Post ID or object to check for field data (Default: global post)
221 * @return bool TRUE if field data exists
222 */
223 function cnr_has_data($field_id = null, $item = null) {
224 global $cnr_content_utilities;
225 return $cnr_content_utilities->has_item_data($item, $field_id);
226 }
227
228 /**
229 * Retrieve data from a field
230 * @global $cnr_content_utilities
231 * @see CNR_Content_Utilities::get_item_data() for more information
232 * @param string $field_id ID of field to retrieve
233 * @param string $layout (optional) Name of layout to use when returning data
234 * @param array $attr (optional) Additional attributes to pass to field
235 * @param int|object $item (optional) Post object to retrieve data from (Default: global post object)
236 * @param mixed $default Default value to return in case of errors (invalid field, no data, etc.)
237 * @return mixed Specified field data
238 */
239 function cnr_get_data($field_id = null, $layout = 'display', $attr = null, $item = null, $default = '') {
240 global $cnr_content_utilities;
241 return $cnr_content_utilities->get_item_data($item, $field_id, $layout, $default, $attr);
242 }
243
244 /**
245 * Prints an item's field data
246 * @see CNR_Content_Utilities::the_item_data() for more information
247 * @param string $field_id Name of field to retrieve
248 * @param string $layout(optional) Layout to use when returning field data (Default: display)
249 * @param array $attr Additional items to pass to field
250 * @param int|object $item(optional) Content item to retrieve field from (Default: null - global $post object will be used)
251 * @param mixed $default Default value to return in case of errors, etc.
252 */
253 function cnr_the_data($field_id = null, $layout = 'display', $attr = null, $item = null, $default = '') {
254 global $cnr_content_utilities;
255 $cnr_content_utilities->the_item_data($item, $field_id, $layout, $default, $attr);
256 }