PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.13
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.13
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 2.4.13, at public/template/loop/class-loop-html.php

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