class-admin-notice-custom-css.php
3 days ago
class-admin-notices.php
3 days ago
class-admin.php
3 days ago
class-attachment-fields.php
3 days ago
class-columns.php
3 days ago
class-demo-content.php
3 days ago
class-extensions.php
3 days ago
class-gallery-attachment-modal.php
3 days ago
class-gallery-datasources.php
3 days ago
class-gallery-editor.php
3 days ago
class-gallery-metabox-fields.php
3 days ago
class-gallery-metabox-items.php
3 days ago
class-gallery-metabox-settings-helper.php
3 days ago
class-gallery-metabox-settings.php
3 days ago
class-gallery-metabox-template.php
3 days ago
class-gallery-metaboxes.php
3 days ago
class-menu.php
3 days ago
class-pro-promotion.php
3 days ago
class-settings.php
3 days ago
class-silent-installer-skin.php
3 days ago
class-trial-mode.php
3 days ago
demo-content-galleries.php
3 days ago
demo-content-images.php
3 days ago
index.php
3 days ago
pro-features.php
3 days ago
view-features.php
3 days ago
view-help-demos.php
3 days ago
view-help-getting-started.php
3 days ago
view-help-pro.php
3 days ago
view-help.php
3 days ago
view-system-info.php
3 days ago
class-gallery-metabox-settings-helper.php
486 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Settings helper with sanitized internal values |
| 8 | /** |
| 9 | * Created by bradvin |
| 10 | * Date: 28/04/2017 |
| 11 | * |
| 12 | */ |
| 13 | if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Settings_Helper' ) ) { |
| 14 | |
| 15 | class FooGallery_Admin_Gallery_MetaBox_Settings_Helper { |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * @var FooGallery |
| 20 | */ |
| 21 | private $gallery; |
| 22 | |
| 23 | /** |
| 24 | * @var bool |
| 25 | */ |
| 26 | private $hide_help; |
| 27 | |
| 28 | /** |
| 29 | * @var bool |
| 30 | */ |
| 31 | private $hide_promo; |
| 32 | |
| 33 | /** |
| 34 | * @var array |
| 35 | */ |
| 36 | public $gallery_templates; |
| 37 | |
| 38 | /** |
| 39 | * @var string |
| 40 | */ |
| 41 | private $current_gallery_template; |
| 42 | |
| 43 | /** |
| 44 | * FooGallery_Admin_Gallery_MetaBox_Settings_Helper constructor. |
| 45 | * @param $gallery FooGallery |
| 46 | */ |
| 47 | function __construct($gallery) { |
| 48 | $this->gallery = $gallery; |
| 49 | $this->hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' ); |
| 50 | $this->hide_promo = 'on' == foogallery_get_setting( 'pro_promo_disabled' ); |
| 51 | |
| 52 | $this->gallery_templates = foogallery_gallery_templates(); |
| 53 | |
| 54 | $this->current_gallery_template = foogallery_default_gallery_template(); |
| 55 | if ( ! empty( $this->gallery->gallery_template ) ) { |
| 56 | $this->current_gallery_template = $this->gallery->gallery_template; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Render gallery template settings tabs. |
| 62 | * |
| 63 | * @param array $template The gallery template configuration. |
| 64 | * @param array $sections The sections within the template. |
| 65 | * |
| 66 | * @return void |
| 67 | */ |
| 68 | private function render_gallery_template_settings_tabs( $template, $sections ) { |
| 69 | $tab_active = 'foogallery-tab-active'; |
| 70 | foreach ( $sections as $section_slug => $section ) { |
| 71 | $subsection_active = ''; |
| 72 | //if there are no fields then set the slug to the first subsection |
| 73 | if ( isset( $section['subsections'] ) && count( $section['fields'] ) === 0 ) { |
| 74 | foreach ( $section['subsections'] as $subsection_slug => $subsection ) { |
| 75 | $section_slug = $subsection_slug; |
| 76 | $subsection_active = 'foogallery-tab-active'; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | ?> |
| 81 | <div class="foogallery-vertical-tab <?php echo $tab_active; ?>" |
| 82 | data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>"> |
| 83 | <span class="dashicons <?php echo $section['icon_class']; ?>"></span> |
| 84 | <span class="foogallery-tab-text"><?php echo $section['name']; ?></span> |
| 85 | <?php |
| 86 | if ( isset( $section['subsections'] ) ) { ?> |
| 87 | <div class="foogallery-vertical-child-tabs"> |
| 88 | <?php foreach ( $section['subsections'] as $subsection_slug => $subsection ) { ?> |
| 89 | <div class="foogallery-vertical-child-tab <?php echo $subsection_active; ?>" data-name="<?php echo esc_attr( $template['slug'] . '-' . $subsection_slug ); ?>"> |
| 90 | <span class="foogallery-tab-text"><?php echo esc_html( $subsection['name'] ); ?></span> |
| 91 | </div> |
| 92 | <?php |
| 93 | $subsection_active = ''; |
| 94 | } ?> |
| 95 | </div> |
| 96 | <?php } ?> |
| 97 | </div> |
| 98 | <?php |
| 99 | $tab_active = ''; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Render gallery template settings tab contents. |
| 105 | * |
| 106 | * @param array $template The gallery template configuration. |
| 107 | * @param array $sections The sections within the template. |
| 108 | * @param string $tab_active The active tab class. |
| 109 | * |
| 110 | * @return void |
| 111 | */ |
| 112 | private function render_gallery_template_settings_tab_contents( $template, $sections, $tab_active = 'foogallery-tab-active' ) { |
| 113 | foreach ( $sections as $section_slug => $section ) { |
| 114 | $subsection_active = ''; |
| 115 | |
| 116 | //if we are on an active section, then do the check for subsections |
| 117 | if ( $tab_active === 'foogallery-tab-active' ) { |
| 118 | //if there are no fields then set the slug to the first subsection |
| 119 | if ( isset( $section['subsections'] ) && count( $section['fields'] ) === 0 ) { |
| 120 | foreach ( $section['subsections'] as $subsection_slug => $subsection ) { |
| 121 | $subsection_active = 'foogallery-tab-active'; |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | ?> |
| 128 | <div class="foogallery-tab-content <?php echo $tab_active; ?>" |
| 129 | data-name="<?php echo $template['slug']; ?>-<?php echo $section_slug; ?>"> |
| 130 | <?php $this->render_gallery_template_settings_tab_contents_fields( $template, $section ); ?> |
| 131 | </div> |
| 132 | <?php |
| 133 | if ( isset( $section['subsections'] ) ) { |
| 134 | $this->render_gallery_template_settings_tab_contents( $template, $section['subsections'], $subsection_active ); |
| 135 | $subsection_active = ''; |
| 136 | } |
| 137 | $tab_active = ''; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Render gallery template settings tab contents fields. |
| 143 | * |
| 144 | * @param array $template The gallery template configuration. |
| 145 | * @param array $section The section within the template. |
| 146 | * |
| 147 | * @return void |
| 148 | */ |
| 149 | private function render_gallery_template_settings_tab_contents_fields( $template, $section ) { |
| 150 | $minimize_gallery_settings_help = foogallery_get_setting( 'minimize_gallery_settings_help', false ) === 'on'; |
| 151 | ?> |
| 152 | <table class="foogallery-metabox-settings"> |
| 153 | <tbody> |
| 154 | <?php |
| 155 | foreach ( $section['fields'] as $field ) { |
| 156 | $field_type = isset( $field['type'] ) ? $field['type'] : 'unknown'; |
| 157 | $field_class = "foogallery_template_field foogallery_template_field_type-{$field_type} foogallery_template_field_id-{$field['id']} foogallery_template_field_template-{$template['slug']} foogallery_template_field_template_id-{$template['slug']}-{$field['id']}"; |
| 158 | $is_mobile_capable = isset( $field['mobile'] ) && ( true === $field['mobile'] || is_array( $field['mobile'] ) ); |
| 159 | $mobile_field = false; |
| 160 | $mobile_mode = null; |
| 161 | $mobile_fallback_mode = null; |
| 162 | $mobile_fallback_value = null; |
| 163 | if ( $is_mobile_capable ) { |
| 164 | $desktop_default = array_key_exists( 'default', $field ) ? $field['default'] : null; |
| 165 | $desktop_value = $this->gallery->get_meta( $template['slug'] . '_' . $field['id'], $desktop_default ); |
| 166 | $mobile_field = foogallery_get_mobile_field_for_template_field( $field, $desktop_value, $template['slug'] ); |
| 167 | } |
| 168 | $is_mobile_friendly = is_array( $mobile_field ); |
| 169 | $is_mobile_locked = $is_mobile_capable && ! $is_mobile_friendly && ! $this->hide_promo; |
| 170 | if ( $is_mobile_friendly ) { |
| 171 | $mobile_definition = is_array( $field['mobile'] ) ? $field['mobile'] : array(); |
| 172 | $mobile_has_default = array_key_exists( 'default', $mobile_definition ); |
| 173 | $mobile_fallback_mode = $mobile_has_default ? 'default' : 'inherit'; |
| 174 | $mobile_fallback_value = $mobile_has_default ? $mobile_definition['default'] : $desktop_value; |
| 175 | $mobile_storage_key = $template['slug'] . '_' . $mobile_field['id']; |
| 176 | $mobile_is_custom = is_array( $this->gallery->settings ) |
| 177 | && array_key_exists( $mobile_storage_key, $this->gallery->settings ) |
| 178 | && ! foogallery_mobile_setting_values_match( $this->gallery->settings[ $mobile_storage_key ], $mobile_fallback_value ); |
| 179 | $mobile_mode = $mobile_is_custom ? 'custom' : $mobile_fallback_mode; |
| 180 | |
| 181 | if ( ! $mobile_has_default && ( is_scalar( $mobile_fallback_value ) || null === $mobile_fallback_value ) && isset( $mobile_field['choices'] ) && is_array( $mobile_field['choices'] ) && array_key_exists( $mobile_fallback_value, $mobile_field['choices'] ) ) { |
| 182 | $choice = $mobile_field['choices'][ $mobile_fallback_value ]; |
| 183 | $choice_label = is_array( $choice ) && isset( $choice['label'] ) ? $choice['label'] : $choice; |
| 184 | /* translators: %s: desktop setting choice label. */ |
| 185 | $choice_label = sprintf( __( '%s (Same as desktop)', 'foogallery' ), $choice_label ); |
| 186 | |
| 187 | if ( is_array( $choice ) ) { |
| 188 | $choice['label'] = $choice_label; |
| 189 | $mobile_field['choices'][ $mobile_fallback_value ] = $choice; |
| 190 | } else { |
| 191 | $mobile_field['choices'][ $mobile_fallback_value ] = $choice_label; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | $is_promo = array_key_exists( 'promo', $field ); |
| 196 | if ( $is_promo ) { |
| 197 | $field_class .= ' foogallery_template_field_promo'; |
| 198 | } |
| 199 | if ( array_key_exists( 'class', $field ) ) { |
| 200 | $field_class .= ' ' . $field['class']; |
| 201 | } |
| 202 | if ( $is_mobile_friendly ) { |
| 203 | $field_class .= ' foogallery_template_field_mobile_friendly'; |
| 204 | $field['row_data'] = isset( $field['row_data'] ) && is_array( $field['row_data'] ) ? $field['row_data'] : array(); |
| 205 | $field['row_data']['data-foogallery-change-selector'] = ':input, range-input'; |
| 206 | } |
| 207 | if ( $is_mobile_locked ) { |
| 208 | $field_class .= ' foogallery_template_field_mobile_locked'; |
| 209 | } |
| 210 | $field_row_data_html = ''; |
| 211 | if ( isset( $field['row_data'] ) ) { |
| 212 | $field_row_data = array_map( 'esc_attr', $field['row_data'] ); |
| 213 | foreach ( $field_row_data as $field_row_data_name => $field_row_data_value ) { |
| 214 | $field_row_data_html .= " $field_row_data_name=" . '"' . esc_attr( $field_row_data_value ) . '"'; |
| 215 | } |
| 216 | } |
| 217 | ?> |
| 218 | <tr data-foogallery-setting-id="<?php echo esc_attr( $field['id'] ); ?>" data-foogallery-setting-type="<?php echo esc_attr( $field_type ); ?>" class="<?php echo esc_attr( $field_class ); ?>"<?php echo $field_row_data_html; ?><?php echo $is_mobile_friendly ? ' data-foogallery-mobile-friendly="true" data-foogallery-mobile-setting-id="' . esc_attr( $mobile_field['id'] ) . '" data-foogallery-setting-viewport="desktop" data-foogallery-mobile-mode="' . esc_attr( $mobile_mode ) . '" data-foogallery-mobile-fallback-mode="' . esc_attr( $mobile_fallback_mode ) . '" data-foogallery-mobile-fallback-value="' . esc_attr( wp_json_encode( $mobile_fallback_value ) ) . '"' : ''; ?><?php echo $is_mobile_locked ? ' data-foogallery-mobile-locked="true"' : ''; ?>> |
| 219 | <?php |
| 220 | if ( 'warning' === $field_type ) { |
| 221 | ?> |
| 222 | <td colspan="2"> |
| 223 | <div class="foogallery-help foogallery-warning"> |
| 224 | <i class="dashicons dashicons-warning"></i> |
| 225 | <?php if ( array_key_exists( 'title', $field ) ) { ?> |
| 226 | <?php echo '<h4>' . $field['title'] . '</h4>'; ?> |
| 227 | <?php } ?> |
| 228 | <?php if ( array_key_exists( 'desc', $field ) ) { ?> |
| 229 | <p><?php echo $field['desc']; ?></p> |
| 230 | <?php } ?> |
| 231 | </div> |
| 232 | </td> |
| 233 | <?php } |
| 234 | else if ( 'help' === $field_type ) { ?> |
| 235 | <td colspan="2"> |
| 236 | <div class="foogallery-help"> |
| 237 | <i class="dashicons dashicons-editor-help"></i> |
| 238 | <?php if ( array_key_exists( 'title', $field ) ) { ?> |
| 239 | <?php echo '<h4>' . $field['title'] . '</h4>'; ?> |
| 240 | <?php } ?> |
| 241 | <?php if ( array_key_exists( 'desc', $field ) ) { ?> |
| 242 | <p><?php echo $field['desc']; ?></p> |
| 243 | <?php } ?> |
| 244 | </div> |
| 245 | </td> |
| 246 | <?php } else if ( 'promo' === $field_type ) { ?> |
| 247 | <td colspan="2"> |
| 248 | <div class="foogallery-promo"> |
| 249 | <button class="foogallery-admin-promo-dismiss notice-dismiss"></button> |
| 250 | <?php echo '<strong>' . $field['title'] . '</strong><br /><br />'; ?> |
| 251 | <?php |
| 252 | echo $field['desc']; |
| 253 | if ( array_key_exists( 'cta_text', $field ) ) { |
| 254 | echo '<a class="button-primary" href="' . $field['cta_link'] . '" target="_blank">' . $field['cta_text'] . '</a>'; |
| 255 | } |
| 256 | if ( array_key_exists( 'cta', $field ) ) { |
| 257 | foreach ( $field['cta'] as $cta ) { |
| 258 | $button_class = isset( $cta['class'] ) ? $cta['class'] : 'button-primary'; |
| 259 | echo '<a class="' . $button_class . '" href="' . $cta['link'] . '" target="_blank">' . $cta['text'] . '</a>'; |
| 260 | } |
| 261 | } |
| 262 | ?> |
| 263 | </div> |
| 264 | </td> |
| 265 | <?php } else { |
| 266 | $for_attribute = $this->field_for_attribute( $template, $field ); |
| 267 | $setting_helper = ! empty( $field['alias'] ) ? $field['alias'] : $field['id']; |
| 268 | if ( !empty( $for_attribute ) ) { |
| 269 | $for_html = ' for="' . esc_attr( $for_attribute ) . '"'; |
| 270 | } else { |
| 271 | $for_html = ''; |
| 272 | } |
| 273 | ?> |
| 274 | <th> |
| 275 | <label class="foogallery-setting-label" data-setting="<?php echo esc_attr( $setting_helper ); ?>" data-desktop-for="<?php echo esc_attr( $for_attribute ); ?>"<?php if ( $is_mobile_friendly ) { ?> data-mobile-for="<?php echo esc_attr( $this->field_for_attribute( $template, $mobile_field ) ); ?>"<?php } ?><?php echo $for_html; ?>><?php esc_html_e( $field['title'] ); ?></label> |
| 276 | <?php if ( $is_promo ) { ?> |
| 277 | <span data-balloon-length="large" data-balloon-pos="right" data-balloon="<?php echo esc_attr($field['promo']); ?>"><i class="dashicons dashicons-star-filled"></i></span> |
| 278 | <?php } ?> |
| 279 | <?php if ( !empty( $field['desc'] ) && $minimize_gallery_settings_help ) { ?> |
| 280 | <span class="foogallery-settings-help" data-balloon-length="large" data-balloon-pos="right" data-balloon="<?php echo esc_attr($field['desc']); ?>"><i class="dashicons dashicons-editor-help"></i></span> |
| 281 | <?php } ?> |
| 282 | <?php if ( $is_mobile_friendly ) { ?> |
| 283 | <div class="foogallery-setting-viewport-actions" role="group" aria-label="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( '%s responsive values', 'foogallery' ), $field['title'] ) ); ?>"> |
| 284 | <button type="button" class="foogallery-setting-viewport-btn active" data-viewport="desktop" aria-label="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( 'Edit %s desktop and tablet value', 'foogallery' ), $field['title'] ) ); ?>" aria-controls="<?php echo esc_attr( $this->field_control_id( $template, $field, 'desktop' ) ); ?>" aria-pressed="true"><span class="dashicons dashicons-desktop" aria-hidden="true"></span></button> |
| 285 | <button type="button" class="foogallery-setting-viewport-btn" data-viewport="mobile" aria-label="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( 'Edit %s mobile value', 'foogallery' ), $field['title'] ) ); ?>" aria-controls="<?php echo esc_attr( $this->field_control_id( $template, $field, 'mobile' ) ); ?>" aria-pressed="false"><span class="dashicons dashicons-smartphone" aria-hidden="true"></span></button> |
| 286 | </div> |
| 287 | <?php } elseif ( $is_mobile_locked ) { ?> |
| 288 | <div class="foogallery-setting-viewport-actions" role="group" aria-label="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( '%s responsive availability', 'foogallery' ), $field['title'] ) ); ?>"> |
| 289 | <button type="button" class="foogallery-setting-viewport-btn foogallery-setting-mobile-locked-desktop active" data-viewport="desktop" aria-label="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( 'Use %s desktop and tablet value', 'foogallery' ), $field['title'] ) ); ?>" aria-pressed="true"><span class="dashicons dashicons-desktop" aria-hidden="true"></span></button> |
| 290 | <button type="button" class="foogallery-setting-mobile-locked" data-viewport="mobile" data-foogallery-mobile-promo-label="<?php echo esc_attr( wp_strip_all_tags( $field['title'] ) ); ?>" aria-label="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( 'Give %s its own mobile value with PRO Starter', 'foogallery' ), $field['title'] ) ); ?>" aria-haspopup="dialog" aria-expanded="false" aria-pressed="false" data-foogallery-mobile-promo="true" title="<?php /* translators: %s: Gallery setting label. */ echo esc_attr( sprintf( __( 'Give %s its own mobile value with PRO Starter', 'foogallery' ), $field['title'] ) ); ?>"><span class="dashicons dashicons-smartphone" aria-hidden="true"></span><span class="dashicons dashicons-star-filled" aria-hidden="true"></span></button> |
| 291 | </div> |
| 292 | <?php } ?> |
| 293 | </th> |
| 294 | <td> |
| 295 | <?php if ( $is_mobile_friendly ) { ?> |
| 296 | <div id="<?php echo esc_attr( $this->field_control_id( $template, $field, 'desktop' ) ); ?>" class="foogallery-setting-control foogallery-setting-control-desktop" data-viewport="desktop"> |
| 297 | <?php do_action( 'foogallery_render_gallery_template_field', $field, $this->gallery, $template ); ?> |
| 298 | </div> |
| 299 | <fieldset id="<?php echo esc_attr( $this->field_control_id( $template, $field, 'mobile' ) ); ?>" class="foogallery-setting-control foogallery-setting-control-mobile" data-viewport="mobile" hidden> |
| 300 | <?php do_action( 'foogallery_render_gallery_template_field', $mobile_field, $this->gallery, $template ); ?> |
| 301 | </fieldset> |
| 302 | <?php } else { ?> |
| 303 | <?php do_action( 'foogallery_render_gallery_template_field', $field, $this->gallery, $template ); ?> |
| 304 | <?php } ?> |
| 305 | <?php if ( ! empty( $field['desc'] ) && ! $minimize_gallery_settings_help ) { ?> |
| 306 | <p class="foogallery-settings-description"><?php echo esc_html( $field['desc'] ); ?></p> |
| 307 | <?php } ?> |
| 308 | </td> |
| 309 | <?php } ?> |
| 310 | </tr> |
| 311 | <?php } ?> |
| 312 | </tbody> |
| 313 | </table> |
| 314 | <?php |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Return the input ID targeted by a field label. |
| 319 | * |
| 320 | * @param array $template Gallery template definition. |
| 321 | * @param array $field Gallery field definition. |
| 322 | * |
| 323 | * @return string |
| 324 | */ |
| 325 | private function field_for_attribute( $template, $field ) { |
| 326 | $for_attribute = 'FooGallerySettings_' . $template['slug'] . '_' . $field['id']; |
| 327 | $field_type = isset( $field['type'] ) ? $field['type'] : 'unknown'; |
| 328 | $radio_types = array( 'radio', 'checkboxlist', 'icon', 'htmlicon' ); |
| 329 | |
| 330 | if ( in_array( $field_type, $radio_types, true ) ) { |
| 331 | $for_attribute .= '0'; |
| 332 | } |
| 333 | |
| 334 | if ( isset( $field['for'] ) ) { |
| 335 | $for_attribute = 'none' === $field['for'] ? '' : 'FooGallerySettings_' . $template['slug'] . '_' . $field['for']; |
| 336 | } |
| 337 | |
| 338 | return $for_attribute; |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Return a stable ID for one responsive control wrapper. |
| 343 | * |
| 344 | * @param array $template Gallery template definition. |
| 345 | * @param array $field Gallery field definition. |
| 346 | * @param string $viewport Responsive control viewport. |
| 347 | * |
| 348 | * @return string |
| 349 | */ |
| 350 | private function field_control_id( $template, $field, $viewport ) { |
| 351 | return 'FooGallerySettingControl_' . $template['slug'] . '_' . $field['id'] . '_' . $viewport; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Render the settings for a specific gallery template. |
| 356 | * |
| 357 | * @param array $template The gallery template configuration. |
| 358 | * |
| 359 | * @return void |
| 360 | */ |
| 361 | private function render_gallery_template_settings( $template ) { |
| 362 | $sections = $this->build_model_for_template( $template ); |
| 363 | ?> |
| 364 | <div class="foogallery-settings"> |
| 365 | <div class="foogallery-vertical-tabs"> |
| 366 | <?php $this->render_gallery_template_settings_tabs( $template, $sections ); ?> |
| 367 | </div> |
| 368 | <div class="foogallery-tab-contents"> |
| 369 | <?php $this->render_gallery_template_settings_tab_contents( $template, $sections ); ?> |
| 370 | </div> |
| 371 | </div> |
| 372 | <?php |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Public method to render gallery settings for all templates. |
| 377 | * |
| 378 | * @return void |
| 379 | */ |
| 380 | public function render_gallery_settings() { |
| 381 | foreach ( $this->gallery_templates as $template ) { |
| 382 | $field_visibility = ( $this->current_gallery_template !== $template['slug'] ) ? 'style="display:none"' : ''; |
| 383 | ?><div |
| 384 | class="foogallery-settings-container foogallery-settings-container-<?php echo $template['slug']; ?>" |
| 385 | <?php echo $field_visibility; ?>> |
| 386 | <?php $this->render_gallery_template_settings( $template ); ?> |
| 387 | </div><?php |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Build the model used to render gallery settings. |
| 393 | * |
| 394 | * @param array $template Gallery template definition. |
| 395 | * @return array |
| 396 | */ |
| 397 | private function build_model_for_template( $template ) { |
| 398 | $fields = foogallery_get_fields_for_template( $template ); |
| 399 | $registered_sections = foogallery_get_gallery_setting_sections(); |
| 400 | |
| 401 | $sections = array(); |
| 402 | foreach ( $fields as $field ) { |
| 403 | if ( isset( $field['type'] ) && 'help' === $field['type'] && $this->hide_help ) { |
| 404 | continue; |
| 405 | } |
| 406 | |
| 407 | if ( isset( $field['type'] ) && 'promo' === $field['type'] && $this->hide_promo ) { |
| 408 | continue; |
| 409 | } |
| 410 | |
| 411 | $field = foogallery_normalize_gallery_setting_field_sections( $field, $registered_sections ); |
| 412 | $section_slug = $field['section_id']; |
| 413 | $section_config = isset( $registered_sections[ $section_slug ] ) && is_array( $registered_sections[ $section_slug ] ) |
| 414 | ? $registered_sections[ $section_slug ] |
| 415 | : array(); |
| 416 | $section_name = isset( $section_config['label'] ) |
| 417 | ? $section_config['label'] |
| 418 | : ( isset( $field['section'] ) ? $field['section'] : ucwords( str_replace( array( '-', '_' ), ' ', $section_slug ) ) ); |
| 419 | $section_order = isset( $section_config['order'] ) |
| 420 | ? intval( $section_config['order'] ) |
| 421 | : ( isset( $field['section_order'] ) ? intval( $field['section_order'] ) : 99 ); |
| 422 | |
| 423 | if ( ! isset( $sections[ $section_slug ] ) ) { |
| 424 | $sections[ $section_slug ] = array( |
| 425 | 'name' => $section_name, |
| 426 | 'icon_class' => foogallery_get_gallery_setting_section_icon( $section_slug, $section_name ), |
| 427 | 'fields' => array(), |
| 428 | 'order' => $section_order, |
| 429 | ); |
| 430 | } |
| 431 | |
| 432 | if ( ! empty( $field['subsection_id'] ) ) { |
| 433 | $subsection = $field['subsection_id']; |
| 434 | $subsection_config = isset( $section_config['subsections'][ $subsection ] ) && is_array( $section_config['subsections'][ $subsection ] ) |
| 435 | ? $section_config['subsections'][ $subsection ] |
| 436 | : array(); |
| 437 | if ( ! isset( $sections[ $section_slug ]['subsections'] ) ) { |
| 438 | $sections[ $section_slug ]['subsections'] = array(); |
| 439 | } |
| 440 | if ( ! array_key_exists( $subsection, $sections[ $section_slug ]['subsections'] ) ) { |
| 441 | $sections[ $section_slug ]['subsections'][ $subsection ] = array( |
| 442 | 'name' => isset( $subsection_config['label'] ) |
| 443 | ? $subsection_config['label'] |
| 444 | : ( isset( $field['subsection'][ $subsection ] ) ? $field['subsection'][ $subsection ] : ucwords( str_replace( array( '-', '_' ), ' ', $subsection ) ) ), |
| 445 | 'fields' => array(), |
| 446 | 'order' => isset( $subsection_config['order'] ) ? intval( $subsection_config['order'] ) : 99, |
| 447 | ); |
| 448 | } |
| 449 | $sections[ $section_slug ]['subsections'][ $subsection ]['fields'][] = $field; |
| 450 | } else { |
| 451 | $sections[ $section_slug ]['fields'][] = $field; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | uasort( $sections, array( $this, 'sort_template_sections' ) ); |
| 456 | foreach ( $sections as &$section ) { |
| 457 | if ( isset( $section['subsections'] ) ) { |
| 458 | uasort( $section['subsections'], array( $this, 'sort_template_sections' ) ); |
| 459 | } |
| 460 | } |
| 461 | unset( $section ); |
| 462 | |
| 463 | return $sections; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Used to sort sections |
| 468 | * |
| 469 | * @param mixed $a First section. |
| 470 | * @param mixed $b Second section. |
| 471 | * |
| 472 | * @return int |
| 473 | */ |
| 474 | public function sort_template_sections( $a, $b ) { |
| 475 | if ( isset( $a['order'] ) && isset( $b['order'] ) ) { |
| 476 | if ( $a['order'] === $b['order'] ) { |
| 477 | return 0; |
| 478 | } |
| 479 | return ( $a['order'] < $b['order'] ) ? -1 : 1; |
| 480 | } |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 |