Code Duplication    Length = 37-38 lines in 2 locations

class.json-api-endpoints.php 1 location

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

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

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