PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.1.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.1.0
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
← All changes | app/Hooks/Handlers/FileHandler.php +32 -23 1.95.22.1.0 View file →
@@ -32,39 +32,48 @@
32 32 );
33 33 }
34 34
35 35 /**
36 - * Summary of deleteFileByUrl
37 - * @param mixed $file_url
36 + * Delete a local attachment only when its stored path belongs to Fluent Boards.
37 + *
38 + * @param mixed $attachment
39 + * @param int|null $boardId
38 40 * @return bool
39 41 */
40 - public function deleteFileByUrl($file_url)
42 + public function deleteAttachmentFile($attachment, $boardId = null)
41 43 {
42 - $exists = Attachment::where('full_url', $file_url)->exists();
43 - if($exists) {
44 - return;
44 + if (
45 + !$attachment ||
46 + $attachment->attachment_type === 'url' ||
47 + (!empty($attachment->driver) && $attachment->driver !== 'local') ||
48 + empty($attachment->file_path)
49 + ) {
50 + return false;
45 51 }
46 - // Convert the URL to the local file path
47 - $upload_dir = wp_upload_dir();
48 - $file_path = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $file_url);
49 52
50 - // Check if the file exists
51 - if (file_exists($file_path)) {
52 - // Delete the file
53 - $deleted = wp_delete_file($file_path);
53 + $storedFilename = rawurldecode((string) $attachment->file_path);
54 + $isBareFilename = $storedFilename !== ''
55 + && strpos($storedFilename, '/') === false
56 + && strpos($storedFilename, '\\') === false;
57 + $filePath = FileSystem::resolveLocalAttachmentPath($attachment->file_path, $boardId);
54 58
55 - // Optionally, you can also remove the file from the media library
56 - // Note: This won't delete the file physically, but it will remove it from the media library
57 - $attachment_id = attachment_url_to_postid($file_url);
58 - if ($attachment_id) {
59 - wp_delete_attachment($attachment_id, true);
59 + if (!$filePath) {
60 + return false;
61 + }
62 +
63 + // Legacy filenames need the board-qualified URL to distinguish same-named files across boards.
64 + if ($isBareFilename) {
65 + if (
66 + empty($attachment->full_url) ||
67 + Attachment::where('full_url', $attachment->full_url)->exists()
68 + ) {
69 + return false;
60 70 }
71 + } elseif (Attachment::where('file_path', $attachment->file_path)->exists()) {
72 + return false;
73 + }
61 74
62 - // Return true if the file was successfully deleted
63 - return $deleted;
64 - }
65 - // Return false if the file does not exist
66 - return false;
75 + return (bool) wp_delete_file($filePath);
67 76 }
68 77
69 78
70 79 /**