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

165 lines 5.5 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 class Smart_Post_Show_Public {
16
17 /**
18 * Script and style suffix
19 *
20 * @since 2.2.0
21 * @access protected
22 * @var string
23 */
24 protected $suffix;
25
26 /**
27 * Initialize the class and set its properties.
28 *
29 * @since 2.2.0
30 */
31 public function __construct() {
32 $this->load_public_dependencies();
33 $this->pcp_public_action();
34 }
35
36 /**
37 * Public dependencies.
38 *
39 * @return void
40 */
41 private function load_public_dependencies() {
42 require_once SP_PC_PATH . 'public/helpers/class-post-functions.php';
43 require_once SP_PC_PATH . 'public/helpers/class-pcp-queryinside.php';
44 require_once SP_PC_PATH . 'public/template/loop/class-loop-html.php';
45 }
46
47 /**
48 * Public Action
49 *
50 * @return void
51 */
52 private function pcp_public_action() {
53 add_shortcode( 'smart_post_show', array( $this, 'pcp_shortcode_render' ) );
54 add_shortcode( 'sp_postcarousel', array( $this, 'pcp_shortcode_render' ) );
55 add_shortcode( 'post-carousel', array( $this, 'pcp_shortcode_render' ) );
56
57 $this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? '' : '.min';
58 }
59
60 /**
61 * Register the stylesheets for the public-facing side of the site.
62 *
63 * @since 2.2.0
64 */
65 public function enqueue_styles() {
66
67 $pcp_settings = get_option( 'sp_post_carousel_settings' );
68 if ( $pcp_settings['pcp_fontawesome_css'] ) {
69 wp_enqueue_style( 'font-awesome', SP_PC_URL . 'public/assets/css/font-awesome.min.css', array(), SP_PC_VERSION, 'all' );
70 }
71 if ( $pcp_settings['pcp_swiper_css'] ) {
72 wp_enqueue_style( 'pcp_swiper', SP_PC_URL . 'public/assets/css/swiper-bundle' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
73 }
74 wp_enqueue_style( 'pcp-style', SP_PC_URL . 'public/assets/css/style' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
75
76 $pcp_posts = new WP_Query(
77 array(
78 'post_type' => 'sp_post_carousel',
79 'posts_per_page' => 900,
80 )
81 );
82 $post_ids = wp_list_pluck( $pcp_posts->posts, 'ID' );
83 $custom_css = '';
84 $pcp_custom_css = $pcp_settings['pcp_custom_css'];
85 foreach ( $post_ids as $pcp_id ) {
86 $view_options = get_post_meta( $pcp_id, 'sp_pcp_view_options', true );
87 $layouts = get_post_meta( $pcp_id, 'sp_pcp_layouts', true );
88 // Include dynamic style file.
89 include 'dynamic-css/dynamic-css.php';
90 }
91 if ( ! empty( $pcp_custom_css ) ) {
92 $custom_css .= $pcp_custom_css;
93 }
94 // Add dynamic style.
95 wp_add_inline_style( 'pcp-style', $custom_css );
96 }
97
98 /**
99 * Register the JavaScript for the public-facing side of the site.
100 *
101 * @since 2.2.0
102 */
103 public function enqueue_scripts() {
104 wp_register_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
105 wp_register_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
106 }
107
108 /**
109 * Full html show.
110 *
111 * @param array $view_options all options.
112 * @param array $layout show layout.
113 * @param array $pcp_gl_id Shortcode ID.
114 * @param array $section_title Shortcode section title.
115 * @return mixed
116 */
117 public static function pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title ) {
118 $pcp_settings = get_option( 'sp_post_carousel_settings' );
119 $post_content_sorter = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
120 $pcp_content_position = isset( $view_options['post_content_orientation'] ) ? $view_options['post_content_orientation'] : '';
121 $margin_between_post = isset( $view_options['margin_between_post']['all'] ) ? $view_options['margin_between_post']['all'] : '';
122 $show_preloader = isset( $view_options['show_preloader'] ) ? $view_options['show_preloader'] : 0;
123 $query_args = SP_PC_QueryInside::get_filtered_content( $view_options, $pcp_gl_id, $layout );
124 $pcp_query = new WP_Query( $query_args );
125 $total_post_count = $pcp_query->post_count;
126 // Pagination.
127 $show_pagination = isset( $view_options['show_post_pagination'] ) ? $view_options['show_post_pagination'] : '';
128 $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
129 wp_enqueue_script( 'pcp_script' );
130 $pcp_custom_js = $pcp_settings['pcp_custom_js'];
131 if ( ! empty( $pcp_custom_js ) ) {
132 wp_add_inline_script( 'pcp_script', $pcp_custom_js );
133 }
134
135 if ( 'carousel_layout' === $layout_preset ) {
136 require SP_PC_TEMPLATE_PATH . '/carousel.php';
137 } elseif ( 'grid_layout' === $layout_preset ) {
138 require SP_PC_TEMPLATE_PATH . '/grid.php';
139 }
140
141 }
142 /**
143 * Function get layout from atts and create class depending on it.
144 *
145 * @since 2.0
146 * @param array $attribute attribute of this shortcode.
147 */
148 public function pcp_shortcode_render( $attribute ) {
149 if ( empty( $attribute['id'] ) ) {
150 return;
151 }
152 $pcp_gl_id = $attribute['id']; // Smart Post Show global ID for Shortcode metaboxes.
153
154 // Preset Layouts.
155 $layout = get_post_meta( $pcp_gl_id, 'sp_pcp_layouts', true );
156
157 // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
158 $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
159 $section_title = get_the_title( $pcp_gl_id );
160 ob_start();
161 SP_PC_Output::pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title );
162 return ob_get_clean();
163 }
164 }
165