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

511 lines 19.5 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.7
7 Author: webvitaly
8 Author URI: http://web-profile.net/wordpress/plugins/
9 License: GPLv3
10 */
11
12 define('PAGE_LIST_PLUGIN_VERSION', '5.7');
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 '.esc_attr($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' => isset($post->ID) ? $post->ID : 0,
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 '.esc_attr($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 = isset($post->ID) ? $post->ID : 0;
146 }
147
148 $page_list_args = array(
149 'depth' => $depth,
150 'child_of' => isset($post->post_parent) ? $post->post_parent : 0,
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 '.esc_attr($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 // Sanitize and validate image_width
222 $image_width = absint($image_width);
223 if ($image_width === 0) {
224 $image_width = 150; // Set a default value if invalid input is provided
225 }
226
227 // Sanitize and validate image_height
228 $image_height = absint($image_height);
229 if ($image_height === 0) {
230 $image_height = 150; // Set a default value if invalid input is provided
231 }
232
233 if ( $child_of == '' ) { // show subpages if child_of is empty
234 $child_of = isset($post->ID) ? $post->ID : 0;
235 }
236
237 $page_list_ext_args = array(
238 'show_image' => $show_image,
239 'show_first_image' => $show_first_image,
240 'show_title' => $show_title,
241 'show_content' => $show_content,
242 'more_tag' => $more_tag,
243 'limit_content' => $limit_content,
244 'image_width' => $image_width,
245 'image_height' => $image_height,
246 'sort_order' => $sort_order,
247 'sort_column' => $sort_column,
248 'hierarchical' => $hierarchical,
249 'exclude' => pagelist_unqprfx_norm_params($exclude),
250 'include' => pagelist_unqprfx_norm_params($include),
251 'meta_key' => $meta_key,
252 'meta_value' => $meta_value,
253 'authors' => $authors,
254 'child_of' => pagelist_unqprfx_norm_params($child_of),
255 'parent' => pagelist_unqprfx_norm_params($parent),
256 'exclude_tree' => pagelist_unqprfx_norm_params($exclude_tree),
257 'number' => '', // $number - own counter
258 'offset' => 0, // $offset - own offset
259 'post_type' => $post_type,
260 'post_status' => $post_status,
261 'class' => $class,
262 'strip_tags' => $strip_tags,
263 'strip_shortcodes' => $strip_shortcodes,
264 'show_child_count' => $show_child_count,
265 'child_count_template' => $child_count_template,
266 'show_meta_key' => $show_meta_key,
267 'meta_template' => $meta_template
268 );
269 $page_list_ext_args_all = array(
270 'show_image' => $show_image,
271 'show_first_image' => $show_first_image,
272 'show_title' => $show_title,
273 'show_content' => $show_content,
274 'more_tag' => $more_tag,
275 'limit_content' => $limit_content,
276 'image_width' => $image_width,
277 'image_height' => $image_height,
278 'sort_order' => $sort_order,
279 'sort_column' => $sort_column,
280 'hierarchical' => $hierarchical,
281 'exclude' => pagelist_unqprfx_norm_params($exclude),
282 'include' => pagelist_unqprfx_norm_params($include),
283 'meta_key' => $meta_key,
284 'meta_value' => $meta_value,
285 'authors' => $authors,
286 'child_of' => 0, // for showing all pages
287 'parent' => pagelist_unqprfx_norm_params($parent),
288 'exclude_tree' => pagelist_unqprfx_norm_params($exclude_tree),
289 'number' => '', // $number - own counter
290 'offset' => 0, // $offset - own offset
291 'post_type' => $post_type,
292 'post_status' => $post_status,
293 'class' => $class,
294 'strip_tags' => $strip_tags,
295 'strip_shortcodes' => $strip_shortcodes,
296 'show_child_count' => $show_child_count,
297 'child_count_template' => $child_count_template,
298 'show_meta_key' => $show_meta_key,
299 'meta_template' => $meta_template
300 );
301 $list_pages = get_pages( $page_list_ext_args );
302 if ( count( $list_pages ) == 0 ) { // if there is no subpages
303 $list_pages = get_pages( $page_list_ext_args_all ); // we are showing all pages
304 }
305 $list_pages_html = '';
306 $count = 0;
307 $offset_count = 0;
308 if ( $list_pages !== false && count( $list_pages ) > 0 ) {
309 foreach($list_pages as $page){
310 $count++;
311 $offset_count++;
312 if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) {
313 $count = 0; // number counter to zero if offset is not finished
314 }
315 if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) {
316 if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) {
317 $link = get_permalink( $page->ID );
318 $list_pages_html .= '<div class="page-list-ext-item">';
319 if ( $show_image == 1 ) {
320 if ( get_the_post_thumbnail( $page->ID ) ) { // if there is a featured image
321 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
322 //$list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height)); // doesn't work good with image size
323
324 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), array($image_width,$image_height) ); // get featured img; 'large'
325 $img_url = $image[0]; // get the src of the featured image
326 $list_pages_html .= '<img src="'.$img_url.'" width="'.esc_attr($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
327
328 $list_pages_html .= '</a></div> ';
329 } else {
330 if ( $show_first_image == 1 ) {
331 $img_scr = pagelist_unqprfx_get_first_image( $page->post_content );
332 if ( !empty( $img_scr ) ) {
333 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
334 $list_pages_html .= '<img src="'.$img_scr.'" width="'.esc_attr($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
335 $list_pages_html .= '</a></div> ';
336 }
337 }
338 }
339 }
340
341
342 if ( $show_title == 1 ) {
343 $list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'.$page->post_title.'</a></h3>';
344 }
345 if ( $show_content == 1 ) {
346 //$content = apply_filters('the_content', $page->post_content);
347 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
348
349 if ( !empty( $page->post_excerpt ) ) {
350 $text_content = $page->post_excerpt;
351 } else {
352 $text_content = $page->post_content;
353 }
354
355 if ( post_password_required($page) ) {
356 $content = '<!-- password protected -->';
357 } else {
358 $content = pagelist_unqprfx_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
359 $content = do_shortcode( $content );
360
361 if ( $show_title == 0 ) { // make content as a link if there is no title
362 $content = '<a href="'.$link.'">'.$content.'</a>';
363 }
364 }
365
366 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
367
368 }
369 if ( $show_child_count == 1 ) {
370 $count_subpages = count(get_pages("child_of=".$page->ID));
371 if ( $count_subpages > 0 ) { // hide empty
372 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
373 if ($child_count_pos === false) { // %child_count% not found in template
374 $child_count_template_html = $child_count_template.' '.$count_subpages;
375 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
376 } else { // %child_count% found in template
377 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
378 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
379 }
380 }
381 }
382 if ( $show_meta_key != '' ) {
383 $post_meta = do_shortcode(get_post_meta($page->ID, $show_meta_key, true));
384 if ( !empty($post_meta) ) { // hide empty
385 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
386 if ($meta_pos === false) { // %meta% not found in template
387 $meta_template_html = $meta_template.' '.$post_meta;
388 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
389 } else { // %meta% found in template
390 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
391 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
392 }
393 }
394 }
395 $list_pages_html .= '</div>'."\n";
396 }
397 }
398 }
399 }
400 $return .= $pagelist_unq_settings['powered_by'];
401 if ($list_pages_html) {
402 $return .= '<div class="page-list page-list-ext '.esc_attr($class).'">'."\n".$list_pages_html."\n".'</div>';
403 } else {
404 $return .= '<!-- no pages to show -->'; // this line will not work, because we show all pages if there is no pages to show
405 }
406 return $return;
407 }
408 add_shortcode( 'pagelist_ext', 'pagelist_unqprfx_ext_shortcode' );
409 add_shortcode( 'pagelistext', 'pagelist_unqprfx_ext_shortcode' );
410 }
411
412
413 if ( !function_exists('pagelist_unqprfx_norm_params') ) {
414 function pagelist_unqprfx_norm_params( $str ) {
415 global $post;
416 $new_str = $str;
417 if(isset($post)) {
418 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
419 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
420 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
421 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
422 }
423 return $new_str;
424 }
425 }
426
427
428 if ( !function_exists('pagelist_unqprfx_parse_content') ) {
429 function pagelist_unqprfx_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
430
431 $more_tag_found = 0;
432
433 if ( $more_tag ) { // "more_tag" have higher priority than "limit_content"
434 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
435 $more_tag_found = 1;
436 $more_tag = $matches[0];
437 $content_temp = explode($matches[0], $content);
438 $content_temp = $content_temp[0];
439 $content_before_more_tag_length = strlen($content_temp);
440 $content = substr_replace($content, '###more###', $content_before_more_tag_length, 0);
441 }
442 }
443
444 // replace php and comments tags so they do not get stripped
445 //$content = preg_replace("@<\?@", "#?#", $content);
446 //$content = preg_replace("@<!--@", "#!--#", $content); // save html comments
447 // strip tags normally
448 //$content = strip_tags($content);
449 if ( $strip_tags ) {
450 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
451 $content = strip_tags($content); // ,'<p>'
452 }
453 // return php and comments tags to their origial form
454 //$content = preg_replace("@#\?#@", "<?", $content);
455 //$content = preg_replace("@#!--#@", "<!--", $content);
456
457 if ( $strip_shortcodes ) {
458 $content = strip_shortcodes( $content );
459 }
460
461 if ( $more_tag && $more_tag_found ) { // "more_tag" have higher priority than "limit_content"
462 $fake_more_pos = mb_strpos($content, '###more###', 0, 'UTF-8');
463 if ( $fake_more_pos === false ) {
464 // substring not found in string and this is strange :)
465 } else {
466 $content = mb_substr($content, 0, $fake_more_pos, 'UTF-8');
467 }
468 } else {
469 if ( strlen($content) > $limit_content ) { // limiting content
470 $pos = strpos($content, ' ', $limit_content); // find first space position
471 if ($pos !== false) {
472 $first_space_pos = $pos;
473 } else {
474 $first_space_pos = $limit_content;
475 }
476 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
477 }
478 }
479
480 $output = force_balance_tags($content);
481 return $output;
482 }
483 }
484
485
486 if ( !function_exists('pagelist_unqprfx_get_first_image') ) {
487 function pagelist_unqprfx_get_first_image( $content='' ) {
488 $first_img = '';
489 $matchCount = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
490 if ( $matchCount !== 0 ) { // if we found first image
491 $first_img = $matches[1][0];
492 }
493 return $first_img;
494 }
495 }
496
497 if ( ! function_exists('pagelist_unqprfx_plugin_meta') ) {
498 function pagelist_unqprfx_plugin_meta( $links, $file ) { // add links to plugin meta row
499 if ( $file == plugin_basename( __FILE__ ) ) {
500 $row_meta = array(
501 'support' => '<a href="http://web-profile.net/wordpress/plugins/page-list/" target="_blank">' . __( 'Page-list', 'page-list' ) . '</a>',
502 'donate' => '<a href="http://web-profile.net/donate/" target="_blank">' . __( 'Donate', 'page-list' ) . '</a>',
503 'pro' => '<a href="https://1.envato.market/KdRNz" target="_blank" title="Advanced iFrame Pro">' . __( 'Advanced iFrame Pro', 'page-list' ) . '</a>'
504 );
505 $links = array_merge( $links, $row_meta );
506 }
507 return (array) $links;
508 }
509 add_filter( 'plugin_row_meta', 'pagelist_unqprfx_plugin_meta', 10, 2 );
510 }
511