PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.7
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-bookmark-file.php

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

83 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — `bookmark` file type.
4 *
5 * Reference is the URL itself (validated against `esc_url_raw`).
6 * Title falls back to the host when the user hasn't set one — the
7 * UI promotes a separate `title` field stored alongside the
8 * placement in the placement row's `meta` column (Phase 2), but
9 * the base shape works without it.
10 *
11 * @package OpenStation
12 */
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * The `bookmark` desktop file type.
18 */
19 class OpenStation_Bookmark_File extends OpenStation_File {
20
21 /**
22 * Get the file type identifier.
23 *
24 * @return string
25 */
26 public static function type(): string {
27 return 'bookmark';
28 }
29
30 /**
31 * Whether the bookmark URL is non-empty.
32 *
33 * @return bool
34 */
35 public function exists(): bool {
36 return '' !== $this->url();
37 }
38
39 /**
40 * Get a label from the bookmark URL's host.
41 *
42 * @return string
43 */
44 public function title(): string {
45 $url = $this->url();
46 if ( '' === $url ) {
47 return __( '(missing bookmark)', 'desktop-mode' );
48 }
49 $host = wp_parse_url( $url, PHP_URL_HOST );
50 return is_string( $host ) && '' !== $host ? $host : $url;
51 }
52
53 /**
54 * Get the Dashicon class for bookmark tiles.
55 *
56 * @return string
57 */
58 public function icon(): string {
59 return 'dashicons-admin-links';
60 }
61
62 /**
63 * Augment the base serialized shape with the bookmark URL.
64 *
65 * @return array
66 */
67 public function serialize(): array {
68 $shape = parent::serialize();
69 $shape['url'] = $this->url();
70 return $shape;
71 }
72
73 /**
74 * Sanitize the stored ref into a valid URL.
75 *
76 * @return string Empty string when the ref is not a valid URL.
77 */
78 private function url(): string {
79 $url = esc_url_raw( $this->ref );
80 return is_string( $url ) ? $url : '';
81 }
82 }
83