$robots Directives. * @return array */ public static function robots( $robots ) { $id = (int) VEFDK_Settings::get( 'page_id' ); if ( $id > 0 && is_page( $id ) && ! self::is_indexable( $id ) ) { $robots['noindex'] = true; $robots['nofollow'] = true; unset( $robots['index'], $robots['follow'] ); } return $robots; } /** * Whether search engines may list the page of the tools. * * Never for a person who is signed in, and never for an address that carries a state of the plugin * (the message shown after a sign-out, for example). For everybody else the answer is no, unless the * webmaster opened the page to everyone: then it is a public page. The documents of the visitors are * never part of it: they are private files, only handed over as attachments that carry "noindex". * * @param int $page_id Page of the tools. * @return bool */ public static function is_indexable( $page_id ) { if ( is_user_logged_in() || self::has_plugin_argument() ) { return false; } /** * Whether search engines may list the page of the tools (a visitor who is not signed in, a plain address). * * @param bool $indexable True when the page is open to everyone. * @param int $page_id Page of the tools. */ return (bool) apply_filters( 'vefdk_page_indexable', VEFDK_REST::is_public(), (int) $page_id ); } /** * Whether the address carries an argument of the plugin (only the names are read). * * @return bool */ private static function has_plugin_argument() { foreach ( array_keys( $_GET ) as $name ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only the names are read, never a value. if ( 0 === strpos( (string) $name, 'vefdk' ) ) { return true; } } return false; } /** * Prints (returns) the page. * * @param string $context "front" or "admin". * @param string $view Screen to open: all (with the tab bar), process, tools, journal, and the ones an extension adds. * @param array $vars Style variables of this one block (already checked, see VEFDK_Views::style_vars()). * @return string */ public static function render( $context, $view, $vars = array() ) { if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- constant read by the page-cache plugins. } $public = VEFDK_REST::is_public(); $style = ''; foreach ( $vars as $name => $value ) { $style .= $name . ':' . $value . ';'; } $style = '' !== $style ? ' style="' . esc_attr( $style ) . '"' : ''; if ( 'front' === $context && ! is_user_logged_in() && ! $public ) { return self::login_panel( $style ); } if ( 'front' === $context && is_user_logged_in() && ! VEFDK_REST::can_use() ) { return self::panel( '

' . esc_html__( 'Your account cannot use this page. Ask the administrator of the site to give you access.', 'vefdocskit' ) . '

' . '

' . esc_html__( 'Sign out', 'vefdocskit' ) . '

', $style ); } self::enqueue( $context ); $logout = ( 'front' === $context && is_user_logged_in() ) ? wp_logout_url( VEFDK_Accounts::front_url() ) : ''; return '
' . '

' . esc_html__( 'Loading…', 'vefdocskit' ) . '

' . '' . '
'; } /** * Loads the style and the script of the page. * * @param string $context "front" or "admin". * @return void */ public static function enqueue( $context ) { static $done = array(); if ( isset( $done[ $context ] ) ) { return; } $done[ $context ] = true; self::enqueue_style( $context ); wp_enqueue_script( 'vefdk-app', VEFDK_PLUGIN_URL . 'assets/js/app.js', array( 'wp-i18n' ), VEFDK_VERSION, true ); wp_set_script_translations( 'vefdk-app', 'vefdocskit' ); // The other screens register themselves on the object that app.js creates. wp_enqueue_script( 'vefdk-tools', VEFDK_PLUGIN_URL . 'assets/js/tools.js', array( 'vefdk-app', 'wp-i18n' ), VEFDK_VERSION, true ); wp_set_script_translations( 'vefdk-tools', 'vefdocskit' ); /** * The page is about to be shown: an extension loads its own scripts (they depend on 'vefdk-app'). * * @param string $context "front" or "admin". */ do_action( 'vefdk_enqueue_app', $context ); wp_add_inline_script( 'vefdk-app', 'window.vefdkConfig = ' . wp_json_encode( array( 'rest' => esc_url_raw( rest_url( VEFDK_REST::NS ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'context' => $context, 'follow' => 'front' === $context ? self::follows_site() : array(), 'accept' => '.pdf,.jpg,.jpeg,.png,application/pdf,image/jpeg,image/png', ) ) . ';', 'before' ); } /** * Loads the stylesheet, with the variables the webmaster set in the Style tab. The style * belongs to the page of the users: the screens of the administration never take it. * * @param string $context "front" or "admin". * @return void */ public static function enqueue_style( $context = 'front' ) { wp_enqueue_style( 'vefdk-app', VEFDK_PLUGIN_URL . 'assets/css/app.css', array(), VEFDK_VERSION ); $vars = ''; if ( 'front' !== $context ) { return; } foreach ( VEFDK_Settings::style_variables() as $name => $value ) { $vars .= $name . ':' . $value . ';'; } if ( '' !== $vars ) { wp_add_inline_style( 'vefdk-app', '.vefdk-app,.vefdk-panel{' . $vars . '}' ); } } /** * Whether the look should be read from the site (nothing was set in the Style tab). * * @return array For each readable value, whether the webmaster left it empty. */ private static function follows_site() { $style = VEFDK_Settings::get( 'style' ); return array( 'accent' => '' === $style['accent'], 'text' => '' === $style['text'], 'radius' => '' === $style['radius'], ); } /** * The sign-in panel shown to a visitor when the page is for account holders. * * @param string $style Style attribute of this one block (empty, or ' style="..."'). * @return string */ private static function login_panel( $style ) { self::enqueue_style(); $form = wp_login_form( array( 'echo' => false, 'redirect' => VEFDK_Accounts::front_url(), 'form_id' => 'vefdk-login', 'label_username' => __( 'E-mail address or username', 'vefdocskit' ), 'label_log_in' => __( 'Sign in', 'vefdocskit' ), ) ); $lost = '

' . esc_html__( 'Forgot your password?', 'vefdocskit' ) . '

'; /** * Lets an extension add a line under the sign-in form (for example a link to create an account). The HTML * is printed as it is: the extension escapes it. * * @param string $html Extra HTML, empty by default. */ $lost .= (string) apply_filters( 'vefdk_login_panel_extra', '' ); $bye = ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only picks a fixed text. if ( isset( $_GET['vefdk_bye'] ) && VEFDK_Accounts::purges_on_logout() ) { $bye = '

' . esc_html__( 'You are signed out. Your documents were deleted from the server.', 'vefdocskit' ) . '

'; } return self::panel( $bye . '

' . esc_html__( 'Sign in', 'vefdocskit' ) . '

' . esc_html__( 'This page is for the people who received an account. Sign in to handle your documents.', 'vefdocskit' ) . '

' . $form . $lost, $style ); } /** * A framed message. * * @param string $html Contents (already escaped). * @param string $style Style attribute of this one block (empty, or ' style="..."'). * @return string */ private static function panel( $html, $style = '' ) { return '
' . $html . '
'; } }