PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.2
ShopBuilder – WooCommerce Builder For Elementor v1.1.2
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Admin / Ajax / ModalTemplate.php

ModalTemplate.php in ShopBuilder – WooCommerce Builder For Elementor 1.1.2, at app/Controllers/Admin/Ajax/ModalTemplate.php

286 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4
5 use RadiusTheme\SB\Helpers\BuilderFns;
6 use RadiusTheme\SB\Helpers\Fns;
7 use RadiusTheme\SB\Traits\SingletonTrait;
8
9 // Do not allow directly accessing this file.
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit( 'This script cannot be accessed directly.' );
12 }
13
14 /**
15 * Template Create Modal.
16 */
17 class ModalTemplate {
18 /**
19 * Singleton Trait.
20 */
21 use SingletonTrait;
22
23 /**
24 * Construct function
25 */
26 private function __construct() {
27 add_action( 'wp_ajax_rtsb_builder_modal_template', [ $this, 'response' ] );
28 add_action( 'wp_ajax_rtsb_modal_product_search', [ $this, 'product_search' ] );
29 }
30
31 /**
32 * Popups For Create Template
33 *
34 * @return void
35 */
36 public function response() {
37 $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>';
38 if ( ! Fns::verify_nonce() ) {
39 $return = [
40 'success' => false,
41 'title' => $title,
42 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
43 ];
44 wp_send_json( $return );
45 }
46 $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
47
48 $template_type = null;
49 $template_default = null;
50 $url = null;
51 $tmp_title = '';
52 $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor';
53 if ( $post_id ) {
54 $tmp_title = get_the_title( $post_id );
55 $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() );
56 $template_type = isset( $type[0] ) ? $type[0] : '';
57 $template_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) );
58 $edit_by = Fns::page_edit_with( $post_id );
59 $action = 'edit';
60
61 // TODO:: This Condition Will remove after relase Gutenberg Addons.
62 if ( 'gutenberg' == $edit_by ) {
63 $action = 'elementor';
64 $edit_by = 'elementor';
65 }
66
67 if ( 'elementor' == $edit_by ) {
68 $action = 'elementor';
69 }
70
71 $url = add_query_arg(
72 [
73 'post' => $post_id,
74 'action' => $action,
75 ],
76 admin_url( 'post.php' )
77 );
78 }
79 ob_start();
80
81 ?>
82 <form action="<?php echo esc_url( admin_url( 'edit.php?post_type=rtsb_builder' ) ); ?>" autocomplete="off">
83 <div class="rtsb-tb-modal-wrapper ">
84 <div class="rtsb-template-name rtsb-tb-field-wraper">
85 <label for="rtsb_tb_template_name"> <?php esc_html_e( 'Template Name', 'shopbuilder' ); ?></label>
86 <input
87 required
88 class="rtsb-field"
89 type="text"
90 id="rtsb_tb_template_name"
91 name="rtsb_tb_template_name"
92 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
93 value="<?php echo esc_attr( $tmp_title ); ?>"
94 autocomplete="off"
95 >
96 <span class="message"
97 style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
98 </div>
99 <div class="rtsb-template-type rtsb-tb-field-wraper">
100 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
101 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
102 <?php
103 $builder_page_types = BuilderFns::builder_page_types();
104 foreach ( $builder_page_types as $key => $value ) {
105 ?>
106 <option <?php echo $key === $template_type ? 'selected="selected"' : ''; ?> value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option>
107 <?php } ?>
108 </select>
109 </div>
110
111 <div class="rtsb-product-page-preview rtsb-tb-field-wraper" style="display:none;">
112 <?php
113 $default_items = '';
114 $product_id = get_post_meta( $post_id, BuilderFns::$product_template_meta, true );
115 if ( $product_id ) {
116 $default_items = '<option selected="selected" value="' . $product_id . '">' . get_the_title( $product_id ) . '</option>';
117 }
118 ?>
119 <label for="rtsb_product_page_preview"><?php esc_html_e( 'Select Product For Preview', 'shopbuilder' ); ?></label>
120 <select class="rtsb-field" id="rtsb_product_page_preview" name="rtsb_product_page_preview">
121 <?php echo $default_items; ?>
122 </select>
123 <p style="margin:0;"> This Product is only used for preview. </p>
124 </div>
125
126 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
127 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
128 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
129 required>
130 <option value="elementor" <?php echo 'elementor' === $edit_by ? 'selected="selected"' : ''; ?> ><?php esc_html_e( 'Elementor', 'shopbuilder' ); ?></option>
131 <option disabled
132 value="gutenberg" <?php // echo 'gutenberg' === $edit_by ? 'selected="selected"' : ''; ?> ><?php esc_html_e( 'Gutenberg (Coming Soon)', 'shopbuilder' ); ?></option>
133 </select>
134 </div>
135 <div class="rtsb-template-setdefaults rtsb-tb-field-wraper">
136 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label>
137 <span class="rtsb-switch-wrapper"
138 title="<?php esc_html_e( 'Only publish post can set default ', 'shopbuilder' ); ?>">
139 <label class="rtsb-switch">
140 <input class="rtsb_set_default rtsb-field"
141 type="checkbox"
142 id="default_template"
143 class="rtsb-field"
144 name="default_template"
145 value="default_template"
146 <?php echo ( $post_id && absint( $post_id ) === absint( $template_default ) ) ? 'checked' : ''; ?>
147 >
148 <span class="rtsb-slider rtsb-round ">
149 <span class="rtsb-loader"></span>
150 </span>
151 </label>
152 </span>
153 </div>
154 <?php if ( ! $post_id ) { ?>
155 <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
156 <label><?php esc_html_e( 'Sample Designs', 'shopbuilder' ); ?></label>
157 <div class="set-default-layout">
158 <?php
159 foreach ( BuilderFns::default_layout() as $key => $layouts ) {
160 foreach ( $layouts as $value ) {
161 $is_checked = '';
162 if ( 'default' == $key && empty( $value['import_file'] ) && ! $is_checked ) {
163 $is_checked = 'checked';
164 }
165 ?>
166 <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
167 data-layout-type='<?php echo esc_attr( $key ); ?>'>
168 <input
169 <?php echo esc_attr( $is_checked ); ?>
170 class="rtsb-field"
171 type="radio"
172 value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
173 name="import_default_layout">
174 <span class="checkmark dashicons"></span>
175 <div class="image-wrapper">
176 <?php if ( ! empty( $value['image'] ) ) { ?>
177 <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
178 <?php } ?>
179 </div>
180 <?php if ( ! empty( $value['text_label'] ) ) { ?>
181 <div class="image-label">
182 <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
183 <?php if ( ! empty( $value['live_preview'] ) ) { ?>
184 <a target="_blank" class="btn-live-preview"
185 href="<?php echo esc_url( $value['live_preview'] ); ?>"> <span
186 class="dashicons dashicons-visibility"></span> <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
187 </a>
188 <?php } ?>
189 </div>
190 <?php } ?>
191
192 </label>
193 <?php
194 }
195 }
196 ?>
197 </div>
198 </div>
199 <?php } ?>
200 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
201 </div>
202 </form>
203 <?php
204 $content = ob_get_clean();
205 ob_start();
206 ?>
207 <div class="rtsb-template-footer">
208 <div class="rtsb-tb-button-wrapper save-button">
209 <button <?php echo $post_id ? esc_attr( 'disabled' ) : ''; ?>
210 type="submit"
211 id="rtsb_tb_button">
212 <?php esc_html_e( 'Save', 'shopbuilder' ); ?>
213 </button>
214 </div>
215 <div class="rtsb-tb-button-wrapper rtsb-tb-edit-button-wrapper">
216 <a href="<?php echo esc_url( $url ); ?>"
217 class="btn"> <?php esc_html_e( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); ?> </a>
218 </div>
219 </div>
220 <?php
221 $footer = ob_get_clean();
222 $return = [
223 'success' => true,
224 'title' => $title,
225 'content' => $content,
226 'footer' => $footer,
227 ];
228 wp_send_json( $return );
229 wp_die();
230 }
231
232 /**
233 * Popups For Create Template
234 *
235 * @return void
236 */
237 public function product_search() {
238 if ( ! Fns::verify_nonce() ) {
239 $return = [
240 'success' => false,
241 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
242 ];
243 wp_send_json( $return );
244 }
245 global $wpdb;
246 $search = isset( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
247 if ( empty( $search ) ) {
248 $return = [
249 'success' => false,
250 'content' => esc_html__( 'Empty string Not allowed...', 'shopbuilder' ),
251 ];
252 wp_send_json( $return );
253 }
254 $query = $wpdb->prepare(
255 "SELECT ID, post_title
256 FROM $wpdb->posts
257 WHERE post_type = 'product'
258 AND post_status = 'publish'
259 AND post_title LIKE %s
260 LIMIT %d",
261 '%' . $search . '%',
262 10
263 );
264
265 $_product = wp_cache_get( md5( $query ), 'rtsb-product-query' );
266 if ( false === $_product ) {
267 $_product = $wpdb->get_results( $query );
268 wp_cache_set( md5( $query ), $_product, 'rtsb-product-query' );
269 }
270
271 $product_list = [];
272 foreach ( $_product as $product ) {
273 $product_list['items'][] = [
274 'id' => $product->ID,
275 'text' => $product->post_title,
276 ];
277 }
278
279 wp_send_json_success( $product_list );
280 wp_die();
281
282 }
283
284
285 }
286