← All changes
|
includes/Core/Integration/ZohoProjects/FilesApiHelper.php
+17
-0
3.1.0
→
3.3.1
View file →
| @@ -46,8 +46,9 @@ | ||
| 46 | 46 | * @return mixed $uploadedFiles ID's of uploaded file in Zoho Projects |
| 47 | 47 | */ |
| 48 | 48 | public function uploadFiles($files, $portalId, $projectId, $event, $eventId, $dataCenter) |
| 49 | 49 | { |
| 50 | + $files = self::normalizeFileNames($files); | |
| 50 | 51 | $uploadFileEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/" . ('task' === $event || 'subtask' === $event ? 'tasks' : 'bugs') . "/{$eventId}/attachments/"; |
| 51 | 52 | |
| 52 | 53 | $payload = ''; |
| 53 | 54 | if (is_array($files)) { |
| @@ -78,6 +79,22 @@ | ||
| 78 | 79 | $payload .= '--' . $this->_payloadBoundary . '--'; |
| 79 | 80 | $uploadResponse = HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader); |
| 80 | 81 | |
| 81 | 82 | return $uploadResponse; |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Field values may arrive as public file URLs (see IntegrationHandler::handleFileUrl), | |
| 87 | + * so reduce each to the stored file name before resolving against the entry directory. | |
| 88 | + * | |
| 89 | + * @param mixed $files file name(s) or URL(s) | |
| 90 | + * | |
| 91 | + * @return mixed | |
| 92 | + */ | |
| 93 | + private static function normalizeFileNames($files) | |
| 94 | + { | |
| 95 | + if (is_array($files)) { | |
| 96 | + return array_map([__CLASS__, 'normalizeFileNames'], $files); | |
| 97 | + } | |
| 98 | + return is_string($files) ? basename(wp_parse_url($files, PHP_URL_PATH) ?: $files) : $files; | |
| 82 | 99 | } |
| 83 | 100 | } |