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

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