PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.12
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.12
6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / includes / DbQueryUtils.php
kirki / includes Last commit date
API 2 weeks ago Admin 1 month ago Ajax 1 week ago ExportImport 2 weeks ago FormValidator 2 months ago Frontend 1 week ago Manager 2 weeks ago API.php 1 month ago Admin.php 2 months ago Ajax.php 1 week ago Apps.php 1 month ago ContentManager.php 2 months ago DbQueryUtils.php 1 month ago ElementVisibilityConditions.php 2 months ago Frontend.php 2 months ago HelperFunctions.php 1 week ago KirkiBase.php 2 months ago PostsQueryUtils.php 2 months ago Staging.php 2 months ago View.php 2 weeks ago
DbQueryUtils.php
212 lines
1 <?php
2 /**
3 * DbQueryUtils for form data management
4 *
5 * @package kirki
6 */
7
8 namespace Kirki;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * DbQueryUtils Class
16 */
17 class DbQueryUtils {
18
19 /**
20 * Find query builder
21 *
22 * @param string $column The name of the column.
23 * @param string $str which string needs to find.
24 * @return string
25 */
26 public static function contains( $column, $str ) {
27 global $wpdb;
28 $wild = '%';
29 $esc_str = $wpdb->esc_like( $str );
30 $like = $wild . $esc_str . $wild;
31 return $wpdb->prepare( '%1s LIKE %s', array( $column, $like ) );
32 }
33
34 /**
35 * Does_not_contain query builder
36 *
37 * @param string $column The name of the column.
38 * @param string $str which string needs to find.
39 * @return string
40 */
41 public static function does_not_contain( $column, $str ) {
42 global $wpdb;
43 $wild = '%';
44 $esc_str = $wpdb->esc_like( $str );
45 $like = $wild . $esc_str . $wild;
46 return $wpdb->prepare( '%1s NOT LIKE %s', array( $column, $like ) );
47 }
48
49 /**
50 * Start_with query builder
51 *
52 * @param string $column The name of the column.
53 * @param string $str which string needs to find.
54 * @return string
55 */
56 public static function start_with( $column, $str ) {
57 global $wpdb;
58 $wild = '%';
59 $esc_str = $wpdb->esc_like( $str );
60 $like = $esc_str . $wild;
61 return $wpdb->prepare( '%1s LIKE %s', array( $column, $like ) );
62 }
63
64 /**
65 * End_with query builder
66 *
67 * @param string $column The name of the column.
68 * @param string $str which string needs to find.
69 * @return string
70 */
71 public static function end_with( $column, $str ) {
72 global $wpdb;
73 $wild = '%';
74 $esc_str = $wpdb->esc_like( $str );
75 $like = $wild . $esc_str;
76 return $wpdb->prepare( '%1s LIKE %s', array( $column, $like ) );
77 }
78
79 /**
80 * Is query builder
81 *
82 * @param string $column The name of the column.
83 * @param string $str which string needs to find.
84 * @return string
85 */
86 public static function is( $column, $str ) {
87 global $wpdb;
88 $esc_str = $wpdb->esc_like( $str );
89 return $wpdb->prepare( '%1s LIKE %s', array( $column, $esc_str ) );
90 }
91
92 /**
93 * Is_not query builder
94 *
95 * @param string $column The name of the column.
96 * @param string $str which string needs to find.
97 * @return string
98 */
99 public static function is_not( $column, $str ) {
100 global $wpdb;
101 $esc_str = $wpdb->esc_like( $str );
102 return $wpdb->prepare( '%1s NOT LIKE %s', array( $column, $esc_str ) );
103 }
104
105 /**
106 * Cell_is_not_empty query builder
107 *
108 * @param string $column The name of the column.
109 * @return string
110 */
111 public static function cell_is_not_empty( $column ) {
112 global $wpdb;
113 return $wpdb->prepare( "%1s <> '' OR %1s <> NULL", array( $column, $column ) );
114 }
115
116 /**
117 * Cell_is_empty query builder
118 *
119 * @param string $column The name of the column.
120 * @return string
121 */
122 public static function cell_is_empty( $column ) {
123 global $wpdb;
124 return $wpdb->prepare( "%1s = '' OR %1s = NULL", array( $column, $column ) );
125 }
126
127 /**
128 * Today query builder
129 *
130 * @param string $column The name of the column.
131 * @return string
132 */
133 public static function today( $column ) {
134 global $wpdb;
135 return $wpdb->prepare( 'DATE(%1s) = %s', array( $column, gmdate( 'Y-m-d' ) ) );
136 }
137
138 /**
139 * This_week query builder
140 *
141 * @param string $column The name of the column.
142 * @return string
143 */
144 public static function this_week( $column ) {
145 global $wpdb;
146 return $wpdb->prepare( 'WEEK(%1s) = %d AND YEAR(%1s) = %d', array( $column, (int) gmdate( 'W' ), $column, (int) gmdate( 'Y' ) ) );
147 }
148
149 /**
150 * Last_month query builder
151 *
152 * @param string $column The name of the column.
153 * @return string
154 */
155 public static function last_month( $column ) {
156 global $wpdb;
157 return $wpdb->prepare( 'YEAR(%1s) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH) AND MONTH(%1s) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)', array( $column, $column ) );
158 }
159
160 /**
161 * Last_year query builder
162 *
163 * @param string $column The name of the column.
164 * @return string
165 */
166 public static function last_year( $column ) {
167 global $wpdb;
168 return $wpdb->prepare( 'YEAR(%1s) - 1 = %d', array( $column, (int) gmdate( 'Y' ) - 1 ) );
169 }
170
171 /**
172 * Between query builder
173 *
174 * @param string $column The name of the column.
175 * @param string $start start time.
176 * @param string $end end time.
177 * @return string
178 */
179 public static function between( $column, $start, $end ) {
180 global $wpdb;
181 $start_time = gmdate( 'Y-m-d', strtotime( $start ) );
182 $end_time = gmdate( 'Y-m-d', strtotime( $end ) );
183 return $wpdb->prepare( '%1s BETWEEN %s AND %s', array( $column, $start_time, $end_time ) );
184 }
185
186 /**
187 * Before query builder
188 *
189 * @param string $column The name of the column.
190 * @param string $date date.
191 * @return string
192 */
193 public static function before( $column, $date ) {
194 global $wpdb;
195 $date = gmdate( 'Y-m-d', strtotime( $date ) );
196 return $wpdb->prepare( 'DATE(%1s) < %s', array( $column, $date ) );
197 }
198
199 /**
200 * Start_with query builder
201 *
202 * @param string $column The name of the column.
203 * @param string $date date.
204 * @return string
205 */
206 public static function after( $column, $date ) {
207 global $wpdb;
208 $date = gmdate( 'Y-m-d', strtotime( $date ) );
209 return $wpdb->prepare( 'DATE(%1s) > %s', array( $column, $date ) );
210 }
211 }
212