| 1 |
<?php |
| 2 |
/** |
| 3 |
* Desktop Mode — `link` file type. |
| 4 |
* |
| 5 |
* A "web link" tile — double-click opens the stored URL in a new |
| 6 |
* browser tab via `window.open( url, '_blank', 'noopener,noreferrer' )`. |
| 7 |
* The URL itself is the entity reference; an optional human-friendly |
| 8 |
* name lives on the placement row's `meta.name` so two tiles |
| 9 |
* pointing at the same URL can carry different labels. |
| 10 |
* |
| 11 |
* @package WPDesktopMode |
| 12 |
* @since 0.8.1 |
| 13 |
*/ |
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* @since 0.8.1 |
| 19 |
*/ |
| 20 |
class Desktop_Mode_Link_File extends Desktop_Mode_File { |
| 21 |
|
| 22 |
public static function type(): string { |
| 23 |
return 'link'; |
| 24 |
} |
| 25 |
|
| 26 |
public function exists(): bool { |
| 27 |
return '' !== $this->url(); |
| 28 |
} |
| 29 |
|
| 30 |
public function title(): string { |
| 31 |
$url = $this->url(); |
| 32 |
if ( '' === $url ) { |
| 33 |
return __( '(missing link)', 'desktop-mode' ); |
| 34 |
} |
| 35 |
$host = wp_parse_url( $url, PHP_URL_HOST ); |
| 36 |
return is_string( $host ) && '' !== $host ? $host : $url; |
| 37 |
} |
| 38 |
|
| 39 |
public function icon(): string { |
| 40 |
return 'dashicons-admin-links'; |
| 41 |
} |
| 42 |
|
| 43 |
public function serialize(): array { |
| 44 |
$shape = parent::serialize(); |
| 45 |
$shape['url'] = $this->url(); |
| 46 |
return $shape; |
| 47 |
} |
| 48 |
|
| 49 |
private function url(): string { |
| 50 |
$url = esc_url_raw( $this->ref ); |
| 51 |
return is_string( $url ) ? $url : ''; |
| 52 |
} |
| 53 |
} |
| 54 |
|