PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.2
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 3 years ago ReSizer.php 3 years ago
Field.php
763 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 $class;
29 private $holderClass;
30 private $description;
31 private $descriptionAdv;
32 private $options;
33 private $option;
34 private $optionLabel;
35 private $attr;
36 private $multiple;
37 private $alignment;
38 private $placeholder;
39 private $blank;
40
41 function __construct() {
42 }
43
44 private function setArgument( $key, $attr ) {
45 global $pagenow;
46
47 $this->type = isset( $attr['type'] ) ? ( $attr['type'] ? $attr['type'] : 'text' ) : 'text';
48 $this->multiple = isset( $attr['multiple'] ) ? ( $attr['multiple'] ? $attr['multiple'] : false ) : false;
49 $this->name = ! empty( $key ) ? $key : null;
50 $id = isset( $attr['id'] ) ? $attr['id'] : null;
51 $this->id = ! empty( $id ) ? $id : $this->name;
52 $this->default = isset( $attr['default'] ) ? $attr['default'] : null;
53 $this->value = isset( $attr['value'] ) ? ( $attr['value'] ? $attr['value'] : null ) : null;
54
55 if ( ! $this->value ) {
56 $post_id = get_the_ID();
57
58 if ( ! Fns::meta_exist( $this->name, $post_id ) && $pagenow == 'post-new.php' ) {
59 $this->value = $this->default;
60 } else {
61 if ( $this->multiple ) {
62 if ( metadata_exists( 'post', $post_id, $this->name ) ) {
63 $this->value = get_post_meta( $post_id, $this->name );
64 } else {
65 $this->value = $this->default;
66 }
67 } else {
68 if ( metadata_exists( 'post', $post_id, $this->name ) ) {
69 $this->value = get_post_meta( $post_id, $this->name, true );
70 } else {
71 $this->value = $this->default;
72 }
73 }
74 }
75 }
76
77 $this->label = isset( $attr['label'] ) ? ( $attr['label'] ? $attr['label'] : null ) : null;
78 $this->class = isset( $attr['class'] ) ? ( $attr['class'] ? $attr['class'] : null ) : null;
79 $this->holderClass = isset( $attr['holderClass'] ) ? ( $attr['holderClass'] ? $attr['holderClass'] : null ) : null;
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
92 public function Field( $key, $attr = [] ) {
93 $this->setArgument( $key, $attr );
94 $holderId = $this->name . '_holder';
95
96 if ( ! rtTPG()->hasPro() ) {
97 $class = $this->holderClass;
98 } else {
99 $class = str_replace( 'pro-field', '', $this->holderClass );
100 }
101
102 $html = null;
103 $html .= '<div class="field-holder ' . esc_attr( $class ) . '" id="' . esc_attr( $holderId ) . '">';
104
105 $holderClass = explode( ' ', $this->holderClass );
106
107 if ( $this->label ) {
108 $html .= "<div class='field-label'>";
109 $html .= '<label>' . Fns::htmlKses( $this->label, 'basic' ) . '</label>';
110
111 if ( in_array( 'pro-field', $holderClass, true ) && ! rtTPG()->hasPro() ) {
112 $html .= '<span class="rttpg-tooltip">[Pro]<span class="rttpg-tooltip-text">' . esc_html__( 'Premium Option', 'the-post-grid' ) . '</span></span>';
113 }
114
115 $html .= '</div>';
116 }
117
118 $html .= "<div class='field'>";
119
120 switch ( $this->type ) {
121 case 'text':
122 $html .= $this->text();
123 break;
124
125 case 'url':
126 $html .= $this->url();
127 break;
128
129 case 'number':
130 $html .= $this->number();
131 break;
132
133 case 'select':
134 $html .= $this->select();
135 break;
136
137 case 'textarea':
138 $html .= $this->textArea();
139 break;
140
141 case 'checkbox':
142 $html .= $this->checkbox();
143 break;
144
145 case 'switch':
146 $html .= $this->switchField();
147 break;
148
149 case 'checkboxFilter':
150 $html .= $this->checkboxFilter();
151 break;
152
153 case 'radio':
154 $html .= $this->radioField();
155 break;
156
157 case 'radio-image':
158 $html .= $this->radioImage();
159 break;
160
161 case 'date_range':
162 $html .= $this->dateRange();
163 break;
164
165 case 'script':
166 $html .= $this->script();
167 break;
168
169 case 'image':
170 $html .= $this->image();
171 break;
172
173 case 'image_size':
174 $html .= $this->imageSize();
175 break;
176 }
177
178 if ( $this->description ) {
179 $html .= '<p class="description">' . Fns::htmlKses( $this->description, 'basic' ) . '</p>';
180 }
181
182 if ( $this->descriptionAdv ) {
183 $html .= '<p class="description">' . Fns::htmlKses( $this->descriptionAdv, 'advanced' ) . '</p>';
184 }
185
186 $html .= '</div>'; // field.
187 $html .= '</div>'; // field holder.
188
189 return $html;
190 }
191
192 private function text() {
193 $holderClass = explode( ' ', $this->holderClass );
194
195 $h = null;
196 $h .= '<input
197 type="text"
198 class="' . esc_attr( $this->class ) . '"
199 id="' . esc_attr( $this->id ) . '"
200 value="' . esc_attr( $this->value ) . '"
201 name="' . esc_attr( $this->name ) . '"
202 placeholder="' . esc_attr( $this->placeholder ) . '"
203 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
204 />';
205
206 return $h;
207 }
208
209 private function script() {
210 $type = 'script';
211
212 if ( $this->id == 'custom-css' ) {
213 $type = 'css';
214 }
215
216 $h = null;
217 $h .= '<div class="rt-script-wrapper" data-type="' . esc_attr( $type ) . '">';
218 $h .= '<div class="rt-script-container">';
219 $h .= "<div name='" . esc_attr( $this->name ) . "' id='ret-" . absint( wp_rand() ) . "' class='rt-script'>";
220 $h .= '</div>';
221 $h .= '</div>';
222
223 $h .= '<textarea
224 style="display: none;"
225 class="rt-script-textarea"
226 id="' . esc_attr( $this->id ) . '"
227 name="' . esc_attr( $this->name ) . '"
228 >' . wp_strip_all_tags( $this->value ) . '</textarea>';
229 $h .= '</div>';
230
231 return $h;
232 }
233
234 private function url() {
235 $h = null;
236 $h .= '<input
237 type="url"
238 class="' . esc_attr( $this->class ) . '"
239 id="' . esc_attr( $this->id ) . '"
240 value="' . esc_url( $this->value ) . '"
241 name="' . esc_attr( $this->name ) . '"
242 placeholder="' . esc_attr( $this->placeholder ) . '"
243 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
244 />';
245
246 return $h;
247 }
248
249 private function number() {
250 $holderClass = explode( ' ', $this->holderClass );
251
252 $h = null;
253 $h .= '<input
254 type="number"
255 class="' . esc_attr( $this->class ) . '"
256 id="' . esc_attr( $this->id ) . '"
257 value="' . ( ! empty( $this->value ) ? absint( $this->value ) : null ) . '"
258 name="' . esc_attr( $this->name ) . '"
259 placeholder="' . esc_attr( $this->placeholder ) . '"
260 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
261 />';
262
263 return $h;
264 }
265
266 private function select() {
267 $holderClass = explode( ' ', $this->holderClass );
268 $atts = ( in_array( 'pro-field', $holderClass, true ) ) && ! rtTPG()->hasPro() ? 'disabled="true"' : '';
269 $h = null;
270
271 if ( $this->multiple ) {
272 $this->attr = " style='min-width:160px;'";
273 $this->name = $this->name . '[]';
274 $this->attr = $this->attr . " multiple='multiple'";
275 $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : [] );
276 } else {
277 $this->value = [ $this->value ];
278 }
279
280 $h .= '<select ' . $atts . ' name="' . esc_attr( $this->name ) . '" id="' . esc_attr( $this->id ) . '" class="' . esc_attr( $this->class ) . '" ' . Fns::htmlKses( $this->attr, 'basic' ) . '>';
281
282 if ( $this->blank ) {
283 $h .= '<option value="">' . esc_html( $this->blank ) . '</option>';
284 }
285
286 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
287 foreach ( $this->options as $key => $value ) {
288 $slt = ( in_array( $key, $this->value ) ? 'selected' : null );
289 $h .= '<option ' . esc_attr( $slt ) . ' value="' . esc_attr( $key ) . '">' . esc_html( $value ) . '</option>';
290 }
291 }
292
293 $h .= '</select>';
294
295 return $h;
296 }
297
298 private function textArea() {
299 $holderClass = explode( ' ', $this->holderClass );
300
301 $h = null;
302 $h .= '<textarea
303 class="' . esc_attr( $this->class ) . ' rt-textarea"
304 id="' . esc_attr( $this->id ) . '"
305 name="' . esc_attr( $this->name ) . '"
306 placeholder="' . esc_attr( $this->placeholder ) . '"
307 ' . Fns::htmlKses( $this->attr, 'basic' ) . '
308 >' . wp_kses_post( $this->value ) . '</textarea>';
309
310 return $h;
311 }
312
313 private function image() {
314 $holderClass = explode( ' ', $this->holderClass );
315
316 $h = null;
317 $img = null;
318
319 $h .= "<div class='rt-image-holder'>";
320 $h .= '<input type="hidden" name="' . esc_attr( $this->name ) . '" value="' . absint( $this->value ) . '" id="' . esc_attr( $this->id ) . '" class="hidden-image-id" />';
321 $c = 'hidden';
322
323 if ( $id = absint( $this->value ) ) {
324 $aImg = wp_get_attachment_image_src( $id, 'thumbnail' );
325 $img = '<img src="' . esc_url( $aImg[0] ) . '" >';
326 $c = null;
327 }
328
329 $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>';
330
331 $h .= '</div>';
332
333 return $h;
334 }
335
336 private function imageSize() {
337 $width = ( ! empty( $this->value[0] ) ? $this->value[0] : null );
338 $height = ( ! empty( $this->value[1] ) ? $this->value[1] : null );
339 $cropV = ( ! empty( $this->value[2] ) ? $this->value[2] : 'soft' );
340
341 $h = null;
342 $h .= "<div class='rt-image-size-holder'>";
343 $h .= "<div class='rt-image-size-width rt-image-size'>";
344 $h .= '<label>Width</label>';
345 $h .= '<input type="number" name="' . esc_attr( $this->name ) . '[]" value="' . absint( $width ) . '" />';
346 $h .= '</div>';
347 $h .= "<div class='rt-image-size-height rt-image-size'>";
348 $h .= '<label>Height</label>';
349 $h .= '<input type="number" name="' . esc_attr( $this->name ) . '[]" value="' . absint( $height ) . '" />';
350 $h .= '</div>';
351 $h .= "<div class='rt-image-size-crop rt-image-size'>";
352 $h .= '<label>Crop</label>';
353 $h .= '<select name="' . esc_attr( $this->name ) . '[]" class="rt-select2">';
354
355 $cropList = Options::imageCropType();
356
357 foreach ( $cropList as $crop => $cropLabel ) {
358 $cSl = ( $crop == $cropV ? 'selected' : null );
359 $h .= '<option value="' . esc_attr( $crop ) . '" ' . esc_attr( $cSl ) . '>' . esc_html( $cropLabel ) . '</option>';
360 }
361
362 $h .= '</select>';
363 $h .= '</div>';
364 $h .= '</div>';
365
366 return $h;
367 }
368
369 private function checkbox() {
370 $holderClass = explode( ' ', $this->holderClass );
371 $this->alignment .= ( in_array( 'pro-field', $holderClass, true ) ) && ! rtTPG()->hasPro() ? ' disabled' : '';
372 $h = null;
373
374 if ( $this->multiple ) {
375 $this->name = $this->name . '[]';
376 $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : [] );
377 }
378
379 if ( $this->multiple ) {
380 $h .= '<div class="checkbox-group ' . esc_attr( $this->alignment ) . '" id="' . esc_attr( $this->id ) . '">';
381
382 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
383 foreach ( $this->options as $key => $value ) {
384 $checked = ( in_array( $key, $this->value ) ? 'checked' : null );
385
386 $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>';
387 }
388 }
389
390 $h .= '</div>';
391 } else {
392 $checked = ( $this->value ? 'checked' : null );
393 $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>';
394 }
395
396 return $h;
397 }
398
399 private function switchField() {
400 $h = null;
401 $checked = $this->value ? 'checked' : null;
402 $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>';
403
404 return $h;
405 }
406
407 private function checkboxFilter() {
408 global $post;
409
410 $pt = get_post_meta( $post->ID, 'tpg_post_type', true );
411 $advFilters = Options::rtTPAdvanceFilters();
412 $holderClass = explode( ' ', $this->holderClass );
413 $h = null;
414
415 if ( $this->multiple ) {
416 $this->name = $this->name . '[]';
417 $this->value = ( is_array( $this->value ) && ! empty( $this->value ) ? $this->value : [] );
418 }
419
420 if ( $this->multiple ) {
421 $h .= '<div class="checkbox-group ' . esc_attr( $this->alignment ) . '" id="' . esc_attr( $this->id ) . '">';
422
423 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
424 foreach ( $this->options as $key => $value ) {
425 $checked = ( in_array( $key, $this->value ) ? 'checked' : null );
426
427 $h .= '<div class="checkbox-filter-field">';
428 $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>';
429
430 if ( $key == 'tpg_taxonomy' ) {
431 $h .= "<div class='rt-tpg-filter taxonomy tpg_taxonomy tpg-hidden'>";
432
433 if ( isset( $pt ) && $pt ) {
434 $taxonomies = Fns::rt_get_all_taxonomy_by_post_type( $pt );
435 $taxA = get_post_meta( $post->ID, 'tpg_taxonomy' );
436 $post_filter = get_post_meta( $post->ID, 'post_filter' );
437
438 $h .= "<div class='taxonomy-field'>";
439
440 if ( is_array( $post_filter ) && ! empty( $post_filter ) && in_array( 'tpg_taxonomy', $post_filter ) && ! empty( $taxonomies ) ) {
441 $h .= Fns::rtFieldGenerator(
442 [
443 'tpg_taxonomy' => [
444 'type' => 'checkbox',
445 'label' => '',
446 'id' => 'post-taxonomy',
447 'multiple' => true,
448 'options' => $taxonomies,
449 ],
450 ]
451 );
452 } else {
453 $h .= '<div class="field-holder">' . esc_html__( 'No Taxonomy found', 'the-post-grid' ) . '</div>';
454 }
455
456 $h .= '</div>';
457 $h .= "<div class='rt-tpg-filter-item term-filter-item tpg-hidden'>";
458 $h .= '<div class="field-holder">';
459 $h .= '<div class="field-label">Terms</div>';
460 $h .= '<div class="field term-filter-holder">';
461
462 if ( is_array( $taxA ) && ! empty( $taxA ) ) {
463 foreach ( $taxA as $tax ) {
464
465 $h .= '<div class="term-filter-item-container ' . esc_attr( $tax ) . '">';
466 $h .= Fns::rtFieldGenerator(
467 [
468 'term_' . $tax => [
469 'type' => 'select',
470 'label' => ucfirst( str_replace( '_', ' ', $tax ) ),
471 'class' => 'rt-select2 full',
472 'holderClass' => "term-filter-item {$tax}",
473 'value' => get_post_meta( $post->ID, 'term_' . $tax ),
474 'multiple' => true,
475 'options' => Fns::rt_get_all_term_by_taxonomy( $tax ),
476 ],
477 ]
478 );
479 $h .= Fns::rtFieldGenerator(
480 [
481 'term_operator_' . $tax => [
482 'type' => 'select',
483 'label' => esc_html__( 'Operator', 'the-post-grid' ),
484 'class' => 'rt-select2 full',
485 'holderClass' => "term-filter-item-operator {$tax}",
486 'value' => get_post_meta( $post->ID, 'term_operator_' . $tax, true ),
487 'options' => Options::rtTermOperators(),
488 ],
489 ]
490 );
491 $h .= '</div>';
492 }
493 }
494
495 $h .= '</div>';
496 $h .= '</div>';
497
498 $h .= Fns::rtFieldGenerator(
499 [
500 'taxonomy_relation' => [
501 'type' => 'select',
502 'label' => esc_html__( 'Relation', 'the-post-grid' ),
503 'class' => 'rt-select2',
504 'holderClass' => 'term-filter-item-relation ' . ( count( $taxA ) > 1 ? null : 'hidden' ),
505 'value' => get_post_meta( $post->ID, 'taxonomy_relation', true ),
506 'options' => Options::rtTermRelations(),
507 ],
508 ]
509 );
510
511 $h .= '</div>';
512 } else {
513 $h .= "<div class='taxonomy-field'>";
514 $h .= '</div>';
515 $h .= "<div class='rt-tpg-filter-item'>";
516 $h .= '<div class="field-holder">';
517 $h .= '<div class="field-label">Terms</div>';
518 $h .= '<div class="field term-filter-holder">';
519 $h .= '</div>';
520 $h .= '</div>';
521 $h .= '</div>';
522 $h .= Fns::rtFieldGenerator(
523 [
524 'taxonomy_relation' => [
525 'type' => 'select',
526 'label' => esc_html__( 'Relation', 'the-post-grid' ),
527 'class' => 'rt-select2',
528 'holderClass' => 'term-filter-item-relation tpg-hidden',
529 'default' => 'OR',
530 'options' => Options::rtTermRelations(),
531 ],
532 ]
533 );
534 }
535
536 $h .= '</div>';
537 } elseif ( $key == 'order' ) {
538 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
539 $h .= "<div class='rt-tpg-filter-item'>";
540 $h .= "<div class='field-holder'>";
541 $h .= "<div class='field'>";
542 $h .= Fns::rtFieldGenerator(
543 [
544 'order_by' => [
545 'type' => 'select',
546 'label' => esc_html__( 'Order by', 'the-post-grid' ),
547 'class' => 'rt-select2 filter-item',
548 'value' => get_post_meta( $post->ID, 'order_by', true ),
549 'options' => Options::rtPostOrderBy( false, true ),
550 'description' => esc_html__( 'If "Meta value", "Meta value Number" or "Meta value datetime" is chosen then meta key is required.', 'the-post-grid' ),
551 ],
552 ]
553 );
554 $h .= Fns::rtFieldGenerator(
555 [
556 'tpg_meta_key' => [
557 'type' => 'text',
558 'label' => esc_html__( 'Meta key', 'the-post-grid' ),
559 'class' => 'rt-select2 filter-item',
560 'holderClass' => 'tpg-hidden',
561 'value' => get_post_meta( $post->ID, 'tpg_meta_key', true ),
562 ],
563 ]
564 );
565 $h .= Fns::rtFieldGenerator(
566 [
567 'order' => [
568 'type' => 'radio',
569 'label' => esc_html__( 'Order', 'the-post-grid' ),
570 'class' => 'rt-select2 filter-item',
571 'alignment' => 'vertical',
572 'default' => 'DESC',
573 'value' => get_post_meta( $post->ID, 'order', true ),
574 'options' => Options::rtPostOrders(),
575 ],
576 ]
577 );
578 $h .= '</div>';
579 $h .= '</div>';
580 $h .= '</div>';
581 $h .= '</div>';
582 } elseif ( $key == 'author' ) {
583 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
584 $h .= "<div class='rt-tpg-filter-item'>";
585 $h .= Fns::rtFieldGenerator(
586 [
587 $key => [
588 'type' => 'select',
589 'label' => '',
590 'class' => 'rt-select2 filter-item full',
591 'value' => get_post_meta( $post->ID, $key ),
592 'multiple' => true,
593 'options' => Fns::rt_get_users(),
594 ],
595 ]
596 );
597 $h .= '</div>';
598 $h .= '</div>';
599 } elseif ( $key == 'tpg_post_status' ) {
600 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
601 $h .= "<div class='rt-tpg-filter-item'>";
602 $h .= Fns::rtFieldGenerator(
603 [
604 $key => [
605 'type' => 'select',
606 'label' => '',
607 'class' => 'rt-select2 filter-item full',
608 'default' => [ 'publish' ],
609 'value' => get_post_meta( $post->ID, $key ),
610 'multiple' => true,
611 'options' => Options::rtTPGPostStatus(),
612 ],
613 ]
614 );
615 $h .= '</div>';
616 $h .= '</div>';
617 } elseif ( $key == 's' ) {
618 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
619 $h .= "<div class='rt-tpg-filter-item'>";
620 $h .= Fns::rtFieldGenerator(
621 [
622 $key => [
623 'type' => 'text',
624 'label' => esc_html__( 'Keyword', 'the-post-grid' ),
625 'class' => 'filter-item full',
626 'value' => get_post_meta( $post->ID, $key, true ),
627 ],
628 ]
629 );
630 $h .= '</div>';
631 $h .= '</div>';
632 } elseif ( $key == 'date_range' ) {
633 $range_start = get_post_meta( $post->ID, 'date_range_start', true );
634 $range_end = get_post_meta( $post->ID, 'date_range_end', true );
635 $range_value = [
636 'start' => $range_start,
637 'end' => $range_end,
638 ];
639 $h .= '<div class="rt-tpg-filter ' . esc_attr( $key ) . ' tpg-hidden">';
640 $h .= "<div class='rt-tpg-filter-item'>";
641 $h .= Fns::rtFieldGenerator(
642 [
643 $key => [
644 'type' => 'date_range',
645 'label' => '',
646 'class' => 'filter-item full rt-date-range',
647 'value' => $range_value,
648 'description' => "Date format should be 'yyyy-mm-dd'",
649 ],
650 ]
651 );
652 $h .= '</div>';
653 $h .= '</div>';
654 }
655 // }
656
657 $h .= '</div>';
658 }
659 }
660 $h .= '</div>';
661 } else {
662 $checked = ( $this->value ? 'checked' : null );
663 $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>';
664 }
665
666 return $h;
667 }
668
669 private function radioField() {
670 $holderClass = explode( ' ', $this->holderClass );
671 $this->alignment .= ( in_array( 'pro-field', $holderClass, true ) ) && ! rtTPG()->hasPro() ? ' disabled' : '';
672 $h = null;
673
674 $h .= '<div class="radio-group ' . esc_attr( $this->alignment ) . '" id="' . esc_attr( $this->id ) . '">';
675
676 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
677 foreach ( $this->options as $key => $value ) {
678 $checked = ( $key == $this->value ? 'checked' : null );
679
680 $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>';
681 }
682 }
683
684 $h .= '</div>';
685
686 return $h;
687 }
688
689 /**
690 * Radio Image
691 *
692 * @return String
693 */
694 private function radioImage() {
695 $h = null;
696 $id = 'rttpg-' . $this->name;
697
698 $h .= sprintf( "<div class='rttpg-radio-image %s' id='%s'>", esc_attr( $this->alignment ), esc_attr( $id ) );
699 $selected_value = $this->value;
700
701 if ( is_array( $this->options ) && ! empty( $this->options ) ) {
702 foreach ( $this->options as $key => $value ) {
703 $checked = ( $key == $selected_value ? 'checked' : null );
704 $title = isset( $value['title'] ) && $value['title'] ? $value['title'] : '';
705 $link = isset( $value['layout_link'] ) && $value['layout_link'] ? $value['layout_link'] : '';
706 $linkHtml = empty( $link ) ? esc_html( $title ) : '<a href="' . esc_url( $link ) . '" target="_blank">' . esc_html( $title ) . '</a>';
707 $layout = isset( $value['layout'] ) ? $value['layout'] : '';
708 $taghtml = isset( $value['tag'] ) ? '<div class="rt-tpg-layout-tag"><span>' . $value['tag'] . '</span></div>' : '';
709 $h .= sprintf(
710 '<div class="rt-tpg-radio-layout %7$s"><label data-type="%7$s" class="radio-image %7$s" for="%2$s">
711 <input type="radio" id="%2$s" %3$s name="%4$s" value="%2$s">
712 <div class="rttpg-radio-image-wrap">
713 <img src="%5$s" title="%6$s" alt="%2$s">
714 <div class="rttpg-checked"><span class="dashicons dashicons-yes"></span></div>
715 %9$s
716 </div>
717 </label>
718 <div class="rttpg-demo-name">%8$s</div>
719 </div>',
720 '',
721 esc_attr( $key ),
722 esc_attr( $checked ),
723 esc_attr( $this->name ),
724 esc_url( $value['img'] ),
725 esc_attr( $title ),
726 esc_attr( $layout ),
727 Fns::htmlKses( $linkHtml, 'basic' ),
728 Fns::htmlKses( $taghtml, 'basic' )
729 );
730 }
731 }
732 $h .= '</div>';
733 return $h;
734 }
735
736 private function dateRange() {
737 $h = null;
738 $this->name = ( $this->name ? $this->name : 'date-range-' . rand( 0, 1000 ) );
739 $h .= '<div class="date-range-container" id="' . esc_attr( $this->id ) . '">';
740 $h .= "<div class='date-range-content start'><span>" . esc_html__( 'Start', 'the-post-grid' ) . "</span><input
741 type='text'
742 class='date-range date-range-start {$this->class}'
743 id='" . esc_attr( $this->id ) . "-start'
744 value='" . esc_attr( $this->value['start'] ) . "'
745 name='" . esc_attr( $this->name ) . "_start'
746 placeholder='" . esc_attr( $this->name ) . "'
747 " . Fns::htmlKses( $this->attr, 'basic' ) . '
748 /></div>';
749 $h .= "<div class='date-range-content end'><span>" . esc_html__( 'End', 'the-post-grid' ) . "</span><input
750 type='text'
751 class='date-range date-range-end {$this->class}'
752 id='" . esc_attr( $this->id ) . "-end'
753 value='" . esc_attr( $this->value['end'] ) . "'
754 name='" . esc_attr( $this->name ) . "_end'
755 placeholder='" . esc_attr( $this->name ) . "'
756 " . Fns::htmlKses( $this->attr, 'basic' ) . '
757 /></div>';
758 $h .= '</div>';
759
760 return $h;
761 }
762 }
763