C:\xampp\htdocs\landing\wp-content\plugins\amp\src\Admin\OnboardingWizardSubmenuPage.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/**
 * OnboardingWizardSubmenuPage class.
 *
 * @package AmpProject\AmpWP
 * @since 2.0
 */

namespace AmpProject\AmpWP\Admin;

use 
AMP_Options_Manager;
use 
AmpProject\AmpWP\AmpSlugCustomizationWatcher;
use 
AmpProject\AmpWP\DevTools\UserAccess;
use 
AmpProject\AmpWP\Infrastructure\Conditional;
use 
AmpProject\AmpWP\Infrastructure\Delayed;
use 
AmpProject\AmpWP\Infrastructure\Registerable;
use 
AmpProject\AmpWP\Infrastructure\Service;
use 
AmpProject\AmpWP\Option;
use 
AmpProject\AmpWP\QueryVar;
use 
AmpProject\AmpWP\Services;

/**
 * AMP setup wizard submenu page class.
 *
 * @since 2.0
 * @internal
 */
final class OnboardingWizardSubmenuPage implements ConditionalDelayedRegisterableService {
    
/**
     * Handle for JS file.
     *
     * @since 2.0
     *
     * @var string
     */
    
const ASSET_HANDLE 'amp-onboarding-wizard';

    
/**
     * HTML ID for the app root element.
     *
     * @since 2.0
     *
     * @var string
     */
    
const APP_ROOT_ID 'amp-onboarding-wizard';

    
/**
     * GoogleFonts instance.
     *
     * @var GoogleFonts
     */
    
private $google_fonts;

    
/**
     * ReaderThemes instance.
     *
     * @var ReaderThemes
     */
    
private $reader_themes;

    
/**
     * RESTPreloader instance.
     *
     * @var RESTPreloader
     */
    
private $rest_preloader;

    
/**
     * OnboardingWizardSubmenuPage constructor.
     *
     * @param GoogleFonts   $google_fonts  An instance of the GoogleFonts service.
     * @param ReaderThemes  $reader_themes An instance of the ReaderThemes class.
     * @param RESTPreloader $rest_preloader An instance of the RESTPreloader class.
     */
    
public function __constructGoogleFonts $google_fontsReaderThemes $reader_themesRESTPreloader $rest_preloader ) {
        
$this->google_fonts   $google_fonts;
        
$this->reader_themes  $reader_themes;
        
$this->rest_preloader $rest_preloader;
    }

    
/**
     * Check whether the conditional object is currently needed.
     *
     * @return bool Whether the conditional object is needed.
     */
    
public static function is_needed() {
        return 
amp_should_use_new_onboarding();
    }

    
/**
     * Get the action to use for registering the service.
     *
     * @return string Registration action to use.
     */
    
public static function get_registration_action() {
        return 
'admin_init';
    }

    
/**
     * Sets up hooks.
     *
     * @since 2.0
     */
    
public function register() {
        
add_action'admin_head-' $this->screen_handle(), [ $this'override_template' ] );
        
add_action'admin_enqueue_scripts', [ $this'enqueue_assets' ] );
        
add_filter'admin_title', [ $this'override_title' ] );
    }

    
/**
     * Overrides the admin title on the wizard screen. Without this filter, the title portion would be empty.
     *
     * @param string $admin_title The unfiltered admin title.
     * @return string If on the wizard screen, the admin title with the page title prepended.
     */
    
public function override_title$admin_title ) {
        if ( 
$this->screen_handle() !== get_current_screen()->id ) {
            return 
$admin_title;
        }

        return 
esc_html__'AMP Onboarding Wizard''amp' ) . $admin_title;
    }

    
/**
     * Renders the setup wizard screen output and exits.
     *
     * @since 2.0
     */
    
public function override_template() {
        
$this->render();

        exit();
    }

    
/**
     * Renders the setup wizard screen output, beginning just before the closing head tag.
     */
    
public function render() {
        
// Remove standard admin footer content.
        
add_filter'admin_footer_text''__return_empty_string' );
        
remove_all_filters'update_footer' );

        
/** This action is documented in wp-admin/admin-header.php */
        
do_action'admin_head' );

        
// <head> tag was opened prior to this action and hasn't been closed.
        
?>
        </head>
        <body>
            <?php // The admin footer template closes three divs. ?>
            <div>
            <div>
            <div>
            <div class="amp" id="<?php echo esc_attr( static::APP_ROOT_ID ); ?>"></div>

            <style>
            #wpfooter { display:none; }
            </style>
        <?php

        
require_once ABSPATH 'wp-admin/admin-footer.php';
    }

    
/**
     * Provides the setup screen handle.
     *
     * @since 2.0
     *
     * @return string
     */
    
public function screen_handle() {
        return 
sprintf'admin_page_%s'OnboardingWizardSubmenu::SCREEN_ID );
    }

    
