PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / repeater / repeater.php

repeater.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/repeater/repeater.php

115 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
3 /**
4 *
5 * Field: repeater
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_repeater' ) ) {
12 class CSF_Field_repeater extends CSF_Fields {
13
14 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
15 parent::__construct( $field, $value, $unique, $where, $parent );
16 }
17
18 public function render() {
19
20 $args = wp_parse_args( $this->field, array(
21 'max' => 0,
22 'min' => 0,
23 'button_title' => '<i class="fas fa-plus-circle"></i>',
24 ) );
25
26 if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
27
28 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
29 echo '<div class="csf-notice csf-notice-danger">'. esc_html__( 'Error: Field ID conflict.', 'csf' ) .'</div>';
30
31 } else {
32
33 echo $this->field_before();
34
35 echo '<div class="csf-repeater-item csf-repeater-hidden" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
36 echo '<div class="csf-repeater-content">';
37 foreach ( $this->field['fields'] as $field ) {
38
39 $field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
40 $field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
41
42 CSF::field( $field, $field_default, '___'. $field_unique, 'field/repeater' );
43
44 }
45 echo '</div>';
46 echo '<div class="csf-repeater-helper">';
47 echo '<div class="csf-repeater-helper-inner">';
48 echo '<i class="csf-repeater-sort fas fa-arrows-alt"></i>';
49 echo '<i class="csf-repeater-clone far fa-clone"></i>';
50 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
51 echo '<i class="csf-repeater-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
52 echo '</div>';
53 echo '</div>';
54 echo '</div>';
55
56 echo '<div class="csf-repeater-wrapper csf-data-wrapper" data-field-id="['. esc_attr( $this->field['id'] ) .']" data-max="'. esc_attr( $args['max'] ) .'" data-min="'. esc_attr( $args['min'] ) .'">';
57
58 if ( ! empty( $this->value ) && is_array( $this->value ) ) {
59
60 $num = 0;
61
62 foreach ( $this->value as $key => $value ) {
63
64 echo '<div class="csf-repeater-item">';
65 echo '<div class="csf-repeater-content">';
66 foreach ( $this->field['fields'] as $field ) {
67
68 $field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
69 $field_value = ( isset( $field['id'] ) && isset( $this->value[$key][$field['id']] ) ) ? $this->value[$key][$field['id']] : '';
70
71 CSF::field( $field, $field_value, $field_unique, 'field/repeater' );
72
73 }
74 echo '</div>';
75 echo '<div class="csf-repeater-helper">';
76 echo '<div class="csf-repeater-helper-inner">';
77 echo '<i class="csf-repeater-sort fas fa-arrows-alt"></i>';
78 echo '<i class="csf-repeater-clone far fa-clone"></i>';
79 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
80 echo '<i class="csf-repeater-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
81 echo '</div>';
82 echo '</div>';
83 echo '</div>';
84
85 $num++;
86
87 }
88
89 }
90
91 echo '</div>';
92
93 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
94 echo '<div class="csf-repeater-alert csf-repeater-max">'. esc_html__( 'You cannot add more.', 'csf' ) .'</div>';
95 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
96 echo '<div class="csf-repeater-alert csf-repeater-min">'. esc_html__( 'You cannot remove more.', 'csf' ) .'</div>';
97 echo '<a href="#" class="button button-primary csf-repeater-add">'. $args['button_title'] .'</a>';
98
99 echo $this->field_after();
100
101 }
102
103 }
104
105 public function enqueue() {
106
107 if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
108 wp_enqueue_script( 'jquery-ui-sortable' );
109 }
110
111 }
112
113 }
114 }
115