PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
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
← All changes | includes/Core/Messages/EmailTemplateHandler.php +136 -107 1.93.3.1 View file →
@@ -5,125 +5,154 @@
5 5 use BitCode\BitForm\Core\Database\EmailTemplateModel;
6 6
7 7 final class EmailTemplateHandler
8 8 {
9 - private static $_formID;
10 - private static $_emailTemplateModel;
11 - private $_user_details;
9 + private static $_formID;
10 + private static $_emailTemplateModel;
11 + private $_user_details;
12 12
13 - public function __construct($formID, array $user_details = null)
14 - {
15 - static::$_formID = $formID;
16 - static::$_emailTemplateModel = new EmailTemplateModel();
17 - $this->_user_details = $user_details;
13 + public function __construct($formID, array $user_details = null)
14 + {
15 + static::$_formID = $formID;
16 + static::$_emailTemplateModel = new EmailTemplateModel();
17 + $this->_user_details = $user_details;
18 + }
19 +
20 + /**
21 + * Decode a stored template `config` column into the object shape the admin editor expects.
22 + *
23 + * Older versions could persist an empty config as `[]`; decoded, that reaches the React editor
24 + * as a JS array and setting a key on it throws inside the immutable-draft library. Anything that
25 + * is not a non-empty object collapses to `{}`.
26 + *
27 + * @param mixed $config raw column value (JSON string, already-decoded value, or null)
28 + *
29 + * @return object
30 + */
31 + public static function normalizeConfig($config)
32 + {
33 + if (is_string($config)) {
34 + $config = json_decode($config);
18 35 }
36 + if (is_array($config)) {
37 + $config = (object) $config;
38 + }
19 39
20 - public function getAllTemplate($templateID = null, $userID = null)
21 - {
22 - $condition = array(
23 - 'form_id' => static::$_formID,
24 - );
25 - if (!is_null($templateID)) {
26 - $condition = array_merge($condition, array('id' => $templateID));
27 - }
28 - if (!is_null($userID)) {
29 - $condition = array_merge($condition, array('user_id' => $userID));
30 - }
31 - return static::$_emailTemplateModel->get(
32 - array(
33 - 'id',
34 - 'title',
35 - 'sub',
36 - 'body'
37 - ),
38 - $condition
39 - );
40 - }
40 + return is_object($config) ? $config : (object) [];
41 + }
41 42
42 - public function getATemplate($templateID)
43 - {
44 - return $this->getAllTemplate($templateID);
43 + public function getAllTemplate($templateID = null, $userID = null)
44 + {
45 + $condition = [
46 + 'form_id' => static::$_formID,
47 + ];
48 + if (!is_null($templateID)) {
49 + $condition = array_merge($condition, ['id' => $templateID]);
45 50 }
46 -
47 - public function saveTemplate($templateDetail)
48 - {
49 - return static::$_emailTemplateModel->insert(
50 - array(
51 - "title"=> $templateDetail->title,
52 - "sub"=> $templateDetail->sub,
53 - "body"=> $templateDetail->body,
54 - "form_id"=> static::$_formID,
55 - "user_id"=> $this->_user_details['id'],
56 - "user_ip"=>$this->_user_details['ip'],
57 - "created_at"=> $this->_user_details['time'],
58 - "updated_at"=> $this->_user_details['time']
59 - )
60 - );
51 + if (!is_null($userID)) {
52 + $condition = array_merge($condition, ['user_id' => $userID]);
61 53 }
54 + return static::$_emailTemplateModel->get(
55 + [
56 + 'id',
57 + 'title',
58 + 'sub',
59 + 'body',
60 + 'status',
61 + 'config'
62 + ],
63 + $condition
64 + );
65 + }
62 66
63 - public function updateTemplate($templateDetail)
64 - {
65 - return static::$_emailTemplateModel->update(
66 - array(
67 - "title"=> $templateDetail->title,
68 - "sub"=> $templateDetail->sub,
69 - "body"=> $templateDetail->body,
70 - "form_id"=> static::$_formID,
71 - "user_id"=> $this->_user_details['id'],
72 - "user_ip"=>$this->_user_details['ip'],
73 - "updated_at"=> $this->_user_details['time']
74 - ),
75 - array(
76 - "id" => $templateDetail->id
77 - )
78 - );
79 - }
67 + public function getATemplate($templateID)
68 + {
69 + return $this->getAllTemplate($templateID);
70 + }
80 71
81 - public function deleteTemplate($templateID)
82 - {
83 - return static::$_emailTemplateModel->delete(
84 - array(
85 - 'id' => $templateID,
86 - 'form_id' => static::$_formID,
87 - )
88 - );
89 - }
72 + public function saveTemplate($templateDetail)
73 + {
74 + return static::$_emailTemplateModel->insert(
75 + [
76 + 'title' => $templateDetail->title,
77 + 'sub' => $templateDetail->sub,
78 + 'body' => $templateDetail->body,
79 + 'status' => isset($templateDetail->status) ? (int) $templateDetail->status : 1,
80 + 'config' => isset($templateDetail->config) ? wp_json_encode($templateDetail->config) : null,
81 + 'form_id' => static::$_formID,
82 + 'user_id' => $this->_user_details['id'],
83 + 'user_ip' => $this->_user_details['ip'],
84 + 'created_at'=> $this->_user_details['time'],
85 + 'updated_at'=> $this->_user_details['time']
86 + ]
87 + );
88 + }
90 89
91 - public function duplicateTemplate($templateID)
92 - {
93 - $templateDetail = static::$_emailTemplateModel->get(
94 - array(
95 - 'id' => $templateID,
96 - 'form_id' => static::$_formID,
97 - )
98 - );
99 - if (is_wp_error($templateDetail) || empty($templateDetail)) {
100 - return $templateDetail;
101 - }
90 + public function updateTemplate($templateDetail)
91 + {
92 + return static::$_emailTemplateModel->update(
93 + [
94 + 'title' => $templateDetail->title,
95 + 'sub' => $templateDetail->sub,
96 + 'body' => $templateDetail->body,
97 + 'status' => isset($templateDetail->status) ? (int) $templateDetail->status : 1,
98 + 'config' => isset($templateDetail->config) ? wp_json_encode($templateDetail->config) : null,
99 + 'form_id' => static::$_formID,
100 + 'user_id' => $this->_user_details['id'],
101 + 'user_ip' => $this->_user_details['ip'],
102 + 'updated_at'=> $this->_user_details['time']
103 + ],
104 + [
105 + 'id' => $templateDetail->id
106 + ]
107 + );
108 + }
102 109
103 - $title = empty($templateDetail[0]->title) ? "Duplicate of Template #$templateID" :
104 - "Duplicate of $templateDetail[0]->title";
110 + public function deleteTemplate($templateID)
111 + {
112 + return static::$_emailTemplateModel->delete(
113 + [
114 + 'id' => $templateID,
115 + 'form_id' => static::$_formID,
116 + ]
117 + );
118 + }
105 119
106 - $templateDetail[0]->title = $title;
107 - return $this->saveTemplate($templateDetail);
120 + public function duplicateTemplate($templateID)
121 + {
122 + $templateDetail = static::$_emailTemplateModel->get(
123 + [
124 + 'id' => $templateID,
125 + 'form_id' => static::$_formID,
126 + ]
127 + );
128 + if (is_wp_error($templateDetail) || empty($templateDetail)) {
129 + return $templateDetail;
108 130 }
109 131
110 - public function duplicateAllTempInAForm($oldFromId)
111 - {
112 - $allCols = ["title","sub","body","form_id","user_id","user_ip","created_at","updated_at"];
113 - $dupData = array(
114 - "title",
115 - "sub",
116 - "body",
117 - static::$_formID,
118 - $this->_user_details['id'],
119 - $this->_user_details['ip'],
120 - $this->_user_details['time'],
121 - $this->_user_details['time']
122 - );
123 - return static::$_emailTemplateModel->duplicate(
124 - $allCols,
125 - $dupData,
126 - ['form_id' => $oldFromId]
127 - );
128 - }
132 + $title = empty($templateDetail[0]->title) ? "Duplicate of Template #$templateID" :
133 + "Duplicate of $templateDetail[0]->title";
134 +
135 + $templateDetail[0]->title = $title;
136 + return $this->saveTemplate($templateDetail);
137 + }
138 +
139 + public function duplicateAllTempInAForm($oldFromId)
140 + {
141 + $allCols = ['title', 'sub', 'body', 'form_id', 'user_id', 'user_ip', 'created_at', 'updated_at'];
142 + $dupData = [
143 + 'title',
144 + 'sub',
145 + 'body',
146 + static::$_formID,
147 + $this->_user_details['id'],
148 + $this->_user_details['ip'],
149 + $this->_user_details['time'],
150 + $this->_user_details['time']
151 + ];
152 + return static::$_emailTemplateModel->duplicate(
153 + $allCols,
154 + $dupData,
155 + ['form_id' => $oldFromId]
156 + );
157 + }
129 158 }