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
← All changes | public/class-smart-post-show-public.php +141 -199 4.0.7 → 2.2.10 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /**
3 3 * File for the public facing functions.
4 4 *
5 - * @link https://wpsmartpost.com/
5 + * @link https://smartpostshow.com/
6 6 * @since 2.2.0
7 7 *
8 8 * @package Smart_Post_Show
9 9 * @subpackage Smart_Post_Show/public
@@ -8,14 +8,14 @@
8 8 * @package Smart_Post_Show
9 9 * @subpackage Smart_Post_Show/public
10 10 */
11 11
12 -if ( ! defined( 'ABSPATH' ) ) {
13 - exit; // Exit if accessed directly.
14 -}
15 -
16 12 /**
17 13 * The public-facing functionality of the plugin.
14 + *
15 + * @package Smart_Post_Show
16 + * @subpackage Smart_Post_Show/public
17 + * @author ShapedPlugin <[email protected]>
18 18 */
19 19 class Smart_Post_Show_Public {
20 20
21 21 /**
@@ -53,259 +53,201 @@
53 53 *
54 54 * @return void
55 55 */
56 56 private function pcp_public_action() {
57 - add_action( 'template_redirect', array( $this, 'pcp_handle_site_mode_redirection' ) );
58 57 add_shortcode( 'smart_post_show', array( $this, 'pcp_shortcode_render' ) );
59 58 add_shortcode( 'sp_postcarousel', array( $this, 'pcp_shortcode_render' ) );
60 59 add_shortcode( 'post-carousel', array( $this, 'pcp_shortcode_render' ) );
61 - add_action( 'save_post', array( $this, 'delete_page_sp_pcp_option_on_save' ) );
62 60
63 61 $this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? '' : '.min';
64 62 }
65 63
66 -
67 64 /**
68 - * Handle Site Mode (Maintenance/Coming Soon) redirection.
65 + * Register the stylesheets for the public-facing side of the site.
69 66 *
70 - * @return void
67 + * @since 2.2.0
71 68 */
72 - public function pcp_handle_site_mode_redirection() {
73 - $settings = get_option( 'sp_post_carousel_settings', array() );
74 - $site_mode = isset( $settings['pcp_site_mode'] ) ? $settings['pcp_site_mode'] : 'live';
75 - $redirect_page_id = isset( $settings['pcp_select_page'] ) ? absint( $settings['pcp_select_page'] ) : 0;
76 - $user_capability = apply_filters( 'pcp_user_role_permission', 'manage_options' );
69 + public function enqueue_styles() {
77 70
78 - if ( 'live' !== $site_mode && ! empty( $redirect_page_id ) ) {
79 - if ( ! current_user_can( $user_capability ) ) {
80 - $current_page_id = get_queried_object_id();
81 - if ( $current_page_id !== $redirect_page_id ) {
82 - wp_safe_redirect( get_permalink( $redirect_page_id ) );
83 - exit;
84 - }
85 - }
71 + $pcp_settings = get_option( 'sp_post_carousel_settings' );
72 + if ( $pcp_settings['pcp_fontawesome_css'] ) {
73 + wp_enqueue_style( 'font-awesome', SP_PC_URL . 'public/assets/css/font-awesome.min.css', array(), SP_PC_VERSION, 'all' );
86 74 }
75 + if ( $pcp_settings['pcp_swiper_css'] ) {
76 + wp_enqueue_style( 'pcp_swiper', SP_PC_URL . 'public/assets/css/swiper-bundle' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
77 + }
78 + wp_enqueue_style( 'pcp-style', SP_PC_URL . 'public/assets/css/style' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
79 +
80 + $pcp_posts = new WP_Query(
81 + array(
82 + 'post_type' => 'sp_post_carousel',
83 + 'posts_per_page' => 900,
84 + )
85 + );
86 + $post_ids = wp_list_pluck( $pcp_posts->posts, 'ID' );
87 + $custom_css = '';
88 + $pcp_custom_css = $pcp_settings['pcp_custom_css'];
89 + foreach ( $post_ids as $pcp_id ) {
90 + // Include dynamic style file.
91 + include 'dynamic-css/dynamic-css.php';
92 + }
93 + if ( ! empty( $pcp_custom_css ) ) {
94 + $custom_css .= $pcp_custom_css;
95 + }
96 + // Add dynamic style.
97 + wp_add_inline_style( 'pcp-style', $custom_css );
87 98 }
88 99
89 100 /**
90 - * Minify output
101 + * Register the JavaScript for the public-facing side of the site.
91 102 *
92 - * @param statement $html output.
93 - * @return statement
103 + * @since 2.2.0
94 104 */
95 - public static function minify_output( $html ) {
96 - $html = preg_replace( '/<!--(?!s*(?:[if [^]]+]|!|>))(?:(?!-->).)*-->/s', '', $html );
97 - $html = str_replace( array( "\r\n", "\r", "\n", "\t" ), '', $html );
98 - while ( stristr( $html, ' ' ) ) {
99 - $html = str_replace( ' ', ' ', $html );
100 - }
101 - return $html;
105 + public function enqueue_scripts() {
106 + wp_register_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
107 + wp_register_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
102 108 }
103 109
104 110 /**
105 - * Register the stylesheets for the public-facing side of the site.
111 + * PCP shortcode markup wrapper classes.
106 112 *
107 - * @since 2.2.0
113 + * @param string $layout_preset The selected layout name.
114 + * @param int $shortcode_id The shortcode ID.
108 115 */
109 - public function enqueue_styles() {
110 - // Get the existing shortcode ids from the current page.
111 - $get_page_data = self::get_page_data();
112 - $found_shortcode_id = $get_page_data['generator_id'];
113 - // Check shortcode ids are exist in the current page and then enqueue all styles.
114 - if ( $found_shortcode_id ) {
115 - wp_enqueue_style( 'font-awesome' );
116 - wp_enqueue_style( 'pcp_swiper' );
117 - wp_enqueue_style( 'pcp_fonttello_icon' );
118 - wp_enqueue_style( 'pcp-style' );
119 - $dynamic_style = self::load_dynamic_style( $found_shortcode_id );
120 - wp_add_inline_style( 'pcp-style', $dynamic_style['dynamic_css'] );
116 + public static function pcp_wrapper_classes( $layout_preset, $shortcode_id ) {
117 + $wrapper_class = "sp-pcp-section sp-pcp-container pcp-wrapper-{$shortcode_id}";
118 + switch ( $layout_preset ) {
119 + case 'carousel_layout':
120 + $wrapper_class .= ' pcp-carousel-wrapper';
121 + break;
121 122 }
123 + echo esc_attr( $wrapper_class );
122 124 }
123 125
124 126 /**
125 - * Function get layout from attrs and create class depending on it.
127 + * Shortcode Wrapper data attributes.
126 128 *
127 - * @since 2.0
128 - * @param array $attribute attribute of this shortcode.
129 + * @param int $shortcode_id The shortcode ID.
130 + * @return void
129 131 */
130 - public function pcp_shortcode_render( $attribute ) {
131 - $shortcode_id = esc_attr( intval( $attribute['id'] ) );
132 - // Check the shortcode existence and status.
133 - if ( empty( $shortcode_id ) || 'sp_post_carousel' !== get_post_type( $shortcode_id ) || 'trash' === get_post_status( $shortcode_id ) ) {
134 - return;
135 - }
136 - // Preset Layouts.
137 - $layout = get_post_meta( $shortcode_id, 'sp_pcp_layouts', true );
138 - // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
139 - $view_options = get_post_meta( $shortcode_id, 'sp_pcp_view_options', true );
140 - $section_title = get_the_title( $shortcode_id );
132 + public static function wrapper_data( $shortcode_id ) {
133 + $wrapper_data = " data-pagination= 'no_ajax'";
141 134
142 - // Get the existing shortcode id from the current page.
143 - $get_page_data = self::get_page_data();
144 - $found_shortcode_id = $get_page_data['generator_id'];
145 - ob_start();
146 - // Check if shortcode and page ids are not exist in the current page then enqueue the stylesheet.
147 - if ( ! is_array( $found_shortcode_id ) || ! $found_shortcode_id || ! in_array( $shortcode_id, $found_shortcode_id ) ) {
148 - wp_enqueue_style( 'font-awesome' );
149 - wp_enqueue_style( 'pcp_swiper' );
150 - wp_enqueue_style( 'pcp-style' );
151 - $dynamic_style = self::load_dynamic_style( $shortcode_id, $view_options, $layout );
152 - // Add dynamic style.
153 - echo '<style id="sp_pcp_dynamic_style' . esc_attr( $shortcode_id ) . '">' . wp_strip_all_tags( $dynamic_style['dynamic_css'] ) . '</style>'; // phpcs:ignore
135 + if ( $shortcode_id ) {
136 + $wrapper_data .= " data-sid={$shortcode_id}";
154 137 }
155 - // Update options if the existing shortcode id option not found.
156 - self::sps_db_options_update( $shortcode_id, $get_page_data );
157 - SP_PC_Output::pc_html_show( $view_options, $layout, $shortcode_id, $section_title );
158 - return ob_get_clean();
138 + echo esc_html( $wrapper_data );
159 139 }
160 140
161 141 /**
162 - * Register all Styles and Scripts for the public-facing side of the site.
142 + * HTML classes for Post.
163 143 *
164 - * @since 2.4.17
144 + * @return string
165 145 */
166 - public function register_all_scripts() {
167 - $pcp_settings = get_option( 'sp_post_carousel_settings' );
168 - /**
169 - * Register all the styles for the public-facing side of the site.
170 - */
171 - if ( $pcp_settings['pcp_fontawesome_css'] ) {
172 - wp_register_style( 'font-awesome', SP_PC_URL . 'public/assets/css/font-awesome.min.css', array(), SP_PC_VERSION, 'all' );
173 - }
174 - if ( $pcp_settings['pcp_swiper_css'] ) {
175 - wp_register_style( 'pcp_swiper', SP_PC_URL . 'public/assets/css/swiper-bundle.min.css', array(), SP_PC_VERSION, 'all' );
176 - }
177 - wp_register_style( 'pcp_fonttello_icon', SP_PC_URL . 'admin/assets/css/fontello.min.css', array(), SP_PC_VERSION, 'all' );
178 -
179 - wp_register_style( 'pcp-style', SP_PC_URL . 'public/assets/css/style.min.css', array(), SP_PC_VERSION, 'all' );
180 -
181 - /**
182 - * Register all the Scripts for the public-facing side of the site.
183 - */
184 - wp_register_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle.min.js', array( 'jquery' ), SP_PC_VERSION, true );
185 - wp_register_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts.min.js', array( 'jquery' ), SP_PC_VERSION, true );
186 -
187 - wp_localize_script(
188 - 'pcp_script',
189 - 'pcp_vars',
190 - array(
191 - 'swiperEnqueue' => $pcp_settings['pcp_swiper_js'],
192 - )
193 - );
146 + public static function pcp_alt_post_class() {
147 + $pcp_alt_post_class = 'sp-pcp-post';
148 + return apply_filters( 'post_post_class_name', $pcp_alt_post_class );
194 149 }
195 150
196 151 /**
197 - * Gets the existing shortcode-id, page-id and option-key from the current page.
152 + * Post responsive columns class.
198 153 *
199 - * @return array
154 + * @param string $layout Layout preset.
155 + * @param string $columns Columns number.
156 + * @return string
200 157 */
201 - public static function get_page_data() {
202 - $current_page_id = get_queried_object_id();
203 - $option_key = 'sp_pcp_page_id' . $current_page_id;
204 - $found_generator_id = get_option( $option_key );
205 - if ( is_multisite() ) {
206 - $option_key = 'sp_pcp_page_id' . get_current_blog_id() . $current_page_id;
207 - $found_generator_id = get_site_option( $option_key );
158 + public static function pcp_post_responsive_columns( $layout, $columns ) {
159 + $pcp_post_columns = '';
160 + if ( 'carousel_layout' === $layout ) {
161 + $pcp_post_columns .= ' swiper-slide swiper-lazy';
162 + } else {
163 + $pcp_post_columns .= " sp-pcp-col-xs-$columns[mobile] sp-pcp-col-sm-$columns[mobile_landscape] sp-pcp-col-md-$columns[tablet] sp-pcp-col-lg-$columns[desktop] sp-pcp-col-xl-$columns[lg_desktop]";
208 164 }
209 - $get_page_data = array(
210 - 'page_id' => $current_page_id,
211 - 'generator_id' => $found_generator_id,
212 - 'option_key' => $option_key,
213 - );
214 - return $get_page_data;
165 + return $pcp_post_columns;
215 166 }
216 167
217 168 /**
218 - * If the option does not exist, it will be created.
169 + * Post Loop.
219 170 *
220 - * It will be serialized before it is inserted into the database.
221 - *
222 - * @param string $post_id existing shortcode id.
223 - * @param array $get_page_data get current page-id, shortcode-id and option-key from the the current page.
171 + * @param array $options Views options.
172 + * @param string $layout Layout preset.
173 + * @param array $sorter Post sorting options.
174 + * @param int $scode_id Shortcode ID.
224 175 * @return void
225 176 */
226 - public static function sps_db_options_update( $post_id, $get_page_data ) {
227 - $found_generator_id = $get_page_data['generator_id'];
228 - $option_key = $get_page_data['option_key'];
229 - $current_page_id = $get_page_data['page_id'];
230 - if ( $found_generator_id ) {
231 - $found_generator_id = is_array( $found_generator_id ) ? $found_generator_id : array( $found_generator_id );
232 - if ( ! in_array( $post_id, $found_generator_id ) || empty( $found_generator_id ) ) {
233 - // If not found the shortcode id in the page options.
234 - array_push( $found_generator_id, $post_id );
235 - if ( is_multisite() ) {
236 - update_site_option( $option_key, $found_generator_id );
237 - } else {
238 - update_option( $option_key, $found_generator_id );
239 - }
240 - }
241 - } else {
242 - // If option not set in current page add option.
243 - if ( $current_page_id ) {
244 - if ( is_multisite() ) {
245 - add_site_option( $option_key, array( $post_id ) );
246 - } else {
247 - add_option( $option_key, array( $post_id ) );
248 - }
249 - }
250 - }
177 + public static function pcp_post_loop( $options, $layout, $sorter, $scode_id ) {
178 + global $post;
179 + $number_of_columns = SP_PC_Functions::pcp_metabox_value( 'pcp_number_of_columns', $options );
180 + ?>
181 + <div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns ) ); ?>">
182 + <div class="sp-pcp-post pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
183 + <?php
184 + SP_PC_HTML::pcp_post_content_with_thumb( $sorter, $layout, $scode_id, $post, $options );
185 + ?>
186 + </div>
187 + </div>
188 + <?php
251 189 }
252 190
253 191 /**
254 - * Load dynamic style of the existing shortcode id.
192 + * Get all query posts.
255 193 *
256 - * @param mixed $found_generator_id to push id option for getting how many shortcode in the page.
257 - * @param mixed $view_options shortcode options.
258 - * @param mixed $layout all layout based options.
259 - * @return array dynamic style use in the existing shortcodes in the current page.
194 + * @param array $options Views options.
195 + * @param array $layout Layout preset.
196 + * @param array $sorter Post sorting options.
197 + * @param object $pcp_query post query.
198 + * @param int $view_id Shortcode ID.
199 + * @return void
260 200 */
261 - public static function load_dynamic_style( $found_generator_id, $view_options = array(), $layout = '' ) {
262 - $pcp_settings = get_option( 'sp_post_carousel_settings' );
263 - $custom_css = '';
264 - // If multiple shortcode found in the current page.
265 - if ( is_array( $found_generator_id ) ) {
266 - foreach ( $found_generator_id as $pcp_id ) {
267 - if ( $pcp_id && is_numeric( $pcp_id ) && get_post_status( $pcp_id ) !== 'trash' ) {
268 - $view_options = get_post_meta( $pcp_id, 'sp_pcp_view_options', true );
269 - $layout = get_post_meta( $pcp_id, 'sp_pcp_layouts', true );
270 - if ( is_array( $view_options ) ) {
271 - include SP_PC_PATH . 'public/dynamic-css/dynamic-css.php';
272 - }
273 - }
274 - }
275 - } else {
276 - // If single shortcode found in the current page.
277 - $pcp_id = $found_generator_id;
278 - if ( is_array( $view_options ) ) {
279 - include SP_PC_PATH . 'public/dynamic-css/dynamic-css.php';
280 - }
201 + public static function pcp_get_posts( $options, $layout, $sorter, $pcp_query, $view_id ) {
202 + $pcp_count = 1;
203 + while ( $pcp_query->have_posts() ) {
204 + $pcp_query->the_post();
205 + self::pcp_post_loop( $options, $layout, $sorter, $view_id );
206 + $pcp_count++;
281 207 }
282 - // Custom css merge with dynamic style.
283 - $pcp_custom_css = isset( $pcp_settings['pcp_custom_css'] ) ? trim( html_entity_decode( $pcp_settings['pcp_custom_css'] ) ) : '';
284 - if ( ! empty( $pcp_custom_css ) ) {
285 - $custom_css .= $pcp_custom_css;
286 - }
287 - $dynamic_style = array(
288 - 'dynamic_css' => self::minify_output( $custom_css ),
289 - );
290 - return $dynamic_style;
208 + wp_reset_postdata();
291 209 }
292 210
293 211 /**
294 - * Delete page shortcode ids array option on save
212 + * Function get layout from atts and create class depending on it.
295 213 *
296 - * @param int $post_ID current post id.
297 - * @return void
298 - *
299 - * @since 2.4.17
214 + * @since 2.0
215 + * @param array $attribute attribute of this shortcode.
300 216 */
301 - public function delete_page_sp_pcp_option_on_save( $post_ID ) {
302 - if ( is_multisite() ) {
303 - $option_key = 'sp_pcp_page_id' . get_current_blog_id() . $post_ID;
304 - if ( get_site_option( $option_key ) ) {
305 - delete_site_option( $option_key );
306 - }
307 - } elseif ( get_option( 'sp_pcp_page_id' . $post_ID ) ) {
308 - delete_option( 'sp_pcp_page_id' . $post_ID );
217 + public function pcp_shortcode_render( $attribute ) {
218 + if ( empty( $attribute['id'] ) ) {
219 + return;
309 220 }
221 + $pcp_gl_id = $attribute['id']; // Smart Post Show global ID for Shortcode metaboxes.
222 + // Setting options.
223 + $pcp_settings = get_option( 'sp_post_carousel_settings' );
224 + // Preset Layouts.
225 + $layout = get_post_meta( $pcp_gl_id, 'sp_pcp_layouts', true );
226 + $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
227 + // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
228 + $options = SP_PC_Functions::view_options( $pcp_gl_id );
229 + $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
230 + $post_content_sorter = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
231 + $pcp_content_position = isset( $view_options['post_content_orientation'] ) ? $view_options['post_content_orientation'] : '';
232 + $margin_between_post = isset( $view_options['margin_between_post']['all'] ) ? $view_options['margin_between_post']['all'] : '';
233 + $show_preloader = isset( $view_options['show_preloader'] ) ? $view_options['show_preloader'] : 0;
234 + $query_args = SP_PC_QueryInside::get_filtered_content( $pcp_gl_id );
235 + $pcp_query = new WP_Query( $query_args );
236 + $total_post_count = $pcp_query->post_count;
237 + // Pagination.
238 + $show_pagination = isset( $view_options['show_post_pagination'] ) ? $view_options['show_post_pagination'] : '';
239 +
240 + wp_enqueue_script( 'pcp_script' );
241 + $pcp_custom_js = $pcp_settings['pcp_custom_js'];
242 + if ( ! empty( $pcp_custom_js ) ) {
243 + wp_add_inline_script( 'pcp_script', $pcp_custom_js );
244 + }
245 + ob_start();
246 + if ( 'carousel_layout' === $layout_preset ) {
247 + require SP_PC_TEMPLATE_PATH . '/carousel.php';
248 + } elseif ( 'grid_layout' === $layout_preset ) {
249 + require SP_PC_TEMPLATE_PATH . '/grid.php';
250 + }
251 + return ob_get_clean();
310 252 }
311 253 }