PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0-dev2
Elementor Website Builder – more than just a page builder v4.2.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 4.2.0-dev2, at app/modules/kit-library/module.php

168 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\Plugin;
6 use Elementor\TemplateLibrary\Source_Local;
7 use Elementor\Core\Base\Module as BaseModule;
8 use Elementor\App\Modules\KitLibrary\Connect\Kit_Library;
9 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
10 use Elementor\App\Modules\KitLibrary\Data\Kits\Controller as Kits_Controller;
11 use Elementor\App\Modules\KitLibrary\Data\Taxonomies\Controller as Taxonomies_Controller;
12 use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
13 use Elementor\Utils as ElementorUtils;
14 use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider;
15 use Elementor\App\Modules\KitLibrary\AdminMenuItems\Editor_One_Website_Templates_Menu;
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_editor_one_menu( Menu_Data_Provider $menu_data_provider ) {
34 $menu_data_provider->register_menu( new Editor_One_Website_Templates_Menu() );
35 }
36
37 private function set_kit_library_settings() {
38 if ( ! Plugin::$instance->common ) {
39 return;
40 }
41
42 /** @var ConnectModule $connect */
43 $connect = Plugin::$instance->common->get_component( 'connect' );
44
45 /** @var Kit_Library $kit_library */
46 $kit_library = $connect->get_app( 'kit-library' );
47
48 Plugin::$instance->app->set_settings( 'kit-library', [
49 'has_access_to_module' => current_user_can( 'manage_options' ),
50 'subscription_plans' => $this->apply_filter_subscription_plans( $connect->get_subscription_plans( 'kit-library' ) ),
51 'is_pro' => false,
52 'is_library_connected' => $kit_library->is_connected(),
53 'library_connect_url' => $kit_library->get_admin_url( 'authorize', [
54 'utm_source' => 'kit-library',
55 'utm_medium' => 'wp-dash',
56 'utm_campaign' => 'library-connect',
57 'utm_term' => '%%page%%', // Will be replaced in the frontend.
58 ] ),
59 'access_level' => ConnectModule::ACCESS_LEVEL_CORE,
60 'access_tier' => ConnectModule::ACCESS_TIER_FREE,
61 'plan_type' => ConnectModule::ACCESS_TIER_FREE,
62 'app_url' => Plugin::$instance->app->get_base_url() . '#/' . $this->get_name(),
63 'urls' => [
64 'createNewPage' => Plugin::$instance->documents->get_create_new_post_url(),
65 ],
66 ] );
67 }
68
69 private function apply_filter_subscription_plans( array $subscription_plans ): array {
70 foreach ( $subscription_plans as $key => $plan ) {
71 if ( null === $plan['promotion_url'] ) {
72 continue;
73 }
74
75 $subscription_plans[ $key ] = Filtered_Promotions_Manager::get_filtered_promotion_data(
76 $plan,
77 'elementor/kit_library/' . $key . '/promotion',
78 'promotion_url'
79 );
80 }
81
82 return $subscription_plans;
83 }
84
85 /**
86 * Module constructor.
87 */
88 public function __construct() {
89 Plugin::$instance->data_manager_v2->register_controller( new Kits_Controller() );
90 Plugin::$instance->data_manager_v2->register_controller( new Taxonomies_Controller() );
91
92 $this->register_actions();
93
94 do_action( 'elementor/kit_library/registered', $this );
95 }
96
97 public function register_actions() {
98 // Assigning this action here since the repository is being loaded by demand.
99 add_action( 'elementor/experiments/feature-state-change/container', [ Repository::class, 'clear_cache' ], 10, 0 );
100
101 add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) {
102 $this->register_editor_one_menu( $menu_data_provider );
103 } );
104
105 add_filter( 'elementor/editor-one/menu/protected_templates_submenu_slugs', function ( array $protected_slugs ): array {
106 $protected_slugs[] = 'edit-tags.php?taxonomy=elementor_library_category&amp;post_type=elementor_library';
107 return $protected_slugs;
108 } );
109
110 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
111 $connect_module->register_app( 'kit-library', Kit_Library::get_class_name() );
112 } );
113
114 add_action( 'elementor/init', function () {
115 $this->set_kit_library_settings();
116 }, 12 /** After the initiation of the connect kit library */ );
117
118 add_action( 'template_redirect', [ $this, 'handle_kit_screenshot_generation' ] );
119 }
120
121 public function handle_kit_screenshot_generation() {
122 $is_kit_preview = ElementorUtils::get_super_global_value( $_GET, 'kit_thumbnail' );
123 $nonce = ElementorUtils::get_super_global_value( $_GET, 'nonce' );
124
125 if ( $is_kit_preview ) {
126 if ( ! wp_verify_nonce( $nonce, 'kit_thumbnail' ) ) {
127 wp_die( esc_html__( 'Not Authorized', 'elementor' ), esc_html__( 'Error', 'elementor' ), 403 );
128 }
129
130 $suffix = ( ElementorUtils::is_script_debug() || ElementorUtils::is_elementor_tests() ) ? '' : '.min';
131
132 show_admin_bar( false );
133
134 wp_enqueue_script(
135 'dom-to-image',
136 ELEMENTOR_ASSETS_URL . "/lib/dom-to-image/js/dom-to-image{$suffix}.js",
137 [],
138 '2.6.0',
139 true
140 );
141
142 wp_enqueue_script(
143 'html2canvas',
144 ELEMENTOR_ASSETS_URL . "/lib/html2canvas/js/html2canvas{$suffix}.js",
145 [],
146 '1.4.1',
147 true
148 );
149
150 wp_enqueue_script(
151 'cloud-library-screenshot',
152 ELEMENTOR_ASSETS_URL . "/js/cloud-library-screenshot{$suffix}.js",
153 [ 'dom-to-image', 'html2canvas', 'elementor-common', 'elementor-common-modules' ],
154 ELEMENTOR_VERSION,
155 true
156 );
157
158 $config = [
159 'home_url' => home_url(),
160 'kit_id' => uniqid(),
161 'selector' => 'body',
162 ];
163
164 wp_add_inline_script( 'cloud-library-screenshot', 'var ElementorScreenshotConfig = ' . wp_json_encode( $config ) . ';' );
165 }
166 }
167 }
168