PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.4
ShopBuilder – WooCommerce Builder For Elementor v1.1.4
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 / BuilderController.php

BuilderController.php in ShopBuilder – WooCommerce Builder For Elementor 1.1.4, at app/Controllers/BuilderController.php

298 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main BuilderController class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers;
9
10 use Elementor\Plugin;
11 use RadiusTheme\SB\Helpers\Fns;
12 use RadiusTheme\SB\Helpers\BuilderFns;
13 use RadiusTheme\SB\Traits\SingletonTrait;
14 use RadiusTheme\SB\Controllers\Builder\BuilderCpt;
15 use RadiusTheme\SB\Controllers\Hooks\BuilderHooks;
16 use RadiusTheme\SB\Elementor\Controls\ImageSelectorControl;
17 use RadiusTheme\SB\Models\ElementList;
18
19 // Do not allow directly accessing this file.
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit( 'This script cannot be accessed directly.' );
22 }
23
24 /**
25 * Builder Controller
26 */
27 class BuilderController {
28 /**
29 * Builder page id.
30 *
31 * @var integer
32 */
33 private $builder_page_id = 0;
34
35 /**
36 * Page Edit By.
37 *
38 * @var string
39 */
40 private $page_edit_with = '';
41
42 /**
43 * Singleton Trait
44 */
45 use SingletonTrait;
46
47 /**
48 * Construct function
49 */
50 private function __construct() {
51 $this->builder_page_id = BuilderFns::builder_page_id_by_page();
52 $this->page_edit_with = Fns::page_edit_with( $this->builder_page_id );
53
54 if ( ! is_admin() ) {
55 BuilderHooks::instance();
56 }
57
58 BuilderCpt::instance();
59
60 add_action( 'elementor/init', [ $this, 'elementor_init' ] );
61 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] );
62 add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 );
63 }
64
65 /**
66 * Apply for frontend.
67 *
68 * @return void
69 */
70 public function both_builder_frontend() {
71 add_action( 'rtsb/builder/template/before/content', [ $this, 'builder_template_before_content' ] );
72 add_action( 'rtsb/builder/template/after/content', [ $this, 'builder_template_after_content' ] );
73 }
74
75 /**
76 * Register Category
77 *
78 * @return void
79 */
80 public function elementor_init() {
81 add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_widget_categories' ] );
82 add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
83 add_action( 'elementor/controls/register', [ $this, 'init_controls' ] );
84 }
85
86 /**
87 * Register Category
88 *
89 * @param object $elements_manager Category hooks.
90 *
91 * @return void
92 */
93 public function add_elementor_widget_categories( $elements_manager ) {
94 $type = BuilderFns::builder_type( get_the_ID() );
95 $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : null;
96 $categories['rtsb-shopbuilder'] = [
97 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ),
98 'icon' => 'fa fa-plug',
99 ];
100 $categories['rtsb-shopbuilder-general'] = [
101 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
102 'icon' => 'fa fa-plug',
103 ];
104
105 $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories );
106 $other_categories = $elements_manager->get_categories();
107 $categories = array_merge(
108 array_slice( $other_categories, 0, 1 ),
109 $categories,
110 array_slice( $other_categories, 1 )
111 );
112
113 $set_categories = function ( $categories ) {
114 $this->categories = $categories;
115 };
116
117 $set_categories->call( $elements_manager, $categories );
118 }
119
120 /**
121 * Init Controls
122 *
123 * Include controls files and register them
124 *
125 * @param object $controls_manager Controls Manager.
126 *
127 * @since 1.0.0
128 */
129 public function init_controls( $controls_manager ) {
130 $controls_manager->register( new ImageSelectorControl() );
131 }
132
133 /**
134 * Init Widgets
135 *
136 * Include widgets files and register them
137 *
138 * @since 1.0.0
139 */
140 public function init_widgets( $widgets_manager ) {
141 foreach ( ElementList::instance()->get_list( true, 'active' ) as $element ) {
142 if ( isset( $element['active'] ) && $element['active'] !== 'on' ) {
143 continue;
144 }
145
146 if ( ! empty( $element['package'] ) && $element['package'] === 'pro-disabled' ) {
147 continue;
148 }
149
150 if ( isset( $element['base_class'] ) && ! class_exists( $element['base_class'] ) ) {
151 continue;
152 }
153
154 if ( ! empty( $element['category'] ) ) {
155 $widget = false;
156 switch ( $element['category'] ) {
157 case 'product':
158 if ( BuilderFns::is_product() ) {
159 $widget = new $element['base_class']();
160 }
161 break;
162 case 'shop':
163 if ( BuilderFns::is_archive() || BuilderFns::is_shop() ) {
164 $widget = new $element['base_class']();
165 }
166 break;
167 case 'archive':
168 if ( BuilderFns::is_archive() ) {
169 $widget = new $element['base_class']();
170 }
171 break;
172 case 'cart':
173 if ( BuilderFns::is_cart() ) {
174 $widget = new $element['base_class']();
175 }
176 break;
177 case 'checkout':
178 if ( BuilderFns::is_checkout() ) {
179 $widget = new $element['base_class']();
180 }
181 break;
182 case 'general':
183 $widget = new $element['base_class']();
184 break;
185 default:
186 }
187 $widget = apply_filters( 'rtsb/element/list/init/widgets', $widget, $element );
188
189 if ( $widget && is_object( $widget ) ) {
190 $widgets_manager->register( $widget );
191 }
192 }
193 }
194 }
195
196 /**
197 * Editor JS.
198 *
199 * @return void
200 */
201 public function editor_scripts() {
202 $version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION;
203
204 wp_enqueue_script(
205 'rtsb-editor-script',
206 rtsb()->get_assets_uri( 'js/backend/editor.js' ),
207 [
208 'jquery',
209 'elementor-editor',
210 ],
211 $version,
212 true
213 );
214 $params = [
215 'isEditorForBuilder' => false,
216 ];
217 if ( BuilderFns::is_builder_preview() ) {
218 $params['isEditorForBuilder'] = true;
219 }
220 wp_localize_script( 'rtsb-editor-script', 'rtsbTemplateBuilderEditorScript', $params );
221 wp_enqueue_style( 'rtsb-el-editor-style', rtsb()->get_assets_uri( 'css/backend/elementor-editor.css' ), [], $version );
222 }
223
224 /**
225 * Before Content for Elementor.
226 *
227 * @return void
228 */
229 public function builder_template_before_content() {
230 /**
231 * Before Header-Footer page template content.
232 *
233 * Fires before the content of Elementor Header-Footer page template.
234 *
235 * @since 2.0.0
236 */
237 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
238 do_action( 'elementor/page_templates/header-footer/before_content' );
239 }
240
241 $parent_class = apply_filters( 'rtsb/builder/content/parent_class', [] );
242
243 if ( BuilderFns::is_product() ) {
244 $product_id = Fns::get_prepared_product_id();
245 $parent_class = wc_get_product_class( $parent_class, $product_id );
246 }
247
248 if ( BuilderFns::is_shop() ) {
249 $parent_class[] = 'shop';
250 }
251
252 if ( BuilderFns::is_archive() ) {
253 $parent_class[] = 'archive';
254 }
255
256 if ( BuilderFns::is_checkout() ) {
257 $parent_class[] = 'checkout-page ';
258 }
259
260 ?>
261 <!-- Before Content start -->
262 <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>">
263 <?php if ( BuilderFns::is_checkout() ) { ?>
264 <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
265 <?php
266 }
267
268 }
269
270 /**
271 * After Content for Elementor.
272 *
273 * @return void
274 */
275 public function builder_template_after_content() {
276 /**
277 * After Header-Footer page template content.
278 *
279 * Fires after the content of Elementor Header-Footer page template.
280 *
281 * @since 2.0.0
282 */
283 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
284 do_action( 'elementor/page_templates/header-footer/after_content' );
285 }
286
287 if ( BuilderFns::is_checkout() ) {
288 ?>
289 </form>
290 <?php
291 }
292 ?>
293 </div>
294 <!-- After Content end -->
295 <?php
296 }
297 }
298