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

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

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