| 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: 4.2 |
| 7 |
Author: webvitaly |
| 8 |
Author URI: http://web-profile.com.ua/wordpress/plugins/ |
| 9 |
License: GPLv3 |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( !function_exists('pagelist_unqprfx_add_stylesheet') ) { |
| 13 |
function pagelist_unqprfx_add_stylesheet() { |
| 14 |
wp_enqueue_style( 'page-list-style', plugins_url( '/css/page-list.css', __FILE__ ), false, '4.2', 'all' ); |
| 15 |
} |
| 16 |
add_action('wp_print_styles', 'pagelist_unqprfx_add_stylesheet'); |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
$pagelist_unqprfx_powered_line = "\n".'<!-- Page-list plugin v.4.2 wordpress.org/plugins/page-list/ -->'."\n"; |
| 21 |
|
| 22 |
|
| 23 |
if ( !function_exists('pagelist_unqprfx_shortcode') ) { |
| 24 |
function pagelist_unqprfx_shortcode( $atts ) { |
| 25 |
global $post, $pagelist_unqprfx_powered_line; |
| 26 |
$return = ''; |
| 27 |
extract( shortcode_atts( array( |
| 28 |
'depth' => '0', |
| 29 |
'child_of' => '0', |
| 30 |
'exclude' => '0', |
| 31 |
'exclude_tree' => '', |
| 32 |
'include' => '0', |
| 33 |
'title_li' => '', |
| 34 |
'number' => '', |
| 35 |
'offset' => '', |
| 36 |
'meta_key' => '', |
| 37 |
'meta_value' => '', |
| 38 |
'show_date' => '', |
| 39 |
'sort_column' => 'menu_order, post_title', |
| 40 |
'sort_order' => 'ASC', |
| 41 |
'link_before' => '', |
| 42 |
'link_after' => '', |
| 43 |
'class' => '' |
| 44 |
), $atts ) ); |
| 45 |
|
| 46 |
$page_list_args = array( |
| 47 |
'depth' => $depth, |
| 48 |
'child_of' => pagelist_unqprfx_norm_params($child_of), |
| 49 |
'exclude' => pagelist_unqprfx_norm_params($exclude), |
| 50 |
'exclude_tree' => $exclude_tree, |
| 51 |
'include' => $include, |
| 52 |
'title_li' => $title_li, |
| 53 |
'number' => $number, |
| 54 |
'offset' => $offset, |
| 55 |
'meta_key' => $meta_key, |
| 56 |
'meta_value' => $meta_value, |
| 57 |
'show_date' => $show_date, |
| 58 |
'date_format' => get_option('date_format'), |
| 59 |
'echo' => 0, |
| 60 |
'authors' => '', |
| 61 |
'sort_column' => $sort_column, |
| 62 |
'sort_order' => $sort_order, |
| 63 |
'link_before' => $link_before, |
| 64 |
'link_after' => $link_after, |
| 65 |
'walker' => '' |
| 66 |
); |
| 67 |
$list_pages = wp_list_pages( $page_list_args ); |
| 68 |
|
| 69 |
$return = $pagelist_unqprfx_powered_line; |
| 70 |
if ($list_pages) { |
| 71 |
$return .= '<ul class="page-list '.$class.'">'."\n".$list_pages."\n".'</ul>'; |
| 72 |
}else{ |
| 73 |
$return .= '<!-- no pages to show -->'; |
| 74 |
} |
| 75 |
return $return; |
| 76 |
} |
| 77 |
add_shortcode( 'pagelist', 'pagelist_unqprfx_shortcode' ); |
| 78 |
add_shortcode( 'page_list', 'pagelist_unqprfx_shortcode' ); |
| 79 |
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.) |
| 80 |
add_shortcode( 'sitemap', 'pagelist_unqprfx_shortcode' ); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
if ( !function_exists('subpages_unqprfx_shortcode') ) { |
| 85 |
function subpages_unqprfx_shortcode( $atts ) { |
| 86 |
global $post, $pagelist_unqprfx_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_unqprfx_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 |
$return = $pagelist_unqprfx_powered_line; |
| 131 |
if ($list_pages) { |
| 132 |
$return .= '<ul class="page-list subpages-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>'; |
| 133 |
}else{ |
| 134 |
$return .= '<!-- no pages to show -->'; |
| 135 |
} |
| 136 |
return $return; |
| 137 |
} |
| 138 |
add_shortcode( 'subpages', 'subpages_unqprfx_shortcode' ); |
| 139 |
add_shortcode( 'sub_pages', 'subpages_unqprfx_shortcode' ); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
if ( !function_exists('siblings_unqprfx_shortcode') ) { |
| 144 |
function siblings_unqprfx_shortcode( $atts ) { |
| 145 |
global $post, $pagelist_unqprfx_powered_line; |
| 146 |
$return = ''; |
| 147 |
extract( shortcode_atts( array( |
| 148 |
'depth' => '0', |
| 149 |
//'child_of' => '0', |
| 150 |
'exclude' => '0', |
| 151 |
'exclude_tree' => '', |
| 152 |
'include' => '0', |
| 153 |
'title_li' => '', |
| 154 |
'number' => '', |
| 155 |
'offset' => '', |
| 156 |
'meta_key' => '', |
| 157 |
'meta_value' => '', |
| 158 |
'show_date' => '', |
| 159 |
'sort_column' => 'menu_order, post_title', |
| 160 |
'sort_order' => 'ASC', |
| 161 |
'link_before' => '', |
| 162 |
'link_after' => '', |
| 163 |
'class' => '' |
| 164 |
), $atts ) ); |
| 165 |
|
| 166 |
if( $exclude == 'current' || $exclude == 'this' ){ |
| 167 |
$exclude = $post->ID; |
| 168 |
} |
| 169 |
|
| 170 |
$page_list_args = array( |
| 171 |
'depth' => $depth, |
| 172 |
'child_of' => $post->post_parent, |
| 173 |
'exclude' => pagelist_unqprfx_norm_params($exclude), |
| 174 |
'exclude_tree' => $exclude_tree, |
| 175 |
'include' => $include, |
| 176 |
'title_li' => $title_li, |
| 177 |
'number' => $number, |
| 178 |
'offset' => $offset, |
| 179 |
'meta_key' => $meta_key, |
| 180 |
'meta_value' => $meta_value, |
| 181 |
'show_date' => $show_date, |
| 182 |
'date_format' => get_option('date_format'), |
| 183 |
'echo' => 0, |
| 184 |
'authors' => '', |
| 185 |
'sort_column' => $sort_column, |
| 186 |
'sort_order' => $sort_order, |
| 187 |
'link_before' => $link_before, |
| 188 |
'link_after' => $link_after, |
| 189 |
'walker' => '' |
| 190 |
); |
| 191 |
$list_pages = wp_list_pages( $page_list_args ); |
| 192 |
|
| 193 |
$return = $pagelist_unqprfx_powered_line; |
| 194 |
if ($list_pages) { |
| 195 |
$return .= '<ul class="page-list siblings-page-list '.$class.'">'."\n".$list_pages."\n".'</ul>'; |
| 196 |
}else{ |
| 197 |
$return .= '<!-- no pages to show -->'; |
| 198 |
} |
| 199 |
return $return; |
| 200 |
} |
| 201 |
add_shortcode( 'siblings', 'siblings_unqprfx_shortcode' ); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
if ( !function_exists('pagelist_unqprfx_ext_shortcode') ) { |
| 206 |
function pagelist_unqprfx_ext_shortcode( $atts ) { |
| 207 |
global $post, $pagelist_unqprfx_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' => '150', |
| 217 |
'image_height' => '150', |
| 218 |
'child_of' => '', |
| 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 == '' ){ // show subpages if child_of is empty |
| 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_unqprfx_norm_params($child_of), |
| 256 |
'sort_order' => $sort_order, |
| 257 |
'sort_column' => $sort_column, |
| 258 |
'hierarchical' => $hierarchical, |
| 259 |
'exclude' => pagelist_unqprfx_norm_params($exclude), |
| 260 |
'include' => $include, |
| 261 |
'meta_key' => $meta_key, |
| 262 |
'meta_value' => $meta_value, |
| 263 |
'authors' => $authors, |
| 264 |
'parent' => pagelist_unqprfx_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 |
$page_list_ext_args_all = array( |
| 279 |
'show_image' => $show_image, |
| 280 |
'show_first_image' => $show_first_image, |
| 281 |
'show_title' => $show_title, |
| 282 |
'show_content' => $show_content, |
| 283 |
'more_tag' => $more_tag, |
| 284 |
'limit_content' => $limit_content, |
| 285 |
'image_width' => $image_width, |
| 286 |
'image_height' => $image_height, |
| 287 |
'child_of' => 0, // for showing all pages |
| 288 |
'sort_order' => $sort_order, |
| 289 |
'sort_column' => $sort_column, |
| 290 |
'hierarchical' => $hierarchical, |
| 291 |
'exclude' => pagelist_unqprfx_norm_params($exclude), |
| 292 |
'include' => $include, |
| 293 |
'meta_key' => $meta_key, |
| 294 |
'meta_value' => $meta_value, |
| 295 |
'authors' => $authors, |
| 296 |
'parent' => pagelist_unqprfx_norm_params($parent), |
| 297 |
'exclude_tree' => $exclude_tree, |
| 298 |
'number' => '', // $number - own counter |
| 299 |
'offset' => 0, // $offset - own offset |
| 300 |
'post_type' => $post_type, |
| 301 |
'post_status' => $post_status, |
| 302 |
'class' => $class, |
| 303 |
'strip_tags' => $strip_tags, |
| 304 |
'strip_shortcodes' => $strip_shortcodes, |
| 305 |
'show_child_count' => $show_child_count, |
| 306 |
'child_count_template' => $child_count_template, |
| 307 |
'show_meta_key' => $show_meta_key, |
| 308 |
'meta_template' => $meta_template |
| 309 |
); |
| 310 |
$list_pages = get_pages( $page_list_ext_args ); |
| 311 |
if( count( $list_pages ) == 0 ){ // if there is no subpages |
| 312 |
$list_pages = get_pages( $page_list_ext_args_all ); // we are showing all pages |
| 313 |
} |
| 314 |
$list_pages_html = ''; |
| 315 |
$count = 0; |
| 316 |
$offset_count = 0; |
| 317 |
if( $list_pages !== false && count( $list_pages ) > 0 ){ |
| 318 |
foreach($list_pages as $page){ |
| 319 |
$count++; |
| 320 |
$offset_count++; |
| 321 |
if ( !empty( $offset ) && is_numeric( $offset ) && $offset_count <= $offset ) { |
| 322 |
$count = 0; // number counter to zero if offset is not finished |
| 323 |
} |
| 324 |
if ( ( !empty( $offset ) && is_numeric( $offset ) && $offset_count > $offset ) || ( empty( $offset ) ) || ( !empty( $offset ) && !is_numeric( $offset ) ) ) { |
| 325 |
if ( ( !empty( $number ) && is_numeric( $number ) && $count <= $number ) || ( empty( $number ) ) || ( !empty( $number ) && !is_numeric( $number ) ) ) { |
| 326 |
$link = get_permalink( $page->ID ); |
| 327 |
$list_pages_html .= '<div class="page-list-ext-item">'; |
| 328 |
if( $show_image == 1 ){ |
| 329 |
if ( function_exists( 'get_the_post_thumbnail' ) ) { // if we have WordPress 2.9+ |
| 330 |
if( get_the_post_thumbnail( $page->ID ) ){ // if there is a featured image |
| 331 |
$list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'; |
| 332 |
//$list_pages_html .= get_the_post_thumbnail($page->ID, array($image_width,$image_height)); // doesn't work good with image size |
| 333 |
|
| 334 |
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), array($image_width,$image_height) ); // get featured img; 'large' |
| 335 |
$img_url = $image[0]; // get the src of the featured image |
| 336 |
$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 |
| 337 |
|
| 338 |
$list_pages_html .= '</a></div> '; |
| 339 |
}else{ |
| 340 |
if( $show_first_image == 1 ){ |
| 341 |
$img_scr = pagelist_unqprfx_get_first_image( $page->post_content ); |
| 342 |
if( !empty( $img_scr ) ){ |
| 343 |
$list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'; |
| 344 |
$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 |
| 345 |
$list_pages_html .= '</a></div> '; |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
}else{ // if we have old WordPress 2.8 or lower |
| 350 |
if( $show_first_image == 1 ){ |
| 351 |
$img_scr = pagelist_unqprfx_get_first_image( $page->post_content ); |
| 352 |
if( !empty( $img_scr ) ){ |
| 353 |
$list_pages_html .= '<div class="page-list-ext-image"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'; |
| 354 |
$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 |
| 355 |
$list_pages_html .= '</a></div> '; |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
if( $show_title == 1 ){ |
| 363 |
$list_pages_html .= '<h3 class="page-list-ext-title"><a href="'.$link.'" title="'.esc_attr($page->post_title).'">'.$page->post_title.'</a></h3>'; |
| 364 |
} |
| 365 |
if( $show_content == 1 ){ |
| 366 |
//$content = apply_filters('the_content', $page->post_content); |
| 367 |
//$content = str_replace(']]>', ']]>', $content); // both used in default the_content() function |
| 368 |
|
| 369 |
if( !empty( $page->post_excerpt ) ){ |
| 370 |
$text_content = $page->post_excerpt; |
| 371 |
}else{ |
| 372 |
$text_content = $page->post_content; |
| 373 |
} |
| 374 |
|
| 375 |
if ( post_password_required($page) ) { |
| 376 |
$content = '<!-- password protected -->'; |
| 377 |
}else{ |
| 378 |
$content = pagelist_unqprfx_parse_content( $text_content, $limit_content, $strip_tags, $strip_shortcodes, $more_tag ); |
| 379 |
$content = do_shortcode( $content ); |
| 380 |
|
| 381 |
if( $show_title == 0 ){ // make content as a link if there is no title |
| 382 |
$content = '<a href="'.$link.'">'.$content.'</a>'; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
$list_pages_html .= '<div class="page-list-ext-item-content">'.$content.'</div>'; |
| 387 |
|
| 388 |
} |
| 389 |
if( $show_child_count == 1 ){ |
| 390 |
$count_subpages = count(get_pages("child_of=".$page->ID)); |
| 391 |
if( $count_subpages > 0 ){ // hide empty |
| 392 |
$child_count_pos = strpos($child_count_template, '%child_count%'); // check if we have %child_count% marker in template |
| 393 |
if($child_count_pos === false) { // %child_count% not found in template |
| 394 |
$child_count_template_html = $child_count_template.' '.$count_subpages; |
| 395 |
$list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>'; |
| 396 |
} else { // %child_count% found in template |
| 397 |
$child_count_template_html = str_replace('%child_count%', $count_subpages, $child_count_template); |
| 398 |
$list_pages_html .= '<div class="page-list-ext-child-count">'.$child_count_template_html.'</div>'; |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
if( $show_meta_key != '' ){ |
| 403 |
$post_meta = get_post_meta($page->ID, $show_meta_key, true); |
| 404 |
if( !empty($post_meta) ){ // hide empty |
| 405 |
$meta_pos = strpos($meta_template, '%meta%'); // check if we have %meta% marker in template |
| 406 |
if($meta_pos === false) { // %meta% not found in template |
| 407 |
$meta_template_html = $meta_template.' '.$post_meta; |
| 408 |
$list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>'; |
| 409 |
} else { // %meta% found in template |
| 410 |
$meta_template_html = str_replace('%meta%', $post_meta, $meta_template); |
| 411 |
$list_pages_html .= '<div class="page-list-ext-meta">'.$meta_template_html.'</div>'; |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
$list_pages_html .= '</div>'."\n"; |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
$return = $pagelist_unqprfx_powered_line; |
| 421 |
if ($list_pages_html) { |
| 422 |
$return .= '<div class="page-list page-list-ext '.$class.'">'."\n".$list_pages_html."\n".'</div>'; |
| 423 |
}else{ |
| 424 |
$return .= '<!-- no pages to show -->'; // this line will not work, because we show all pages if there is no pages to show |
| 425 |
} |
| 426 |
return $return; |
| 427 |
} |
| 428 |
add_shortcode( 'pagelist_ext', 'pagelist_unqprfx_ext_shortcode' ); |
| 429 |
add_shortcode( 'pagelistext', 'pagelist_unqprfx_ext_shortcode' ); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
if ( !function_exists('pagelist_unqprfx_norm_params') ) { |
| 434 |
function pagelist_unqprfx_norm_params( $str ) { |
| 435 |
global $post; |
| 436 |
$new_str = $str; |
| 437 |
$new_str = str_replace('this', $post->ID, $new_str); // exclude this page |
| 438 |
$new_str = str_replace('current', $post->ID, $new_str); // exclude current page |
| 439 |
$new_str = str_replace('curent', $post->ID, $new_str); // exclude curent page with mistake |
| 440 |
$new_str = str_replace('parent', $post->post_parent, $new_str); // exclude parent page |
| 441 |
return $new_str; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
if ( !function_exists('pagelist_unqprfx_parse_content') ) { |
| 447 |
function pagelist_unqprfx_parse_content($content, $limit_content = 250, $strip_tags = 1, $strip_shortcodes = 1, $more_tag = 1) { |
| 448 |
|
| 449 |
$more_tag_found = 0; |
| 450 |
$content_before_more_tag_length = 0; |
| 451 |
|
| 452 |
if( $more_tag ){ // "more_tag" have higher priority than "limit_content" |
| 453 |
if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { |
| 454 |
$more_tag_found = 1; |
| 455 |
$more_tag = $matches[0]; |
| 456 |
$content_temp = explode($matches[0], $content); |
| 457 |
$content_temp = $content_temp[0]; |
| 458 |
$content_before_more_tag_length = strlen($content_temp); |
| 459 |
$content = substr_replace($content, '###more###', $content_before_more_tag_length, 0); |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
// replace php and comments tags so they do not get stripped |
| 464 |
//$content = preg_replace("@<\?@", "#?#", $content); |
| 465 |
//$content = preg_replace("@<!--@", "#!--#", $content); // save html comments |
| 466 |
// strip tags normally |
| 467 |
//$content = strip_tags($content); |
| 468 |
if( $strip_tags ){ |
| 469 |
$content = str_replace('</', ' </', $content); // <p>line1</p><p>line2</p> - adding space between lines |
| 470 |
$content = strip_tags($content); // ,'<p>' |
| 471 |
} |
| 472 |
// return php and comments tags to their origial form |
| 473 |
//$content = preg_replace("@#\?#@", "<?", $content); |
| 474 |
//$content = preg_replace("@#!--#@", "<!--", $content); |
| 475 |
|
| 476 |
if( $strip_shortcodes ){ |
| 477 |
$content = strip_shortcodes( $content ); |
| 478 |
} |
| 479 |
|
| 480 |
if( $more_tag && $more_tag_found ){ // "more_tag" have higher priority than "limit_content" |
| 481 |
$fake_more_pos = mb_strpos($content, '###more###', 0, 'UTF-8'); |
| 482 |
if( $fake_more_pos === false ) { |
| 483 |
// substring not found in string and this is strange :) |
| 484 |
} else { |
| 485 |
$content = mb_substr($content, 0, $fake_more_pos, 'UTF-8'); |
| 486 |
} |
| 487 |
}else{ |
| 488 |
if( strlen($content) > $limit_content ){ // limiting content |
| 489 |
$pos = strpos($content, ' ', $limit_content); // find first space position |
| 490 |
if ($pos !== false) { |
| 491 |
$first_space_pos = $pos; |
| 492 |
}else{ |
| 493 |
$first_space_pos = $limit_content; |
| 494 |
} |
| 495 |
$content = mb_substr($content, 0, $first_space_pos, 'UTF-8') . '...'; |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
$output = force_balance_tags($content); |
| 500 |
return $output; |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
if ( !function_exists('pagelist_unqprfx_get_first_image') ) { |
| 506 |
function pagelist_unqprfx_get_first_image( $content='' ) { |
| 507 |
$first_img = ''; |
| 508 |
//ob_start(); |
| 509 |
//ob_end_clean(); |
| 510 |
$matchCount = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches); |
| 511 |
if ( $matchCount !== 0 ) { // if we found first image |
| 512 |
$first_img = $matches[1][0]; |
| 513 |
} |
| 514 |
return $first_img; |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
if ( ! function_exists('pagelist_unqprfx_plugin_meta') ) { |
| 519 |
function pagelist_unqprfx_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row |
| 520 |
if ( strpos( $file, 'page-list.php' ) !== false ) { |
| 521 |
$links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/page-list/" title="Plugin page">Page-list</a>' ) ); |
| 522 |
$links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">Donate</a>' ) ); |
| 523 |
$links = array_merge( $links, array( '<a href="http://codecanyon.net/popular_item/by_category?category=wordpress&ref=webvitaly">WordPress Pro plugins</a>' ) ); |
| 524 |
} |
| 525 |
return $links; |
| 526 |
} |
| 527 |
add_filter( 'plugin_row_meta', 'pagelist_unqprfx_plugin_meta', 10, 2 ); |
| 528 |
} |