PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.4
Elementor Website Builder – more than just a page builder v3.19.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.19.4, at modules/apps/admin-apps-page.php

195 lines 5.9 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 public static function render() {
11 ?>
12 <div class="wrap e-a-apps">
13
14 <div class="e-a-page-title">
15 <h2><?php echo esc_html__( 'Popular Apps, New Possibilities.', 'elementor' ); ?></h2>
16 <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>
17 <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>
18 </p>
19 </div>
20
21 <div class="e-a-list">
22 <?php self::render_plugins_list(); ?>
23 </div>
24 <div class="e-a-page-footer">
25 <p><?php echo esc_html__( 'Please note that certain services on this page are developed by third-party companies. When you click on the their action button, you may be redirected to an external website.', 'elementor' ); ?></p>
26 </div>
27 </div>
28 <?php
29 }
30
31 private static function render_plugins_list() {
32 $plugins = self::get_plugins();
33
34 foreach ( $plugins as $plugin ) {
35 self::render_plugin_item( $plugin );
36 }
37 }
38
39 private static function get_plugins() : array {
40 $apps = static::get_remote_apps();
41
42 return static::filter_apps( $apps );
43 }
44
45 private static function get_remote_apps() {
46 $apps = wp_remote_get( 'https://assets.elementor.com/apps/v1/apps.json' );
47
48 if ( is_wp_error( $apps ) ) {
49 return [];
50 }
51
52 $apps = json_decode( wp_remote_retrieve_body( $apps ), true );
53
54 if ( empty( $apps['apps'] ) || ! is_array( $apps['apps'] ) ) {
55 return [];
56 }
57
58 return $apps['apps'];
59 }
60
61 private static function filter_apps( $apps ) {
62 $filtered_apps = [];
63
64 foreach ( $apps as $app ) {
65 if ( static::is_wporg_app( $app ) ) {
66 $app = static::filter_wporg_app( $app );
67 }
68
69 if ( static::is_ecom_app( $app ) ) {
70 $app = static::filter_ecom_app( $app );
71 }
72
73 if ( empty( $app ) ) {
74 continue;
75 }
76
77 $filtered_apps[] = $app;
78 }
79
80 return $filtered_apps;
81 }
82
83 private static function is_wporg_app( $app ) {
84 return isset( $app['type'] ) && 'wporg' === $app['type'];
85 }
86
87 private static function filter_wporg_app( $app ) {
88 if ( static::is_plugin_activated( $app['file_path'] ) ) {
89 return null;
90 }
91
92 if ( static::is_plugin_installed( $app['file_path'] ) ) {
93 if ( current_user_can( 'activate_plugins' ) ) {
94 $app['action_label'] = 'Activate';
95 $app['action_url'] = static::get_activate_plugin_url( $app['file_path'] );
96 } else {
97 $app['action_label'] = 'Cannot Activate';
98 $app['action_url'] = '#';
99 }
100 } else {
101 if ( current_user_can( 'install_plugins' ) ) {
102 $app['action_label'] = 'Install';
103 $app['action_url'] = static::get_install_plugin_url( $app['file_path'] );
104 } else {
105 $app['action_label'] = 'Cannot Install';
106 $app['action_url'] = '#';
107 }
108 }
109
110 return $app;
111 }
112
113 private static function is_ecom_app( $app ) {
114 return isset( $app['type'] ) && 'ecom' === $app['type'];
115 }
116
117 private static function filter_ecom_app( $app ) {
118 if ( static::is_plugin_activated( $app['file_path'] ) ) {
119 return null;
120 }
121
122 if ( ! static::is_plugin_installed( $app['file_path'] ) ) {
123 return $app;
124 }
125
126 if ( current_user_can( 'activate_plugins' ) ) {
127 $app['action_label'] = 'Activate';
128 $app['action_url'] = static::get_activate_plugin_url( $app['file_path'] );
129 } else {
130 $app['action_label'] = 'Cannot Activate';
131 $app['action_url'] = '#';
132 }
133
134 $app['target'] = '_self';
135
136 return $app;
137 }
138
139 private static function get_images_url() {
140 return ELEMENTOR_URL . 'modules/apps/images/';
141 }
142
143 private static function is_elementor_pro_installed() {
144 return defined( 'ELEMENTOR_PRO_VERSION' );
145 }
146
147 private static function is_plugin_installed( $file_path ) {
148 $installed_plugins = get_plugins();
149
150 return isset( $installed_plugins[ $file_path ] );
151 }
152
153 private static function is_plugin_activated( $file_path ) {
154 return is_plugin_active( $file_path );
155 }
156
157 private static function get_activate_plugin_url( $file_path ) {
158 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 );
159 }
160
161 private static function get_install_plugin_url( $file_path ) {
162 $slug = dirname( $file_path );
163
164 return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
165 }
166
167 private static function render_plugin_item( $plugin ) {
168 ?>
169 <div class="e-a-item">
170 <div class="e-a-heading">
171 <img class="e-a-img" src="<?php echo esc_url( $plugin['image'] ); ?>" alt="<?php echo esc_attr( $plugin['name'] ); ?>">
172 <?php if ( ! empty( $plugin['badge'] ) ) : ?>
173 <span class="e-a-badge"><?php echo esc_html( $plugin['badge'] ); ?></span>
174 <?php endif; ?>
175 </div>
176 <h3 class="e-a-title"><?php echo esc_html( $plugin['name'] ); ?></h3>
177 <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>
178 <div class="e-a-desc">
179 <p><?php echo esc_html( $plugin['description'] ); ?></p>
180 <?php if ( ! empty( $plugin['offering'] ) ) : ?>
181 <p class="e-a-offering"><?php echo esc_html( $plugin['offering'] ); ?></p>
182 <?php endif; ?>
183 </div>
184
185 <p class="e-a-actions">
186 <?php if ( ! empty( $plugin['learn_more_url'] ) ) : ?>
187 <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>
188 <?php endif; ?>
189 <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>
190 </p>
191 </div>
192 <?php
193 }
194 }
195