| @@ 517-554 (lines=38) @@ | ||
| 514 | return $suggestions; |
|
| 515 | } |
|
| 516 | ||
| 517 | private function format_taxonomy( $taxonomy, $taxonomy_type, $context ) { |
|
| 518 | // Permissions |
|
| 519 | switch ( $context ) { |
|
| 520 | case 'edit' : |
|
| 521 | $tax = get_taxonomy( $taxonomy_type ); |
|
| 522 | if ( !current_user_can( $tax->cap->edit_terms ) ) |
|
| 523 | return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 ); |
|
| 524 | break; |
|
| 525 | case 'display' : |
|
| 526 | if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) { |
|
| 527 | return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 ); |
|
| 528 | } |
|
| 529 | break; |
|
| 530 | default : |
|
| 531 | return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 ); |
|
| 532 | } |
|
| 533 | ||
| 534 | $response = array(); |
|
| 535 | $response['ID'] = (int) $taxonomy->term_id; |
|
| 536 | $response['name'] = (string) $taxonomy->name; |
|
| 537 | $response['slug'] = (string) $taxonomy->slug; |
|
| 538 | $response['description'] = (string) $taxonomy->description; |
|
| 539 | $response['post_count'] = (int) $taxonomy->count; |
|
| 540 | ||
| 541 | if ( is_taxonomy_hierarchical( $taxonomy_type ) ) { |
|
| 542 | $response['parent'] = (int) $taxonomy->parent; |
|
| 543 | } |
|
| 544 | ||
| 545 | $response['meta'] = (object) array( |
|
| 546 | 'links' => (object) array( |
|
| 547 | 'self' => (string) $this->links->get_taxonomy_link( $this->site->get_id(), $taxonomy->slug, $taxonomy_type ), |
|
| 548 | 'help' => (string) $this->links->get_taxonomy_link( $this->site->get_id(), $taxonomy->slug, $taxonomy_type, 'help' ), |
|
| 549 | 'site' => (string) $this->links->get_site_link( $this->site->get_id() ), |
|
| 550 | ), |
|
| 551 | ); |
|
| 552 | ||
| 553 | return (object) $response; |
|
| 554 | } |
|
| 555 | ||
| 556 | // TODO: factor this out into site |
|
| 557 | private function get_media_item_v1_1( $media_id ) { |
|
| @@ 1298-1335 (lines=38) @@ | ||
| 1295 | return $this->format_taxonomy( $taxonomy, $taxonomy_type, $context ); |
|
| 1296 | } |
|
| 1297 | ||
| 1298 | function format_taxonomy( $taxonomy, $taxonomy_type, $context ) { |
|
| 1299 | // Permissions |
|
| 1300 | switch ( $context ) { |
|
| 1301 | case 'edit' : |
|
| 1302 | $tax = get_taxonomy( $taxonomy_type ); |
|
| 1303 | if ( !current_user_can( $tax->cap->edit_terms ) ) |
|
| 1304 | return new WP_Error( 'unauthorized', 'User cannot edit taxonomy', 403 ); |
|
| 1305 | break; |
|
| 1306 | case 'display' : |
|
| 1307 | if ( -1 == get_option( 'blog_public' ) && ! current_user_can( 'read' ) ) { |
|
| 1308 | return new WP_Error( 'unauthorized', 'User cannot view taxonomy', 403 ); |
|
| 1309 | } |
|
| 1310 | break; |
|
| 1311 | default : |
|
| 1312 | return new WP_Error( 'invalid_context', 'Invalid API CONTEXT', 400 ); |
|
| 1313 | } |
|
| 1314 | ||
| 1315 | $response = array(); |
|
| 1316 | $response['ID'] = (int) $taxonomy->term_id; |
|
| 1317 | $response['name'] = (string) $taxonomy->name; |
|
| 1318 | $response['slug'] = (string) $taxonomy->slug; |
|
| 1319 | $response['description'] = (string) $taxonomy->description; |
|
| 1320 | $response['post_count'] = (int) $taxonomy->count; |
|
| 1321 | ||
| 1322 | if ( is_taxonomy_hierarchical( $taxonomy_type ) ) { |
|
| 1323 | $response['parent'] = (int) $taxonomy->parent; |
|
| 1324 | } |
|
| 1325 | ||
| 1326 | $response['meta'] = (object) array( |
|
| 1327 | 'links' => (object) array( |
|
| 1328 | 'self' => (string) $this->links->get_taxonomy_link( $this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type ), |
|
| 1329 | 'help' => (string) $this->links->get_taxonomy_link( $this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type, 'help' ), |
|
| 1330 | 'site' => (string) $this->links->get_site_link( $this->api->get_blog_id_for_output() ), |
|
| 1331 | ), |
|
| 1332 | ); |
|
| 1333 | ||
| 1334 | return (object) $response; |
|
| 1335 | } |
|
| 1336 | ||
| 1337 | /** |
|
| 1338 | * Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00 |
|