| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode helper functions. | |
| 3 | + * OpenStation helper functions. | |
| 4 | 4 | * |
| 5 | - * @package WPDesktopMode | |
| 5 | + * @package OpenStation | |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | defined( 'ABSPATH' ) || exit; |
| 9 | 9 | |
| @@ -15,17 +15,15 @@ | ||
| 15 | 15 | * per-file ternaries didn't have: release zips ship the minified |
| 16 | 16 | * bundles only (the ~4–5 MB of dev bundles are a source-checkout |
| 17 | 17 | * artifact — see bin/package.sh), so a production site that happens |
| 18 | 18 | * to define SCRIPT_DEBUG would otherwise request dev files that |
| 19 | - * don't exist and 404 every desktop-mode script. Probe one | |
| 19 | + * don't exist and 404 every openstation script. Probe one | |
| 20 | 20 | * canonical dev bundle; if it's absent, this is a minified-only |
| 21 | 21 | * install and `.min` is the only truth available. |
| 22 | 22 | * |
| 23 | - * @since 0.9.7 | |
| 24 | - * | |
| 25 | 23 | * @return string `'.min'` or `''`. |
| 26 | 24 | */ |
| 27 | -function desktop_mode_asset_suffix() { | |
| 25 | +function openstation_asset_suffix() { | |
| 28 | 26 | static $suffix = null; |
| 29 | 27 | if ( null !== $suffix ) { |
| 30 | 28 | return $suffix; |
| 31 | 29 | } |
| @@ -32,20 +30,20 @@ | ||
| 32 | 30 | if ( ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) { |
| 33 | 31 | $suffix = '.min'; |
| 34 | 32 | return $suffix; |
| 35 | 33 | } |
| 36 | - $suffix = file_exists( DESKTOP_MODE_DIR . 'assets/js/desktop.js' ) ? '' : '.min'; | |
| 34 | + $suffix = file_exists( OPENSTATION_DIR . 'assets/js/desktop.js' ) ? '' : '.min'; | |
| 37 | 35 | return $suffix; |
| 38 | 36 | } |
| 39 | 37 | |
| 40 | 38 | /** |
| 41 | - * Checks whether a user has desktop mode enabled. | |
| 39 | + * Checks whether a user has OpenStation enabled. | |
| 42 | 40 | * |
| 43 | 41 | * Two gates, both must pass: |
| 44 | 42 | * |
| 45 | 43 | * 1. The user's `desktop_mode_mode` user-meta is `'1'` (the per-user |
| 46 | 44 | * opt-in toggle the admin-bar button writes via the AJAX endpoint). |
| 47 | - * 2. The `desktop_mode_mode_enabled` filter returns truthy for that user. | |
| 45 | + * 2. The `openstation_mode_enabled` filter returns truthy for that user. | |
| 48 | 46 | * |
| 49 | 47 | * Centralising the filter check here means render-time gates (chromeless |
| 50 | 48 | * detection, payload generation, REST permission callbacks) can rely on |
| 51 | 49 | * a single helper instead of every call site re-running the filter. |
| @@ -52,15 +50,13 @@ | ||
| 52 | 50 | * A user whose meta is `'1'` but whose filter denies them is treated as |
| 53 | 51 | * not-enabled everywhere, which is the documented contract of the |
| 54 | 52 | * filter — see docs/examples/gate-by-role.md. |
| 55 | 53 | * |
| 56 | - * @since 0.1.0 | |
| 57 | - * | |
| 58 | 54 | * @param int $user_id Optional. User ID to check. Defaults to the |
| 59 | 55 | * current user. |
| 60 | - * @return bool True if the user has desktop mode active. | |
| 56 | + * @return bool True if the user has OpenStation active. | |
| 61 | 57 | */ |
| 62 | -function desktop_mode_is_enabled( $user_id = 0 ) { | |
| 58 | +function openstation_is_enabled( $user_id = 0 ) { | |
| 63 | 59 | $user_id = (int) $user_id; |
| 64 | 60 | if ( $user_id <= 0 ) { |
| 65 | 61 | if ( ! is_user_logged_in() ) { |
| 66 | 62 | return false; |
| @@ -72,49 +68,45 @@ | ||
| 72 | 68 | return false; |
| 73 | 69 | } |
| 74 | 70 | |
| 75 | 71 | /** |
| 76 | - * Filters whether desktop mode is available for this user. | |
| 72 | + * Filters whether OpenStation is available for this user. | |
| 77 | 73 | * |
| 78 | - * See `docs/hooks-reference.md` (`desktop_mode_mode_enabled`) for the | |
| 74 | + * See `docs/hooks-reference.md` (`openstation_mode_enabled`) for the | |
| 79 | 75 | * full contract. Returning `false` here makes the helper return |
| 80 | 76 | * `false` for the user even when their meta is set, which propagates |
| 81 | 77 | * to every render-time gate that consults the helper. |
| 82 | 78 | * |
| 83 | - * @since 0.1.0 | |
| 84 | - * | |
| 85 | - * @param bool $enabled Whether desktop mode is enabled. Default true. | |
| 79 | + * @param bool $enabled Whether OpenStation is enabled. Default true. | |
| 86 | 80 | * @param int $user_id The user ID being checked. |
| 87 | 81 | */ |
| 88 | - return (bool) apply_filters( 'desktop_mode_mode_enabled', true, $user_id ); | |
| 82 | + return (bool) apply_filters( 'openstation_mode_enabled', true, $user_id ); | |
| 89 | 83 | } |
| 90 | 84 | |
| 91 | 85 | /** |
| 92 | - * Shared REST permission gate for Desktop Mode's per-user endpoints. | |
| 86 | + * Shared REST permission gate for OpenStation's per-user endpoints. | |
| 93 | 87 | * |
| 94 | 88 | * Routes that only ever read or write the *current* user's own Desktop |
| 95 | 89 | * Mode state (OS settings, session, default-window, seen-intros, PWA |
| 96 | 90 | * state, presence) must not be reachable by accounts that haven't |
| 97 | - * actually entered Desktop Mode. | |
| 91 | + * actually entered OpenStation. | |
| 98 | 92 | * |
| 99 | 93 | * `current_user_can( 'read' )` alone is too loose: every authenticated |
| 100 | 94 | * role — Subscriber included — carries `read`, so the old gate let any |
| 101 | - * logged-in user touch these routes without ever enabling Desktop Mode. | |
| 102 | - * We gate on {@see desktop_mode_is_enabled()} instead (the same opt-in + | |
| 103 | - * `desktop_mode_mode_enabled` filter the shell itself uses) and return | |
| 95 | + * logged-in user touch these routes without ever enabling OpenStation. | |
| 96 | + * We gate on {@see openstation_is_enabled()} instead (the same opt-in + | |
| 97 | + * `openstation_mode_enabled` filter the shell itself uses) and return | |
| 104 | 98 | * the conventional 401/403 split so REST clients can tell "log in" from |
| 105 | 99 | * "not allowed". |
| 106 | 100 | * |
| 107 | - * This is the canonical gate; `desktop_mode_presence_rest_permission()` | |
| 101 | + * This is the canonical gate; `openstation_presence_rest_permission()` | |
| 108 | 102 | * pioneered the shape and now delegates here. |
| 109 | 103 | * |
| 110 | - * @since 0.8.10 | |
| 111 | - * | |
| 112 | 104 | * @return true|WP_Error True when allowed; a `rest_forbidden` WP_Error |
| 113 | - * (401 when logged out, 403 when desktop mode is | |
| 105 | + * (401 when logged out, 403 when OpenStation is | |
| 114 | 106 | * not enabled for the account) otherwise. |
| 115 | 107 | */ |
| 116 | -function desktop_mode_rest_require_enabled() { | |
| 108 | +function openstation_rest_require_enabled() { | |
| 117 | 109 | if ( ! is_user_logged_in() ) { |
| 118 | 110 | return new WP_Error( |
| 119 | 111 | 'rest_forbidden', |
| 120 | 112 | __( 'Authentication required.', 'desktop-mode' ), |
| @@ -121,12 +113,12 @@ | ||
| 121 | 113 | array( 'status' => 401 ) |
| 122 | 114 | ); |
| 123 | 115 | } |
| 124 | 116 | |
| 125 | - if ( ! desktop_mode_is_enabled() ) { | |
| 117 | + if ( ! openstation_is_enabled() ) { | |
| 126 | 118 | return new WP_Error( |
| 127 | 119 | 'rest_forbidden', |
| 128 | - __( 'Desktop mode is not enabled for your account.', 'desktop-mode' ), | |
| 120 | + __( 'OpenStation is not enabled for your account.', 'desktop-mode' ), | |
| 129 | 121 | array( 'status' => 403 ) |
| 130 | 122 | ); |
| 131 | 123 | } |
| 132 | 124 | |
| @@ -134,18 +126,18 @@ | ||
| 134 | 126 | } |
| 135 | 127 | |
| 136 | 128 | // Chromeless / classic admin-bar suppression and the `wp_redirect` |
| 137 | 129 | // flag-preservation filter pair were moved to |
| 138 | -// `includes/core/routing.php` in 0.8.1. The functions and the | |
| 130 | +// `includes/core/routing.php`. The functions and the | |
| 139 | 131 | // add_filter / add_action hookings live there now; this file |
| 140 | -// remains the home of `desktop_mode_is_enabled()` (called from the | |
| 132 | +// remains the home of `openstation_is_enabled()` (called from the | |
| 141 | 133 | // routing helpers at hook-fire time, after every include has |
| 142 | 134 | // loaded), which is why `desktop-mode.php` can safely require |
| 143 | 135 | // routing.php BEFORE helpers.php. |
| 144 | 136 | |
| 145 | 137 | /** |
| 146 | - * `desktop_mode_is_chromeless_request()` and `desktop_mode_is_classic_request()` | |
| 147 | - * were moved to `includes/core/routing.php` in 0.8.1 — see that | |
| 138 | + * `openstation_is_chromeless_request()` and `openstation_is_classic_request()` | |
| 139 | + * were moved to `includes/core/routing.php` — see that | |
| 148 | 140 | * file for the canonical definitions. The function names didn't |
| 149 | 141 | * change; PHP looks them up by name at call time, so every |
| 150 | 142 | * existing caller (helpers, render, hooks) keeps working. |
| 151 | 143 | */ |
| @@ -158,9 +150,9 @@ | ||
| 158 | 150 | * Exposed as a filter so themes/plugins can set a site-wide default |
| 159 | 151 | * without forking the TS build. |
| 160 | 152 | * |
| 161 | 153 | * ```php |
| 162 | - * add_filter( 'desktop_mode_default_wallpaper', function () { | |
| 154 | + * add_filter( 'openstation_default_wallpaper', function () { | |
| 163 | 155 | * return 'my-plugin/brand'; |
| 164 | 156 | * } ); |
| 165 | 157 | * ``` |
| 166 | 158 | * |
| @@ -165,24 +157,20 @@ | ||
| 165 | 157 | * ``` |
| 166 | 158 | * |
| 167 | 159 | * The returned string is passed through `sanitize_key()` so a filter |
| 168 | 160 | * that returns an invalid slug degrades to the empty string (and the |
| 169 | - * shell falls back to its hard-coded `'dark'` preset). | |
| 161 | + * shell falls back to its hard-coded default preset). | |
| 170 | 162 | * |
| 171 | - * @since 0.5.0 | |
| 172 | - * | |
| 173 | 163 | * @return string Wallpaper id. Empty string if the filter returns |
| 174 | 164 | * an invalid value. |
| 175 | 165 | */ |
| 176 | -function desktop_mode_get_default_wallpaper() { | |
| 166 | +function openstation_get_default_wallpaper() { | |
| 177 | 167 | /** |
| 178 | 168 | * Filters the wallpaper id loaded on first boot / new user. |
| 179 | 169 | * |
| 180 | - * @since 0.5.0 | |
| 181 | - * | |
| 182 | 170 | * @param string $id Default wallpaper slug. |
| 183 | 171 | */ |
| 184 | - $id = apply_filters( 'desktop_mode_default_wallpaper', 'dark' ); | |
| 172 | + $id = apply_filters( 'openstation_default_wallpaper', 'galaxy' ); | |
| 185 | 173 | if ( ! is_string( $id ) ) { |
| 186 | 174 | return ''; |
| 187 | 175 | } |
| 188 | 176 | return sanitize_key( $id ); |
| @@ -188,23 +176,89 @@ | ||
| 188 | 176 | return sanitize_key( $id ); |
| 189 | 177 | } |
| 190 | 178 | |
| 191 | 179 | /** |
| 192 | - * Build a `WP_Error` for a desktop-mode registration failure. | |
| 180 | + * The site's own name, ready to use as a window / icon title. | |
| 193 | 181 | * |
| 182 | + * The desktop shows objects, not the software running it — so the | |
| 183 | + * *root folder* of a site's content is named after the site itself | |
| 184 | + * ("Izzi's Gym"), not after WordPress. That is the breadcrumb root and | |
| 185 | + * the Content Graph's site label; the app that browses it is called WP | |
| 186 | + * Explorer, which is a different string (see | |
| 187 | + * `openstation_my_wordpress_app_title()`). This is the single source | |
| 188 | + * for the site one. | |
| 189 | + * | |
| 190 | + * `get_bloginfo( 'name' )` returns the display-filtered option, which | |
| 191 | + * carries HTML entities (`&`, `'`). Titles land in | |
| 192 | + * `title=` attributes and JS-rendered text nodes, so the entities are | |
| 193 | + * decoded here — leaving them encoded would render a literal | |
| 194 | + * `Ben & Jerry` on the desktop. | |
| 195 | + * | |
| 196 | + * @return string Decoded site title. Falls back to `WordPress` when | |
| 197 | + * the site has no name set. | |
| 198 | + */ | |
| 199 | +function openstation_site_title() { | |
| 200 | + $title = wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ); | |
| 201 | + $title = trim( $title ); | |
| 202 | + | |
| 203 | + if ( '' === $title ) { | |
| 204 | + $title = __( 'WordPress', 'desktop-mode' ); | |
| 205 | + } | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Filters the site title used for openstation window and icon | |
| 209 | + * titles — WP Explorer's breadcrumb root, the Content Graph's site | |
| 210 | + * label, and any "Open in <site>" action. | |
| 211 | + * | |
| 212 | + * Return a different string to label the desktop objects after | |
| 213 | + * something other than `blogname` (a brand, a network name, a | |
| 214 | + * per-user workspace label). | |
| 215 | + * | |
| 216 | + * @param string $title Decoded site title, never empty. | |
| 217 | + */ | |
| 218 | + $filtered = apply_filters( 'openstation_site_title', $title ); | |
| 219 | + | |
| 220 | + return is_string( $filtered ) && '' !== trim( $filtered ) ? $filtered : $title; | |
| 221 | +} | |
| 222 | + | |
| 223 | +/** | |
| 224 | + * Decode a rendered title into the plain text the desktop paints with. | |
| 225 | + * | |
| 226 | + * `wptexturize()` encodes the characters titles are full of — `&` as | |
| 227 | + * `&`, an apostrophe as `’` — and the shell writes titles | |
| 228 | + * into text nodes, where the entity renders as itself. Same reasoning | |
| 229 | + * as {@see openstation_site_title()}, one layer down. | |
| 230 | + * | |
| 231 | + * Decode BEFORE the tag strip, never after: `<script>` decodes | |
| 232 | + * into a real tag, and stripping second is what removes it. | |
| 233 | + * | |
| 234 | + * @param string $rendered A title that has been through a display filter. | |
| 235 | + * @return string Plain text, tag-free. | |
| 236 | + */ | |
| 237 | +function openstation_plain_text_title( $rendered ) { | |
| 238 | + $decoded = html_entity_decode( | |
| 239 | + (string) $rendered, | |
| 240 | + ENT_QUOTES, | |
| 241 | + get_bloginfo( 'charset' ) | |
| 242 | + ); | |
| 243 | + | |
| 244 | + return trim( wp_strip_all_tags( $decoded ) ); | |
| 245 | +} | |
| 246 | + | |
| 247 | +/** | |
| 248 | + * Build a `WP_Error` for a openstation registration failure. | |
| 249 | + * | |
| 194 | 250 | * Centralises the error-code vocabulary used by every |
| 195 | - * `desktop_mode_register_*()` function so plugin authors see a | |
| 251 | + * `openstation_register_*()` function so plugin authors see a | |
| 196 | 252 | * consistent contract. The canonical error-code list lives in |
| 197 | 253 | * `docs/hooks-reference.md`. |
| 198 | 254 | * |
| 199 | - * @since 0.5.0 | |
| 200 | - * | |
| 201 | - * @param string $code Short error slug (e.g. `desktop_mode_missing_title`). | |
| 255 | + * @param string $code Short error slug (e.g. `openstation_missing_title`). | |
| 202 | 256 | * @param string $message Human-readable message. Should be translated. |
| 203 | 257 | * @param array $data Optional extra context attached to the error. |
| 204 | 258 | * @return WP_Error |
| 205 | 259 | */ |
| 206 | -function desktop_mode_registration_error( $code, $message, $data = array() ) { | |
| 260 | +function openstation_registration_error( $code, $message, $data = array() ) { | |
| 207 | 261 | return new WP_Error( |
| 208 | 262 | (string) $code, |
| 209 | 263 | (string) $message, |
| 210 | 264 | is_array( $data ) ? $data : array() |
| @@ -210,12 +264,12 @@ | ||
| 210 | 264 | is_array( $data ) ? $data : array() |
| 211 | 265 | ); |
| 212 | 266 | } |
| 213 | 267 | |
| 214 | -// `desktop_mode_url_is_same_admin()`, | |
| 215 | -// `desktop_mode_resolve_admin_target()` and | |
| 216 | -// `desktop_mode_admin_target_allowlist()` were moved to | |
| 217 | -// `includes/core/routing.php` in 0.8.1 — see that file for the | |
| 268 | +// `openstation_url_is_same_admin()`, | |
| 269 | +// `openstation_resolve_admin_target()` and | |
| 270 | +// `openstation_admin_target_allowlist()` were moved to | |
| 271 | +// `includes/core/routing.php` — see that file for the | |
| 218 | 272 | // canonical definitions. Function names didn't change; PHP's |
| 219 | 273 | // runtime resolution finds them across the module split. |
| 220 | 274 | |
| 221 | 275 | |
| @@ -220,9 +274,9 @@ | ||
| 220 | 274 | |
| 221 | 275 | |
| 222 | 276 | // Dock building, menu / native-windows payload assembly and the |
| 223 | 277 | // script/style handle resolvers were moved to |
| 224 | -// `includes/core/payload.php` in 0.8.1. Function names didn't | |
| 278 | +// `includes/core/payload.php`. Function names didn't | |
| 225 | 279 | // change; existing callers find them via PHP's runtime function |
| 226 | 280 | // resolution. desktop-mode.php loads payload.php right after |
| 227 | -// helpers.php so the foundational helpers (desktop_mode_is_enabled | |
| 281 | +// helpers.php so the foundational helpers (openstation_is_enabled | |
| 228 | 282 | // etc.) are present when payload functions are invoked. |