| 1 |
<?php |
| 2 |
class BBlocksFlipBoxes extends BBlocks{ |
| 3 |
public function __construct(){ |
| 4 |
add_action( 'init', [$this, 'register'] ); |
| 5 |
} |
| 6 |
|
| 7 |
function register(){ |
| 8 |
$this::registerScripts( 'flip-boxes', 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 |
'boxes' => array( 'type' => 'array', 'default' => array( |
| 20 |
array( |
| 21 |
'frontBG' => array(), |
| 22 |
'backBG' => array(), |
| 23 |
'border' => array(), |
| 24 |
'shadow' => array(), |
| 25 |
|
| 26 |
'frontIcon' => array( 'class' => 'fa fa-sync-alt', 'fontSize' => 70, 'color' => '#fff' ), |
| 27 |
'backIcon' => array( 'class' => 'fa fa-wordpress', 'fontSize' => 70, 'color' => '#fff' ), |
| 28 |
|
| 29 |
'frontTitle' => 'Front Title 1', |
| 30 |
'backTitle' => 'Back Title 1', |
| 31 |
'titleColor' => '#fff', |
| 32 |
|
| 33 |
'desc' => 'This content area describes flip box 1 descriptions/details.', |
| 34 |
'descColor' => '#fff', |
| 35 |
|
| 36 |
'btn' => 'Button 1', |
| 37 |
'btnLink' => '#', |
| 38 |
'btnBorder' => array( 'radius' => '3px' ), |
| 39 |
'btnColors' => array( 'color' => '#fff', 'bg' => '#ff4500' ), |
| 40 |
'btnHovColors' => array( 'color' => '#fff', 'bg' => '#ff7500' ) |
| 41 |
), |
| 42 |
array( |
| 43 |
'frontBG' => array(), |
| 44 |
'backBG' => array(), |
| 45 |
'border' => array(), |
| 46 |
'shadow' => array(), |
| 47 |
|
| 48 |
'frontIcon' => array( 'class' => 'fa fa-sync-alt', 'fontSize' => 70, 'color' => '#fff' ), |
| 49 |
'backIcon' => array( 'class' => 'fa fa-wordpress', 'fontSize' => 70, 'color' => '#fff' ), |
| 50 |
|
| 51 |
'frontTitle' => 'Front Title 2', |
| 52 |
'backTitle' => 'Back Title 2', |
| 53 |
'titleColor' => '#fff', |
| 54 |
|
| 55 |
'desc' => 'This content area describes flip box 2 descriptions/details.', |
| 56 |
'descColor' => '#fff', |
| 57 |
|
| 58 |
'btn' => 'Button 2', |
| 59 |
'btnLink' => '#', |
| 60 |
'btnBorder' => array( 'radius' => '3px' ), |
| 61 |
'btnColors' => array( 'color' => '#fff', 'bg' => '#ff4500' ), |
| 62 |
'btnHovColors' => array( 'color' => '#fff', 'bg' => '#ff7500' ) |
| 63 |
), |
| 64 |
array( |
| 65 |
'frontBG' => array(), |
| 66 |
'backBG' => array(), |
| 67 |
'border' => array(), |
| 68 |
'shadow' => array(), |
| 69 |
|
| 70 |
'frontIcon' => array( 'class' => 'fa fa-sync-alt', 'fontSize' => 70, 'color' => '#fff' ), |
| 71 |
'backIcon' => array( 'class' => 'fa fa-wordpress', 'fontSize' => 70, 'color' => '#fff' ), |
| 72 |
|
| 73 |
'frontTitle' => 'Front Title 3', |
| 74 |
'backTitle' => 'Back Title 3', |
| 75 |
'titleColor' => '#fff', |
| 76 |
|
| 77 |
'desc' => 'This content area describes flip box 3 descriptions/details.', |
| 78 |
'descColor' => '#fff', |
| 79 |
|
| 80 |
'btn' => 'Button 3', |
| 81 |
'btnLink' => '#', |
| 82 |
'btnBorder' => array( 'radius' => '3px' ), |
| 83 |
'btnColors' => array( 'color' => '#fff', 'bg' => '#ff4500' ), |
| 84 |
'btnHovColors' => array( 'color' => '#fff', 'bg' => '#ff7500' ) |
| 85 |
), |
| 86 |
) ), |
| 87 |
|
| 88 |
'columns' => array( 'type' => 'object', 'default' => array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 ) ), |
| 89 |
|
| 90 |
'columnGap' => array( 'type' => 'string', 'default' => '40px' ), |
| 91 |
'rowGap' => array( 'type' => 'string', 'default' => '30px' ), |
| 92 |
|
| 93 |
'boxHeight' => array( 'type' => 'string', 'default' => '400px' ), |
| 94 |
'textAlign' => array( 'type' => 'string', 'default' => 'center' ), |
| 95 |
'boxPadding' => array( 'type' => 'object', 'default' => array( 'vertical' => '30px', 'horizontal' => '25px' ) ), |
| 96 |
|
| 97 |
'isIcon' => array( 'type' => 'boolean', 'default' => true ), |
| 98 |
'iconMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '20px' ) ), |
| 99 |
'titleTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 25 ) ), |
| 100 |
'titleMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '20px' ) ), |
| 101 |
'isDesc' => array( 'type' => 'boolean', 'default' => true ), |
| 102 |
'descTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 16 ) ), |
| 103 |
'isBtn' => array( 'type' => 'boolean', 'default' => true ), |
| 104 |
'btnTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 16 ) ), |
| 105 |
'btnPadding' => array( 'type' => 'object', 'default' => array( 'vertical' => '15px', 'horizontal' => '25px' ) ) |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
function render( $attributes ){ |
| 110 |
extract( $attributes ); |
| 111 |
|
| 112 |
// Generate Styles |
| 113 |
$flipBoxesStyle = new BBlocksStyleGenerator(); |
| 114 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBoxes", array( |
| 115 |
'grid-gap' => "$rowGap $columnGap" |
| 116 |
) ); |
| 117 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBox", array( |
| 118 |
'height' => $boxHeight |
| 119 |
) ); |
| 120 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBox .box", array( |
| 121 |
'text-align' => $textAlign, |
| 122 |
'padding' => $boxPadding['styles'] ?? '30px 25px' |
| 123 |
) ); |
| 124 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBox .flipIcon", array( |
| 125 |
'margin' => $iconMargin['styles'] ?? '0 0 20px 0' |
| 126 |
) ); |
| 127 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBox .flipTitle", array( |
| 128 |
$titleTypo['styles'] ?? 'font-size: 25px;' => '', |
| 129 |
'margin' => $titleMargin['styles'] ?? '0 0 20px 0' |
| 130 |
) ); |
| 131 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBox .flipDescription", array( |
| 132 |
$descTypo['styles'] ?? 'font-size: 16px;' => '' |
| 133 |
) ); |
| 134 |
$flipBoxesStyle::addStyle( "#bBlocksFlipBoxes-$cId .bBlocksFlipBox .flipBtn", array( |
| 135 |
$btnTypo['styles'] ?? 'font-size: 16px;' => '', |
| 136 |
'padding' => $btnPadding['styles'] ?? '15px 25px' |
| 137 |
) ); |
| 138 |
|
| 139 |
ob_start(); ?> |
| 140 |
<div class='wp-block-b-blocks-flip-boxes <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksFlipBoxes-<?php echo esc_attr( $cId ); ?>'> |
| 141 |
<style> |
| 142 |
@import url(<?php echo esc_url( $titleTypo['googleFontLink'] ?? '' ); ?>); |
| 143 |
@import url(<?php echo esc_url( $descTypo['googleFontLink'] ?? '' ); ?>); |
| 144 |
@import url(<?php echo esc_url( $btnTypo['googleFontLink'] ?? '' ); ?>); |
| 145 |
<?php echo wp_kses( $flipBoxesStyle::renderStyle(), array() ); ?> |
| 146 |
</style> |
| 147 |
|
| 148 |
<div class='bBlocksFlipBoxes columns-<?php echo esc_attr( $columns['desktop'] ); ?> columns-tablet-<?php echo esc_attr( $columns['tablet'] ); ?> columns-mobile-<?php echo esc_attr( $columns['mobile'] ); ?>'> |
| 149 |
<?php foreach ( $boxes as $index => $box ) { |
| 150 |
extract( $box ); |
| 151 |
|
| 152 |
$flipBoxStyle = new BBlocksStyleGenerator(); |
| 153 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .box", array( |
| 154 |
$border['styles'] ?? '' => '', |
| 155 |
'box-shadow' => $shadow['styles'] ?? 'none' |
| 156 |
) ); |
| 157 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .box.front", array( |
| 158 |
$frontBG['styles'] ?? 'background-color: #000000b3;' => '' |
| 159 |
) ); |
| 160 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .box.back", array( |
| 161 |
$backBG['styles'] ?? 'background-color: #000000b3;' => '' |
| 162 |
) ); |
| 163 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .flipIcon.frontIcon", array( |
| 164 |
$frontIcon['styles'] ?? 'font-size: 70px; color: #fff;' => '' |
| 165 |
) ); |
| 166 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .flipIcon.backIcon", array( |
| 167 |
$backIcon['styles'] ?? 'font-size: 70px; color: #fff;' => '' |
| 168 |
) ); |
| 169 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .flipTitle", array( |
| 170 |
'color' => $titleColor |
| 171 |
) ); |
| 172 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .flipDescription", array( |
| 173 |
'color' => $descColor |
| 174 |
) ); |
| 175 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .flipBtn", array( |
| 176 |
$btnColors['styles'] ?? 'color: #fff; background: #ff4500;' => '', |
| 177 |
$btnBorder['styles'] ?? 'border-radius: 3px;' => '' |
| 178 |
) ); |
| 179 |
$flipBoxStyle::addStyle( "#bBlocksFlipBoxes-$cId #bBlocksFlipBox-$index .flipBtn:hover", array( |
| 180 |
$btnHovColors['styles'] ?? 'color: #fff; background: #ff7500;' => '' |
| 181 |
) ); ?> |
| 182 |
|
| 183 |
<div class='bBlocksFlipBox' id='bBlocksFlipBox-<?php echo esc_attr( $index ); ?>'> |
| 184 |
<style><?php echo wp_kses( $flipBoxStyle::renderStyle(), array() ); ?></style> |
| 185 |
|
| 186 |
<div class='box front'> |
| 187 |
<div class='frontContent'> |
| 188 |
<?php echo $isIcon && $frontIcon['class'] ? "<i class='flipIcon frontIcon ". esc_html( $frontIcon['class'] ) ."'></i>" : ''; ?> |
| 189 |
|
| 190 |
<?php echo $frontTitle ? "<h3 class='flipTitle flipFrontTitle'>". wp_kses_post( $frontTitle ) ."</h3>" : ''; ?> |
| 191 |
|
| 192 |
<?php echo $isDesc && $desc ? "<p class='flipDescription'>". wp_kses_post( $desc ) ."</p>" : ''; ?> |
| 193 |
</div> |
| 194 |
</div> |
| 195 |
|
| 196 |
<div class='box back'> |
| 197 |
<div class='backContent'> |
| 198 |
<?php echo $isIcon && $backIcon['class'] ? "<i class='flipIcon backIcon ". esc_html( $backIcon['class'] ) ."'></i>" : ''; ?> |
| 199 |
|
| 200 |
<?php echo $backTitle ? "<h3 class='flipTitle flipBackTitle'>". wp_kses_post( $backTitle ) ."</h3>" : ''; ?> |
| 201 |
|
| 202 |
<?php echo $isBtn && $btn ? "<a href='". esc_attr( $btnLink ) ."' class='flipBtn' target='_blank' rel='noreferrer noopener'>". wp_kses_post( $btn ) ."</a>" : ''; ?> |
| 203 |
</div> |
| 204 |
</div> |
| 205 |
</div> |
| 206 |
<?php $flipBoxStyle::$styles = array(); } ?> |
| 207 |
</div> |
| 208 |
</div> |
| 209 |
|
| 210 |
<?php $flipBoxesStyle::$styles = array(); // Empty styles |
| 211 |
return ob_get_clean(); |
| 212 |
} |
| 213 |
} |
| 214 |
new BBlocksFlipBoxes(); |