| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Folder sharing visibility logic. | |
| 3 | + * OpenStation — Folder sharing visibility logic. | |
| 4 | 4 | * |
| 5 | 5 | * Computes which folders a viewer can see from each folder's |
| 6 | 6 | * `share_mode` plus the shares / decisions tables: |
| 7 | 7 | * |
| @@ -10,17 +10,16 @@ | ||
| 10 | 10 | * grant in the `_desktop_mode_folder_shares` table (role grants |
| 11 | 11 | * additionally require a per-user accepted row in the decisions |
| 12 | 12 | * table). The folders row's `share_meta` column is |
| 13 | 13 | * diagnostic-only and is never consulted for visibility. |
| 14 | - * - `all` — every desktop-mode user on the site. | |
| 14 | + * - `all` — every openstation user on the site. | |
| 15 | 15 | * |
| 16 | - * Hooked at priority 5 on `desktop_mode_files_visible_folders` | |
| 16 | + * Hooked at priority 5 on `openstation_files_visible_folders` | |
| 17 | 17 | * so plugins layering custom share modes (registered via |
| 18 | - * `desktop_mode_files_share_modes`) can run later in the chain | |
| 18 | + * `openstation_files_share_modes`) can run later in the chain | |
| 19 | 19 | * without competing for the early slot. |
| 20 | 20 | * |
| 21 | - * @package WPDesktopMode | |
| 22 | - * @since 0.9.0 | |
| 21 | + * @package OpenStation | |
| 23 | 22 | */ |
| 24 | 23 | |
| 25 | 24 | defined( 'ABSPATH' ) || exit; |
| 26 | 25 | |
| @@ -27,15 +26,13 @@ | ||
| 27 | 26 | /** |
| 28 | 27 | * Filter callback that augments the owner-only list with folders |
| 29 | 28 | * the viewer can see by virtue of a non-private share mode. |
| 30 | 29 | * |
| 31 | - * @since 0.9.0 | |
| 32 | - * | |
| 33 | 30 | * @param array $owned Owner-only folders (default from the store). |
| 34 | 31 | * @param int $user_id Viewer. |
| 35 | 32 | * @return array |
| 36 | 33 | */ |
| 37 | -function desktop_mode_files_compute_visible_folders( $owned, $user_id ) { | |
| 34 | +function openstation_files_compute_visible_folders( $owned, $user_id ) { | |
| 38 | 35 | global $wpdb; |
| 39 | 36 | $user_id = (int) $user_id; |
| 40 | 37 | if ( $user_id <= 0 ) { |
| 41 | 38 | return is_array( $owned ) ? $owned : array(); |
| @@ -40,9 +37,9 @@ | ||
| 40 | 37 | if ( $user_id <= 0 ) { |
| 41 | 38 | return is_array( $owned ) ? $owned : array(); |
| 42 | 39 | } |
| 43 | 40 | |
| 44 | - $tables = desktop_mode_files_table_names(); | |
| 41 | + $tables = openstation_files_table_names(); | |
| 45 | 42 | $user = get_userdata( $user_id ); |
| 46 | 43 | $roles = $user ? array_values( (array) $user->roles ) : array(); |
| 47 | 44 | |
| 48 | 45 | // Source 1 — `share_mode='all'`. Pull straight from the folders |
| @@ -83,9 +80,9 @@ | ||
| 83 | 80 | // invites (we don't flip a role share to 'accepted' on behalf of |
| 84 | 81 | // every member of the role — that would be a "first to click |
| 85 | 82 | // decides for all" bug). The per-user acceptance lives in the |
| 86 | 83 | // decisions table, mirroring the resolution logic in |
| 87 | - // `desktop_mode_folder_share_user_capability`. | |
| 84 | + // `openstation_folder_share_user_capability`. | |
| 88 | 85 | // |
| 89 | 86 | // Without this join the role recipient could see the folder via |
| 90 | 87 | // REST `list_placements` (which routes through |
| 91 | 88 | // `_user_capability`, which DOES consult decisions) but their |
| @@ -122,33 +119,31 @@ | ||
| 122 | 119 | foreach ( $visible as $row ) { |
| 123 | 120 | $seen_ids[ (int) $row['id'] ] = true; |
| 124 | 121 | } |
| 125 | 122 | foreach ( array_merge( (array) $all_rows, (array) $share_rows ) as $raw ) { |
| 126 | - $row = desktop_mode_files_normalize_folder_row( $raw ); | |
| 123 | + $row = openstation_files_normalize_folder_row( $raw ); | |
| 127 | 124 | $id = (int) $row['id']; |
| 128 | 125 | if ( isset( $seen_ids[ $id ] ) ) { |
| 129 | 126 | continue; |
| 130 | 127 | } |
| 131 | - if ( desktop_mode_files_user_can_see_folder( $row, $user_id, $roles ) ) { | |
| 132 | - $visible[] = $row; | |
| 128 | + if ( openstation_files_user_can_see_folder( $row, $user_id, $roles ) ) { | |
| 129 | + $visible[] = $row; | |
| 133 | 130 | $seen_ids[ $id ] = true; |
| 134 | 131 | } |
| 135 | 132 | } |
| 136 | 133 | return $visible; |
| 137 | 134 | } |
| 138 | -add_filter( 'desktop_mode_files_visible_folders', 'desktop_mode_files_compute_visible_folders', 5, 2 ); | |
| 135 | +add_filter( 'openstation_files_visible_folders', 'openstation_files_compute_visible_folders', 5, 2 ); | |
| 139 | 136 | |
| 140 | 137 | /** |
| 141 | 138 | * Whether the viewer's identity satisfies a folder's share rules. |
| 142 | 139 | * |
| 143 | - * @since 0.9.0 | |
| 144 | - * | |
| 145 | 140 | * @param array $folder Normalized folder row. |
| 146 | 141 | * @param int $user_id Viewer. |
| 147 | 142 | * @param string[] $user_roles Viewer's roles. |
| 148 | 143 | * @return bool |
| 149 | 144 | */ |
| 150 | -function desktop_mode_files_user_can_see_folder( $folder, $user_id, $user_roles ) { | |
| 145 | +function openstation_files_user_can_see_folder( $folder, $user_id, $user_roles ) { | |
| 151 | 146 | $mode = (string) $folder['share_mode']; |
| 152 | 147 | |
| 153 | 148 | // Owner always sees the folder. |
| 154 | 149 | if ( (int) $folder['owner_id'] === (int) $user_id ) { |
| @@ -162,9 +157,9 @@ | ||
| 162 | 157 | // drafts had a fallback that silently re-granted access |
| 163 | 158 | // to revoked recipients; reviewer caught the |
| 164 | 159 | // revocation-bypass and we dropped the fallback before |
| 165 | 160 | // the feature shipped.) |
| 166 | - $cap = desktop_mode_folder_share_user_capability( (int) $folder['id'], (int) $user_id ); | |
| 161 | + $cap = openstation_folder_share_user_capability( (int) $folder['id'], (int) $user_id ); | |
| 167 | 162 | $can = 'none' !== $cap; |
| 168 | 163 | } |
| 169 | 164 | |
| 170 | 165 | /** |
| @@ -171,13 +166,11 @@ | ||
| 171 | 166 | * Filter the per-folder visibility decision. Plugins layering |
| 172 | 167 | * custom share modes (e.g. 'team', 'workspace') can compute |
| 173 | 168 | * `$can` here. |
| 174 | 169 | * |
| 175 | - * @since 0.9.0 | |
| 176 | - * | |
| 177 | 170 | * @param bool $can Default decision. |
| 178 | 171 | * @param array $folder Folder row. |
| 179 | 172 | * @param int $user_id Viewer. |
| 180 | 173 | * @param string[] $roles Viewer's roles. |
| 181 | 174 | */ |
| 182 | - return (bool) apply_filters( 'desktop_mode_files_user_can_see_folder', $can, $folder, $user_id, $user_roles ); | |
| 175 | + return (bool) apply_filters( 'openstation_files_user_can_see_folder', $can, $folder, $user_id, $user_roles ); | |
| 183 | 176 | } |