PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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.21.13, at includes/Core/Integration/ZohoProjects/FilesApiHelper.php

84 lines 2.9 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\FileHandler;
11 use BitCode\BitForm\Core\Util\HttpHelper;
12
13 /**
14 * Provide functionality for Upload files
15 */
16 final class FilesApiHelper
17 {
18 private $_defaultHeader;
19 private $_apiDomain;
20 private $_payloadBoundary;
21 private $_basepath;
22
23 /**
24 *
25 * @param object $tokenDetails Api token details
26 * @param integer $formID ID of the form, for which integration is executing
27 * @param integer $entryID Current submittion ID
28 */
29 public function __construct($tokenDetails, $formID, $entryID)
30 {
31 $this->_payloadBoundary = wp_generate_password(24);
32 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
33 $this->_defaultHeader['content-type'] = 'multipart/form-data; boundary=' . $this->_payloadBoundary;
34 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
35 $this->_basepath = FileHandler::getEntriesFileUploadDir($formID, $entryID) . DIRECTORY_SEPARATOR;
36 }
37
38 /**
39 * Helps to execute upload files api
40 *
41 * @param mixed $files Files path
42 * @param bool $isAttachment Check upload type
43 * @param mixed $module Attachment Module name
44 * @param mixed $recordID Record id
45 *
46 * @return mixed $uploadedFiles ID's of uploaded file in Zoho Projects
47 */
48 public function uploadFiles($files, $portalId, $projectId, $event, $eventId, $dataCenter)
49 {
50 $uploadFileEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/" . ('task' === $event || 'subtask' === $event ? 'tasks' : 'bugs') . "/{$eventId}/attachments/";
51
52 $payload = '';
53 if (is_array($files)) {
54 foreach ($files as $fileIndex => $fileName) {
55 if (file_exists("{$this->_basepath}{$fileName}")) {
56 $payload .= '--' . $this->_payloadBoundary;
57 $payload .= "\r\n";
58 $payload .= 'Content-Disposition: form-data; name="' . 'uploaddoc' .
59 '"; filename="' . basename("{$this->_basepath}{$fileName}") . '"' . "\r\n";
60 $payload .= "\r\n";
61 $payload .= file_get_contents("{$this->_basepath}{$fileName}");
62 $payload .= "\r\n";
63 }
64 }
65 } elseif (file_exists("{$this->_basepath}{$files}")) {
66 $payload .= '--' . $this->_payloadBoundary;
67 $payload .= "\r\n";
68 $payload .= 'Content-Disposition: form-data; name="' . 'uploaddoc' .
69 '"; filename="' . basename("{$this->_basepath}{$files}") . '"' . "\r\n";
70 $payload .= "\r\n";
71 $payload .= file_get_contents("{$this->_basepath}{$files}");
72 $payload .= "\r\n";
73 }
74
75 if (empty($payload)) {
76 return false;
77 }
78 $payload .= '--' . $this->_payloadBoundary . '--';
79 $uploadResponse = HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
80
81 return $uploadResponse;
82 }
83 }
84