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/Database/ApiModel.php +92 -39 2.03.3.1 View file →
@@ -7,15 +7,20 @@
7 7 /**
8 8 * Undocumented class
9 9 */
10 10
11 -class ApiModel extends Model {
12 - public function __construct() {
11 +class ApiModel extends Model
12 +{
13 + public $_wpdb;
14 +
15 + public function __construct()
16 + {
13 17 global $wpdb;
14 18 $this->_wpdb = $wpdb;
15 19 }
16 20
17 - public function getForm() {
21 + public function getForm()
22 + {
18 23 $result = $this->_wpdb->get_results(
19 24 "
20 25 SELECT form_name,id FROM `{$this->_wpdb->prefix}bitforms_form` WHERE `status`=1 order By created_at DESC
21 26 "
@@ -22,42 +27,63 @@
22 27 );
23 28 return $result;
24 29 }
25 30
26 - public function getField($id) {
31 + public function getField($id)
32 + {
27 33 $result = $this->_wpdb->get_results(
28 - "
29 - SELECT form_content,id FROM `{$this->_wpdb->prefix}bitforms_form` WHERE `status`=1 AND `id`='$id'
30 - "
34 + $this->_wpdb->prepare(
35 + "SELECT form_content,id FROM `{$this->_wpdb->prefix}bitforms_form` WHERE `status`=1 AND `id`=%d",
36 + $id
37 + )
31 38 );
32 39 return $result;
33 40 }
34 41
35 - public function editEntry($entryID) {
42 + public function editEntry($entryID)
43 + {
36 44 $result = $this->_wpdb->get_results(
37 - "
38 - SELECT bitforms_form_entry_id,meta_key,meta_value FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` WHERE `bitforms_form_entry_id`='$entryID'
39 - "
45 + $this->_wpdb->prepare(
46 + "SELECT bitforms_form_entry_id,meta_key,meta_value FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` WHERE `bitforms_form_entry_id`=%d",
47 + $entryID
48 + )
40 49 );
41 50 return $result;
42 51 }
43 52
44 - public function entryDelete($entryID) {
45 - $sql = "DELETE FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` WHERE `bitforms_form_entry_id` = $entryID";
53 + public function entryDelete($entryID)
54 + {
55 + $sql = $this->_wpdb->prepare(
56 + "DELETE FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` WHERE `bitforms_form_entry_id` = %d",
57 + $entryID
58 + );
46 59 $result = $this->_wpdb->query($sql);
47 60 return $result;
48 61 }
49 62
50 - public function findRecord($table_name, $column, $value) {
51 - $result = $this->_wpdb->get_results(
52 - "
53 - SELECT $column FROM `{$this->_wpdb->prefix}$table_name` WHERE `$column`='$value'
54 - "
63 + public function findRecord($table_name, $column, $value)
64 + {
65 + // Identifiers (table/column) cannot be parameterized with wpdb placeholders.
66 + // Sanitize identifiers to prevent SQL injection through dynamic identifiers.
67 + $safeTable = preg_replace('/[^A-Za-z0-9_]/', '', (string) $table_name);
68 + $safeColumn = preg_replace('/[^A-Za-z0-9_]/', '', (string) $column);
69 + $table_name = $this->_wpdb->prefix . $safeTable;
70 + $value = is_scalar($value) ? $value : ''; // Ensure value is scalar for placeholder.
71 + if ('' === $safeTable || '' === $safeColumn) {
72 + return [];
73 + }
74 +
75 + $sql = $this->_wpdb->prepare(
76 + 'SELECT `%1$s` FROM `%2$s` WHERE `%1$s`=%3$s',
77 + $safeColumn,
78 + $table_name,
79 + $value
55 80 );
56 - return $result;
81 + return $this->_wpdb->get_results($sql);
57 82 }
58 83
59 - public function noteCreate($formID, $entryID, $note_details) {
84 + public function noteCreate($formID, $entryID, $note_details)
85 + {
60 86 $ipTool = new IpTool();
61 87 $user_details = $ipTool->getUserDetail();
62 88 $result = $this->_wpdb->insert(
63 89 "{$this->_wpdb->prefix}bitforms_form_entry_relatedinfo",
@@ -73,27 +99,27 @@
73 99 );
74 100 return $result;
75 101 }
76 102
77 - public function noteList() {
78 - $result = $this->_wpdb->get_results(
79 - "
80 - SELECT * FROM `{$this->_wpdb->prefix}bitforms_form_entry_relatedinfo` WHERE `status`=1
81 - "
82 - );
103 + public function noteList()
104 + {
105 + $result = $this->_wpdb->get_results("SELECT * FROM `{$this->_wpdb->prefix}bitforms_form_entry_relatedinfo` WHERE `status`=1");
83 106 return $result;
84 107 }
85 108
86 - public function getWorkFlow($formID) {
109 + public function getWorkFlow($formID)
110 + {
87 111 $result = $this->_wpdb->get_results(
88 - "
89 - SELECT workflow_name,id FROM `{$this->_wpdb->prefix}bitforms_workflows` WHERE `form_id`= $formID
90 - "
112 + $this->_wpdb->prepare(
113 + "SELECT workflow_name,id FROM `{$this->_wpdb->prefix}bitforms_workflows` WHERE `form_id` = %d",
114 + $formID
115 + )
91 116 );
92 117 return $result;
93 118 }
94 119
95 - public function noteUpdate($noteID, $note_details) {
120 + public function noteUpdate($noteID, $note_details)
121 + {
96 122 $data = ['info_details' => $note_details];
97 123 $result = $this->_wpdb->update(
98 124 "{$this->_wpdb->prefix}bitforms_form_entry_relatedinfo",
99 125 $data,
@@ -103,31 +129,58 @@
103 129 );
104 130 return $result;
105 131 }
106 132
107 - public function noteDelete($noteID) {
108 - $sql = "DELETE FROM `{$this->_wpdb->prefix}bitforms_form_entry_relatedinfo` WHERE `id` = $noteID";
133 + public function noteDelete($noteID)
134 + {
135 + $sql = $this->_wpdb->prepare(
136 + "DELETE FROM `{$this->_wpdb->prefix}bitforms_form_entry_relatedinfo` WHERE `id` = %d",
137 + $noteID
138 + );
109 139 $result = $this->_wpdb->query($sql);
110 140 return $result;
111 141 }
112 142
113 - public function get_form_value($entryID) {
114 - $sql = "SELECT `meta_key`,`meta_value` FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` where bitforms_form_entry_id=$entryID";
143 + public function get_form_value($entryID)
144 + {
145 + $sql = $this->_wpdb->prepare(
146 + "SELECT `meta_key`,`meta_value` FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` WHERE bitforms_form_entry_id=%d",
147 + $entryID
148 + );
115 149 $result = $this->_wpdb->get_results($sql);
116 150 return $result;
117 151 }
118 152
119 - public function logUpdate($updateValue, $logID) {
153 + public function logUpdate($updateValue, $logID)
154 + {
120 155 if (empty($logID)) {
121 156 return false;
122 157 }
123 - $sql = "UPDATE `{$this->_wpdb->prefix}bitforms_form_entry_log` SET content='$updateValue' WHERE id=$logID";
158 + $sql = $this->_wpdb->prepare(
159 + "UPDATE `{$this->_wpdb->prefix}bitforms_form_entry_log` SET content=%s WHERE id=%d",
160 + $updateValue,
161 + $logID
162 + );
124 163 $result = $this->_wpdb->get_results($sql);
125 164 return $result;
126 165 }
127 166
128 - public function getFormId($formID) {
129 - $sql = "SELECT form_id FROM `{$this->_wpdb->prefix}bitforms_form_entries` WHERE id=$formID";
167 + public function getFormId($formID)
168 + {
169 + $sql = $this->_wpdb->prepare(
170 + "SELECT form_id FROM `{$this->_wpdb->prefix}bitforms_form_entries` WHERE id=%d",
171 + $formID
172 + );
173 + $result = $this->_wpdb->get_results($sql);
174 + return $result;
175 + }
176 +
177 + public function getOnSubmitWorkflow($formID)
178 + {
179 + $sql = $this->_wpdb->prepare(
180 + "SELECT `id`, `workflow_name`, `workflow_type`, `workflow_run`, `workflow_behaviour`, `workflow_status` FROM `{$this->_wpdb->prefix}bitforms_workflows` WHERE `form_id`=%d AND `workflow_type`='onsubmit' ORDER BY id DESC",
181 + $formID
182 + );
130 183 $result = $this->_wpdb->get_results($sql);
131 184 return $result;
132 185 }
133 186 }