PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev2
Elementor Website Builder – more than just a page builder v3.32.0-dev2
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 / app / modules / kit-library / module.php

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

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