PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.2
Kubio AI Page Builder v2.8.2
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / build / block-library / blocks / logo / index.php
kubio / build / block-library / blocks / logo Last commit date
block.json 1 year ago default.json 4 years ago index.php 1 year ago
index.php
147 lines
1 <?php
2
3 namespace Kubio\Blocks;
4
5 use Kubio\Core\Blocks\BlockBase;
6 use Kubio\Core\Utils;
7 use Kubio\Core\Registry;
8
9 class LogoBlock extends BlockBase {
10 const CONTAINER = 'container';
11 const IMAGE = 'image';
12 const ALTERNATE_IMAGE = 'alternateImage';
13 const TEXT = 'text';
14
15 private $direction_classes = array(
16 'image' => 'kubio-logo-direction-row kubio-logo-without-text',
17 'text' => 'kubio-logo-direction-row',
18 'imageLeft' => 'kubio-logo-direction-row',
19 'imageRight' => 'kubio-logo-direction-row-reverse',
20 'imageBelow' => 'kubio-logo-direction-column-reverse',
21 'imageAbove' => 'kubio-logo-direction-column',
22 );
23
24 private $imageShowData = array(
25 'image' => array(
26 'showImage' => true,
27 'showAlternateImage' => true,
28 ),
29 'text' => array(
30 'showImage' => false,
31 'showAlternateImage' => false,
32 ),
33 'imageBelow' => array(
34 'showImage' => true,
35 'showAlternateImage' => true,
36 ),
37 'imageAbove' => array(
38 'showImage' => true,
39 'showAlternateImage' => true,
40 ),
41 'imageRight' => array(
42 'showImage' => true,
43 'showAlternateImage' => true,
44 ),
45 'imageLeft' => array(
46 'showImage' => true,
47 'showAlternateImage' => true,
48 ),
49 );
50
51 public function computed() {
52 $iconEnabled = $this->getProp( 'showIcon', false );
53 $iconPosition = $this->getProp( 'iconPosition', 'before' );
54 $layout_type = $this->getProp( 'layoutType', 'image' );
55 $showBeforeIcon = $iconEnabled && $iconPosition === 'before';
56 $showAfterIcon = $iconEnabled && $iconPosition === 'after';
57
58 return array(
59 'showBeforeIcon' => $showBeforeIcon,
60 'showAfterIcon' => $showAfterIcon,
61 'layout_type' => $layout_type,
62 'showNormalImage' => $this->imageShowData[ $layout_type ]['showImage'],
63 'showAlternateImage' => $this->imageShowData[ $layout_type ]['showAlternateImage'],
64 );
65 }
66
67 public function mapPropsToElements() {
68 $computed = $this->computed();
69 if ( $computed['layout_type'] === 'image' ) {
70 $text = '';
71 } else {
72 $text = \get_bloginfo( 'name' );
73 }
74
75 if ( $computed['layout_type'] === 'text' ) {
76 $image_src = '';
77 $alternate_image_src = '';
78 } else {
79 $image_src = $this->getImageLogoUrl();
80 $alternate_image_src = $this->getAlternateImageLogoUrl();
81 }
82
83 $link_data = array();
84 if ( $this->getAttribute( 'linkTo' ) === 'homePage' ) {
85 $href = '';
86 if ( kubio_wpml_is_active() ) {
87 $href = apply_filters( 'wpml_home_url', site_url() );
88 } else {
89 $href = site_url();
90 }
91 $link_data = array(
92 'href' => $href,
93 );
94 } else {
95 $link_data = Utils::getLinkAttributes( $this->getAttribute( 'link' ) );
96 }
97
98 $map[ self::CONTAINER ] = array_merge(
99 array(
100 'className' => array(
101 $this->direction_classes[ $computed['layout_type'] ],
102 $this->getAttribute( 'mode', 'default' ),
103 ),
104 ),
105 $link_data
106 );
107
108 if ( $this->imageShowData[ $computed['layout_type'] ]['showImage'] ) {
109 $map[ self::IMAGE ] = array(
110 'alt' => esc_attr( $this->getAttribute( 'alt', '' ) ),
111 'src' => esc_url( $image_src ),
112 );
113 }
114
115 if ( $this->imageShowData[ $computed['layout_type'] ]['showImage'] ) {
116 $map[ self::ALTERNATE_IMAGE ] = array(
117 'alt' => esc_attr( $this->getAttribute( 'alt', '' ) ),
118 'src' => esc_url( $alternate_image_src ),
119 );
120 }
121
122 $map[ self::TEXT ] = array(
123 'innerHTML' => wp_kses_post( $text ),
124 );
125 return $map;
126 }
127
128 private function getImageLogoUrl() {
129 $custom_logo_id = get_theme_mod( 'custom_logo', false );
130 if ( ! $custom_logo_id ) {
131 $placeholder = kubio_url( '/static/default-assets/logo-fallback.png' );
132 return $placeholder;
133 }
134 return wp_get_attachment_image_url( $custom_logo_id, 'full' );
135 }
136
137 private function getAlternateImageLogoUrl() {
138 $alternateImage = kubio_get_global_data( 'alternateLogo' );
139 if ( $alternateImage ) {
140 return $alternateImage;
141 }
142 return $this->getImageLogoUrl();
143 }
144 }
145
146 Registry::registerBlock( __DIR__, LogoBlock::class );
147