Code Duplication    Length = 60-60 lines in 2 locations

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

@@ 525-584 (lines=60) @@
522
523
524
525
	function win8_gallery_shortcode( $attr ) {
526
		global $post;
527
528
		static $instance = 0;
529
		$instance++;
530
531
		$output = '';
532
533
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
534
		if ( isset( $attr['orderby'] ) ) {
535
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
536
			if ( !$attr['orderby'] )
537
				unset( $attr['orderby'] );
538
		}
539
540
		extract( shortcode_atts( array(
541
			'order'     => 'ASC',
542
			'orderby'   => 'menu_order ID',
543
			'id'        => $post->ID,
544
			'include'   => '',
545
			'exclude'   => '',
546
			'slideshow' => false
547
		), $attr, 'gallery' ) );
548
549
		// Custom image size and always use it
550
		add_image_size( 'win8app-column', 480 );
551
		$size = 'win8app-column';
552
553
		$id = intval( $id );
554
		if ( 'RAND' === $order )
555
			$orderby = 'none';
556
557
		if ( !empty( $include ) ) {
558
			$include      = preg_replace( '/[^0-9,]+/', '', $include );
559
			$_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
560
			$attachments  = array();
561
			foreach ( $_attachments as $key => $val ) {
562
				$attachments[$val->ID] = $_attachments[$key];
563
			}
564
		} elseif ( !empty( $exclude ) ) {
565
			$exclude     = preg_replace( '/[^0-9,]+/', '', $exclude );
566
			$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
567
		} else {
568
			$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
569
		}
570
571
		if ( ! empty( $attachments ) ) {
572
			foreach ( $attachments as $id => $attachment ) {
573
				$link = isset( $attr['link'] ) && 'file' === $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
574
575
				if ( $captiontag && trim($attachment->post_excerpt) ) {
576
					$output .= "<div class='wp-caption aligncenter'>$link
577
						<p class='wp-caption-text'>" . wptexturize($attachment->post_excerpt) . "</p>
578
						</div>";
579
				} else {
580
					$output .= $link . ' ';
581
				}
582
			}
583
		}
584
	}
585
586
	/**
587
	 * Returns attachment object.

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

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