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

225 lines 7.4 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', 'taxonomies' )`.
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 'taxonomies' => array(
68 'category' => is_object_in_taxonomy( $type->name, 'category' ),
69 'post_tag' => is_object_in_taxonomy( $type->name, 'post_tag' ),
70 ),
71 );
72 }
73
74 /**
75 * Filter the list of post types shown in the Content Graph filter
76 * bar. Each entry declares `slug`, `label`, `icon`, and optionally
77 * `taxonomies` (`array( 'category' => bool, 'post_tag' => bool )`);
78 * entries missing `taxonomies` get it derived from
79 * `is_object_in_taxonomy()` after filtering. Removing
80 * an entry hides it from the filter bar AND excludes it from the
81 * graph entirely.
82 *
83 * @since 0.8.2
84 *
85 * @param array[] $result Default: every public post type except attachment.
86 */
87 $filtered = apply_filters( 'desktop_mode_content_graph_post_types', $result );
88 $filtered = is_array( $filtered ) ? array_values( $filtered ) : $result;
89
90 foreach ( $filtered as $i => $entry ) {
91 $slug = isset( $entry['slug'] ) ? (string) $entry['slug'] : '';
92 $filtered[ $i ]['taxonomies'] = array(
93 'category' => isset( $entry['taxonomies'] ) ? ! empty( $entry['taxonomies']['category'] ) : is_object_in_taxonomy( $slug, 'category' ),
94 'post_tag' => isset( $entry['taxonomies'] ) ? ! empty( $entry['taxonomies']['post_tag'] ) : is_object_in_taxonomy( $slug, 'post_tag' ),
95 );
96 }
97
98 return $filtered;
99 }
100
101 /**
102 * Render the Content Graph window's static template body. The bundle
103 * mounts its UI into `[data-desktop-mode-content-graph-root]`.
104 *
105 * @since 0.8.2
106 */
107 function desktop_mode_content_graph_render_template() {
108 ob_start();
109 ?>
110 <div class="desktop-mode-content-graph" data-desktop-mode-content-graph-root>
111 <header class="desktop-mode-content-graph__toolbar" data-desktop-mode-content-graph-toolbar></header>
112 <div class="desktop-mode-content-graph__body">
113 <div class="desktop-mode-content-graph__stage" data-desktop-mode-content-graph-stage>
114 <div class="desktop-mode-content-graph__loading" data-desktop-mode-content-graph-loading>
115 <wpd-spinner></wpd-spinner>
116 </div>
117 </div>
118 <aside class="desktop-mode-content-graph__panel" data-desktop-mode-content-graph-panel hidden></aside>
119 </div>
120 </div>
121 <?php
122 $html = (string) ob_get_clean();
123
124 /**
125 * Filter the Content Graph window's template HTML.
126 *
127 * @since 0.8.2
128 *
129 * @param string $html Default template HTML.
130 */
131 $filtered = (string) apply_filters( 'desktop_mode_content_graph_template_html', $html );
132
133 $allowed_html = function_exists( 'desktop_mode_native_window_allowed_html' )
134 ? desktop_mode_native_window_allowed_html()
135 : wp_kses_allowed_html( 'post' );
136
137 echo wp_kses( $filtered, $allowed_html );
138 }
139
140 /**
141 * Register the native window + the desktop icon on `init` priority 20,
142 * matching the my-wordpress + recycle-bin modules.
143 *
144 * @since 0.8.2
145 */
146 function desktop_mode_content_graph_register_window() {
147 if ( ! desktop_mode_content_graph_user_can_use() ) {
148 return;
149 }
150
151 $window_args = array(
152 'title' => __( 'Content Graph', 'desktop-mode' ),
153 'icon' => 'dashicons-networking',
154 'template' => 'desktop_mode_content_graph_render_template',
155 'script' => 'desktop-mode-content-graph',
156 'style' => 'desktop-mode-content-graph',
157 'width' => 1080,
158 'height' => 720,
159 'min_width' => 720,
160 'min_height' => 480,
161 'placement' => 'none',
162 'config' => array(
163 'restRoot' => esc_url_raw( rest_url() ),
164 'restNonce' => wp_create_nonce( 'wp_rest' ),
165 'apiBase' => esc_url_raw( rest_url( 'desktop-mode/v1/content-graph' ) ),
166 'editPostUrl' => esc_url_raw( admin_url( 'post.php' ) ),
167 'editTermUrl' => esc_url_raw( admin_url( 'term.php' ) ),
168 'editUserUrl' => esc_url_raw( admin_url( 'user-edit.php' ) ),
169 'editCommentUrl' => esc_url_raw( admin_url( 'comment.php' ) ),
170 'mediaUrl' => esc_url_raw( admin_url( 'upload.php' ) ),
171 'postTypes' => desktop_mode_content_graph_post_types(),
172 ),
173 );
174
175 /**
176 * Filter the args used to register the Content Graph native window.
177 *
178 * @since 0.8.2
179 *
180 * @param array $window_args Args passed to `desktop_mode_register_window()`.
181 */
182 $window_args = (array) apply_filters( 'desktop_mode_content_graph_window_args', $window_args );
183
184 $registered = desktop_mode_register_window( 'desktop-mode-content-graph', $window_args );
185 if ( is_wp_error( $registered ) ) {
186 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
187 error_log( '[desktop-mode] Content Graph window registration failed: ' . $registered->get_error_message() );
188 return;
189 }
190
191 $icon_args = array(
192 'title' => __( 'Content Graph', 'desktop-mode' ),
193 'icon' => 'dashicons-networking',
194 'window' => 'desktop-mode-content-graph',
195 'pinned' => false,
196 'position' => 20,
197 );
198
199 /**
200 * Filter the args used to register the Content Graph desktop icon.
201 *
202 * @since 0.8.2
203 *
204 * @param array $icon_args Args passed to `desktop_mode_register_icon()`.
205 */
206 $icon_args = (array) apply_filters( 'desktop_mode_content_graph_icon_args', $icon_args );
207
208 desktop_mode_register_icon( 'desktop-mode-content-graph', $icon_args );
209 }
210 add_action( 'init', 'desktop_mode_content_graph_register_window', 20 );
211
212 /**
213 * Enqueue the bundle's CSS in admin context. The script is lazy-
214 * loaded by the native-window sync.
215 *
216 * @since 0.8.2
217 */
218 function desktop_mode_content_graph_enqueue_styles() {
219 if ( ! desktop_mode_content_graph_user_can_use() ) {
220 return;
221 }
222 wp_enqueue_style( 'desktop-mode-content-graph' );
223 }
224 add_action( 'admin_enqueue_scripts', 'desktop_mode_content_graph_enqueue_styles', 30 );
225