PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.3.6
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.3.6
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 / class-smart-post-show-public.php

class-smart-post-show-public.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.3.6, at public/class-smart-post-show-public.php

169 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * File for the public facing functions.
4 *
5 * @link https://smartpostshow.com/
6 * @since 2.2.0
7 *
8 * @package Smart_Post_Show
9 * @subpackage Smart_Post_Show/public
10 */
11
12 /**
13 * The public-facing functionality of the plugin.
14 *
15 * @package Smart_Post_Show
16 * @subpackage Smart_Post_Show/public
17 * @author ShapedPlugin <support@shapedplugin.com>
18 */
19 class Smart_Post_Show_Public {
20
21 /**
22 * Script and style suffix
23 *
24 * @since 2.2.0
25 * @access protected
26 * @var string
27 */
28 protected $suffix;
29
30 /**
31 * Initialize the class and set its properties.
32 *
33 * @since 2.2.0
34 */
35 public function __construct() {
36 $this->load_public_dependencies();
37 $this->pcp_public_action();
38 }
39
40 /**
41 * Public dependencies.
42 *
43 * @return void
44 */
45 private function load_public_dependencies() {
46 require_once SP_PC_PATH . 'public/helpers/class-post-functions.php';
47 require_once SP_PC_PATH . 'public/helpers/class-pcp-queryinside.php';
48 require_once SP_PC_PATH . 'public/template/loop/class-loop-html.php';
49 }
50
51 /**
52 * Public Action
53 *
54 * @return void
55 */
56 private function pcp_public_action() {
57 add_shortcode( 'smart_post_show', array( $this, 'pcp_shortcode_render' ) );
58 add_shortcode( 'sp_postcarousel', array( $this, 'pcp_shortcode_render' ) );
59 add_shortcode( 'post-carousel', array( $this, 'pcp_shortcode_render' ) );
60
61 $this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? '' : '.min';
62 }
63
64 /**
65 * Register the stylesheets for the public-facing side of the site.
66 *
67 * @since 2.2.0
68 */
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' );
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 $view_options = get_post_meta( $pcp_id, 'sp_pcp_view_options', true );
91 $layouts = get_post_meta( $pcp_id, 'sp_pcp_layouts', true );
92 // Include dynamic style file.
93 include 'dynamic-css/dynamic-css.php';
94 }
95 if ( ! empty( $pcp_custom_css ) ) {
96 $custom_css .= $pcp_custom_css;
97 }
98 // Add dynamic style.
99 wp_add_inline_style( 'pcp-style', $custom_css );
100 }
101
102 /**
103 * Register the JavaScript for the public-facing side of the site.
104 *
105 * @since 2.2.0
106 */
107 public function enqueue_scripts() {
108 wp_register_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
109 wp_register_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
110 }
111
112 /**
113 * Full html show.
114 *
115 * @param array $view_options all options.
116 * @param array $layout show layout.
117 * @param array $pcp_gl_id Shortcode ID.
118 * @param array $section_title Shortcode section title.
119 * @return mixed
120 */
121 public static function pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title ) {
122 $pcp_settings = get_option( 'sp_post_carousel_settings' );
123 $post_content_sorter = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
124 $pcp_content_position = isset( $view_options['post_content_orientation'] ) ? $view_options['post_content_orientation'] : '';
125 $margin_between_post = isset( $view_options['margin_between_post']['all'] ) ? $view_options['margin_between_post']['all'] : '';
126 $show_preloader = isset( $view_options['show_preloader'] ) ? $view_options['show_preloader'] : 0;
127 $query_args = SP_PC_QueryInside::get_filtered_content( $view_options, $layout );
128 $pcp_query = new WP_Query( $query_args );
129 $total_post_count = $pcp_query->post_count;
130 // Pagination.
131 $show_pagination = isset( $view_options['show_post_pagination'] ) ? $view_options['show_post_pagination'] : '';
132 $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
133 wp_enqueue_script( 'pcp_script' );
134 $pcp_custom_js = $pcp_settings['pcp_custom_js'];
135 if ( ! empty( $pcp_custom_js ) ) {
136 wp_add_inline_script( 'pcp_script', $pcp_custom_js );
137 }
138
139 if ( 'carousel_layout' === $layout_preset ) {
140 require SP_PC_TEMPLATE_PATH . '/carousel.php';
141 } elseif ( 'grid_layout' === $layout_preset ) {
142 require SP_PC_TEMPLATE_PATH . '/grid.php';
143 }
144
145 }
146 /**
147 * Function get layout from atts and create class depending on it.
148 *
149 * @since 2.0
150 * @param array $attribute attribute of this shortcode.
151 */
152 public function pcp_shortcode_render( $attribute ) {
153 if ( empty( $attribute['id'] ) ) {
154 return;
155 }
156 $pcp_gl_id = $attribute['id']; // Smart Post Show global ID for Shortcode metaboxes.
157
158 // Preset Layouts.
159 $layout = get_post_meta( $pcp_gl_id, 'sp_pcp_layouts', true );
160
161 // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
162 $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
163 $section_title = get_the_title( $pcp_gl_id );
164 ob_start();
165 SP_PC_Output::pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title );
166 return ob_get_clean();
167 }
168 }
169