Code Duplication    Length = 60-60 lines in 2 locations

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

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

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

@@ 280-339 (lines=60) @@
277
		return $post;
278
	}
279
280
	function win8_gallery_shortcode( $attr ) {
281
		global $post;
282
283
		static $instance = 0;
284
		$instance++;
285
286
		$output = '';
287
288
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
289
		if ( isset( $attr['orderby'] ) ) {
290
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
291
			if ( !$attr['orderby'] )
292
				unset( $attr['orderby'] );
293
		}
294
295
		extract( shortcode_atts( array(
296
			'order'     => 'ASC',
297
			'orderby'   => 'menu_order ID',
298
			'id'        => $post->ID,
299
			'include'   => '',
300
			'exclude'   => '',
301
			'slideshow' => false
302
		), $attr, 'gallery' ) );
303
304
		// Custom image size and always use it
305
		add_image_size( 'win8app-column', 480 );
306
		$size = 'win8app-column';
307
308
		$id = intval( $id );
309
		if ( 'RAND' === $order )
310
			$orderby = 'none';
311
312
		if ( !empty( $include ) ) {
313
			$include      = preg_replace( '/[^0-9,]+/', '', $include );
314
			$_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
315
			$attachments  = array();
316
			foreach ( $_attachments as $key => $val ) {
317
				$attachments[$val->ID] = $_attachments[$key];
318
			}
319
		} elseif ( !empty( $exclude ) ) {
320
			$exclude     = preg_replace( '/[^0-9,]+/', '', $exclude );
321
			$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
322
		} else {
323
			$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
324
		}
325
326
		if ( ! empty( $attachments ) ) {
327
			foreach ( $attachments as $id => $attachment ) {
328
				$link = isset( $attr['link'] ) && 'file' === $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
329
330
				if ( $captiontag && trim($attachment->post_excerpt) ) {
331
					$output .= "<div class='wp-caption aligncenter'>$link
332
						<p class='wp-caption-text'>" . wptexturize($attachment->post_excerpt) . "</p>
333
						</div>";
334
				} else {
335
					$output .= $link . ' ';
336
				}
337
			}
338
		}
339
	}
340
}
341