| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation — `embed` file type. |
| 4 |
* |
| 5 |
* An "embedded web window" tile — double-click opens the stored URL |
| 6 |
* in an iframe-based desktop window so the page renders inside the |
| 7 |
* shell instead of a new browser tab. The URL is the entity |
| 8 |
* reference; an optional human-friendly name lives on the |
| 9 |
* placement row's `meta.name`. The window's last `{ x, y, width, |
| 10 |
* height }` is persisted on `meta.window` after every drag / |
| 11 |
* resize end so the next open restores that geometry (clamped to |
| 12 |
* the current desktop area on the JS side). |
| 13 |
* |
| 14 |
* @package OpenStation |
| 15 |
*/ |
| 16 |
|
| 17 |
defined( 'ABSPATH' ) || exit; |
| 18 |
|
| 19 |
/** |
| 20 |
* The `embed` desktop file type. |
| 21 |
*/ |
| 22 |
class OpenStation_Embed_File extends OpenStation_File { |
| 23 |
|
| 24 |
/** |
| 25 |
* Get the file type identifier. |
| 26 |
* |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public static function type(): string { |
| 30 |
return 'embed'; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Whether the embed URL is non-empty. |
| 35 |
* |
| 36 |
* @return bool |
| 37 |
*/ |
| 38 |
public function exists(): bool { |
| 39 |
return '' !== $this->url(); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Get a label from the embed URL's host. |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public function title(): string { |
| 48 |
$url = $this->url(); |
| 49 |
if ( '' === $url ) { |
| 50 |
return __( '(missing embed)', 'desktop-mode' ); |
| 51 |
} |
| 52 |
$host = wp_parse_url( $url, PHP_URL_HOST ); |
| 53 |
return is_string( $host ) && '' !== $host ? $host : $url; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get the Dashicon class for embed tiles. |
| 58 |
* |
| 59 |
* @return string |
| 60 |
*/ |
| 61 |
public function icon(): string { |
| 62 |
return 'dashicons-welcome-view-site'; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Augment the base serialized shape with the embed URL. |
| 67 |
* |
| 68 |
* @return array |
| 69 |
*/ |
| 70 |
public function serialize(): array { |
| 71 |
$shape = parent::serialize(); |
| 72 |
$shape['url'] = $this->url(); |
| 73 |
return $shape; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Sanitize the stored ref into a valid URL. |
| 78 |
* |
| 79 |
* @return string Empty string when the ref is not a valid URL. |
| 80 |
*/ |
| 81 |
private function url(): string { |
| 82 |
$url = esc_url_raw( $this->ref ); |
| 83 |
return is_string( $url ) ? $url : ''; |
| 84 |
} |
| 85 |
} |
| 86 |
|