PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.1
ShopBuilder – WooCommerce Builder For Elementor v1.0.1
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.0.1, at app/Controllers/BuilderController.php

286 lines 7.5 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/controls_registered', [ $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 $builder_type = BuilderFns::builder_type( get_the_ID() );
95 $categories['rtsb-shopbuilder'] = [
96 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . $builder_type,
97 'icon' => 'fa fa-plug',
98 ];
99 $categories['rtsb-shopbuilder-general'] = [
100 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ),
101 'icon' => 'fa fa-plug',
102 ];
103
104 $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories );
105 $other_categories = $elements_manager->get_categories();
106 $categories = array_merge(
107 array_slice( $other_categories, 0, 1 ),
108 $categories,
109 array_slice( $other_categories, 1 )
110 );
111
112 $set_categories = function ( $categories ) {
113 $this->categories = $categories;
114 };
115
116 $set_categories->call( $elements_manager, $categories );
117 }
118
119 /**
120 * Init Controls
121 *
122 * Include controls files and register them
123 *
124 * @since 1.0.0
125 */
126 public function init_controls() {
127 $controls_manager = Plugin::instance()->controls_manager;
128 $controls_manager->register( new ImageSelectorControl() );
129 }
130 /**
131 * Init Widgets
132 *
133 * Include widgets files and register them
134 *
135 * @since 1.0.0
136 */
137 public function init_widgets( $widgets_manager ) {
138 foreach ( ElementList::instance()->get_list( true, 'active' ) as $element ) {
139
140 if ( isset( $element['active'] ) && $element['active'] !== 'on' ) {
141 continue;
142 }
143
144 if ( ! empty( $element['package'] ) && $element['package'] === 'pro-disabled' ) {
145 continue;
146 }
147
148 if ( isset( $element['base_class'] ) && ! class_exists( $element['base_class'] ) ) {
149 continue;
150 }
151
152 if ( ! empty( $element['category'] ) ) {
153 $widget = false;
154 switch ( $element['category'] ) {
155 case 'product':
156 if ( BuilderFns::is_product() ) {
157 $widget = new $element['base_class']();
158 }
159 break;
160 case 'shop':
161 if ( BuilderFns::is_archive() || BuilderFns::is_shop() ) {
162 $widget = new $element['base_class']();
163 }
164 break;
165 case 'archive':
166 if ( BuilderFns::is_archive() ) {
167 $widget = new $element['base_class']();
168 }
169 break;
170 case 'cart':
171 if ( BuilderFns::is_cart() ) {
172 $widget = new $element['base_class']();
173 }
174 break;
175 case 'checkout':
176 if ( BuilderFns::is_checkout() ) {
177 $widget = new $element['base_class']();
178 }
179 break;
180 case 'general':
181 $widget = new $element['base_class']();
182 break;
183 default:
184 $widget = apply_filters( 'rtsb_element_list_init_widgets', $widget, $element );
185 }
186
187 if ( $widget && is_object( $widget ) ) {
188 $widgets_manager->register( $widget );
189 }
190 }
191 }
192 }
193
194 /**
195 * Editor JS.
196 *
197 * @return void
198 */
199 public function editor_scripts() {
200 $version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION;
201
202 wp_enqueue_script( 'rtsb-editor-script', rtsb()->get_assets_uri( 'js/backend/editor.js' ), [ 'jquery', 'elementor-editor' ], $version, true );
203 $params = [
204 'isEditorForBuilder' => false,
205 ];
206 if ( BuilderFns::is_builder_preview() ) {
207 $params['isEditorForBuilder'] = true;
208 }
209 wp_localize_script( 'rtsb-editor-script', 'rtsbTemplateBuilderEditorScript', $params );
210 wp_enqueue_style( 'rtsb-el-editor-style', rtsb()->get_assets_uri( 'css/backend/elementor-editor.css' ), [], $version );
211 }
212
213 /**
214 * Before Content for Elementor.
215 *
216 * @return void
217 */
218 public function builder_template_before_content() {
219 /**
220 * Before Header-Footer page template content.
221 *
222 * Fires before the content of Elementor Header-Footer page template.
223 *
224 * @since 2.0.0
225 */
226 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
227 do_action( 'elementor/page_templates/header-footer/before_content' );
228 }
229
230 $parent_class = apply_filters( 'rtsb_builder_content_parent_class', [] );
231
232 if ( BuilderFns::is_product() ) {
233 $product_id = Fns::get_prepared_product_id();
234 $parent_class = wc_get_product_class( $parent_class, $product_id );
235 }
236
237 if ( BuilderFns::is_shop() ) {
238 $parent_class[] = 'shop';
239 }
240
241 if ( BuilderFns::is_archive() ) {
242 $parent_class[] = 'archive';
243 }
244
245 if ( BuilderFns::is_checkout() ) {
246 $parent_class[] = 'checkout-page woocommerce-checkout';
247 }
248
249 ?>
250 <!-- Before Content start -->
251 <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>">
252 <?php if ( BuilderFns::is_checkout() ) { ?>
253 <form name="checkout" method="post" class="checkout " action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
254 <?php
255 }
256
257 }
258 /**
259 * After Content for Elementor.
260 *
261 * @return void
262 */
263 public function builder_template_after_content() {
264 /**
265 * After Header-Footer page template content.
266 *
267 * Fires after the content of Elementor Header-Footer page template.
268 *
269 * @since 2.0.0
270 */
271 if ( did_action( 'elementor/loaded' ) && 'elementor' === $this->page_edit_with ) {
272 do_action( 'elementor/page_templates/header-footer/after_content' );
273 }
274
275 if ( BuilderFns::is_checkout() ) {
276 ?>
277 </form>
278 <?php
279 }
280 ?>
281 </div>
282 <!-- After Content end -->
283 <?php
284 }
285 }
286