PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 2.9.13
Brevo – Email, SMS, Web Push, Chat, and more. v2.9.13
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 6 years ago model-lang.php 6 years ago model-users.php 6 years ago
model-forms.php
442 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 $wpdb->query($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 'requiredMsg' => $formData['requiredMsg'],
150 'attributes' => 'email,NAME',
151 );
152 } else {
153 $query = 'select * from ' . $wpdb->prefix . self::TABLE_NAME . ' where id=' . $frmID . ';';
154 $results = $wpdb->get_row( $query, ARRAY_A ); // db call ok; no-cache ok.
155 }
156
157 if ( is_array( $results ) && count( $results ) > 0 ) {
158 $listIDs = maybe_unserialize( $results['listID'] );
159 $results['listID'] = $listIDs;
160 return $results;
161 }
162 return array();
163 }
164
165 /**
166 * Get all forms
167 */
168 public static function getForms() {
169 global $wpdb;
170
171 $query = 'select * from ' . $wpdb->prefix . self::TABLE_NAME . ';';
172 $results = $wpdb->get_results( $query, ARRAY_A ); // db call ok; no-cache ok.
173
174 if ( is_array( $results ) && count( $results ) > 0 ) {
175 // add list names field to display form table.
176 foreach ( $results as $key => $form ) {
177 if ( SIB_Forms_Lang::check_form_trans( $form['id'] ) == true ) {
178 unset( $results[ $key ] );
179 continue;
180 }
181 $listIDs = maybe_unserialize( $form['listID'] );
182 $listIDs = !empty($listIDs) ? $listIDs : array();
183 // get names form id array.
184 $lists = SIB_API_Manager::get_lists(); // pair of id and name.
185
186 $listNames = array();
187 foreach ( $lists as $list ) {
188 if ( in_array( $list['id'], $listIDs ) ) {
189 $listNames[] = $list['name'];
190 }
191 }
192 $results[ $key ]['listName'] = implode( ',', $listNames );
193 $results[ $key ]['listID'] = $listIDs;
194 }
195 return $results;
196 }
197 return array();
198
199 }
200
201 /**
202 * Add new form
203 *
204 * @param array $formData - form data.
205 * @return null|string
206 */
207 public static function addForm( $formData ) {
208 global $wpdb;
209
210 $current_date = date( 'Y-m-d' );
211
212 global $wpdb;
213 $query = 'INSERT INTO ' . $wpdb->prefix . self::TABLE_NAME . ' ';
214 $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) ';
215 $query .= "VALUES ('{$formData['title']}','{$formData['html']}','{$formData['css']}','{$formData['dependTheme']}','{$formData['listID']}',
216 '{$formData['templateID']}','{$formData['confirmID']}','{$formData['isOpt']}','{$formData['isDopt']}','{$formData['redirectInEmail']}','{$formData['redirectInForm']}',
217 '{$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']}')";
218 $wpdb->query( $query ); // db call ok; no-cache ok.
219 $index = $wpdb->get_var( 'SELECT LAST_INSERT_ID();' ); // db call ok; no-cache ok.
220 return $index;
221 }
222
223 /**
224 * Update form
225 *
226 * @param int $formID - form ID.
227 * @param array $formData - form data.
228 * @return bool
229 */
230 public static function updateForm( $formID, $formData ) {
231 global $wpdb;
232
233 $current_date = date( 'Y-m-d' );
234
235 global $wpdb;
236 $query = 'update ' . $wpdb->prefix . self::TABLE_NAME . ' ';
237 $query .= "set title='{$formData['title']}',html='{$formData['html']}',css='{$formData['css']}',dependTheme='{$formData['dependTheme']}',listID='{$formData['listID']}',
238 isOpt='{$formData['isOpt']}',isDopt='{$formData['isDopt']}',templateID='{$formData['templateID']}',confirmID='{$formData['confirmID']}',
239 redirectInEmail='{$formData['redirectInEmail']}',redirectInForm='{$formData['redirectInForm']}',
240 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']}'";
241 $query .= 'where id=' . $formID . ';';
242 $wpdb->query( $query ); // db call ok; no-cache ok.
243
244 return true;
245 }
246
247 /**
248 * Remove form
249 *
250 * @param int $id - target form id.
251 */
252 public static function deleteForm( $id ) {
253 global $wpdb;
254
255 $wpdb->delete(
256 $wpdb->prefix . self::TABLE_NAME,
257 array(
258 'id' => $id,
259 )
260 ); // db call ok; no-cache ok.
261 }
262
263 /** Clear forms data */
264 public static function removeAllForms() {
265 global $wpdb;
266 $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . self::TABLE_NAME ); // db call ok; no-cache ok.
267 return true;
268 }
269
270 /** Create default form */
271 public static function createDefaultForm() {
272 $formData = self::getDefaultForm();
273 $html = $formData['html'];
274 $css = $formData['css'];
275 $list = maybe_serialize( array( SIB_API_Manager::get_default_list_id() ) );
276 $current_date = date( 'Y-m-d' );
277 $attributes = 'email,NAME';
278 global $wpdb;
279 $query = 'INSERT INTO ' . $wpdb->prefix . self::TABLE_NAME . ' ';
280 $deafult_form_name = esc_attr( __( 'Default Form', 'sib_lang' ) );
281 $query .= '(title,html,css,listID,dependTheme,successMsg,errorMsg,existMsg,invalidMsg,requiredMsg,attributes,date,isDefault) ';
282 $query .= "VALUES ('{$deafult_form_name}','{$html}','{$css}','{$list}','1','{$formData['successMsg']}','{$formData['errorMsg']}','{$formData['existMsg']}','{$formData['invalidMsg']}','{$formData['requiredMsg']}','{$attributes}','{$current_date}','1')";
283 $wpdb->query( $query ); // db call ok; no-cache ok.
284 }
285
286 /** Get default form data */
287 public static function getDefaultForm() {
288 $html = <<<EOD
289 <p class="sib-email-area">
290 <label class="sib-email-area">Email Address*</label>
291 <input type="email" class="sib-email-area" name="email" required="required">
292 </p>
293 <p class="sib-NAME-area">
294 <label class="sib-NAME-area">Name</label>
295 <input type="text" class="sib-NAME-area" name="NAME" >
296 </p>
297 <p>
298 <input type="submit" class="sib-default-btn" value="Subscribe">
299 </p>
300 EOD;
301 $css = <<<EOD
302 [form] {
303 padding: 5px;
304 -moz-box-sizing:border-box;
305 -webkit-box-sizing: border-box;
306 box-sizing: border-box;
307 }
308 [form] input[type=text],[form] input[type=email], [form] select {
309 width: 100%;
310 border: 1px solid #bbb;
311 height: auto;
312 margin: 5px 0 0 0;
313 }
314 [form] .sib-default-btn {
315 margin: 5px 0;
316 padding: 6px 12px;
317 color:#fff;
318 background-color: #333;
319 border-color: #2E2E2E;
320 font-size: 14px;
321 font-weight:400;
322 line-height: 1.4285;
323 text-align: center;
324 cursor: pointer;
325 vertical-align: middle;
326 -webkit-user-select:none;
327 -moz-user-select:none;
328 -ms-user-select:none;
329 user-select:none;
330 white-space: normal;
331 border:1px solid transparent;
332 border-radius: 3px;
333 }
334 [form] .sib-default-btn:hover {
335 background-color: #444;
336 }
337 [form] p{
338 margin: 10px 0 0 0;
339 }
340 EOD;
341
342 $result = array(
343 'html' => $html,
344 'css' => $css,
345 'successMsg' => esc_attr( __( 'Thank you, you have successfully registered !', 'sib_lang' ) ),
346 'errorMsg' => esc_attr( __( 'Something wrong occured', 'sib_lang' ) ),
347 'existMsg' => esc_attr( __( 'You have already registered', 'sib_lang' ) ),
348 'invalidMsg' => esc_attr( __( 'Your email address is invalid', 'sib_lang' ) ),
349 'requiredMsg' => esc_attr(__('Please fill out this field', 'sib_lang'))
350 );
351 return $result;
352 }
353
354 /** Get Default css */
355 public static function getDefaultMessageCss() {
356 $css = <<<EOD
357 [form] p.sib-alert-message {
358 padding: 6px 12px;
359 margin-bottom: 20px;
360 border: 1px solid transparent;
361 border-radius: 4px;
362 -webkit-box-sizing: border-box;
363 -moz-box-sizing: border-box;
364 box-sizing: border-box;
365 }
366 [form] p.sib-alert-message-error {
367 background-color: #f2dede;
368 border-color: #ebccd1;
369 color: #a94442;
370 }
371 [form] p.sib-alert-message-success {
372 background-color: #dff0d8;
373 border-color: #d6e9c6;
374 color: #3c763d;
375 }
376 [form] p.sib-alert-message-warning {
377 background-color: #fcf8e3;
378 border-color: #faebcc;
379 color: #8a6d3b;
380 }
381 EOD;
382 return $css;
383
384 }
385
386 /**
387 * Get form data of old version
388 * We suppose that the clients have got own setting values for form.
389 * If the client have default setting only then it will be return error.
390 * This function will be removed after next version
391 */
392 public static function get_old_form() {
393 // create form from old version.
394 $form_settings = get_option( 'sib_subscription_option' );
395 $html = $form_settings['sib_form_html'];
396 $avail_atts = $form_settings['available_attributes'];
397
398 $signup_settings = get_option( 'sib_signup_option' );
399 $is_confirm_email = 'yes' == $signup_settings['is_confirm_email'] ? 1 : 0;
400 $is_double_optin = 'yes' == $signup_settings['is_double_optin'] ? 1 : 0;
401 $redirect_url = $signup_settings['redirect_url'];
402 $redirect_url_click = $signup_settings['redirect_url_click'];
403 $template_id = 1 == $is_confirm_email ? $signup_settings['template_id'] : $signup_settings['doubleoptin_template_id'];
404
405 $confirmMsg = get_option( 'sib_confirm_option' );
406
407 $homeSetting = get_option( 'sib_home_option' );
408 $sib_list = maybe_serialize( array( (string) $homeSetting['list_id'] ) );
409
410 $formData = array(
411 'title' => 'Old Form',
412 'html' => $html,
413 'css' => '',
414 'dependTheme' => '1',
415 'listID' => $sib_list,
416 'templateID' => $template_id,
417 'isOpt' => $is_confirm_email,
418 'isDopt' => $is_double_optin,
419 'redirectInEmail' => $redirect_url,
420 'redirectInForm' => $redirect_url_click,
421 'successMsg' => $confirmMsg['alert_success_message'],
422 'errorMsg' => $confirmMsg['alert_error_message'],
423 'existMsg' => $confirmMsg['alert_exist_subscriber'],
424 'invalidMsg' => $confirmMsg['alert_invalid_email'],
425 'attributes' => 'email,' . implode( ',', $avail_atts ),
426 );
427
428 return $formData;
429 }
430
431 /** Add prefix to the table */
432 public static function add_prefix() {
433 global $wpdb;
434 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . self::TABLE_NAME . "'" ) == self::TABLE_NAME ) {
435 $query = 'ALTER TABLE ' . self::TABLE_NAME . ' RENAME TO ' . $wpdb->prefix . self::TABLE_NAME . ';';
436 $wpdb->query( $query ); // db call ok; no-cache ok.
437 }
438 }
439
440 }
441 }
442