| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Code-registered desktop themes + payload builder. | |
| 3 | + * OpenStation — Code-registered desktop themes + payload builder. | |
| 4 | 4 | * |
| 5 | 5 | * Two ways a theme reaches the shell: |
| 6 | 6 | * |
| 7 | 7 | * - **Uploaded** — a ZIP installed through the REST route. Assets |
| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | * - **Uploaded** — a ZIP installed through the REST route. Assets |
| 8 | 8 | * live in `uploads/desktop-mode-themes/<slug>/` and the compiled |
| 9 | 9 | * stylesheet is a real file, so the payload ships a `cssUrl`. |
| 10 | 10 | * - **Code-registered** — a plugin calls |
| 11 | - * `desktop_mode_register_desktop_theme()` with asset URLs it | |
| 11 | + * `openstation_register_desktop_theme()` with asset URLs it | |
| 12 | 12 | * already publishes. There is no file to link, so the payload |
| 13 | 13 | * ships the compiled stylesheet as `cssText` and `cssUrl` is |
| 14 | 14 | * empty. PHP prints it via `wp_add_inline_style()` at boot; the |
| 15 | 15 | * shell injects a `<style>` for live switches. |
| @@ -18,9 +18,9 @@ | ||
| 18 | 18 | * code theme is exactly as constrained as an uploaded one — a plugin |
| 19 | 19 | * that wants arbitrary CSS should enqueue a stylesheet, not pretend |
| 20 | 20 | * to be a theme. |
| 21 | 21 | * |
| 22 | - * @package WPDesktopMode | |
| 22 | + * @package OpenStation | |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | defined( 'ABSPATH' ) || exit; |
| 26 | 26 | |
| @@ -35,9 +35,9 @@ | ||
| 35 | 35 | * @param mixed $entry Entry to write, `'__unset__'` to remove, or |
| 36 | 36 | * `null` to read. |
| 37 | 37 | * @return array|null |
| 38 | 38 | */ |
| 39 | -function desktop_mode_desktop_theme_registry( $slug = '', $entry = null ) { | |
| 39 | +function openstation_desktop_theme_registry( $slug = '', $entry = null ) { | |
| 40 | 40 | static $store = array(); |
| 41 | 41 | |
| 42 | 42 | if ( '' === (string) $slug ) { |
| 43 | 43 | return $store; |
| @@ -59,15 +59,15 @@ | ||
| 59 | 59 | * absolute http(s) URL the plugin already serves — there is no ZIP, |
| 60 | 60 | * so there is nothing for us to host. |
| 61 | 61 | * |
| 62 | 62 | * ```php |
| 63 | - * desktop_mode_register_desktop_theme( 'my-plugin/neon', array( | |
| 63 | + * openstation_register_desktop_theme( 'my-plugin/neon', array( | |
| 64 | 64 | * 'name' => __( 'Neon', 'my-plugin' ), |
| 65 | 65 | * 'version' => '1.0.0', |
| 66 | 66 | * 'preview' => plugins_url( 'theme/preview.png', __FILE__ ), |
| 67 | 67 | * 'tokens' => array( |
| 68 | - * '--desktop-mode-window-radius' => '14px', | |
| 69 | - * '--desktop-mode-titlebar-bg' => '#12122a', | |
| 68 | + * '--os-window-radius' => '14px', | |
| 69 | + * '--os-titlebar-bg' => '#12122a', | |
| 70 | 70 | * ), |
| 71 | 71 | * 'icons' => array( |
| 72 | 72 | * 'WINDOW_CONTROL_CLOSE' => array( |
| 73 | 73 | * 'type' => 'image', |
| @@ -98,9 +98,9 @@ | ||
| 98 | 98 | * @type string $version Version string. Optional. |
| 99 | 99 | * @type string $author Author name. Optional. |
| 100 | 100 | * @type string $description Short description. Optional. |
| 101 | 101 | * @type string $preview Absolute URL of a preview image. |
| 102 | - * @type array $tokens Map of `--desktop-mode-*` => value. | |
| 102 | + * @type array $tokens Map of `--os-*` => value. | |
| 103 | 103 | * @type string $iconColor Default tint for every icon that does |
| 104 | 104 | * not set its own `color`. |
| 105 | 105 | * @type array $icons Map of slot => icon descriptor. |
| 106 | 106 | * @type array $textures Map of slot => texture descriptor. |
| @@ -119,9 +119,9 @@ | ||
| 119 | 119 | * activates the theme. |
| 120 | 120 | * } |
| 121 | 121 | * @return true|WP_Error |
| 122 | 122 | */ |
| 123 | -function desktop_mode_register_desktop_theme( $id, $args = array() ) { | |
| 123 | +function openstation_register_desktop_theme( $id, $args = array() ) { | |
| 124 | 124 | $args = wp_parse_args( |
| 125 | 125 | is_array( $args ) ? $args : array(), |
| 126 | 126 | array( |
| 127 | 127 | 'name' => '', |
| @@ -138,9 +138,9 @@ | ||
| 138 | 138 | 'recommendedOsSettings' => array(), |
| 139 | 139 | ) |
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | - $manifest = desktop_mode_sanitize_desktop_theme_manifest( | |
| 142 | + $manifest = openstation_sanitize_desktop_theme_manifest( | |
| 143 | 143 | array( |
| 144 | 144 | // Code registrations declare v2 unconditionally: the array |
| 145 | 145 | // they hand over always HAS the recommendation key, empty |
| 146 | 146 | // or not, so there is nothing for a version to disambiguate. |
| @@ -158,12 +158,12 @@ | ||
| 158 | 158 | 'fonts' => $args['fonts'], |
| 159 | 159 | 'wallpapers' => $args['wallpapers'], |
| 160 | 160 | 'recommendedOsSettings' => $args['recommendedOsSettings'], |
| 161 | 161 | ), |
| 162 | - desktop_mode_desktop_theme_url_asset_resolver() | |
| 162 | + openstation_desktop_theme_url_asset_resolver() | |
| 163 | 163 | ); |
| 164 | 164 | if ( is_wp_error( $manifest ) ) { |
| 165 | - return desktop_mode_registration_error( | |
| 165 | + return openstation_registration_error( | |
| 166 | 166 | $manifest->get_error_code(), |
| 167 | 167 | $manifest->get_error_message(), |
| 168 | 168 | array( 'id' => (string) $id ) |
| 169 | 169 | ); |
| @@ -174,11 +174,11 @@ | ||
| 174 | 174 | 'slug' => $slug, |
| 175 | 175 | 'manifest' => $manifest, |
| 176 | 176 | // Code themes carry absolute asset URLs already, so the |
| 177 | 177 | // compiler needs no base to join against. |
| 178 | - 'cssText' => desktop_mode_desktop_theme_compile_css( $manifest, $slug, '' ), | |
| 178 | + 'cssText' => openstation_desktop_theme_compile_css( $manifest, $slug, '' ), | |
| 179 | 179 | ); |
| 180 | - desktop_mode_desktop_theme_registry( $slug, $entry ); | |
| 180 | + openstation_desktop_theme_registry( $slug, $entry ); | |
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * Fires after a desktop theme is registered from code. |
| 184 | 184 | * |
| @@ -186,9 +186,9 @@ | ||
| 186 | 186 | * |
| 187 | 187 | * @param string $slug Theme slug. |
| 188 | 188 | * @param array $entry Stored registry entry. |
| 189 | 189 | */ |
| 190 | - do_action( 'desktop_mode_desktop_theme_registered', $slug, $entry ); | |
| 190 | + do_action( 'openstation_desktop_theme_registered', $slug, $entry ); | |
| 191 | 191 | |
| 192 | 192 | return true; |
| 193 | 193 | } |
| 194 | 194 | |
| @@ -195,19 +195,19 @@ | ||
| 195 | 195 | /** |
| 196 | 196 | * Remove a code-registered desktop theme. |
| 197 | 197 | * |
| 198 | 198 | * Has no effect on uploaded themes — those are removed with |
| 199 | - * {@see desktop_mode_desktop_theme_delete()}. | |
| 199 | + * {@see openstation_desktop_theme_delete()}. | |
| 200 | 200 | * |
| 201 | 201 | * @param string $id Theme id or slug. |
| 202 | 202 | * @return void |
| 203 | 203 | */ |
| 204 | -function desktop_mode_unregister_desktop_theme( $id ) { | |
| 205 | - $slug = desktop_mode_desktop_theme_slug_from_id( $id ); | |
| 204 | +function openstation_unregister_desktop_theme( $id ) { | |
| 205 | + $slug = openstation_desktop_theme_slug_from_id( $id ); | |
| 206 | 206 | if ( '' === $slug ) { |
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | - desktop_mode_desktop_theme_registry( $slug, '__unset__' ); | |
| 209 | + openstation_desktop_theme_registry( $slug, '__unset__' ); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | 213 | * Shape one stored/registered entry into the payload entry the |
| @@ -218,9 +218,9 @@ | ||
| 218 | 218 | * @param array $entry Stored entry (`slug`, `manifest`, …). |
| 219 | 219 | * @param string $source `'upload'` or `'code'`. |
| 220 | 220 | * @return array|null |
| 221 | 221 | */ |
| 222 | -function desktop_mode_shape_desktop_theme_payload_entry( $entry, $source ) { | |
| 222 | +function openstation_shape_desktop_theme_payload_entry( $entry, $source ) { | |
| 223 | 223 | if ( ! is_array( $entry ) || empty( $entry['manifest'] ) || ! is_array( $entry['manifest'] ) ) { |
| 224 | 224 | return null; |
| 225 | 225 | } |
| 226 | 226 | $manifest = $entry['manifest']; |
| @@ -229,9 +229,9 @@ | ||
| 229 | 229 | return null; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | $is_upload = 'upload' === $source; |
| 233 | - $base_url = $is_upload ? desktop_mode_desktop_themes_url( $slug ) : ''; | |
| 233 | + $base_url = $is_upload ? openstation_desktop_themes_url( $slug ) : ''; | |
| 234 | 234 | $installed_at = isset( $entry['installedAt'] ) ? (int) $entry['installedAt'] : 0; |
| 235 | 235 | // Every generated asset URL carries the install timestamp so a |
| 236 | 236 | // re-upload (which reuses the same paths by design) cannot be |
| 237 | 237 | // served from the browser's cache. Without it an author fixes |
| @@ -243,9 +243,9 @@ | ||
| 243 | 243 | // |
| 244 | 244 | // Tints ride in a PARALLEL map rather than turning `icons` into a |
| 245 | 245 | // map of objects. That keeps `resolveIcon()` returning a paintable |
| 246 | 246 | // string (its documented contract, and what the |
| 247 | - // `desktop-mode.desktop-theme.icon` filter is typed against) and | |
| 247 | + // `os.desktop-theme.icon` filter is typed against) and | |
| 248 | 248 | // keeps the resolver's hot path a single lookup. A slot with no |
| 249 | 249 | // tint is simply absent from `iconColors`, which is also the |
| 250 | 250 | // "paint it the way you always did" signal. |
| 251 | 251 | $icons = array(); |
| @@ -257,9 +257,9 @@ | ||
| 257 | 257 | } |
| 258 | 258 | if ( 'dashicon' === $icon['type'] ) { |
| 259 | 259 | $icons[ $slot ] = (string) $icon['name']; |
| 260 | 260 | } else { |
| 261 | - $url = desktop_mode_desktop_theme_asset_url( $icon['path'], $base_url, $asset_version ); | |
| 261 | + $url = openstation_desktop_theme_asset_url( $icon['path'], $base_url, $asset_version ); | |
| 262 | 262 | if ( '' === $url ) { |
| 263 | 263 | continue; |
| 264 | 264 | } |
| 265 | 265 | $icons[ $slot ] = $url; |
| @@ -286,18 +286,18 @@ | ||
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $preview_url = ''; |
| 289 | 289 | if ( ! empty( $manifest['preview'] ) ) { |
| 290 | - $preview_url = desktop_mode_desktop_theme_asset_url( $manifest['preview'], $base_url, $asset_version ); | |
| 290 | + $preview_url = openstation_desktop_theme_asset_url( $manifest['preview'], $base_url, $asset_version ); | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - $css_url = ''; | |
| 294 | - $css_text = ''; | |
| 293 | + $css_url = ''; | |
| 294 | + $css_text = ''; | |
| 295 | 295 | if ( $is_upload ) { |
| 296 | 296 | $css_url = add_query_arg( |
| 297 | 297 | 'ver', |
| 298 | 298 | (string) $installed_at, |
| 299 | - desktop_mode_desktop_themes_url( $slug ) . '/theme.css' | |
| 299 | + openstation_desktop_themes_url( $slug ) . '/theme.css' | |
| 300 | 300 | ); |
| 301 | 301 | } else { |
| 302 | 302 | $css_text = isset( $entry['cssText'] ) ? (string) $entry['cssText'] : ''; |
| 303 | 303 | } |
| @@ -306,9 +306,9 @@ | ||
| 306 | 306 | // way in. A stored manifest can predate a schema change (an enum |
| 307 | 307 | // value core dropped, a key a plugin stopped offering), and the |
| 308 | 308 | // shell must never be handed a value the current build no longer |
| 309 | 309 | // understands. |
| 310 | - $recommended = desktop_mode_sanitize_desktop_theme_recommended_os_settings( | |
| 310 | + $recommended = openstation_sanitize_desktop_theme_recommended_os_settings( | |
| 311 | 311 | isset( $manifest['recommendedOsSettings'] ) ? $manifest['recommendedOsSettings'] : null |
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | 314 | return array( |
| @@ -345,19 +345,19 @@ | ||
| 345 | 345 | * the same slug from code. |
| 346 | 346 | * |
| 347 | 347 | * @return array[] |
| 348 | 348 | */ |
| 349 | -function desktop_mode_build_desktop_themes_payload() { | |
| 349 | +function openstation_build_desktop_themes_payload() { | |
| 350 | 350 | $entries = array(); |
| 351 | 351 | |
| 352 | - foreach ( desktop_mode_desktop_theme_registry() as $slug => $entry ) { | |
| 353 | - $shaped = desktop_mode_shape_desktop_theme_payload_entry( $entry, 'code' ); | |
| 352 | + foreach ( openstation_desktop_theme_registry() as $slug => $entry ) { | |
| 353 | + $shaped = openstation_shape_desktop_theme_payload_entry( $entry, 'code' ); | |
| 354 | 354 | if ( $shaped ) { |
| 355 | 355 | $entries[ $slug ] = $shaped; |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | - foreach ( desktop_mode_desktop_themes_index() as $slug => $entry ) { | |
| 359 | - $shaped = desktop_mode_shape_desktop_theme_payload_entry( $entry, 'upload' ); | |
| 358 | + foreach ( openstation_desktop_themes_index() as $slug => $entry ) { | |
| 359 | + $shaped = openstation_shape_desktop_theme_payload_entry( $entry, 'upload' ); | |
| 360 | 360 | if ( $shaped ) { |
| 361 | 361 | $entries[ $slug ] = $shaped; |
| 362 | 362 | } |
| 363 | 363 | } |
| @@ -370,9 +370,9 @@ | ||
| 370 | 370 | * picker without touching the stored files. |
| 371 | 371 | * |
| 372 | 372 | * @param array[] $entries Map of slug => payload entry. |
| 373 | 373 | */ |
| 374 | - $entries = apply_filters( 'desktop_mode_desktop_themes', $entries ); | |
| 374 | + $entries = apply_filters( 'openstation_desktop_themes', $entries ); | |
| 375 | 375 | if ( ! is_array( $entries ) ) { |
| 376 | 376 | return array(); |
| 377 | 377 | } |
| 378 | 378 | |
| @@ -384,10 +384,13 @@ | ||
| 384 | 384 | $out[] = $entry; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | // Stable, human-sensible order for the picker grid. |
| 388 | - usort( $out, static function ( $a, $b ) { | |
| 389 | - return strcasecmp( (string) $a['name'], (string) $b['name'] ); | |
| 390 | - } ); | |
| 388 | + usort( | |
| 389 | + $out, | |
| 390 | + static function ( $a, $b ) { | |
| 391 | + return strcasecmp( (string) $a['name'], (string) $b['name'] ); | |
| 392 | + } | |
| 393 | + ); | |
| 391 | 394 | |
| 392 | - return array_slice( $out, 0, desktop_mode_desktop_themes_payload_cap() ); | |
| 395 | + return array_slice( $out, 0, openstation_desktop_themes_payload_cap() ); | |
| 393 | 396 | } |