PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 2.9.4
Brevo – Email, SMS, Web Push, Chat, and more. v2.9.4
2.9.13 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.1.29 3.1.3 3.1.30 3.1.31 3.1.32 3.1.33 3.1.34 3.1.35 3.1.36 3.1.37 3.1.38 3.1.39 3.1.4 3.1.40 3.1.41 3.1.42 3.1.43 3.1.44 3.1.45 3.1.46 3.1.47 3.1.48 3.1.49 3.1.5 3.1.50 3.1.51 3.1.52 3.1.53 3.1.54 3.1.55 3.1.56 3.1.57 3.1.58 3.1.59 3.1.6 3.1.60 3.1.61 3.1.62 3.1.63 3.1.64 3.1.65 3.1.66 3.1.67 3.1.68 3.1.69 3.1.7 3.1.70 3.1.71 3.1.72 3.1.73 3.1.74 3.1.75 3.1.76 3.1.77 3.1.78 3.1.79 3.1.8 3.1.80 3.1.81 3.1.82 3.1.83 3.1.84 3.1.85 3.1.86 3.1.87 3.1.88 3.1.89 3.1.9 3.1.90 3.1.91 3.1.92 3.1.93 3.1.94 3.1.95 3.1.96 3.1.97 3.1.98 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 trunk 1.0 1.5 2.0.8 2.9.10 2.9.11 2.9.12
mailin / model / model-forms.php
mailin / model Last commit date
index.php 11 years ago model-contacts.php 8 years ago model-forms.php 7 years ago model-lang.php 8 years ago model-users.php 8 years ago
model-forms.php
439 lines
1 <?php
2 /**
3 * Model class <i>SIB_Forms</i> represents forms
4 *
5 * @package SIB_Forms
6 */
7
8 if ( ! class_exists( 'SIB_Forms' ) ) {
9 /**
10 * Class SIB_Forms
11 *
12 * @package SIB_Forms
13 */
14 class SIB_Forms {
15
16 /**
17 * Tab table name
18 */
19 const TABLE_NAME = 'sib_model_forms';
20
21 /** Create Table */
22 public static function createTable() {
23 global $wpdb;
24 // create list table.
25 $creation_query =
26 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . self::TABLE_NAME . ' (
27 `id` int(20) NOT NULL AUTO_INCREMENT,
28 `title` varchar(120) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
29 `html` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
30 `css` longtext,
31 `dependTheme` int(1) NOT NULL DEFAULT 1,
32 `listID` longtext,
33 `templateID` int(20) NOT NULL DEFAULT -1,
34 `confirmID` int(20) NOT NULL DEFAULT -1,
35 `isDopt` int(1) NOT NULL DEFAULT 0,
36 `isOpt` int(1) NOT NULL DEFAULT 0,
37 `redirectInEmail` varchar(255),
38 `redirectInForm` varchar(255),
39 `successMsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
40 `errorMsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
41 `existMsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
42 `invalidMsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
43 `requiredMsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
44 `attributes` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
45 `date` DATE NOT NULL,
46 `isDefault` int(1) NOT NULL DEFAULT 0,
47 `gCaptcha` int(1) NOT NULL DEFAULT 0,
48 `gCaptcha_secret` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
49 `gCaptcha_site` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
50 `termAccept` int(1) NOT NULL DEFAULT 0,
51 `termsURL` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
52 PRIMARY KEY (`id`)
53 );';
54 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
55 dbDelta( $creation_query );
56 // create default form.
57 $rows = $wpdb->get_results('SELECT * FROM '. $wpdb->prefix . self::TABLE_NAME );
58 if (count( $rows ) == 0 )
59 {
60 self::createDefaultForm();
61 }
62 }
63
64 /**
65 * Remove table
66 */
67 public static function removeTable() {
68 global $wpdb;
69 $query = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . self::TABLE_NAME . ';';
70 $wpdb->query( $query ); // db call ok; no-cache ok.
71 }
72
73 /**
74 * Add columns for old versions
75 */
76 public static function alterTable() {
77 global $wpdb;
78 // add columns -gCaptcha, gCaptcha_secret.
79 $table_name = $wpdb->prefix . self::TABLE_NAME;
80
81 // check if gCaptcha fields exist
82 $gCaptcha = 'gCaptcha';
83 $result = $wpdb->query( $wpdb->prepare( "SHOW COLUMNS FROM `$table_name` LIKE %s ", $gCaptcha ) ); // db call ok; no-cache ok.
84
85 if ( empty( $result ) ) {
86 $alter_query = 'ALTER TABLE ' . $table_name . '
87 ADD COLUMN gCaptcha int(1) not NULL DEFAULT 0,
88 ADD COLUMN gCaptcha_secret varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
89 ADD COLUMN gCaptcha_site varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci';
90 $ret = $wpdb->query( $alter_query );
91 }
92
93 // add columns -termAccept, termsURL : version 2.9.0
94 $check_query = 'SHOW COLUMNS FROM `' . $table_name . "` LIKE 'termAccept';";
95 $result = $wpdb->query( $check_query );
96 if ( empty( $result ) ) {
97 $alter_query = 'ALTER TABLE ' . $table_name . '
98 ADD COLUMN termAccept int(1) not NULL DEFAULT 1,
99 ADD COLUMN termsURL varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci';
100 $ret = $wpdb->query( $alter_query );
101 }
102 // add columns - confirmID : version 2.9.0
103 $check_query = 'SHOW COLUMNS FROM `' . $table_name . "` LIKE 'confirmID';";
104 $result = $wpdb->query( $check_query );
105 if ( empty( $result ) ) {
106 $alter_query = 'ALTER TABLE ' . $table_name . '
107 ADD COLUMN confirmID int(20) not NULL DEFAULT -1';
108 $ret = $wpdb->query( $alter_query );
109 }
110 // add columns - requiredMsg : version 2.9.3
111 $check_query = 'SHOW COLUMNS FROM `' . $table_name . "` LIKE 'requiredMsg';";
112 $result = $wpdb->query( $check_query );
113 if ( empty( $result ) ) {
114 $alter_query = 'ALTER TABLE ' . $table_name . '
115 ADD COLUMN requiredMsg varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci';
116 $ret = $wpdb->query( $alter_query );
117 }
118 }
119
120 /**
121 * Get form data
122 *
123 * @param string $frmID - form ID.
124 * @return array|null|object|void
125 */
126 public static function getForm( $frmID = 'new' ) {
127 global $wpdb;
128 if ( 'new' == $frmID ) {
129 // default form.
130 $formData = self::getDefaultForm();
131 $list = maybe_serialize( array( SIB_API_Manager::get_default_list_id() ) );
132 $results = array(
133 'title' => '',
134 'html' => $formData['html'],
135 'css' => $formData['css'],
136 'listID' => $list,
137 'dependTheme' => '1',
138 'templateID' => '-1',
139 'confirmID' => '-1',
140 'isOpt' => '0',
141 'isDopt' => '0',
142 'redirectInEmail' => '',
143 'redirectInForm' => '',
144 'date' => date( 'Y-m-d' ),
145 'successMsg' => $formData['successMsg'],
146 'errorMsg' => $formData['errorMsg'],
147 'existMsg' => $formData['existMsg'],
148 'invalidMsg' => $formData['invalidMsg'],
149 'attributes' => 'email,NAME',
150 );
151 } else {
152 $query = 'select * from ' . $wpdb->prefix . self::TABLE_NAME . ' where id=' . $frmID . ';';
153 $results = $wpdb->get_row( $query, ARRAY_A ); // db call ok; no-cache ok.
154 }
155
156 if ( is_array( $results ) && count( $results ) > 0 ) {
157 $listIDs = maybe_unserialize( $results['listID'] );
158 $results['listID'] = $listIDs;
159 return $results;
160 }
161 return array();
162 }
163
164 /**
165 * Get all forms
166 */
167 public static function getForms() {
168 global $wpdb;
169
170 $query = 'select * from ' . $wpdb->prefix . self::TABLE_NAME . ';';
171 $results = $wpdb->get_results( $query, ARRAY_A ); // db call ok; no-cache ok.
172
173 if ( is_array( $results ) && count( $results ) > 0 ) {
174 // add list names field to display form table.
175 foreach ( $results as $key => $form ) {
176 if ( SIB_Forms_Lang::check_form_trans( $form['id'] ) == true ) {
177 unset( $results[ $key ] );
178 continue;
179 }
180 $listIDs = maybe_unserialize( $form['listID'] );
181 // get names form id array.
182 $lists = SIB_API_Manager::get_lists(); // pair of id and name.
183
184 $listNames = array();
185 foreach ( $lists as $list ) {
186 if ( in_array( $list['id'], $listIDs ) ) {
187 $listNames[] = $list['name'];
188 }
189 }
190 $results[ $key ]['listName'] = implode( ',', $listNames );
191 $results[ $key ]['listID'] = $listIDs;
192 }
193 return $results;
194 }
195 return array();
196
197 }
198
199 /**
200 * Add new form
201 *
202 * @param array $formData - form data.
203 * @return null|string
204 */
205 public static function addForm( $formData ) {
206 global $wpdb;
207
208 $current_date = date( 'Y-m-d' );
209
210 global $wpdb;
211 $query = 'INSERT INTO ' . $wpdb->prefix . self::TABLE_NAME . ' ';
212 $query .= '(title,html,css,dependTheme,listID,templateID,confirmID,isOpt,isDopt,redirectInEmail,redirectInForm,successMsg,errorMsg,existMsg,invalidMsg,requiredMsg,attributes,date,gCaptcha,gCaptcha_secret,gCaptcha_site,termAccept,termsURL) ';
213 $query .= "VALUES ('{$formData['title']}','{$formData['html']}','{$formData['css']}','{$formData['dependTheme']}','{$formData['listID']}',
214 '{$formData['templateID']}','{$formData['confirmID']}','{$formData['isOpt']}','{$formData['isDopt']}','{$formData['redirectInEmail']}','{$formData['redirectInForm']}',
215 '{$formData['successMsg']}','{$formData['errorMsg']}','{$formData['existMsg']}','{$formData['invalidMsg']}','{$formData['requiredMsg']}','{$formData['attributes']}','{$current_date}','{$formData['gcaptcha']}','{$formData['gcaptcha_secret']}' ,'{$formData['gcaptcha_site']}','{$formData['termAccept']}','{$formData['termsURL']}')";
216 $wpdb->query( $query ); // db call ok; no-cache ok.
217 $index = $wpdb->get_var( 'SELECT LAST_INSERT_ID();' ); // db call ok; no-cache ok.
218 return $index;
219 }
220
221 /**
222 * Update form
223 *
224 * @param int $formID - form ID.
225 * @param array $formData - form data.
226 * @return bool
227 */
228 public static function updateForm( $formID, $formData ) {
229 global $wpdb;
230
231 $current_date = date( 'Y-m-d' );
232
233 global $wpdb;
234 $query = 'update ' . $wpdb->prefix . self::TABLE_NAME . ' ';
235 $query .= "set title='{$formData['title']}',html='{$formData['html']}',css='{$formData['css']}',dependTheme='{$formData['dependTheme']}',listID='{$formData['listID']}',
236 isOpt='{$formData['isOpt']}',isDopt='{$formData['isDopt']}',templateID='{$formData['templateID']}',confirmID='{$formData['confirmID']}',
237 redirectInEmail='{$formData['redirectInEmail']}',redirectInForm='{$formData['redirectInForm']}',
238 successMsg='{$formData['successMsg']}',errorMsg='{$formData['errorMsg']}',existMsg='{$formData['existMsg']}',invalidMsg='{$formData['invalidMsg']}',requiredMsg='{$formData['requiredMsg']}',date='{$current_date}',attributes='{$formData['attributes']}',gCaptcha='{$formData['gcaptcha']}',gCaptcha_secret='{$formData['gcaptcha_secret']}' ,gCaptcha_site='{$formData['gcaptcha_site']}' ,termAccept='{$formData['termAccept']}',termsURL='{$formData['termsURL']}'";
239 $query .= 'where id=' . $formID . ';';
240 $wpdb->query( $query ); // db call ok; no-cache ok.
241
242 return true;
243 }
244
245 /**
246 * Remove form
247 *
248 * @param int $id - target form id.
249 */
250 public static function deleteForm( $id ) {
251 global $wpdb;
252
253 $wpdb->delete(
254 $wpdb->prefix . self::TABLE_NAME,
255 array(
256 'id' => $id,
257 )
258 ); // db call ok; no-cache ok.
259 }
260
261 /** Clear forms data */
262 public static function removeAllForms() {
263 global $wpdb;
264 $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . self::TABLE_NAME ); // db call ok; no-cache ok.
265 return true;
266 }
267
268 /** Create default form */
269 public static function createDefaultForm() {
270 $formData = self::getDefaultForm();
271 $html = $formData['html'];
272 $css = $formData['css'];
273 $list = maybe_serialize( array( SIB_API_Manager::get_default_list_id() ) );
274 $current_date = date( 'Y-m-d' );
275 $attributes = 'email,NAME';
276 global $wpdb;
277 $query = 'INSERT INTO ' . $wpdb->prefix . self::TABLE_NAME . ' ';
278 $query .= '(title,html,css,listID,dependTheme,successMsg,errorMsg,existMsg,invalidMsg,requiredMsg,attributes,date,isDefault) ';
279 $query .= "VALUES ('Default Form','{$html}','{$css}','{$list}','1','{$formData['successMsg']}','{$formData['errorMsg']}','{$formData['existMsg']}','{$formData['invalidMsg']}','{$formData['requiredMsg']}','{$attributes}','{$current_date}','1')";
280 $wpdb->query( $query ); // db call ok; no-cache ok.
281 }
282
283 /** Get default form data */
284 public static function getDefaultForm() {
285 $html = <<<EOD
286 <p class="sib-email-area">
287 <label class="sib-email-area">Email Address*</label>
288 <input type="email" class="sib-email-area" name="email" required="required">
289 </p>
290 <p class="sib-NAME-area">
291 <label class="sib-NAME-area">Name</label>
292 <input type="text" class="sib-NAME-area" name="NAME" >
293 </p>
294 <p>
295 <input type="submit" class="sib-default-btn" value="Subscribe">
296 </p>
297 EOD;
298 $css = <<<EOD
299 [form] {
300 padding: 5px;
301 -moz-box-sizing:border-box;
302 -webkit-box-sizing: border-box;
303 box-sizing: border-box;
304 }
305 [form] input[type=text],[form] input[type=email], [form] select {
306 width: 100%;
307 border: 1px solid #bbb;
308 height: auto;
309 margin: 5px 0 0 0;
310 }
311 [form] .sib-default-btn {
312 margin: 5px 0;
313 padding: 6px 12px;
314 color:#fff;
315 background-color: #333;
316 border-color: #2E2E2E;
317 font-size: 14px;
318 font-weight:400;
319 line-height: 1.4285;
320 text-align: center;
321 cursor: pointer;
322 vertical-align: middle;
323 -webkit-user-select:none;
324 -moz-user-select:none;
325 -ms-user-select:none;
326 user-select:none;
327 white-space: normal;
328 border:1px solid transparent;
329 border-radius: 3px;
330 }
331 [form] .sib-default-btn:hover {
332 background-color: #444;
333 }
334 [form] p{
335 margin: 10px 0 0 0;
336 }
337 EOD;
338
339 $result = array(
340 'html' => $html,
341 'css' => $css,
342 'successMsg' => esc_attr( __( 'Thank you, you have successfully registered !', 'sib_lang' ) ),
343 'errorMsg' => esc_attr( __( 'Something wrong occured', 'sib_lang' ) ),
344 'existMsg' => esc_attr( __( 'You have already registered', 'sib_lang' ) ),
345 'invalidMsg' => esc_attr( __( 'Your email address is invalid', 'sib_lang' ) ),
346 'requiredMsg' => esc_attr(__('Please fill out this field', 'sib_lang'))
347 );
348 return $result;
349 }
350
351 /** Get Default css */
352 public static function getDefaultMessageCss() {
353 $css = <<<EOD
354 [form] p.sib-alert-message {
355 padding: 6px 12px;
356 margin-bottom: 20px;
357 border: 1px solid transparent;
358 border-radius: 4px;
359 -webkit-box-sizing: border-box;
360 -moz-box-sizing: border-box;
361 box-sizing: border-box;
362 }
363 [form] p.sib-alert-message-error {
364 background-color: #f2dede;
365 border-color: #ebccd1;
366 color: #a94442;
367 }
368 [form] p.sib-alert-message-success {
369 background-color: #dff0d8;
370 border-color: #d6e9c6;
371 color: #3c763d;
372 }
373 [form] p.sib-alert-message-warning {
374 background-color: #fcf8e3;
375 border-color: #faebcc;
376 color: #8a6d3b;
377 }
378 EOD;
379 return $css;
380
381 }
382
383 /**
384 * Get form data of old version
385 * We suppose that the clients have got own setting values for form.
386 * If the client have default setting only then it will be return error.
387 * This function will be removed after next version
388 */
389 public static function get_old_form() {
390 // create form from old version.
391 $form_settings = get_option( 'sib_subscription_option' );
392 $html = $form_settings['sib_form_html'];
393 $avail_atts = $form_settings['available_attributes'];
394
395 $signup_settings = get_option( 'sib_signup_option' );
396 $is_confirm_email = 'yes' == $signup_settings['is_confirm_email'] ? 1 : 0;
397 $is_double_optin = 'yes' == $signup_settings['is_double_optin'] ? 1 : 0;
398 $redirect_url = $signup_settings['redirect_url'];
399 $redirect_url_click = $signup_settings['redirect_url_click'];
400 $template_id = 1 == $is_confirm_email ? $signup_settings['template_id'] : $signup_settings['doubleoptin_template_id'];
401
402 $confirmMsg = get_option( 'sib_confirm_option' );
403
404 $homeSetting = get_option( 'sib_home_option' );
405 $sib_list = maybe_serialize( array( (string) $homeSetting['list_id'] ) );
406
407 $formData = array(
408 'title' => 'Old Form',
409 'html' => $html,
410 'css' => '',
411 'dependTheme' => '1',
412 'listID' => $sib_list,
413 'templateID' => $template_id,
414 'isOpt' => $is_confirm_email,
415 'isDopt' => $is_double_optin,
416 'redirectInEmail' => $redirect_url,
417 'redirectInForm' => $redirect_url_click,
418 'successMsg' => $confirmMsg['alert_success_message'],
419 'errorMsg' => $confirmMsg['alert_error_message'],
420 'existMsg' => $confirmMsg['alert_exist_subscriber'],
421 'invalidMsg' => $confirmMsg['alert_invalid_email'],
422 'attributes' => 'email,' . implode( ',', $avail_atts ),
423 );
424
425 return $formData;
426 }
427
428 /** Add prefix to the table */
429 public static function add_prefix() {
430 global $wpdb;
431 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . self::TABLE_NAME . "'" ) == self::TABLE_NAME ) {
432 $query = 'ALTER TABLE ' . self::TABLE_NAME . ' RENAME TO ' . $wpdb->prefix . self::TABLE_NAME . ';';
433 $wpdb->query( $query ); // db call ok; no-cache ok.
434 }
435 }
436
437 }
438 }
439