PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / trunk
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid vtrunk
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Models / Field.php
the-post-grid / app / Models Last commit date
Field.php 9 months ago ReSizer.php 2 years ago
Field.php
795 lines
1 <?php
2 /**
3 * Fields class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Models;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGrid\Helpers\Options;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Fields class.
20 */
21 class Field {
22 private $type;
23 private $name;
24 private $value;
25 private $default;
26 private $label;
27 private $id;
28 private $parent_class;
29 private $class;
30 private $holderClass = '';
31 private $description;
32 private $descriptionAdv;
33 private $options;
34 private $option;
35 private $optionLabel;
36 private $attr;
37 private $multiple;
38 private $alignment;
39 private $placeholder;
40 private $blank;
41 private $icon;
42
43 function __construct() {
44 }
45
46 private function setArgument( $key, $attr ) {
47 global $pagenow;
48
49 $this->type = isset( $attr['type'] ) ? ( $attr['type'] ? $attr['type'] : 'text' ) : 'text';
50 $this->multiple = isset( $attr['multiple'] ) ? ( $attr['multiple'] ? $attr['multiple'] : false ) : false;
51 $this->name = ! empty( $key ) ? $key : null;
52 $id = isset( $attr['id'] ) ? $attr['id'] : null;
53 $this->id = ! empty( $id ) ? $id : $this->name;
54 $this->default = isset( $attr['default'] ) ? $attr['default'] : null;
55 $this->value = isset( $attr['value'] ) ? ( $attr['value'] ? $attr['value'] : null ) : null;
56 $this->icon = isset( $attr['icon'] ) ? ( $attr['icon'] ? $attr['icon'] : [] ) : [];
57
58 if ( ! $this->value ) {
59 $post_id = get_the_ID();
60
61 if ( ! Fns::meta_exist( $this->name, $post_id ) && $pagenow == 'post-new.php' ) {
62 $this->value = $this->default;
63 } elseif ( $this->multiple ) {
64 if ( metadata_exists( 'post', $post_id, $this->name ) ) {
65 $this->value = get_post_meta( $post_id, $this->name );
66 } else {
67 $this->value = $this->default;
68 }
69 } elseif ( metadata_exists( 'post', $post_id, $this->name ) ) {
70 $this->value = get_post_meta( $post_id, $this->name, true );
71 } else {
72 $this->value = $this->default;
73 }
74 }
75
76 $this->label = isset( $attr['label'] ) ? ( $attr['label'] ? $attr['label'] : null ) : null;
77 $this->parent_class = isset( $attr['parent_class'] ) ? ( $attr['parent_class'] ? $attr['parent_class'] : '' ) : '';
78 $this->class = isset( $attr['class'] ) ? ( $attr['class'] ? $attr['class'] : null ) : null;
79 $this->holderClass = isset( $attr['holderClass'] ) ? ( $attr['holderClass'] ? $attr['holderClass'] : '' ) : '';
80 $this->placeholder = isset( $attr['placeholder'] ) ? ( $attr['placeholder'] ? $attr['placeholder'] : null ) : null;
81 $this->description = isset( $attr['description'] ) ? ( $attr['description'] ? $attr['description'] : null ) : null;
82 $this->descriptionAdv = isset( $attr['description_adv'] ) ? ( $attr['description_adv'] ? $attr['description_adv'] : null ) : null;
83 $this->options = isset( $attr['options'] ) ? ( $attr['options'] ? $attr['options'] : [] ) : [];
84 $this->option = isset( $attr['option'] ) ? ( $attr['option'] ? $attr['option'] : null ) : null;
85 $this->optionLabel = isset( $attr['optionLabel'] ) ? ( $attr['optionLabel'] ? $attr['optionLabel'] : null ) : null;
86 $this->attr = isset( $attr['attr'] ) ? ( $attr['attr'] ? $attr['attr'] : null ) : null;
87 $this->alignment = isset( $attr['alignment'] ) ? ( $attr['alignment'] ? $attr['alignment'] : null ) : null;
88 $this->blank = ! empty( $attr['blank'] ) ? $attr['blank'] : null;
89 }
90
91 private function getIcon( $icon ) {
92 if ( ! is_array( $icon ) || ! $icon ) {
93 return;
94 }
95 $icon_name = $icon['name'] ?? 'info';
96 $size = $icon['size'] ?? '16';
97 $color = $icon['color'] ?? '';
98
99 switch ( $icon_name ) {
100 case 'info':
101 $color = $color ?: '#2196f2';
102
103 return '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="' . $size . '" height="' . $size . '" x="0" y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512" xml:space="preserve" class=""><g><g data-name="Layer 2"><circle cx="12" cy="12" r="10" fill="' . $color . '" opacity="1" data-original="' . $color . '" class=""></circle><g fill="#fff"><circle cx="12" cy="7.38" r="1.25" fill="#ffffff" opacity="1" data-original="#ffffff"></circle><path d="M12 17.88a1 1 0 0 1-1-1v-5a1 1 0 0 1 0-2h1a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1z" fill="#ffffff" opacity="1" data-original="#ffffff"></path><path d="M13 17.88h-2a1 1 0 0 1 0-2h2a1 1 0 1 1 0 2z" fill="#ffffff" opacity="1" data-original="#ffffff"></path></g></g></g></svg>';
104 case 'notice':
105 $color = $color ?: '#000000';
106
107 return '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="' . $size . '" height="' . $size . '" x="0" y="0" viewBox="0 0 485.811 485.811" style="enable-background:new 0 0 512 512" xml:space="preserve" class=""><g><path d="m476.099 353.968-170.2-294.8c-27.8-48.7-98.1-48.7-125.8 0l-170.3 294.8c-27.8 48.7 6.8 109.2 62.9 109.2h339.9c56.1 0 91.3-61.1 63.5-109.2zm-233.2 43.8c-14.8 0-27.1-12.3-27.1-27.1s12.3-27.1 27.1-27.1 27.1 12.3 26.5 27.8c.7 14.1-12.3 26.4-26.5 26.4zm24.7-175.2c-1.2 21-2.5 41.9-3.7 62.9-.6 6.8-.6 13-.6 19.7-.6 11.1-9.3 19.7-20.4 19.7s-19.7-8-20.4-19.1c-1.8-32.7-3.7-64.8-5.5-97.5-.6-8.6-1.2-17.3-1.9-25.9 0-14.2 8-25.9 21-29.6 13-3.1 25.9 3.1 31.5 15.4 1.9 4.3 2.5 8.6 2.5 13.6-.6 13.7-1.9 27.3-2.5 40.8z" fill="' . $color . '" opacity="1" data-original="' . $color . '" class=""></path></g></svg>';
108 }
109 }
110
111 public function Field( $key, $attr = [] ) {
112 $this->setArgument( $key, $attr );
113 $holderId = $this->name . '_holder';
114
115 if ( ! rtTPG()->hasPro() ) {
116 $class = $this->holderClass;
117 } else {
118 $class = str_replace( 'pro-field', '', $this->holderClass );
119 }
120
121 $html = null;
122
123 if ( $this->type == 'hr' ) {
124 return "<hr/>";
125 }
126
127 if ( $this->parent_class ) {
128 $class .= ' ' . $this->parent_class;
129 }
130
131 $html .= '<div class="field-holder ' . esc_attr( $class ) . '" id="' . esc_attr( $holderId ) . '">';
132
133 $holderClass = explode( ' ', $this->holderClass );
134
135 if ( $this->label ) {
136 $html .= "<div class='field-label'>";
137 $html .= '<label>' . self::getIcon( $this->icon ) . Fns::htmlKses( $this->label, 'basic' ) . '</label>';
138
139 if ( in_array( 'pro-field', $holderClass, true ) && ! rtTPG()->hasPro() ) {
140 $html .= '<span class="rttpg-tooltip">Pro<span class="rttpg-tooltip-text">' . esc_html__( 'Premium Option', 'the-post-grid' ) . '</span></span>';
141 }
142
143 $html .= '</div>';
144 }
145
146 $html .= "<div class='field'>";
147
148 switch ( $this->type ) {
149 case 'text':
150 $html .= $this->text();
151 break;
152
153 case 'url':
154 $html .= $this->url();
155 break;
156
157 case 'number':
158 $html .= $this->number();
159 break;
160
161 case 'select':
162 $html .= $this->select();
163 break;
164
165 case 'textarea':
166 $html .= $this->textArea();
167 break;
168
169 case 'checkbox':
170 $html .= $this->checkbox();
171 break;
172
173 case 'switch':
174 $html .= $this->switchField();
175 break;
176
177 case 'checkboxFilter':
178 $html .= $this->checkboxFilter();
179 break;
180
181 case 'radio':
182 $html .= $this->radioField();
183 break;
184
185 case 'radio-image':
186 $html .= $this->radioImage();
187 break;
188
189 case 'date_range':
190 $html .= $this->dateRange();
191 break;
192
193 case 'script':
194 $html .= $this->script();
195 break;
196
197 case 'image':
198 $html .= $this->image();
199 break;
200
201 case 'image_size':
202 $html .= $this->imageSize();
203 break;
204 }
205
206 if ( $this->description ) {
207 $html .= '<p class="description">' . Fns::htmlKses( $this->description, 'basic' ) . '</p>';
208 }
209
210 if ( $this->descriptionAdv ) {
211 $html .= '<p class="description">' . Fns::htmlKses( $this->descriptionAdv, 'advanced' ) . '</p>';
212 }
213
214 $html .= '</div>'; // field.
215 $html .= '</div>'; // field holder.
216
217 return $html;
218 }
219
220
221 private function text() {
222 $holderClass = explode( ' ', $this->holderClass );
223
224 $h = null;
225 $h .= '<input
226 type="text"
227 class="' . esc_attr( $this->class ) . '"
228 id="' . esc_attr( $this->id ) . '"
229 value="' . esc_attr( $this->value ) . '"
230 name="' . esc_attr( $this->name ) . '"
231 placeholder="' . esc_attr( $this->placeholder ) . '"
232 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
233 />';
234
235 return $h;
236 }
237
238 private function script() {
239 $type = 'script';
240
241 if ( $this->id == 'custom-css' ) {
242 $type = 'css';
243 }
244
245 $h = null;
246 $h .= '<div class="rt-script-wrapper" data-type="' . esc_attr( $type ) . '">';
247 $h .= '<div class="rt-script-container">';
248 $h .= "<div name='" . esc_attr( $this->name ) . "' id='ret-" . absint( wp_rand() ) . "' class='rt-script'>";
249 $h .= '</div>';
250 $h .= '</div>';
251
252 $h .= '<textarea
253 style="display: none;"
254 class="rt-script-textarea"
255 id="' . esc_attr( $this->id ) . '"
256 name="' . esc_attr( $this->name ) . '"
257 >' . wp_strip_all_tags( $this->value ) . '</textarea>';
258 $h .= '</div>';
259
260 return $h;
261 }
262
263 private function url() {
264 $h = null;
265 $h .= '<input
266 type="url"
267 class="' . esc_attr( $this->class ) . '"
268 id="' . esc_attr( $this->id ) . '"
269 value="' . esc_url( $this->value ) . '"
270 name="' . esc_attr( $this->name ) . '"
271 placeholder="' . esc_attr( $this->placeholder ) . '"
272 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
273 />';
274
275 return $h;
276 }
277
278 private function number() {
279 $holderClass = explode( ' ', $this->holderClass );
280
281 $h = null;
282 $h .= '<input
283 type="number"
284 class="' . esc_attr( $this->class ) . '"
285 id="' . esc_attr( $this->id ) . '"
286 value="' . ( ! empty( $this->value ) ? esc_html( $this->value ) : null ) . '"
287 name="' . esc_attr( $this->name ) . '"
288 placeholder="' . esc_attr( $this->placeholder ) . '"
289 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
290 />';
291
292 return $h;
293 }
294
295 private function select() {
296 $holderClass = explode( ' ', $this->holderClass );
297 $atts = ( in_array( 'pro-field', $holderClass, true ) ) && ! rtTPG()->hasPro() ? 'disabled="true"' : '';
298 $h = null;
299
300 if ( $this->multiple ) {
301 $this->attr = " style='min-width:160px;'";
302 $this->name = $this->name . '[]';
303 $this->attr = $this->attr . " multiple='multiple'";
304 $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : [] );
305 } else {
306 $this->value = [ $this->value ];
307 }
308
309 $h .= '<select ' . $atts . ' name="' . esc_attr( $this->name ) . '" id="' . esc_attr( $this->id ) . '" class="' . esc_attr( $this->class ) . '" ' . Fns::htmlKses( $this->attr, 'basic' ) . '>';
310
311 if ( $this->blank ) {
312 $h .= '<option value="">' . esc_html( $this->blank ) . '</option>';
313 }
314
315 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
316 foreach ( $this->options as $key => $value ) {
317 $slt = ( in_array( $key, $this->value ) ? 'selected' : null );
318 $h .= '<option ' . esc_attr( $slt ) . ' value="' . esc_attr( $key ) . '">' . esc_html( $value ) . '</option>';
319 }
320 }
321
322 $h .= '</select>';
323
324 return $h;
325 }
326
327 private function textArea() {
328 $holderClass = explode( ' ', $this->holderClass );
329
330 $h = null;
331 $h .= '<textarea
332 class="' . esc_attr( $this->class ) . ' rt-textarea"
333 id="' . esc_attr( $this->id ) . '"
334 name="' . esc_attr( $this->name ) . '"
335 placeholder="' . esc_attr( $this->placeholder ) . '"
336 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
337 >' . wp_kses_post( $this->value ?? '' ) . '</textarea>';
338
339 return $h;
340 }
341
342 private function image() {
343 $holderClass = explode( ' ', $this->holderClass );
344
345 $h = null;
346 $img = null;
347
348 $h .= "<div class='rt-image-holder'>";
349 $h .= '<input type="hidden" name="' . esc_attr( $this->name ) . '" value="' . absint( $this->value ) . '" id="' . esc_attr( $this->id ) . '" class="hidden-image-id" />';
350 $c = 'hidden';
351
352 if ( $id = absint( $this->value ) ) {
353 $aImg = wp_get_attachment_image_src( $id, 'thumbnail' );
354 $img = '<img src="' . esc_url( $aImg[0] ) . '" >';
355 $c = null;
356 }
357
358 $h .= '<div class="rt-image-preview">' . Fns::htmlKses( $img, 'image' ) . '<span class="dashicons dashicons-plus-alt rtAddImage"></span><span class="dashicons dashicons-trash rtRemoveImage ' . esc_attr( $c ) . '"></span></div>';
359
360 $h .= '</div>';
361
362 return $h;
363 }
364
365 private function imageSize() {
366 $width = ( ! empty( $this->value[0] ) ? $this->value[0] : null );
367 $height = ( ! empty( $this->value[1] ) ? $this->value[1] : null );
368 $cropV = ( ! empty( $this->value[2] ) ? $this->value[2] : 'soft' );
369
370 $h = null;
371 $h .= "<div class='rt-image-size-holder'>";
372 $h .= "<div class='rt-image-size-width rt-image-size'>";
373 $h .= '<label>Width</label>';
374 $h .= '<input type="number" name="' . esc_attr( $this->name ) . '[]" value="' . absint( $width ) . '" />';
375 $h .= '</div>';
376 $h .= "<div class='rt-image-size-height rt-image-size'>";
377 $h .= '<label>Height</label>';
378 $h .= '<input type="number" name="' . esc_attr( $this->name ) . '[]" value="' . absint( $height ) . '" />';
379 $h .= '</div>';
380 $h .= "<div class='rt-image-size-crop rt-image-size'>";
381 $h .= '<label>Crop</label>';
382 $h .= '<select name="' . esc_attr( $this->name ) . '[]" class="rt-select2">';
383
384 $cropList = Options::imageCropType();
385
386 foreach ( $cropList as $crop => $cropLabel ) {
387 $cSl = ( $crop == $cropV ? 'selected' : null );
388 $h .= '<option value="' . esc_attr( $crop ) . '" ' . esc_attr( $cSl ) . '>' . esc_html( $cropLabel ) . '</option>';
389 }
390
391 $h .= '</select>';
392 $h .= '</div>';
393 $h .= '</div>';
394
395 return $h;
396 }
397
398 private function checkbox() {
399 $holderClass = explode( ' ', $this->holderClass );
400 $this->alignment .= ( in_array( 'pro-field', $holderClass, true ) ) && ! rtTPG()->hasPro() ? ' disabled' : '';
401 $h = null;
402
403 if ( $this->multiple ) {
404 $this->name = $this->name . '[]';
405 $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : [] );
406 }
407
408 if ( $this->multiple ) {
409 $h .= '<div class="checkbox-group ' . esc_attr( $this->alignment ) . '" id="' . esc_attr( $this->id ) . '">';
410
411 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
412 foreach ( $this->options as $key => $value ) {
413 $checked = ( in_array( $key, $this->value ) ? 'checked' : null );
414
415 $h .= '<label for="' . esc_attr( $this->id ) . '-' . esc_attr( $key ) . '"><input type="checkbox" id="' . esc_attr( $this->id ) . '-' . esc_attr( $key ) . '" ' . esc_attr( $checked ) . ' name="' . esc_attr( $this->name ) . '" value="' . esc_attr( $key ) . '">' . esc_html( $value ) . '</label>';
416 }
417 }
418
419 $h .= '</div>';
420 } else {
421 $checked = ( $this->value ? 'checked' : null );
422 $h .= '<label><input type="checkbox" ' . esc_attr( $checked ) . ' id="' . esc_attr( $this->id ) . '" name="' . esc_attr( $this->name ) . '" value="1" />' . esc_html( $this->option ) . '</label>';
423 }
424
425 return $h;
426 }
427
428 private function switchField() {
429 $h = null;
430 $checked = $this->value ? 'checked' : null;
431 $h .= '<label class="rttm-switch"><input type="checkbox" ' . esc_attr( $checked ) . ' id="' . esc_attr( $this->id ) . '" name="' . esc_attr( $this->name ) . '" value="1" /><span class="rttm-switch-slider round"></span></label>';
432
433 return $h;
434 }
435
436 private function checkboxFilter() {
437 global $post;
438
439 $pt = get_post_meta( $post->ID, 'tpg_post_type', true );
440 $advFilters = Options::rtTPAdvanceFilters();
441 $holderClass = explode( ' ', $this->holderClass );
442 $h = null;
443
444 if ( $this->multiple ) {
445 $this->name = $this->name . '[]';
446 $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : [] );
447 }
448
449 if ( $this->multiple ) {
450 $h .= '<div class="checkbox-group ' . esc_attr( $this->alignment ) . '" id="' . esc_attr( $this->id ) . '">';
451
452 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
453 foreach ( $this->options as $key => $value ) {
454 $checked = ( in_array( $key, $this->value ) ? 'checked' : null );
455
456 $h .= '<div class="checkbox-filter-field">';
457 $h .= '<label for="' . esc_attr( $this->id ) . '-' . esc_attr( $key ) . '"><input type="checkbox" id="' . esc_attr( $this->id ) . '-' . esc_attr( $key ) . '" ' . esc_attr( $checked ) . ' name="' . esc_attr( $this->name ) . '" value="' . esc_attr( $key ) . '">' . esc_html( $value ) . '</label>';
458
459 if ( $key == 'tpg_taxonomy' ) {
460 $h .= "<div class='rt-tpg-filter taxonomy tpg_taxonomy tpg-hidden'>";
461
462 if ( isset( $pt ) && $pt ) {
463 $taxonomies = Fns::rt_get_all_taxonomy_by_post_type( $pt );
464 $taxA = get_post_meta( $post->ID, 'tpg_taxonomy' );
465 $post_filter = get_post_meta( $post->ID, 'post_filter' );
466
467 $h .= "<div class='taxonomy-field'>";
468
469 if ( is_array( $post_filter ) && ! empty( $post_filter ) && in_array( 'tpg_taxonomy', $post_filter ) && ! empty( $taxonomies ) ) {
470 $h .= Fns::rtFieldGenerator(
471 [
472 'tpg_taxonomy' => [
473 'type' => 'checkbox',
474 'label' => '',
475 'id' => 'post-taxonomy',
476 'multiple' => true,
477 'options' => $taxonomies,
478 ],
479 ]
480 );
481 } else {
482 $h .= '<div class="field-holder">' . esc_html__( 'No Taxonomy found', 'the-post-grid' ) . '</div>';
483 }
484
485 $h .= '</div>';
486 $h .= "<div class='rt-tpg-filter-item term-filter-item tpg-hidden'>";
487 $h .= '<div class="field-holder">';
488 $h .= '<div class="field-label">Terms</div>';
489 $h .= '<div class="field term-filter-holder">';
490
491 if ( is_array( $taxA ) && ! empty( $taxA ) ) {
492 foreach ( $taxA as $tax ) {
493
494 $h .= '<div class="term-filter-item-container ' . esc_attr( $tax ) . '">';
495 $h .= Fns::rtFieldGenerator(
496 [
497 'term_' . $tax => [
498 'type' => 'select',
499 'label' => ucfirst( str_replace( '_', ' ', $tax ) ),
500 'class' => 'rt-select2 full',
501 'holderClass' => "term-filter-item {$tax}",
502 'value' => get_post_meta( $post->ID, 'term_' . $tax ),
503 'multiple' => true,
504 'options' => Fns::rt_get_all_term_by_taxonomy( $tax ),
505 ],
506 ]
507 );
508 $h .= Fns::rtFieldGenerator(
509 [
510 'term_operator_' . $tax => [
511 'type' => 'select',
512 'label' => esc_html__( 'Operator', 'the-post-grid' ),
513 'class' => 'rt-select2 full',
514 'holderClass' => "term-filter-item-operator {$tax}",
515 'value' => get_post_meta( $post->ID, 'term_operator_' . $tax, true ),
516 'options' => Options::rtTermOperators(),
517 ],
518 ]
519 );
520 $h .= '</div>';
521 }
522 }
523
524 $h .= '</div>';
525 $h .= '</div>';
526
527 $h .= Fns::rtFieldGenerator(
528 [
529 'taxonomy_relation' => [
530 'type' => 'select',
531 'label' => esc_html__( 'Relation', 'the-post-grid' ),
532 'class' => 'rt-select2',
533 'holderClass' => 'term-filter-item-relation ' . ( count( $taxA ) > 1 ? null : 'hidden' ),
534 'value' => get_post_meta( $post->ID, 'taxonomy_relation', true ),
535 'options' => Options::rtTermRelations(),
536 ],
537 ]
538 );
539
540 $h .= '</div>';
541 } else {
542 $h .= "<div class='taxonomy-field'>";
543 $h .= '</div>';
544 $h .= "<div class='rt-tpg-filter-item'>";
545 $h .= '<div class="field-holder">';
546 $h .= '<div class="field-label">Terms</div>';
547 $h .= '<div class="field term-filter-holder">';
548 $h .= '</div>';
549 $h .= '</div>';
550 $h .= '</div>';
551 $h .= Fns::rtFieldGenerator(
552 [
553 'taxonomy_relation' => [
554 'type' => 'select',
555 'label' => esc_html__( 'Relation', 'the-post-grid' ),
556 'class' => 'rt-select2',
557 'holderClass' => 'term-filter-item-relation tpg-hidden',
558 'default' => 'OR',
559 'options' => Options::rtTermRelations(),
560 ],
561 ]
562 );
563 }
564
565 $h .= '</div>';
566 } elseif ( $key == 'order' ) {
567 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
568 $h .= "<div class='rt-tpg-filter-item'>";
569 $h .= "<div class='field-holder'>";
570 $h .= "<div class='field'>";
571 $h .= Fns::rtFieldGenerator(
572 [
573 'order_by' => [
574 'type' => 'select',
575 'label' => esc_html__( 'Order by', 'the-post-grid' ),
576 'class' => 'rt-select2 filter-item',
577 'value' => get_post_meta( $post->ID, 'order_by', true ),
578 'options' => Options::rtPostOrderBy( false, true ),
579 'description' => esc_html__( 'If "Meta value", "Meta value Number" or "Meta value datetime" is chosen then meta key is required.', 'the-post-grid' ),
580 ],
581 ]
582 );
583 $h .= Fns::rtFieldGenerator(
584 [
585 'tpg_meta_key' => [
586 'type' => 'text',
587 'label' => esc_html__( 'Meta key', 'the-post-grid' ),
588 'class' => 'rt-select2 filter-item',
589 'holderClass' => 'tpg-hidden',
590 'value' => get_post_meta( $post->ID, 'tpg_meta_key', true ),
591 ],
592 ]
593 );
594 $h .= Fns::rtFieldGenerator(
595 [
596 'order' => [
597 'type' => 'radio',
598 'label' => esc_html__( 'Order', 'the-post-grid' ),
599 'class' => 'rt-select2 filter-item',
600 'alignment' => 'vertical',
601 'default' => 'DESC',
602 'value' => get_post_meta( $post->ID, 'order', true ),
603 'options' => Options::rtPostOrders(),
604 ],
605 ]
606 );
607 $h .= '</div>';
608 $h .= '</div>';
609 $h .= '</div>';
610 $h .= '</div>';
611 } elseif ( $key == 'author' ) {
612 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
613 $h .= "<div class='rt-tpg-filter-item'>";
614 $h .= Fns::rtFieldGenerator(
615 [
616 $key => [
617 'type' => 'select',
618 'label' => '',
619 'class' => 'rt-select2 filter-item full',
620 'value' => get_post_meta( $post->ID, $key ),
621 'multiple' => true,
622 'options' => Fns::rt_get_users(),
623 ],
624 ]
625 );
626 $h .= '</div>';
627 $h .= '</div>';
628 } elseif ( $key == 's' ) {
629 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
630 $h .= "<div class='rt-tpg-filter-item'>";
631 $h .= Fns::rtFieldGenerator(
632 [
633 $key => [
634 'type' => 'text',
635 'label' => esc_html__( 'Keyword', 'the-post-grid' ),
636 'class' => 'filter-item full',
637 'value' => get_post_meta( $post->ID, $key, true ),
638 ],
639 ]
640 );
641 $h .= '</div>';
642 $h .= '</div>';
643 } elseif ( $key == 'date_range' ) {
644 $range_start = get_post_meta( $post->ID, 'date_range_start', true );
645 $range_end = get_post_meta( $post->ID, 'date_range_end', true );
646 $range_value = [
647 'start' => $range_start,
648 'end' => $range_end,
649 ];
650 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
651 $h .= "<div class='rt-tpg-filter-item'>";
652 $h .= Fns::rtFieldGenerator(
653 [
654 $key => [
655 'type' => 'date_range',
656 'label' => '',
657 'class' => 'filter-item full rt-date-range',
658 'value' => $range_value,
659 'description' => "Date format should be 'yyyy-mm-dd'",
660 ],
661 ]
662 );
663 $h .= '</div>';
664 $h .= '</div>';
665 }
666 /* Post status has removed
667 * elseif ( $key == 'tpg_post_status' ) {
668 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
669 $h .= "<div class='rt-tpg-filter-item'>";
670 $h .= Fns::rtFieldGenerator(
671 array(
672 $key => array(
673 'type' => 'select',
674 'label' => '',
675 'class' => 'rt-select2 filter-item full',
676 'default' => array( 'publish' ),
677 'value' => get_post_meta( $post->ID, $key ),
678 'multiple' => true,
679 'options' => Options::rtTPGPostStatus(),
680 ),
681 )
682 );
683 $h .= '</div>';
684 $h .= '</div>';
685 }*/
686 // }
687
688 $h .= '</div>';
689 }
690 }
691 $h .= '</div>';
692 } else {
693 $checked = ( $this->value ? 'checked' : null );
694 $h .= '<label><input type="checkbox" ' . esc_attr( $checked ) . ' id="' . esc_attr( $this->id ) . '" name="' . esc_attr( $this->name ) . '" value="1" />' . esc_html( $this->option ) . '</label>';
695 }
696
697 return $h;
698 }
699
700 private function radioField() {
701 $holderClass = explode( ' ', $this->holderClass );
702 $this->alignment .= ( in_array( 'pro-field', $holderClass, true ) ) && ! rtTPG()->hasPro() ? ' disabled' : '';
703 $h = null;
704
705 $h .= '<div class="radio-group ' . esc_attr( $this->alignment ) . '" id="' . esc_attr( $this->id ) . '">';
706
707 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
708 foreach ( $this->options as $key => $value ) {
709 $checked = ( $key == $this->value ? 'checked' : null );
710
711 $h .= '<label for="' . esc_attr( $this->name ) . '-' . esc_attr( $key ) . '"><input type="radio" id="' . esc_attr( $this->id ) . '-' . esc_attr( $key ) . '" ' . esc_attr( $checked ) . ' name="' . esc_attr( $this->name ) . '" value="' . esc_attr( $key ) . '">' . esc_html( $value ) . '</label>';
712 }
713 }
714
715 $h .= '</div>';
716
717 return $h;
718 }
719
720 /**
721 * Radio Image
722 *
723 * @return String
724 */
725 private function radioImage() {
726 $h = null;
727 $id = 'rttpg-' . $this->name;
728
729 $h .= sprintf( "<div class='rttpg-radio-image %s' id='%s'>", esc_attr( $this->alignment ), esc_attr( $id ) );
730 $selected_value = $this->value;
731
732 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
733 foreach ( $this->options as $key => $value ) {
734 $checked = ( $key == $selected_value ? 'checked' : null );
735 $title = isset( $value['title'] ) && $value['title'] ? $value['title'] : '';
736 $link = isset( $value['layout_link'] ) && $value['layout_link'] ? $value['layout_link'] : '';
737 $linkHtml = empty( $link ) ? esc_html( $title ) : '<a href="' . esc_url( $link ) . '" target="_blank">' . esc_html( $title ) . '</a>';
738 $layout = isset( $value['layout'] ) ? $value['layout'] : '';
739 $taghtml = isset( $value['tag'] ) ? '<div class="rt-tpg-layout-tag"><span>' . $value['tag'] . '</span></div>' : '';
740 $h .= sprintf(
741 '<div class="rt-tpg-radio-layout %7$s"><label data-type="%7$s" class="radio-image %7$s" for="%2$s">
742 <input type="radio" id="%2$s" %3$s name="%4$s" value="%2$s">
743 <div class="rttpg-radio-image-wrap">
744 <img src="%5$s" title="%6$s" alt="%2$s">
745 <div class="rttpg-checked"><span class="dashicons dashicons-yes"></span></div>
746 %9$s
747 </div>
748 </label>
749 <div class="rttpg-demo-name">%8$s</div>
750 </div>',
751 '',
752 esc_attr( $key ),
753 esc_attr( $checked ),
754 esc_attr( $this->name ),
755 esc_url( $value['img'] ),
756 esc_attr( $title ),
757 esc_attr( $layout ),
758 Fns::htmlKses( $linkHtml, 'basic' ),
759 Fns::htmlKses( $taghtml, 'basic' )
760 );
761 }
762 }
763 $h .= '</div>';
764
765 return $h;
766 }
767
768 private function dateRange() {
769 $h = null;
770 $this->name = ( $this->name ? $this->name : 'date-range-' . wp_rand( 0, 1000 ) );
771 $h .= '<div class="date-range-container" id="' . esc_attr( $this->id ) . '">';
772 $h .= "<div class='date-range-content start'><span>" . esc_html__( 'Start', 'the-post-grid' ) . "</span><input
773 type='text'
774 class='date-range date-range-start {$this->class}'
775 id='" . esc_attr( $this->id ) . "-start'
776 value='" . esc_attr( $this->value['start'] ) . "'
777 name='" . esc_attr( $this->name ) . "_start'
778 placeholder='" . esc_attr( $this->name ) . "'
779 " . Fns::htmlKses( $this->attr, 'basic' ) . '
780 /></div>';
781 $h .= "<div class='date-range-content end'><span>" . esc_html__( 'End', 'the-post-grid' ) . "</span><input
782 type='text'
783 class='date-range date-range-end {$this->class}'
784 id='" . esc_attr( $this->id ) . "-end'
785 value='" . esc_attr( $this->value['end'] ) . "'
786 name='" . esc_attr( $this->name ) . "_end'
787 placeholder='" . esc_attr( $this->name ) . "'
788 " . Fns::htmlKses( $this->attr, 'basic' ) . '
789 /></div>';
790 $h .= '</div>';
791
792 return $h;
793 }
794 }
795