PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Core/Integration/ZohoRecruit/FilesApiHelper.php +33 -12 2.03.3.1 View file →
@@ -6,14 +6,16 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\ZohoRecruit;
9 9
10 +use BitCode\BitForm\Core\Util\FileHandler;
10 11 use BitCode\BitForm\Core\Util\HttpHelper;
11 12
12 13 /**
13 14 * Provide functionality for Upload files
14 15 */
15 -final class FilesApiHelper {
16 +final class FilesApiHelper
17 +{
16 18 private $_defaultHeader;
17 19 private $_apiDomain;
18 20 private $_payloadBoundary;
19 21 private $_basepath;
@@ -21,14 +23,15 @@
21 23
22 24 private $_dataCenter;
23 25
24 26 /**
25 - * @param String $module zoho recruit module dname
26 - * @param Object $tokenDetails Api token details
27 - * @param Integer $formID ID of the form, for which integration is executing
28 - * @param Integer $entryID Current submittion ID
27 + * @param string $module zoho recruit module dname
28 + * @param object $tokenDetails Api token details
29 + * @param integer $formID ID of the form, for which integration is executing
30 + * @param integer $entryID Current submission ID
29 31 */
30 - public function __construct($module, $dataCenter, $tokenDetails, $formID, $entryID) {
32 + public function __construct($module, $dataCenter, $tokenDetails, $formID, $entryID)
33 + {
31 34 $this->_module = $module;
32 35 $this->_dataCenter = $dataCenter;
33 36 $this->_payloadBoundary = wp_generate_password(24);
34 37 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
@@ -33,21 +36,23 @@
33 36 $this->_payloadBoundary = wp_generate_password(24);
34 37 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
35 38 $this->_defaultHeader['content-type'] = 'multipart/form; boundary=' . $this->_payloadBoundary;
36 39 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
37 - $this->_basepath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
40 + $this->_basepath = FileHandler::getEntriesFileUploadDir($formID, $entryID) . DIRECTORY_SEPARATOR;
38 41 }
39 42
40 43 /**
41 44 * Helps to execute upload files api
42 45 *
43 - * @param Mixed $files Files path
44 - * @param Mixed $recordID Record id
45 - * @param String $zohoField zoho recruit upload fieldname
46 + * @param mixed $files Files path
47 + * @param mixed $recordID Record id
48 + * @param string $zohoField zoho recruit upload fieldname
46 49 *
47 - * @return Array $uploadedFiles ID's of uploaded file in Zoho Recruit
50 + * @return array $uploadedFiles ID's of uploaded file in Zoho Recruit
48 51 */
49 - public function uploadFiles($files, $recordID, $zohoField) {
52 + public function uploadFiles($files, $recordID, $zohoField)
53 + {
54 + $files = self::normalizeFileNames($files);
50 55 $uploadFileEndpoint = '';
51 56
52 57 if ('Candidate Photo' === $zohoField) {
53 58 $uploadFileEndpoint = "https://recruit.zoho.{$this->_dataCenter}/recruit/private/xml/{$this->_module}/uploadPhoto?Scope=recruitapi&type={$zohoField}&version=2&id={$recordID}";
@@ -81,6 +86,22 @@
81 86 return false;
82 87 }
83 88 $payload .= '--' . $this->_payloadBoundary . '--';
84 89 return HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
90 + }
91 +
92 + /**
93 + * Field values may arrive as public file URLs (see IntegrationHandler::handleFileUrl),
94 + * so reduce each to the stored file name before resolving against the entry directory.
95 + *
96 + * @param mixed $files file name(s) or URL(s)
97 + *
98 + * @return mixed
99 + */
100 + private static function normalizeFileNames($files)
101 + {
102 + if (is_array($files)) {
103 + return array_map([__CLASS__, 'normalizeFileNames'], $files);
104 + }
105 + return is_string($files) ? basename(wp_parse_url($files, PHP_URL_PATH) ?: $files) : $files;
85 106 }
86 107 }