Code Duplication    Length = 38-38 lines in 2 locations

class.json-api-endpoints.php 1 location

@@ 1297-1334 (lines=38) @@
1294
		return $this->format_taxonomy( $taxonomy, $taxonomy_type, $context );
1295
	}
1296
1297
	function format_taxonomy( $taxonomy, $taxonomy_type, $context ) {
1298
		// Permissions
1299
		switch ( $context ) {
1300
		case 'edit' :
1301
			$tax = get_taxonomy( $taxonomy_type );
1302
			if ( !current_user_can( $tax->cap->edit_terms ) )
1303
				return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 );
1304
			break;
1305
		case 'display' :
1306
			if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) {
1307
				return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 );
1308
			}
1309
			break;
1310
		default :
1311
			return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 );
1312
		}
1313
1314
		$response                = array();
1315
		$response['ID']          = (int) $taxonomy->term_id;
1316
		$response['name']        = (string) $taxonomy->name;
1317
		$response['slug']        = (string) $taxonomy->slug;
1318
		$response['description'] = (string) $taxonomy->description;
1319
		$response['post_count']  = (int) $taxonomy->count;
1320
1321
		if ( is_taxonomy_hierarchical( $taxonomy_type ) ) {
1322
			$response['parent'] = (int) $taxonomy->parent;
1323
		}
1324
1325
		$response['meta'] = (object) array(
1326
			'links' => (object) array(
1327
				'self' => (string) $this->links->get_taxonomy_link( $this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type ),
1328
				'help' => (string) $this->links->get_taxonomy_link( $this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type, 'help' ),
1329
				'site' => (string) $this->links->get_site_link( $this->api->get_blog_id_for_output() ),
1330
			),
1331
		);
1332
1333
		return (object) $response;
1334
	}
1335
1336
	/**
1337
	 * Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00

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

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