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

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