| 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&plugin=' . $file_path . '&plugin_status=all&paged=1&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 |
|