PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / apps / my-wordpress / parts / payload.php

payload.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.10, at apps/my-wordpress/parts/payload.php

108 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * My WordPress — the data payload.
4 *
5 * Part of the `my-wordpress` app: required by `my-wordpress.os.php`,
6 * same namespace, plain `.php` on purpose — only `*.os.php` files are
7 * app entries to the framework loader. One function: everything the
8 * client view is a function of, recomputed on every dispatch.
9 *
10 * @package OpenStation
11 */
12
13 namespace OpenStation\Apps\MyWordPress;
14
15 use OpenStation\App\Os;
16 use OpenStation\App\State;
17
18 // Direct access, unless a standalone host is booting on bare PHP.
19 if ( ! defined( 'ABSPATH' ) ) {
20 defined( 'OPENSTATION_STANDALONE' ) || exit;
21 }
22
23 /**
24 * The whole data payload for one render, and the state repairs that
25 * go with it (a vanished section falls back to the root rather than a
26 * dead end).
27 *
28 * @param State $state State.
29 * @param Os $os Host handle.
30 * @return array<string,mixed>
31 */
32 function payload( State $state, Os $os ) {
33 $sections = sections( $os );
34 $section = section_of( $os, (string) $state->get( 'section' ) );
35 if ( ! $section && '' !== (string) $state->get( 'section' ) ) {
36 // A section that vanished (deactivated plugin, lost cap):
37 // fall back to the root rather than a dead end.
38 $state->set( 'section', '' )->set( 'item', 0 );
39 }
40 $group_list = groups( $sections );
41 $group_ids = array_column( $group_list, 'id' );
42 if ( '' !== (string) $state->get( 'group' ) && ! in_array( (string) $state->get( 'group' ), $group_ids, true ) ) {
43 $state->set( 'group', '' );
44 }
45
46 $with_counts = array();
47 foreach ( $sections as $entry ) {
48 $entry['count'] = count_of( $entry );
49 unset( $entry['capability'] );
50 $with_counts[] = $entry;
51 }
52
53 $item = (int) $state->get( 'item' );
54 $into = (int) $state->get( 'into' );
55 // A `flat` section (Woo's Orders) has no detail folder behind its
56 // tiles — its rows are not posts, so the relation queries have
57 // nothing to stand on.
58 if ( $into > 0 && ( ! $section || 'post' !== $section['kind'] || ! empty( $section['flat'] ) ) ) {
59 $state->set( 'into', 0 )->set( 'relation', '' );
60 $into = 0;
61 }
62 $relation = (string) $state->get( 'relation' );
63 $fp = (int) $state->get( 'footprint' );
64 if ( $fp > 0 && false === get_userdata( $fp ) ) {
65 // The person vanished — fall back to the list, not a dead end.
66 $state->set( 'footprint', 0 )->set( 'fpName', '' );
67 $fp = 0;
68 }
69 $is_post = $section && 'post' === $section['kind'] && empty( $section['flat'] );
70 $is_agents = $section && 'agent' === $section['kind'];
71 $choices = $is_post ? edit_choices() : array(
72 'authors' => array(),
73 'categories' => array(),
74 'tags' => array(),
75 );
76 return array(
77 'siteName' => (string) get_bloginfo( 'name' ),
78 // Whether the agents REST routes exist — gates the "Send to"
79 // menu intake's cache warm-up client-side.
80 'agentsEnabled' => function_exists( 'openstation_agents_enabled' ) && openstation_agents_enabled(),
81 'sections' => $with_counts,
82 'groups' => $group_list,
83 'sortOptions' => $section
84 ? array_map(
85 static function ( $row ) {
86 return $row[0];
87 },
88 sort_options( $section )
89 )
90 : (object) array(),
91 'list' => $section && ! $is_agents && 0 === $into && 0 === $fp ? fetch( $os, $section, $state ) : null,
92 'detail' => $section && ! $is_agents && 0 === $into && 0 === $fp && $item > 0 ? detail( $os, $section, $item ) : null,
93 'agents' => $is_agents ? agents_payload( $os, $state ) : null,
94 'folder' => $section && $into > 0 ? folder( $os, $section, $into ) : null,
95 'sub' => $section && $into > 0 && '' !== $relation ? sub( $os, $section, $into, $relation ) : null,
96 'subDetail' => $section && $into > 0 && '' !== $relation && $item > 0
97 ? sub_detail( $os, $section, $into, $relation, $item )
98 : null,
99 'authors' => $choices['authors'],
100 'categories' => $choices['categories'],
101 'tags' => $choices['tags'],
102 'previewActions' => preview_actions( $os ),
103 // The list view's remembered column choices, per section.
104 // An object even when empty — the client indexes it by id.
105 'hiddenColumns' => (object) hidden_columns( $os ),
106 );
107 }
108