PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.5
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.5
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 / includes / content-graph / window.php

window.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 0.9.5, at includes/content-graph/window.php

208 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — Content Graph: window + desktop icon registration.
4 *
5 * Filterable surface (mirrors the my-wordpress module shape):
6 *
7 * - `desktop_mode_content_graph_window_args`
8 * - `desktop_mode_content_graph_icon_args`
9 * - `desktop_mode_content_graph_user_can_use`
10 * - `desktop_mode_content_graph_post_types`
11 * - `desktop_mode_content_graph_template_html`
12 *
13 * @package WPDesktopMode
14 * @since 0.8.2
15 */
16
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Whether the current user should see Content Graph.
21 *
22 * Mirrors the my-wordpress gate, anyone who can edit posts can view
23 * the link map of the content they author and maintain.
24 *
25 * @since 0.8.2
26 *
27 * @return bool
28 */
29 function desktop_mode_content_graph_user_can_use() {
30 $can = current_user_can( 'edit_posts' );
31
32 /**
33 * Filter whether the current user can see the Content Graph
34 * desktop icon and window.
35 *
36 * @since 0.8.2
37 *
38 * @param bool $can Default: edit_posts capability.
39 */
40 return (bool) apply_filters( 'desktop_mode_content_graph_user_can_use', $can );
41 }
42
43 /**
44 * Build the descriptor list of post types eligible for the graph.
45 * Defaults to every public post type (so CPTs participate by
46 * default), matching the user-facing filter bar that ships ON for all
47 * of them.
48 *
49 * @since 0.8.2
50 *
51 * @return array[] Each entry: `array( 'slug', 'label', 'icon' )`.
52 */
53 function desktop_mode_content_graph_post_types() {
54 $types = get_post_types( array( 'public' => true ), 'objects' );
55 $result = array();
56 foreach ( $types as $type ) {
57 // `attachment` is public but participates in the graph as media
58 // (rendered in the side panel) rather than as a node — skip it
59 // on the node-type axis to avoid every image becoming a node.
60 if ( 'attachment' === $type->name ) {
61 continue;
62 }
63 $result[] = array(
64 'slug' => (string) $type->name,
65 'label' => (string) $type->labels->name,
66 'icon' => (string) ( ! empty( $type->menu_icon ) ? $type->menu_icon : 'dashicons-admin-post' ),
67 );
68 }
69
70 /**
71 * Filter the list of post types shown in the Content Graph filter
72 * bar. Each entry must declare `slug`, `label`, and `icon`. Removing
73 * an entry hides it from the filter bar AND excludes it from the
74 * graph entirely.
75 *
76 * @since 0.8.2
77 *
78 * @param array[] $result Default: every public post type except attachment.
79 */
80 $filtered = apply_filters( 'desktop_mode_content_graph_post_types', $result );
81 return is_array( $filtered ) ? array_values( $filtered ) : $result;
82 }
83
84 /**
85 * Render the Content Graph window's static template body. The bundle
86 * mounts its UI into `[data-desktop-mode-content-graph-root]`.
87 *
88 * @since 0.8.2
89 */
90 function desktop_mode_content_graph_render_template() {
91 ob_start();
92 ?>
93 <div class="desktop-mode-content-graph" data-desktop-mode-content-graph-root>
94 <header class="desktop-mode-content-graph__toolbar" data-desktop-mode-content-graph-toolbar></header>
95 <div class="desktop-mode-content-graph__body">
96 <div class="desktop-mode-content-graph__stage" data-desktop-mode-content-graph-stage>
97 <div class="desktop-mode-content-graph__loading" data-desktop-mode-content-graph-loading>
98 <wpd-spinner></wpd-spinner>
99 </div>
100 </div>
101 <aside class="desktop-mode-content-graph__panel" data-desktop-mode-content-graph-panel hidden></aside>
102 </div>
103 </div>
104 <?php
105 $html = (string) ob_get_clean();
106
107 /**
108 * Filter the Content Graph window's template HTML.
109 *
110 * @since 0.8.2
111 *
112 * @param string $html Default template HTML.
113 */
114 $filtered = (string) apply_filters( 'desktop_mode_content_graph_template_html', $html );
115
116 $allowed_html = function_exists( 'desktop_mode_native_window_allowed_html' )
117 ? desktop_mode_native_window_allowed_html()
118 : wp_kses_allowed_html( 'post' );
119
120 echo wp_kses( $filtered, $allowed_html );
121 }
122
123 /**
124 * Register the native window + the desktop icon on `init` priority 20,
125 * matching the my-wordpress + recycle-bin modules.
126 *
127 * @since 0.8.2
128 */
129 function desktop_mode_content_graph_register_window() {
130 if ( ! desktop_mode_content_graph_user_can_use() ) {
131 return;
132 }
133
134 $window_args = array(
135 'title' => __( 'Content Graph', 'desktop-mode' ),
136 'icon' => 'dashicons-networking',
137 'template' => 'desktop_mode_content_graph_render_template',
138 'script' => 'desktop-mode-content-graph',
139 'style' => 'desktop-mode-content-graph',
140 'width' => 1080,
141 'height' => 720,
142 'min_width' => 720,
143 'min_height' => 480,
144 'placement' => 'none',
145 'config' => array(
146 'restRoot' => esc_url_raw( rest_url() ),
147 'restNonce' => wp_create_nonce( 'wp_rest' ),
148 'apiBase' => esc_url_raw( rest_url( 'desktop-mode/v1/content-graph' ) ),
149 'editPostUrl' => esc_url_raw( admin_url( 'post.php' ) ),
150 'editTermUrl' => esc_url_raw( admin_url( 'term.php' ) ),
151 'editUserUrl' => esc_url_raw( admin_url( 'user-edit.php' ) ),
152 'editCommentUrl' => esc_url_raw( admin_url( 'comment.php' ) ),
153 'mediaUrl' => esc_url_raw( admin_url( 'upload.php' ) ),
154 'postTypes' => desktop_mode_content_graph_post_types(),
155 ),
156 );
157
158 /**
159 * Filter the args used to register the Content Graph native window.
160 *
161 * @since 0.8.2
162 *
163 * @param array $window_args Args passed to `desktop_mode_register_window()`.
164 */
165 $window_args = (array) apply_filters( 'desktop_mode_content_graph_window_args', $window_args );
166
167 $registered = desktop_mode_register_window( 'desktop-mode-content-graph', $window_args );
168 if ( is_wp_error( $registered ) ) {
169 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
170 error_log( '[desktop-mode] Content Graph window registration failed: ' . $registered->get_error_message() );
171 return;
172 }
173
174 $icon_args = array(
175 'title' => __( 'Content Graph', 'desktop-mode' ),
176 'icon' => 'dashicons-networking',
177 'window' => 'desktop-mode-content-graph',
178 'pinned' => false,
179 'position' => 20,
180 );
181
182 /**
183 * Filter the args used to register the Content Graph desktop icon.
184 *
185 * @since 0.8.2
186 *
187 * @param array $icon_args Args passed to `desktop_mode_register_icon()`.
188 */
189 $icon_args = (array) apply_filters( 'desktop_mode_content_graph_icon_args', $icon_args );
190
191 desktop_mode_register_icon( 'desktop-mode-content-graph', $icon_args );
192 }
193 add_action( 'init', 'desktop_mode_content_graph_register_window', 20 );
194
195 /**
196 * Enqueue the bundle's CSS in admin context. The script is lazy-
197 * loaded by the native-window sync.
198 *
199 * @since 0.8.2
200 */
201 function desktop_mode_content_graph_enqueue_styles() {
202 if ( ! desktop_mode_content_graph_user_can_use() ) {
203 return;
204 }
205 wp_enqueue_style( 'desktop-mode-content-graph' );
206 }
207 add_action( 'admin_enqueue_scripts', 'desktop_mode_content_graph_enqueue_styles', 30 );
208