| 1 |
<?php |
| 2 |
namespace Elementor\Core\Common\Modules\Connect\Apps; |
| 3 |
|
| 4 |
use Elementor\User; |
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly |
| 10 |
} |
| 11 |
|
| 12 |
class Library extends Common_App { |
| 13 |
public function get_title() { |
| 14 |
return __( 'Library', 'elementor' ); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* @since 2.3.0 |
| 19 |
* @access protected |
| 20 |
*/ |
| 21 |
protected function get_slug() { |
| 22 |
return 'library'; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_template_content( $id ) { |
| 26 |
if ( ! $this->is_connected() ) { |
| 27 |
return new \WP_Error( '401', __( 'Connecting to the Library failed. Please try reloading the page and try again', 'elementor' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
$body_args = [ |
| 31 |
'id' => $id, |
| 32 |
|
| 33 |
// Which API version is used. |
| 34 |
'api_version' => ELEMENTOR_VERSION, |
| 35 |
// Which language to return. |
| 36 |
'site_lang' => get_bloginfo( 'language' ), |
| 37 |
]; |
| 38 |
|
| 39 |
/** |
| 40 |
* API: Template body args. |
| 41 |
* |
| 42 |
* Filters the body arguments send with the GET request when fetching the content. |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
* |
| 46 |
* @param array $body_args Body arguments. |
| 47 |
*/ |
| 48 |
$body_args = apply_filters( 'elementor/api/get_templates/body_args', $body_args ); |
| 49 |
|
| 50 |
$template_content = $this->request( 'get_template_content', $body_args, true ); |
| 51 |
|
| 52 |
return $template_content; |
| 53 |
} |
| 54 |
|
| 55 |
public function localize_settings( $settings ) { |
| 56 |
$is_connected = $this->is_connected(); |
| 57 |
|
| 58 |
/** @var ConnectModule $connect */ |
| 59 |
$connect = Plugin::$instance->common->get_component( 'connect' ); |
| 60 |
|
| 61 |
return array_replace_recursive( $settings, [ |
| 62 |
'library_connect' => [ |
| 63 |
'is_connected' => $is_connected, |
| 64 |
'subscription_plans' => $connect->get_subscription_plans( 'panel-library' ), |
| 65 |
'base_access_level' => ConnectModule::ACCESS_LEVEL_CORE, |
| 66 |
'current_access_level' => ConnectModule::ACCESS_LEVEL_CORE, |
| 67 |
], |
| 68 |
] ); |
| 69 |
} |
| 70 |
|
| 71 |
public function library_connect_popup_seen() { |
| 72 |
User::set_introduction_viewed( [ |
| 73 |
'introductionKey' => 'library_connect', |
| 74 |
] ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* @param \Elementor\Core\Common\Modules\Ajax\Module $ajax_manager |
| 79 |
*/ |
| 80 |
public function register_ajax_actions( $ajax_manager ) { |
| 81 |
$ajax_manager->register_ajax_action( 'library_connect_popup_seen', [ $this, 'library_connect_popup_seen' ] ); |
| 82 |
} |
| 83 |
|
| 84 |
protected function get_app_info() { |
| 85 |
return [ |
| 86 |
'user_common_data' => [ |
| 87 |
'label' => 'User Common Data', |
| 88 |
'value' => get_user_option( $this->get_option_name(), get_current_user_id() ), |
| 89 |
], |
| 90 |
'connect_site_key' => [ |
| 91 |
'label' => 'Site Key', |
| 92 |
'value' => get_option( 'elementor_connect_site_key' ), |
| 93 |
], |
| 94 |
'remote_info_library' => [ |
| 95 |
'label' => 'Remote Library Info', |
| 96 |
'value' => get_option( 'elementor_remote_info_library' ), |
| 97 |
], |
| 98 |
]; |
| 99 |
} |
| 100 |
|
| 101 |
protected function init() { |
| 102 |
add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] ); |
| 103 |
add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); |
| 104 |
} |
| 105 |
} |
| 106 |
|