PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.8
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.8
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 / desktop-files / types / class-openstation-embed-file.php

class-openstation-embed-file.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.8, at includes/desktop-files/types/class-openstation-embed-file.php

86 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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