PluginProbe
Page-list / 3.8
Page-list v3.8
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.8, at page-list.php

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