| 1 |
<?php |
| 2 |
/** |
| 3 |
* Posts — the native Posts window, as an OpenStation app. |
| 4 |
* |
| 5 |
* Claims the FROZEN window id `desktop-mode-posts` (see AGENTS.md): |
| 6 |
* the `edit.php` remap in the shell, the OS Settings opt-in and every |
| 7 |
* session that saved the window keep working unchanged. The dock tile |
| 8 |
* is WordPress's own Posts entry (`placement none`); the JS-side |
| 9 |
* remap routes its click here under `nativePostsEnabled`. |
| 10 |
* |
| 11 |
* The body is `posts.os.ts`: the toolbar, the `<os-table>` and the |
| 12 |
* pager as a client view, plus the Categories mind map and the Tags |
| 13 |
* cloud on their tabs. The list itself is the same `/wp/v2/posts` |
| 14 |
* request the legacy bundle fetched, run in-process by `data()` |
| 15 |
* (`parts/query.php`); the taxonomy REST surface is `parts/terms-rest.php`. |
| 16 |
* |
| 17 |
* (Header kept short on purpose: Plugin Check's direct-access scan |
| 18 |
* reads only the first 50 raw lines, and the guard must land inside.) |
| 19 |
* |
| 20 |
* @package OpenStation |
| 21 |
*/ |
| 22 |
|
| 23 |
namespace OpenStation\Apps\Posts; |
| 24 |
|
| 25 |
use OpenStation\App; |
| 26 |
use OpenStation\App\Os; |
| 27 |
use OpenStation\App\State; |
| 28 |
|
| 29 |
// Direct access, unless a standalone host is booting on bare PHP. |
| 30 |
if ( ! defined( 'ABSPATH' ) ) { |
| 31 |
defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 32 |
} |
| 33 |
|
| 34 |
require_once __DIR__ . '/parts/permissions.php'; |
| 35 |
require_once __DIR__ . '/parts/query.php'; |
| 36 |
require_once __DIR__ . '/parts/terms-rest.php'; |
| 37 |
|
| 38 |
return App::define( 'desktop-mode-posts' ) |
| 39 |
->title( __( 'Posts', 'desktop-mode' ) ) |
| 40 |
->icon( 'dashicons-admin-post' ) |
| 41 |
->size( 1100, 720 ) |
| 42 |
->min_size( 720, 480 ) |
| 43 |
// No dock or wallpaper tile from this registration: the Posts dock |
| 44 |
// tile lives in WordPress's `$menu`, and the shell's URL remap |
| 45 |
// routes it here. A separate tile would be a duplicate entry point. |
| 46 |
->placement( 'none' ) |
| 47 |
// Cap-only gate (`edit_posts`, filterable) so flipping the opt-in |
| 48 |
// mid-session never needs an F5 — the toggle is a runtime check on |
| 49 |
// the JS-side remap. |
| 50 |
->can( |
| 51 |
static function () { |
| 52 |
return openstation_posts_window_user_can_register(); |
| 53 |
} |
| 54 |
) |
| 55 |
// A closure: resolved when the manifest is built, for the acting |
| 56 |
// user — not once when this file loads. |
| 57 |
->config( |
| 58 |
static function () { |
| 59 |
return openstation_posts_app_config( 'posts', 'date', 'desc' ); |
| 60 |
} |
| 61 |
) |
| 62 |
->state( openstation_posts_app_state( 'date', 'desc' ) ) |
| 63 |
->action( |
| 64 |
'filter', |
| 65 |
static function ( State $state ) { |
| 66 |
openstation_posts_app_filter( $state ); |
| 67 |
} |
| 68 |
) |
| 69 |
->action( |
| 70 |
'page', |
| 71 |
static function ( State $state, Os $os, array $args ) { |
| 72 |
openstation_posts_app_page( $state, $args ); |
| 73 |
} |
| 74 |
) |
| 75 |
->action( |
| 76 |
'sort', |
| 77 |
static function ( State $state, Os $os, array $args ) { |
| 78 |
openstation_posts_app_sort( $state, $args, 'date', 'desc' ); |
| 79 |
} |
| 80 |
) |
| 81 |
->action( |
| 82 |
'trash', |
| 83 |
static function ( State $state, Os $os, array $args ) { |
| 84 |
openstation_posts_app_trash( $os, $args, 'post' ); |
| 85 |
} |
| 86 |
) |
| 87 |
// A post trashed, restored or edited anywhere on the desktop |
| 88 |
// repaints the list — the legacy bundle's `os.post.changed` |
| 89 |
// subscription. |
| 90 |
->watch( 'post' ) |
| 91 |
->data( |
| 92 |
static function ( State $state ) { |
| 93 |
return openstation_posts_app_data( 'wp/v2/posts', openstation_posts_window_default_query_args(), $state ); |
| 94 |
} |
| 95 |
); |
| 96 |
|