Plugin::now() ) ); } public static function reply_to_visitor( array $conv, array $msg, $operator_name ) { if ( ! is_email( $conv['visitor_email'] ) ) { return false; } $seen = $conv['visitor_seen_at'] ? ( time() - strtotime( $conv['visitor_seen_at'] . ' UTC' ) ) : 9999; if ( $seen < 90 ) { return false; } // still on the page: they see it in the widget $site = Options::get( 'business' ); /* translators: %s: the operator's name */ $subject = sprintf( __( 'Reply from %s', 'chatdozo' ), $site ); $back = $conv['page_url'] ? $conv['page_url'] : home_url( '/' ); $body = $msg['body']; /* translators: %s: the file name */ if ( $msg['attachment'] ) { $body .= ( $body ? "\n" : '' ) . sprintf( __( 'Attachment: %s', 'chatdozo' ), $msg['attachment'] ); } $lines = array( /* translators: 1: operator's name, 2: site name */ sprintf( __( '%1$s from %2$s replied to your message:', 'chatdozo' ), $operator_name, $site ), '', ' ' . wp_strip_all_tags( $body ), '', __( 'To carry on the conversation, open the chat again here:', 'chatdozo' ), $back, ); $ok = wp_mail( $conv['visitor_email'], $subject, implode( "\n", $lines ) ); if ( $ok ) { Store::mark_emailed( $msg['id'] ); } return (bool) $ok; } /** The conversation as plain text. $notes = include private notes (operators' export only). */ public static function transcript_text( array $conv, $notes = false ) { $site = Options::get( 'business' ); $who = $conv['visitor_name'] !== '' ? $conv['visitor_name'] : __( 'Visitor', 'chatdozo' ); /* translators: 1: visitor's name, 2: site name */ $lines = array( sprintf( __( 'Chat with %1$s · %2$s', 'chatdozo' ), $site, wp_date( get_option( 'date_format' ), strtotime( $conv['created_at'] . ' UTC' ) ) ), '' ); foreach ( Store::messages( $conv['id'], 0, 2000, ! $notes ) as $m ) { $when = wp_date( get_option( 'time_format' ), strtotime( $m['created_at'] . ' UTC' ) ); if ( $m['sender'] === 'visitor' ) { $name = $who; } elseif ( $m['sender'] === 'note' ) { $name = __( 'Note', 'chatdozo' ); } elseif ( $m['sender'] === 'operator' ) { $u = get_user_by( 'id', (int) $m['user_id'] ); $name = $u ? Util::op_name( $u->ID ) : $site; } else { $name = (string) apply_filters( 'chatdozo_sender_name', $site, $m ); } // system lines, and whatever the Pro edition writes (its assistant, its automatic lines) $text = $m['body']; if ( $m['attachment'] ) { $text .= ( $text ? ' ' : '' ) . '[' . ( $m['attachment_name'] ?: $m['attachment_type'] ) . '] ' . $m['attachment']; } $lines[] = "[$when] $name: $text"; } return implode( "\n", $lines ) . "\n"; } public static function transcript( array $conv ) { if ( ! is_email( $conv['visitor_email'] ) ) { return false; } $site = Options::get( 'business' ); /* translators: %s: site name */ $ok = wp_mail( $conv['visitor_email'], sprintf( __( 'Your chat with %s', 'chatdozo' ), $site ), self::transcript_text( $conv, false ) ); if ( $ok ) { Store::update( $conv['id'], array( 'transcript_at' => Plugin::now() ) ); } return (bool) $ok; } }