Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/elementor/app/modules/kit-library/module.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
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\Plugin;
8 + use Elementor\TemplateLibrary\Source_Local;
9 + use Elementor\Core\Base\Module as BaseModule;
10 + use Elementor\App\Modules\KitLibrary\Connect\Kit_Library;
11 + use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
12 + use Elementor\App\Modules\KitLibrary\Data\Kits\Controller as Kits_Controller;
13 + use Elementor\App\Modules\KitLibrary\Data\Taxonomies\Controller as Taxonomies_Controller;
14 + use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
15 + use Elementor\Utils as ElementorUtils;
16 + use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
17 + use Elementor\App\Modules\KitLibrary\AdminMenuItems\Editor_One_Website_Templates_Menu;
18 +
19 + if ( ! defined( 'ABSPATH' ) ) {
20 + exit; // Exit if accessed directly.
21 + }
22 +
23 + class Module extends BaseModule {
24 + /**
25 + * Get name.
26 + *
27 + * @access public
28 + *
29 + * @return string
30 + */
31 + public function get_name() {
32 + return 'kit-library';
33 + }
34 +
35 + private function register_admin_menu( MainMenu $menu ) {
36 + $menu->add_submenu( [
37 + 'page_title' => esc_html__( 'Website Templates', 'elementor' ),
38 + 'menu_title' => '<span id="e-admin-menu__kit-library">' . esc_html__( 'Website Templates', 'elementor' ) . '</span>',
39 + 'menu_slug' => Plugin::$instance->app->get_base_url() . '&source=wp_db_templates_menu#/kit-library',
40 + 'index' => 40,
41 + ] );
42 + }
43 +
44 + private function register_admin_menu_legacy( Admin_Menu_Manager $admin_menu ) {
45 + if ( ! $this->is_editor_one_active() ) {
46 + $admin_menu->register(
47 + Plugin::$instance->app->get_base_url() . '&source=wp_db_templates_menu#/kit-library',
48 + new Kit_Library_Menu_Item()
49 + );
50 + }
51 + }
52 +
53 + private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
54 + $menu_data_provider->register_menu( new Editor_One_Website_Templates_Menu() );
55 + }
56 +
57 + private function is_editor_one_active(): bool {
58 + return (bool) Plugin::instance()->modules_manager->get_modules( 'editor-one' );
59 + }
60 +
61 + private function set_kit_library_settings() {
62 + if ( ! Plugin::$instance->common ) {
63 + return;
64 + }
65 +
66 + /** @var ConnectModule $connect */
67 + $connect = Plugin::$instance->common->get_component( 'connect' );
68 +
69 + /** @var Kit_Library $kit_library */
70 + $kit_library = $connect->get_app( 'kit-library' );
71 +
72 + Plugin::$instance->app->set_settings( 'kit-library', [
73 + 'has_access_to_module' => current_user_can( 'manage_options' ),
74 + 'subscription_plans' => $this->apply_filter_subscription_plans( $connect->get_subscription_plans( 'kit-library' ) ),
75 + 'is_pro' => false,
76 + 'is_library_connected' => $kit_library->is_connected(),
77 + 'library_connect_url' => $kit_library->get_admin_url( 'authorize', [
78 + 'utm_source' => 'kit-library',
79 + 'utm_medium' => 'wp-dash',
80 + 'utm_campaign' => 'library-connect',
81 + 'utm_term' => '%%page%%', // Will be replaced in the frontend.
82 + ] ),
83 + 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
84 + 'access_tier' => ConnectModule::ACCESS_TIER_FREE,
85 + 'plan_type' => ConnectModule::ACCESS_TIER_FREE,
86 + 'app_url' => Plugin::$instance->app->get_base_url() . '#/' . $this->get_name(),
87 + ] );
88 + }
89 +
90 + private function apply_filter_subscription_plans( array $subscription_plans ): array {
91 + foreach ( $subscription_plans as $key => $plan ) {
92 + if ( null === $plan['promotion_url'] ) {
93 + continue;
94 + }
95 +
96 + $subscription_plans[ $key ] = Filtered_Promotions_Manager::get_filtered_promotion_data(
97 + $plan,
98 + 'elementor/kit_library/' . $key . '/promotion',
99 + 'promotion_url'
100 + );
101 + }
102 +
103 + return $subscription_plans;
104 + }
105 +
106 + /**
107 + * Module constructor.
108 + */
109 + public function __construct() {
110 + Plugin::$instance->data_manager_v2->register_controller( new Kits_Controller() );
111 + Plugin::$instance->data_manager_v2->register_controller( new Taxonomies_Controller() );
112 +
113 + $this->register_actions();
114 +
115 + do_action( 'elementor/kit_library/registered', $this );
116 + }
117 +
118 + public function register_actions() {
119 + // Assigning this action here since the repository is being loaded by demand.
120 + add_action( 'elementor/experiments/feature-state-change/container', [ Repository::class, 'clear_cache' ], 10, 0 );
121 +
122 + add_action( 'elementor/admin/menu/register', function( Admin_Menu_Manager $admin_menu ) {
123 + $this->register_admin_menu_legacy( $admin_menu );
124 + }, Source_Local::ADMIN_MENU_PRIORITY + 30 );
125 +
126 + add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
127 + $this->register_editor_one_menu( $menu_data_provider );
128 + } );
129 +
130 + add_filter( 'elementor/editor-one/menu/protected_templates_submenu_slugs', function ( array $protected_slugs ): array {
131 + $protected_slugs[] = 'edit-tags.php?taxonomy=elementor_library_category&amp;post_type=elementor_library';
132 + return $protected_slugs;
133 + } );
134 +
135 + add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
136 + $connect_module->register_app( 'kit-library', Kit_Library::get_class_name() );
137 + } );
138 +
139 + add_action( 'elementor/init', function () {
140 + $this->set_kit_library_settings();
141 + }, 12 /** After the initiation of the connect kit library */ );
142 +
143 + add_action( 'template_redirect', [ $this, 'handle_kit_screenshot_generation' ] );
144 + }
145 +
146 + public function handle_kit_screenshot_generation() {
147 + $is_kit_preview = ElementorUtils::get_super_global_value( $_GET, 'kit_thumbnail' );
148 + $nonce = ElementorUtils::get_super_global_value( $_GET, 'nonce' );
149 +
150 + if ( $is_kit_preview ) {
151 + if ( ! wp_verify_nonce( $nonce, 'kit_thumbnail' ) ) {
152 + wp_die( esc_html__( 'Not Authorized', 'elementor' ), esc_html__( 'Error', 'elementor' ), 403 );
153 + }
154 +
155 + $suffix = ( ElementorUtils::is_script_debug() || ElementorUtils::is_elementor_tests() ) ? '' : '.min';
156 +
157 + show_admin_bar( false );
158 +
159 + wp_enqueue_script(
160 + 'dom-to-image',
161 + ELEMENTOR_ASSETS_URL . "/lib/dom-to-image/js/dom-to-image{$suffix}.js",
162 + [],
163 + '2.6.0',
164 + true
165 + );
166 +
167 + wp_enqueue_script(
168 + 'html2canvas',
169 + ELEMENTOR_ASSETS_URL . "/lib/html2canvas/js/html2canvas{$suffix}.js",
170 + [],
171 + '1.4.1',
172 + true
173 + );
174 +
175 + wp_enqueue_script(
176 + 'cloud-library-screenshot',
177 + ELEMENTOR_ASSETS_URL . "/js/cloud-library-screenshot{$suffix}.js",
178 + [ 'dom-to-image', 'html2canvas', 'elementor-common', 'elementor-common-modules' ],
179 + ELEMENTOR_VERSION,
180 + true
181 + );
182 +
183 + $config = [
184 + 'home_url' => home_url(),
185 + 'kit_id' => uniqid(),
186 + 'selector' => 'body',
187 + ];
188 +
189 + wp_add_inline_script( 'cloud-library-screenshot', 'var ElementorScreenshotConfig = ' . wp_json_encode( $config ) . ';' );
190 + }
191 + }
192 + }
193 +