PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.3
Post Grid Gutenberg Blocks – PostX v4.1.3
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / blocks / Image.php

Image.php in Post Grid Gutenberg Blocks – PostX 4.1.3, at blocks/Image.php

115 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Image {
7
8 public function __construct() {
9 add_action( 'init', array( $this, 'register' ) );
10 }
11 public function get_attributes() {
12 return array(
13 'blockId' => '',
14 'previewImg' => '',
15 // Image Settings
16 'imageUpload' => (object)[ 'id'=>'999999', 'url' => ULTP_URL.'assets/img/ultp-placeholder.jpg' ],
17 'darkImgEnable' => false,
18 'darkImage' => (object)[ 'id'=>'999999', 'url' => ULTP_URL.'assets/img/ultp-placeholder.jpg' ],
19 'linkType' => 'link',
20 'imgLink' => '',
21 'linkTarget' => '_blank',
22 'imgAlt' => 'Image',
23 'imgAlignment' => ['lg' => 'left'],
24 'imgCrop' => 'full',
25 'imgAnimation' => 'none',
26 'imgMargin' => (object)['lg'=>''],
27 'imgOverlay' => false,
28 'imgOverlayType' => 'default',
29 'imgSrcset' => false,
30 'imgLazy' => false,
31 // Heading Setting/Style
32 'headingText' => 'This is a Image Example',
33 'headingEnable' => false,
34 'alignment' => ['lg' => 'left'],
35 // Button Settings
36 'buttonEnable' => false,
37 'btnText' => 'Free Download',
38 'btnLink' => '#',
39 'btnTarget' => '_blank',
40 'btnPosition' => 'centerCenter',
41 // Style
42
43 'advanceId' => '',
44 'advanceZindex' => '',
45 'hideExtraLarge' => false,
46 'hideTablet' => false,
47 'hideMobile' => false,
48 'advanceCss' => '',
49 );
50 }
51
52 public function register() {
53 register_block_type( 'ultimate-post/image',
54 array(
55 'editor_script' => 'ultp-blocks-editor-script',
56 'editor_style' => 'ultp-blocks-editor-css',
57 'render_callback' => array( $this, 'content' )
58 )
59 );
60 }
61
62 public function content( $attr, $noAjax ) {
63 $attr = wp_parse_args( $attr, $this->get_attributes() );
64
65 $wraper_before = '';
66 $block_name = 'image';
67 $attr['headingShow'] = true;
68 $darkImageArr = (array)$attr['darkImage'];
69 $darkImg = [
70 'enable'=> $attr['darkImgEnable'],
71 'url'=> isset($darkImageArr['url']) ? $darkImageArr['url'] : ULTP_URL.'assets/img/ultp-placeholder.jpg',
72 'srcset' => $attr['imgSrcset'] ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($darkImageArr['id'])).'"' : ''
73 ];
74
75 $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : '';
76 $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : '';
77 $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : '';
78 $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : '';
79 $attr['imgAnimation'] = sanitize_html_class( $attr['imgAnimation'] );
80 $attr['imgOverlayType'] = sanitize_html_class( $attr['imgOverlayType'] );
81 $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags();
82 $attr['btnText'] = wp_kses($attr['btnText'], $allowed_html_tags);
83 $attr['headingText'] = wp_kses($attr['headingText'], $allowed_html_tags);
84
85
86 $wraper_before .= '<div '.($attr['advanceId'] ? 'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].''.($attr["align"] ? ' align' .$attr["align"]:'').''.($attr["className"] ?' '.$attr["className"]:'').'">';
87 $wraper_before .= '<div class="ultp-block-wrapper">';
88 $wraper_before .= '<figure class="ultp-image-block-wrapper">';
89 $wraper_before .= '<div class="ultp-image-block ultp-image-block-'.$attr['imgAnimation'].($attr["imgOverlay"] ? ' ultp-image-block-overlay ultp-image-block-'.$attr["imgOverlayType"] : '' ).'">';
90 // Single Image
91 $img_arr = (array)$attr['imageUpload'];
92 $img_url = ( isset($img_arr['size']) && isset($img_arr['size'][$attr['imgCrop']]) ) ? ( isset($img_arr['size'][$attr['imgCrop']]['url']) ? $img_arr['size'][$attr['imgCrop']]['url'] : $img_arr['size'][$attr['imgCrop']] ) : $img_arr['url'];
93 if ( ! empty( $img_arr ) ) {
94 $srcset_data = $attr['imgSrcset'] ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($img_arr['id'])).'"' : '';
95 if ( $attr['linkType'] == 'link' && $attr['imgLink'] ) {
96 $wraper_before .= '<a href="'.esc_url($attr['imgLink']).'" target="'.sanitize_html_class( $attr['linkTarget'] ).'">'.ultimate_post()->get_image_html($img_url, 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg, $srcset_data).'</a>';
97 } else {
98 // $wraper_before .= ultimate_post()->get_image_html($img_arr['url'], 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg);
99 $wraper_before .= ultimate_post()->get_image_html( $img_url, 'full', 'ultp-image', $attr['imgAlt'], $attr['imgLazy'], $darkImg, $srcset_data );
100 }
101 }
102 if ( $attr['btnLink'] && $attr['linkType'] == 'button' ) {
103 $wraper_before .= '<div class="ultp-image-button ultp-image-button-'.sanitize_html_class( $attr['btnPosition']).'"><a href="'.esc_url($attr['btnLink']).'" target="'.sanitize_html_class($attr['btnTarget']).'">'.$attr['btnText'].'</a></div>';
104 }
105 $wraper_before .= '</div>';
106 if ( $attr['headingEnable'] == 1 ) {
107 $wraper_before .= '<figcaption class="ultp-image-caption">'.$attr['headingText'].'</figcaption>';
108 }
109 $wraper_before .= '</figure>';
110 $wraper_before .= '</div>';
111 $wraper_before .= '</div>';
112
113 return $wraper_before;
114 }
115 }