← All changes
|
json-endpoints/class.wpcom-json-api-post-endpoint.php
+10
-117
12.7.3
→
16.3-a.1
View file →
| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | /** |
| 4 | 8 | * Post Endpoint class. |
| 5 | 9 | */ |
| 6 | 10 | abstract class WPCOM_JSON_API_Post_Endpoint extends WPCOM_JSON_API_Endpoint { |
| @@ -111,13 +115,8 @@ | ||
| 111 | 115 | $GLOBALS['content_width'] = (int) $args['content_width']; |
| 112 | 116 | } |
| 113 | 117 | } |
| 114 | 118 | |
| 115 | - if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ), 'wp-windows8' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- we're not using this value and making changes, just checking if it exists. | |
| 116 | - remove_shortcode( 'gallery', 'gallery_shortcode' ); | |
| 117 | - add_shortcode( 'gallery', array( $this, 'win8_gallery_shortcode' ) ); | |
| 118 | - } | |
| 119 | - | |
| 120 | 119 | switch ( $field ) { |
| 121 | 120 | case 'name': |
| 122 | 121 | $post_id = $this->get_post_id_by_name( $field_value ); |
| 123 | 122 | if ( is_wp_error( $post_id ) ) { |
| @@ -196,9 +195,9 @@ | ||
| 196 | 195 | case 'title': |
| 197 | 196 | if ( 'display' === $context ) { |
| 198 | 197 | $response[ $key ] = (string) get_the_title( $post->ID ); |
| 199 | 198 | } else { |
| 200 | - $response[ $key ] = (string) htmlspecialchars_decode( $post->post_title, ENT_QUOTES ); | |
| 199 | + $response[ $key ] = htmlspecialchars_decode( $post->post_title, ENT_QUOTES ); | |
| 201 | 200 | } |
| 202 | 201 | break; |
| 203 | 202 | case 'URL': |
| 204 | 203 | if ( 'revision' === $post->post_type ) { |
| @@ -244,9 +243,9 @@ | ||
| 244 | 243 | break; |
| 245 | 244 | case 'password': |
| 246 | 245 | $response[ $key ] = (string) $post->post_password; |
| 247 | 246 | if ( 'edit' === $context ) { |
| 248 | - $response[ $key ] = htmlspecialchars_decode( (string) $response[ $key ], ENT_QUOTES ); | |
| 247 | + $response[ $key ] = htmlspecialchars_decode( $response[ $key ], ENT_QUOTES ); | |
| 249 | 248 | } |
| 250 | 249 | break; |
| 251 | 250 | /** (object|false) */ |
| 252 | 251 | case 'parent': |
| @@ -254,9 +253,9 @@ | ||
| 254 | 253 | $parent = get_post( $post->post_parent ); |
| 255 | 254 | if ( 'display' === $context ) { |
| 256 | 255 | $parent_title = (string) get_the_title( $parent->ID ); |
| 257 | 256 | } else { |
| 258 | - $parent_title = (string) htmlspecialchars_decode( $post->post_title, ENT_QUOTES ); | |
| 257 | + $parent_title = htmlspecialchars_decode( $post->post_title, ENT_QUOTES ); | |
| 259 | 258 | } |
| 260 | 259 | $response[ $key ] = (object) array( |
| 261 | 260 | 'ID' => (int) $parent->ID, |
| 262 | 261 | 'type' => (string) $parent->post_type, |
| @@ -280,9 +279,9 @@ | ||
| 280 | 279 | /** This filter is documented in modules/likes.php */ |
| 281 | 280 | $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) ); |
| 282 | 281 | $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true ); |
| 283 | 282 | $post_likes_enabled = $post_likes_switched || ( $sitewide_likes_enabled && $post_likes_switched !== '0' ); |
| 284 | - $response[ $key ] = (bool) $post_likes_enabled; | |
| 283 | + $response[ $key ] = $post_likes_enabled; | |
| 285 | 284 | break; |
| 286 | 285 | case 'sharing_enabled': |
| 287 | 286 | $show = true; |
| 288 | 287 | /** This filter is documented in modules/sharedaddy/sharing-service.php */ |
| @@ -404,9 +403,9 @@ | ||
| 404 | 403 | break; |
| 405 | 404 | } |
| 406 | 405 | } |
| 407 | 406 | } |
| 408 | - $response[ $key ] = (array) $publicize_urls; | |
| 407 | + $response[ $key ] = $publicize_urls; | |
| 409 | 408 | break; |
| 410 | 409 | case 'tags': |
| 411 | 410 | $response[ $key ] = array(); |
| 412 | 411 | $terms = wp_get_post_tags( $post->ID ); |
| @@ -570,117 +569,11 @@ | ||
| 570 | 569 | } |
| 571 | 570 | } |
| 572 | 571 | |
| 573 | 572 | /** |
| 574 | - * Win8 Gallery shortcode. | |
| 575 | - * | |
| 576 | - * @param array $attr - the attribute. | |
| 577 | - */ | |
| 578 | - public function win8_gallery_shortcode( $attr ) { | |
| 579 | - global $post; | |
| 580 | - | |
| 581 | - static $instance = 0; | |
| 582 | - ++$instance; | |
| 583 | - | |
| 584 | - // @todo - find out if this is a bug, intentionally unused, or can be removed. | |
| 585 | - $output = ''; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 586 | - | |
| 587 | - // We're trusting author input, so let's at least make sure it looks like a valid orderby statement | |
| 588 | - if ( isset( $attr['orderby'] ) ) { | |
| 589 | - $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); | |
| 590 | - if ( ! $attr['orderby'] ) { | |
| 591 | - unset( $attr['orderby'] ); | |
| 592 | - } | |
| 593 | - } | |
| 594 | - | |
| 595 | - $atts = shortcode_atts( | |
| 596 | - array( | |
| 597 | - 'order' => 'ASC', | |
| 598 | - 'orderby' => 'menu_order ID', | |
| 599 | - 'id' => $post->ID, | |
| 600 | - 'include' => '', | |
| 601 | - 'exclude' => '', | |
| 602 | - 'slideshow' => false, | |
| 603 | - ), | |
| 604 | - $attr, | |
| 605 | - 'gallery' | |
| 606 | - ); | |
| 607 | - $id = ! empty( $atts['id'] ) ? (int) $atts['id'] : 0; | |
| 608 | - | |
| 609 | - // Custom image size and always use it. | |
| 610 | - add_image_size( 'win8app-column', 480 ); | |
| 611 | - $size = 'win8app-column'; | |
| 612 | - | |
| 613 | - if ( 'RAND' === $atts['order'] ) { | |
| 614 | - $orderby = 'none'; | |
| 615 | - } else { | |
| 616 | - $orderby = $atts['orderby']; | |
| 617 | - } | |
| 618 | - | |
| 619 | - if ( ! empty( $atts['include'] ) ) { | |
| 620 | - $include = preg_replace( '/[^0-9,]+/', '', $atts['include'] ); | |
| 621 | - $_attachments = get_posts( | |
| 622 | - array( | |
| 623 | - 'include' => $include, | |
| 624 | - 'post_status' => 'inherit', | |
| 625 | - 'post_type' => 'attachment', | |
| 626 | - 'post_mime_type' => 'image', | |
| 627 | - 'order' => $atts['order'], | |
| 628 | - 'orderby' => $orderby, | |
| 629 | - ) | |
| 630 | - ); | |
| 631 | - $attachments = array(); | |
| 632 | - foreach ( $_attachments as $key => $val ) { | |
| 633 | - $attachments[ $val->ID ] = $_attachments[ $key ]; | |
| 634 | - } | |
| 635 | - } elseif ( ! empty( $atts['exclude'] ) ) { | |
| 636 | - $exclude = preg_replace( '/[^0-9,]+/', '', $atts['exclude'] ); | |
| 637 | - $attachments = get_children( | |
| 638 | - array( | |
| 639 | - 'post_parent' => $id, | |
| 640 | - 'exclude' => $exclude, | |
| 641 | - 'post_status' => 'inherit', | |
| 642 | - 'post_type' => 'attachment', | |
| 643 | - 'post_mime_type' => 'image', | |
| 644 | - 'order' => $atts['order'], | |
| 645 | - 'orderby' => $orderby, | |
| 646 | - ) | |
| 647 | - ); | |
| 648 | - } else { | |
| 649 | - $attachments = get_children( | |
| 650 | - array( | |
| 651 | - 'post_parent' => $id, | |
| 652 | - 'post_status' => 'inherit', | |
| 653 | - 'post_type' => 'attachment', | |
| 654 | - 'post_mime_type' => 'image', | |
| 655 | - 'order' => $atts['order'], | |
| 656 | - 'orderby' => $orderby, | |
| 657 | - ) | |
| 658 | - ); | |
| 659 | - } | |
| 660 | - | |
| 661 | - if ( ! empty( $attachments ) ) { | |
| 662 | - foreach ( $attachments as $id => $attachment ) { | |
| 663 | - $link = isset( $attr['link'] ) && 'file' === $attr['link'] | |
| 664 | - ? wp_get_attachment_link( $id, $size, false, false ) | |
| 665 | - : wp_get_attachment_link( $id, $size, true, false ); | |
| 666 | - // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 667 | - if ( $captiontag && trim( $attachment->post_excerpt ) ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable | |
| 668 | - $output .= "<div class='wp-caption aligncenter'>$link | |
| 669 | - <p class='wp-caption-text'>" . wptexturize( $attachment->post_excerpt ) . '</p> | |
| 670 | - </div>'; | |
| 671 | - } else { | |
| 672 | - $output .= $link . ' '; | |
| 673 | - } | |
| 674 | - // phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 675 | - } | |
| 676 | - } | |
| 677 | - } | |
| 678 | - | |
| 679 | - /** | |
| 680 | 573 | * Returns attachment object. |
| 681 | 574 | * |
| 682 | - * @param object - $attachment attachment row. | |
| 575 | + * @param object $attachment attachment row. | |
| 683 | 576 | * |
| 684 | 577 | * @return object |
| 685 | 578 | */ |
| 686 | 579 | public function get_attachment( $attachment ) { |