PluginProbe
oik / 1.4
oik v1.4
1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.2 1.3 1.3.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.0.1 2.1 2.2 2.3 2.4 2.5 2.5.1 All 71 releases
oik / oik-pages.php

oik-pages.php in oik 1.4, at oik-pages.php

263 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Plugin Name: oik pages
5 Plugin URI: http://www.oik-plugins.com/oik
6 Description: [bw_pages] shortcode to summarize child pages
7 Version: 1.4
8 Author: bobbingwide
9 Author URI: http://www.bobbingwide.com
10 License: GPL2
11
12 Copyright 2010, 2011 Bobbing Wide (email : herb@bobbingwide.com )
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 2,
16 as published by the Free Software Foundation.
17
18 You may NOT assume that you can use any other version of the GPL.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 The license for this software can likely be found here:
26 http://www.gnu.org/licenses/gpl-2.0.html
27
28 */
29
30 require_once( 'bobbfunc.inc' );
31 require_once( 'bobbingwide.inc' );
32 /* This include will enable oik shortcodes even if the oik base is not enabled. Is this is good idea? */
33 require_once( 'oik-add-shortcodes.php' );
34 /* Include functions to determine level of Artisteer theme whilst Artisteer doesn't provide it */
35 require_once( 'oik-artisteer.php' );
36
37
38 bw_add_shortcode( 'bw_pages', 'bw_pages' );
39
40 /**
41 * Extract the excerpt from the $post
42 * Note: The function _theme_get_excerpt is not expected to exist. Artisteer doesn't "properly" extract the excerpt
43 * so the '_' prefix disables the call to the Artisteer function
44 *
45 */
46 function bw_excerpt( $post_id ) {
47 if ( function_exists( '_theme_get_excerpt' ) ) {
48
49 global $post;
50 $save_post = $post;
51 $post = $post_id;
52 $excerpt = theme_get_excerpt();
53 $post = $save_post;
54
55 } elseif ( empty( $post_id->excerpt ) ) {
56 $content = explode( '<!--more-->', $post_id->post_content);
57 $excerpt = $content[0];
58 } else {
59 $excerpt = $post_id->excerpt;
60 }
61 return( $excerpt );
62 }
63
64 /**
65 * Return an array suitable for passing to image functions to determine the size
66
67 * @param mixed string representing the size.
68 * if a single integer then make the array square
69 * otherwise it's widthxheight or width,height or some other way of specifying width and height
70 * so we split at the non numeric value(s) and take the first two integer bits
71 */
72 function bw_get_image_size( $size=100 ) {
73 $pattern = "/([\d]+)/";
74 preg_match_all($pattern, $size, $thumbnail);
75 if ( count( $thumbnail ) < 2 )
76 $thumbnail[1] = $thumbnail[0];
77
78 bw_trace( $thumbnail, __FUNCTION__, __LINE__, __FILE__, "thumbnail" );
79 return( $thumbnail );
80 }
81
82 /**
83 * get the thumbnail of the specified size
84 *
85 * Note: There is no code to control the size yet.
86 */
87 function bw_thumbnail( $post_id, $atts=NULL ) {
88
89 $thumbnail = bw_array_get( $atts, 'thumbnail', 'thumbnail' );
90 switch ( $thumbnail ) {
91 case 'thumbnail':
92 case 'medium':
93 case 'large':
94 $torf = TRUE;
95 break;
96
97 default:
98 $torf = bw_validate_torf( $thumbnail );
99 if ( $torf ) {
100 $thumbnail = 'thumbnail';
101 } else {
102 $thumbnail = bw_get_image_size( $thumbnail );
103 }
104 break;
105 }
106
107 if ( function_exists( 'theme_get_post_thumbnail') ) {
108 global $post;
109 $save_post = $post;
110 $post = $post_id;
111
112 $thumbnail = theme_get_post_thumbnail();
113 $post = $save_post;
114
115 } else {
116 $thumbnail = bw_get_thumbnail( $post, $thumbnail );
117 }
118
119 return( $thumbnail );
120 // $thumb = get_the_post_thumbnail( $post->ID,
121 }
122
123 /**
124 * Format the "post" - basic first version
125 *
126 */
127 function bw_format_post( $post, $atts ) {
128 setup_postdata( $post );
129
130 bw_trace( $post, __FUNCTION__, __LINE__, __FILE__, "post" );
131
132 $atts['title'] = get_the_title( $post->ID );
133 $read_more = bw_array_get( $atts, "read_more", "read more" );
134
135 $in_block = bw_validate_torf( bw_array_get( $atts, "block", TRUE ));
136 if ( $in_block ) {
137 e( bw_block( $atts ));
138 e( bw_thumbnail( $post, $atts ) );
139 }
140 else {
141 $class = bw_array_get( $atts, "class", "" );
142 sdiv( $class );
143 e( bw_thumbnail( $post, $atts ) );
144 span( "title" );
145 strong( $atts['title'] );
146 epan();
147 br();
148 }
149
150 e( bw_excerpt( $post ) );
151 sp();
152 art_button( get_permalink( $post->ID ), $read_more, $read_more );
153 ep();
154 if ( $in_block )
155 e( bw_eblock() );
156 else {
157 sediv( "cleared" );
158 ediv();
159 }
160 }
161
162
163 /**
164 * List sub-pages of the current or selected page
165 *
166 * This function is designed to replace the functionality of [bw_plug name='extended-page-lists'] and other plugins that list pages
167 * It works in conjunction with Artisteer blocks - to enable the page list to be styled as a series of blocks
168 * Well, that's the plan
169 * [bw_pages class="classes for bw_block"
170 * post_type='page'
171 * post_parent
172 * orderby='title'
173 * order='ASC'
174 * posts_per_page=-1
175 * block=true or false
176 * thumbnail=specification - see bw_thumbnail
177 */
178 function bw_pages( $atts = NULL ) {
179
180 // $block_atts = array( "class"=> $class, );
181
182 // Copy the atts from the shortcode to create the array for the query
183 // removing the class and title parameter that gets passed to bw_block()
184
185 $attr = $atts;
186 bw_trace( $atts, __FUNCTION__, __LINE__, __FILE__, "atts" );
187 bw_trace( $attr, __FUNCTION__, __LINE__, __FILE__, "attr" );
188
189 //unset( $attr['class'] );
190 //unset( $attr['title'] );
191
192 /* Set default values if not already set */
193
194 $attr['post_type'] = bw_array_get( $attr, 'post_type', 'page' );
195 $attr['post_parent'] = bw_array_get( $attr, "post_parent", $GLOBALS['post']->ID );
196 $attr['numberposts'] = bw_array_get( $attr, "numberposts", -1 );
197 $attr['orderby'] = bw_array_get( $attr, "orderby", "title" );
198 $attr['order'] = bw_array_get( $attr, "order", "ASC" );
199
200 $posts = get_posts( $attr );
201 bw_trace( $posts, __FUNCTION__, __LINE__, __FILE__, "posts" );
202
203 foreach ( $posts as $post ) {
204 bw_format_post( $post, $atts );
205 //p( "this is a post" );
206 //e( $post->ID );
207 }
208
209 return( bw_ret() );
210 }
211
212
213 /**
214 * get the post thumbnail
215 */
216
217 function bw_get_thumbnail( $post_id = null, $size = 'thumbnail' ) {
218
219 /* Return Value: An array containing:
220 $image[0] => attachment id
221 $image[1] => url
222 $image[2] => width
223 $image[3] => height
224 */
225 If ($post_id == Null) $post_id = get_the_id();
226
227 If (Function_Exists('get_post_thumbnail_id') && $thumb_id = get_post_thumbnail_id($post_id) )
228 return Array_Merge ( Array($thumb_id), (Array) wp_get_attachment_image_src($thumb_id, $size) );
229 ElseIf ($arr_thumb = bw_get_attached_image($post_id, 1, 'rand', $size))
230 return $arr_thumb[0];
231 Else
232 return False;
233 }
234
235 /**
236 * get the attached image
237 */
238 function bw_get_attached_image( $post_id = null, $number = 1, $orderby = 'rand', $image_size = 'thumbnail') {
239 If ($post_id == Null) $post_id = get_the_id();
240 $number = IntVal ($number);
241 $arr_attachment = get_posts (Array( 'post_parent' => $post_id,
242 'post_type' => 'attachment',
243 'numberposts' => $number,
244 'post_mime_type' => 'image',
245 'orderby' => $orderby ));
246
247 // Check if there are attachments
248 If (Empty($arr_attachment)) return False;
249
250 // Convert the attachment objects to urls
251 ForEach ($arr_attachment AS $index => $attachment){
252 $arr_attachment[$index] = Array_Merge ( Array($attachment->ID), (Array) wp_get_attachment_image_src($attachment->ID, $image_size));
253 /* Return Value: An array containing:
254 $image[0] => attachment id
255 $image[1] => url
256 $image[2] => width
257 $image[3] => height
258 */
259 }
260
261 return $arr_attachment;
262 }
263