PluginProbe ʕ •ᴥ•ʔ
Brevo – Email, SMS, Web Push, Chat, and more. / 3.0.9
Brevo – Email, SMS, Web Push, Chat, and more. v3.0.9
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-users.php
mailin / model Last commit date
index.php 11 years ago model-contacts.php 5 years ago model-forms.php 5 years ago model-lang.php 5 years ago model-users.php 5 years ago
model-users.php
236 lines
1 <?php
2 /**
3 * Model class <i>SIB_Model_Users</i> represents account
4 *
5 * @package SIB_Model
6 */
7 class SIB_Model_Users {
8
9 /**
10 * Tab table name
11 */
12 const TABLE_NAME = 'sib_model_users';
13
14 /**
15 * Holds found campaign count
16 *
17 * @var $found_count
18 */
19 static $found_count;
20
21 /**
22 * Holds all campaign count
23 *
24 * @var $all_count
25 */
26 static $all_count;
27
28 /** Create Table */
29 public static function createTable() {
30 global $wpdb;
31 // create list table.
32 $creation_query =
33 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . self::TABLE_NAME . ' (
34 `id` int(20) NOT NULL AUTO_INCREMENT,
35 `email` varchar(255),
36 `code` varchar(100),
37 `listIDs` longtext,
38 `redirectUrl` varchar(255),
39 `info` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci,
40 `frmid` int(2),
41 PRIMARY KEY (`id`)
42 );';
43 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
44 $wpdb->query($creation_query);
45 }
46
47 /**
48 * Remove table
49 */
50 public static function removeTable() {
51 global $wpdb;
52 $query = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . self::TABLE_NAME . ';';
53 $wpdb->query( $query ); // db call ok; no-cache ok.
54 }
55
56 /**
57 * Get data by id
58 *
59 * @param int $id - user id.
60 * @return bool|mixed
61 */
62 public static function get_data( $id ) {
63 global $wpdb;
64 $query = $wpdb->prepare("SELECT * from " . $wpdb->prefix . self::TABLE_NAME . " where id = %d",array(esc_sql($id)));
65 $results = $wpdb->get_results( $query, ARRAY_A ); // db call ok; no-cache ok.
66
67 if ( is_array( $results ) ) {
68 return $results[0];
69 } else {
70 return false;
71 }
72 }
73
74 /**
75 * Get data by code
76 *
77 * @param string $code - code.
78 * @return array|bool|null|object|void
79 */
80 public static function get_data_by_code( $code ) {
81 global $wpdb;
82 $query = $wpdb->prepare("SELECT * from " . $wpdb->prefix . self::TABLE_NAME . " where code like %s",array(esc_sql($code)));
83 $results = $wpdb->get_row( $query,ARRAY_A ); // db call ok; no-cache ok.
84
85 if ( is_array( $results ) && count( $results ) > 0 ) {
86 return $results;
87 } else {
88 return false;
89 }
90 }
91
92 /**
93 * Get code by email.
94 *
95 * @param string $email - email.
96 * @param int $formID - form ID.
97 * @return array|bool|null|object|void
98 */
99 public static function get_data_by_email( $email, $formID ) {
100 global $wpdb;
101 $query = $wpdb->prepare("SELECT * from " . $wpdb->prefix . self::TABLE_NAME . " where email = %s and frmid = %d",array(esc_sql($email),esc_sql($formID)));
102 $results = $wpdb->get_row( $query,ARRAY_A ); // db call ok; no-cache ok.
103
104 if ( is_array( $results ) && count( $results ) > 0 ) {
105 return $results;
106 } else {
107 return false;
108 }
109 }
110
111 /**
112 * Add record
113 *
114 * @param array $data - record data.
115 * @return null|string
116 */
117 public static function add_record( $data ) {
118 global $wpdb;
119
120 foreach ($data as $key => $value) {
121 if(!in_array($key, array("listIDs","info")))
122 $data[$key] = esc_sql($value);
123 }
124
125 $query = $wpdb->prepare('INSERT INTO ' . $wpdb->prefix . self::TABLE_NAME . ' (email,code,info,frmid,listIDs,redirectUrl) VALUES (%s, %s, %s, %d, %s, %s) ',array( $data["email"], $data["code"], $data["info"], $data["frmid"], $data["listIDs"], $data["redirectUrl"] ));
126 $wpdb->query( $query ); // db call ok; no-cache ok.
127 $index = $wpdb->get_var( 'SELECT LAST_INSERT_ID();' ); // db call ok; no-cache ok.
128
129 return $index;
130 }
131
132 /**
133 * Check email exist
134 *
135 * @param string $email - email.
136 * @param string $id - id.
137 * @return bool
138 */
139 public static function is_exist_same_email( $email, $id = '' ) {
140 global $wpdb;
141
142 $query = $wpdb->prepare("SELECT * from " . $wpdb->prefix . self::TABLE_NAME . " where email like %s",array(esc_sql($email)));
143 $results = $wpdb->get_results( $query, ARRAY_A ); // db call ok; no-cache ok.
144
145 if ( is_array( $results ) && (count( $results ) > 0) ) {
146 if ( '' === $id ) {
147 return true;
148 }
149 if ( isset( $results ) && is_array( $results ) ) {
150 foreach ( $results as $result ) {
151 if ( $result['id'] != $id ) {
152 return true;
153 }
154 }
155 }
156 }
157
158 return false;
159 }
160
161 /**
162 * Remove guest
163 *
164 * @param int $id - id.
165 */
166 public static function remove_record( $id ) {
167 global $wpdb;
168
169 $query = $wpdb->prepare("DELETE from " . $wpdb->prefix . self::TABLE_NAME . " where id = %d",array(esc_sql($id)));
170 $wpdb->query( $query ); // db call ok; no-cache ok.
171 }
172
173 /**
174 * Get all guests by pagenum, per_page
175 *
176 * @param string $orderby - ORDER BY.
177 * @param string $order - sort order.
178 * @param int $pagenum - page number.
179 * @param int $per_page - count per page.
180 * @return array|null|object
181 */
182 public static function get_all( $orderby = 'email', $order = 'asc', $pagenum = 1, $per_page = 15 ) {
183 global $wpdb;
184
185 $limit = ($pagenum - 1) * $per_page;
186 $query = 'SELECT * FROM ' . $wpdb->prefix . self::TABLE_NAME . ' ORDER BY %s %s LIMIT %d,%d';
187 $query = $wpdb->prepare($query,array(esc_sql($orderby), esc_sql($order), esc_sql($limit), esc_sql($per_page)));
188
189
190 $results = $wpdb->get_results( $query, ARRAY_A ); // db call ok; no-cache ok.
191 self::$found_count = self::get_count_element();
192
193 if ( ! is_array( $results ) ) {
194 $results = array();
195 return $results;
196 }
197
198 return $results;
199 }
200
201 /** Get all records of table */
202 public static function get_all_records() {
203 global $wpdb;
204
205 $query = $wpdb->prepare('select * from ' . $wpdb->prefix . self::TABLE_NAME . ' order by %s %s;', array("email","asc"));
206 $results = $wpdb->get_results( $query, ARRAY_A ); // db call ok; no-cache ok.
207
208 if ( ! is_array( $results ) ) {
209 $results = array();
210 return $results;
211 }
212
213 return $results;
214 }
215
216 /** Get count of row */
217 public static function get_count_element() {
218 global $wpdb;
219
220 $query = 'Select count(*) from ' . $wpdb->prefix . self::TABLE_NAME . ';';
221
222 $count = $wpdb->get_var( $query ); // db call ok; no-cache ok.
223
224 return $count;
225 }
226
227 /** Add prefix to the table */
228 public static function add_prefix() {
229 global $wpdb;
230 if ( $wpdb->get_var( "SHOW TABLES LIKE '" . self::TABLE_NAME . "'" ) == self::TABLE_NAME ) {
231 $query = 'ALTER TABLE ' . self::TABLE_NAME . ' RENAME TO ' . $wpdb->prefix . self::TABLE_NAME . ';';
232 $wpdb->query( $query ); // db call ok; no-cache ok.
233 }
234 }
235
236 }