PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.41
Post Grid Gutenberg Blocks – PostX v5.0.41
5.0.41 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 All 238 releases
ultimate-post / addons / builder / blocks / Advance_Post_Meta.php

Advance_Post_Meta.php in Post Grid Gutenberg Blocks – PostX 5.0.41, at addons/builder/blocks/Advance_Post_Meta.php

327 lines 13.6 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 Advance_Post_Meta {
7 public function __construct() {
8 add_action( 'init', array( $this, 'register' ) );
9 }
10 public function get_attributes() {
11
12 return array(
13 'blockId' => '',
14 /*
15 ============================
16 Advanced Post Meta Settings
17 ============================*/
18 // META ITEM ENABLE
19 'authorShow' => true,
20 'dateShow' => true,
21 'cmtCountShow' => true,
22 'viewCountShow' => false,
23 'readTimeShow' => false,
24 'catShow' => false,
25 'tagShow' => false,
26 'metaSeparator' => 'dot',
27 'metaItemSort' => array( 'author', 'date', 'cmtCount', 'viewCount', 'readTime', 'cat', 'tag' ),
28
29 /*
30 ============================
31 Post Author Style
32 ============================*/
33 // Avatar
34 'authImgShow' => false,
35 // Author Label
36 'authLabelShow' => true,
37 'authLabel' => 'Author',
38 // Auth Icon
39 'authIconShow' => false,
40 'authIconStyle' => 'author1',
41 'authAlign' => false,
42
43 /*
44 ============================
45 Post Publish Time Style
46 ============================*/
47 'dateFormat' => 'updated',
48 'metaDateFormat' => 'M j, Y',
49 'dateColor' => '#a4a4a4',
50 // Prefix
51 'enablePrefix' => true,
52 'datePubText' => 'Publish Update',
53 'dateText' => 'Latest Update',
54 // Icon
55 'DateIconShow' => false,
56 'dateIconStyle' => 'date1',
57 'dateAlign' => false,
58
59 /*
60 ============================
61 Comment Style
62 ============================*/
63 // Prefix
64 'cmtLabelShow' => true,
65 'cmtLabel' => 'Comment',
66 // Icon
67 'cmtIconShow' => false,
68 'cmntIconStyle' => 'commentCount1',
69 'cmntAlign' => false,
70 // Prefix Style
71 'viewLabelShow' => true,
72 'viewLabel' => 'View',
73 // Icon
74 'viewIconShow' => false,
75 'viewIconStyle' => 'viewCount1',
76 'viewAlign' => false,
77
78 /*
79 ============================
80 Reading Time Style
81 ============================*/
82 // Prefix
83 'readTimePrefix' => true,
84 'readTimeText' => 'Minute Read',
85 'readPrefixAlign' => 'after',
86 // Icon
87 'readTimeIcon' => false,
88 'readIconStyle' => 'readingTime2',
89 'readAlign' => false,
90
91 /*
92 ============================
93 Categories Style
94 ============================*/
95 'catLabelShow' => true,
96 'catLabel' => 'Category',
97 'catIconShow' => false,
98 'catIconStyle' => 'cat2',
99 'catAlign' => false,
100
101 /*
102 ============================
103 Tag Style
104 ============================*/
105 'tagColor' => '#545454',
106 'tagHovColor' => '#ddd',
107 'tagTypo' => (object) array(
108 'openTypography' => 1,
109 'decoration' => 'none',
110 'size' => (object) array(
111 'lg' => 15,
112 'unit' => 'px',
113 ),
114 'height' => (object) array(
115 'lg' => 20,
116 'unit' => 'px',
117 ),
118 ),
119 'tagSpace' => (object) array(
120 'lg' => '7',
121 'unit' => 'px',
122 ),
123
124 'tagLabelShow' => true,
125 'tagLabel' => 'Tag - ',
126 'tagIconShow' => false,
127 'tagIconStyle' => 'tag2',
128 'tagAlign' => false,
129
130 /*
131 ============================
132 Advance Setting
133 ============================*/
134 'advanceId' => '',
135 'advanceZindex' => '',
136 'hideExtraLarge' => false,
137 'hideDesktop' => false,
138 'hideTablet' => false,
139 'hideMobile' => false,
140 'advanceCss' => '',
141 );
142 }
143
144 public function register() {
145 register_block_type(
146 'ultimate-post/advance-post-meta',
147 array(
148 'editor_script' => 'ultp-blocks-editor-script',
149 'editor_style' => 'ultp-blocks-editor-css',
150 'render_callback' => array( $this, 'content' ),
151 )
152 );
153 }
154
155
156 public function content( $attr, $noAjax ) {
157 $attr = wp_parse_args( $attr, $this->get_attributes() );
158
159 $block_name = 'post_meta';
160 $wrapper_before = $wrapper_after = $wrapper_content = $authContent = $updateLabel = $dateLabel = '';
161
162 $post_id = get_the_ID();
163 $contentAlign = ( $attr['catAlign'] || $attr['tagAlign'] || $attr['cmntAlign'] || $attr['viewAlign'] || $attr['readAlign'] || $attr['authAlign'] || $attr['dateAlign'] ) ? 'ultp-contentMeta-align' : 'ultp-contentMeta';
164
165 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
166 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
167 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
168 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
169 $attr['metaSeparator'] = sanitize_html_class( $attr['metaSeparator'] );
170 $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags();
171 $attr['authLabel'] = wp_kses( $attr['authLabel'], $allowed_html_tags );
172 $attr['dateText'] = wp_kses( $attr['dateText'], $allowed_html_tags );
173 $attr['datePubText'] = wp_kses( $attr['datePubText'], $allowed_html_tags );
174 $attr['cmtLabel'] = wp_kses( $attr['cmtLabel'], $allowed_html_tags );
175 $attr['viewLabel'] = wp_kses( $attr['viewLabel'], $allowed_html_tags );
176 $attr['readTimeText'] = wp_kses( $attr['readTimeText'], $allowed_html_tags );
177 $attr['catLabel'] = wp_kses( $attr['catLabel'], $allowed_html_tags );
178 $attr['tagLabel'] = wp_kses( $attr['tagLabel'], $allowed_html_tags );
179
180 // Author Content
181 if ( $attr['authorShow'] ) {
182 $author_id = get_post_field( 'post_author', $post_id );
183 $authContent .= '<span class="ultp-post-auth ultp-meta-separator">';
184 $authContent .= '<span class="ultp-auth-heading">';
185 if ( $attr['authIconShow'] ) {
186 $authContent .= ultimate_post()->get_svg_icon( '' . $attr['authIconStyle'] . '' );
187 }
188 if ( $attr['authImgShow'] ) {
189 $authContent .= get_avatar( $author_id, 32 );
190 }
191 if ( $attr['authLabelShow'] ) {
192 $authContent .= '<span class="ultp-auth-label">' . $attr['authLabel'] . '</span>';
193 }
194 $authContent .= ' </span>';
195 $authContent .= '<a href="' . get_author_posts_url( $author_id ) . '" class="ultp-auth-name">';
196 $authContent .= get_the_author_meta( 'display_name', $author_id );
197 $authContent .= '</a>';
198 $authContent .= '</span>';
199 }
200
201 // Date Content
202 if ( $attr['enablePrefix'] ) {
203 $dateLabel .= '<span class="ultp-date-prefix">' . $attr['dateText'] . '</span>';
204 }
205 if ( $attr['enablePrefix'] ) {
206 $updateLabel .= '<span class="ultp-date-prefix">' . $attr['datePubText'] . '</span>';
207 }
208 $dateContent = '';
209 if ( $attr['dateShow'] ) {
210 $dateContent .= '<span class="ultp-date-meta ultp-meta-separator">';
211 if ( $attr['DateIconShow'] ) {
212 $dateContent .= '<span class="ultp-date-icon">' . ultimate_post()->get_svg_icon( '' . $attr['dateIconStyle'] . '' ) . '</span>';
213 }
214 if ( $attr['dateFormat'] == 'updated' ) {
215 $dateContent .= '<span class="ultp-post-update">' . $dateLabel . '<span class="ultp-post-date__val">' . get_the_modified_date( ultimate_post()->get_format( $attr['metaDateFormat'] ), $post_id ) . '</span></span>';
216 }
217 if ( $attr['dateFormat'] == 'publish' ) {
218 $dateContent .= '<span class="ultp-post-date">' . $updateLabel . ' <span class="ultp-post-date__val">' . get_the_date( ultimate_post()->get_format( $attr['metaDateFormat'] ), $post_id ) . '</span></span>';
219 }
220 $dateContent .= '</span>';
221 }
222
223 // Main Content
224 $wrapper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '">';
225 $wrapper_before .= '<div class="ultp-block-wrapper">';
226 $wrapper_content .= '<div class="ultp-advance-post-meta ' . $contentAlign . ' ultp-post-meta-' . $attr['metaSeparator'] . '">';
227 $wrapper_content .= '<div>';
228 foreach ( $attr['metaItemSort'] as $val ) {
229 if ( $val == 'author' && $attr['authorShow'] && $attr['authAlign'] == false ) {
230 $wrapper_content .= $authContent;
231 }
232 if ( $val == 'date' && $attr['dateShow'] && $attr['dateAlign'] == false ) {
233 $wrapper_content .= $dateContent;
234 }
235 if ( $val == 'cmtCount' && $attr['cmtCountShow'] && $attr['cmntAlign'] == false ) {
236 $wrapper_content .= $this->renderPostCount( 'comment', get_post_field( 'comment_count', '' ), $attr['cmtLabelShow'], $attr['cmtLabel'], $attr['cmtIconShow'], ultimate_post()->get_svg_icon( '' . $attr['cmntIconStyle'] . '' ), $post_id );
237 }
238 if ( $val == 'viewCount' && $attr['viewCountShow'] && $attr['viewAlign'] == false ) {
239 $wrapper_content .= $this->renderPostCount( 'view', get_post_meta( $post_id, '__post_views_count', true ), $attr['viewLabelShow'], $attr['viewLabel'], $attr['viewIconShow'], ultimate_post()->get_svg_icon( '' . $attr['viewIconStyle'] . '' ), $post_id );
240 }
241 if ( $val == 'readTime' && $attr['readTimeShow'] && $attr['readAlign'] == false ) {
242 $wrapper_content .= $this->renderPostCount( 'readTime', 12, $attr['readTimePrefix'], $attr['readTimeText'], $attr['readTimeIcon'], ultimate_post()->get_svg_icon( '' . $attr['readIconStyle'] . '' ), $post_id );
243 }
244 if ( $val == 'cat' && $attr['catShow'] && $attr['catAlign'] == false ) {
245 $wrapper_content .= $this->renderPostCount( 'cat', get_the_category(), $attr['catLabelShow'], $attr['catLabel'], $attr['catIconShow'], ultimate_post()->get_svg_icon( '' . $attr['catIconStyle'] . '' ), $post_id );
246 }
247 if ( $val == 'tag' && $attr['tagShow'] && $attr['tagAlign'] == false ) {
248 $wrapper_content .= $this->renderPostCount( 'tag', get_the_tags(), $attr['tagLabelShow'], $attr['tagLabel'], $attr['tagIconShow'], ultimate_post()->get_svg_icon( '' . $attr['tagIconStyle'] . '' ), $post_id );
249 }
250 }
251 $wrapper_content .= '</div>';
252 $wrapper_content .= '<div>';
253 foreach ( $attr['metaItemSort'] as $content ) {
254 if ( $content == 'author' && $attr['authorShow'] && $attr['authAlign'] ) {
255 $wrapper_content .= $authContent;
256 }
257 if ( $content == 'date' && $attr['dateShow'] && $attr['dateAlign'] ) {
258 $wrapper_content .= $dateContent;
259 }
260 if ( $content == 'cmtCount' && $attr['cmtCountShow'] && $attr['cmntAlign'] ) {
261 $wrapper_content .= $this->renderPostCount( 'comment', get_post_field( 'comment_count', '' ), $attr['cmtLabelShow'], $attr['cmtLabel'], $attr['cmtIconShow'], ultimate_post()->get_svg_icon( '' . $attr['cmntIconStyle'] . '' ), $post_id );
262 }
263 if ( $content == 'viewCount' && $attr['viewCountShow'] && $attr['viewAlign'] ) {
264 $wrapper_content .= $this->renderPostCount( 'view', get_post_meta( get_the_ID(), '__post_views_count', true ), $attr['viewLabelShow'], $attr['viewLabel'], $attr['viewIconShow'], ultimate_post()->get_svg_icon( '' . $attr['viewIconStyle'] . '' ), $post_id );
265 }
266 if ( $content == 'readTime' && $attr['readTimeShow'] && $attr['readAlign'] ) {
267 $wrapper_content .= $this->renderPostCount( 'readTime', 12, $attr['readTimePrefix'], $attr['readTimeText'], $attr['readTimeIcon'], ultimate_post()->get_svg_icon( '' . $attr['readIconStyle'] . '' ), $post_id );
268 }
269 if ( $content == 'cat' && $attr['catShow'] && $attr['catAlign'] ) {
270 $wrapper_content .= $this->renderPostCount( 'cat', get_the_category(), $attr['catLabelShow'], $attr['catLabel'], $attr['catIconShow'], ultimate_post()->get_svg_icon( '' . $attr['catIconStyle'] . '' ), $post_id );
271 }
272 if ( $content == 'tag' && $attr['tagShow'] && $attr['tagAlign'] ) {
273 $wrapper_content .= $this->renderPostCount( 'tag', get_the_tags(), $attr['tagLabelShow'], $attr['tagLabel'], $attr['tagIconShow'], ultimate_post()->get_svg_icon( '' . $attr['tagIconStyle'] . '' ), $post_id );
274 }
275 }
276 $wrapper_content .= '</div>';
277 $wrapper_content .= '</div>';
278 $wrapper_after .= '</div>';
279 $wrapper_after .= '</div>';
280
281 return $wrapper_before . $wrapper_content . $wrapper_after;
282 }
283
284 public function renderPostCount( $title, $data, $labelEnable, $labelText, $iconEnable, $icon, $post_id = null ) {
285 $content = '';
286 $content .= '<span class="ultp-' . $title . '-wrap ultp-meta-separator">';
287 if ( ( $title == 'tag' || $title == 'cat' ) && $iconEnable ) {
288 $content .= '<span>' . $icon . '</span>';
289 }
290 if ( ( $title == 'tag' || $title == 'cat' ) && ( $labelEnable ) ) {
291 $content .= '<span class="ultp-' . $title . '-label">' . $labelText . '</span>';
292 }
293 if ( $title == 'tag' || $title == 'cat' ) {
294 $content .= '<span class="ultp-post-' . $title . '">';
295 if ( is_array( $data ) && count( $data ) > 0 ) {
296 if ( is_array( $data ) ) {
297 foreach ( $data as $dt ) {
298 $content .= '<a href="' . get_category_link( $dt->term_taxonomy_id ) . '">' . $dt->name . '</a>';
299 }
300 }
301 } else {
302 $content .= '<a>No Taxonomy Found.</a>';
303 }
304 $content .= '</span>';
305 } elseif ( ( $title != 'tag' && $title != 'cat' && $title != 'readTime' ) ) {
306 $content .= '<span class="ultp-' . $title . '-count">';
307 if ( $iconEnable ) {
308 $content .= $icon; }
309 $content .= $data ? $data : 0;
310 $content .= '</span>';
311 }
312 if ( ( $title != 'tag' && $title != 'cat' && $title != 'readTime' ) && $labelEnable ) {
313 $content .= '<span class="ultp-' . $title . '-label">' . $labelText . '</span>';
314 }
315 if ( $title == 'readTime' ) {
316 if ( $iconEnable ) {
317 $content .= $icon; }
318
319 $content .= '<div>' . ceil( mb_strlen( wp_strip_all_tags( get_the_content( null, false, $post_id ) ) ) / 1200 ) . '</div>';
320 $content .= $labelEnable ? '<span class="ultp-read-label">' . $labelText . '</span>' : '';
321 $content .= '</span>';
322 }
323 $content .= '</span>';
324 return $content;
325 }
326 }
327