ai_topics ?? '' ) ), 'strlen' ) ); } /** * Marks for urgent leads, orders, job applications and likely spam. * * @param object $lead Lead. * @return string HTML. */ public static function marks( $lead ) { $marks = array(); if ( ! empty( $lead->ai_urgent ) && in_array( $lead->status, array( 'new', 'contacted' ), true ) ) { $marks[] = '' . esc_html__( 'Urgent', 'dealroot' ) . ''; } $kinds = array( 'order' => __( 'Order', 'dealroot' ), 'job' => __( 'Job application', 'dealroot' ), 'spam' => __( 'Looks like spam', 'dealroot' ), ); $kind = (string) ( $lead->ai_kind ?? '' ); if ( isset( $kinds[ $kind ] ) && ( 'spam' !== $kind || 'spam' !== $lead->status ) ) { $marks[] = '' . esc_html( $kinds[ $kind ] ) . ''; } if ( '' !== (string) ( $lead->privacy_request ?? '' ) ) { $marks[] = '' . esc_html__( 'Personal data', 'dealroot' ) . ''; } if ( ! empty( $lead->ai_abusive ) ) { $marks[] = '' . esc_html__( 'Insulting', 'dealroot' ) . ''; } return implode( '', $marks ); } /** * The summary above the fields of a lead. * * @param object $lead Lead. */ public static function summary( $lead ) { $state = (string) ( $lead->ai_state ?? '' ); if ( 'done' === $state && '' !== (string) $lead->ai_summary ) { ?>
ai_summary ); ?>
'; echo wp_kses( $marks, Kses::screen() ); foreach ( $topics as $topic ) { echo '' . esc_html( $topic ) . ''; } echo ''; } self::confirmation( $lead ); if ( 'spam' === $lead->status && 'spam' === (string) $lead->ai_kind ) { echo '' . esc_html__( 'The AI assistant moved this enquiry to spam. If it is a real one, set its status back.', 'dealroot' ) . '
'; } ?>' . esc_html__( 'The AI assistant is reading the enquiry…', 'dealroot' ) . '
'; } } /** * Budget, date, quantity and place the assistant read in the enquiry. * * @param object $lead Lead. */ private static function facts( $lead ) { $facts = array(); if ( null !== ( $lead->ai_budget ?? null ) && '' !== (string) $lead->ai_budget ) { $facts[ __( 'Budget', 'dealroot' ) ] = Format::money( (float) $lead->ai_budget, (string) $lead->ai_currency ); } $labels = array( 'when' => __( 'When', 'dealroot' ), 'quantity' => __( 'How many', 'dealroot' ), 'place' => __( 'Where', 'dealroot' ), ); foreach ( Ai::details( $lead ) as $key => $value ) { if ( isset( $labels[ $key ] ) ) { $facts[ $labels[ $key ] ] = $value; } } if ( ! $facts ) { return; } echo 'array() ) ); ?>
' . esc_html( Ai::abusive_note() ) . '
'; return; } ?>__( 'This lead was deleted, or the link is not complete.', 'dealroot' ) ), 404 ); } $draft = Ai::draft( $lead, isset( $_POST['hint'] ) ? sanitize_text_field( wp_unslash( $_POST['hint'] ) ) : '' ); if ( is_wp_error( $draft ) ) { wp_send_json_error( array( 'message' => $draft->get_error_message() ) ); } wp_send_json_success( array( 'draft' => $draft ) ); } /** * A ticket for writing the draft word by word in the browser. */ public function ajax_ticket() { check_ajax_referer( 'dealroot_ai_draft', 'nonce' ); if ( ! current_user_can( Admin::capability() ) ) { wp_send_json_error( null, 403 ); } $lead = Leads::get( isset( $_POST['lead'] ) ? absint( $_POST['lead'] ) : 0 ); if ( ! $lead ) { wp_send_json_error( array( 'message' => __( 'This lead was deleted, or the link is not complete.', 'dealroot' ) ), 404 ); } $ticket = Ai::ticket( $lead, isset( $_POST['hint'] ) ? sanitize_text_field( wp_unslash( $_POST['hint'] ) ) : '' ); if ( is_wp_error( $ticket ) ) { wp_send_json_error( array( 'message' => $ticket->get_error_message() ) ); } wp_send_json_success( $ticket ); } /** * What customers ask for in a period: the topics with their leads, customers and revenue. * * @param string $period Period key. */ public static function topics_panel( $period ) { list( $from, $to ) = Reports::range( $period ); $topics = Ai::topics( $from, $to ); if ( count( $topics ) < 2 ) { return; } $max = max( wp_list_pluck( $topics, 'leads' ) ); ?>
%1$s: %2$s enquiry asked about it, but no page of your site mentions it. A page or a few questions and answers would help visitors decide before they write.', '%1$s: %2$s enquiries asked about it, but no page of your site mentions it. A page or a few questions and answers would help visitors decide before they write.', (int) $idea['leads'], 'dealroot' ), esc_html( $idea['topic'] ), esc_html( number_format_i18n( (int) $idea['leads'] ) ) ), array( 'strong' => array() ) ); ?>
>