PluginProbe
Qi Blocks / 1.2.2
Qi Blocks v1.2.2
1.5.3 1.5.2 1.5.1 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 All 45 releases
qi-blocks / inc / comments / helper.php

helper.php in Qi Blocks 1.2.2, at inc/comments/helper.php

184 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly.
4 defined( 'ABSPATH' ) || exit;
5
6 if ( ! function_exists( 'qi_blocks_get_comments_list_args' ) ) {
7 /**
8 * Function that define new comment list args in order to override default WordPress comment list
9 *
10 * @param int $post_ID
11 * @param boolean $ajax
12 *
13 * @return array
14 */
15 function qi_blocks_get_comments_list_args( $post_ID, $ajax = false ) {
16 $args = array(
17 'post_id' => (int) $post_ID,
18 'orderby' => 'comment_date_gmt',
19 'order' => 'DESC',
20 'status' => 'approve',
21 'no_found_rows' => false,
22 'page' => '',
23 'per_page' => '',
24 );
25
26 if ( 'desc' === get_option( 'comment_order' ) ) {
27 $args['order'] = 'asc';
28 }
29
30 if ( get_option( 'thread_comments' ) ) {
31 $args['max_depth'] = get_option( 'thread_comments_depth' );
32 } else {
33 $args['max_depth'] = -1;
34 }
35
36 if ( get_option( 'page_comments' ) === '1' || get_option( 'page_comments' ) === true ) {
37 $per_page = (int) get_option( 'comments_per_page' );
38 $default_page = get_option( 'default_comments_page' );
39 if ( $per_page > 0 ) {
40 $args['per_page'] = $per_page;
41
42 $page = (int) get_query_var( 'cpage' );
43 if ( $page ) {
44 $args['page'] = $page;
45 $args['paged'] = $page;
46 } elseif ( 'oldest' === $default_page ) {
47 $args['page'] = 1;
48 $args['paged'] = 1;
49 } elseif ( 'newest' === $default_page ) {
50 $max_comments_num = ( new WP_Comment_Query( array_merge( $args, array( 'number' => $per_page ) ) ) )->max_num_pages;
51
52 $args['page'] = $max_comments_num;
53 $args['paged'] = $max_comments_num;
54 }
55
56 // Set the `cpage` query var to ensure the previous and next pagination links are correct
57 // when inheriting the Discussion Settings.
58 if ( 0 === $page && isset( $args['paged'] ) && $args['paged'] > 0 ) {
59 set_query_var( 'cpage', (int) $args['paged'] );
60 }
61 }
62 }
63
64 return $args;
65 }
66 }
67
68 if ( ! function_exists( 'qi_blocks_get_comments_list_template' ) ) {
69 /**
70 * Function which modify default WordPress comments list template
71 *
72 * @param object $comment
73 * @param array $args
74 * @param int $depth
75 *
76 * @return string that contains comments list html
77 */
78 function qi_blocks_get_comments_list_template( $comment, $args, $depth ) {
79 global $post;
80
81 $classes = array();
82
83 $is_author_comment = $post->post_author === $comment->user_id;
84 if ( $is_author_comment ) {
85 $classes[] = 'qodef-comment--author';
86 }
87
88 $is_specific_comment = 'pingback' === $comment->comment_type || 'trackback' === $comment->comment_type;
89 if ( $is_specific_comment ) {
90 $classes[] = 'qodef-comment--no-avatar';
91 $classes[] = 'qodef-comment--' . esc_attr( $comment->comment_type );
92 }
93 ?>
94 <li class="qodef-comment-item qodef-e <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
95 <div id="comment-<?php comment_ID(); ?>" class="qodef-e-inner">
96 <?php if ( ! $is_specific_comment ) { ?>
97 <div class="qodef-e-image"><?php echo get_avatar( $comment, 150 ); ?></div>
98 <?php } ?>
99 <div class="qodef-e-content">
100 <div class="qodef-e-info">
101 <div class="qodef-e-date commentmetadata">
102 <a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>"><?php comment_time( get_option( 'date_format' ) ); ?></a>
103 </div>
104 <div class="qodef-e-links">
105 <?php
106 comment_reply_link(
107 array_merge(
108 $args,
109 array(
110 // translators: %s - Add svg icon for reply link
111 'reply_text' => qi_blocks_get_svg_icon( 'comment-reply' ),
112 'depth' => $depth,
113 'max_depth' => $args['max_depth'],
114 )
115 )
116 );
117
118 // translators: %s - Add svg icon for edit link
119 edit_comment_link( qi_blocks_get_svg_icon( 'comment-edit' ) );
120 ?>
121 </div>
122 </div>
123 <h5 class="qodef-e-title vcard"><?php echo sprintf( '<span class="fn">%s%s</span>', esc_attr( $is_specific_comment ) ? sprintf( '%s: ', esc_attr( ucwords( $comment->comment_type ) ) ) : '', get_comment_author_link() ); ?></h5>
124 <?php if ( ! $is_specific_comment ) { ?>
125 <div class="qodef-e-text"><?php comment_text( $comment ); ?></div>
126 <?php } ?>
127 </div>
128 </div>
129 <?php //li tag will be closed by WordPress after looping through child elements ?>
130 <?php
131 }
132 }
133
134 if ( ! function_exists( 'qi_blocks_get_comment_form_args' ) ) {
135 /**
136 * Function that define new comment form args in order to override default WordPress comment form
137 *
138 * @param array $attributes
139 *
140 * @return array
141 */
142 function qi_blocks_get_comment_form_args( $attributes ) {
143 $classes = array(
144 'qodef-comment-form-button',
145 'qodef--filled',
146 );
147
148 $icon = '';
149
150 if ( $attributes['formButtonShowIcon'] ) {
151 $classes[] = 'qodef--with-icon';
152
153 $icon = qi_blocks_get_svg_icon( 'button-arrow', 'qodef-m-icon' );
154
155 if ( isset( $attributes['formButtonIcon'] ) && ! empty( $attributes['formButtonIcon'] ) ) {
156
157 if ( is_object( $attributes['formButtonIcon'] ) && isset( $attributes['formButtonIcon']->html ) && ! empty( $attributes['formButtonIcon']->html ) ) {
158 $icon = '<span class="qodef-m-icon">' . $attributes['formButtonIcon']->html . '</span>';
159 }
160
161 if ( is_array( $attributes['formButtonIcon'] ) && isset( $attributes['formButtonIcon']['html'] ) && ! empty( $attributes['formButtonIcon']['html'] ) ) {
162 $icon = '<span class="qodef-m-icon">' . $attributes['formButtonIcon']['html'] . '</span>';
163 }
164 }
165 }
166
167 $args = array(
168 'title_reply_to' => esc_attr__( 'Reply to %s', 'qi-blocks' ),
169 'title_reply_before' => '<' . esc_attr( $attributes['titleTag'] ) . ' id="reply-title" class="comment-reply-title">',
170 'title_reply_after' => '</' . esc_attr( $attributes['titleTag'] ) . '>',
171 'comment_field' => sprintf(
172 '<p class="comment-form-comment">%s %s</p>',
173 '<label for="comment">' . esc_html__( 'Comment', 'qi-blocks' ) . '</label>',
174 '<textarea id="comment" name="comment" cols="45" rows="6" maxlength="65525" required="required"></textarea>'
175 ),
176 'submit_button' => '<button name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s"><span class="qodef-m-text">%4$s</span>' . $icon . '</button>',
177 'class_submit' => implode( ' ', $classes ),
178 'class_form' => 'qodef-comment-form',
179 );
180
181 return apply_filters( 'qi_blocks_filter_comment_form_args', $args );
182 }
183 }
184