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

469 lines 16.4 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.1
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.1', 'all' );
20 }
21
22 $pagelist_powered_line = "\n".'<!-- Page-list plugin v.3.1 (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 'more_tag' => 1,
215 'limit_content' => 250,
216 'image_width' => '50',
217 'image_height' => '50',
218 'child_of' => '0',
219 'sort_order' => 'ASC',
220 'sort_column' => 'menu_order, post_title',
221 'hierarchical' => 1,
222 'exclude' => '0',
223 'include' => '0',
224 'meta_key' => '',
225 'meta_value' => '',
226 'authors' => '',
227 'parent' => -1,
228 'exclude_tree' => '',
229 'number' => '',
230 'offset' => 0,
231 'post_type' => 'page',
232 'post_status' => 'publish',
233 'class' => '',
234 'strip_tags' => 1,
235 'strip_shortcodes' => 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 'more_tag' => $more_tag,
252 'limit_content' => $limit_content,
253 'image_width' => $image_width,
254 'image_height' => $image_height,
255 'child_of' => pagelist_norm_params($child_of),
256 'sort_order' => $sort_order,
257 'sort_column' => $sort_column,
258 'hierarchical' => $hierarchical,
259 'exclude' => pagelist_norm_params($exclude),
260 'include' => $include,
261 'meta_key' => $meta_key,
262 'meta_value' => $meta_value,
263 'authors' => $authors,
264 'parent' => pagelist_norm_params($parent),
265 'exclude_tree' => $exclude_tree,
266 'number' => '', // $number - own counter
267 'offset' => 0, // $offset - own offset
268 'post_type' => $post_type,
269 'post_status' => $post_status,
270 'class' => $class,
271 'strip_tags' => $strip_tags,
272 'strip_shortcodes' => $strip_shortcodes,
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 if( !empty( $img_scr ) ){
302 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
303 $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
304 $list_pages_html .= '</a></div> ';
305 }
306 }
307 }
308 }else{
309 if( $show_first_image == 1 ){
310 $img_scr = get_first_image( $page->post_content );
311 if( !empty( $img_scr ) ){
312 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
313 $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
314 $list_pages_html .= '</a></div> ';
315 }
316 }
317 }
318 }
319
320 // get_first_image()
321
322 if( $show_title == 1 ){
323 $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>';
324 }
325 if( $show_content == 1 ){
326 //$content = apply_filters('the_content', $page->post_content);
327 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
328
329 if( !empty( $page->post_excerpt ) ){
330 $text_content = $page->post_excerpt;
331 }else{
332 $text_content = $page->post_content;
333 }
334
335 if ( post_password_required($page) ) {
336 $content = '<!-- password protected -->';
337 }else{
338 $content = page_list_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
339
340 if( $show_title == 0 ){ // make content as a link if there is no title
341 $content = '<a href="'.$link.'">'.$content.'</a>';
342 }
343 }
344
345 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
346
347 }
348 if( $show_child_count == 1 ){
349 $count_subpages = count(get_pages("child_of=".$page->ID));
350 if( $count_subpages > 0 ){ // hide empty
351 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
352 if($child_count_pos === false) { // %child_count% not found in template
353 $child_count_template_html = $child_count_template.' '.$count_subpages;
354 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
355 } else { // %child_count% found in template
356 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
357 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
358 }
359 }
360 }
361 if( $show_meta_key != '' ){
362 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
363 if( !empty($post_meta) ){ // hide empty
364 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
365 if($meta_pos === false) { // %meta% not found in template
366 $meta_template_html = $meta_template.' '.$post_meta;
367 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
368 } else { // %meta% found in template
369 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
370 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
371 }
372 }
373 }
374 $list_pages_html .= '</div>'."\n";
375 }
376 }
377 }
378 if ($list_pages_html) {
379 $return = $pagelist_powered_line;
380 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
381 }else{
382 $return = '';
383 }
384 return $return;
385 }
386 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
387 }
388
389 if ( !function_exists('pagelist_norm_params') ) {
390 function pagelist_norm_params( $str ) {
391 global $post;
392 $new_str = $str;
393 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
394 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
395 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
396 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
397 return $new_str;
398 }
399 }
400
401 if ( !function_exists('page_list_parse_content') ) {
402 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
403
404 $more_tag_found = 0;
405 $content_before_more_tag_length = 0;
406
407 if( $more_tag ){ // "more_tag" have higher priority than "limit_content"
408 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
409 $more_tag_found = 1;
410 $more_tag = $matches[0];
411 $content_temp = explode($matches[0], $content);
412 $content_temp = $content_temp[0];
413 $content_before_more_tag_length = strlen($content_temp);
414 $content = substr_replace($content, '###more###', $content_before_more_tag_length, 0);
415 }
416 }
417
418 // replace php and comments tags so they do not get stripped
419 //$content = preg_replace("@<\?@", "#?#", $content);
420 //$content = preg_replace("@<!--@", "#!--#", $content); // save html comments
421 // strip tags normally
422 //$content = strip_tags($content);
423 if( $strip_tags ){
424 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
425 $content = strip_tags($content); // ,'<p>'
426 }
427 // return php and comments tags to their origial form
428 //$content = preg_replace("@#\?#@", "<?", $content);
429 //$content = preg_replace("@#!--#@", "<!--", $content);
430
431 if( $strip_shortcodes ){
432 $content = strip_shortcodes( $content );
433 }
434
435 if( $more_tag && $more_tag_found ){ // "more_tag" have higher priority than "limit_content"
436 $fake_more_pos = strpos($content, '###more###');
437 if( $fake_more_pos === false ) {
438 // substring not found in string and this is strange :)
439 } else {
440 $content = mb_substr($content, 0, $fake_more_pos, 'UTF-8');
441 }
442 }else{
443 if( strlen($content) > $limit_content ){ // limiting content
444 $pos = strpos($content, ' ', $limit_content); // find first space position
445 if ($pos !== false) {
446 $first_space_pos = $pos;
447 }else{
448 $first_space_pos = $limit_content;
449 }
450 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
451 }
452 }
453
454 $output = force_balance_tags($content);
455 return $output;
456 }
457 }
458
459 function get_first_image( $content='' ) {
460 $first_img = '';
461 //ob_start();
462 //ob_end_clean();
463 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
464 $first_img = $matches[1][0];
465 if(empty($first_img)){ // no image found
466 $first_img = '';
467 }
468 return $first_img;
469 }