Changeset 2347430
- Timestamp:
- 07/27/2020 08:52:03 PM (6 years ago)
- File:
-
- 1 edited
-
vi-include-post-by/trunk/vi_include_post_by.php (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vi-include-post-by/trunk/vi_include_post_by.php
r2325894 r2347430 4 4 Plugin URI: http://neathawk.com 5 5 Description: Ability to include posts inside other posts/pages, etc, with a shortcode. 6 Version: 0.4.200 6176 Version: 0.4.200706 7 7 Author: Joseph Neathawk 8 8 Author URI: http://Neathawk.com … … 52 52 public static function enqueue_scripts() { 53 53 //style for the plugin 54 wp_enqueue_style( 'vi-include-post-by', plugins_url( '/style.css', __FILE__ ), NULL , NULL , 'all' ); 54 wp_enqueue_style( 'vi-ipb-css', plugins_url( '/style.css', __FILE__ ), NULL , NULL , 'all' ); 55 56 wp_enqueue_script( 'vi-ipb-js', plugins_url( '/common.js', __FILE__ ), array('jquery') , NULL , true ); 55 57 } 56 58 … … 72 74 { 73 75 //return value 74 $the_post_thumbnail_url = '';76 $the_post_thumbnail_url = plugins_url( '/default-image.png', __FILE__ ); 75 77 $image_size = sanitize_text_field($image_size); 76 78 $working_post = $input_post; … … 108 110 { 109 111 //already have a thumbnail? use that one 110 if( get_the_post_thumbnail($input_post->ID) != '' ) 111 { 112 ob_start(); 113 the_post_thumbnail_url($image_size); 114 $the_post_thumbnail_url = ob_get_contents(); 115 ob_end_clean(); 116 } 117 else 112 113 $the_post_thumbnail_url = get_the_post_thumbnail_url($input_post->ID, $image_size); 114 if( $the_post_thumbnail_url == false ) 118 115 { 119 116 //no thumbnail set, then grab the first image … … 124 121 $the_post_thumbnail_url = $matches[1][0]; 125 122 126 //echo('<pre style="display:none">' . site_var_dump_return($input_post) . '</pre>');127 128 123 //set a default image inside the theme folder 129 124 if(empty($the_post_thumbnail_url)) 130 125 { 131 $the_post_thumbnail_url = get_stylesheet_directory_uri() ."/image/default_thumbnail.png";126 $the_post_thumbnail_url = plugins_url( '/default-image.png', __FILE__ ); 132 127 } 133 128 } … … 150 145 { 151 146 //return value 152 $the_post_thumbnail_url = '';147 $the_post_thumbnail_url = plugins_url( '/default-image.png', __FILE__ ); 153 148 $working_post = $input_post; 154 149 … … 185 180 { 186 181 //already have a thumbnail? use that one 187 if( get_the_post_thumbnail ($input_post->ID) != '')182 if( get_the_post_thumbnail_url($input_post->ID) != false ) 188 183 { 189 ob_start(); 190 the_post_thumbnail_url("thumbnail"); 191 $the_post_thumbnail_url .= 'url(' . ob_get_contents(). ') ' . intval( get_option( "thumbnail_size_w" ) ) . 'px, '; 192 ob_end_clean(); 193 194 ob_start(); 195 the_post_thumbnail_url("medium"); 196 $the_post_thumbnail_url .= 'url(' . ob_get_contents(). ') ' . intval( get_option( "medium_size_w" ) ) . 'px, '; 197 ob_end_clean(); 198 199 ob_start(); 200 the_post_thumbnail_url("full"); 201 $the_post_thumbnail_url .= 'url(' . ob_get_contents(). ') ' . intval( get_option( "large_size_w" ) ) . 'px'; 202 ob_end_clean(); 203 184 $the_post_thumbnail_url = 'url(' . get_the_post_thumbnail_url($input_post->ID, 'thumbnail') . ') ' . intval( get_option( "thumbnail_size_w" ) ) . 'px, '; 185 $the_post_thumbnail_url .= 'url(' . get_the_post_thumbnail_url($input_post->ID, 'medium') . ') ' . intval( get_option( "medium_size_w" ) ) . 'px, '; 186 $the_post_thumbnail_url .= 'url(' . get_the_post_thumbnail_url($input_post->ID, 'full') . ') ' . intval( get_option( "large_size_w" ) ) . 'px'; 204 187 205 188 } … … 211 194 $matches = array(); 212 195 $output = preg_match_all('/<img.+?src=[\'"]([^\'"]+)[\'"].*?>/i', $input_post->post_content, $matches); 213 $the_post_thumbnail_url = $matches[1][0]; 214 215 //echo('<pre style="display:none">' . site_var_dump_return($input_post) . '</pre>'); 196 $the_post_thumbnail_url = 'url(' . $matches[1][0] . ') ' . intval( get_option( "medium_size_w" ) ) . 'px, '; 216 197 217 198 //set a default image inside the theme folder 218 199 if(empty($the_post_thumbnail_url)) 219 200 { 220 $the_post_thumbnail_url = get_stylesheet_directory_uri() ."/image/default_thumbnail.png";201 $the_post_thumbnail_url = 'url(' . plugins_url( '/default-image.png', __FILE__ ) . ') ' . intval( get_option( "medium_size_w" ) ) . 'px, '; 221 202 } 222 203 } … … 242 223 * return the full thumbnail content 243 224 * 244 * @version 0.4.200 611225 * @version 0.4.200706 245 226 * @since 0.3.191007 246 227 */ 247 228 private static function get_thumbnail($post = NULL, $link = true, $class = '', $image_size = 'full') 248 229 { 249 if( $link ) 250 { 251 echo( '<div class="post-thumbnail aspect-ratio ' . $class . '">' ); 252 echo( '<div class="dummy"></div>' ); 253 echo( '<a href="' . esc_url( get_permalink() ) . '" >' ); 254 echo( '<div class="element" style="background-image:url(' . vi_include_post_by::get_thumbnail_url($post, $image_size) . '); "></div>' ); 255 echo( '</a>' ); 256 echo( '</div>' ); 257 } 258 else 259 { 260 echo( '<div class="post-thumbnail aspect-ratio ' . $class . '">' ); 261 echo( '<div class="dummy"></div>' ); 262 echo( '<div class="element" style="background-image:url(' . vi_include_post_by::get_thumbnail_url($post, $image_size) . '); "></div>' ); 263 echo( '</div>' ); 264 } 230 if($error_report){echo('<pre>[ipb] thumbnail' . "\n" . var_dump_return( $post ) . '</pre>');} 231 echo( '<div class="post-thumbnail aspect-ratio ' . $class . '">' ); 232 if( $link ){ echo( '<a href="' . esc_url( get_permalink($post) ) . '" >' ); } 233 echo( '<img class="element" src="' . vi_include_post_by::get_thumbnail_url($post, $image_size) . '" alt="thumbnail for ' . $post->post_title . '" />' ); 234 if( $link ){ echo( '</a>' ); } 235 echo( '</div>' ); 265 236 } 266 237 … … 271 242 * @since 0.3.191007 272 243 */ 273 private static function get_title($ link = true)244 private static function get_title($post = NULL, $link = true) 274 245 { 275 246 if( $link ) 276 247 { 277 the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">','</a></h2>' );248 echo( '<h2 class="entry-title"><a href="' . esc_url( get_permalink($post) ) . '" rel="bookmark">' . get_the_title($post) . '</a></h2>' ); 278 249 } 279 250 else 280 251 { 281 the_title( '<h2 class="entry-title">','</h2>' );252 echo( '<h2 class="entry-title">' . get_the_title($post) . '</h2>' ); 282 253 } 283 254 } … … 290 261 * @since 0.1.181213 291 262 */ 292 private static function posted_on( )263 private static function posted_on($post = NULL) 293 264 { 294 265 $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; 295 if ( get_the_time( 'U' ) !== get_the_modified_time( 'U') ) {266 if ( get_the_time( 'U', $post ) !== get_the_modified_time( 'U', $post ) ) { 296 267 $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; 297 268 } 269 $date_format = get_option('date_format', 'c'); 298 270 299 271 $time_string = sprintf( $time_string, 300 esc_attr( get_the_date( 'c' ) ),301 esc_html( get_the_date( ) ),302 esc_attr( get_the_modified_date( 'c' ) ),303 esc_html( get_the_modified_date( ) )272 esc_attr( get_the_date( 'c', $post ) ), 273 esc_html( get_the_date( $date_format, $post ) ), 274 esc_attr( get_the_modified_date( 'c', $post ) ), 275 esc_html( get_the_modified_date( $date_format, $post ) ) 304 276 ); 305 277 … … 307 279 /* translators: %s: post date. */ 308 280 esc_html_x( 'Posted on %s', 'post date', 'vi_include_post_by' ), 309 '<a href="' . esc_url( get_permalink( ) ) . '" rel="bookmark">' . $time_string . '</a>'281 '<a href="' . esc_url( get_permalink($post) ) . '" rel="bookmark">' . $time_string . '</a>' 310 282 ); 311 283 … … 320 292 * @since 0.1.181213 321 293 */ 322 private static function posted_by() 323 { 294 private static function posted_by($post = NULL) 295 { 296 $author_id = $post->post_author; 297 324 298 $byline = sprintf( 325 299 /* translators: %s: post author. */ 326 300 esc_html_x( 'by %s', 'post author', 'vi_include_post_by' ), 327 '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'301 '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( $author_id ) ) . '">' . esc_html( get_the_author_meta('display_name', $author_id) ) . '</a></span>' 328 302 ); 329 303 … … 337 311 * @since 0.3.191007 338 312 */ 339 private static function get_meta( )313 private static function get_meta($post = NULL) 340 314 { 341 315 echo( '<div class="entry-meta">' ); 342 vi_include_post_by::posted_on( );343 vi_include_post_by::posted_by( );316 vi_include_post_by::posted_on($post); 317 vi_include_post_by::posted_by($post); 344 318 echo( '</div>' ); 345 319 } … … 351 325 * @since 0.3.191007 352 326 */ 353 private static function get_content( )327 private static function get_content($post = NULL) 354 328 { 355 329 echo( '<div class="entry-content">' ); 356 the_content();330 echo( do_shortcode( get_the_content('', false, $post) ) ); 357 331 echo( '</div>' ); 358 332 } … … 364 338 * @since 0.3.191007 365 339 */ 366 private static function get_excerpt( )340 private static function get_excerpt($post = NULL) 367 341 { 368 342 echo( '<div class="entry-content">' ); 369 the_excerpt();343 echo( get_the_excerpt($post) ); 370 344 echo( '</div>' ); 371 345 } … … 377 351 * @since 0.3.191007 378 352 */ 379 private static function get_more($ more_text = "Continue Reading")380 { 381 echo( '<a class="read-more" href="' . esc_url( get_permalink( ) ) . '">' . $more_text . '</a>' );353 private static function get_more($post = NULL, $more_text = "Continue Reading") 354 { 355 echo( '<a class="read-more" href="' . esc_url( get_permalink($post) ) . '">' . $more_text . '</a>' ); 382 356 } 383 357 … … 388 362 * @since 0.1.181213 389 363 */ 390 private static function category_list( )391 { 392 if ( 'post' === get_post_type( ) ) {364 private static function category_list($post = NULL) 365 { 366 if ( 'post' === get_post_type($post) ) { 393 367 /* translators: used between list items, there is a space after the comma */ 394 $categories_list = get_the_category_list( esc_html__( ', ', 'vi_include_post_by' ) );368 $categories_list = get_the_category_list( esc_html__( ', ', 'vi_include_post_by' ), '', $post->ID ); 395 369 if ( $categories_list ) { 396 370 /* translators: 1: list of categories. */ … … 406 380 * @since 0.3.191007 407 381 */ 408 private static function get_footer( )382 private static function get_footer($post = NULL) 409 383 { 410 384 echo( '<div class="entry-footer">' ); 411 vi_include_post_by::category_list( );385 vi_include_post_by::category_list($post); 412 386 echo( '</div>' ); 413 387 } … … 431 405 $style .= ' border:1px solid rgba(0,0,0,0); '; 432 406 } 433 return '<a style="' . $style . '" href="' . esc_url(get_permalink( )) . '?pn=' . $number . '" title="Page ' . $number . '">' . $number . '</a>';407 return '<a style="' . $style . '" href="' . esc_url(get_permalink($post)) . '?pn=' . $number . '" title="Page ' . $number . '">' . $number . '</a>'; 434 408 } 435 409 … … 479 453 480 454 if ( $error_report === 'true' ) $error_report = true; 481 if($error_report){$output .= '*** error reporting enabled <br>';} 455 if($error_report){$output .= '*** [ipb-id] error reporting enabled <br>';} 456 457 if($error_report){$output .= '<pre>[ipb-id] ' . "\n" . var_dump_return( $attr ) . '</pre>';} 482 458 483 459 //remove spaces, and build array … … 511 487 if($card) 512 488 { 513 $class .= ' card';489 $class_inner.= ' card'; 514 490 $class_header .= ' card-header'; 515 491 $class_body .= ' card-body'; … … 518 494 519 495 520 if($error_report){$output .= '*** sanitization complete <br>';}496 if($error_report){$output .= '*** [ipb-id] sanitization complete <br>';} 521 497 522 498 … … 543 519 //do each display in the order in which it was given by the user 544 520 //also break apart into -> header, body, footer 545 if($first_item) $class_inner .= ' active'; 546 547 echo( '<div class="include-post-by inner ' . $class_inner . '">' ); 521 522 echo( '<div class="include-post-by inner ' . $class_inner . ($first_item ? ' active' : '') . '">' ); 548 523 549 524 //HEADER 550 525 if(!empty($display_header)) 551 526 { 527 if($error_report){$output .= '<pre>[ipb-id] header' . "\n" . var_dump_return( $the_posts->post->ID ) . '</pre>';} 528 if($error_report){$output .= '<pre>[ipb-id] header' . "\n" . var_dump_return( $display_header_option_input ) . '</pre>';} 552 529 echo( '<div class="header ' . $class_header . '">' ); 553 530 foreach( $display_header_option_input as $key => &$value ) … … 556 533 { 557 534 case 'title': 558 vi_include_post_by::get_title($ link);535 vi_include_post_by::get_title($the_posts->post, $link); 559 536 break; 560 537 case 'meta': 561 vi_include_post_by::get_meta( );538 vi_include_post_by::get_meta($the_posts->post); 562 539 break; 563 540 case 'thumbnail': … … 565 542 break; 566 543 case 'content': 567 vi_include_post_by::get_content( );544 vi_include_post_by::get_content($the_posts->post); 568 545 break; 569 546 case 'excerpt': 570 vi_include_post_by::get_excerpt( );547 vi_include_post_by::get_excerpt($the_posts->post); 571 548 break; 572 549 case 'more': 573 vi_include_post_by::get_more($ more_text);550 vi_include_post_by::get_more($the_posts->post, $more_text); 574 551 break; 575 552 case 'footer': 576 vi_include_post_by::get_footer( );553 vi_include_post_by::get_footer($the_posts->post); 577 554 break; 578 555 case 'all': 579 556 //default ordering 580 vi_include_post_by::get_title($ link);581 vi_include_post_by::get_meta( );557 vi_include_post_by::get_title($the_posts->post, $link); 558 vi_include_post_by::get_meta($the_posts->post); 582 559 vi_include_post_by::get_thumbnail($the_posts->post, $link, $class_thumbnail, $image_size); 583 vi_include_post_by::get_content( );584 vi_include_post_by::get_footer( );560 vi_include_post_by::get_content($the_posts->post); 561 vi_include_post_by::get_footer($the_posts->post); 585 562 break; 586 563 default: 587 564 //any other values are garbage in 588 565 $value = null; 589 unset($display_ option_input[$key]);566 unset($display_header_option_input[$key]); 590 567 } 591 568 } … … 596 573 if(!empty($display_body)) 597 574 { 575 if($error_report){$output .= '<pre>[ipb-id] body' . "\n" . var_dump_return( $the_posts->post->ID ) . '</pre>';} 576 if($error_report){$output .= '<pre>[ipb-id] body' . "\n" . var_dump_return( $display_body_option_input ) . '</pre>';} 598 577 echo( '<div class="body ' . $class_body. '">' ); 599 578 foreach( $display_body_option_input as $key => &$value ) … … 602 581 { 603 582 case 'title': 604 vi_include_post_by::get_title($ link);583 vi_include_post_by::get_title($the_posts->post, $link); 605 584 break; 606 585 case 'meta': 607 vi_include_post_by::get_meta( );586 vi_include_post_by::get_meta($the_posts->post); 608 587 break; 609 588 case 'thumbnail': … … 611 590 break; 612 591 case 'content': 613 vi_include_post_by::get_content( );592 vi_include_post_by::get_content($the_posts->post); 614 593 break; 615 594 case 'excerpt': 616 vi_include_post_by::get_excerpt( );595 vi_include_post_by::get_excerpt($the_posts->post); 617 596 break; 618 597 case 'more': 619 vi_include_post_by::get_more($ more_text);598 vi_include_post_by::get_more($the_posts->post, $more_text); 620 599 break; 621 600 case 'footer': 622 vi_include_post_by::get_footer( );601 vi_include_post_by::get_footer($the_posts->post); 623 602 break; 624 603 case 'all': 625 604 //default ordering 626 vi_include_post_by::get_title($ link);627 vi_include_post_by::get_meta( );605 vi_include_post_by::get_title($the_posts->post, $link); 606 vi_include_post_by::get_meta($the_posts->post); 628 607 vi_include_post_by::get_thumbnail($the_posts->post, $link, $class_thumbnail, $image_size); 629 vi_include_post_by::get_content( );630 vi_include_post_by::get_footer( );608 vi_include_post_by::get_content($the_posts->post); 609 vi_include_post_by::get_footer($the_posts->post); 631 610 break; 632 611 default: 633 612 //any other values are garbage in 634 $value = null;635 unset($display_option_input[$key]);613 //$value = null; 614 //unset($display_body_option_input[$key]); 636 615 } 637 616 } … … 642 621 if(!empty($display_footer)) 643 622 { 623 if($error_report){$output .= '<pre>[ipb-id] footer' . "\n" . var_dump_return( $the_posts->post->ID ) . '</pre>';} 624 if($error_report){$output .= '<pre>[ipb-id] footer' . "\n" . var_dump_return( $display_footer_option_input ) . '</pre>';} 644 625 echo( '<div class="footer ' . $class_footer . '">' ); 645 626 foreach( $display_footer_option_input as $key => &$value ) … … 648 629 { 649 630 case 'title': 650 vi_include_post_by::get_title($ link);631 vi_include_post_by::get_title($the_posts->post, $link); 651 632 break; 652 633 case 'meta': 653 vi_include_post_by::get_meta( );634 vi_include_post_by::get_meta($the_posts->post); 654 635 break; 655 636 case 'thumbnail': … … 657 638 break; 658 639 case 'content': 659 vi_include_post_by::get_content( );640 vi_include_post_by::get_content($the_posts->post); 660 641 break; 661 642 case 'excerpt': 662 vi_include_post_by::get_excerpt( );643 vi_include_post_by::get_excerpt($the_posts->post); 663 644 break; 664 645 case 'more': 665 vi_include_post_by::get_more($ more_text);646 vi_include_post_by::get_more($the_posts->post, $more_text); 666 647 break; 667 648 case 'footer': 668 vi_include_post_by::get_footer( );649 vi_include_post_by::get_footer($the_posts->post); 669 650 break; 670 651 case 'all': 671 652 //default ordering 672 vi_include_post_by::get_title($ link);673 vi_include_post_by::get_meta( );653 vi_include_post_by::get_title($the_posts->post, $link); 654 vi_include_post_by::get_meta($the_posts->post); 674 655 vi_include_post_by::get_thumbnail($the_posts->post, $link, $class_thumbnail, $image_size); 675 vi_include_post_by::get_content( );676 vi_include_post_by::get_footer( );656 vi_include_post_by::get_content($the_posts->post); 657 vi_include_post_by::get_footer($the_posts->post); 677 658 break; 678 659 default: 679 660 //any other values are garbage in 680 661 $value = null; 681 unset($display_ option_input[$key]);662 unset($display_footer_option_input[$key]); 682 663 } 683 664 } … … 685 666 } 686 667 687 688 689 668 echo( '</div>' );//include-post-by 690 691 if($error_report){$output .= '<pre>' . var_dump_return( $display_option_input ) . '</pre>';}692 693 669 694 670 /*********************** … … 700 676 701 677 //obstream to $output 702 $output = ob_get_contents();678 $output .= ob_get_contents(); 703 679 ob_end_clean(); 704 680 } … … 738 714 'offset' => 0, 739 715 'class_container' => '', 740 ' parent_id' => '',716 'id_container' => '', 741 717 'moretext' => 'Continue Reading', 742 718 'error_report' => false … … 747 723 748 724 if ( $error_report === 'true' ) $error_report = true; 749 if($error_report){$output .= '*** error reporting enabled <br>';} 725 if($error_report){$output .= '*** [ipb-cat] error reporting enabled <br>';} 726 727 if($error_report){$output .= '<pre>[ipb-cat] ' . "\n" . var_dump_return( $attr ) . '</pre>';} 750 728 751 729 … … 799 777 800 778 $class_container = sanitize_text_field( $class_container ); 801 $ parent_id = sanitize_text_field( $parent_id);802 803 804 if($error_report){$output .= '*** sanitization complete <br>';}779 $id_container = sanitize_text_field( $id_container ); 780 781 782 if($error_report){$output .= '*** [ipb-cat] sanitization complete <br>';} 805 783 806 784 //get all posts … … 826 804 827 805 828 if($error_report){$output .= '*** content gathered, transient id = ' . $transient_name . '<br>';}806 if($error_report){$output .= '*** [ipb-cat] content gathered, transient id = ' . $transient_name . '<br>';} 829 807 830 808 //display content 831 $output .= '<div id="' . $ parent_id.'" class="include-post-by-container ' . get_category( $cat )->slug . ' ' . $class_container . '">';809 $output .= '<div id="' . $id_container .'" class="include-post-by-container ' . get_category( $cat )->slug . ' ' . $class_container . '">'; 832 810 if(is_array( $post_array ) && count( $post_array ) > 0) 833 811 { … … 847 825 $first_item = false; 848 826 849 if($error_report){$output .= '<pre> '. var_dump_return( $item ) . '</pre>';}827 if($error_report){$output .= '<pre>[ipb-cat] ' . "\n" . var_dump_return( $item ) . '</pre>';} 850 828 851 829 $output .= vi_include_post_by::include_post_by_id( $attr ); … … 853 831 854 832 855 if($error_report){$output .= '*** content complete, begin paginate <br>';}833 if($error_report){$output .= '*** [ipb-cat] content complete, begin paginate <br>';} 856 834 857 835 //pagination … … 933 911 } 934 912 935 936 if($error_report){$output .= '<pre>' . var_dump_return( $post_array ) . '</pre>';}913 // a bit redundanta and lengthy 914 //if($error_report){$output .= '<pre>' . var_dump_return( $post_array ) . '</pre>';} 937 915 938 916 return $output;
Note: See TracChangeset
for help on using the changeset viewer.