| 1 |
<?php |
| 2 |
/** |
| 3 |
* Social profile class for Smart Post Show Blocks. |
| 4 |
* |
| 5 |
* @package Smart_Post_Show_Pro |
| 6 |
* @subpackage Smart_Post_Show_Pro/blocks/includes |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SmartPostShow\Blocks; |
| 10 |
|
| 11 |
use SmartPostShow\Blocks\Helper; |
| 12 |
|
| 13 |
use SmartPostShow\Blocks\Block_Base; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Social Profile Item Block Class. |
| 21 |
*/ |
| 22 |
class Social_Profile_Item extends Block_Base { |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Set_block_properties |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
protected function set_block_properties() { |
| 31 |
$this->block_name = 'social-profile-item'; |
| 32 |
$this->styles = array( 'sp_smart_post_blocks_social_icons_style', 'sp_smart_post_blocks_google_fonts' ); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* Render Social Profile Item block. |
| 38 |
* |
| 39 |
* @param array $attributes Block attributes. |
| 40 |
* @param string $content Block content. |
| 41 |
* @param array $blocks Inner blocks. |
| 42 |
* @return $content. |
| 43 |
*/ |
| 44 |
public function render_block( $attributes, $content = '', $blocks = array() ) { |
| 45 |
if ( Helper::is_editor_page() ) { |
| 46 |
return $content; |
| 47 |
} |
| 48 |
$attributes['page_id'] = get_the_ID(); |
| 49 |
|
| 50 |
// Attributes for Social Profile Item. |
| 51 |
$sp_block_name = $attributes['blockName'] ?? ''; |
| 52 |
$sp_unique_id = $attributes['uniqueId'] ?? ''; |
| 53 |
$social_link_relation = isset( $attributes['socialSingleLinkRelation'] ) ? $attributes['socialSingleLinkRelation'] : ''; |
| 54 |
$social_icon_type = isset( $attributes['socialSingleIconType'] ) ? $attributes['socialSingleIconType'] : ''; |
| 55 |
$icon_enable = isset( $attributes['iconEnableParent'] ) ? $attributes['iconEnableParent'] : false; |
| 56 |
$social_icon = isset( $attributes['socialSingleIcon'] ) ? $attributes['socialSingleIcon'] : ''; |
| 57 |
$social_image = isset( $attributes['socialSingleImage'] ) ? $attributes['socialSingleImage'] : ''; |
| 58 |
$layout = isset( $attributes['layoutParent'] ) ? $attributes['layoutParent'] : ''; |
| 59 |
$social_label = isset( $attributes['socialSingleLabel'] ) ? $attributes['socialSingleLabel'] : ''; |
| 60 |
$social_sub_text = isset( $attributes['socialSingleSubText'] ) ? $attributes['socialSingleSubText'] : ''; |
| 61 |
$label_enable = isset( $attributes['labelEnableParent'] ) ? $attributes['labelEnableParent'] : false; |
| 62 |
$sub_text_enable = isset( $attributes['subTextEnableParent'] ) ? $attributes['subTextEnableParent'] : false; |
| 63 |
$sp_social_link = isset( $attributes['socialSingleLink'] ) ? $attributes['socialSingleLink'] : ''; |
| 64 |
$sp_link_target = isset( $attributes['socialSingleLinkOpen'] ) ? $attributes['socialSingleLinkOpen'] : ''; |
| 65 |
$align_class = isset( $attributes['align'] ) ? 'align' . $attributes['align'] : ''; |
| 66 |
|
| 67 |
$additional_css_class = $attributes['additionalCssClass'] ?? ''; |
| 68 |
$container_class = $align_class . ( $additional_css_class === '' ? '' : ' ' . $additional_css_class ); |
| 69 |
|
| 70 |
$label_class = 'sp-social-profile-item-label ' . ( |
| 71 |
$attributes['socialLabelGlobalTypographyParent']['class'] ?? '' |
| 72 |
); |
| 73 |
|
| 74 |
$sub_text_class = 'sp-social-profile-item-sub-text ' . ( |
| 75 |
$attributes['socialSubTextGlobalTypographyParent']['class'] ?? '' |
| 76 |
); |
| 77 |
|
| 78 |
ob_start(); |
| 79 |
?> |
| 80 |
<div class="<?php echo esc_attr( $container_class ); ?>"> |
| 81 |
<div |
| 82 |
id="<?php echo esc_attr( $sp_unique_id ); ?>" class="sp-social-profile-item-container"> |
| 83 |
<a class="sp-social-profile-item-wrapper" href="<?php echo esc_url( $sp_social_link ); ?>" target="<?php echo esc_attr( $sp_link_target ); ?>" rel="<?php echo esc_attr( $social_link_relation ); ?>"> |
| 84 |
<div class="sp-social-profile-item"> |
| 85 |
<!-- Social Profile Single Item Icon/Image --> |
| 86 |
<?php if ( 'none' !== $social_icon_type && $icon_enable ) : ?> |
| 87 |
<div class="sp-social-profile-item-icon-wrapper"> |
| 88 |
<?php if ( 'icon' === $social_icon_type ) : ?> |
| 89 |
<div class="sp-social-profile-item-icon sp-social-icon-<?php echo esc_attr( $social_icon ); ?>"> |
| 90 |
<i class="sp-icon-<?php echo esc_attr( $social_icon ); ?> sp-social-profile-item-icon-class"></i> |
| 91 |
</div> |
| 92 |
<?php endif; ?> |
| 93 |
<?php if ( 'image' === $social_icon_type && ! empty( $social_image ) ) : ?> |
| 94 |
<div class="sp-social-profile-item-image"> |
| 95 |
<img |
| 96 |
src="<?php echo esc_url( $social_image['url'] ); ?>" |
| 97 |
alt="<?php echo esc_attr( $social_image['alt'] ); ?>" |
| 98 |
class="sp-social-image wp-image" /> |
| 99 |
</div> |
| 100 |
<?php endif; ?> |
| 101 |
</div> |
| 102 |
<?php endif; ?> |
| 103 |
<?php if ( 'social-profiles-layout-three' === $layout ) : ?> |
| 104 |
<span class="sp-social-profile-icon-divider"></span> |
| 105 |
<?php endif; ?> |
| 106 |
|
| 107 |
<?php if ( ! empty( trim( $social_label ) ) || ! empty( trim( $social_sub_text ) ) ) : ?> |
| 108 |
<div class="sp-social-profile-item-text"> |
| 109 |
<?php if ( ! empty( trim( $social_label ) ) && $label_enable ) : ?> |
| 110 |
<span class="<?php echo esc_attr( $label_class ); ?>"> |
| 111 |
<?php echo wp_kses_post( $social_label ); ?> |
| 112 |
</span> |
| 113 |
<?php endif; ?> |
| 114 |
<?php if ( ! empty( trim( $social_sub_text ) ) && $sub_text_enable ) : ?> |
| 115 |
<span class="<?php echo esc_attr( $sub_text_class ); ?>"> |
| 116 |
<?php echo wp_kses_post( $social_sub_text ); ?> |
| 117 |
</span> |
| 118 |
<?php endif; ?> |
| 119 |
</div> |
| 120 |
<?php endif; ?> |
| 121 |
</div> |
| 122 |
</a> |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
<?php |
| 126 |
return ob_get_clean(); |
| 127 |
} |
| 128 |
} |
| 129 |
|