PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.2
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 / admin / ElementAddons / Smart_Post_Show_Template_Widget.php

Smart_Post_Show_Template_Widget.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.2, at admin/ElementAddons/Smart_Post_Show_Template_Widget.php

205 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Template widget file.
4 *
5 * @package Smart_Post_Show_Pro
6 * @subpackage Smart_Post_Show_Pro/admin/ElementAddons
7 */
8
9 use SmartPostShow\Blocks\Helper;
10
11 /**
12 * Elementor smart post show pro Template Widget.
13 *
14 * @since 2.4.1
15 */
16 class Smart_Post_Show_Template_Widget extends \Elementor\Widget_Base {
17 /**
18 * Get widget name.
19 *
20 * @since 2.4.1
21 * @access public
22 *
23 * @return string Widget name.
24 */
25 public function get_name() {
26 return 'smart_post_show_pro_template';
27 }
28
29 /**
30 * Get widget title.
31 *
32 * @since 2.4.1
33 * @access public
34 *
35 * @return string Widget title.
36 */
37 public function get_title() {
38 return __( 'Saved Templates', 'post-carousel' );
39 }
40
41 /**
42 * Get widget icon.
43 *
44 * @since 2.2.5
45 * @access public
46 *
47 * @return string Widget icon.
48 */
49 public function get_icon() {
50 return 'sps-icon-elementor';
51 }
52
53 /**
54 * Get widget categories.
55 *
56 * @since 2.2.5
57 * @access public
58 *
59 * @return array Widget categories.
60 */
61 public function get_categories() {
62 return array( 'basic' );
63 }
64
65 /**
66 * Enqueue scripts for editor preview.
67 *
68 * @return array Script handles.
69 */
70 public function get_script_depends() {
71 return array( 'sp_smart_post_blocks_script_js' );
72 }
73
74 /**
75 * Enqueue styles for editor preview.
76 *
77 * @return array Style handles.
78 */
79 public function get_style_depends() {
80 return array(
81 'sp_smart_post_blocks_css',
82 'sp_smart_post_blocks_social_icons_style',
83 'sp_smart_post_blocks_google_fonts',
84 );
85 }
86
87 /**
88 * Controls register.
89 *
90 * @return void
91 */
92 protected function register_controls() {
93 $this->start_controls_section(
94 'content_section',
95 array(
96 'label' => __( 'Content', 'post-carousel' ),
97 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
98 )
99 );
100
101 $this->add_control(
102 'sp_smart_post_show_pro_template',
103 array(
104 'label' => __( 'Smart Post Templates', 'post-carousel' ),
105 'type' => \Elementor\Controls_Manager::SELECT2,
106 'label_block' => true,
107 'default' => '0',
108 'options' => Helper::get_save_template_list(),
109 )
110 );
111
112 $this->end_controls_section();
113 }
114
115 /**
116 * Render the template content by querying the sp_post_template post
117 * and applying the_content filter so Gutenberg blocks render properly.
118 *
119 * @since 2.4.1
120 * @param int $template_id Template post ID.
121 * @return void
122 */
123 protected function render_template_content( $template_id ) {
124 $args = array(
125 'p' => $template_id,
126 'post_type' => 'sp_post_template',
127 'post_status' => 'publish',
128 'posts_per_page' => 1,
129 );
130 $the_query = new \WP_Query( $args );
131
132 $dynamic_css = get_post_meta( $template_id, '_sp_smart_css', true ); // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_post_meta_param2
133
134 if ( $the_query->have_posts() ) {
135 echo '<style>' . $dynamic_css . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
136 echo '<div class="sp-smart-post-wrapper" data-postid="' . esc_attr( $template_id ) . '">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
137 while ( $the_query->have_posts() ) {
138 $the_query->the_post();
139 echo apply_filters( 'the_content', get_the_content() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
140 }
141 echo '</div>';
142 wp_reset_postdata();
143 } else {
144 echo '<div style="text-align: center; padding: 10px;">'
145 . esc_html__( 'Template not found.', 'post-carousel' )
146 . '</div>';
147 }
148 }
149
150 /**
151 * Render smart post show pro shortcode widget output on the frontend.
152 *
153 * @since 2.4.1
154 * @access protected
155 */
156 protected function render() {
157
158 $settings = $this->get_settings_for_display();
159 $sp_pcp_template = $settings['sp_smart_post_show_pro_template'] ?? '';
160 $template_id = (int) $sp_pcp_template;
161
162 if ( empty( $template_id ) ) {
163 echo '<div style="
164 text-align: center;
165 padding: 20px;
166 border: 2px dashed #ccc;
167 color: #999;
168 font-size: 14px;
169 ">
170 Please select a Smart Post Saved Templates
171 </div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
172 return;
173 }
174
175 if ( $template_id ) {
176
177 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
178
179 $upload_dir = wp_upload_dir();
180 $css_file = $upload_dir['basedir'] . '/smart-post-show/static/sp-post-' . $template_id . '.css';
181 $css_url = $upload_dir['baseurl'] . '/smart-post-show/static/sp-post-' . $template_id . '.css';
182
183 if ( file_exists( $css_file ) ) {
184 echo '<link rel="stylesheet" href="' . esc_url( $css_url ) . '?v=' . filemtime( $css_file ) . '">'; // phpcs:ignore
185 }
186
187 $dynamic_css = get_post_meta( $template_id, '_sp_smart_css', true ); // phpcs:ignore WordPress.WP.DeprecatedParameters.Get_post_meta_param2
188
189 echo '<style>' . $dynamic_css . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
190
191 echo do_shortcode( '[smart_post id="' . $template_id . '"]' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
192
193 ?>
194
195 <?php
196
197 } else {
198 echo '<div class="sp-smart-post-builder-wrap" data-builderTemplateId="' . esc_attr( $template_id ) . '">';
199 echo do_shortcode( '[smart_post id="' . $template_id . '"]' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
200 echo '</div>';
201 }
202 }
203 }
204 }
205