PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
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 2.10.2 All 137 releases
bit-form / includes / Core / Integration / ZohoCreator / FilesApiHelper.php

FilesApiHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Core/Integration/ZohoCreator/FilesApiHelper.php

80 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoCreator Files Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoCreator;
9
10 use BitCode\BitForm\Core\Util\HttpHelper;
11
12 /**
13 * Provide functionality for Upload files
14 */
15 final class FilesApiHelper {
16 private $_defaultHeader;
17 private $_apiDomain;
18 private $_payloadBoundary;
19 private $_basepath;
20
21 /**
22 *
23 * @param Object $tokenDetails Api token details
24 * @param Integer $formID ID of the form, for which integration is executing
25 * @param Integer $entryID Current submittion ID
26 */
27 public function __construct($tokenDetails, $formID, $entryID) {
28 $this->_payloadBoundary = wp_generate_password(24);
29 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
30 $this->_defaultHeader['content-type'] = 'multipart/form-data; boundary=' . $this->_payloadBoundary;
31 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
32 $this->_basepath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
33 }
34
35 /**
36 * Helps to execute upload files api
37 *
38 * @param Mixed $files Files path
39 * @param Bool $isAttachment Check upload type
40 * @param Mixed $module Attachment Module name
41 * @param Mixed $recordID Record id
42 *
43 * @return Array $uploadedFiles ID's of uploaded file in Zoho Creator
44 */
45 public function uploadFiles($dataCenter, $files, $accountOwner, $applicationId, $reportId, $recordId, $fieldId) {
46 $uploadFileEndpoint = "https://creator.zoho.{$dataCenter}/api/v2/{$accountOwner}/{$applicationId}/report/{$reportId}/{$recordId}/{$fieldId}/upload";
47 $payload = '';
48 if (is_array($files)) {
49 foreach ($files as $fileIndex => $fileName) {
50 if (file_exists("{$this->_basepath}{$fileName}")) {
51 $payload .= '--' . $this->_payloadBoundary;
52 $payload .= "\r\n";
53 $payload .= 'Content-Disposition: form-data; name="' . 'file' .
54 '"; filename="' . basename("{$this->_basepath}{$fileName}") . '"' . "\r\n";
55 $payload .= "\r\n";
56 $payload .= file_get_contents("{$this->_basepath}{$fileName}");
57 $payload .= "\r\n";
58 }
59 }
60 } elseif (file_exists("{$this->_basepath}{$files}")) {
61 $payload .= '--' . $this->_payloadBoundary;
62 $payload .= "\r\n";
63 $payload .= 'Content-Disposition: form-data; name="' . 'file' .
64 '"; filename="' . basename("{$this->_basepath}{$files}") . '"' . "\r\n";
65 $payload .= "\r\n";
66 $payload .= file_get_contents("{$this->_basepath}{$files}");
67 $payload .= "\r\n";
68 }
69
70 if (empty($payload)) {
71 return false;
72 }
73 $payload .= '--' . $this->_payloadBoundary . '--';
74
75 $uploadResponse = HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
76
77 return $uploadResponse;
78 }
79 }
80