| @@ -8,10 +8,12 @@ | ||
| 8 | 8 | * Lists the types eligible for the graph (`slug`, `label`, `icon`, |
| 9 | 9 | * `count`, `taxonomies`). |
| 10 | 10 | * |
| 11 | 11 | * GET /nodes?types=post,page,... |
| 12 | - * Returns the full `{ nodes, edges, stats }` tuple. Cached server- | |
| 13 | - * side, see graph-builder.php. | |
| 12 | + * Returns the full `{ nodes, edges, groups, stats }` tuple. Cached | |
| 13 | + * server-side, see graph-builder.php. `types` omitted means every | |
| 14 | + * registered type; `types=` (present but empty) means none — the | |
| 15 | + * shell sends the latter when every toolbar chip is off. | |
| 14 | 16 | * |
| 15 | 17 | * GET /post/<id> |
| 16 | 18 | * Returns the side-panel detail bundle for one post: |
| 17 | 19 | * { post: {...}, author, contributors, comments, categories, |
| @@ -51,12 +53,17 @@ | ||
| 51 | 53 | 'methods' => WP_REST_Server::READABLE, |
| 52 | 54 | 'callback' => 'openstation_content_graph_rest_nodes', |
| 53 | 55 | 'permission_callback' => 'openstation_content_graph_rest_permission', |
| 54 | 56 | 'args' => array( |
| 57 | + // Deliberately no `default`: the dispatcher copies a | |
| 58 | + // registered default into the request before the | |
| 59 | + // callback runs, and `WP_REST_Request::has_param()` | |
| 60 | + // sees it, so a default here would make an omitted | |
| 61 | + // parameter indistinguishable from an explicitly empty | |
| 62 | + // one — and the callback tells those two apart. | |
| 55 | 63 | 'types' => array( |
| 56 | - 'description' => 'Comma-separated list of post type slugs to include.', | |
| 64 | + 'description' => 'Comma-separated list of post type slugs to include. Omit for every registered type; pass an empty value for none.', | |
| 57 | 65 | 'type' => 'string', |
| 58 | - 'default' => '', | |
| 59 | 66 | ), |
| 60 | 67 | ), |
| 61 | 68 | ) |
| 62 | 69 | ); |
| @@ -113,16 +120,21 @@ | ||
| 113 | 120 | |
| 114 | 121 | /** |
| 115 | 122 | * GET /nodes |
| 116 | 123 | * |
| 124 | + * An omitted `types` parameter selects every registered type; a | |
| 125 | + * present-but-empty one selects none. The route registers no default | |
| 126 | + * for the parameter so the two stay distinguishable through a real | |
| 127 | + * dispatch (see the route registration above). | |
| 128 | + * | |
| 117 | 129 | * @param WP_REST_Request $request |
| 118 | 130 | * @return WP_REST_Response |
| 119 | 131 | */ |
| 120 | 132 | function openstation_content_graph_rest_nodes( WP_REST_Request $request ) { |
| 121 | - $raw = (string) $request->get_param( 'types' ); | |
| 122 | - $types = '' === $raw | |
| 123 | - ? wp_list_pluck( openstation_content_graph_post_types(), 'slug' ) | |
| 124 | - : array_map( 'trim', explode( ',', $raw ) ); | |
| 133 | + $raw = $request->get_param( 'types' ); | |
| 134 | + $types = $request->has_param( 'types' ) | |
| 135 | + ? array_map( 'trim', explode( ',', (string) $raw ) ) | |
| 136 | + : wp_list_pluck( openstation_content_graph_post_types(), 'slug' ); | |
| 125 | 137 | $payload = openstation_content_graph_build( (array) $types ); |
| 126 | 138 | return rest_ensure_response( openstation_content_graph_filter_payload_for_user( $payload ) ); |
| 127 | 139 | } |
| 128 | 140 | |
| @@ -261,9 +273,9 @@ | ||
| 261 | 273 | return null; |
| 262 | 274 | } |
| 263 | 275 | return array( |
| 264 | 276 | 'id' => $user_id, |
| 265 | - 'name' => (string) $user->display_name, | |
| 277 | + 'name' => openstation_plain_text_title( $user->display_name ), | |
| 266 | 278 | 'slug' => (string) $user->user_nicename, |
| 267 | 279 | 'avatar' => (string) get_avatar_url( $user_id, array( 'size' => 64 ) ), |
| 268 | 280 | 'edit_url' => (string) get_edit_user_link( $user_id ), |
| 269 | 281 | ); |
| @@ -341,12 +353,12 @@ | ||
| 341 | 353 | $out = array(); |
| 342 | 354 | foreach ( $comments as $comment ) { |
| 343 | 355 | $out[] = array( |
| 344 | 356 | 'id' => (int) $comment->comment_ID, |
| 345 | - 'author' => (string) $comment->comment_author, | |
| 357 | + 'author' => openstation_plain_text_title( $comment->comment_author ), | |
| 346 | 358 | 'user_id' => (int) $comment->user_id, |
| 347 | 359 | 'date' => mysql2date( 'c', $comment->comment_date_gmt, false ), |
| 348 | - 'excerpt' => wp_html_excerpt( wp_strip_all_tags( (string) $comment->comment_content ), 140, '...' ), | |
| 360 | + 'excerpt' => openstation_plain_text_title( wp_html_excerpt( openstation_strip_all_tags( (string) $comment->comment_content ), 140, '...' ) ), | |
| 349 | 361 | 'edit_url' => (string) admin_url( 'comment.php?action=editcomment&c=' . (int) $comment->comment_ID ), |
| 350 | 362 | ); |
| 351 | 363 | } |
| 352 | 364 | return $out; |
| @@ -372,9 +384,9 @@ | ||
| 372 | 384 | } |
| 373 | 385 | foreach ( $terms as $term ) { |
| 374 | 386 | $out[] = array( |
| 375 | 387 | 'id' => (int) $term->term_id, |
| 376 | - 'name' => (string) $term->name, | |
| 388 | + 'name' => openstation_plain_text_title( $term->name ), | |
| 377 | 389 | 'slug' => (string) $term->slug, |
| 378 | 390 | 'taxonomy' => (string) $term->taxonomy, |
| 379 | 391 | 'tax_label' => (string) $tax->labels->singular_name, |
| 380 | 392 | 'count' => (int) $term->count, |
| @@ -397,9 +409,9 @@ | ||
| 397 | 409 | $out = array(); |
| 398 | 410 | foreach ( $attachments as $att ) { |
| 399 | 411 | $out[] = array( |
| 400 | 412 | 'id' => (int) $att->ID, |
| 401 | - 'title' => (string) get_the_title( $att ), | |
| 413 | + 'title' => openstation_plain_text_title( get_the_title( $att ) ), | |
| 402 | 414 | 'mime' => (string) $att->post_mime_type, |
| 403 | 415 | 'thumb' => (string) wp_get_attachment_image_url( $att->ID, 'thumbnail' ), |
| 404 | 416 | 'edit_url' => (string) get_edit_post_link( $att->ID, 'raw' ), |
| 405 | 417 | ); |