' . Nodebook_Node::blob( $mood, 56 ) . '

' . esc_html( Nodebook_Node::headline( $items, $name ) ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. if ( $items ) { echo '
    '; foreach ( $items as $i => $item ) { echo '
  1. ' . esc_html( $item['text'] ) . '' . esc_html( $item['action'][0] ) . ''; echo '
    '; wp_nonce_field( 'nodebook_node' ); echo '
  2. '; } echo '
'; } echo ''; } /** Setup as a conversation: one step at a time, with the rest as dots. */ private static function onboarding( $name ) { $steps = Nodebook_Setup::steps(); $done = count( array_filter( wp_list_pluck( $steps, 'done' ) ) ); $next = ''; foreach ( $steps as $key => $s ) { if ( ! $s['done'] ) { $next = $key; break; } } $step = $steps[ $next ]; $intro = Nodebook_Node::introducing(); echo '
' . Nodebook_Node::blob( 'hello', 64 ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. echo '

' . esc_html( Nodebook_Node::setup_line( $next, $done, count( $steps ), $intro, $name ) ) . '

'; echo '
' . esc_html( $step['label'] ) . '

' . esc_html( $step['help'] ) . '

' . ( ! empty( $step['choices'] ) ? '
' . Nodebook_Setup::choices( $step ) . '
' : '' . esc_html( $step['cta'] ) . '' ) . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- choices() escapes its own output. echo '
    '; foreach ( $steps as $key => $s ) { echo '
  1. ' . esc_html( $s['label'] . ( $s['done'] ? ' ' . __( '(done)', 'nodebook' ) : '' ) ) . '
  2. '; } echo '
' . esc_html( /* translators: 1: steps done, 2: total steps */ sprintf( __( '%1$d of %2$d done', 'nodebook' ), $done, count( $steps ) ) ) . '
'; wp_nonce_field( 'nodebook_hide_setup' ); echo '
'; } /** A one-line Node tip on a record's page (contact, deal). */ public static function tip( $tip ) { if ( ! $tip || ! Nodebook_Node::on() ) { return; } echo '
' . Nodebook_Node::blob( $tip['mood'], 32 ) . '

' . esc_html( $tip['text'] ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. if ( ! empty( $tip['action'] ) ) { echo '' . esc_html( $tip['action'][0] ) . ''; } echo '
'; } /** Node speaking in an empty state: blob, a line, and what to do next (buttons). Returns false when Node is off. */ public static function says( $text, $mood = 'hello', array $actions = array() ) { if ( ! Nodebook_Node::on() ) { return false; } echo '
' . Nodebook_Node::blob( $mood, 56 ) . '

' . esc_html( $text ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. if ( $actions ) { echo '

'; $first = true; foreach ( $actions as $label => $url ) { echo '' . esc_html( $label ) . ' '; $first = false; } echo '

'; } echo '
'; return true; } /** * Node in the corner of the other Nodebook screens. Clicking opens a small panel right there: what * Node thinks about the record on screen, today's focus with "Not now", and a way to Today. */ public static function bubble() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- screen detection only. $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; if ( ! Nodebook_Node::on() || in_array( $page, array( 'nodebook-today', '' ), true ) ) { return; } $action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : ''; $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; // phpcs:enable $ctx = ''; if ( 'view' === $action && $id && 'nodebook' === $page ) { $ctx = 'contact'; } elseif ( 'view' === $action && $id && 'nodebook-deals' === $page ) { $ctx = 'deal'; } $n = Nodebook_Node::count(); $label = $n /* translators: %d: number of things */ ? sprintf( _n( 'Node: %d thing deserves your attention', 'Node: %d things deserve your attention', $n, 'nodebook' ), $n ) : __( 'Node: all caught up', 'nodebook' ); echo '
'; echo ''; echo ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. echo '
'; } /** AJAX: the panel's contents for the screen it was opened on. */ public static function panel_ajax() { check_ajax_referer( 'nodebook_node', 'nonce' ); Nodebook_Admin::require_cap(); $ctx = isset( $_POST['ctx'] ) ? sanitize_key( wp_unslash( $_POST['ctx'] ) ) : ''; $id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0; $tip = null; if ( 'contact' === $ctx && $id && Nodebook_Team::can_see( $id ) ) { $c = Nodebook_Contacts::get( $id ); $tip = $c ? Nodebook_Node::contact_tip( $c ) : null; $who = $c ? Nodebook_Contacts::display_name( $c ) : ''; } elseif ( 'deal' === $ctx && $id ) { $d = Nodebook_Deals::get( $id ); $tip = $d && Nodebook_Deals::can_see( $d ) ? Nodebook_Node::deal_tip( $d ) : null; $who = $d ? (string) $d['title'] : ''; } $items = Nodebook_Node::focus(); $name = Nodebook_Node::user_first( get_current_user_id() ); ob_start(); echo '
' . Nodebook_Node::blob( $tip ? $tip['mood'] : Nodebook_Node::mood( $items ), 36 ) . '

' . esc_html( Nodebook_Node::headline( $items, $name ) ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- blob() escapes its own attributes. if ( $tip ) { echo '
' . esc_html( /* translators: %s: contact or deal name */ sprintf( __( 'About %s', 'nodebook' ), $who ) ) . '

' . esc_html( $tip['text'] ) . '

' . esc_html( $tip['action'][0] ) . '
'; } if ( $items ) { echo '
    '; foreach ( $items as $item ) { echo '
  1. ' . esc_html( $item['text'] ) . '

    ' . esc_html( $item['action'][0] ) . '
  2. '; } echo '
'; } echo '

' . esc_html__( 'Open Today', 'nodebook' ) . ' →'; if ( current_user_can( 'manage_options' ) ) { echo '' . esc_html__( 'Node settings', 'nodebook' ) . ''; } echo '

'; wp_send_json_success( array( 'html' => ob_get_clean(), 'count' => count( $items ), ) ); } /** AJAX: "Not now" in the panel. */ public static function dismiss_ajax() { check_ajax_referer( 'nodebook_node', 'nonce' ); Nodebook_Admin::require_cap(); $key = isset( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : ''; if ( '' !== $key ) { Nodebook_Node::dismiss( $key ); } self::panel_ajax(); } }