class-masonry-gallery-template.php
554 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if ( !class_exists( 'FooGallery_Masonry_Gallery_Template' ) ) { |
| 8 | |
| 9 | define('FOOGALLERY_MASONRY_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
| 10 | |
| 11 | class FooGallery_Masonry_Gallery_Template { |
| 12 | |
| 13 | const template_id = 'masonry'; |
| 14 | |
| 15 | /** |
| 16 | * Wire up everything we need to run the extension |
| 17 | */ |
| 18 | function __construct() { |
| 19 | add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) ); |
| 20 | add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
| 21 | |
| 22 | add_action( 'foogallery_enqueue_preview_dependencies', array( $this, 'enqueue_preview_dependencies' ) ); |
| 23 | |
| 24 | add_filter( 'foogallery_located_template-masonry', array( $this, 'enqueue_dependencies' ) ); |
| 25 | |
| 26 | add_filter( 'foogallery_template_thumbnail_dimensions-masonry', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
| 27 | |
| 28 | //add the data options needed for masonry |
| 29 | add_filter( 'foogallery_build_container_data_options-masonry', array( $this, 'add_masonry_options' ), 10, 3 ); |
| 30 | add_filter( 'foogallery_build_container_mobile_data_options-masonry', array( $this, 'add_mobile_masonry_options' ), 10, 3 ); |
| 31 | |
| 32 | //build up the thumb dimensions from some arguments |
| 33 | add_filter( 'foogallery_calculate_thumbnail_dimensions-masonry', array( $this, 'build_thumbnail_dimensions_from_arguments' ), 10, 2 ); |
| 34 | |
| 35 | //build up the arguments needed for rendering this template |
| 36 | add_filter( 'foogallery_gallery_template_arguments-masonry', array( $this, 'build_gallery_template_arguments' ) ); |
| 37 | |
| 38 | //add extra fields to the templates |
| 39 | add_filter( 'foogallery_override_gallery_template_fields-masonry', array( $this, 'add_masonry_fields' ), 10, 2 ); |
| 40 | |
| 41 | //remove the captions if the captions are below thumbs |
| 42 | add_filter( 'foogallery_build_attachment_html_caption', array( $this, 'remove_captions' ), 10, 3 ); |
| 43 | |
| 44 | add_filter( 'foogallery_build_class_attribute', array( $this, 'override_class_attributes' ), 99, 2 ); |
| 45 | |
| 46 | // Adjust the default settings for this layout |
| 47 | add_filter( 'foogallery_override_gallery_template_fields_defaults-masonry', array( $this, 'field_defaults' ), 10, 1 ); |
| 48 | |
| 49 | // handle aliases for masonry template settings |
| 50 | add_filter( 'foogallery_gallery_template_argument_alias', array( $this, 'handle_alias' ), 10, 2 ); |
| 51 | add_filter( 'foogallery_gallery_template_setting-thumbnail_width', array( $this, 'handle_thumbnail_width_alias_value' ) ); |
| 52 | |
| 53 | // add a style block for the gallery based on the field settings. |
| 54 | add_action( 'foogallery_template_style_block-masonry', array( $this, 'add_css' ), 10, 2 ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Handle aliases for masonry template settings. |
| 59 | * |
| 60 | * @param string $key The key of the setting. |
| 61 | * @param string $template The template slug. |
| 62 | * |
| 63 | * @return string |
| 64 | */ |
| 65 | function handle_alias( $key, $template ) { |
| 66 | global $current_foogallery_arguments; |
| 67 | |
| 68 | if ( 'thumbnail_width' === $key && self::template_id === $template && is_array( $current_foogallery_arguments ) && ! array_key_exists( 'thumbnail_width', $current_foogallery_arguments ) ) { |
| 69 | return 'thumbnail_size'; |
| 70 | } |
| 71 | |
| 72 | return $key; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Convert an aliased thumbnail_size array to masonry's thumbnail_width value. |
| 77 | * |
| 78 | * @param mixed $value The setting value. |
| 79 | * |
| 80 | * @return mixed |
| 81 | */ |
| 82 | function handle_thumbnail_width_alias_value( $value ) { |
| 83 | global $current_foogallery_template; |
| 84 | |
| 85 | if ( self::template_id === $current_foogallery_template && is_array( $value ) && array_key_exists( 'width', $value ) ) { |
| 86 | return $value['width']; |
| 87 | } |
| 88 | |
| 89 | return $value; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Override the classes for the layout |
| 94 | * |
| 95 | * @param $classes array |
| 96 | * @param $gallery FooGallery |
| 97 | * |
| 98 | * @return array |
| 99 | */ |
| 100 | function override_class_attributes( $classes, $gallery ) { |
| 101 | if ( self::template_id === $gallery->gallery_template ) { |
| 102 | $classes[] = 'fg-' . foogallery_gallery_template_setting( 'layout', 'fixed' ); |
| 103 | } |
| 104 | |
| 105 | return $classes; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Register myself so that all associated JS and CSS files can be found and automatically included |
| 110 | * @param $extensions |
| 111 | * |
| 112 | * @return array |
| 113 | */ |
| 114 | function register_myself( $extensions ) { |
| 115 | $extensions[] = __FILE__; |
| 116 | return $extensions; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Add our gallery template to the list of templates available for every gallery |
| 121 | * @param $gallery_templates |
| 122 | * |
| 123 | * @return array |
| 124 | */ |
| 125 | function add_template( $gallery_templates ) { |
| 126 | $gallery_templates[self::template_id] = array( |
| 127 | 'slug' => self::template_id, |
| 128 | 'name' => __( 'Masonry', 'foogallery' ), |
| 129 | 'preview_support' => true, |
| 130 | 'common_fields_support' => true, |
| 131 | 'lazyload_support' => true, |
| 132 | 'paging_support' => true, |
| 133 | 'mandatory_classes' => 'fg-masonry', |
| 134 | 'thumbnail_dimensions' => true, |
| 135 | 'filtering_support' => true, |
| 136 | 'icon' => '<svg viewBox="0 0 24 24"> |
| 137 | <rect x="3" y="3" width="6" height="10"/> |
| 138 | <rect x="9" y="3" width="6" height="6"/> |
| 139 | <rect x="15" y="3" width="6" height="14"/> |
| 140 | <rect x="3" y="13" width="6" height="7"/> |
| 141 | <rect x="9" y="9" width="6" height="13"/> |
| 142 | </svg>', |
| 143 | 'fields' => array( |
| 144 | array( |
| 145 | 'id' => 'thumbnail_width', |
| 146 | 'title' => __( 'Thumbnail Width', 'foogallery' ), |
| 147 | 'desc' => __( 'Choose the width of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ), |
| 148 | 'section' => __( 'General', 'foogallery' ), |
| 149 | 'alias' => 'thumbnail_size', |
| 150 | 'type' => 'number', |
| 151 | 'class' => 'small-text', |
| 152 | 'default' => 250, |
| 153 | 'step' => '1', |
| 154 | 'min' => '0', |
| 155 | 'mobile' => true, |
| 156 | 'row_data'=> array( |
| 157 | 'data-foogallery-change-selector' => 'input', |
| 158 | 'data-foogallery-preview' => 'shortcode' |
| 159 | ) |
| 160 | ), |
| 161 | array( |
| 162 | 'id' => 'gutter_width', |
| 163 | 'title' => __( 'Thumbnail Gap', 'foogallery' ), |
| 164 | 'desc' => __( 'The spacing or gap between your thumbnails.', 'foogallery' ), |
| 165 | 'section' => __( 'General', 'foogallery' ), |
| 166 | 'type' => 'slider', |
| 167 | 'min' => 0, |
| 168 | 'max' => 100, |
| 169 | 'step' => 1, |
| 170 | 'default' => 10, |
| 171 | 'mobile' => true, |
| 172 | 'row_data'=> array( |
| 173 | 'data-foogallery-change-selector' => 'range-input', |
| 174 | 'data-foogallery-preview' => 'shortcode', |
| 175 | ) |
| 176 | ), |
| 177 | array( |
| 178 | 'id' => 'layout', |
| 179 | 'title' => __( 'Masonry Layout', 'foogallery' ), |
| 180 | 'desc' => __( 'Choose a fixed width thumb layout, or responsive columns.', 'foogallery' ), |
| 181 | 'section' => __( 'General', 'foogallery' ), |
| 182 | 'type' => 'radio', |
| 183 | 'choices' => array( |
| 184 | 'fixed' => __( 'Fixed Width', 'foogallery' ), |
| 185 | 'col6' => __( '6 Columns', 'foogallery' ), |
| 186 | 'col5' => __( '5 Columns', 'foogallery' ), |
| 187 | 'col4' => __( '4 Columns', 'foogallery' ), |
| 188 | 'col3' => __( '3 Columns', 'foogallery' ), |
| 189 | 'col2' => __( '2 Columns', 'foogallery' ), |
| 190 | ), |
| 191 | 'class' => 'foogallery-radios-stacked', |
| 192 | 'default' => 'fixed', |
| 193 | 'mobile' => array( |
| 194 | 'choices' => array( |
| 195 | 'fixed' => __( 'Fixed Width', 'foogallery' ), |
| 196 | 'col3' => __( '3 Columns', 'foogallery' ), |
| 197 | 'col2' => __( '2 Columns', 'foogallery' ), |
| 198 | 'col1' => __( '1 Column', 'foogallery' ), |
| 199 | ), |
| 200 | ), |
| 201 | 'row_data'=> array( |
| 202 | 'data-foogallery-change-selector' => 'input:radio', |
| 203 | 'data-foogallery-value-selector' => 'input:checked', |
| 204 | 'data-foogallery-preview' => 'shortcode' |
| 205 | ) |
| 206 | ), |
| 207 | array( |
| 208 | 'id' => 'horizontal', |
| 209 | 'title' => __( 'Horizontal Layout', 'foogallery' ), |
| 210 | 'desc' => __( 'You can choose to lay out items to (mostly) maintain horizontal left-to-right order.', 'foogallery' ), |
| 211 | 'section' => __( 'General', 'foogallery' ), |
| 212 | 'type' => 'radio', |
| 213 | 'choices' => array( |
| 214 | '' => __( 'Disabled', 'foogallery' ), |
| 215 | 'yes' => __( 'Try to maintain lef-to-right order', 'foogallery' ), |
| 216 | ), |
| 217 | 'default' => '', |
| 218 | 'row_data'=> array( |
| 219 | 'data-foogallery-change-selector' => 'input:radio', |
| 220 | 'data-foogallery-value-selector' => 'input:checked', |
| 221 | 'data-foogallery-preview' => 'shortcode' |
| 222 | ) |
| 223 | ), |
| 224 | |
| 225 | array( |
| 226 | 'id' => 'gutter_percent', |
| 227 | 'title' => __( 'Gutter Size', 'foogallery' ), |
| 228 | 'desc' => __( 'Choose a gutter size when using responsive columns.', 'foogallery' ), |
| 229 | 'section' => __( 'General', 'foogallery' ), |
| 230 | 'type' => 'radio', |
| 231 | 'choices' => array( |
| 232 | 'fg-gutter-none' => __( 'No Gutter', 'foogallery' ), |
| 233 | '' => __( 'Normal Size Gutter', 'foogallery' ), |
| 234 | 'fg-gutter-large' => __( 'Larger Gutter', 'foogallery' ) |
| 235 | ), |
| 236 | 'default' => '', |
| 237 | 'mobile' => true, |
| 238 | 'row_data'=> array( |
| 239 | 'data-foogallery-hidden' => true, |
| 240 | 'data-foogallery-change-selector' => 'input:radio', |
| 241 | 'data-foogallery-value-selector' => 'input:checked', |
| 242 | 'data-foogallery-show-when-field' => 'layout', |
| 243 | 'data-foogallery-show-when-field-operator' => '!==', |
| 244 | 'data-foogallery-show-when-field-value' => 'fixed', |
| 245 | 'data-foogallery-preview' => 'shortcode' |
| 246 | ) |
| 247 | ), |
| 248 | array( |
| 249 | 'id' => 'alignment', |
| 250 | 'title' => __( 'Alignment', 'foogallery' ), |
| 251 | 'desc' => __( 'You can choose to center align your images or leave them at the default (left). Only applicable when using a fixed layout!', 'foogallery' ), |
| 252 | 'section' => __( 'General', 'foogallery' ), |
| 253 | 'type' => 'radio', |
| 254 | 'choices' => array( |
| 255 | '' => __( 'Left', 'foogallery' ), |
| 256 | 'fg-center' => __( 'Center', 'foogallery' ) |
| 257 | ), |
| 258 | 'default' => 'fg-center', |
| 259 | 'row_data'=> array( |
| 260 | 'data-foogallery-hidden' => true, |
| 261 | 'data-foogallery-show-when-field' => 'layout', |
| 262 | 'data-foogallery-show-when-field-value' => 'fixed', |
| 263 | 'data-foogallery-change-selector' => 'input:radio', |
| 264 | 'data-foogallery-preview' => 'shortcode' |
| 265 | ) |
| 266 | ), |
| 267 | array( |
| 268 | 'id' => 'thumbnail_link', |
| 269 | 'title' => __( 'Thumbnail Link', 'foogallery' ), |
| 270 | 'default' => 'image' , |
| 271 | 'type' => 'thumb_link', |
| 272 | ), |
| 273 | array( |
| 274 | 'id' => 'lightbox', |
| 275 | 'type' => 'lightbox', |
| 276 | ), |
| 277 | ), |
| 278 | ); |
| 279 | |
| 280 | |
| 281 | return $gallery_templates; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Enqueue scripts that the masonry gallery template relies on |
| 286 | */ |
| 287 | function enqueue_preview_dependencies() { |
| 288 | wp_enqueue_script( 'masonry' ); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Enqueue scripts that the masonry gallery template relies on |
| 293 | */ |
| 294 | function enqueue_dependencies() { |
| 295 | wp_enqueue_script( 'masonry' ); |
| 296 | |
| 297 | //enqueue core files |
| 298 | foogallery_enqueue_core_gallery_template_style(); |
| 299 | foogallery_enqueue_core_gallery_template_script( array('jquery', 'masonry' ) ); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Get the thumb dimensions arguments saved for the gallery for this gallery template |
| 304 | * |
| 305 | * @param array $dimensions |
| 306 | * @param FooGallery $foogallery |
| 307 | * |
| 308 | * @return mixed |
| 309 | */ |
| 310 | function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
| 311 | $width = $foogallery->get_meta( 'masonry_thumbnail_width', false ); |
| 312 | return array( |
| 313 | 'height' => 0, |
| 314 | 'width' => intval( $width ), |
| 315 | 'crop' => false |
| 316 | ); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Add the required masonry options if needed |
| 321 | * |
| 322 | * @param $options |
| 323 | * @param $gallery FooGallery |
| 324 | * |
| 325 | * @param $attributes array |
| 326 | * |
| 327 | * @return array |
| 328 | */ |
| 329 | function add_masonry_options($options, $gallery, $attributes) { |
| 330 | $layout = foogallery_gallery_template_setting( 'layout', 'fixed' ); |
| 331 | if ( 'fixed' === $layout ) { |
| 332 | $width = foogallery_gallery_template_setting( 'thumbnail_width', '250' ); |
| 333 | $gutter_width = foogallery_gallery_template_setting( 'gutter_width', '10' ); |
| 334 | $options['template']['columnWidth'] = intval($width); |
| 335 | $options['template']['gutter'] = intval($gutter_width); |
| 336 | } |
| 337 | $horizontal = foogallery_gallery_template_setting( 'horizontal', '' ); |
| 338 | if ( 'yes' === $horizontal ) { |
| 339 | $options['template']['horizontalOrder'] = true; |
| 340 | } |
| 341 | return $options; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Add the fixed-layout mobile gutter understood by the Masonry client. |
| 346 | * |
| 347 | * @param array $options Mobile client options. |
| 348 | * @param FooGallery $_gallery Gallery instance (unused). |
| 349 | * @param array $_attributes Gallery container attributes (unused). |
| 350 | * |
| 351 | * @return array |
| 352 | */ |
| 353 | function add_mobile_masonry_options( $options, $_gallery, $_attributes ) { |
| 354 | $mobile_layout = foogallery_gallery_template_setting( 'mobile_layout', null ); |
| 355 | if ( is_scalar( $mobile_layout ) && in_array( (string) $mobile_layout, array( 'fixed', 'col1', 'col2', 'col3' ), true ) ) { |
| 356 | $options['template']['layout'] = (string) $mobile_layout; |
| 357 | } |
| 358 | |
| 359 | $effective_layout = isset( $options['template']['layout'] ) ? $options['template']['layout'] : foogallery_gallery_template_setting( 'layout', 'fixed' ); |
| 360 | if ( 'fixed' !== $effective_layout ) { |
| 361 | return $options; |
| 362 | } |
| 363 | |
| 364 | $mobile_gutter = foogallery_gallery_template_setting( 'mobile_gutter_width', null ); |
| 365 | if ( is_scalar( $mobile_gutter ) && is_numeric( trim( (string) $mobile_gutter ) ) ) { |
| 366 | $options['template']['gutter'] = max( 0, min( 100, intval( $mobile_gutter ) ) ); |
| 367 | } |
| 368 | |
| 369 | $mobile_width = foogallery_gallery_template_setting( 'mobile_thumbnail_width', null ); |
| 370 | if ( is_scalar( $mobile_width ) && is_numeric( trim( (string) $mobile_width ) ) ) { |
| 371 | $options['template']['columnWidth'] = max( 0, intval( $mobile_width ) ); |
| 372 | } |
| 373 | |
| 374 | return $options; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Builds thumb dimensions from arguments |
| 379 | * |
| 380 | * @param array $dimensions |
| 381 | * @param array $arguments |
| 382 | * |
| 383 | * @return mixed |
| 384 | */ |
| 385 | function build_thumbnail_dimensions_from_arguments( $dimensions, $arguments ) { |
| 386 | if ( array_key_exists( 'thumbnail_width', $arguments) ) { |
| 387 | return array( |
| 388 | 'height' => 0, |
| 389 | 'width' => intval($arguments['thumbnail_width']), |
| 390 | 'crop' => false |
| 391 | ); |
| 392 | } |
| 393 | return null; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Build up the arguments needed for rendering this gallery template |
| 398 | * |
| 399 | * @param $args |
| 400 | * @return array |
| 401 | */ |
| 402 | function build_gallery_template_arguments( $args ) { |
| 403 | $args = array( |
| 404 | 'width' => foogallery_gallery_template_setting( 'thumbnail_width', '250' ), |
| 405 | 'link' => foogallery_gallery_template_setting( 'thumbnail_link', 'image' ), |
| 406 | 'crop' => false |
| 407 | ); |
| 408 | |
| 409 | return $args; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Add masonry-specific fields to the gallery template |
| 414 | * |
| 415 | * @uses "foogallery_override_gallery_template_fields" |
| 416 | * @param $fields |
| 417 | * @param $template |
| 418 | * |
| 419 | * @return array |
| 420 | */ |
| 421 | function add_masonry_fields( $fields, $template ) { |
| 422 | //update specific fields |
| 423 | foreach ($fields as &$field) { |
| 424 | if ( 'hover_effect_caption_visibility' === $field['id'] |
| 425 | || 'caption_visibility_no_hover_effect' === $field['id'] ) { |
| 426 | //add a new choice for captions to show below the thumbs |
| 427 | $field['choices']['fg-captions-bottom'] = __( 'Below Thumbnail', 'foogallery' ); |
| 428 | $field['default'] = 'fg-captions-bottom'; |
| 429 | } else if ( 'theme' === $field['id'] ) { |
| 430 | $field['default'] = 'fg-dark'; |
| 431 | $field['choices'] = array( |
| 432 | 'fg-light' => __( 'Light', 'foogallery' ), |
| 433 | 'fg-dark' => __( 'Dark', 'foogallery' ), |
| 434 | 'fg-transparent' => __( 'Transparent', 'foogallery' ), |
| 435 | 'fg-custom' => __( 'Custom', 'foogallery' ) |
| 436 | ); |
| 437 | } else if ( 'drop_shadow' === $field['id'] ) { |
| 438 | $field['default'] = 'fg-shadow-small'; |
| 439 | } else if ( 'hover_effect_icon' === $field['id'] ) { |
| 440 | $field['default'] = 'fg-hover-plus'; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | return $fields; |
| 445 | } |
| 446 | |
| 447 | function remove_captions( $captions, $foogallery_attachment, $args ) { |
| 448 | global $current_foogallery_template; |
| 449 | |
| 450 | //check if masonry |
| 451 | if ( 'masonry' === $current_foogallery_template ) { |
| 452 | |
| 453 | $hover_effect_caption_visibility = foogallery_gallery_template_setting( 'hover_effect_caption_visibility', 'fg-caption-hover' ); |
| 454 | |
| 455 | //check if captions are set to show below the thumbs |
| 456 | if ( 'fg-captions-bottom' === $hover_effect_caption_visibility ) { |
| 457 | //if we have no captions then do not output captions at all |
| 458 | if ( !array_key_exists( 'title', $captions ) && !array_key_exists( 'desc', $captions ) ) { |
| 459 | $captions = false; |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | return $captions; |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * Return an array of field defaults for the template |
| 469 | * |
| 470 | * @param $field_defaults |
| 471 | * |
| 472 | * @return string[] |
| 473 | */ |
| 474 | function field_defaults( $field_defaults ) { |
| 475 | return array_merge( $field_defaults, array( |
| 476 | 'theme' => 'fg-light', |
| 477 | 'hover_effect_caption_visibility' => 'fg-captions-bottom', |
| 478 | 'caption_visibility_no_hover_effect' => 'fg-captions-bottom', |
| 479 | 'border_size' => 'fg-border-medium', |
| 480 | 'drop_shadow' => 'fg-shadow-outline', |
| 481 | 'rounded_corners' => 'fg-round-small', |
| 482 | 'inner_shadow' => '', |
| 483 | 'hover_effect_icon' => 'fg-hover-zoom4', |
| 484 | 'hover_effect_scale' => 'fg-hover-semi-zoomed', |
| 485 | 'captions_limit_length' => 'clamp', |
| 486 | 'caption_title_clamp' => '1', |
| 487 | 'caption_desc_clamp' => '2', |
| 488 | ) ); |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Add css to the page for the gallery |
| 493 | * |
| 494 | * @param $gallery FooGallery |
| 495 | */ |
| 496 | function add_css( $css, $gallery ) { |
| 497 | |
| 498 | $id = $gallery->container_id(); |
| 499 | $layout = foogallery_gallery_template_setting( 'layout', 'fixed' ); |
| 500 | $gutter_width = intval( foogallery_gallery_template_setting( 'gutter_width', 10 ) ); |
| 501 | |
| 502 | //get out early if the layout is not fixed |
| 503 | if ( 'fixed' === $layout ) { |
| 504 | $thumbnail_width = intval( foogallery_gallery_template_setting( 'thumbnail_width', 250 ) ); |
| 505 | $css[] = '#' . $id . '.fg-masonry .fg-item { width: ' . $thumbnail_width . 'px; }'; |
| 506 | } else { |
| 507 | $gutter_percent = foogallery_gallery_template_setting( 'gutter_percent', '' ); |
| 508 | if ( 'fg-gutter-none' === $gutter_percent ) { |
| 509 | $gutter_width = 0; |
| 510 | } else if ( 'fg-gutter-large' === $gutter_percent ) { |
| 511 | $gutter_width = 20; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | $css[] = '#' . $id . '.fg-masonry { --fg-gutter: ' . $gutter_width . 'px; }'; |
| 516 | |
| 517 | $mobile_gutter_width = null; |
| 518 | if ( 'fixed' === $layout ) { |
| 519 | $mobile_gutter = foogallery_gallery_template_setting( 'mobile_gutter_width', null ); |
| 520 | if ( is_scalar( $mobile_gutter ) && is_numeric( trim( (string) $mobile_gutter ) ) ) { |
| 521 | $mobile_gutter_width = max( 0, min( 100, intval( $mobile_gutter ) ) ); |
| 522 | } |
| 523 | } else { |
| 524 | $mobile_gutter = foogallery_gallery_template_setting( 'mobile_gutter_percent', null ); |
| 525 | if ( 'fg-gutter-none' === $mobile_gutter ) { |
| 526 | $mobile_gutter_width = 0; |
| 527 | } elseif ( 'fg-gutter-large' === $mobile_gutter ) { |
| 528 | $mobile_gutter_width = 20; |
| 529 | } elseif ( '' === $mobile_gutter ) { |
| 530 | $mobile_gutter_width = 10; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | if ( null !== $mobile_gutter_width ) { |
| 535 | $mobile_rule = '#' . $id . '.fg-masonry { --fg-gutter: ' . $mobile_gutter_width . 'px; }'; |
| 536 | $css[] = '@media only screen and (max-width: ' . foogallery_get_mobile_size() . 'px) { ' . $mobile_rule . ' }'; |
| 537 | $css[] = '.foogallery-preview-wrapper.viewport-mobile ' . $mobile_rule; |
| 538 | } |
| 539 | |
| 540 | if ( 'fixed' === $layout ) { |
| 541 | $mobile_thumbnail_width = foogallery_gallery_template_setting( 'mobile_thumbnail_width', null ); |
| 542 | if ( is_scalar( $mobile_thumbnail_width ) && is_numeric( trim( (string) $mobile_thumbnail_width ) ) ) { |
| 543 | $mobile_thumbnail_width = max( 0, intval( $mobile_thumbnail_width ) ); |
| 544 | $mobile_rule = '#' . $id . '.fg-masonry .fg-item { width: ' . $mobile_thumbnail_width . 'px; }'; |
| 545 | $css[] = '@media only screen and (max-width: ' . foogallery_get_mobile_size() . 'px) { ' . $mobile_rule . ' }'; |
| 546 | $css[] = '.foogallery-preview-wrapper.viewport-mobile ' . $mobile_rule; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return $css; |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 |