| 1 |
<?php |
| 2 |
/** |
| 3 |
* Desktop Mode — `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 WPDesktopMode |
| 12 |
*/ |
| 13 |
|
| 14 |
defined( 'ABSPATH' ) || exit; |
| 15 |
|
| 16 |
/** |
| 17 |
* The `bookmark` desktop file type. |
| 18 |
*/ |
| 19 |
class Desktop_Mode_Bookmark_File extends Desktop_Mode_File { |
| 20 |
|
| 21 |
public static function type(): string { |
| 22 |
return 'bookmark'; |
| 23 |
} |
| 24 |
|
| 25 |
public function exists(): bool { |
| 26 |
return '' !== $this->url(); |
| 27 |
} |
| 28 |
|
| 29 |
public function title(): string { |
| 30 |
$url = $this->url(); |
| 31 |
if ( '' === $url ) { |
| 32 |
return __( '(missing bookmark)', 'desktop-mode' ); |
| 33 |
} |
| 34 |
$host = wp_parse_url( $url, PHP_URL_HOST ); |
| 35 |
return is_string( $host ) && '' !== $host ? $host : $url; |
| 36 |
} |
| 37 |
|
| 38 |
public function icon(): string { |
| 39 |
return 'dashicons-admin-links'; |
| 40 |
} |
| 41 |
|
| 42 |
public function serialize(): array { |
| 43 |
$shape = parent::serialize(); |
| 44 |
$shape['url'] = $this->url(); |
| 45 |
return $shape; |
| 46 |
} |
| 47 |
|
| 48 |
private function url(): string { |
| 49 |
$url = esc_url_raw( $this->ref ); |
| 50 |
return is_string( $url ) ? $url : ''; |
| 51 |
} |
| 52 |
} |
| 53 |
|