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 / post-comments / index.php
kubio / build / block-library / blocks / post-comments Last commit date
block.json 3 years ago index.php 1 year ago
index.php
106 lines
1 <?php
2
3 namespace Kubio\Blocks;
4
5 use Kubio\Core\Blocks\BlockBase;
6 use Kubio\Core\Registry;
7 use Kubio_Walker_Comment;
8
9 class PostCommentsBlock extends BlockBase {
10
11 const CONTAINER = 'commentsContainer';
12
13
14
15 static function getPostCommentsTemplate() {
16 return KUBIO_ROOT_DIR . '/lib/blog/comments.php';
17 }
18
19 public function serverSideRender() {
20 global $withcomments;
21 $withcomments = true;
22
23 return $this->getPostComments(
24 array(
25 'none' => $this->getAttribute( 'noCommentsTitle' ),
26 'one' => $this->getAttribute( 'oneCommentTitle' ),
27 'multiple' => $this->getAttribute( 'multipleComments' ),
28 'disabled' => $this->getAttribute( 'commentsDisabled' ),
29 'avatar_size' => $this->getAttribute( 'avatarSize' ),
30 )
31 );
32 }
33
34 function getPostComments( $attrs = array() ) {
35
36 if ( apply_filters( 'kubio/sandboxed_render', false ) ) {
37 return '';
38 }
39
40 $atts = array_merge(
41 array(
42 'none' => __( 'No responses yet', 'kubio' ),
43 'one' => __( 'One response', 'kubio' ),
44 'multiple' => __( '{COMMENTS-COUNT} Responses', 'kubio' ),
45 'disabled' => __( 'Comments are closed', 'kubio' ),
46 'avatar_size' => 32,
47 ),
48 $attrs
49 );
50
51 if ( kubio_wpml_is_active() ) {
52 foreach ( $atts as $key => $value ) {
53 $atts[ $key ] = kubio_wpml_get_translated_string( $value );
54 }
55 }
56
57 global $kubio_comments_data;
58 $kubio_comments_data = $atts;
59
60 ob_start();
61 add_filter( 'kubio/walker-comment', array( $this, 'getCommentWalker' ) );
62
63 add_filter( 'comments_template', array( PostCommentsBlock::class, 'getPostCommentsTemplate' ) );
64 if ( comments_open( get_the_ID() ) ) {
65 comments_template();
66 } else {
67 return sprintf( '<p class="comments-disabled">%s</p>', esc_attr( $atts['disabled'] ) );
68 }
69 $content = ob_get_clean();
70
71 remove_filter( 'comments_template', array( PostCommentsBlock::class, 'getPostCommentsTemplate' ) );
72 remove_filter( 'kubio/walker-comment', array( $this, 'getCommentWalker' ) );
73
74 return $content;
75 }
76
77 public function getCommentWalker( $walker ) {
78 $migrations = $this->getAppliedMigrations();
79 if ( in_array( 1, $migrations ) || in_array( '1', $migrations ) ) {
80 require_once KUBIO_ROOT_DIR . '/lib/blog/walker-comment.php';
81 return new Kubio_Walker_Comment();
82 }
83
84 return $walker;
85 }
86
87 public function mapPropsToElements() {
88 return array(
89 self::CONTAINER => array(
90 'innerHTML' => $this->getPostComments(
91 array(
92 'none' => wp_kses_post( $this->getAttribute( 'noCommentsTitle' ) ),
93 'one' => wp_kses_post( $this->getAttribute( 'oneCommentTitle' ) ),
94 'multiple' => wp_kses_post( $this->getAttribute( 'multipleComments' ) ),
95 'disabled' => wp_kses_post( $this->getAttribute( 'commentsDisabled' ) ),
96 'avatar_size' => wp_kses_post( $this->getAttribute( 'avatarSize' ) ),
97 'html5' => true,
98 )
99 ),
100 ),
101 );
102 }
103 }
104
105 Registry::registerBlock( __DIR__, PostCommentsBlock::class );
106