Code Duplication    Length = 38-38 lines in 2 locations

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 ) {

class.json-api-endpoints.php 1 location

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