PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 1.5.3
bBlocks – Essential Gutenberg Blocks & Patterns Collection v1.5.3
2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 107 releases
b-blocks / inc / image-gallery.php

image-gallery.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 1.5.3, at inc/image-gallery.php

102 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class BBlocksImageGallery extends BBlocks{
3 public function __construct(){
4 add_action( 'init', [$this, 'register'] );
5 }
6
7 function register(){
8 $this::registerScripts( 'image-gallery', array(
9 'attributes' => $this->attributes(),
10 'render_callback' => [$this, 'render']
11 ) );
12 }
13
14 function attributes(){
15 return array(
16 'align' => array( 'type' => 'string', 'default' => '' ),
17 'cId' => array( 'type' => 'string', 'default' => '' ),
18
19 'images' => array( 'type' => 'array', 'default' => array() ),
20
21 'columns' => array( 'type' => 'object', 'default' => array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 ) ),
22
23 'imgPadding' => array( 'type' => 'object', 'default' => array() ),
24 'imgBorder' => array( 'type' => 'object', 'default' => array() ),
25 'imgShadow' => array( 'type' => 'object', 'default' => array() ),
26
27 'isCap' => array( 'type' => 'boolean', 'default' => true ),
28 'capAlign' => array( 'type' => 'string', 'default' => 'left' ),
29 'capColor' => array( 'type' => 'string', 'default' => '#333' ),
30 'capTitleTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 18 ) ),
31 'capDescTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) )
32 );
33 }
34
35 function render( $attributes ){
36 extract( $attributes );
37
38 // Generate Styles
39 $imgShadow = $imgShadow['styles'] ?? '';
40 $imgPaddingH = $imgPadding['horizontal'] ?? '0px';
41 $imgPaddingV = $imgPadding['vertical'] ?? '0px';
42
43 $imageGalleryStyle = new BBlocksStyleGenerator();
44 $imageGalleryStyle::addStyle( "#bBlocksImageGallery-$cId .imgGalleryWrapper .imgGalleryImgLink .imgGalleryImg", array(
45 'padding' => $imgPadding['styles'] ?? '0 0',
46 $imgBorder['styles'] ?? '' => '',
47 'filter' => "drop-shadow($imgShadow)"
48 ) );
49 $imageGalleryStyle::addStyle( "#bBlocksImageGallery-$cId .imgGalleryWrapper .imgGalleryImgLink .imgGalleryImgCaption", array(
50 'text-align' => $capAlign,
51 'color' => $capColor,
52 'margin' => $imgPadding['styles'] ?? '0 0',
53 'width' => "calc((100% - 10px) - ($imgPaddingH * 2) )",
54 'height' => "calc((100% - 10px) - ($imgPaddingV * 2) )",
55 'border-radius' => $imgBorder['radius'] ?? '0px'
56 ) );
57 $imageGalleryStyle::addStyle( "#bBlocksImageGallery-$cId .imgGalleryWrapper .imgGalleryImgLink .imgGalleryImgCaption h4", array(
58 $capTitleTypo['styles'] ?? 'font-size: 18px;' => ''
59 ) );
60 $imageGalleryStyle::addStyle( "#bBlocksImageGallery-$cId .imgGalleryWrapper .imgGalleryImgLink .imgGalleryImgCaption p", array(
61 $capDescTypo['styles'] ?? 'font-size: 15px;' => ''
62 ) );
63
64 ob_start(); ?>
65 <div class='wp-block-b-blocks-image-gallery <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksImageGallery-<?php echo esc_attr( $cId ); ?>'>
66 <style>
67 @import url(<?php echo esc_url( $capTitleTypo['googleFontLink'] ?? '' ); ?>);
68 @import url(<?php echo esc_url( $capDescTypo['googleFontLink'] ?? '' ); ?>);
69 <?php echo wp_kses( $imageGalleryStyle::renderStyle(), array() ); ?>
70 </style>
71
72 <div class='imgGalleryWrapper columns-<?php echo esc_attr( $columns['desktop'] ); ?> columns-tablet-<?php echo esc_attr( $columns['tablet'] ); ?> columns-mobile-<?php echo esc_attr( $columns['mobile'] ); ?>'>
73 <?php foreach ( $images as $image ) {
74 // Components
75 $imgDesc = isset( $image['description'] ) && $image['description'] ? "<p>". $image['description'] ."</p>" : '';
76 $imgCaption = $isCap && isset( $image['caption'] ) && $image['caption'] ? "<div class=imgGalleryImgCaption>
77 <div class='captionContent'>
78 <h4>". $image['caption'] ."</h4>
79 $imgDesc
80 </div>
81 </div>" : ''; ?>
82
83 <a class='imgGalleryImgLink'>
84 <img src='<?php echo esc_url( $image['url'] ); ?>' alt='' class='imgGalleryImg' />
85
86 <?php echo wp_kses( $imgCaption, array(
87 'div' => array(
88 'class' => array()
89 ),
90 'h4' => array(),
91 'p' => array()
92 ) ); ?>
93 </a>
94 <?php } ?>
95 </div>
96 </div>
97
98 <?php $imageGalleryStyle::$styles = array(); // Empty styles
99 return ob_get_clean();
100 }
101 }
102 new BBlocksImageGallery();