Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 59
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2/**
3 * WordPress.com Site Helper Private Site Template.
4 *
5 * @package private-site
6 */
7
8namespace Private_Site;
9
10nocache_headers();
11header( 'Content-Type: ' . get_bloginfo( 'html_type' ) . '; charset=' . get_bloginfo( 'charset' ) );
12
13?><!DOCTYPE html>
14<!--[if IE 8]>
15<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
16<![endif]-->
17<!--[if !(IE 8) ]><!-->
18<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
19<!--<![endif]-->
20<head>
21    <script>
22        window.addEventListener('message', function(e) {
23            window.calypso = e.source;
24        })
25    </script>
26    <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
27    <meta name="viewport" content="width=device-width, initial-scale=1">
28    <title><?php bloginfo( 'name' ); ?></title>
29    <?php
30    // Use styles from wp-login.
31    wp_enqueue_style( 'login' );
32    do_action( 'login_enqueue_scripts' );
33    do_action( 'login_head' );
34
35    $classes = array( 'wp-core-ui' );
36    if ( is_rtl() ) {
37        $classes[] = 'rtl';
38    }
39    $classes[] = ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
40
41    $preview_source = site_preview_source();
42    $redirect_to    = $preview_source === 'android-app' ? '/' : set_url_scheme( original_request_url() );
43    $login_link     = site_url() . '/wp-login.php?redirect_to=' . $redirect_to;
44    ?>
45
46</head>
47<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
48<div id="login">
49    <h1><a href="<?php echo esc_url( $login_link ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
50    <div class="message" style="overflow: auto;">
51        <p>
52            <?php if ( $preview_source === 'android-app' ) { ?>
53                <?php
54                    // This text will be only ever displayed to english audience - Android support will land before scaling to
55                    // non-english users
56                ?>
57                This site is private. Private sites cannot be previewed from the app yet. Log in using your web browser to preview the site. <br>
58                <?php $button_text = 'Log in using browser'; ?>
59            <?php } elseif ( is_user_logged_in() ) { ?>
60                <?php esc_html_e( 'This site is private. You need to log in as a user with permissions before previewing it.', 'wpcomsh' ); ?><br>
61                <?php $button_text = 'Switch user'; ?>
62            <?php } else { ?>
63                <?php esc_html_e( 'This site is private. You need to log in to the preview to see it.', 'wpcomsh' ); ?><br>
64                <?php $button_text = 'Log in'; ?>
65            <?php } ?>
66
67            <br>
68            <?php if ( $preview_source === 'browser-iframe' ) { ?>
69                <script>
70                    function handleClick() {
71                        <?php if ( isset( $_GET['calypso_token'] ) ) { /* phpcs:ignore WordPress.Security */ ?>
72                            window.calypso.postMessage(JSON.stringify({
73                                type: 'needs-auth',
74                                channel: "preview-" + <?php echo wp_json_encode( $_GET['calypso_token'], JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); /* phpcs:ignore WordPress.Security */ ?>
75                            }), '*');
76                        <?php } else { ?>
77                            window.location.href = <?php echo wp_json_encode( $login_link, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
78                        <?php } ?>
79                    }
80                </script>
81                <span class="button-primary" onclick="handleClick()">
82                    <?php echo esc_html( $button_text ); ?>
83                </span>
84            <?php } else { ?>
85                <a class="button-primary" href="<?php echo esc_url( $login_link ); ?>">
86                    <?php echo esc_html( $button_text ); ?>
87                </a>
88            <?php } ?>
89        </p>
90    </div>
91    <?php wp_footer(); ?>
92</div>
93</body>
94</html>