PluginProbe
Depicter — Popup & Slider Builder / 1.3.8
Depicter — Popup & Slider Builder v1.3.8
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Modules / ModulesServiceProvider.php

ModulesServiceProvider.php in Depicter — Popup & Slider Builder 1.3.8, at app/src/Modules/ModulesServiceProvider.php

175 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Modules;
4 ;
5 use Depicter\Modules\Elementor\SliderWidget;
6 use WPEmerge\ServiceProviders\ServiceProviderInterface;
7
8 /**
9 * Register widgets.
10 */
11 class ModulesServiceProvider implements ServiceProviderInterface {
12 /**
13 * {@inheritDoc}
14 */
15 public function register( $container ) {
16 add_action( 'plugins_loaded', [ $this, 'elementorModulesLoaded' ] );
17 $this->modulesLoaded();
18 }
19
20 public function elementorModulesLoaded() {
21 if( defined( 'ELEMENTOR_VERSION' ) ){
22 New Elementor\Module();
23 }
24 }
25
26 public function modulesLoaded(){
27
28 add_action( 'init', [ $this, 'initGutenbergBlock'] );
29 add_action( 'admin_enqueue_scripts', [ $this, 'loadGutenbergWidgetScripts'] );
30
31 add_action( 'init', [ $this, 'initBeaverModule' ] );
32 add_action( 'wp_enqueue_scripts', [ $this, 'load_beaver_builder_widget_script'] );
33
34 add_action( 'vc_before_init', [ $this, 'initWPBakeryModule' ] );
35 add_action( 'init', [ $this, 'initDiviModule' ] );
36
37 // add_action( 'init', [ $this, 'loadOxygenModule' ] );
38 }
39
40 /**
41 * {@inheritDoc}
42 */
43 public function bootstrap( $container ) {
44
45 }
46
47 public function load_beaver_builder_widget_script() {
48 if ( class_exists( '\FLBuilderModel' ) && \FLBuilderModel::is_builder_active() ) {
49 $this->enqueueEditorScripts();
50 }
51 }
52
53 public function enqueueEditorScripts() {
54
55 \Depicter::core()->assets()->enqueueStyle(
56 'depicter-admin',
57 \Depicter::core()->assets()->getUrl() . '/resources/styles/admin/admin.css'
58 );
59
60 \Depicter::core()->assets()->enqueueScript(
61 'depicter-admin',
62 \Depicter::core()->assets()->getUrl() . '/resources/scripts/admin/index.js',
63 ['jquery'],
64 true
65 );
66
67 wp_localize_script( 'depicter-admin', 'depicterParams',[
68 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
69 'editorUrl' => \Depicter::editor()->getEditUrl('1'),
70 'token' => \Depicter::csrf()->getToken( \Depicter\Security\CSRF::EDITOR_ACTION ),
71 'publishedText' => esc_html__( 'Published', 'depicter' )
72 ]);
73 }
74
75 public function loadGutenbergWidgetScripts() {
76
77 $current_screen = get_current_screen();
78 if ( !$current_screen->is_block_editor() ) {
79 return;
80 }
81
82 $list = [
83 [
84 'id' => "0",
85 'name' => __( 'Select Slider', 'depicter' )
86 ]
87 ];
88 $documents = \Depicter::documentRepository()->select( ['id', 'name'] )->orderBy('modified_at', 'DESC')->findAll()->get();
89 $list = $documents ? array_merge( $list, $documents->toArray() ) : $list;
90 if ( !empty( $list ) ) {
91 foreach ( $list as $key => $item ) {
92 $list[ $key ]['label'] = $item['name'];
93 unset( $list[ $key ]['name'] );
94
95 $list[ $key ]['value'] = $item['id'];
96 unset( $list[ $key ]['id'] );
97 }
98 }
99
100 // load common assets
101 \Depicter::front()->assets()->enqueueStyles();
102 \Depicter::front()->assets()->enqueueScripts();
103
104 wp_localize_script( 'wp-block-editor', 'depicterSliders',[
105 'list' => $list,
106 'ajax_url' => admin_url('admin-ajax.php'),
107 'token' => \Depicter::csrf()->getToken( \Depicter\Security\CSRF::EDITOR_ACTION ),
108 ]);
109
110 }
111
112 public function initGutenbergBlock() {
113 register_block_type( __DIR__ . '/Gutenberg/build', [
114 'render_callback' => [ $this, 'renderGutenbergBlock' ]
115 ] );
116 }
117
118 public function renderGutenbergBlock( $blockAttributes ) {
119
120 if ( !empty( $blockAttributes['id'] ) ) {
121 $id = (int) $blockAttributes['id'];
122 return depicter( $id, ['echo' => false ] );
123 } else {
124 echo esc_html__( 'Slider ID required', 'depicter' );
125 }
126
127 }
128
129
130 /**
131 * Load beaver builder module
132 *
133 * @return void
134 */
135 public function initBeaverModule() {
136 if ( class_exists( '\FLBuilder' ) ) {
137 require_once 'Beaver/module.php';
138 }
139 }
140
141 /**
142 * Load WPBakery module
143 *
144 * @return void
145 */
146 public function initWPBakeryModule() {
147 require_once 'WPBakery/module.php';
148
149 if ( !empty( $_GET['vc_action'] ) && $_GET['vc_action'] == 'vc_inline' ) {
150 $this->enqueueEditorScripts();
151 }
152 }
153
154 /**
155 * Load divi module
156 *
157 * @return void
158 */
159 public function initDiviModule() {
160 if ( class_exists( 'ET_Builder_Plugin' ) ) {
161 require_once 'Divi/depicter-divi.php';
162
163 if ( !empty( $_GET['et_fb'] ) ) {
164 add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] );
165 }
166 }
167 }
168
169 public function loadOxygenModule() {
170 if ( class_exists('\OxyEl') ) {
171 require_once 'Oxygen/module.php';
172 }
173 }
174 }
175