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

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

90 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoRecruit Files Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoRecruit;
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 private $_module;
22
23 private $_dataCenter;
24
25 /**
26 * @param String $module zoho recruit module dname
27 * @param Object $tokenDetails Api token details
28 * @param Integer $formID ID of the form, for which integration is executing
29 * @param Integer $entryID Current submittion ID
30 */
31 public function __construct($module, $dataCenter, $tokenDetails, $formID, $entryID)
32 {
33 $this->_module = $module;
34 $this->_dataCenter = $dataCenter;
35 $this->_payloadBoundary = wp_generate_password(24);
36 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
37 $this->_defaultHeader['content-type'] = 'multipart/form; boundary=' . $this->_payloadBoundary;
38 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
39 $this->_basepath = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID . DIRECTORY_SEPARATOR;
40 }
41
42 /**
43 * Helps to execute upload files api
44 *
45 * @param Mixed $files Files path
46 * @param Mixed $recordID Record id
47 * @param String $zohoField zoho recruit upload fieldname
48 *
49 * @return Array $uploadedFiles ID's of uploaded file in Zoho Recruit
50 */
51 public function uploadFiles($files, $recordID, $zohoField)
52 {
53 $uploadFileEndpoint = '';
54
55 if ('Candidate Photo' === $zohoField) {
56 $uploadFileEndpoint = "https://recruit.zoho.{$this->_dataCenter}/recruit/private/xml/{$this->_module}/uploadPhoto?Scope=recruitapi&type={$zohoField}&version=2&id={$recordID}";
57 } else {
58 $uploadFileEndpoint = "https://recruit.zoho.{$this->_dataCenter}/recruit/private/json/{$this->_module}/uploadFile?Scope=ZohoRecruit.modules.all&type={$zohoField}&version=2&id={$recordID}";
59 }
60
61 $payload = '';
62 if (is_array($files)) {
63 foreach ($files as $fileIndex => $fileName) {
64 if (file_exists("{$this->_basepath}{$fileName}")) {
65 $payload .= '--' . $this->_payloadBoundary;
66 $payload .= "\r\n";
67 $payload .= 'Content-Disposition: form-data; name="' . 'content' .
68 '"; filename="' . basename("{$this->_basepath}{$fileName}") . '"' . "\r\n";
69 $payload .= "\r\n";
70 $payload .= file_get_contents("{$this->_basepath}{$fileName}");
71 $payload .= "\r\n";
72 }
73 }
74 } elseif (file_exists("{$this->_basepath}{$files}")) {
75 $payload .= '--' . $this->_payloadBoundary;
76 $payload .= "\r\n";
77 $payload .= 'Content-Disposition: form-data; name="' . 'content' .
78 '"; filename="' . basename("{$this->_basepath}{$files}") . '"' . "\r\n";
79 $payload .= "\r\n";
80 $payload .= file_get_contents("{$this->_basepath}{$files}");
81 $payload .= "\r\n";
82 }
83 if (empty($payload)) {
84 return false;
85 }
86 $payload .= '--' . $this->_payloadBoundary . '--';
87 return HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader);
88 }
89 }
90