| @@ -3,9 +3,8 @@ | ||
| 3 | 3 | namespace Depicter\Modules; |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | use Depicter\Modules\Elementor\SliderWidget; |
| 7 | -use Depicter\Modules\WooCommerce\Module; | |
| 8 | 7 | use WPEmerge\ServiceProviders\ServiceProviderInterface; |
| 9 | 8 | |
| 10 | 9 | /** |
| 11 | 10 | * Register widgets. |
| @@ -23,13 +22,8 @@ | ||
| 23 | 22 | $container[ 'depicter.modules.manager' ] = function () { |
| 24 | 23 | return new Modules(); |
| 25 | 24 | }; |
| 26 | 25 | $app->alias( 'modules', 'depicter.modules.manager' ); |
| 27 | - | |
| 28 | - $container[ 'depicter.modules.woocommerce' ] = function () { | |
| 29 | - return new Module(); | |
| 30 | - }; | |
| 31 | - $app->alias( 'WooCommerce', 'depicter.modules.woocommerce' ); | |
| 32 | 26 | } |
| 33 | 27 | |
| 34 | 28 | public function elementorModulesLoaded() { |
| 35 | 29 | if( defined( 'ELEMENTOR_VERSION' ) ){ |
| @@ -38,19 +32,18 @@ | ||
| 38 | 32 | } |
| 39 | 33 | |
| 40 | 34 | public function modulesLoaded(){ |
| 41 | 35 | |
| 42 | - add_action( 'init', [ $this, 'loadGutenbergModule' ] ); | |
| 36 | + add_action( 'init', [ $this, 'initGutenbergBlock'] ); | |
| 37 | + add_action( 'admin_enqueue_scripts', [ $this, 'loadGutenbergWidgetScripts'] ); | |
| 43 | 38 | |
| 44 | 39 | add_action( 'init', [ $this, 'initBeaverModule' ] ); |
| 45 | 40 | add_action( 'wp_enqueue_scripts', [ $this, 'load_beaver_builder_widget_script'] ); |
| 46 | 41 | |
| 47 | 42 | add_action( 'vc_before_init', [ $this, 'initWPBakeryModule' ] ); |
| 48 | - add_action( 'init', [ $this, 'initDiviModule' ], 99 ); | |
| 43 | + add_action( 'init', [ $this, 'initDiviModule' ] ); | |
| 49 | 44 | |
| 50 | 45 | add_action( 'init', [ $this, 'loadOxygenModule' ] ); |
| 51 | - | |
| 52 | - add_action( 'init', [ $this, 'loadBricksElements'], 11 ); | |
| 53 | 46 | } |
| 54 | 47 | |
| 55 | 48 | /** |
| 56 | 49 | * {@inheritDoc} |
| @@ -86,12 +79,66 @@ | ||
| 86 | 79 | 'publishedText' => esc_html__( 'Published', 'depicter' ) |
| 87 | 80 | ]); |
| 88 | 81 | } |
| 89 | 82 | |
| 90 | - public function loadGutenbergModule() { | |
| 91 | - require_once 'Gutenberg/module.php'; | |
| 83 | + public function loadGutenbergWidgetScripts() { | |
| 84 | + | |
| 85 | + $current_screen = get_current_screen(); | |
| 86 | + if ( !$current_screen->is_block_editor() ) { | |
| 87 | + return; | |
| 88 | + } | |
| 89 | + | |
| 90 | + $list = [ | |
| 91 | + [ | |
| 92 | + 'id' => "0", | |
| 93 | + 'name' => __( 'Select Slider', 'depicter' ) | |
| 94 | + ] | |
| 95 | + ]; | |
| 96 | + $documents = \Depicter::documentRepository()->select( ['id', 'name'] )->orderBy('modified_at', 'DESC')->findAll()->get(); | |
| 97 | + $list = $documents ? array_merge( $list, $documents->toArray() ) : $list; | |
| 98 | + if ( !empty( $list ) ) { | |
| 99 | + foreach ( $list as $key => $item ) { | |
| 100 | + $list[ $key ]['label'] = $item['name']; | |
| 101 | + unset( $list[ $key ]['name'] ); | |
| 102 | + | |
| 103 | + $list[ $key ]['value'] = $item['id']; | |
| 104 | + unset( $list[ $key ]['id'] ); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + // load common assets | |
| 109 | + \Depicter::front()->assets()->enqueueStyles(); | |
| 110 | + \Depicter::front()->assets()->enqueueScripts(['player', 'iframe-resizer']); | |
| 111 | + | |
| 112 | + wp_localize_script( 'wp-block-editor', 'depicterSliders',[ | |
| 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' ) | |
| 119 | + ]); | |
| 120 | + | |
| 92 | 121 | } |
| 93 | 122 | |
| 123 | + public function initGutenbergBlock() { | |
| 124 | + register_block_type( __DIR__ . '/Gutenberg/build', [ | |
| 125 | + 'render_callback' => [ $this, 'renderGutenbergBlock' ] | |
| 126 | + ] ); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public function renderGutenbergBlock( $blockAttributes ) { | |
| 130 | + | |
| 131 | + if ( !empty( $blockAttributes['id'] ) ) { | |
| 132 | + $id = (int) $blockAttributes['id']; | |
| 133 | + return depicter( $id, ['echo' => false ] ); | |
| 134 | + } else { | |
| 135 | + echo esc_html__( 'Slider ID required', 'depicter' ); | |
| 136 | + } | |
| 137 | + | |
| 138 | + } | |
| 139 | + | |
| 140 | + | |
| 94 | 141 | /** |
| 95 | 142 | * Load beaver builder module |
| 96 | 143 | * |
| 97 | 144 | * @return void |
| @@ -120,9 +167,9 @@ | ||
| 120 | 167 | * |
| 121 | 168 | * @return void |
| 122 | 169 | */ |
| 123 | 170 | public function initDiviModule() { |
| 124 | - if ( class_exists( 'DiviExtension' ) ) { | |
| 171 | + if ( class_exists( 'ET_Builder_Plugin' ) ) { | |
| 125 | 172 | require_once 'Divi/depicter-divi.php'; |
| 126 | 173 | |
| 127 | 174 | if ( !empty( $_GET['et_fb'] ) ) { |
| 128 | 175 | add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] ); |
| @@ -137,14 +184,6 @@ | ||
| 137 | 184 | |
| 138 | 185 | if ( isset( $_GET['ct_builder'] ) ) { |
| 139 | 186 | add_action( 'wp_enqueue_scripts', [ $this, 'enqueueEditorScripts' ] ); |
| 140 | 187 | } |
| 141 | - } | |
| 142 | - | |
| 143 | - public function loadBricksElements() { | |
| 144 | - if ( ! class_exists( '\Bricks\Elements' ) ) { | |
| 145 | - return; | |
| 146 | - } | |
| 147 | - | |
| 148 | - \Bricks\Elements::register_element( __DIR__ . '/Bricks/widget.php', ); | |
| 149 | 188 | } |
| 150 | 189 | } |