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