PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-gallery-metabox-fields.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 2 months ago class-admin-notices.php 2 months ago class-admin.php 2 months ago class-attachment-fields.php 2 months ago class-columns.php 2 months ago class-demo-content.php 2 months ago class-extensions.php 2 months ago class-gallery-attachment-modal.php 2 months ago class-gallery-datasources.php 2 months ago class-gallery-editor.php 2 months ago class-gallery-metabox-fields.php 2 months ago class-gallery-metabox-items.php 2 months ago class-gallery-metabox-settings-helper.php 2 months ago class-gallery-metabox-settings.php 2 months ago class-gallery-metabox-template.php 2 months ago class-gallery-metaboxes.php 2 months ago class-menu.php 2 months ago class-pro-promotion.php 2 months ago class-settings.php 2 months ago class-silent-installer-skin.php 2 months ago class-trial-mode.php 2 months ago demo-content-galleries.php 2 months ago demo-content-images.php 2 months ago index.php 2 months ago pro-features.php 2 months ago view-features.php 2 months ago view-help-demos.php 2 months ago view-help-getting-started.php 2 months ago view-help-pro.php 2 months ago view-help.php 2 months ago view-system-info.php 2 months ago
class-gallery-metabox-fields.php
231 lines
1 <?php
2
3 if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Fields' ) ) {
4
5 class FooGallery_Admin_Gallery_MetaBox_Fields {
6
7 function __construct() {
8 //render the different types of fields for our gallery settings
9 add_action( 'foogallery_render_gallery_template_field', array( $this, 'render_gallery_template_field' ), 10, 3 );
10 }
11
12 /**
13 * Renders a gallery template field into the gallery settings metabox for a FooGallery
14 *
15 * @param array $field
16 * @param $gallery FooGallery
17 * @param $template
18 */
19 function render_gallery_template_field( $field, $gallery, $template ) {
20 $template_slug = $template['slug'];
21 // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Complex form generation with internal template settings, not user input
22
23 //only declare up front so no debug warnings are shown
24 $type = $id = $desc = $default = $placeholder = $choices = $class = $spacer = $opactiy = null;
25
26 extract( $field );
27
28 $id = $template_slug . '_' . $id;
29
30 $field['value'] = apply_filters( 'foogallery_render_gallery_template_field_value', $gallery->get_meta( $id, $default ), $field, $gallery, $template );
31
32 $field_class = empty($class) ? '' : ' class="' . $class . '"';
33 $field_disabled = ! empty( $field['disabled'] ) ? ' disabled="disabled"' : '';
34
35 $field['choices'] = apply_filters( 'foogallery_render_gallery_template_field_choices', $choices, $field, $gallery );
36
37 //allow for UI customization
38 do_action( 'foogallery_render_gallery_template_field_before', $field, $gallery );
39
40 echo '<div class="foogallery_metabox_field-' . $type . '">';
41
42 switch ( $type ) {
43
44 case 'html':
45 echo $desc;
46 $desc = '';
47 break;
48
49 case 'checkbox':
50 if ( isset($gallery->settings[$id]) && $gallery->settings[$id] == 'on' ) {
51 $field['value'] = 'on';
52 } else if ( ! isset($gallery->settings) && $default == 'on' ) {
53 $field['value'] = 'on';
54 } else {
55 $field['value'] = '';
56 }
57
58 $checked = 'on' === $field['value'] ? ' checked="checked"' : '';
59 echo '<input' . $field_class . ' type="checkbox" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="on"' . $checked . ' />';
60 break;
61
62 case 'select':
63 echo '<select' . $field_class . ' id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']">';
64 foreach ( $choices as $value => $label ) {
65 $selected = '';
66 if ( $field['value'] == $value ) {
67 $selected = ' selected="selected"';
68 }
69 echo '<option ' . $selected . ' value="' . $value . '">' . $label . '</option>';
70 }
71
72 echo '</select>';
73 break;
74
75 case 'radio':
76 $i = 0;
77 foreach ( $choices as $value => $label ) {
78 $selected = '';
79 if ( $field['value'] == $value ) {
80 $selected = ' checked="checked"';
81 }
82 $label_class = '';
83 $label_icon = '';
84 $label_tooltip = '';
85 $label_tooltip_end = '';
86 $input_disabled = '';
87 if ( is_array( $label ) ) {
88 if ( array_key_exists( 'class', $label ) ) {
89 $label_class = ' class="' . $label['class'] . '"';
90 }
91 if ( array_key_exists( 'icon', $label ) ) {
92 $label_icon = '<i class="dashicons ' . $label['icon'] . '"></i>';
93 }
94 if ( array_key_exists( 'tooltip', $label ) ) {
95 $label_tooltip = '<span data-balloon-length="large" data-balloon-pos="right" data-balloon="' . $label['tooltip'] . '">';
96 $label_tooltip_end = '</span>';
97 }
98 if ( array_key_exists( 'disabled', $label ) ) {
99 $input_disabled = ' disabled="disabled"';
100 }
101 $label = $label['label'];
102 }
103 echo '<label '.$label_class.'>';
104 echo '<input' . $field_class . $selected . $input_disabled . ' type="radio" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" id="FooGallerySettings_' . $id . $i . '" value="' . $value . '">';
105 echo $label_tooltip . $label . $label_icon . $label_tooltip_end;
106 echo '</label>';
107 $i++;
108 }
109 break;
110
111 case 'textarea':
112 echo '<textarea' . $field_class . $field_disabled . ' id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" placeholder="' . $placeholder . '">' . esc_attr( $field['value'] ) . '</textarea>';
113
114 break;
115
116 case 'text':
117 echo '<input' . $field_class . $field_disabled . ' type="text" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="' . esc_attr( $field['value'] ) . '" />';
118
119 break;
120
121 case 'colorpicker':
122
123 $opacity_attribute = empty($opacity) ? '' : ' data-show-alpha="true"';
124
125 echo '<input ' . $opacity_attribute . ' class="colorpicker" type="text" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="' . esc_attr( $field['value'] ) . '" />';
126
127 break;
128
129 case 'number':
130 $min = isset($min) ? $min : 0;
131 $step = isset($step) ? $step : 1;
132 echo '<input class="small-text ' . $class . '" type="number" step="' . $step . '" min="' . $min .'" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" placeholder="' . $placeholder . '" value="' . esc_attr( $field['value'] ) . '" />';
133
134 break;
135
136 case 'slider':
137 $min = isset($min) ? $min : 0;
138 $step = isset($step) ? $step : 1;
139 $mask = isset($mask) ? $mask : '{0}px';
140 echo '<range-input class="' . esc_attr( $class ) . '" step="' . esc_attr( $step ) . '" min="' . esc_attr( $min ) . '" max="' . esc_attr( $max ) . '" mask="' . esc_attr( $mask ) . '" id="FooGallerySettings_' . $id . '" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . ']" value="' . esc_attr( $field['value'] ) . '" />';
141
142 break;
143
144 case 'checkboxlist':
145 $i = 0;
146 foreach ( $choices as $value => $label ) {
147
148 $checked = '';
149 if ( in_array( $value, $field['value'] ) ) {
150 $checked = 'checked="checked"';
151 }
152
153 echo '<input' . $field_class . ' ' . $checked . ' type="checkbox" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][' . $value . ']" id="FooGallerySettings_' . $id . $i . '" value="' . $value . '" data-value="' . $value . '"> <label for="FooGallerySettings_' . $id . $i . '">' . $label . '</label>';
154 if ( $i < count( $choices ) - 1 ) {
155 echo '<br />';
156 }
157 $i++;
158 }
159
160 break;
161 case 'icon':
162 $i = 0;
163 $input_name = FOOGALLERY_META_SETTINGS . '[' . $id . ']';
164 $icon_html = '';
165 foreach ( $choices as $value => $icon ) {
166 $selected = ( $field['value'] == $value ) ? ' checked="checked"' : '';
167 $icon_html .= '<input style="display:none" name="' . $input_name. '" id="FooGallerySettings_' . $id . $i . '" ' . $selected . ' type="radio" value="' . $value . '" tabindex="' . $i . '"/>';
168 $title = $icon['label'];
169 $img = $icon['img'];
170 $icon_html .= '<label for="FooGallerySettings_' . $id . $i . '" data-balloon-length="small" data-balloon-pos="down" data-balloon="' . $title . '"><img src="' . $img . '" /></label>';
171 $i++;
172 }
173 echo $icon_html;
174 break;
175
176 case 'htmlicon':
177 $i = 0;
178 $input_name = FOOGALLERY_META_SETTINGS . '[' . $id . ']';
179 $icon_html = '';
180 foreach ( $choices as $value => $icon ) {
181 $selected = ( $field['value'] == $value ) ? ' checked="checked"' : '';
182 $icon_html .= '<input style="display:none" name="' . $input_name. '" id="FooGallerySettings_' . $id . $i . '" ' . $selected . ' type="radio" value="' . $value . '" tabindex="' . $i . '"/>';
183 $title = $icon['label'];
184 $html = $icon['html'];
185 $icon_html .= '<label for="FooGallerySettings_' . $id . $i . '" data-balloon-length="small" data-balloon-pos="down" data-balloon="' . $title . '">' . $html . '</label>';
186 $i++;
187 }
188 echo $icon_html;
189 break;
190
191 case 'thumb_size':
192 $width = is_array( $field['value'] ) ? $field['value']['width'] : 150;
193 $height = is_array( $field['value'] ) ? $field['value']['height'] : 150;
194 $crop = is_array( $field['value'] ) && array_key_exists( 'crop', $field['value'] ) ? $field['value']['crop'] : 0;
195 $crop_checked = ( $crop == 1 ) ? ' checked="checked"' : '';
196 echo '<label for="FooGallerySettings_' . $id . '_width">' . esc_html__( 'Width', 'foogallery' ) . '</label>';
197 echo '<input class="small-text" type="number" step="1" min="0" id="FooGallerySettings_' . $id . '_width" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][width]" value="' . esc_attr( $width ) . '" />';
198 echo '<label for="FooGallerySettings_' . $id . '_width">' . esc_html__( 'Height', 'foogallery' ) . '</label>';
199 echo '<input class="small-text" type="number" step="1" min="0" id="FooGallerySettings_' . $id . '_height" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][height]" value="' . esc_attr( $height ) . '" />';
200 echo '<div class="foogallery-thumbsize-crop"><input name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][crop]" type="hidden" id="FooGallerySettings_' . $id . '_nocrop" value="0" />';
201 echo '<input name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][crop]" type="checkbox" id="FooGallerySettings_' . $id . '_crop" value="1"' . $crop_checked . '>';
202 echo '<label for="FooGallerySettings_' . $id . '_crop">' . esc_html__( 'Crop thumbnail to exact dimensions', 'foogallery' ) . '</label></div>';
203 break;
204
205 case 'thumb_size_no_crop':
206 $width = is_array( $field['value'] ) ? $field['value']['width'] : 150;
207 $height = is_array( $field['value'] ) ? $field['value']['height'] : 150;
208 echo '<label for="FooGallerySettings_' . $id . '_width">' . esc_html__( 'Width', 'foogallery' ) . '</label>';
209 echo '<input class="small-text" type="number" step="1" min="0" id="FooGallerySettings_' . $id . '_width" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][width]" value="' . esc_attr( $width ) . '" />';
210 echo '<label for="FooGallerySettings_' . $id . '_width">' . esc_html__( 'Height', 'foogallery' ) . '</label>';
211 echo '<input class="small-text" type="number" step="1" min="0" id="FooGallerySettings_' . $id . '_height" name="' . FOOGALLERY_META_SETTINGS . '[' . $id . '][height]" value="' . esc_attr( $height ) . '" />';
212 break;
213
214 default:
215 do_action( 'foogallery_render_gallery_template_field_custom', $field, $gallery, $template );
216 break;
217 }
218
219 if (!empty($suffix)) {
220 echo $suffix;
221 }
222
223 echo '</div>';
224
225 //allow for more customization
226 do_action( 'foogallery_render_gallery_template_field_after', $field, $gallery );
227 }
228 // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
229 }
230 }
231