Code Duplication    Length = 60-60 lines in 2 locations

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

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

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

@@ 327-386 (lines=60) @@
324
		return $post;
325
	}
326
327
	function win8_gallery_shortcode( $attr ) {
328
		global $post;
329
330
		static $instance = 0;
331
		$instance++;
332
333
		$output = '';
334
335
		// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
336
		if ( isset( $attr['orderby'] ) ) {
337
			$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
338
			if ( !$attr['orderby'] )
339
				unset( $attr['orderby'] );
340
		}
341
342
		extract( shortcode_atts( array(
343
			'order'     => 'ASC',
344
			'orderby'   => 'menu_order ID',
345
			'id'        => $post->ID,
346
			'include'   => '',
347
			'exclude'   => '',
348
			'slideshow' => false
349
		), $attr, 'gallery' ) );
350
351
		// Custom image size and always use it
352
		add_image_size( 'win8app-column', 480 );
353
		$size = 'win8app-column';
354
355
		$id = (int) $id;
356
		if ( 'RAND' === $order )
357
			$orderby = 'none';
358
359
		if ( !empty( $include ) ) {
360
			$include      = preg_replace( '/[^0-9,]+/', '', $include );
361
			$_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
362
			$attachments  = array();
363
			foreach ( $_attachments as $key => $val ) {
364
				$attachments[$val->ID] = $_attachments[$key];
365
			}
366
		} elseif ( !empty( $exclude ) ) {
367
			$exclude     = preg_replace( '/[^0-9,]+/', '', $exclude );
368
			$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
369
		} else {
370
			$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
371
		}
372
373
		if ( ! empty( $attachments ) ) {
374
			foreach ( $attachments as $id => $attachment ) {
375
				$link = isset( $attr['link'] ) && 'file' === $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
376
377
				if ( $captiontag && trim($attachment->post_excerpt) ) {
378
					$output .= "<div class='wp-caption aligncenter'>$link
379
						<p class='wp-caption-text'>" . wptexturize($attachment->post_excerpt) . "</p>
380
						</div>";
381
				} else {
382
					$output .= $link . ' ';
383
				}
384
			}
385
		}
386
	}
387
}
388