| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Depicter\Modules; |
| 4 | 4 | |
| 5 | + | |
| 5 | 6 | use Depicter\Modules\Elementor\SliderWidget; |
| 6 | 7 | use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 7 | 8 | |
| 8 | 9 | /** |
| @@ -12,24 +13,26 @@ | ||
| 12 | 13 | /** |
| 13 | 14 | * {@inheritDoc} |
| 14 | 15 | */ |
| 15 | 16 | public function register( $container ) { |
| 16 | - // Nothing to register. | |
| 17 | + add_action( 'plugins_loaded', [ $this, 'elementorModulesLoaded' ] ); | |
| 18 | + $this->modulesLoaded(); | |
| 19 | + | |
| 20 | + $app = $container[ WPEMERGE_APPLICATION_KEY ]; | |
| 21 | + | |
| 22 | + $container[ 'depicter.modules.manager' ] = function () { | |
| 23 | + return new Modules(); | |
| 24 | + }; | |
| 25 | + $app->alias( 'modules', 'depicter.modules.manager' ); | |
| 17 | 26 | } |
| 18 | 27 | |
| 19 | - /** | |
| 20 | - * {@inheritDoc} | |
| 21 | - */ | |
| 22 | - public function bootstrap( $container ) { | |
| 23 | - | |
| 24 | - if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) { | |
| 25 | - add_action( 'elementor/widgets/register', [$this, 'registerElementorWidgets'] ); | |
| 26 | - } else { | |
| 27 | - add_action( 'elementor/widgets/widgets_registered', [$this, 'registerElementorWidgets'] ); | |
| 28 | + public function elementorModulesLoaded() { | |
| 29 | + if( defined( 'ELEMENTOR_VERSION' ) ){ | |
| 30 | + New Elementor\Module(); | |
| 28 | 31 | } |
| 32 | + } | |
| 29 | 33 | |
| 30 | - add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueueEditorScripts'] ); | |
| 31 | - add_action( 'wp_enqueue_scripts', [ $this, 'loadElementorWidgetScript'] ); | |
| 34 | + public function modulesLoaded(){ | |
| 32 | 35 | |
| 33 | 36 | add_action( 'init', [ $this, 'initGutenbergBlock'] ); |
| 34 | 37 | add_action( 'admin_enqueue_scripts', [ $this, 'loadGutenbergWidgetScripts'] ); |
| 35 | 38 | |
| @@ -37,30 +40,17 @@ | ||
| 37 | 40 | add_action( 'wp_enqueue_scripts', [ $this, 'load_beaver_builder_widget_script'] ); |
| 38 | 41 | |
| 39 | 42 | add_action( 'vc_before_init', [ $this, 'initWPBakeryModule' ] ); |
| 40 | 43 | add_action( 'init', [ $this, 'initDiviModule' ] ); |
| 44 | + | |
| 45 | + add_action( 'init', [ $this, 'loadOxygenModule' ] ); | |
| 41 | 46 | } |
| 42 | 47 | |
| 43 | 48 | /** |
| 44 | - * Register Elementor widgets. | |
| 45 | - * | |
| 46 | - * @return void | |
| 49 | + * {@inheritDoc} | |
| 47 | 50 | */ |
| 48 | - public function registerElementorWidgets() { | |
| 49 | - if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) { | |
| 50 | - \Elementor\Plugin::instance()->widgets_manager->register( new SliderWidget() ); | |
| 51 | - } else { | |
| 52 | - \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new SliderWidget() ); | |
| 53 | - } | |
| 54 | - } | |
| 51 | + public function bootstrap( $container ) { | |
| 55 | 52 | |
| 56 | - /** | |
| 57 | - * load required script for elementor widget in elementor editor env | |
| 58 | - */ | |
| 59 | - public function loadElementorWidgetScript() { | |
| 60 | - if ( class_exists( '\Elementor\Plugin' ) && \Elementor\Plugin::$instance->preview->is_preview_mode() ) { | |
| 61 | - \Depicter::front()->assets()->enqueueScripts('widget'); | |
| 62 | - } | |
| 63 | 53 | } |
| 64 | 54 | |
| 65 | 55 | public function load_beaver_builder_widget_script() { |
| 66 | 56 | if ( class_exists( '\FLBuilderModel' ) && \FLBuilderModel::is_builder_active() ) { |
| @@ -102,9 +92,10 @@ | ||
| 102 | 92 | 'id' => "0", |
| 103 | 93 | 'name' => __( 'Select Slider', 'depicter' ) |
| 104 | 94 | ] |
| 105 | 95 | ]; |
| 106 | - $list = array_merge( $list, \Depicter::app()->documentRepository()->getList(['name','id']) ); | |
| 96 | + $documents = \Depicter::documentRepository()->select( ['id', 'name'] )->orderBy('modified_at', 'DESC')->findAll()->get(); | |
| 97 | + $list = $documents ? array_merge( $list, $documents->toArray() ) : $list; | |
| 107 | 98 | if ( !empty( $list ) ) { |
| 108 | 99 | foreach ( $list as $key => $item ) { |
| 109 | 100 | $list[ $key ]['label'] = $item['name']; |
| 110 | 101 | unset( $list[ $key ]['name'] ); |
| @@ -112,10 +103,20 @@ | ||
| 112 | 103 | $list[ $key ]['value'] = $item['id']; |
| 113 | 104 | unset( $list[ $key ]['id'] ); |
| 114 | 105 | } |
| 115 | 106 | } |
| 107 | + | |
| 108 | + // load common assets | |
| 109 | + \Depicter::front()->assets()->enqueueStyles(); | |
| 110 | + \Depicter::front()->assets()->enqueueScripts(['player', 'iframe-resizer']); | |
| 111 | + | |
| 116 | 112 | wp_localize_script( 'wp-block-editor', 'depicterSliders',[ |
| 117 | - 'list' => $list | |
| 113 | + 'list' => $list, | |
| 114 | + 'ajax_url' => admin_url('admin-ajax.php'), | |
| 115 | + 'editor_url' => \Depicter::editor()->getEditUrl('1'), | |
| 116 | + 'token' => \Depicter::csrf()->getToken( \Depicter\Security\CSRF::EDITOR_ACTION ), | |
| 117 | + 'publish_text' => esc_html__( 'Publish Slider', 'depicter' ), | |
| 118 | + 'edit_text' => esc_html__( 'Edit Slider', 'depicter' ) | |
| 118 | 119 | ]); |
| 119 | 120 | |
| 120 | 121 | } |
| 121 | 122 | |
| @@ -154,8 +155,12 @@ | ||
| 154 | 155 | * @return void |
| 155 | 156 | */ |
| 156 | 157 | public function initWPBakeryModule() { |
| 157 | 158 | require_once 'WPBakery/module.php'; |
| 159 | + | |
| 160 | + if ( !empty( $_GET['vc_action'] ) && $_GET['vc_action'] == 'vc_inline' ) { | |
| 161 | + $this->enqueueEditorScripts(); | |
| 162 | + } | |
| 158 | 163 | } |
| 159 | 164 | |
| 160 | 165 | /** |
| 161 | 166 | * Load divi module |
| @@ -164,7 +169,21 @@ | ||
| 164 | 169 | */ |
| 165 | 170 | public function initDiviModule() { |
| 166 | 171 | if ( class_exists( 'ET_Builder_Plugin' ) ) { |
| 167 | 172 | require_once 'Divi/depicter-divi.php'; |
| 173 | + | |
| 174 | + if ( !empty( $_GET['et_fb'] ) ) { | |
| 175 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] ); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + public function loadOxygenModule() { | |
| 181 | + if ( class_exists('\OxyEl') ) { | |
| 182 | + require_once 'Oxygen/module.php'; | |
| 183 | + } | |
| 184 | + | |
| 185 | + if ( isset( $_GET['ct_builder'] ) ) { | |
| 186 | + add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] ); | |
| 168 | 187 | } |
| 169 | 188 | } |
| 170 | 189 | } |