PluginProbe
Qi Blocks / trunk
Qi Blocks vtrunk
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 trunk, at inc/comments/helper.php

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