PluginProbe
Elementor Website Builder – more than just a page builder / 3.29.0-dev4
Elementor Website Builder – more than just a page builder v3.29.0-dev4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / cloud-library / module.php

module.php in Elementor Website Builder – more than just a page builder 3.29.0-dev4, at modules/cloud-library/module.php

160 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\CloudLibrary;
3
4 use Elementor\Core\Base\Module as BaseModule;
5 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
6 use Elementor\Core\Documents_Manager;
7 use Elementor\Core\Frontend\Render_Mode_Manager;
8 use Elementor\Modules\CloudLibrary\Connect\Cloud_Library;
9 use Elementor\Core\Common\Modules\Connect\Apps\Library;
10 use Elementor\Core\Experiments\Manager as ExperimentsManager;
11 use Elementor\Plugin;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Module extends BaseModule {
18
19 /**
20 * @var callable
21 */
22 protected $print_preview_callback;
23
24 public function get_name(): string {
25 return 'cloud-library';
26 }
27
28 public function __construct() {
29 parent::__construct();
30
31 $this->register_experiment();
32
33 if ( Plugin::$instance->experiments->is_feature_active( $this->get_name() ) ) {
34 $this->register_app();
35
36 add_action( 'elementor/init', function () {
37 $this->set_cloud_library_settings();
38 }, 12 /** After the initiation of the connect cloud library */ );
39
40 add_filter( 'elementor/editor/localize_settings', function ( $settings ) {
41 return $this->localize_settings( $settings );
42 }, 11 /** After Elementor Core */ );
43
44 add_filter( 'elementor/render_mode/module', function( $module_name ) {
45 $render_mode_manager = \Elementor\Plugin::$instance->frontend->render_mode_manager;
46
47 if ( $render_mode_manager && $render_mode_manager->get_current() instanceof \Elementor\Modules\CloudLibrary\Render_Mode_Preview ) {
48 return 'cloud-library';
49 }
50
51 return $module_name;
52 }, 12);
53 }
54 }
55
56 public function localize_settings( $settings ) {
57 if ( isset( $settings['i18n'] ) ) {
58 $settings['i18n']['folder'] = esc_html__( 'Folder', 'elementor' );
59 }
60
61 $settings['library']['doc_types'] = $this->get_document_types();
62
63 return $settings;
64 }
65
66 private function register_experiment() {
67 Plugin::$instance->experiments->add_feature( [
68 'name' => $this->get_name(),
69 'title' => esc_html__( 'Cloud Templates', 'elementor' ),
70 'description' => esc_html__( 'Cloud Templates empowers you to save and manage design elements across all your projects. This feature is associated and connected to your Elementor Pro account and can be accessed from any website associated with your account.', 'elementor' ),
71 'release_status' => ExperimentsManager::RELEASE_STATUS_BETA,
72 'default' => ExperimentsManager::STATE_ACTIVE,
73 ] );
74 }
75
76 private function register_app() {
77 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
78 $connect_module->register_app( 'cloud-library', Cloud_Library::get_class_name() );
79 } );
80
81 add_action( 'elementor/frontend/render_mode/register', [ $this, 'register_render_mode' ] );
82
83 add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) {
84 $documents_manager->register_document_type(
85 Documents\Cloud_Template_Preview::TYPE,
86 Documents\Cloud_Template_Preview::get_class_full_name()
87 );
88 });
89 }
90
91 /**
92 * @param Render_Mode_Manager $manager
93 *
94 * @throws \Exception
95 */
96 public function register_render_mode( Render_Mode_Manager $manager ) {
97 $manager->register_render_mode( Render_Mode_Preview::class );
98 }
99
100 private function set_cloud_library_settings() {
101 if ( ! Plugin::$instance->common ) {
102 return;
103 }
104
105 /** @var ConnectModule $connect */
106 $connect = Plugin::$instance->common->get_component( 'connect' );
107
108 /** @var Library $library */
109 $library = $connect->get_app( 'library' );
110
111 if ( ! $library ) {
112 return;
113 }
114
115 Plugin::$instance->app->set_settings( 'cloud-library', [
116 'library_connect_url' => esc_url( $library->get_admin_url( 'authorize', [
117 'utm_source' => 'template-library',
118 'utm_medium' => 'wp-dash',
119 'utm_campaign' => 'library-connect',
120 'utm_content' => 'cloud-library',
121 'source' => 'cloud-library',
122 ] ) ),
123 'library_connect_title' => esc_html__( 'Connect to your Elementor account', 'elementor' ),
124 'library_connect_sub_title' => esc_html__( 'Then you can find all your templates in one convenient library.', 'elementor' ),
125 'library_connect_button_text' => esc_html__( 'Connect', 'elementor' ),
126 ] );
127 }
128
129 private function get_document_types() {
130 $document_types = Plugin::$instance->documents->get_document_types( [
131 'show_in_library' => true,
132 ] );
133
134 $data = [];
135
136 foreach ( $document_types as $name => $document_type ) {
137 $data[ $name ] = $document_type::get_title();
138 }
139
140 return $data;
141 }
142
143 public function print_content() {
144 if ( ! $this->print_preview_callback ) {
145 $this->print_preview_callback = [ $this, 'print_thumbnail_preview_callback' ];
146 }
147
148 call_user_func( $this->print_preview_callback );
149 }
150
151 private function print_thumbnail_preview_callback() {
152 $doc = Plugin::$instance->documents->get_current();
153
154 // PHPCS - should not be escaped.
155 echo Plugin::$instance->frontend->get_builder_content_for_display( $doc->get_main_id(), true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
156
157 wp_delete_post( $doc->get_main_id(), true );
158 }
159 }
160