PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.0
ShopBuilder – WooCommerce Builder For Elementor v1.0.0
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.0.0, at app/Controllers/Admin/Ajax/ModalTemplate.php

202 lines 7.2 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 * Template Create Modal.
15 */
16 class ModalTemplate {
17 /**
18 * Singleton Trait.
19 */
20 use SingletonTrait;
21 /**
22 * Construct function
23 */
24 private function __construct() {
25 add_action( 'wp_ajax_rtsb_builder_modal_template', [ $this, 'response' ] );
26 }
27
28 /**
29 * Popups For Create Template
30 *
31 * @return void
32 */
33 public function response() {
34 $title = '<h2>' . esc_html__( 'Template Settings', 'shopbuilder' ) . '</h2>';
35 if ( ! Fns::verify_nonce() ) {
36 $return = [
37 'success' => false,
38 'title' => $title,
39 'content' => esc_html__( 'Session Expired...', 'shopbuilder' ),
40 ];
41 wp_send_json( $return );
42 }
43 $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : null;
44
45 $template_type = null;
46 $template_default = null;
47 $url = null;
48 $tmp_title = '';
49 $edit_by = did_action( 'elementor/loaded' ) ? 'elementor' : 'elementor';
50 if ( $post_id ) {
51 $tmp_title = get_the_title( $post_id );
52 $type = get_post_meta( $post_id, BuilderFns::template_type_meta_key() );
53 $template_type = isset( $type[0] ) ? $type[0] : '';
54 $template_default = absint( BuilderFns::builder_page_id_by_type( $template_type ) );
55 $edit_by = Fns::page_edit_with( $post_id );
56 $action = 'edit';
57
58 // TODO:: This Condition Will remove after relase Gutenberg Addons.
59 if ( 'gutenberg' == $edit_by ) {
60 $action = 'elementor';
61 $edit_by = 'elementor';
62 }
63
64 if ( 'elementor' == $edit_by ) {
65 $action = 'elementor';
66 }
67
68 $url = add_query_arg(
69 [
70 'post' => $post_id,
71 'action' => $action,
72 ],
73 admin_url( 'post.php' )
74 );
75 }
76 ob_start();
77
78 ?>
79 <form action="<?php echo esc_url( admin_url( 'edit.php?post_type=rtsb_builder' ) ); ?>" autocomplete="off">
80 <div class="rtsb-tb-modal-wrapper ">
81 <div class="rtsb-template-name rtsb-tb-field-wraper">
82 <label for="rtsb_tb_template_name"> <?php esc_html_e( 'Template Name', 'shopbuilder' ); ?></label>
83 <input
84 required
85 class="rtsb-field"
86 type="text"
87 id="rtsb_tb_template_name"
88 name="rtsb_tb_template_name"
89 placeholder="<?php esc_attr_e( 'Enter Template Name', 'shopbuilder' ); ?>"
90 value="<?php echo esc_attr( $tmp_title ); ?>"
91 autocomplete="off"
92 >
93 <span class="message"
94 style="display: none; color:red"><?php esc_html_e( 'This field is required', 'shopbuilder' ); ?></span>
95 </div>
96 <div class="rtsb-template-type rtsb-tb-field-wraper">
97 <label for="rtsb_tb_template_type"><?php esc_html_e( 'Select Template Type', 'shopbuilder' ); ?></label>
98 <select class="rtsb-field" id="rtsb_tb_template_type" name="rtsb_tb_template_type">
99 <?php
100 $builder_page_types = BuilderFns::builder_page_types();
101 foreach ( $builder_page_types as $key => $value ) {
102 ?>
103 <option <?php echo $key === $template_type ? 'selected="selected"' : ''; ?>
104 value="<?php echo esc_attr( $key ); ?>"> <?php echo esc_html( $value ); ?> </option>
105 <?php } ?>
106 </select>
107 </div>
108 <div class="rtsb-template-edit-with rtsb-tb-field-wraper">
109 <label for="rtsb_tb_template_edit_with"><?php esc_html_e( 'Select Editor Type', 'shopbuilder' ); ?></label>
110 <select class="rtsb-field" id="rtsb_tb_template_edit_with" name="rtsb_tb_template_edit_with"
111 required>
112 <option value="elementor" <?php echo 'elementor' === $edit_by ? 'selected="selected"' : ''; ?> ><?php esc_html_e( 'Elementor', 'shopbuilder' ); ?></option>
113 <option disabled
114 value="gutenberg" <?php // echo 'gutenberg' === $edit_by ? 'selected="selected"' : ''; ?> ><?php esc_html_e( 'Gutenberg (Coming Soon)', 'shopbuilder' ); ?></option>
115 </select>
116 </div>
117 <?php if ( ! $post_id ) { ?>
118 <div class="set-default-layout-wrapper rtsb-tb-field-wraper">
119 <label><?php esc_html_e( 'Sample Designs', 'shopbuilder' ); ?></label>
120 <div class="set-default-layout">
121 <?php
122 foreach ( BuilderFns::default_layout() as $key => $layouts ) {
123 foreach ( $layouts as $value ) {
124 $is_checked = '';
125 if ( 'default' == $key && empty( $value['import_file'] ) && ! $is_checked ) {
126 $is_checked = 'checked';
127 }
128 ?>
129 <label class="layout-container type-<?php echo esc_attr( $key ); ?>"
130 data-layout-type='<?php echo esc_attr( $key ); ?>'>
131 <input
132 <?php echo esc_attr( $is_checked ); ?>
133 class="rtsb-field"
134 type="radio"
135 value="<?php echo ! empty( $value['import_file'] ) ? esc_attr( $value['import_file'] ) : ''; ?>"
136 name="import_default_layout">
137 <span class="checkmark dashicons"></span>
138 <div class="image-wrapper">
139 <?php if ( ! empty( $value['image'] ) ) { ?>
140 <img src="<?php echo esc_url( $value['image'] ); ?>" alt="">
141 <?php } ?>
142 </div>
143 <?php if ( ! empty( $value['text_label'] ) ) { ?>
144 <div class="image-label">
145 <span class="label-text"><?php echo esc_html( $value['text_label'] ); ?></span>
146 <?php if ( ! empty( $value['live_preview'] ) ) { ?>
147 <a target="_blank" class="btn-live-preview"
148 href="<?php echo esc_url( $value['live_preview'] ); ?>"> <span
149 class="dashicons dashicons-visibility"></span> <?php esc_html_e( 'Live Preview', 'shopbuilder' ); ?>
150 </a>
151 <?php } ?>
152 </div>
153 <?php } ?>
154
155 </label>
156 <?php
157 }
158 }
159 ?>
160 </div>
161 </div>
162 <?php } ?>
163 <input type="hidden" id="page_id" name="page_id" value="<?php echo esc_attr( $post_id ); ?>">
164 <div class="rtsb-template-setdefaults">
165 <input
166 type="checkbox"
167 id="default_template"
168 class="rtsb-field"
169 name="default_template"
170 value="default_template"
171 <?php echo ( $post_id && absint( $post_id ) === absint( $template_default ) ) ? 'checked' : ''; ?>
172 >
173 <label for="default_template"> <?php esc_html_e( 'Set as Active Template', 'shopbuilder' ); ?></label><br>
174 </div>
175 <div class="rtsb-template-footer">
176 <div class="rtsb-tb-button-wrapper save-button">
177 <button <?php echo $post_id ? esc_attr( 'disabled' ) : ''; ?>
178 type="submit"
179 id="rtsb_tb_button">
180 <?php esc_html_e( 'Save', 'shopbuilder' ); ?>
181 </button>
182 </div>
183 <div class="rtsb-tb-button-wrapper rtsb-tb-edit-button-wrapper">
184 <a href="<?php echo esc_url( $url ); ?>"
185 class="btn"> <?php esc_html_e( sprintf( 'Edit with %s', $edit_by ), 'shopbuilder' ); ?> </a>
186 </div>
187 </div>
188 </div>
189 </form>
190 <?php
191 $content = ob_get_clean();
192 $return = [
193 'success' => true,
194 'title' => $title,
195 'content' => $content,
196 ];
197 wp_send_json( $return );
198 wp_die();
199 }
200
201 }
202