PluginProbe
Page-list / 4.1
Page-list v4.1
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 4.1, at page-list.php

527 lines 19.6 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://wordpress.org/extend/plugins/page-list/
5 Description: [pagelist], [subpages], [siblings] and [pagelist_ext] shortcodes
6 Version: 4.1
7 Author: webvitaly
8 Author URI: http://profiles.wordpress.org/webvitaly/
9 License: GPLv2 or later
10 */
11
12 if ( !function_exists('pagelist_unqprfx_add_stylesheet') ) {
13 function pagelist_unqprfx_add_stylesheet() {
14 wp_enqueue_style( 'page-list-style', plugins_url( '/css/page-list.css', __FILE__ ), false, '4.1', 'all' );
15 }
16 add_action('wp_print_styles', 'pagelist_unqprfx_add_stylesheet');
17 }
18
19
20 $pagelist_unqprfx_powered_line = "\n".'<!-- Page-list plugin v.4.1 wordpress.org/extend/plugins/page-list/ -->'."\n";
21
22
23 if ( !function_exists('pagelist_unqprfx_shortcode') ) {
24 function pagelist_unqprfx_shortcode( $atts ) {
25 global $post, $pagelist_unqprfx_powered_line;
26 $return = '';
27 extract( shortcode_atts( array(
28 'depth' => '0',
29 'child_of' => '0',
30 'exclude' => '0',
31 'exclude_tree' => '',
32 'include' => '0',
33 'title_li' => '',
34 'number' => '',
35 'offset' => '',
36 'meta_key' => '',
37 'meta_value' => '',
38 'show_date' => '',
39 'sort_column' => 'menu_order, post_title',
40 'sort_order' => 'ASC',
41 'link_before' => '',
42 'link_after' => '',
43 'class' => ''
44 ), $atts ) );
45
46 $page_list_args = array(
47 'depth' => $depth,
48 'child_of' => pagelist_unqprfx_norm_params($child_of),
49 'exclude' => pagelist_unqprfx_norm_params($exclude),
50 'exclude_tree' => $exclude_tree,
51 'include' => $include,
52 'title_li' => $title_li,
53 'number' => $number,
54 'offset' => $offset,
55 'meta_key' => $meta_key,
56 'meta_value' => $meta_value,
57 'show_date' => $show_date,
58 'date_format' => get_option('date_format'),
59 'echo' => 0,
60 'authors' => '',
61 'sort_column' => $sort_column,
62 'sort_order' => $sort_order,
63 'link_before' => $link_before,
64 'link_after' => $link_after,
65 'walker' => ''
66 );
67 $list_pages = wp_list_pages( $page_list_args );
68
69 $return = $pagelist_unqprfx_powered_line;
70 if ($list_pages) {
71 $return .= '<ul class="page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
72 }else{
73 $return .= '<!-- no pages to show -->';
74 }
75 return $return;
76 }
77 add_shortcode( 'pagelist', 'pagelist_unqprfx_shortcode' );
78 add_shortcode( 'page_list', 'pagelist_unqprfx_shortcode' );
79 add_shortcode( 'page-list', 'pagelist_unqprfx_shortcode' ); // not good (Shortcode names should be all lowercase and use all letters, but numbers and underscores (not dashes!) should work fine too.)
80 add_shortcode( 'sitemap', 'pagelist_unqprfx_shortcode' );
81 }
82
83
84 if ( !function_exists('subpages_unqprfx_shortcode') ) {
85 function subpages_unqprfx_shortcode( $atts ) {
86 global $post, $pagelist_unqprfx_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_unqprfx_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 $return = $pagelist_unqprfx_powered_line;
131 if ($list_pages) {
132 $return .= '<ul class="page-list subpages-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
133 }else{
134 $return .= '<!-- no pages to show -->';
135 }
136 return $return;
137 }
138 add_shortcode( 'subpages', 'subpages_unqprfx_shortcode' );
139 add_shortcode( 'sub_pages', 'subpages_unqprfx_shortcode' );
140 add_shortcode( 'sub-pages', 'subpages_unqprfx_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_unqprfx_shortcode' );
142 }
143
144
145 if ( !function_exists('siblings_unqprfx_shortcode') ) {
146 function siblings_unqprfx_shortcode( $atts ) {
147 global $post, $pagelist_unqprfx_powered_line;
148 $return = '';
149 extract( shortcode_atts( array(
150 'depth' => '0',
151 //'child_of' => '0',
152 'exclude' => '0',
153 'exclude_tree' => '',
154 'include' => '0',
155 'title_li' => '',
156 'number' => '',
157 'offset' => '',
158 'meta_key' => '',
159 'meta_value' => '',
160 'show_date' => '',
161 'sort_column' => 'menu_order, post_title',
162 'sort_order' => 'ASC',
163 'link_before' => '',
164 'link_after' => '',
165 'class' => ''
166 ), $atts ) );
167
168 if( $exclude == 'current' || $exclude == 'this' ){
169 $exclude = $post->ID;
170 }
171
172 $page_list_args = array(
173 'depth' => $depth,
174 'child_of' => $post->post_parent,
175 'exclude' => pagelist_unqprfx_norm_params($exclude),
176 'exclude_tree' => $exclude_tree,
177 'include' => $include,
178 'title_li' => $title_li,
179 'number' => $number,
180 'offset' => $offset,
181 'meta_key' => $meta_key,
182 'meta_value' => $meta_value,
183 'show_date' => $show_date,
184 'date_format' => get_option('date_format'),
185 'echo' => 0,
186 'authors' => '',
187 'sort_column' => $sort_column,
188 'sort_order' => $sort_order,
189 'link_before' => $link_before,
190 'link_after' => $link_after,
191 'walker' => ''
192 );
193 $list_pages = wp_list_pages( $page_list_args );
194
195 $return = $pagelist_unqprfx_powered_line;
196 if ($list_pages) {
197 $return .= '<ul class="page-list siblings-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>';
198 }else{
199 $return .= '<!-- no pages to show -->';
200 }
201 return $return;
202 }
203 add_shortcode( 'siblings', 'siblings_unqprfx_shortcode' );
204 }
205
206
207 if ( !function_exists('pagelist_unqprfx_ext_shortcode') ) {
208 function pagelist_unqprfx_ext_shortcode( $atts ) {
209 global $post, $pagelist_unqprfx_powered_line;
210 $return = '';
211 extract( shortcode_atts( array(
212 'show_image' => 1,
213 'show_first_image' => 0,
214 'show_title' => 1,
215 'show_content' => 1,
216 'more_tag' => 1,
217 'limit_content' => 250,
218 'image_width' => '50',
219 'image_height' => '50',
220 'child_of' => '',
221 'sort_order' => 'ASC',
222 'sort_column' => 'menu_order, post_title',
223 'hierarchical' => 1,
224 'exclude' => '0',
225 'include' => '0',
226 'meta_key' => '',
227 'meta_value' => '',
228 'authors' => '',
229 'parent' => -1,
230 'exclude_tree' => '',
231 'number' => '',
232 'offset' => 0,
233 'post_type' => 'page',
234 'post_status' => 'publish',
235 'class' => '',
236 'strip_tags' => 1,
237 'strip_shortcodes' => 1,
238 'show_child_count' => 0,
239 'child_count_template' => 'Subpages: %child_count%',
240 'show_meta_key' => '',
241 'meta_template' => '%meta%'
242 ), $atts ) );
243
244 if( $child_of == '' ){ // show subpages if child_of is empty
245 $child_of = $post->ID;
246 }
247
248 $page_list_ext_args = array(
249 'show_image' => $show_image,
250 'show_first_image' => $show_first_image,
251 'show_title' => $show_title,
252 'show_content' => $show_content,
253 'more_tag' => $more_tag,
254 'limit_content' => $limit_content,
255 'image_width' => $image_width,
256 'image_height' => $image_height,
257 'child_of' => pagelist_unqprfx_norm_params($child_of),
258 'sort_order' => $sort_order,
259 'sort_column' => $sort_column,
260 'hierarchical' => $hierarchical,
261 'exclude' => pagelist_unqprfx_norm_params($exclude),
262 'include' => $include,
263 'meta_key' => $meta_key,
264 'meta_value' => $meta_value,
265 'authors' => $authors,
266 'parent' => pagelist_unqprfx_norm_params($parent),
267 'exclude_tree' => $exclude_tree,
268 'number' => '', // $number - own counter
269 'offset' => 0, // $offset - own offset
270 'post_type' => $post_type,
271 'post_status' => $post_status,
272 'class' => $class,
273 'strip_tags' => $strip_tags,
274 'strip_shortcodes' => $strip_shortcodes,
275 'show_child_count' => $show_child_count,
276 'child_count_template' => $child_count_template,
277 'show_meta_key' => $show_meta_key,
278 'meta_template' => $meta_template
279 );
280 $page_list_ext_args_all = array(
281 'show_image' => $show_image,
282 'show_first_image' => $show_first_image,
283 'show_title' => $show_title,
284 'show_content' => $show_content,
285 'more_tag' => $more_tag,
286 'limit_content' => $limit_content,
287 'image_width' => $image_width,
288 'image_height' => $image_height,
289 'child_of' => 0, // for showing all pages
290 'sort_order' => $sort_order,
291 'sort_column' => $sort_column,
292 'hierarchical' => $hierarchical,
293 'exclude' => pagelist_unqprfx_norm_params($exclude),
294 'include' => $include,
295 'meta_key' => $meta_key,
296 'meta_value' => $meta_value,
297 'authors' => $authors,
298 'parent' => pagelist_unqprfx_norm_params($parent),
299 'exclude_tree' => $exclude_tree,
300 'number' => '', // $number - own counter
301 'offset' => 0, // $offset - own offset
302 'post_type' => $post_type,
303 'post_status' => $post_status,
304 'class' => $class,
305 'strip_tags' => $strip_tags,
306 'strip_shortcodes' => $strip_shortcodes,
307 'show_child_count' => $show_child_count,
308 'child_count_template' => $child_count_template,
309 'show_meta_key' => $show_meta_key,
310 'meta_template' => $meta_template
311 );
312 $list_pages = get_pages( $page_list_ext_args );
313 if( count( $list_pages ) == 0 ){ // if there is no subpages
314 $list_pages = get_pages( $page_list_ext_args_all ); // we are showing all pages
315 }
316 $list_pages_html = '';
317 $count = 0;
318 $offset_count = 0;
319 foreach($list_pages as $page){
320 $count++;
321 $offset_count++;
322 if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) {
323 $count = 0; // number counter to zero if offset is not finished
324 }
325 if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) {
326 if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) {
327 $link = get_permalink( $page->ID );
328 $list_pages_html .= '<div class="page-list-ext-item">';
329 if( $show_image == 1 ){
330 if ( function_exists( 'get_the_post_thumbnail' ) ) { // if we have WordPress 2.9+
331 if( get_the_post_thumbnail( $page->ID ) ){ // if there is a featured image
332 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
333 //$list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height)); // doesn't work good with image size
334
335 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), array($image_width,$image_height) ); // get featured img; 'large'
336 $img_url = $image[0]; // get the src of the featured image
337 $list_pages_html .= '<img src="'.$img_url.'" width="'.$image_width.'" alt="'.esc_attr($page->post_title).'" />'; // not using height="'.$image_height.'" because images could be not square shaped and they will be stretched
338
339 $list_pages_html .= '</a></div> ';
340 }else{
341 if( $show_first_image == 1 ){
342 $img_scr = pagelist_unqprfx_get_first_image( $page->post_content );
343 if( !empty( $img_scr ) ){
344 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
345 $list_pages_html .= '<img src="'.$img_scr.'" width="'.$image_width.'" alt="'.esc_attr($page->post_title).'" />'; // not using height="'.$image_height.'" because images could be not square shaped and they will be stretched
346 $list_pages_html .= '</a></div> ';
347 }
348 }
349 }
350 }else{ // if we have old WordPress 2.8 or lower
351 if( $show_first_image == 1 ){
352 $img_scr = pagelist_unqprfx_get_first_image( $page->post_content );
353 if( !empty( $img_scr ) ){
354 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
355 $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
356 $list_pages_html .= '</a></div> ';
357 }
358 }
359 }
360 }
361
362
363 if( $show_title == 1 ){
364 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'.$page->post_title.'</a></h3>';
365 }
366 if( $show_content == 1 ){
367 //$content = apply_filters('the_content', $page->post_content);
368 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
369
370 if( !empty( $page->post_excerpt ) ){
371 $text_content = $page->post_excerpt;
372 }else{
373 $text_content = $page->post_content;
374 }
375
376 if ( post_password_required($page) ) {
377 $content = '<!-- password protected -->';
378 }else{
379 $content = pagelist_unqprfx_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
380 $content = do_shortcode( $content );
381
382 if( $show_title == 0 ){ // make content as a link if there is no title
383 $content = '<a href="'.$link.'">'.$content.'</a>';
384 }
385 }
386
387 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
388
389 }
390 if( $show_child_count == 1 ){
391 $count_subpages = count(get_pages("child_of=".$page->ID));
392 if( $count_subpages > 0 ){ // hide empty
393 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
394 if($child_count_pos === false) { // %child_count% not found in template
395 $child_count_template_html = $child_count_template.' '.$count_subpages;
396 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
397 } else { // %child_count% found in template
398 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
399 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
400 }
401 }
402 }
403 if( $show_meta_key != '' ){
404 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
405 if( !empty($post_meta) ){ // hide empty
406 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
407 if($meta_pos === false) { // %meta% not found in template
408 $meta_template_html = $meta_template.' '.$post_meta;
409 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
410 } else { // %meta% found in template
411 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
412 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
413 }
414 }
415 }
416 $list_pages_html .= '</div>'."\n";
417 }
418 }
419 }
420 $return = $pagelist_unqprfx_powered_line;
421 if ($list_pages_html) {
422 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
423 }else{
424 $return .= '<!-- no pages to show -->'; // this line will not work, because we show all pages if there is no pages to show
425 }
426 return $return;
427 }
428 add_shortcode( 'pagelist_ext', 'pagelist_unqprfx_ext_shortcode' );
429 add_shortcode( 'pagelistext', 'pagelist_unqprfx_ext_shortcode' );
430 }
431
432
433 if ( !function_exists('pagelist_unqprfx_norm_params') ) {
434 function pagelist_unqprfx_norm_params( $str ) {
435 global $post;
436 $new_str = $str;
437 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
438 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
439 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
440 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
441 return $new_str;
442 }
443 }
444
445
446 if ( !function_exists('pagelist_unqprfx_parse_content') ) {
447 function pagelist_unqprfx_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
448
449 $more_tag_found = 0;
450 $content_before_more_tag_length = 0;
451
452 if( $more_tag ){ // "more_tag" have higher priority than "limit_content"
453 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
454 $more_tag_found = 1;
455 $more_tag = $matches[0];
456 $content_temp = explode($matches[0], $content);
457 $content_temp = $content_temp[0];
458 $content_before_more_tag_length = strlen($content_temp);
459 $content = substr_replace($content, '###more###', $content_before_more_tag_length, 0);
460 }
461 }
462
463 // replace php and comments tags so they do not get stripped
464 //$content = preg_replace("@<\?@", "#?#", $content);
465 //$content = preg_replace("@<!--@", "#!--#", $content); // save html comments
466 // strip tags normally
467 //$content = strip_tags($content);
468 if( $strip_tags ){
469 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
470 $content = strip_tags($content); // ,'<p>'
471 }
472 // return php and comments tags to their origial form
473 //$content = preg_replace("@#\?#@", "<?", $content);
474 //$content = preg_replace("@#!--#@", "<!--", $content);
475
476 if( $strip_shortcodes ){
477 $content = strip_shortcodes( $content );
478 }
479
480 if( $more_tag && $more_tag_found ){ // "more_tag" have higher priority than "limit_content"
481 $fake_more_pos = mb_strpos($content, '###more###', 0, 'UTF-8');
482 if( $fake_more_pos === false ) {
483 // substring not found in string and this is strange :)
484 } else {
485 $content = mb_substr($content, 0, $fake_more_pos, 'UTF-8');
486 }
487 }else{
488 if( strlen($content) > $limit_content ){ // limiting content
489 $pos = strpos($content, ' ', $limit_content); // find first space position
490 if ($pos !== false) {
491 $first_space_pos = $pos;
492 }else{
493 $first_space_pos = $limit_content;
494 }
495 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
496 }
497 }
498
499 $output = force_balance_tags($content);
500 return $output;
501 }
502 }
503
504
505 if ( !function_exists('pagelist_unqprfx_get_first_image') ) {
506 function pagelist_unqprfx_get_first_image( $content='' ) {
507 $first_img = '';
508 //ob_start();
509 //ob_end_clean();
510 $matchCount = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
511 if ( $matchCount !== 0 ) { // if we found first image
512 $first_img = $matches[1][0];
513 }
514 return $first_img;
515 }
516 }
517
518 if ( !function_exists('pagelist_unqprfx_plugin_meta') ) {
519 function pagelist_unqprfx_plugin_meta( $links, $file ) { // add 'Support' and 'Donate' links to plugin meta row
520 if ( strpos( $file, 'page-list.php' ) !== false ) {
521 $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/page-list/" title="Need help?">' . __('Support') . '</a>' ) );
522 $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">' . __('Donate') . '</a>' ) );
523 }
524 return $links;
525 }
526 add_filter( 'plugin_row_meta', 'pagelist_unqprfx_plugin_meta', 10, 2 );
527 }