Code Duplication    Length = 38-38 lines in 2 locations

class.json-api-endpoints.php 1 location

@@ 1421-1458 (lines=38) @@
1418
		return $this->format_taxonomy( $taxonomy, $taxonomy_type, $context );
1419
	}
1420
1421
	function format_taxonomy( $taxonomy, $taxonomy_type, $context ) {
1422
		// Permissions
1423
		switch ( $context ) {
1424
		case 'edit' :
1425
			$tax = get_taxonomy( $taxonomy_type );
1426
			if ( !current_user_can( $tax->cap->edit_terms ) )
1427
				return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 );
1428
			break;
1429
		case 'display' :
1430
			if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) {
1431
				return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 );
1432
			}
1433
			break;
1434
		default :
1435
			return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 );
1436
		}
1437
1438
		$response                = array();
1439
		$response['ID']          = (int) $taxonomy->term_id;
1440
		$response['name']        = (string) $taxonomy->name;
1441
		$response['slug']        = (string) $taxonomy->slug;
1442
		$response['description'] = (string) $taxonomy->description;
1443
		$response['post_count']  = (int) $taxonomy->count;
1444
1445
		if ( is_taxonomy_hierarchical( $taxonomy_type ) ) {
1446
			$response['parent'] = (int) $taxonomy->parent;
1447
		}
1448
1449
		$response['meta'] = (object) array(
1450
			'links' => (object) array(
1451
				'self' => (string) $this->links->get_taxonomy_link( $this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type ),
1452
				'help' => (string) $this->links->get_taxonomy_link( $this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type, 'help' ),
1453
				'site' => (string) $this->links->get_site_link( $this->api->get_blog_id_for_output() ),
1454
			),
1455
		);
1456
1457
		return (object) $response;
1458
	}
1459
1460
	/**
1461
	 * Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00

sal/class.json-api-post-base.php 1 location

@@ 523-560 (lines=38) @@
520
		return $suggestions;
521
	}
522
523
	private function format_taxonomy( $taxonomy, $taxonomy_type, $context ) {
524
		// Permissions
525
		switch ( $context ) {
526
		case 'edit' :
527
			$tax = get_taxonomy( $taxonomy_type );
528
			if ( !current_user_can( $tax->cap->edit_terms ) )
529
				return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 );
530
			break;
531
		case 'display' :
532
			if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) {
533
				return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 );
534
			}
535
			break;
536
		default :
537
			return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 );
538
		}
539
540
		$response                = array();
541
		$response['ID']          = (int) $taxonomy->term_id;
542
		$response['name']        = (string) $taxonomy->name;
543
		$response['slug']        = (string) $taxonomy->slug;
544
		$response['description'] = (string) $taxonomy->description;
545
		$response['post_count']  = (int) $taxonomy->count;
546
547
		if ( is_taxonomy_hierarchical( $taxonomy_type ) ) {
548
			$response['parent'] = (int) $taxonomy->parent;
549
		}
550
551
		$response['meta'] = (object) array(
552
			'links' => (object) array(
553
				'self' => (string) $this->links->get_taxonomy_link( $this->site->get_id(), $taxonomy->slug, $taxonomy_type ),
554
				'help' => (string) $this->links->get_taxonomy_link( $this->site->get_id(), $taxonomy->slug, $taxonomy_type, 'help' ),
555
				'site' => (string) $this->links->get_site_link( $this->site->get_id() ),
556
			),
557
		);
558
559
		return (object) $response;
560
	}
561
562
	// TODO: factor this out into site
563
	private function get_media_item_v1_1( $media_id ) {