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

522 lines 19.0 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.0
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.0', '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.0 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')) {
331 if( get_the_post_thumbnail($page->ID) ){
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));
334 $list_pages_html .= '</a></div> ';
335 }else{
336 if( $show_first_image == 1 ){
337 $img_scr = pagelist_unqprfx_get_first_image( $page->post_content );
338 if( !empty( $img_scr ) ){
339 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
340 $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
341 $list_pages_html .= '</a></div> ';
342 }
343 }
344 }
345 }else{
346 if( $show_first_image == 1 ){
347 $img_scr = pagelist_unqprfx_get_first_image( $page->post_content );
348 if( !empty( $img_scr ) ){
349 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
350 $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
351 $list_pages_html .= '</a></div> ';
352 }
353 }
354 }
355 }
356
357
358 if( $show_title == 1 ){
359 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'.$page->post_title.'</a></h3>';
360 }
361 if( $show_content == 1 ){
362 //$content = apply_filters('the_content', $page->post_content);
363 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
364
365 if( !empty( $page->post_excerpt ) ){
366 $text_content = $page->post_excerpt;
367 }else{
368 $text_content = $page->post_content;
369 }
370
371 if ( post_password_required($page) ) {
372 $content = '<!-- password protected -->';
373 }else{
374 $content = pagelist_unqprfx_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
375 $content = do_shortcode( $content );
376
377 if( $show_title == 0 ){ // make content as a link if there is no title
378 $content = '<a href="'.$link.'">'.$content.'</a>';
379 }
380 }
381
382 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
383
384 }
385 if( $show_child_count == 1 ){
386 $count_subpages = count(get_pages("child_of=".$page->ID));
387 if( $count_subpages > 0 ){ // hide empty
388 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
389 if($child_count_pos === false) { // %child_count% not found in template
390 $child_count_template_html = $child_count_template.' '.$count_subpages;
391 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
392 } else { // %child_count% found in template
393 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
394 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
395 }
396 }
397 }
398 if( $show_meta_key != '' ){
399 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
400 if( !empty($post_meta) ){ // hide empty
401 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
402 if($meta_pos === false) { // %meta% not found in template
403 $meta_template_html = $meta_template.' '.$post_meta;
404 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
405 } else { // %meta% found in template
406 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
407 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
408 }
409 }
410 }
411 $list_pages_html .= '</div>'."\n";
412 }
413 }
414 }
415 $return = $pagelist_unqprfx_powered_line;
416 if ($list_pages_html) {
417 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
418 }else{
419 $return .= '<!-- no pages to show -->'; // this line will not work, because we show all pages if there is no pages to show
420 }
421 return $return;
422 }
423 add_shortcode( 'pagelist_ext', 'pagelist_unqprfx_ext_shortcode' );
424 add_shortcode( 'pagelistext', 'pagelist_unqprfx_ext_shortcode' );
425 }
426
427
428 if ( !function_exists('pagelist_unqprfx_norm_params') ) {
429 function pagelist_unqprfx_norm_params( $str ) {
430 global $post;
431 $new_str = $str;
432 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
433 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
434 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
435 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
436 return $new_str;
437 }
438 }
439
440
441 if ( !function_exists('pagelist_unqprfx_parse_content') ) {
442 function pagelist_unqprfx_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
443
444 $more_tag_found = 0;
445 $content_before_more_tag_length = 0;
446
447 if( $more_tag ){ // "more_tag" have higher priority than "limit_content"
448 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
449 $more_tag_found = 1;
450 $more_tag = $matches[0];
451 $content_temp = explode($matches[0], $content);
452 $content_temp = $content_temp[0];
453 $content_before_more_tag_length = strlen($content_temp);
454 $content = substr_replace($content, '###more###', $content_before_more_tag_length, 0);
455 }
456 }
457
458 // replace php and comments tags so they do not get stripped
459 //$content = preg_replace("@<\?@", "#?#", $content);
460 //$content = preg_replace("@<!--@", "#!--#", $content); // save html comments
461 // strip tags normally
462 //$content = strip_tags($content);
463 if( $strip_tags ){
464 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
465 $content = strip_tags($content); // ,'<p>'
466 }
467 // return php and comments tags to their origial form
468 //$content = preg_replace("@#\?#@", "<?", $content);
469 //$content = preg_replace("@#!--#@", "<!--", $content);
470
471 if( $strip_shortcodes ){
472 $content = strip_shortcodes( $content );
473 }
474
475 if( $more_tag && $more_tag_found ){ // "more_tag" have higher priority than "limit_content"
476 $fake_more_pos = mb_strpos($content, '###more###', 0, 'UTF-8');
477 if( $fake_more_pos === false ) {
478 // substring not found in string and this is strange :)
479 } else {
480 $content = mb_substr($content, 0, $fake_more_pos, 'UTF-8');
481 }
482 }else{
483 if( strlen($content) > $limit_content ){ // limiting content
484 $pos = strpos($content, ' ', $limit_content); // find first space position
485 if ($pos !== false) {
486 $first_space_pos = $pos;
487 }else{
488 $first_space_pos = $limit_content;
489 }
490 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
491 }
492 }
493
494 $output = force_balance_tags($content);
495 return $output;
496 }
497 }
498
499
500 if ( !function_exists('pagelist_unqprfx_get_first_image') ) {
501 function pagelist_unqprfx_get_first_image( $content='' ) {
502 $first_img = '';
503 //ob_start();
504 //ob_end_clean();
505 $matchCount = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
506 if ( $matchCount !== 0 ) { // if we found first image
507 $first_img = $matches[1][0];
508 }
509 return $first_img;
510 }
511 }
512
513 if ( !function_exists('pagelist_unqprfx_plugin_meta') ) {
514 function pagelist_unqprfx_plugin_meta( $links, $file ) { // add 'Support' and 'Donate' links to plugin meta row
515 if ( strpos( $file, 'page-list.php' ) !== false ) {
516 $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/page-list/" title="Need help?">' . __('Support') . '</a>' ) );
517 $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">' . __('Donate') . '</a>' ) );
518 }
519 return $links;
520 }
521 add_filter( 'plugin_row_meta', 'pagelist_unqprfx_plugin_meta', 10, 2 );
522 }