/**
     * Enqueues setup assets.
     *
     * @since 2.0
     *
     * @param string $hook_suffix The current admin page.
     */
    
public function enqueue_assets$hook_suffix ) {
        if ( 
$this->screen_handle() !== $hook_suffix ) {
            return;
        }

        
/** This action is documented in includes/class-amp-theme-support.php */
        
do_action'amp_register_polyfills' );

        
$amp_slug_customization_watcher Services::get'amp_slug_customization_watcher' );

        
$asset_file   AMP__DIR__ '/assets/js/' self::ASSET_HANDLE '.asset.php';
        
$asset        = require $asset_file;
        
$dependencies $asset['dependencies'];
        
$version      $asset['version'];

        
wp_enqueue_script(
            
self::ASSET_HANDLE,
            
amp_get_asset_url'js/' self::ASSET_HANDLE '.js' ),
            
$dependencies,
            
$version,
            
true
        
);

        
wp_enqueue_style(
            
self::ASSET_HANDLE,
            
amp_get_asset_url'css/amp-onboarding-wizard.css' ),
            [
                
'wp-components',
                
$this->google_fonts->get_handle(),
            ],
            
AMP__VERSION
        
);

        
wp_styles()->add_dataself::ASSET_HANDLE'rtl''replace' );

        
$theme           wp_get_theme();
        
$is_reader_theme $this->reader_themes->theme_data_existsget_stylesheet() );

        
$exit_link menu_page_urlAMP_Options_Manager::OPTION_NAMEfalse );

        
$setup_wizard_data = [
            
'AMP_OPTIONS_KEY'                    => AMP_Options_Manager::OPTION_NAME,
            
'AMP_QUERY_VAR'                      => amp_get_slug(),
            
'DEFAULT_AMP_QUERY_VAR'              => QueryVar::AMP,
            
'AMP_QUERY_VAR_CUSTOMIZED_LATE'      => $amp_slug_customization_watcher->did_customize_late(),
            
'LEGACY_THEME_SLUG'                  => ReaderThemes::DEFAULT_READER_THEME,
            
'APP_ROOT_ID'                        => self::APP_ROOT_ID,
            
'CUSTOMIZER_LINK'                    => add_query_arg(
                [
                    
'return' => rawurlencode$exit_link ),
                ],
                
admin_url'customize.php' )
            ),
            
'CLOSE_LINK'                         => wp_get_referer() ?: $exit_link,
            
// @todo As of June 2020, an upcoming WP release will allow this to be retrieved via REST.
            
'CURRENT_THEME'                      => [
                
'name'            => $theme->get'Name' ),
                
'description'     => $theme->get'Description' ),
                
'is_reader_theme' => $is_reader_theme,
                
'screenshot'      => $theme->get_screenshot() ?: null,
                
'url'             => $theme->get'ThemeURI' ),
            ],
            
'USING_FALLBACK_READER_THEME'        => $this->reader_themes->using_fallback_theme(),
            
'FINISH_LINK'                        => $exit_link,
            
'OPTIONS_REST_PATH'                  => '/amp/v1/options',
            
'READER_THEMES_REST_PATH'            => '/amp/v1/reader-themes',
            
'UPDATES_NONCE'                      => wp_create_nonce'updates' ),
            
'USER_FIELD_DEVELOPER_TOOLS_ENABLED' => UserAccess::USER_FIELD_DEVELOPER_TOOLS_ENABLED,
            
'USER_REST_PATH'                     => '/wp/v2/users/me',
        ];

        
wp_add_inline_script(
            
self::ASSET_HANDLE,
            
sprintf(
                
'var ampSettings = %s;',
                
wp_json_encode$setup_wizard_data )
            ),
            
'before'
        
);

        if ( 
function_exists'wp_set_script_translations' ) ) {
            
wp_set_script_translationsself::ASSET_HANDLE'amp' );
        } elseif ( 
function_exists'wp_get_jed_locale_data' ) || function_exists'gutenberg_get_jed_locale_data' ) ) {
            
$locale_data  function_exists'wp_get_jed_locale_data' ) ? wp_get_jed_locale_data'amp' ) : gutenberg_get_jed_locale_data'amp' );
            
$translations wp_json_encode$locale_data );

            
wp_add_inline_script(
                
self::ASSET_HANDLE,
                
'wp.i18n.setLocaleData( ' $translations ', "amp" );',
                
'after'
            
);
        }

        
$this->add_preload_rest_paths();
    }

    
/**
     * Adds REST paths to preload.
     */
    
protected function add_preload_rest_paths() {
        
$paths = [
            
'/amp/v1/options',
            
'/amp/v1/reader-themes',
            
'/wp/v2/settings',
            
'/wp/v2/users/me',
        ];

        foreach ( 
$paths as $path ) {
            
$this->rest_preloader->add_preloaded_path$path );
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586