PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.10.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.10.0
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
bit-form / includes / Core / Integration / ZohoBigin / FilesApiHelper.php

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

85 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 * ZohoBigin Files Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoBigin;
9
10 use BitCode\BitForm\Core\Util\HttpHelper;
11
12 /**
13 * Provide functionality for Upload files
14 */
15 final class FilesApiHelper
16 {
17 private $_defaultHeader;
18 private $_apiDomain;
19 private $_payloadBoundary;
20 private $_basepath;
21
22 /**
23 * @param String $module zoho bigin module dname
24 * @param Object $tokenDetails Api token details
25 * @param Integer $formID ID of the form, for which integration is executing
26 * @param Integer $entryID Current submittion ID
27 */
28 public function __construct($tokenDetails, $formID, $entryID)
29 {
30 $this->_payloadBoundary = wp_generate_password(24);
31 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
32 $this->_defaultHeader['content-type'] = 'multipart/form; boundary=' . $this->_payloadBoundary;
33 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
34 $this->_basepath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
35 }
36
37 /**
38 * Helps to execute upload files api
39 *
40 * @param Mixed $files Files path
41 * @param Mixed $recordID Record id
42 * @param String $zohoField zoho bigin upload fieldname
43 *
44 * @return mixed $uploadedFiles ID's of uploaded file in Zoho Bigin
45 */
46 public function uploadFiles($files, $module, $recordID, $isPhoto = null)
47 {
48 $uploadFileEndpoint = '';
49
50 if ($isPhoto) {
51 $uploadFileEndpoint = "https://www.zohoapis.com/bigin/v1/{$module}/{$recordID}/photo";
52 } else {
53 $uploadFileEndpoint = "https://www.zohoapis.com/bigin/v1/{$module}/{$recordID}/Attachments";
54 }
55
56 $payload = '';
57 if (is_array($files)) {
58 foreach ($files as $fileIndex => $fileName) {
59 if (file_exists("{$this->_basepath}{$fileName}")) {
60 $payload .= '--' . $this->_payloadBoundary;
61 $payload .= "\r\n";
62 $payload .= 'Content-Disposition: form-data; name="' . 'file' .
63 '"; filename="' . basename("{$this->_basepath}{$fileName}") . '"' . "\r\n";
64 $payload .= "\r\n";
65 $payload .= file_get_contents("{$this->_basepath}{$fileName}");
66 $payload .= "\r\n";
67 }
68 }
69 } elseif (file_exists("{$this->_basepath}{$files}")) {
70 $payload .= '--' . $this->_payloadBoundary;
71 $payload .= "\r\n";
72 $payload .= 'Content-Disposition: form-data; name="' . 'file' .
73 '"; filename="' . basename("{$this->_basepath}{$files}") . '"' . "\r\n";
74 $payload .= "\r\n";
75 $payload .= file_get_contents("{$this->_basepath}{$files}");
76 $payload .= "\r\n";
77 }
78 if (empty($payload)) {
79 return false;
80 }
81 $payload .= '--' . $this->_payloadBoundary . '--';
82
83 return HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
84 }
85 }