PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Dashboard / DashboardPage.php

DashboardPage.php in Depicter — Popup & Slider Builder 1.2.0, at app/src/Dashboard/DashboardPage.php

145 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Dashboard;
3
4 use Averta\Core\Utility\Arr;
5 use Averta\WordPress\Utility\Escape;
6 use Averta\WordPress\Utility\Plugin;
7 use Depicter\Security\CSRF;
8
9 class DashboardPage
10 {
11
12 const HOOK_SUFFIX = 'toplevel_page_depicter-dashboard';
13
14 /**
15 * @var string
16 */
17 var $hook_suffix = '';
18
19 public function bootstrap(){
20 add_action( 'admin_menu', [ $this, 'registerPage' ] );
21 add_action( 'admin_enqueue_scripts', [ $this, 'enqueueScripts' ] );
22 add_action( 'admin_head', array( $this, 'disable_admin_notices' ) );
23 }
24
25 /**
26 * Register admin pages.
27 *
28 * @return void
29 */
30 public function registerPage() {
31 $this->hook_suffix = add_menu_page(
32 __('Depicter', 'depicter'),
33 __('Depicter', 'depicter'),
34 'manage_options',
35 'depicter-dashboard',
36 [ $this, 'render' ], // called to output the content for this page
37 \Depicter::core()->assets()->getUrl() . '/resources/images/svg/wp-logo.svg'
38 );
39
40 add_action( 'admin_print_scripts-' . $this->hook_suffix, [ $this, 'printScripts' ] );
41 }
42
43 /**
44 * Disable all admin notices in dashboard page
45 *
46 * @return void
47 */
48 public function disable_admin_notices() {
49 $screen = get_current_screen();
50 if ( $screen->id == $this->hook_suffix ) {
51 remove_all_actions( 'admin_notices' );
52 }
53 }
54
55 public function render(){
56 echo Escape::content( \Depicter::view( 'admin/dashboard/index.php' )->toString() );
57 }
58
59 /**
60 * Load dashboard scripts
61 *
62 * @param string $hook_suffix
63 */
64 public function enqueueScripts( $hook_suffix = '' ){
65
66 if( $hook_suffix !== $this->hook_suffix ){
67 return;
68 }
69
70 // Enqueue scripts.
71 \Depicter::core()->assets()->enqueueScript(
72 'depicter-dashboard-js',
73 \Depicter::core()->assets()->getUrl() . '/resources/scripts/dashboard/depicter-dashboard.js',
74 [],
75 true
76 );
77
78 // Enqueue styles.
79 \Depicter::core()->assets()->enqueueStyle(
80 'depicter-dashboard-css',
81 \Depicter::core()->assets()->getUrl() . '/resources/styles/dashboard/index.css'
82 );
83 }
84
85 /**
86 * Print required scripts in Dashboard page
87 *
88 * @return void
89 */
90 public function printScripts()
91 {
92 global $wp_version;
93 $currentUser = wp_get_current_user();
94
95 wp_localize_script('depicter-dashboard-js', 'depicterDashboardEnv',
96 Arr::merge( $this->getCommonEnvParams(), [
97 "assetsAPI" => Escape::url('https://wp-api.depicter.com/' ),
98 "wpRestApi" => Escape::url( get_rest_url() ),
99 "dashboardAPI" => admin_url( 'admin-ajax.php' ),
100 "editorPath" => \Depicter::editor()->getEditUrl( '__id__' ),
101 "documentPreviewPath" => \Depicter::editor()->getEditUrl( '__id__' ),
102 'user' => [
103 'subscriptionPlan' => \Depicter::options()->get('user_plan', 'free-user'),
104 'name' => Escape::html( $currentUser->display_name ),
105 'email' => Escape::html( $currentUser->user_email ),
106 'hasSubscribed' => !! \Depicter::options()->get('has_subscribed')
107 ]
108 ])
109 );
110
111 wp_localize_script('depicter-dashboard-js', 'depicterKitEnv',
112 Arr::merge( $this->getCommonEnvParams(), [
113 'editorAPI' => admin_url( 'admin-ajax.php' ),
114 'user' => [
115 'subscriptionPlan' => \Depicter::options()->get('user_plan', 'free-user')
116 ]
117 ])
118 );
119
120 }
121
122 /**
123 * Get common ENV variables
124 *
125 * @return array
126 */
127 protected function getCommonEnvParams(){
128 global $wp_version;
129
130 return [
131 'wpVersion' => $wp_version,
132 "scriptsPath" => \Depicter::core()->assets()->getUrl(). '/resources/scripts/dashboard/',
133 'clientKey' => \Depicter::options()->get( 'client_key', 'anon' ),
134 'csrfToken' => \Depicter::csrf()->getToken( CSRF::DASHBOARD_ACTION ),
135 'updateInfo' => [
136 'from' => \Depicter::options()->get('version_previous') ?: null,
137 'to' => \Depicter::options()->get('version')
138 ],
139 'integrations' => [
140 'woocommerce' => Plugin::isActive( 'woocommerce/woocommerce.php' )
141 ]
142 ];
143 }
144 }
145