← All changes
|
includes/Core/Integration/ZohoBigin/FilesApiHelper.php
+17
-0
3.2.0
→
V3.3.2
View file →
| @@ -45,8 +45,9 @@ | ||
| 45 | 45 | * @return mixed $uploadedFiles ID's of uploaded file in Zoho Bigin |
| 46 | 46 | */ |
| 47 | 47 | public function uploadFiles($files, $module, $recordID, $isPhoto = null) |
| 48 | 48 | { |
| 49 | + $files = self::normalizeFileNames($files); | |
| 49 | 50 | $uploadFileEndpoint = ''; |
| 50 | 51 | |
| 51 | 52 | if ($isPhoto) { |
| 52 | 53 | $uploadFileEndpoint = "https://www.zohoapis.com/bigin/v1/{$module}/{$recordID}/photo"; |
| @@ -81,6 +82,22 @@ | ||
| 81 | 82 | } |
| 82 | 83 | $payload .= '--' . $this->_payloadBoundary . '--'; |
| 83 | 84 | |
| 84 | 85 | return HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader); |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Field values may arrive as public file URLs (see IntegrationHandler::handleFileUrl), | |
| 90 | + * so reduce each to the stored file name before resolving against the entry directory. | |
| 91 | + * | |
| 92 | + * @param mixed $files file name(s) or URL(s) | |
| 93 | + * | |
| 94 | + * @return mixed | |
| 95 | + */ | |
| 96 | + private static function normalizeFileNames($files) | |
| 97 | + { | |
| 98 | + if (is_array($files)) { | |
| 99 | + return array_map([__CLASS__, 'normalizeFileNames'], $files); | |
| 100 | + } | |
| 101 | + return is_string($files) ? basename(wp_parse_url($files, PHP_URL_PATH) ?: $files) : $files; | |
| 85 | 102 | } |
| 86 | 103 | } |