| 1 |
<?php |
| 2 |
namespace Depicter\Editor; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Arr; |
| 5 |
use Averta\Core\Utility\Data; |
| 6 |
use Averta\WordPress\Utility\Escape; |
| 7 |
use Averta\WordPress\Utility\JSON; |
| 8 |
use Averta\WordPress\Utility\Plugin; |
| 9 |
use Averta\WordPress\Utility\Sanitize; |
| 10 |
use Depicter\Security\CSRF; |
| 11 |
|
| 12 |
|
| 13 |
class EditorAssets |
| 14 |
{ |
| 15 |
public function bootstrap(){ |
| 16 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueueAdminAssets' ] ); |
| 17 |
} |
| 18 |
|
| 19 |
public function enqueueAdminAssets(){ |
| 20 |
global $wp_version; |
| 21 |
|
| 22 |
// This will enqueue the Media Uploader script |
| 23 |
wp_enqueue_media(); |
| 24 |
|
| 25 |
\Depicter::core()->assets()->enqueueScript( |
| 26 |
'depicter-admin', |
| 27 |
\Depicter::core()->assets()->getUrl() . '/resources/scripts/admin/index.js', |
| 28 |
['jquery'], |
| 29 |
true |
| 30 |
); |
| 31 |
|
| 32 |
wp_enqueue_style('common'); |
| 33 |
|
| 34 |
// Enqueue scripts. |
| 35 |
\Depicter::core()->assets()->enqueueScript( |
| 36 |
'depicter-editor-vendors', |
| 37 |
\Depicter::core()->assets()->getUrl() . '/resources/scripts/editor/vendors-main.js', |
| 38 |
[], |
| 39 |
true |
| 40 |
); |
| 41 |
\Depicter::core()->assets()->enqueueScript( |
| 42 |
'depicter-editor-js', |
| 43 |
\Depicter::core()->assets()->getUrl() . '/resources/scripts/editor/depicter-editor.js', |
| 44 |
['depicter-editor-vendors'], |
| 45 |
true |
| 46 |
); |
| 47 |
|
| 48 |
$currentUser = wp_get_current_user(); |
| 49 |
|
| 50 |
// Add Environment variables |
| 51 |
wp_add_inline_script( 'depicter-editor-vendors', 'window.depicterEnv = '. JSON::encode( |
| 52 |
[ |
| 53 |
'wpVersion' => $wp_version, |
| 54 |
"scriptsPath" => \Depicter::core()->assets()->getUrl(). '/resources/scripts/editor/', |
| 55 |
'pluginAPI' => admin_url( 'admin-ajax.php' ), |
| 56 |
'clientKey' => \Depicter::auth()->getClientKey(), |
| 57 |
'csrfToken' => \Depicter::csrf()->getToken( CSRF::EDITOR_ACTION ), |
| 58 |
'wpHomepage' => home_url(), |
| 59 |
'updateInfo' => [ |
| 60 |
'from' => \Depicter::options()->get('version_previous') ?: null, |
| 61 |
'to' => \Depicter::options()->get('version') |
| 62 |
], |
| 63 |
"assetsAPI" => Escape::url('https://api.wp.depicter.com/' ), |
| 64 |
"wpRestAPI" => Escape::url( get_rest_url() ), |
| 65 |
"dashboardURL"=> Escape::url( menu_page_url('depicter-dashboard', false) ), |
| 66 |
"documentId" => Data::cast( Sanitize::key( $_GET['document'] ), 'int' ), |
| 67 |
'user' => [ |
| 68 |
'tier' => \Depicter::auth()->getTier(), |
| 69 |
'name' => Escape::html( $currentUser->display_name ), |
| 70 |
'email' => Escape::html( $currentUser->user_email ), |
| 71 |
'joinedNewsletter' => !! \Depicter::options()->get('has_subscribed') |
| 72 |
], |
| 73 |
'activation' => [ |
| 74 |
'status' => \Depicter::auth()->getActivationStatus(), |
| 75 |
'errorMessage' => \Depicter::options()->get('activation_error_message', ''), |
| 76 |
'expiresAt' => \Depicter::options()->get('subscription_expires_at' , ''), |
| 77 |
'isNew' => isset( $_GET['depicter_upgraded'] ) |
| 78 |
], |
| 79 |
'integrations' => [ |
| 80 |
'woocommerce' => Plugin::isActive( 'woocommerce/woocommerce.php' ) |
| 81 |
] |
| 82 |
] |
| 83 |
), 'before' ); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|