PluginProbe
Elementor Website Builder – more than just a page builder / 3.30.0-beta1
Elementor Website Builder – more than just a page builder v3.30.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 457 releases
elementor / app / modules / kit-library / module.php

module.php in Elementor Website Builder – more than just a page builder 3.30.0-beta1, at app/modules/kit-library/module.php

190 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App\Modules\KitLibrary;
3
4 use Elementor\App\Modules\KitLibrary\Data\Repository;
5 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
6 use Elementor\Core\Admin\Menu\Main as MainMenu;
7 use Elementor\Core\Utils\Exceptions;
8 use Elementor\Plugin;
9 use Elementor\TemplateLibrary\Source_Local;
10 use Elementor\Core\Base\Module as BaseModule;
11 use Elementor\App\Modules\KitLibrary\Connect\Kit_Library;
12 use Elementor\App\Modules\KitLibrary\Connect\Cloud_Kits;
13 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
14 use Elementor\App\Modules\KitLibrary\Data\Kits\Controller as Kits_Controller;
15 use Elementor\App\Modules\KitLibrary\Data\Taxonomies\Controller as Taxonomies_Controller;
16 use Elementor\App\Modules\KitLibrary\Data\CloudKits\Controller as Cloud_Kits_Controller;
17 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
18 use Elementor\Utils as ElementorUtils;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit; // Exit if accessed directly.
22 }
23
24 class Module extends BaseModule {
25 /**
26 * Get name.
27 *
28 * @access public
29 *
30 * @return string
31 */
32 public function get_name() {
33 return 'kit-library';
34 }
35
36 private function register_admin_menu( MainMenu $menu ) {
37 $menu->add_submenu( [
38 'page_title' => esc_html__( 'Kit Library', 'elementor' ),
39 'menu_title' => '<span id="e-admin-menu__kit-library">' . esc_html__( 'Kit Library', 'elementor' ) . '</span>',
40 'menu_slug' => Plugin::$instance->app->get_base_url() . '#/kit-library',
41 'index' => 40,
42 ] );
43 }
44
45 /**
46 * Register the admin menu the old way.
47 */
48 private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) {
49 $admin_menu->register(
50 Plugin::$instance->app->get_base_url() . '#/kit-library',
51 new Kit_Library_Menu_Item()
52 );
53 }
54
55 private function set_kit_library_settings() {
56 if ( ! Plugin::$instance->common ) {
57 return;
58 }
59
60 /** @var ConnectModule $connect */
61 $connect = Plugin::$instance->common->get_component( 'connect' );
62
63 /** @var Kit_Library $kit_library */
64 $kit_library = $connect->get_app( 'kit-library' );
65
66 Plugin::$instance->app->set_settings( 'kit-library', [
67 'has_access_to_module' => current_user_can( 'manage_options' ),
68 'subscription_plans' => $this->apply_filter_subscription_plans( $connect->get_subscription_plans( 'kit-library' ) ),
69 'is_pro' => false,
70 'is_library_connected' => $kit_library->is_connected(),
71 'library_connect_url' => $kit_library->get_admin_url( 'authorize', [
72 'utm_source' => 'kit-library',
73 'utm_medium' => 'wp-dash',
74 'utm_campaign' => 'library-connect',
75 'utm_term' => '%%page%%', // Will be replaced in the frontend.
76 ] ),
77 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
78 'access_tier' => ConnectModule::ACCESS_TIER_FREE,
79 'app_url' => Plugin::$instance->app->get_base_url() . '#/' . $this->get_name(),
80 ] );
81 }
82
83 private function apply_filter_subscription_plans( array $subscription_plans ): array {
84 foreach ( $subscription_plans as $key => $plan ) {
85 if ( null === $plan['promotion_url'] ) {
86 continue;
87 }
88
89 $subscription_plans[ $key ] = Filtered_Promotions_Manager::get_filtered_promotion_data(
90 $plan,
91 'elementor/kit_library/' . $key . '/promotion',
92 'promotion_url'
93 );
94 }
95
96 return $subscription_plans;
97 }
98
99 /**
100 * Module constructor.
101 */
102 public function __construct() {
103 Plugin::$instance->data_manager_v2->register_controller( new Kits_Controller() );
104 Plugin::$instance->data_manager_v2->register_controller( new Taxonomies_Controller() );
105 Plugin::$instance->data_manager_v2->register_controller( new Cloud_Kits_Controller() );
106
107 // Assigning this action here since the repository is being loaded by demand.
108 add_action( 'elementor/experiments/feature-state-change/container', [ Repository::class, 'clear_cache' ], 10, 0 );
109
110 add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
111 $this->register_admin_menu_legacy( $admin_menu );
112 }, Source_Local::ADMIN_MENU_PRIORITY + 30 );
113
114 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
115 $connect_module->register_app( 'kit-library', Kit_Library::get_class_name() );
116
117 if ( Plugin::$instance->experiments->is_feature_active( 'cloud-library' ) ) {
118 $connect_module->register_app( 'cloud-kits', Cloud_Kits::get_class_name() );
119 }
120 } );
121
122 add_action( 'elementor/init', function () {
123 $this->set_kit_library_settings();
124 }, 12 /** After the initiation of the connect kit library */ );
125
126 if ( Plugin::$instance->experiments->is_feature_active( 'cloud-library' ) ) {
127 add_action( 'template_redirect', [ $this, 'handle_kit_screenshot_generation' ] );
128 }
129 }
130
131 public function handle_kit_screenshot_generation() {
132 $is_kit_preview = ElementorUtils::get_super_global_value( $_GET, 'kit_thumbnail' );
133 $nonce = ElementorUtils::get_super_global_value( $_GET, 'nonce' );
134
135 if ( $is_kit_preview ) {
136 if ( ! wp_verify_nonce( $nonce, 'kit_thumbnail' ) ) {
137 wp_die( esc_html__( 'Not Authorized', 'elementor' ), esc_html__( 'Error', 'elementor' ), 403 );
138 }
139
140 $suffix = ( ElementorUtils::is_script_debug() || ElementorUtils::is_elementor_tests() ) ? '' : '.min';
141
142 show_admin_bar( false );
143
144 wp_enqueue_script(
145 'dom-to-image',
146 ELEMENTOR_ASSETS_URL . "/lib/dom-to-image/js/dom-to-image{$suffix}.js",
147 [],
148 '2.6.0',
149 true
150 );
151
152 wp_enqueue_script(
153 'html2canvas',
154 ELEMENTOR_ASSETS_URL . "/lib/html2canvas/js/html2canvas{$suffix}.js",
155 [],
156 '1.4.1',
157 true
158 );
159
160 wp_enqueue_script(
161 'cloud-library-screenshot',
162 ELEMENTOR_ASSETS_URL . "/js/cloud-library-screenshot{$suffix}.js",
163 [ 'dom-to-image', 'html2canvas', 'elementor-common', 'elementor-common-modules' ],
164 ELEMENTOR_VERSION,
165 true
166 );
167
168 $config = [
169 'home_url' => home_url(),
170 'kit_id' => uniqid(),
171 'selector' => 'body',
172 ];
173
174 wp_add_inline_script( 'cloud-library-screenshot', 'var ElementorScreenshotConfig = ' . wp_json_encode( $config ) . ';' );
175 }
176 }
177
178 public static function get_cloud_app(): Cloud_Kits {
179 $cloud_kits_app = Plugin::$instance->common->get_component( 'connect' )->get_app( 'cloud-kits' );
180
181 if ( ! $cloud_kits_app ) {
182 $error_message = esc_html__( 'Cloud-Kits is not instantiated.', 'elementor' );
183
184 throw new \Exception( $error_message, Exceptions::FORBIDDEN ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
185 }
186
187 return $cloud_kits_app;
188 }
189 }
190