PluginProbe
Getwid – Gutenberg Blocks / 2.0.10
Getwid – Gutenberg Blocks v2.0.10
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
getwid / includes / blocks / template-parts / post-date.php

post-date.php in Getwid – Gutenberg Blocks 2.0.10, at includes/blocks/template-parts/post-date.php

177 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 class PostDate extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-date';
8 protected static $assetsHandle = 'getwid/template-parts';
9
10 public function __construct() {
11
12 parent::__construct( self::$blockName );
13
14 register_block_type(
15 self::$blockName,
16 array(
17 'attributes' => array(
18 'blockDivider' => array(
19 'type' => 'string'
20 ),
21
22 //Colors
23 'textColor' => array(
24 'type' => 'string'
25 ),
26 'customTextColor' => array(
27 'type' => 'string'
28 ),
29 'backgroundColor' => array(
30 'type' => 'string'
31 ),
32 'customBackgroundColor' => array(
33 'type' => 'string'
34 ),
35
36 //Colors
37 'icon' => array(
38 'type' => 'string',
39 'default' => 'fas fa-calendar'
40 ),
41 'iconColor' => array(
42 'type' => 'string'
43 ),
44 'customIconColor' => array(
45 'type' => 'string'
46 ),
47 'fontSize' => array(
48 'type' => 'string'
49 ),
50 'customFontSize' => array(
51 'type' => 'string'
52 ),
53 'bold' => array(
54 'type' => 'boolean',
55 'default' => false
56 ),
57 'italic' => array(
58 'type' => 'boolean',
59 'default' => false
60 ),
61 'textAlignment' => array(
62 'type' => 'string'
63 ),
64 'className' => array(
65 'type' => 'string'
66 )
67 ),
68 'render_callback' => [ $this, 'render_callback' ]
69 )
70 );
71 }
72
73 public function block_frontend_assets() {
74
75 if ( is_admin() ) {
76 return;
77 }
78
79 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
80 return;
81 }
82
83 add_filter( 'getwid/optimize/assets',
84 function ( $assets ) {
85 $assets[] = self::$assetsHandle;
86
87 return $assets;
88 }
89 );
90
91 $rtl = is_rtl() ? '.rtl' : '';
92
93 wp_enqueue_style(
94 self::$assetsHandle,
95 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
96 [],
97 getwid()->settings()->getVersion()
98 );
99 }
100
101 public function render_callback( $attributes, $content ) {
102
103 //Not BackEnd render if we view from template page
104 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
105 return $content;
106 }
107
108 $block_name = 'wp-block-getwid-template-post-date';
109 $wrapper_class = $block_name;
110
111 if ( isset( $attributes[ 'className' ] ) ) {
112 $wrapper_class .= ' ' . esc_attr( $attributes[ 'className' ] );
113 }
114
115 $wrapper_style = '';
116 //Classes
117 if ( isset( $attributes[ 'textAlignment' ] ) ) {
118 $wrapper_style .= 'text-align: ' . esc_attr( $attributes[ 'textAlignment' ] ) . ';';
119 }
120 if ( isset( $attributes[ 'bold' ] ) && $attributes[ 'bold' ] ) {
121 $wrapper_style .= 'font-weight: bold;';
122 }
123 if ( isset( $attributes[ 'italic' ]) && $attributes[ 'italic' ] ) {
124 $wrapper_style .= 'font-style: italic;';
125 }
126
127 if ( isset( $attributes[ 'customFontSize' ] ) ) {
128 $font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize'];
129 $wrapper_style .= 'font-size: '.esc_attr( $font_size ) . ';';
130 }
131
132 if ( isset($attributes[ 'fontSize' ] ) ) {
133 $wrapper_class .= ' has-' . esc_attr( $attributes[ 'fontSize' ] ) . '-font-size';
134 }
135
136 $archive_year = get_the_time( 'Y' );
137 $archive_month = get_the_time( 'm' );
138 $archive_day = get_the_time( 'd' );
139
140 $is_back_end = getwid_is_block_editor();
141
142 //Link style & class
143 getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end );
144
145 $icon_class = '';
146 $icon_style = '';
147 getwid_custom_color_style_and_class( $icon_style, $icon_class, $attributes, 'color', $is_back_end, [ 'color' => 'iconColor', 'custom' => 'customIconColor' ] );
148
149 $result = '';
150
151 $extra_attr = array(
152 'wrapper_class' => $wrapper_class,
153 'wrapper_style' => $wrapper_style,
154 'archive_year' => $archive_year,
155 'archive_month' => $archive_month,
156
157 'archive_day' => $archive_day,
158 'icon_class' => $icon_class,
159 'icon_style' => $icon_style
160 );
161
162 if ( get_the_date() ) {
163 ob_start();
164
165 getwid_get_template_part( 'template-parts/post-date', $attributes, false, $extra_attr );
166
167 $result = ob_get_clean();
168 }
169
170 $this->block_frontend_assets();
171
172 return $result;
173 }
174 }
175
176 new \Getwid\Blocks\PostDate();
177