PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.4
Elementor Website Builder – more than just a page builder v3.20.4
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 / apps / admin-apps-page.php

admin-apps-page.php in Elementor Website Builder – more than just a page builder 3.20.4, at modules/apps/admin-apps-page.php

197 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\Apps;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 class Admin_Apps_Page {
9
10 const APPS_URL = 'https://assets.elementor.com/apps/v1/apps.json';
11
12 public static function render() {
13 ?>
14 <div class="wrap e-a-apps">
15
16 <div class="e-a-page-title">
17 <h2><?php echo esc_html__( 'Popular Add-ons, New Possibilities.', 'elementor' ); ?></h2>
18 <p><?php echo esc_html__( 'Boost your web-creation process with add-ons, plugins, and more tools specially selected to unleash your creativity, increase productivity, and enhance your Elementor-powered website.', 'elementor' ); ?>*<br>
19 <a href="https://go.elementor.com/wp-dash-apps-about-apps-page/" target="_blank"><?php echo esc_html__( 'Learn more about this page.', 'elementor' ); ?></a>
20 </p>
21 </div>
22
23 <div class="e-a-list">
24 <?php self::render_plugins_list(); ?>
25 </div>
26 <div class="e-a-page-footer">
27 <p>*<?php echo esc_html__( 'Please note that certain tools and services on this page are developed by third-party companies and are not part of Elementor\'s suite of products or support. Before using them, we recommend independently evaluating them. Additionally, when clicking on their action buttons, you may be redirected to an external website.', 'elementor' ); ?></p>
28 </div>
29 </div>
30 <?php
31 }
32
33 private static function render_plugins_list() {
34 $plugins = self::get_plugins();
35
36 foreach ( $plugins as $plugin ) {
37 self::render_plugin_item( $plugin );
38 }
39 }
40
41 private static function get_plugins() : array {
42 $apps = static::get_remote_apps();
43
44 return static::filter_apps( $apps );
45 }
46
47 private static function get_remote_apps() {
48 $apps = wp_remote_get( static::APPS_URL );
49
50 if ( is_wp_error( $apps ) ) {
51 return [];
52 }
53
54 $apps = json_decode( wp_remote_retrieve_body( $apps ), true );
55
56 if ( empty( $apps['apps'] ) || ! is_array( $apps['apps'] ) ) {
57 return [];
58 }
59
60 return $apps['apps'];
61 }
62
63 private static function filter_apps( $apps ) {
64 $filtered_apps = [];
65
66 foreach ( $apps as $app ) {
67 if ( static::is_wporg_app( $app ) ) {
68 $app = static::filter_wporg_app( $app );
69 }
70
71 if ( static::is_ecom_app( $app ) ) {
72 $app = static::filter_ecom_app( $app );
73 }
74
75 if ( empty( $app ) ) {
76 continue;
77 }
78
79 $filtered_apps[] = $app;
80 }
81
82 return $filtered_apps;
83 }
84
85 private static function is_wporg_app( $app ) {
86 return isset( $app['type'] ) && 'wporg' === $app['type'];
87 }
88
89 private static function filter_wporg_app( $app ) {
90 if ( static::is_plugin_activated( $app['file_path'] ) ) {
91 return null;
92 }
93
94 if ( static::is_plugin_installed( $app['file_path'] ) ) {
95 if ( current_user_can( 'activate_plugins' ) ) {
96 $app['action_label'] = 'Activate';
97 $app['action_url'] = static::get_activate_plugin_url( $app['file_path'] );
98 } else {
99 $app['action_label'] = 'Cannot Activate';
100 $app['action_url'] = '#';
101 }
102 } else {
103 if ( current_user_can( 'install_plugins' ) ) {
104 $app['action_label'] = 'Install';
105 $app['action_url'] = static::get_install_plugin_url( $app['file_path'] );
106 } else {
107 $app['action_label'] = 'Cannot Install';
108 $app['action_url'] = '#';
109 }
110 }
111
112 return $app;
113 }
114
115 private static function is_ecom_app( $app ) {
116 return isset( $app['type'] ) && 'ecom' === $app['type'];
117 }
118
119 private static function filter_ecom_app( $app ) {
120 if ( static::is_plugin_activated( $app['file_path'] ) ) {
121 return null;
122 }
123
124 if ( ! static::is_plugin_installed( $app['file_path'] ) ) {
125 return $app;
126 }
127
128 if ( current_user_can( 'activate_plugins' ) ) {
129 $app['action_label'] = 'Activate';
130 $app['action_url'] = static::get_activate_plugin_url( $app['file_path'] );
131 } else {
132 $app['action_label'] = 'Cannot Activate';
133 $app['action_url'] = '#';
134 }
135
136 $app['target'] = '_self';
137
138 return $app;
139 }
140
141 private static function get_images_url() {
142 return ELEMENTOR_URL . 'modules/apps/images/';
143 }
144
145 private static function is_elementor_pro_installed() {
146 return defined( 'ELEMENTOR_PRO_VERSION' );
147 }
148
149 private static function is_plugin_installed( $file_path ) {
150 $installed_plugins = get_plugins();
151
152 return isset( $installed_plugins[ $file_path ] );
153 }
154
155 private static function is_plugin_activated( $file_path ) {
156 return is_plugin_active( $file_path );
157 }
158
159 private static function get_activate_plugin_url( $file_path ) {
160 return wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $file_path . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $file_path );
161 }
162
163 private static function get_install_plugin_url( $file_path ) {
164 $slug = dirname( $file_path );
165
166 return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
167 }
168
169 private static function render_plugin_item( $plugin ) {
170 ?>
171 <div class="e-a-item">
172 <div class="e-a-heading">
173 <img class="e-a-img" src="<?php echo esc_url( $plugin['image'] ); ?>" alt="<?php echo esc_attr( $plugin['name'] ); ?>">
174 <?php if ( ! empty( $plugin['badge'] ) ) : ?>
175 <span class="e-a-badge"><?php echo esc_html( $plugin['badge'] ); ?></span>
176 <?php endif; ?>
177 </div>
178 <h3 class="e-a-title"><?php echo esc_html( $plugin['name'] ); ?></h3>
179 <p class="e-a-author"><?php esc_html_e( 'By', 'elementor' ); ?> <a href="<?php echo esc_url( $plugin['author_url'] ); ?>" target="_blank"><?php echo esc_html( $plugin['author'] ); ?></a></p>
180 <div class="e-a-desc">
181 <p><?php echo esc_html( $plugin['description'] ); ?></p>
182 <?php if ( ! empty( $plugin['offering'] ) ) : ?>
183 <p class="e-a-offering"><?php echo esc_html( $plugin['offering'] ); ?></p>
184 <?php endif; ?>
185 </div>
186
187 <p class="e-a-actions">
188 <?php if ( ! empty( $plugin['learn_more_url'] ) ) : ?>
189 <a class="e-a-learn-more" href="<?php echo esc_url( $plugin['learn_more_url'] ); ?>" target="_blank"><?php echo esc_html__( 'Learn More', 'elementor' ); ?></a>
190 <?php endif; ?>
191 <a href="<?php echo esc_url( $plugin['action_url'] ); ?>" class="e-btn e-accent" target="<?php echo isset( $plugin['target'] ) ? esc_attr( $plugin['target'] ) : '_blank'; ?>"><?php echo esc_html( $plugin['action_label'] ); ?></a>
192 </p>
193 </div>
194 <?php
195 }
196 }
197