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

465 lines 16.3 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.3
7 Author: webvitaly
8 Author Email: webvitaly(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.3', 'all' );
15 }
16
17 $pagelist_powered_line = "\n".'<!-- Page-list plugin v.3.3 (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' => '0',
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 == '0' ){
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 $list_pages = get_pages( $page_list_ext_args );
274 $list_pages_html = '';
275 $count = 0;
276 $offset_count = 0;
277 foreach($list_pages as $page){
278 $count++;
279 $offset_count++;
280 if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) {
281 $count = 0; // number counter to zero if offset is not finished
282 }
283 if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) {
284 if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) {
285 $link = get_permalink( $page->ID );
286 $list_pages_html .= '<div class="page-list-ext-item">';
287 if( $show_image == 1 ){
288 if (function_exists('get_the_post_thumbnail')) {
289 if( get_the_post_thumbnail($page->ID) ){
290 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
291 $list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height));
292 $list_pages_html .= '</a></div> ';
293 }else{
294 if( $show_first_image == 1 ){
295 $img_scr = page_list_get_first_image( $page->post_content );
296 if( !empty( $img_scr ) ){
297 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
298 $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
299 $list_pages_html .= '</a></div> ';
300 }
301 }
302 }
303 }else{
304 if( $show_first_image == 1 ){
305 $img_scr = page_list_get_first_image( $page->post_content );
306 if( !empty( $img_scr ) ){
307 $list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">';
308 $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
309 $list_pages_html .= '</a></div> ';
310 }
311 }
312 }
313 }
314
315
316 if( $show_title == 1 ){
317 $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>';
318 }
319 if( $show_content == 1 ){
320 //$content = apply_filters('the_content', $page->post_content);
321 //$content = str_replace(']]>', ']]&gt;', $content); // both used in default the_content() function
322
323 if( !empty( $page->post_excerpt ) ){
324 $text_content = $page->post_excerpt;
325 }else{
326 $text_content = $page->post_content;
327 }
328
329 if ( post_password_required($page) ) {
330 $content = '<!-- password protected -->';
331 }else{
332 $content = page_list_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag );
333
334 if( $show_title == 0 ){ // make content as a link if there is no title
335 $content = '<a href="'.$link.'">'.$content.'</a>';
336 }
337 }
338
339 $list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>';
340
341 }
342 if( $show_child_count == 1 ){
343 $count_subpages = count(get_pages("child_of=".$page->ID));
344 if( $count_subpages > 0 ){ // hide empty
345 $child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template
346 if($child_count_pos === false) { // %child_count% not found in template
347 $child_count_template_html = $child_count_template.' '.$count_subpages;
348 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
349 } else { // %child_count% found in template
350 $child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template);
351 $list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>';
352 }
353 }
354 }
355 if( $show_meta_key != '' ){
356 $post_meta = get_post_meta($page->ID, $show_meta_key, true);
357 if( !empty($post_meta) ){ // hide empty
358 $meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template
359 if($meta_pos === false) { // %meta% not found in template
360 $meta_template_html = $meta_template.' '.$post_meta;
361 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
362 } else { // %meta% found in template
363 $meta_template_html = str_replace('%meta%', $post_meta, $meta_template);
364 $list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>';
365 }
366 }
367 }
368 $list_pages_html .= '</div>'."\n";
369 }
370 }
371 }
372 if ($list_pages_html) {
373 $return = $pagelist_powered_line;
374 $return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>';
375 }else{
376 $return = '';
377 }
378 return $return;
379 }
380 add_shortcode( 'pagelist_ext', 'pagelist_ext_shortcode' );
381 }
382
383 if ( !function_exists('pagelist_norm_params') ) {
384 function pagelist_norm_params( $str ) {
385 global $post;
386 $new_str = $str;
387 $new_str = str_replace('this', $post->ID, $new_str); // exclude this page
388 $new_str = str_replace('current', $post->ID, $new_str); // exclude current page
389 $new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake
390 $new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page
391 return $new_str;
392 }
393 }
394
395 if ( !function_exists('page_list_parse_content') ) {
396 function page_list_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) {
397
398 $more_tag_found = 0;
399 $content_before_more_tag_length = 0;
400
401 if( $more_tag ){ // "more_tag" have higher priority than "limit_content"
402 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
403 $more_tag_found = 1;
404 $more_tag = $matches[0];
405 $content_temp = explode($matches[0], $content);
406 $content_temp = $content_temp[0];
407 $content_before_more_tag_length = strlen($content_temp);
408 $content = substr_replace($content, '###more###', $content_before_more_tag_length, 0);
409 }
410 }
411
412 // replace php and comments tags so they do not get stripped
413 //$content = preg_replace("@<\?@", "#?#", $content);
414 //$content = preg_replace("@<!--@", "#!--#", $content); // save html comments
415 // strip tags normally
416 //$content = strip_tags($content);
417 if( $strip_tags ){
418 $content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines
419 $content = strip_tags($content); // ,'<p>'
420 }
421 // return php and comments tags to their origial form
422 //$content = preg_replace("@#\?#@", "<?", $content);
423 //$content = preg_replace("@#!--#@", "<!--", $content);
424
425 if( $strip_shortcodes ){
426 $content = strip_shortcodes( $content );
427 }
428
429 if( $more_tag && $more_tag_found ){ // "more_tag" have higher priority than "limit_content"
430 $fake_more_pos = mb_strpos($content, '###more###', 0, 'UTF-8');
431 if( $fake_more_pos === false ) {
432 // substring not found in string and this is strange :)
433 } else {
434 $content = mb_substr($content, 0, $fake_more_pos, 'UTF-8');
435 }
436 }else{
437 if( strlen($content) > $limit_content ){ // limiting content
438 $pos = strpos($content, ' ', $limit_content); // find first space position
439 if ($pos !== false) {
440 $first_space_pos = $pos;
441 }else{
442 $first_space_pos = $limit_content;
443 }
444 $content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...';
445 }
446 }
447
448 $output = force_balance_tags($content);
449 return $output;
450 }
451 }
452
453 if ( !function_exists('page_list_get_first_image') ) {
454 function page_list_get_first_image( $content='' ) {
455 $first_img = '';
456 //ob_start();
457 //ob_end_clean();
458 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
459 $first_img = $matches[1][0];
460 if(empty($first_img)){ // no image found
461 $first_img = '';
462 }
463 return $first_img;
464 }
465 }