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 / ZohoProjects / FilesApiHelper.php

FilesApiHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Core/Integration/ZohoProjects/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 * ZohoProjects Files Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoProjects;
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 Projects
44 */
45 public function uploadFiles($files, $portalId, $projectId, $event, $eventId, $dataCenter) {
46 $uploadFileEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/" . ('task' === $event || 'subtask' === $event ? 'tasks' : 'bugs') . "/${eventId}/attachments/";
47
48 $payload = '';
49 if (is_array($files)) {
50 foreach ($files as $fileIndex => $fileName) {
51 if (file_exists("{$this->_basepath}{$fileName}")) {
52 $payload .= '--' . $this->_payloadBoundary;
53 $payload .= "\r\n";
54 $payload .= 'Content-Disposition: form-data; name="' . 'uploaddoc' .
55 '"; filename="' . basename("{$this->_basepath}{$fileName}") . '"' . "\r\n";
56 $payload .= "\r\n";
57 $payload .= file_get_contents("{$this->_basepath}{$fileName}");
58 $payload .= "\r\n";
59 }
60 }
61 } elseif (file_exists("{$this->_basepath}{$files}")) {
62 $payload .= '--' . $this->_payloadBoundary;
63 $payload .= "\r\n";
64 $payload .= 'Content-Disposition: form-data; name="' . 'uploaddoc' .
65 '"; filename="' . basename("{$this->_basepath}{$files}") . '"' . "\r\n";
66 $payload .= "\r\n";
67 $payload .= file_get_contents("{$this->_basepath}{$files}");
68 $payload .= "\r\n";
69 }
70
71 if (empty($payload)) {
72 return false;
73 }
74 $payload .= '--' . $this->_payloadBoundary . '--';
75 $uploadResponse = HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
76
77 return $uploadResponse;
78 }
79 }
80