PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.0
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.0
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.0, at public/helpers/class-post-functions.php

263 lines 7.5 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 = $image_src[0];
108 $image_width = $image_src[1];
109 $image_height = $image_src[2];
110 } elseif ( ! empty( $placeholder_img ) ) {
111 $image = $placeholder_img;
112 $image_width = 600;
113 $image_height = 450;
114 }
115 $pcp_image_attr = array(
116 'src' => $image,
117 'width' => $image_width,
118 'height' => $image_height,
119 );
120 return $pcp_image_attr;
121 }
122
123 /**
124 * Process all the post meta.
125 *
126 * @param array $post_meta_fields The selected post meta to show.
127 * @param string $meta_separator The post meta separator.
128 * @return void
129 */
130 public static function pcp_get_post_meta( $post_meta_fields, $meta_separator ) {
131 $i = 0;
132 foreach ( $post_meta_fields as $each_meta ) {
133 $selected_meta = $each_meta['select_post_meta'];
134 $meta_icon = ! empty( $each_meta['select_meta_icon'] ) ? sprintf( '<i class="' . $each_meta['select_meta_icon'] . '"></i>' ) : '';
135 $meta_tag_start = apply_filters( 'pcp_post_meta_html_tag_start', '<li>' );
136 $meta_tag_end = apply_filters( 'pcp_post_meta_html_tag_end', '</li>' );
137
138 switch ( $selected_meta ) {
139 case 'author':
140 if ( 0 < $i ) {
141 echo esc_html( $meta_separator );
142 }
143 echo wp_kses_post( $meta_tag_start );
144 ?>
145 <i class="fa fa-user"></i>
146 <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"
147 rel="author"><?php echo esc_html( get_the_author() ); ?></a>
148 <?php
149 echo wp_kses_post( $meta_tag_end );
150 break;
151 case 'date':
152 if ( 0 < $i ) {
153 echo esc_html( $meta_separator );
154 }
155 echo wp_kses_post( $meta_tag_start );
156 ?>
157 <i class="fa fa-calendar"></i>
158
159 <time class="entry-date published updated"><?php echo esc_html( get_the_date() ); ?></time>
160 <?php
161 echo wp_kses_post( $meta_tag_end );
162 break;
163 case 'comment_count':
164 if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
165 if ( 0 < $i ) {
166 echo esc_html( $meta_separator );
167 }
168 echo wp_kses_post( $meta_tag_start );
169 ?>
170 <i class="fa fa-comments-o"></i>
171 <a href="<?php the_permalink(); ?>"><?php echo esc_html( get_comments_number() ); ?></a>
172 <?php
173 echo wp_kses_post( $meta_tag_end );
174 }
175 break;
176 }
177 ++$i;
178 } // End Foreach.
179 }
180
181 /**
182 * Maximum pages.
183 *
184 * @param int $total_post Number of total posts.
185 * @param int $post_per_page Posts per page.
186 *
187 * @return void
188 */
189 public static function pcp_max_pages( $total_post, $post_per_page ) {
190 if ( ! $total_post ) {
191 return;
192 }
193 $max_num_pages = ceil( $total_post / $post_per_page );
194 return (int) $max_num_pages;
195 }
196
197 /**
198 * Post per page.
199 *
200 * @param int $limit Post Limit.
201 * @param int $post_per_page post per page.
202 * @param int $page paged number.
203 *
204 * @return int
205 */
206 public static function pcp_post_per_page( $limit, $post_per_page, $page ) {
207 $limit = ( empty( $limit ) || '-1' === $limit ) ? 1000000 : $limit;
208 $offset = (int) $post_per_page * ( $page - 1 );
209 $final_post_per_page = $post_per_page;
210 if ( intval( $post_per_page ) > $limit - $offset ) {
211 $final_post_per_page = $limit - $offset;
212 }
213 return $final_post_per_page;
214 }
215
216 /**
217 * Pagination last page post
218 *
219 * @param int $limit total post limit.
220 * @param int $post_per_page post per page.
221 * @param int $total_page last post page.
222 *
223 * @return int.
224 */
225 public static function pcp_last_page_post( $limit, $post_per_page, $total_page ) {
226 $limit = ( empty( $limit ) || '-1' === $limit ) ? 10000000 : $limit;
227 $offset = $post_per_page * ( $total_page - 1 );
228 $pcp_last_page_post = $limit - $offset;
229 return $pcp_last_page_post;
230 }
231
232 /**
233 * Get view option from view ID
234 *
235 * @param string $pcp_gl_id ID of custom field.
236 *
237 * @return array
238 */
239 public static function view_options( $pcp_gl_id ) {
240 if ( ! $pcp_gl_id ) {
241 return;
242 }
243 $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
244 return $view_options;
245 }
246
247 /**
248 * Get value of a setting from global settings array
249 *
250 * @param string $field The full name of setting to get value.
251 * @param array $array_to_get Array to get values of wanted setting.
252 * @param mixed|null $assign The value to assign if setting is not found.
253 */
254 public static function pcp_metabox_value( $field, $array_to_get = null, $assign = null ) {
255 global $pcp_gl_id;
256 if ( empty( $array_to_get ) ) {
257 $array_to_get = self::view_options( $pcp_gl_id );
258 }
259 return isset( $array_to_get[ $field ] ) ? $array_to_get[ $field ] : $assign;
260 }
261
262 }
263