PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.0.3
Post Grid Gutenberg Blocks – PostX v4.0.3
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 / Post_Reading_Time.php

Post_Reading_Time.php in Post Grid Gutenberg Blocks – PostX 4.0.3, at addons/builder/blocks/Post_Reading_Time.php

79 lines 3.4 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 Post_Reading_Time {
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 Post Reading Meta Settings
17 ============================*/
18 'readLabel' => true,
19 'readIconShow' => true,
20 'readLabelText' => 'Reading Time',
21
22 /*============================
23 Post Reading Icon Settings
24 ============================*/
25 'readIconStyle' => 'readingTime1',
26
27 /*============================
28 Advanced Settings
29 ============================*/
30 'advanceId' => '',
31 'advanceZindex' => '',
32 'hideExtraLarge' => false,
33 'hideDesktop' => false,
34 'hideTablet' => false,
35 'hideMobile' => false,
36 'advanceCss' => '',
37 );
38 }
39
40 public function register() {
41 register_block_type( 'ultimate-post/post-reading-time',
42 array(
43 'editor_script' => 'ultp-blocks-editor-script',
44 'editor_style' => 'ultp-blocks-editor-css',
45 'render_callback' => array($this, 'content')
46 )
47 );
48 }
49
50 public function content($attr, $noAjax) {
51 $attr = wp_parse_args($attr, $this->get_attributes());
52 $block_name = 'post-reading-time';
53 $wrapper_before = $wrapper_after = $content = '';
54
55 $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : '';
56 $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : '';
57 $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : '';
58 $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : '';
59 $attr['readLabelText'] = wp_kses($attr['readLabelText'], ultimate_post()->ultp_allowed_html_tags());
60
61 $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"] : '' ).'">';
62 $wrapper_before .= '<div class="ultp-block-wrapper">';
63 $content .= '<span class="ultp-read-count">';
64 if ($attr["readIconShow"] && ($attr["readIconStyle"] != '')) {
65 $content .= ultimate_post()->svg_icon($attr["readIconStyle"]);
66 }
67 $content .= '<div>';
68 $content .= ceil(mb_strlen(wp_strip_all_tags(get_the_content( null, false, get_the_ID() )))/1200);
69 $content .= '</div>';
70 if ($attr["readLabel"]) {
71 $content .= '<span class="ultp-read-label">'.$attr["readLabelText"].'</span>';
72 }
73 $content .= '</span>';
74 $wrapper_after .= '</div>';
75 $wrapper_after .= '</div>';
76
77 return $wrapper_before.$content.$wrapper_after;
78 }
79 }