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 / group / group.php

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

173 lines 7.0 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: group
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_group' ) ) {
12 class CSF_Field_group 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 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
21 $args = wp_parse_args( $this->field, array(
22 'max' => 0,
23 'min' => 0,
24 'fields' => array(),
25 'button_title' => esc_html__( 'Add New', 'csf' ),
26 'accordion_title_prefix' => '',
27 'accordion_title_number' => false,
28 'accordion_title_auto' => true,
29 'accordion_title_by' => array(),
30 'accordion_title_by_prefix' => ' ',
31 ) );
32 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
33
34 $title_prefix = ( ! empty( $args['accordion_title_prefix'] ) ) ? $args['accordion_title_prefix'] : '';
35 $title_number = ( ! empty( $args['accordion_title_number'] ) ) ? true : false;
36 $title_auto = ( ! empty( $args['accordion_title_auto'] ) ) ? true : false;
37 $title_first = ( isset( $this->field['fields'][0]['id'] ) ) ? $this->field['fields'][0]['id'] : $this->field['fields'][1]['id'];
38 $title_by = ( is_array( $args['accordion_title_by'] ) ) ? $args['accordion_title_by'] : (array) $args['accordion_title_by'];
39 $title_by = ( empty( $title_by ) ) ? array( $title_first ) : $title_by;
40 $title_by_prefix = ( ! empty( $args['accordion_title_by_prefix'] ) ) ? $args['accordion_title_by_prefix'] : '';
41
42 if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
43
44 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
45 echo '<div class="csf-notice csf-notice-danger">'. esc_html__( 'Error: Field ID conflict.', 'csf' ) .'</div>';
46
47 } else {
48
49 echo $this->field_before();
50
51 echo '<div class="csf-cloneable-item csf-cloneable-hidden" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
52
53 echo '<div class="csf-cloneable-helper">';
54 echo '<i class="csf-cloneable-sort fas fa-arrows-alt"></i>';
55 echo '<i class="csf-cloneable-clone far fa-clone"></i>';
56 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
57 echo '<i class="csf-cloneable-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
58 echo '</div>';
59
60 echo '<h4 class="csf-cloneable-title">';
61 echo '<span class="csf-cloneable-text">';
62 echo ( $title_number ) ? '<span class="csf-cloneable-title-number"></span>' : '';
63 echo ( $title_prefix ) ? '<span class="csf-cloneable-title-prefix">'. esc_attr( $title_prefix ) .'</span>' : '';
64 echo ( $title_auto ) ? '<span class="csf-cloneable-value"><span class="csf-cloneable-placeholder"></span></span>' : '';
65 echo '</span>';
66 echo '</h4>';
67
68 echo '<div class="csf-cloneable-content">';
69 foreach ( $this->field['fields'] as $field ) {
70
71 $field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
72 $field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
73
74 CSF::field( $field, $field_default, '___'. $field_unique, 'field/group' );
75
76 }
77 echo '</div>';
78
79 echo '</div>';
80
81 echo '<div class="csf-cloneable-wrapper csf-data-wrapper" data-title-by="'. esc_attr( json_encode( $title_by ) ) .'" data-title-by-prefix="'. esc_attr( $title_by_prefix ) .'" data-title-number="'. esc_attr( $title_number ) .'" data-field-id="['. esc_attr( $this->field['id'] ) .']" data-max="'. esc_attr( $args['max'] ) .'" data-min="'. esc_attr( $args['min'] ) .'">';
82
83 if ( ! empty( $this->value ) ) {
84
85 $num = 0;
86
87 foreach ( $this->value as $value ) {
88
89 $title = '';
90
91 if ( ! empty( $title_by ) ) {
92
93 $titles = array();
94
95 foreach ( $title_by as $title_key ) {
96 if ( isset( $value[ $title_key ] ) ) {
97 $titles[] = $value[ $title_key ];
98 }
99 }
100
101 $title = join( $title_by_prefix, $titles );
102
103 }
104
105 $title = ( is_array( $title ) ) ? reset( $title ) : $title;
106
107 echo '<div class="csf-cloneable-item">';
108
109 echo '<div class="csf-cloneable-helper">';
110 echo '<i class="csf-cloneable-sort fas fa-arrows-alt"></i>';
111 echo '<i class="csf-cloneable-clone far fa-clone"></i>';
112 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
113 echo '<i class="csf-cloneable-remove csf-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'csf' ) .'"></i>';
114 echo '</div>';
115
116 echo '<h4 class="csf-cloneable-title">';
117 echo '<span class="csf-cloneable-text">';
118 echo ( $title_number ) ? '<span class="csf-cloneable-title-number">'. esc_attr( $num+1 ) .'.</span>' : '';
119 echo ( $title_prefix ) ? '<span class="csf-cloneable-title-prefix">'. esc_attr( $title_prefix ) .'</span>' : '';
120 echo ( $title_auto ) ? '<span class="csf-cloneable-value">' . esc_attr( $title ) .'</span>' : '';
121 echo '</span>';
122 echo '</h4>';
123
124 echo '<div class="csf-cloneable-content">';
125
126 foreach ( $this->field['fields'] as $field ) {
127
128 $field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
129 $field_value = ( isset( $field['id'] ) && isset( $value[$field['id']] ) ) ? $value[$field['id']] : '';
130
131 CSF::field( $field, $field_value, $field_unique, 'field/group' );
132
133 }
134
135 echo '</div>';
136
137 echo '</div>';
138
139 $num++;
140
141 }
142
143 }
144
145 echo '</div>';
146
147 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
148 echo '<div class="csf-cloneable-alert csf-cloneable-max">'. esc_html__( 'You cannot add more.', 'csf' ) .'</div>';
149 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
150 echo '<div class="csf-cloneable-alert csf-cloneable-min">'. esc_html__( 'You cannot remove more.', 'csf' ) .'</div>';
151 echo '<a href="#" class="button button-primary csf-cloneable-add">'. $args['button_title'] .'</a>';
152
153 echo $this->field_after();
154
155 }
156
157 }
158
159 public function enqueue() {
160
161 if ( ! wp_script_is( 'jquery-ui-accordion' ) ) {
162 wp_enqueue_script( 'jquery-ui-accordion' );
163 }
164
165 if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
166 wp_enqueue_script( 'jquery-ui-sortable' );
167 }
168
169 }
170
171 }
172 }
173