PluginProbe
Page-list / 5.2
Page-list v5.2
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 5.2, at page-list.php

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