Code Duplication    Length = 60-60 lines in 2 locations

json-endpoints/class.wpcom-json-api-post-endpoint.php 1 location

@@ 551-610 (lines=60) @@
548
549
550
551
	function win8_gallery_shortcode( $attr ) {
552
		global $post;
553
554
		static $instance = 0;
555
		$instance++;
556
557
		$output = '';
558
559
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
560
		if ( isset( $attr['orderby'] ) ) {
561
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
562
			if ( !$attr['orderby'] )
563
				unset( $attr['orderby'] );
564
		}
565
566
		extract( shortcode_atts( array(
567
			'order'     => 'ASC',
568
			'orderby'   => 'menu_order ID',
569
			'id'        => $post->ID,
570
			'include'   => '',
571
			'exclude'   => '',
572
			'slideshow' => false
573
		), $attr, 'gallery' ) );
574
575
		// Custom image size and always use it
576
		add_image_size( 'win8app-column', 480 );
577
		$size = 'win8app-column';
578
579
		$id = intval( $id );
580
		if ( 'RAND' === $order )
581
			$orderby = 'none';
582
583
		if ( !empty( $include ) ) {
584
			$include      = preg_replace( '/[^0-9,]+/', '', $include );
585
			$_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
586
			$attachments  = array();
587
			foreach ( $_attachments as $key => $val ) {
588
				$attachments[$val->ID] = $_attachments[$key];
589
			}
590
		} elseif ( !empty( $exclude ) ) {
591
			$exclude     = preg_replace( '/[^0-9,]+/', '', $exclude );
592
			$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
593
		} else {
594
			$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
595
		}
596
597
		if ( ! empty( $attachments ) ) {
598
			foreach ( $attachments as $id => $attachment ) {
599
				$link = isset( $attr['link'] ) && 'file' === $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
600
601
				if ( $captiontag && trim($attachment->post_excerpt) ) {
602
					$output .= "<div class='wp-caption aligncenter'>$link
603
						<p class='wp-caption-text'>" . wptexturize($attachment->post_excerpt) . "</p>
604
						</div>";
605
				} else {
606
					$output .= $link . ' ';
607
				}
608
			}
609
		}
610
	}
611
612
	/**
613
	 * Returns attachment object.

json-endpoints/class.wpcom-json-api-post-v1-1-endpoint.php 1 location

@@ 566-625 (lines=60) @@
563
564
565
566
	function win8_gallery_shortcode( $attr ) {
567
		global $post;
568
569
		static $instance = 0;
570
		$instance++;
571
572
		$output = '';
573
574
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
575
		if ( isset( $attr['orderby'] ) ) {
576
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
577
			if ( !$attr['orderby'] )
578
				unset( $attr['orderby'] );
579
		}
580
581
		extract( shortcode_atts( array(
582
			'order'     => 'ASC',
583
			'orderby'   => 'menu_order ID',
584
			'id'        => $post->ID,
585
			'include'   => '',
586
			'exclude'   => '',
587
			'slideshow' => false
588
		), $attr, 'gallery' ) );
589
590
		// Custom image size and always use it
591
		add_image_size( 'win8app-column', 480 );
592
		$size = 'win8app-column';
593
594
		$id = intval( $id );
595
		if ( 'RAND' === $order )
596
			$orderby = 'none';
597
598
		if ( !empty( $include ) ) {
599
			$include      = preg_replace( '/[^0-9,]+/', '', $include );
600
			$_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
601
			$attachments  = array();
602
			foreach ( $_attachments as $key => $val ) {
603
				$attachments[$val->ID] = $_attachments[$key];
604
			}
605
		} elseif ( !empty( $exclude ) ) {
606
			$exclude     = preg_replace( '/[^0-9,]+/', '', $exclude );
607
			$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
608
		} else {
609
			$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
610
		}
611
612
		if ( ! empty( $attachments ) ) {
613
			foreach ( $attachments as $id => $attachment ) {
614
				$link = isset( $attr['link'] ) && 'file' === $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
615
616
				if ( $captiontag && trim($attachment->post_excerpt) ) {
617
					$output .= "<div class='wp-caption aligncenter'>$link
618
						<p class='wp-caption-text'>" . wptexturize($attachment->post_excerpt) . "</p>
619
						</div>";
620
				} else {
621
					$output .= $link . ' ';
622
				}
623
			}
624
		}
625
	}
626
627
	/**
628
	 * Returns attachment object.