PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.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-desktop-mode-folder-file.php

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

83 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — `folder` file type.
4 *
5 * Folders are first-class files. The reference is the folder's
6 * row id in `{$wpdb->prefix}desktop_mode_folders`. When the row
7 * is missing, title() falls back to a generic "Folder" label and
8 * `exists()` returns false.
9 *
10 * @package WPDesktopMode
11 * @since 0.9.0
12 */
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * @since 0.9.0
18 */
19 class Desktop_Mode_Folder_File extends Desktop_Mode_File {
20
21 public static function type(): string {
22 return 'folder';
23 }
24
25 public function exists(): bool {
26 return null !== $this->folder();
27 }
28
29 public function title(): string {
30 $row = $this->folder();
31 if ( ! $row ) {
32 return __( 'Folder', 'desktop-mode' );
33 }
34 return '' !== (string) $row['name'] ? (string) $row['name'] : __( 'Folder', 'desktop-mode' );
35 }
36
37 public function icon(): string {
38 return 'dashicons-portfolio';
39 }
40
41 public function can_read( int $user_id ): bool {
42 $row = $this->folder();
43 if ( ! $row ) {
44 return false;
45 }
46 if ( (int) $row['owner_id'] === (int) $user_id ) {
47 return true;
48 }
49 // Since 0.8.5 the capability resolver is the authority —
50 // it knows about direct shares, role decisions, AND cascade
51 // (a folder nested inside a shared folder is reachable).
52 if ( function_exists( 'desktop_mode_folder_share_user_capability' ) ) {
53 $cap = desktop_mode_folder_share_user_capability( (int) $row['id'], (int) $user_id );
54 if ( 'none' !== $cap ) {
55 return true;
56 }
57 }
58 // Back-compat fallback for legacy `share_meta` rows that
59 // pre-date the shares table.
60 $visible_ids = wp_list_pluck( desktop_mode_files_get_visible_folders( $user_id ), 'id' );
61 return in_array( (int) $row['id'], array_map( 'intval', (array) $visible_ids ), true );
62 }
63
64 public function serialize(): array {
65 $shape = parent::serialize();
66 $row = $this->folder();
67 $shape['ownerId'] = $row ? (int) $row['owner_id'] : 0;
68 $shape['shareMode'] = $row ? (string) $row['share_mode'] : 'private';
69 return $shape;
70 }
71
72 private function folder(): ?array {
73 $id = (int) $this->ref;
74 if ( $id <= 0 ) {
75 return null;
76 }
77 if ( ! function_exists( 'desktop_mode_files_get_folder' ) ) {
78 return null;
79 }
80 return desktop_mode_files_get_folder( $id );
81 }
82 }
83