PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.4
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.4
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 / render / body-classes.php

body-classes.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.4, at includes/render/body-classes.php

134 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Body class tagging.
4 *
5 * Adds `os-active` / `os-chromeless` to the
6 * admin body class so the shell CSS and the chromeless overrides
7 * stylesheet can key off it, plus `os-admin-bar-<mode>` for
8 * the admin-bar presentation preference. Per-request
9 * `?desktop_mode_classic=1` suppresses them for the detached-tab
10 * workflow.
11 *
12 * Extracted from the 2,525-LOC `render.php` during the
13 * architecture-0.8.1 PHP slicing (phase 6).
14 *
15 * @package OpenStation
16 */
17
18 defined( 'ABSPATH' ) || exit;
19
20 /**
21 * Adds body classes for OpenStation and chromeless iframes.
22 *
23 * The classes anchor all CSS in the shell and chromeless overrides
24 * stylesheets — `.os-active` hides classic chrome and reveals
25 * the shell, `.os-chromeless` reshapes the page inside iframes.
26 *
27 * @param string $classes Space-separated CSS class string.
28 * @return string
29 */
30 function openstation_admin_body_classes( $classes ) {
31 if ( openstation_is_chromeless_request() ) {
32 return ltrim( $classes . ' os-chromeless' );
33 }
34
35 // Per-request classic override: don't tag the body as desktop-active so
36 // the classic chrome isn't hidden by CSS for this one tab.
37 if ( openstation_is_classic_request() ) {
38 return $classes;
39 }
40
41 if ( openstation_is_enabled() ) {
42 $classes = ltrim(
43 $classes . ' os-active os-admin-bar-'
44 . openstation_get_admin_bar_mode()
45 );
46
47 // Solo mode — one window freed onto the real desktop by the
48 // native host. Still `os-active`: the palette, every component
49 // and every registry are scoped to that class, and solo mode
50 // is the same shell with everything but one window hidden.
51 if ( openstation_is_solo_request() ) {
52 $classes .= ' os-solo';
53 }
54
55 return $classes;
56 }
57
58 return $classes;
59 }
60 add_filter( 'admin_body_class', 'openstation_admin_body_classes' );
61
62 /**
63 * Resolves the current user's admin-bar presentation mode.
64 *
65 * Emitted as a `os-admin-bar-<mode>` body class so the very
66 * first paint already has the right chrome — the shell's JS apply pass
67 * re-writes the same class on every settings change, but it runs after
68 * the admin bar has painted, which would flash a bar the user asked to
69 * hide.
70 *
71 * @return string One of `static`, `dynamic`, `hidden`.
72 */
73 function openstation_get_admin_bar_mode() {
74 $settings = openstation_get_os_settings( get_current_user_id() );
75 $mode = isset( $settings['adminBarMode'] ) ? (string) $settings['adminBarMode'] : 'static';
76
77 /**
78 * Filters the admin-bar presentation mode for the current request.
79 *
80 * Lets a plugin pin the mode regardless of the user's own OS
81 * Settings pick — forcing `static` for users who would otherwise
82 * lose their way out of the shell, say, or `hidden` on a kiosk.
83 *
84 * @param string $mode One of `static`, `dynamic`, `hidden`.
85 */
86 $mode = apply_filters( 'openstation_admin_bar_mode', $mode );
87
88 // Fails closed, and deliberately without a `(string)` cast: a
89 // filter returning an array would make that cast emit an
90 // "Array to string conversion" warning on the way to failing
91 // anyway. `static` is the safe landing — it is the only mode
92 // that can't hide the user's way out of the shell.
93 return is_string( $mode ) && in_array( $mode, OPENSTATION_OS_SETTINGS_ADMIN_BAR_MODES, true )
94 ? $mode
95 : 'static';
96 }
97
98 /**
99 * Resolves the current user's behavior for the dock — the single rail
100 * in the Unified layout, the bottom dock in Split. (The Split sidebar
101 * has its own `sideDockBehavior`, but it is synthesised by JS and
102 * needs no first-paint answer from PHP.)
103 *
104 * Emitted as `data-os-dock-behavior` on `#os-dock` by the shell
105 * template so the very first paint already folds (or doesn't) the
106 * rail — the shell's JS apply pass re-writes the same attribute on
107 * every settings change, but it runs after the dock has painted,
108 * which would flash a rail the user asked to keep out of the way.
109 *
110 * @return string One of `static`, `dynamic`.
111 */
112 function openstation_get_dock_behavior() {
113 $settings = openstation_get_os_settings( get_current_user_id() );
114 $behavior = isset( $settings['dockBehavior'] ) ? (string) $settings['dockBehavior'] : 'static';
115
116 /**
117 * Filters the dock behavior for the current request.
118 *
119 * Lets a plugin pin the behavior regardless of the user's own
120 * OpenStation Preferences pick — keeping the rail always on
121 * screen for users who would otherwise not find it, say.
122 *
123 * @param string $behavior One of `static`, `dynamic`.
124 */
125 $behavior = apply_filters( 'openstation_dock_behavior', $behavior );
126
127 // Fails closed, same as the admin-bar mode: `static` is the one
128 // behavior that can't hide the rail from a user who doesn't know
129 // where to point.
130 return is_string( $behavior ) && in_array( $behavior, OPENSTATION_OS_SETTINGS_DOCK_BEHAVIORS, true )
131 ? $behavior
132 : 'static';
133 }
134