| 1 |
<?php |
| 2 |
class BBlocksInfoBox extends BBlocks{ |
| 3 |
public function __construct(){ |
| 4 |
add_action( 'init', [$this, 'register'] ); |
| 5 |
} |
| 6 |
|
| 7 |
function register(){ |
| 8 |
$this::registerScripts( 'info-box', 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 |
'infoBoxAlign' => array( 'type' => 'string', 'default' => 'center' ), |
| 20 |
'textAlign' => array( 'type' => 'string', 'default' => 'center' ), |
| 21 |
|
| 22 |
'width' => array( 'type' => 'string', 'default' => '80%' ), |
| 23 |
'background' => array( 'type' => 'object', 'default' => array( 'color' => '#f1f7ff' ) ), |
| 24 |
'padding' => array( 'type' => 'object', 'default' => array( 'vertical' => '50px', 'horizontal' => '50px' ) ), |
| 25 |
'border' => array( 'type' => 'object', 'default' => array( 'width' => '10px', 'color' => '#fff', 'radius' => '5px' ) ), |
| 26 |
'shadow' => array( 'type' => 'object', 'default' => array( 'blur' => '15px' ) ), |
| 27 |
|
| 28 |
'isIcon' => array( 'type' => 'boolean', 'default' => true ), |
| 29 |
'icon' => array( 'type' => 'object', 'default' => array( 'class' => 'fa fa-info-circle', 'fontSize' => 70, 'color' => '#4527a4' ) ), |
| 30 |
'iconMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '20px' ) ), |
| 31 |
|
| 32 |
'title' => array( 'type' => 'string', 'selector' => 'h3.infoBoxTitle', 'default' => 'Info Box Title' ), |
| 33 |
'titleTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 25, 'fontWeight' => 600 ) ), |
| 34 |
'titleColor' => array( 'type' => 'string', 'default' => '#333' ), |
| 35 |
'titleMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ), |
| 36 |
|
| 37 |
'isDesc' => array( 'type' => 'boolean', 'default' => true ), |
| 38 |
'desc' => array( 'type' => 'string', 'selector' => 'p.infoBoxDescription', 'default' => 'This content area describes info box descriptions or details.' ), |
| 39 |
'descTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) ), |
| 40 |
'descColor' => array( 'type' => 'string', 'default' => '#333' ), |
| 41 |
'descMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '15px' ) ), |
| 42 |
|
| 43 |
'isBtn' => array( 'type' => 'boolean', 'default' => false ), |
| 44 |
'btn' => array( 'type' => 'string', 'selector' => 'a.infoBoxButton', 'default' => 'Click Me' ), |
| 45 |
'btnLink' => array( 'type' => 'string', 'default' => '#' ), |
| 46 |
'isLinkNewTab' => array( 'type' => 'boolean', 'default' => true ), |
| 47 |
'btnTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) ), |
| 48 |
'btnColors' => array( 'type' => 'object', 'default' => array( 'color' => '#fff', 'bg' => '#4527a4' ) ), |
| 49 |
'btnHovColors' => array( 'type' => 'object', 'default' => array( 'color' => '#fff', 'bg' => '#8344c5' ) ), |
| 50 |
'btnPadding' => array( 'type' => 'object', 'default' => array( 'vertical' => '8px', 'horizontal' => '15px' ) ), |
| 51 |
'btnBorder' => array( 'type' => 'object', 'default' => array( 'radius' => '5px' ) ) |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
function render( $attributes ){ |
| 56 |
extract( $attributes ); |
| 57 |
|
| 58 |
// Generate Styles |
| 59 |
$infoBoxStyle = new BBlocksStyleGenerator(); |
| 60 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId", array( |
| 61 |
'text-align' => $infoBoxAlign |
| 62 |
) ); |
| 63 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox", array( |
| 64 |
'text-align' => $textAlign, |
| 65 |
'width' => '0px' === $width || '0%' === $width || '0em' === $width ? '100%' : $width, |
| 66 |
$background['styles'] ?? 'background-color: #f1f7ff;' => '', |
| 67 |
'padding' => $padding['styles'] ?? '50px 50px', |
| 68 |
$border['styles'] ?? 'border: 10px solid #fff; border-radius: 5px;' => '', |
| 69 |
'box-shadow' => $shadow['styles'] ?? 'none' |
| 70 |
) ); |
| 71 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox .infoBoxIcon", array( |
| 72 |
'margin' => $iconMargin['styles'] ?? '0px 0px 20px 0px' |
| 73 |
) ); |
| 74 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox .infoBoxIcon i", array( |
| 75 |
$icon['styles'] ?? 'font-size: 70px; color: #4527a4;' => '' |
| 76 |
) ); |
| 77 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox .infoBoxTitle", array( |
| 78 |
$titleTypo['styles'] ?? 'font-size: 25px; font-weight: 600;' => '', |
| 79 |
'color' => $titleColor, |
| 80 |
'margin' => $titleMargin['styles'] ?? '0px 0px 10px 0px' |
| 81 |
) ); |
| 82 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox .infoBoxDescription", array( |
| 83 |
$descTypo['styles'] ?? 'font-size: 15px;' => '', |
| 84 |
'color' => $descColor, |
| 85 |
'margin' => $descMargin['styles'] ?? '0px 0px 15px 0px' |
| 86 |
) ); |
| 87 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox .infoBoxButton", array( |
| 88 |
$btnTypo['styles'] ?? 'font-size: 15px;' => '', |
| 89 |
$btnColors['styles'] ?? 'color: #fff; background: #4527a4;' => '', |
| 90 |
'padding' => $btnPadding['styles'] ?? '8px 15px', |
| 91 |
$btnBorder['styles'] ?? 'border-radius: 5px;' => '', |
| 92 |
) ); |
| 93 |
$infoBoxStyle::addStyle( "#bBlocksInfoBox-$cId .bBlocksInfoBox .infoBoxButton:hover", array( |
| 94 |
$btnHovColors['styles'] ?? 'color: #fff; background: #8344c5;' => '' |
| 95 |
) ); |
| 96 |
|
| 97 |
$btnTab = $isLinkNewTab ? '_blank' : ''; |
| 98 |
|
| 99 |
ob_start(); ?> |
| 100 |
<div class='wp-block-b-blocks-info-box <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksInfoBox-<?php echo esc_attr( $cId ); ?>'> |
| 101 |
<style> |
| 102 |
@import url(<?php echo esc_url( $titleTypo['googleFontLink'] ?? '' ); ?>); |
| 103 |
@import url(<?php echo esc_url( $descTypo['googleFontLink'] ?? '' ); ?>); |
| 104 |
@import url(<?php echo esc_url( $btnTypo['googleFontLink'] ?? '' ); ?>); |
| 105 |
<?php echo wp_kses( $infoBoxStyle::renderStyle(), array() ); ?> |
| 106 |
</style> |
| 107 |
|
| 108 |
<div class='bBlocksInfoBox'> |
| 109 |
<?php echo $isIcon && $icon['class'] ? "<div class='infoBoxIcon'><i class='". esc_html( $icon['class'] ) ."'></i></div>" : ''; ?> |
| 110 |
<?php echo $title ? "<h3 class='infoBoxTitle'>". wp_kses_post( $title ) ."</h3>" : ''; ?> |
| 111 |
<?php echo $isDesc && $desc ? "<p class='infoBoxDescription'>". wp_kses_post( $desc ) ."</p>" : ''; ?> |
| 112 |
<?php echo $isBtn && $btn ? "<a href='". esc_url( $btnLink ) ."' class='infoBoxButton' target='". esc_attr( $btnTab ) ."' rel='noreferrer noopener'>". wp_kses_post( $btn ) ."</a>" : ''; ?> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
<?php $infoBoxStyle::$styles = array(); // Empty styles |
| 116 |
return ob_get_clean(); |
| 117 |
} |
| 118 |
} |
| 119 |
new BBlocksInfoBox(); |