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 / helpers / class-post-functions.php

class-post-functions.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.13, at public/helpers/class-post-functions.php

264 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file functions.
4 *
5 * @package Smart_Post_Show
6 * @subpackage public
7 *
8 * @since 2.2.0
9 */
10
11 /**
12 * Post views helper method.
13 *
14 * @since 2.2.0
15 */
16 class SP_PC_Functions {
17 /**
18 * WP Version compare
19 *
20 * @param int $version_to_compare The WP version.
21 * @param string $operator Compare operator.
22 * @return mixed
23 */
24 public static function wp_version_compare( $version_to_compare, $operator = '>=' ) {
25 if ( empty( $version_to_compare ) ) {
26 return true;
27 }
28 global $wp_version;
29
30 // Check if using WordPress version 3.7 or higher.
31 return version_compare( $wp_version, $version_to_compare, $operator );
32 }
33
34 /**
35 * Tag name to full tag conversion.
36 *
37 * @param array $meta_tag Tag option.
38 * @return string
39 */
40 public static function short_tag_to_html( $meta_tag ) {
41 $exclude_tag_string = '';
42 foreach ( $meta_tag as $key => $value ) {
43 $exclude_tag_string .= '<' . $value . '>,';
44 }
45 return $exclude_tag_string;
46 }
47
48 /**
49 * Content function.
50 *
51 * @param array $view_options Read more options array.
52 * @param string $type Content type.
53 * @return return
54 */
55 public static function pcp_content( $view_options, $type ) {
56 global $wp_embed;
57 $post_content_ellipsis = isset( $view_options['post_content_ellipsis'] ) ? $view_options['post_content_ellipsis'] : '';
58 $pcp_strip_tags = isset( $view_options['pcp_strip_tags'] ) ? $view_options['pcp_strip_tags'] : '';
59 $pcp_allow_tag_name = isset( $view_options['pcp_allow_tag_name'] ) ? $view_options['pcp_allow_tag_name'] : '';
60 $allowed_tags = explode( ',', $pcp_allow_tag_name );
61 if ( 'full_content' === $type ) {
62 $pcp_post_content = get_the_content();
63 } else {
64 $pcp_post_content = get_the_excerpt();
65 }
66 $pcp_post_content = do_shortcode( $wp_embed->autoembed( wpautop( trim( $pcp_post_content ) ) ) );
67 return $pcp_post_content;
68 }
69
70 /**
71 * Thumbnail alter text
72 *
73 * @param integer $slide_id The slide/post ID.
74 *
75 * @return string
76 */
77 public static function pcp_thumb_alter_text( $slide_id ) {
78 $image_id = get_post_thumbnail_id( $slide_id );
79 $alt_text = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
80 return $alt_text;
81 }
82
83 /**
84 * Thumb Sized function
85 *
86 * @param array $post_thumb_setting Thumbnails options array.
87 * @param integer $slide_id The slide/post ID.
88 *
89 * @return string
90 */
91 public static function pcp_sized_thumb( $post_thumb_setting, $slide_id ) {
92 $thumb_id = '';
93 $image = '';
94 if ( has_post_thumbnail( $slide_id ) ) {
95 $thumb_id = get_post_thumbnail_id();
96 }
97
98 $placeholder_img = SP_PC_URL . 'public/assets/img/placeholder.png';
99 $placeholder_img = apply_filters( 'pcp_no_thumb_placeholder', $placeholder_img );
100 if ( empty( $thumb_id ) && ! empty( $placeholder_img ) ) {
101 $thumb_id = attachment_url_to_postid( $placeholder_img );
102 }
103
104 if ( ! empty( $thumb_id ) ) {
105 $image_sizes = isset( $post_thumb_setting['pcp_thumb_sizes'] ) ? $post_thumb_setting['pcp_thumb_sizes'] : '';
106 $image_src = wp_get_attachment_image_src( $thumb_id, $image_sizes );
107 $image_src = is_array( $image_src ) ? $image_src : array( '', '', '' );
108 $image = $image_src[0];
109 $image_width = $image_src[1];
110 $image_height = $image_src[2];
111 } elseif ( ! empty( $placeholder_img ) ) {
112 $image = $placeholder_img;
113 $image_width = 600;
114 $image_height = 450;
115 }
116 $pcp_image_attr = array(
117 'src' => $image,
118 'width' => $image_width,
119 'height' => $image_height,
120 );
121 return $pcp_image_attr;
122 }
123
124 /**
125 * Process all the post meta.
126 *
127 * @param array $post_meta_fields The selected post meta to show.
128 * @param string $meta_separator The post meta separator.
129 * @return void
130 */
131 public static function pcp_get_post_meta( $post_meta_fields, $meta_separator ) {
132 $i = 0;
133 foreach ( $post_meta_fields as $each_meta ) {
134 $selected_meta = $each_meta['select_post_meta'];
135 $meta_icon = ! empty( $each_meta['select_meta_icon'] ) ? sprintf( '<i class="' . $each_meta['select_meta_icon'] . '"></i>' ) : '';
136 $meta_tag_start = apply_filters( 'pcp_post_meta_html_tag_start', '<li>' );
137 $meta_tag_end = apply_filters( 'pcp_post_meta_html_tag_end', '</li>' );
138
139 switch ( $selected_meta ) {
140 case 'author':
141 if ( 0 < $i ) {
142 echo esc_html( $meta_separator );
143 }
144 echo wp_kses_post( $meta_tag_start );
145 ?>
146 <i class="fa fa-user"></i>
147 <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"
148 rel="author"><?php echo esc_html( get_the_author() ); ?></a>
149 <?php
150 echo wp_kses_post( $meta_tag_end );
151 break;
152 case 'date':
153 if ( 0 < $i ) {
154 echo esc_html( $meta_separator );
155 }
156 echo wp_kses_post( $meta_tag_start );
157 ?>
158 <i class="fa fa-calendar"></i>
159
160 <time class="entry-date published updated"><?php echo esc_html( get_the_date() ); ?></time>
161 <?php
162 echo wp_kses_post( $meta_tag_end );
163 break;
164 case 'comment_count':
165 if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
166 if ( 0 < $i ) {
167 echo esc_html( $meta_separator );
168 }
169 echo wp_kses_post( $meta_tag_start );
170 ?>
171 <i class="fa fa-comments-o"></i>
172 <a href="<?php the_permalink(); ?>"><?php echo esc_html( get_comments_number() ); ?></a>
173 <?php
174 echo wp_kses_post( $meta_tag_end );
175 }
176 break;
177 }
178 ++$i;
179 } // End Foreach.
180 }
181
182 /**
183 * Maximum pages.
184 *
185 * @param int $total_post Number of total posts.
186 * @param int $post_per_page Posts per page.
187 *
188 * @return void
189 */
190 public static function pcp_max_pages( $total_post, $post_per_page ) {
191 if ( ! $total_post ) {
192 return;
193 }
194 $max_num_pages = ceil( $total_post / $post_per_page );
195 return (int) $max_num_pages;
196 }
197
198 /**
199 * Post per page.
200 *
201 * @param int $limit Post Limit.
202 * @param int $post_per_page post per page.
203 * @param int $page paged number.
204 *
205 * @return int
206 */
207 public static function pcp_post_per_page( $limit, $post_per_page, $page ) {
208 $limit = ( empty( $limit ) || '-1' === $limit ) ? 1000000 : $limit;
209 $offset = (int) $post_per_page * ( $page - 1 );
210 $final_post_per_page = $post_per_page;
211 if ( intval( $post_per_page ) > $limit - $offset ) {
212 $final_post_per_page = $limit - $offset;
213 }
214 return $final_post_per_page;
215 }
216
217 /**
218 * Pagination last page post
219 *
220 * @param int $limit total post limit.
221 * @param int $post_per_page post per page.
222 * @param int $total_page last post page.
223 *
224 * @return int.
225 */
226 public static function pcp_last_page_post( $limit, $post_per_page, $total_page ) {
227 $limit = ( empty( $limit ) || '-1' === $limit ) ? 10000000 : $limit;
228 $offset = $post_per_page * ( $total_page - 1 );
229 $pcp_last_page_post = $limit - $offset;
230 return $pcp_last_page_post;
231 }
232
233 /**
234 * Get view option from view ID
235 *
236 * @param string $pcp_gl_id ID of custom field.
237 *
238 * @return array
239 */
240 public static function view_options( $pcp_gl_id ) {
241 if ( ! $pcp_gl_id ) {
242 return;
243 }
244 $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
245 return $view_options;
246 }
247
248 /**
249 * Get value of a setting from global settings array
250 *
251 * @param string $field The full name of setting to get value.
252 * @param array $array_to_get Array to get values of wanted setting.
253 * @param mixed|null $assign The value to assign if setting is not found.
254 */
255 public static function pcp_metabox_value( $field, $array_to_get = null, $assign = null ) {
256 global $pcp_gl_id;
257 if ( empty( $array_to_get ) ) {
258 $array_to_get = self::view_options( $pcp_gl_id );
259 }
260 return isset( $array_to_get[ $field ] ) ? $array_to_get[ $field ] : $assign;
261 }
262
263 }
264