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 +146 -176 2.4.21 → 2.2.10 View file →
@@ -10,8 +10,12 @@
10 10 */
11 11
12 12 /**
13 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]>
14 18 */
15 19 class Smart_Post_Show_Public {
16 20
17 21 /**
@@ -52,232 +56,198 @@
52 56 private function pcp_public_action() {
53 57 add_shortcode( 'smart_post_show', array( $this, 'pcp_shortcode_render' ) );
54 58 add_shortcode( 'sp_postcarousel', array( $this, 'pcp_shortcode_render' ) );
55 59 add_shortcode( 'post-carousel', array( $this, 'pcp_shortcode_render' ) );
56 - add_action( 'save_post', array( $this, 'delete_page_sp_pcp_option_on_save' ) );
57 60
58 61 $this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? '' : '.min';
59 62 }
60 63
61 64 /**
62 - * Minify output
65 + * Register the stylesheets for the public-facing side of the site.
63 66 *
64 - * @param statement $html output.
65 - * @return statement
67 + * @since 2.2.0
66 68 */
67 - public static function minify_output( $html ) {
68 - $html = preg_replace( '/<!--(?!s*(?:[if [^]]+]|!|>))(?:(?!-->).)*-->/s', '', $html );
69 - $html = str_replace( array( "\r\n", "\r", "\n", "\t" ), '', $html );
70 - while ( stristr( $html, ' ' ) ) {
71 - $html = str_replace( ' ', ' ', $html );
69 + public function enqueue_styles() {
70 +
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' );
72 74 }
73 - return $html;
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 );
74 98 }
75 99
76 100 /**
77 - * Register the stylesheets for the public-facing side of the site.
101 + * Register the JavaScript for the public-facing side of the site.
78 102 *
79 - * @since 2.2.0
103 + * @since 2.2.0
80 104 */
81 - public function enqueue_styles() {
82 - // Get the existing shortcode ids from the current page.
83 - $get_page_data = self::get_page_data();
84 - $found_shortcode_id = $get_page_data['generator_id'];
85 - // Check shortcode ids are exist in the current page and then enqueue all styles.
86 - if ( $found_shortcode_id ) {
87 - wp_enqueue_style( 'font-awesome' );
88 - wp_enqueue_style( 'pcp_swiper' );
89 - wp_enqueue_style( 'pcp-style' );
90 - $dynamic_style = self::load_dynamic_style( $found_shortcode_id );
91 - wp_add_inline_style( 'pcp-style', $dynamic_style['dynamic_css'] );
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 );
108 + }
109 +
110 + /**
111 + * PCP shortcode markup wrapper classes.
112 + *
113 + * @param string $layout_preset The selected layout name.
114 + * @param int $shortcode_id The shortcode ID.
115 + */
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;
92 122 }
123 + echo esc_attr( $wrapper_class );
93 124 }
94 125
95 126 /**
96 - * Function get layout from attrs and create class depending on it.
127 + * Shortcode Wrapper data attributes.
97 128 *
98 - * @since 2.0
99 - * @param array $attribute attribute of this shortcode.
129 + * @param int $shortcode_id The shortcode ID.
130 + * @return void
100 131 */
101 - public function pcp_shortcode_render( $attribute ) {
102 - $shortcode_id = esc_attr( intval( $attribute['id'] ) );
103 - // Check the shortcode existence and status.
104 - if ( empty( $shortcode_id ) || 'sp_post_carousel' !== get_post_type( $shortcode_id ) || 'trash' === get_post_status( $shortcode_id ) ) {
105 - return;
106 - }
107 - // Preset Layouts.
108 - $layout = get_post_meta( $shortcode_id, 'sp_pcp_layouts', true );
109 - // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
110 - $view_options = get_post_meta( $shortcode_id, 'sp_pcp_view_options', true );
111 - $section_title = get_the_title( $shortcode_id );
132 + public static function wrapper_data( $shortcode_id ) {
133 + $wrapper_data = " data-pagination= 'no_ajax'";
112 134
113 - // Get the existing shortcode id from the current page.
114 - $get_page_data = self::get_page_data();
115 - $found_shortcode_id = $get_page_data['generator_id'];
116 - ob_start();
117 - // Check if shortcode and page ids are not exist in the current page then enqueue the stylesheet.
118 - if ( ! is_array( $found_shortcode_id ) || ! $found_shortcode_id || ! in_array( $shortcode_id, $found_shortcode_id ) ) {
119 - wp_enqueue_style( 'font-awesome' );
120 - wp_enqueue_style( 'pcp_swiper' );
121 - wp_enqueue_style( 'pcp-style' );
122 - $dynamic_style = self::load_dynamic_style( $shortcode_id, $view_options, $layout );
123 - // Add dynamic style.
124 - echo '<style id="sp_pcp_dynamic_style' . esc_attr( $shortcode_id ) . '">' . $dynamic_style['dynamic_css'] . '</style>'; // phpcs:ignore
135 + if ( $shortcode_id ) {
136 + $wrapper_data .= " data-sid={$shortcode_id}";
125 137 }
126 - // Update options if the existing shortcode id option not found.
127 - self::sps_db_options_update( $shortcode_id, $get_page_data );
128 - SP_PC_Output::pc_html_show( $view_options, $layout, $shortcode_id, $section_title );
129 - return ob_get_clean();
138 + echo esc_html( $wrapper_data );
130 139 }
131 140
132 141 /**
133 - * Register all Styles and Scripts for the public-facing side of the site.
142 + * HTML classes for Post.
134 143 *
135 - * @since 2.4.17
144 + * @return string
136 145 */
137 - public function register_all_scripts() {
138 - $pcp_settings = get_option( 'sp_post_carousel_settings' );
139 - /**
140 - * Register all the styles for the public-facing side of the site.
141 - */
142 - if ( $pcp_settings['pcp_fontawesome_css'] ) {
143 - wp_register_style( 'font-awesome', SP_PC_URL . 'public/assets/css/font-awesome.min.css', array(), SP_PC_VERSION, 'all' );
144 - }
145 - if ( $pcp_settings['pcp_swiper_css'] ) {
146 - wp_register_style( 'pcp_swiper', SP_PC_URL . 'public/assets/css/swiper-bundle' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
147 - }
148 - wp_register_style( 'pcp-style', SP_PC_URL . 'public/assets/css/style' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
149 -
150 - /**
151 - * Register all the Scripts for the public-facing side of the site.
152 - */
153 - wp_register_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
154 - wp_register_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
155 -
156 - wp_localize_script(
157 - 'pcp_script',
158 - 'pcp_vars',
159 - array(
160 - 'swiperEnqueue' => $pcp_settings['pcp_swiper_js'],
161 - )
162 - );
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 );
163 149 }
164 150
165 151 /**
166 - * Gets the existing shortcode-id, page-id and option-key from the current page.
152 + * Post responsive columns class.
167 153 *
168 - * @return array
154 + * @param string $layout Layout preset.
155 + * @param string $columns Columns number.
156 + * @return string
169 157 */
170 - public static function get_page_data() {
171 - $current_page_id = get_queried_object_id();
172 - $option_key = 'sp_pcp_page_id' . $current_page_id;
173 - $found_generator_id = get_option( $option_key );
174 - if ( is_multisite() ) {
175 - $option_key = 'sp_pcp_page_id' . get_current_blog_id() . $current_page_id;
176 - $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]";
177 164 }
178 - $get_page_data = array(
179 - 'page_id' => $current_page_id,
180 - 'generator_id' => $found_generator_id,
181 - 'option_key' => $option_key,
182 - );
183 - return $get_page_data;
165 + return $pcp_post_columns;
184 166 }
185 167
186 168 /**
187 - * If the option does not exist, it will be created.
169 + * Post Loop.
188 170 *
189 - * It will be serialized before it is inserted into the database.
190 - *
191 - * @param string $post_id existing shortcode id.
192 - * @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.
193 175 * @return void
194 176 */
195 - public static function sps_db_options_update( $post_id, $get_page_data ) {
196 - $found_generator_id = $get_page_data['generator_id'];
197 - $option_key = $get_page_data['option_key'];
198 - $current_page_id = $get_page_data['page_id'];
199 - if ( $found_generator_id ) {
200 - $found_generator_id = is_array( $found_generator_id ) ? $found_generator_id : array( $found_generator_id );
201 - if ( ! in_array( $post_id, $found_generator_id ) || empty( $found_generator_id ) ) {
202 - // If not found the shortcode id in the page options.
203 - array_push( $found_generator_id, $post_id );
204 - if ( is_multisite() ) {
205 - update_site_option( $option_key, $found_generator_id );
206 - } else {
207 - update_option( $option_key, $found_generator_id );
208 - }
209 - }
210 - } else {
211 - // If option not set in current page add option.
212 - if ( $current_page_id ) {
213 - if ( is_multisite() ) {
214 - add_site_option( $option_key, array( $post_id ) );
215 - } else {
216 - add_option( $option_key, array( $post_id ) );
217 - }
218 - }
219 - }
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
220 189 }
221 190
222 191 /**
223 - * Load dynamic style of the existing shortcode id.
192 + * Get all query posts.
224 193 *
225 - * @param mixed $found_generator_id to push id option for getting how many shortcode in the page.
226 - * @param mixed $view_options shortcode options.
227 - * @param mixed $layout all layout based options.
228 - * @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
229 200 */
230 - public static function load_dynamic_style( $found_generator_id, $view_options = array(), $layout = '' ) {
231 - $pcp_settings = get_option( 'sp_post_carousel_settings' );
232 - $custom_css = '';
233 - // If multiple shortcode found in the current page.
234 - if ( is_array( $found_generator_id ) ) {
235 - foreach ( $found_generator_id as $pcp_id ) {
236 - if ( $pcp_id && is_numeric( $pcp_id ) && get_post_status( $pcp_id ) !== 'trash' ) {
237 - $view_options = get_post_meta( $pcp_id, 'sp_pcp_view_options', true );
238 - $layout = get_post_meta( $pcp_id, 'sp_pcp_layouts', true );
239 - if ( is_array( $view_options ) ) {
240 - include SP_PC_PATH . 'public/dynamic-css/dynamic-css.php';
241 - }
242 - }
243 - }
244 - } else {
245 - // If single shortcode found in the current page.
246 - $pcp_id = $found_generator_id;
247 - if ( is_array( $view_options ) ) {
248 - include SP_PC_PATH . 'public/dynamic-css/dynamic-css.php';
249 - }
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++;
250 207 }
251 - // Custom css merge with dynamic style.
252 - $pcp_custom_css = isset( $pcp_settings['pcp_custom_css'] ) ? trim( html_entity_decode( $pcp_settings['pcp_custom_css'] ) ) : '';
253 - if ( ! empty( $pcp_custom_css ) ) {
254 - $custom_css .= $pcp_custom_css;
255 - }
256 - $dynamic_style = array(
257 - 'dynamic_css' => self::minify_output( $custom_css ),
258 - );
259 - return $dynamic_style;
208 + wp_reset_postdata();
260 209 }
261 210
262 211 /**
263 - * Delete page shortcode ids array option on save
212 + * Function get layout from atts and create class depending on it.
264 213 *
265 - * @param int $post_ID current post id.
266 - * @return void
267 - *
268 - * @since 2.4.17
214 + * @since 2.0
215 + * @param array $attribute attribute of this shortcode.
269 216 */
270 - public function delete_page_sp_pcp_option_on_save( $post_ID ) {
271 - if ( is_multisite() ) {
272 - $option_key = 'sp_pcp_page_id' . get_current_blog_id() . $post_ID;
273 - if ( get_site_option( $option_key ) ) {
274 - delete_site_option( $option_key );
275 - }
276 - } else {
277 - if ( get_option( 'sp_pcp_page_id' . $post_ID ) ) {
278 - delete_option( 'sp_pcp_page_id' . $post_ID );
279 - }
217 + public function pcp_shortcode_render( $attribute ) {
218 + if ( empty( $attribute['id'] ) ) {
219 + return;
280 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();
281 252 }
282 -
283 253 }