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