PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / public / template / loop / class-loop-html.php

class-loop-html.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.2, at public/template/loop/class-loop-html.php

331 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file of query insides.
4 *
5 * @package Smart_Post_Show
6 * @subpackage Smart_Post_Show/public
7 *
8 * @since 2.0.0
9 */
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die; // Exit if accessed directly.
14 }
15 /**
16 * Post all html method.
17 *
18 * @since 2.0.0
19 */
20 class SP_PC_HTML {
21
22 /**
23 * Section title
24 *
25 * @param int $title shortcode title.
26 * @return void
27 */
28 public static function pcp_section_title( $title ) {
29 $section_title_text = apply_filters( 'pcp_section_title_text', $title );
30 $section_title = apply_filters( 'pcp_filter_section_title', sprintf( '<h2 class="pcp-section-title">%1$s</h2>', $section_title_text ), $section_title_text );
31 echo wp_kses_post( $section_title );
32 }
33
34 /**
35 * Post title html.
36 *
37 * @param array $sorter post content option array.
38 * @param string $layout layout preset.
39 * @param array $options The options array.
40 * @return void
41 */
42 public static function pcp_post_title( $sorter, $layout, $options ) {
43
44 $_meta_settings = SP_PC_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
45 $post_meta_fields = SP_PC_Functions::pcp_metabox_value( 'pcp_post_meta_group', $_meta_settings );
46 $show_post_meta = SP_PC_Functions::pcp_metabox_value( 'show_post_meta', $_meta_settings, true );
47 $pcp_page_link_type = SP_PC_Functions::pcp_metabox_value( 'pcp_page_link_type', $options );
48 $pcp_link_rel = SP_PC_Functions::pcp_metabox_value( 'pcp_link_rel', $options );
49 $pcp_link_rel_text = $pcp_link_rel ? 'rel=nofollow' : '';
50 $pcp_link_target = SP_PC_Functions::pcp_metabox_value( 'pcp_link_target', $options );
51
52 if ( is_array( $post_meta_fields ) && 'accordion_layout' !== $layout && $show_post_meta ) {
53 foreach ( $post_meta_fields as $each_meta ) {
54 if ( 'taxonomy' === $each_meta['select_post_meta'] ) {
55 $taxonomy = $each_meta['post_meta_taxonomy'];
56 $meta_position = $each_meta['pcp_meta_position'];
57 if ( 'above_title' === $meta_position ) {
58 $terms = get_the_term_list( get_the_ID(), $taxonomy, '', ' ' );
59 if ( $terms ) {
60 ?>
61 <div class="pcp-category above_title <?php echo esc_attr( $taxonomy ); ?>">
62 <?php echo wp_kses_post( $terms ); ?>
63 </div>
64 <?php
65 }
66 }
67 }
68 }
69 }
70
71 $post_title_setting = isset( $sorter['pcp_post_title'] ) ? $sorter['pcp_post_title'] : '';
72 $show_post_title = SP_PC_Functions::pcp_metabox_value( 'show_post_title', $post_title_setting );
73
74 $pcp_post_title = get_the_title( get_the_ID() );
75
76 if ( $show_post_title && ! empty( $pcp_post_title ) ) {
77 // Post Title Settings.
78 $post_title_tag = SP_PC_Functions::pcp_metabox_value( 'post_title_tag', $post_title_setting, 'h2' );
79 $allowed_html_tags = array(
80 'em' => array(),
81 'strong' => array(),
82 'sup' => array(),
83 'sub' => array(),
84 'i' => array(),
85 'small' => array(),
86 'del' => array(),
87 'br' => array(),
88 'ins' => array(),
89 'span' => array(
90 'style' => array(),
91 'class' => array(),
92 ),
93 );
94 ?>
95 <<?php echo tag_escape( $post_title_tag ); ?> class="sp-pcp-title">
96 <?php if ( 'none' === $pcp_page_link_type ) { ?>
97 <?php printf( '<a %2$s>%1$s</a>', wp_kses( trim( $pcp_post_title ), $allowed_html_tags ), esc_attr( $pcp_link_rel_text ) ); ?>
98 <?php } else { ?>
99 <?php printf( '<a href="%1$s" %3$s target="%4$s">%2$s</a>', esc_url( get_the_permalink() ), wp_kses( trim( $pcp_post_title ), $allowed_html_tags ), esc_attr( $pcp_link_rel_text ), esc_attr( $pcp_link_target ) ); ?>
100 <?php } ?>
101 </<?php echo tag_escape( $post_title_tag ); ?>>
102 <?php
103 }
104 }
105
106 /**
107 * Show Post Content html.
108 *
109 * @param array $sorter The field ID array.
110 * @param array $options options.
111 * @return void
112 */
113 public static function pcp_content_html( $sorter, $options ) {
114 $post_content_setting = SP_PC_Functions::pcp_metabox_value( 'pcp_post_content', $sorter );
115 $show_post_content = SP_PC_Functions::pcp_metabox_value( 'show_post_content', $post_content_setting );
116 $show_read_more = SP_PC_Functions::pcp_metabox_value( 'show_read_more', $post_content_setting );
117 $pcp_content_type = SP_PC_Functions::pcp_metabox_value( 'post_content_type', $post_content_setting );
118 if ( $show_post_content || $show_read_more ) {
119 ?>
120 <div class="sp-pcp-post-content">
121 <?php
122 if ( $show_post_content ) {
123 echo wp_kses_post( SP_PC_Functions::pcp_content( $post_content_setting, $pcp_content_type ) );
124 }
125 if ( $show_read_more ) {
126 self::pcp_readmore( $post_content_setting, $pcp_content_type, $options );
127 }
128 ?>
129 </div>
130 <?php
131 }
132 }
133
134 /**
135 * Read more function
136 *
137 * @param array $view_options Read more options array.
138 * @param array $content_type The content type.
139 * @param array $options The parent of this field.
140 */
141 public static function pcp_readmore( $view_options, $content_type, $options ) {
142 $show_read_more = isset( $view_options['show_read_more'] ) ? $view_options['show_read_more'] : '';
143 if ( ! $show_read_more || 'full_content' === $content_type ) {
144 return '';
145 }
146
147 $pcp_read_label = isset( $view_options['pcp_read_label'] ) ? $view_options['pcp_read_label'] : '';
148 $pcp_page_link_type = SP_PC_Functions::pcp_metabox_value( 'pcp_page_link_type', $options );
149 $pcp_link_rel = SP_PC_Functions::pcp_metabox_value( 'pcp_link_rel', $options );
150 $pcp_link_rel_text = $pcp_link_rel ? 'rel=nofollow' : '';
151 $readmore_target = SP_PC_Functions::pcp_metabox_value( 'pcp_link_target', $options );
152 ?>
153 <div class="sp-pcp-readmore">
154 <?php if ( 'none' === $pcp_page_link_type ) { ?>
155 <a class="pcp-readmore-link" target="<?php echo esc_attr( $readmore_target ); ?>" <?php echo esc_attr( $pcp_link_rel_text ); ?>>
156 <?php } else { ?>
157 <a class="pcp-readmore-link" target="<?php echo esc_attr( $readmore_target ); ?>" href="<?php the_permalink(); ?>" <?php echo esc_attr( $pcp_link_rel_text ); ?>>
158 <?php } ?>
159 <?php echo esc_html( $pcp_read_label ); ?> </a>
160 </div>
161 <?php
162 }
163
164 /**
165 * Post thumb HTML.
166 *
167 * @param array $sorter post content option array.
168 * @param int $scode_id Shortcode ID.
169 * @param int $slide_id The slide/post ID.
170 * @param array $options The slide/post ID.
171 * @return void
172 */
173 public static function pcp_post_thumb_html( $sorter, $scode_id, $slide_id, $options ) {
174 $_post_thumb_setting = SP_PC_Functions::pcp_metabox_value( 'pcp_post_thumb', $sorter );
175 $pcp_page_link_type = SP_PC_Functions::pcp_metabox_value( 'pcp_page_link_type', $options );
176 $pcp_link_rel = SP_PC_Functions::pcp_metabox_value( 'pcp_link_rel', $options );
177 $pcp_link_rel_text = '';
178 if ( $pcp_link_rel ) {
179 $pcp_link_rel_text = 'rel=nofollow';
180 }
181 $pcp_link_target = SP_PC_Functions::pcp_metabox_value( 'pcp_link_target', $options );
182 if ( SP_PC_Functions::pcp_metabox_value( 'post_thumb_show', $_post_thumb_setting ) ) {
183 $pcp_image_attr = SP_PC_Functions::pcp_sized_thumb( $_post_thumb_setting, $slide_id );
184 $thumb_url = $pcp_image_attr['src'];
185 $alter_text = SP_PC_Functions::pcp_thumb_alter_text( $slide_id );
186 if ( ! empty( $thumb_url ) ) {
187 ?>
188 <div class="pcp-post-thumb-wrapper">
189 <div class="sp-pcp-post-thumb-area">
190 <?php if ( 'none' === $pcp_page_link_type ) { ?>
191 <a class="sp-pcp-thumb" <?php echo esc_attr( $pcp_link_rel_text ); ?>>
192 <?php } else { ?>
193 <a class="sp-pcp-thumb" href="<?php the_permalink(); ?>" target="<?php echo esc_attr( $pcp_link_target ); ?>" <?php echo esc_attr( $pcp_link_rel_text ); ?>>
194 <?php } ?>
195 <img src="<?php echo esc_url( $thumb_url ); ?>" width="<?php echo esc_attr( $pcp_image_attr['width'] ); ?>" height="<?php echo esc_attr( $pcp_image_attr['height'] ); ?>" alt="<?php echo esc_attr( $alter_text ); ?>">
196 </a>
197 </div>
198 </div>
199 <?php
200 }
201 }
202 }
203
204 /**
205 * Post meta HTML
206 *
207 * @param array $sorter post content option array.
208 * @return void
209 */
210 public static function pcp_post_meta_html( $sorter ) {
211 $_meta_settings = SP_PC_Functions::pcp_metabox_value( 'pcp_post_meta', $sorter );
212 $post_meta_fields = SP_PC_Functions::pcp_metabox_value( 'pcp_post_meta_group', $_meta_settings );
213 $show_post_meta = SP_PC_Functions::pcp_metabox_value( 'show_post_meta', $_meta_settings, true );
214 $_meta_separator = SP_PC_Functions::pcp_metabox_value( 'meta_separator', $_meta_settings, ' ' );
215
216 if ( $post_meta_fields && $show_post_meta ) {
217 ?>
218 <div class="sp-pcp-post-meta">
219 <?php
220 echo wp_kses_post( apply_filters( 'pcp_post_meta_wrapper_start', '<ul>' ) );
221 SP_PC_Functions::pcp_get_post_meta( $post_meta_fields, $_meta_separator );
222 echo wp_kses_post( apply_filters( 'pcp_post_meta_wrapper_end', '</ul>' ) );
223 ?>
224 </div>
225 <?php
226 }
227 }
228
229 /**
230 * Post content with thumb.
231 *
232 * @param array $sorter post sorting option.
233 * @param string $layout Layout preset.
234 * @param int $scode_id The Shortcode ID.
235 * @param object $post The Post object.
236 * @param array $options The options array.
237 * @return void
238 */
239 public static function pcp_post_content_with_thumb( $sorter, $layout, $scode_id, $post, $options ) {
240 if ( $sorter ) {
241 foreach ( $sorter as $style_key => $style_value ) {
242 switch ( $style_key ) {
243 case 'pcp_post_thumb':
244 self::pcp_post_thumb_html( $sorter, $scode_id, $post->ID, $options );
245 break;
246 case 'pcp_post_title':
247 self::pcp_post_title( $sorter, $layout, $options );
248 break;
249 case 'pcp_post_content':
250 self::pcp_content_html( $sorter, $options );
251 break;
252 case 'pcp_post_meta':
253 self::pcp_post_meta_html( $sorter );
254 break;
255 }
256 }
257 }
258 }
259
260 /**
261 * Post content without thumb.
262 *
263 * @param array $sorter post sorting option.
264 * @param string $layout Layout preset.
265 * @param object $post visitor number.
266 * @param array $options The options array.
267 * @return void
268 */
269 public static function pcp_post_content_without_thumb( $sorter, $layout, $post, $options ) {
270 if ( $sorter ) {
271 foreach ( $sorter as $style_key => $style_value ) {
272 switch ( $style_key ) {
273 case 'pcp_post_title':
274 self::pcp_post_title( $sorter, $layout, $options );
275 break;
276 case 'pcp_post_content':
277 self::pcp_content_html( $sorter, $options );
278 break;
279 case 'pcp_post_meta':
280 self::pcp_post_meta_html( $sorter );
281 break;
282 }
283 }
284 }
285 }
286
287 /**
288 * Pagination function
289 *
290 * @param object $loop Query array.
291 * @param array $view_options shortcode options.
292 * @param array $shortcode_id shortcode id.
293 * @param array $on_screen screen type.
294 */
295 public static function pcp_pagination_bar( $loop, $view_options, $shortcode_id, $on_screen = null ) {
296 // $posts_found;
297 $posts_found = $loop->found_posts;
298 $post_offset = isset( $view_options['pcp_post_offset'] ) ? $view_options['pcp_post_offset'] : 0;
299 $post_limit = isset( $view_options['pcp_post_limit'] ) ? $view_options['pcp_post_limit'] : '';
300 $post_limit = ( $post_limit > 0 && $posts_found > $post_limit ) ? $post_limit : $posts_found;
301 $post_per_page = isset( $view_options['post_per_page'] ) ? $view_options['post_per_page'] : '';
302 $post_per_page = ( $post_per_page > $post_limit ) ? $post_limit : $post_per_page;
303 // Post display settings.
304 $post_limit = (int) $post_limit;
305 if ( $post_limit < 1 ) {
306 $pages = 0;
307 } else {
308 $pages = SP_PC_Functions::pcp_max_pages( $post_limit, $post_per_page );
309 }
310 $big = 999999999; // need an unlikely integer.
311 if ( $pages > 1 ) {
312 $paged_var = 'paged' . $shortcode_id;
313 // phpcs:ignore WordPress.Security.NonceVerification -- read-only operation, so can safely ignore it.
314 $page_current = ( ! empty( $_GET[ "$paged_var" ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ "$paged_var" ] ) ) : 1;
315 $page_links = paginate_links(
316 array(
317 'format' => '?' . $paged_var . '=%#%',
318 'current' => $page_current,
319 'total' => $pages,
320 'show_all' => true,
321 'prev_next' => true,
322 'type' => 'array',
323 'prev_text' => '<i class="fa fa-angle-left"></i>',
324 'next_text' => '<i class="fa fa-angle-right"></i>',
325 )
326 );
327 echo wp_kses_post( implode( $page_links ) );
328 }
329 }
330 }
331