PluginProbe
Page-list / 3.0
Page-list v3.0
6.3 6.1 6.2 6.0 trunk 1.0.0 1.2.0 1.3.0 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 All 47 releases
page-list / page-list.php

page-list.php in Page-list 3.0, at page-list.php

442 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Page-list
4 Plugin URI: http://web-profile.com.ua/wordpress/plugins/page-list/
5 Description: Show list of pages with [pagelist], [subpages], [siblings] and [pagelist_ext] shortcodes.
6 Version: 3.0
7 Author: webvitaly
8 Author Email: webvitaly(at)gmail.com
9 Author URI: http://web-profile.com.ua/wordpress/
10
11 Future features:
12 - exclude_by_alias;
13 - exclude_front_page;
14 - exclude_post_page;
15 */
16
17 add_action('wp_print_styles', 'pagelist_add_stylesheet');
18 function pagelist_add_stylesheet() {
19 wp_enqueue_style( 'page-list-style', plugins_url( '/css/page-list.css', __FILE__ ), false, '3.0', 'all' );
20 }
21
22 $pagelist_powered_line = "\n".'<!-- Page-list plugin v.3.0 (wordpress.org/extend/plugins/page-list/) -->'."\n";
23
24 if ( !function_exists('pagelist_shortcode') ) {
25 function pagelist_shortcode( $atts ) {
26 global $post, $pagelist_powered_line;
27 $return = '';
28 extract( shortcode_atts( array(
29 'depth' => '0',
30 'child_of' => '0',
31 'exclude' => '0',
32 'exclude_tree' => '',
33 'include' => '0',
34 'title_li' => '',
35 'number' => '',
36 'offset' => '',
37 'meta_key' => '',
38 'meta_value' => '',
39 'show_date' => '',
40 'sort_column' => 'menu_order, post_title',
41 'sort_order' => 'ASC',
42 'link_before' => '',
43 'link_after' => '',
44 'class' => ''
45 ), $atts ) );
46
47 $page_list_args = array(
48 'depth' => $depth,
49 'child_of' => pagelist_norm_params($child_of),
50 'exclude' => pagelist_norm_params($exclude),
51 'exclude_tree' => $exclude_tree,
52 'include' => $include,
53 'title_li' => $title_li,
54 'number' => $number,
55 'offset' => $offset,
56 'meta_key' => $meta_key,
57 'meta_value' => $meta_value,
58 'show_date' => $show_date,
59 'date_format' => get_option('date_format'),
60 'echo' => 0,
61 'authors' => '',
62 'sort_column' => $sort_column,
63 'sort_order' => $sort_order,
64 'link_before' => $link_before,
65 'link_after' => $link_after,
66 'walker' => ''
67 );
68 $list_pages = wp_list_pages( $page_list_args );
69
70 if ($list_pages) {
71 $return = $pagelist_powered_line;
72 $return .= '<ul class="page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
73 }else{
74 $return = '';
75 }
76 return $return;
77 }
78 add_shortcode( 'pagelist', 'pagelist_shortcode' );
79 add_shortcode( 'page_list', 'pagelist_shortcode' );
80 add_shortcode( 'page-list', 'pagelist_shortcode' ); // not good (Shortcode names should be all lowercase and use all letters, but numbers and underscores (not dashes!) should work fine too.)
81 add_shortcode( 'sitemap', 'pagelist_shortcode' );
82 }
83
84 if ( !function_exists('subpages_shortcode') ) {
85 function subpages_shortcode( $atts ) {
86 global $post, $pagelist_powered_line;
87 $return = '';
88 extract( shortcode_atts( array(
89 'depth' => '0',
90 //'child_of' => '0',
91 'exclude' => '0',
92 'exclude_tree' => '',
93 'include' => '0',
94 'title_li' => '',
95 'number' => '',
96 'offset' => '',
97 'meta_key' => '',
98 'meta_value' => '',
99 'show_date' => '',
100 'sort_column' => 'menu_order, post_title',
101 'sort_order' => 'ASC',
102 'link_before' => '',
103 'link_after' => '',
104 'class' => ''
105 ), $atts ) );
106
107 $page_list_args = array(
108 'depth' => $depth,
109 'child_of' => $post->ID,
110 'exclude' => pagelist_norm_params($exclude),
111 'exclude_tree' => $exclude_tree,
112 'include' => $include,
113 'title_li' => $title_li,
114 'number' => $number,
115 'offset' => $offset,
116 'meta_key' => $meta_key,
117 'meta_value' => $meta_value,
118 'show_date' => $show_date,
119 'date_format' => get_option('date_format'),
120 'echo' => 0,
121 'authors' => '',
122 'sort_column' => $sort_column,
123 'sort_order' => $sort_order,
124 'link_before' => $link_before,
125 'link_after' => $link_after,
126 'walker' => ''
127 );
128 $list_pages = wp_list_pages( $page_list_args );
129
130 if ($list_pages) {
131 $return = $pagelist_powered_line;
132 $return .= '<ul class="page-list subpages-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
133 }else{
134 $return = '';
135 }
136 return $return;
137 }
138 add_shortcode( 'subpages', 'subpages_shortcode' );
139 add_shortcode( 'sub_pages', 'subpages_shortcode' );
140 add_shortcode( 'sub-pages', 'subpages_shortcode' ); // not good (Shortcode names should be all lowercase and use all letters, but numbers and underscores (not dashes!) should work fine too.)
141 add_shortcode( 'children', 'subpages_shortcode' );
142 }
143
144 if ( !function_exists('siblings_shortcode') ) {
145 function siblings_shortcode( $atts ) {
146 global $post, $pagelist_powered_line;
147 $return = '';
148 extract( shortcode_atts( array(
149 'depth' => '0',
150 //'child_of' => '0',
151 'exclude' => '0',
152 'exclude_tree' => '',
153 'include' => '0',
154 'title_li' => '',
155 'number' => '',
156 'offset' => '',
157 'meta_key' => '',
158 'meta_value' => '',
159 'show_date' => '',
160 'sort_column' => 'menu_order, post_title',
161 'sort_order' => 'ASC',
162 'link_before' => '',
163 'link_after' => '',
164 'class' => ''
165 ), $atts ) );
166
167 if( $exclude == 'current' || $exclude == 'this' ){
168 $exclude = $post->ID;
169 }
170
171 $page_list_args = array(
172 'depth' => $depth,
173 'child_of' => $post->post_parent,
174 'exclude' => pagelist_norm_params($exclude),
175 'exclude_tree' => $exclude_tree,
176 'include' => $include,
177 'title_li' => $title_li,
178 'number' => $number,
179 'offset' => $offset,
180 'meta_key' => $meta_key,
181 'meta_value' => $meta_value,
182 'show_date' => $show_date,
183 'date_format' => get_option('date_format'),
184 'echo' => 0,
185 'authors' => '',
186 'sort_column' => $sort_column,
187 'sort_order' => $sort_order,
188 'link_before' => $link_before,
189 'link_after' => $link_after,
190 'walker' => ''
191 );
192 $list_pages = wp_list_pages( $page_list_args );
193
194 if ($list_pages) {
195 $return = $pagelist_powered_line;
196 $return .= '<ul class="page-list siblings-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
197 }else{
198 $return = '';
199 }
200 return $return;
201 }
202 add_shortcode( 'siblings', 'siblings_shortcode' );
203 }
204
205 if ( !function_exists('pagelist_ext_shortcode') ) {
206 function pagelist_ext_shortcode( $atts ) {
207 global $post, $pagelist_powered_line;
208 $return = '';
209 extract( shortcode_atts( array(
210 'show_image' => 1,
211 'show_first_image' => 0,
212 'show_title' => 1,
213 'show_content' => 1,
214 'limit_content' => 250,
215 'image_width' => '50',
216 'image_height' => '50',
217 'child_of' => '0',
218 'sort_order' => 'ASC',
219 'sort_column' => 'menu_order, post_title',
220 'hierarchical' => 1,
221 'exclude' => '0',
222 'include' => '0',
223 'meta_key' => '',
224 'meta_value' => '',
225 'authors' => '',
226 'parent' => -1,
227 'exclude_tree' => '',
228 'number' => '',
229 'offset' => 0,
230 'post_type' => 'page',
231 'post_status' => 'publish',
232 'class' => '',
233 'strip_tags' => 1,
234 'strip_shortcodes' => 1,
235 'more_tag' => 1,
236 'show_child_count' => 0,
237 'child_count_template' => 'Subpages: %child_count%',
238 'show_meta_key' => '',
239 'meta_template' => '%meta%'
240 ), $atts ) );
241
242 if( $child_of == '0' ){
243 $child_of = $post->ID;
244 }
245
246 $page_list_ext_args = array(
247 'show_image' => $show_image,
248 'show_first_image' => $show_first_image,
249 'show_title' => $show_title,
250 'show_content' => $show_content,
251 'limit_content' => $limit_content,
252 'image_width' => $image_width,
253 'image_height' => $image_height,
254 'child_of' => pagelist_norm_params($child_of),
255 'sort_order' => $sort_order,
256 'sort_column' => $sort_column,
257 'hierarchical' => $hierarchical,
258 'exclude' => pagelist_norm_params($exclude),
259 'include' => $include,
260 'meta_key' => $meta_key,
261 'meta_value' => $meta_value,
262 'authors' => $authors,
263 'parent' => pagelist_norm_params($parent),
264 'exclude_tree' => $exclude_tree,
265 'number' => '', // $number - own counter
266 'offset' => 0, // $offset - own offset
267 'post_type' => $post_type,
268 'post_status' => $post_status,
269 'class' => $class,
270 'strip_tags' => $strip_tags,
271 'strip_shortcodes' => $strip_shortcodes,
272 'more_tag' => $more_tag,
273 'show_child_count' => $show_child_count,
274 'child_count_template' => $child_count_template,
275 'show_meta_key' => $show_meta_key,
276 'meta_template' => $meta_template
277 );
278 $list_pages = get_pages( $page_list_ext_args );
279 $list_pages_html = '';
280 $count = 0;
281 $offset_count = 0;
282 foreach($list_pages as $page){
283 $count++;
284 $offset_count++;
285 if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) {
286 $count = 0; // number counter to zero if offset is not finished
287 }
288 if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) {
289 if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) {
290 $link = get_permalink( $page->ID );
291 $list_pages_html .= '<div class="page-list-ext-item">';
292 if( $show_image == 1 ){
293 if (function_exists('get_the_post_thumbnail')) {
294 if( get_the_post_thumbnail($page->ID) ){
295 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
296 $list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height));
297 $list_pages_html .= '</a></div> ';
298 }else{
299 if( $show_first_image == 1 ){
300 $img_scr = get_first_image( $page->post_content );
301 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
302 $list_pages_html .= '<img src="'.$img_scr.'" width="'.$image_width.'" />'; // not using height="'.$image_height.'" because images could be not square shaped and they will be stretched
303 $list_pages_html .= '</a></div> ';
304 }
305 }
306 }else{
307 if( $show_first_image == 1 ){
308 $img_scr = get_first_image( $page->post_content );
309 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
310 $list_pages_html .= '<img src="'.$img_scr.'" width="'.$image_width.'" />'; // not using height="'.$image_height.'" because images could be not square shaped and they will be stretched
311 $list_pages_html .= '</a></div> ';
312 }
313 }
314 }
315
316 // get_first_image()
317
318 if( $show_title == 1 ){
319 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'.esc_attr($page->post_title).'</a></h3>';
320 }
321 if( $show_content == 1 ){
322 //$content = apply_filters('the_content', $page->post_content);
323 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
324
325 if( !empty( $page->post_excerpt ) ){
326 $text_content = $page->post_excerpt;
327 }else{
328 $text_content = $page->post_content;
329 }
330
331 if ( post_password_required($page) ) {
332 $content = '<!-- password protected -->';
333 }else{
334 $content = page_list_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
335
336 if( $show_title == 0 ){ // make content as a link if there is no title
337 $content = '<a href="'.$link.'">'.$content.'</a>';
338 }
339 }
340
341 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
342
343 }
344 if( $show_child_count == 1 ){
345 $count_subpages = count(get_pages("child_of=".$page->ID));
346 if( $count_subpages > 0 ){ // hide empty
347 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
348 if($child_count_pos === false) { // %child_count% not found in template
349 $child_count_template_html = $child_count_template.' '.$count_subpages;
350 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
351 } else { // %child_count% found in template
352 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
353 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
354 }
355 }
356 }
357 if( $show_meta_key != '' ){
358 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
359 if( !empty($post_meta) ){ // hide empty
360 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
361 if($meta_pos === false) { // %meta% not found in template
362 $meta_template_html = $meta_template.' '.$post_meta;
363 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
364 } else { // %meta% found in template
365 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
366 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
367 }
368 }
369 }
370 $list_pages_html .= '</div>'."\n";
371 }
372 }
373 }
374 if ($list_pages_html) {
375 $return = $pagelist_powered_line;
376 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
377 }else{
378 $return = '';
379 }
380 return $return;
381 }
382 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
383 }
384
385 if ( !function_exists('pagelist_norm_params') ) {
386 function pagelist_norm_params( $str ) {
387 global $post;
388 $new_str = $str;
389 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
390 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
391 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
392 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
393 return $new_str;
394 }
395 }
396
397 if ( !function_exists('page_list_parse_content') ) {
398 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
399
400 if( $more_tag ){
401 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
402 $more_tag = $matches[0];
403 $content = explode($matches[0], $content);
404 $content = $content[0];
405 }
406 }
407
408 if( $strip_shortcodes ){
409 $content = strip_shortcodes( $content );
410 }
411
412 if( $strip_tags ){
413 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
414 $content = strip_tags($content); // ,'<p>'
415 }
416
417 if( strlen($content) > $limit_content ){
418 $pos = strpos($content, ' ', $limit_content); // find first space position
419 if ($pos !== false) {
420 $first_space_pos = $pos;
421 }else{
422 $first_space_pos = $limit_content;
423 }
424 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
425 }
426
427 $output = force_balance_tags($content);
428 return $output;
429 }
430 }
431
432 function get_first_image( $content='' ) {
433 $first_img = '';
434 //ob_start();
435 //ob_end_clean();
436 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
437 $first_img = $matches[1][0];
438 if(empty($first_img)){ // no image found
439 $first_img = '';
440 }
441 return $first_img;
442 }