<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[11726] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Admin: Stats: Retrieve email stats from Help Scout.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/11726">11726</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/11726","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-03-31 08:55:05 +0000 (Thu, 31 Mar 2022)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Admin: Stats: Retrieve email stats from Help Scout.

See <a href="http://meta.trac.wordpress.org/ticket/4306">#4306</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadmintoolsclassstatsreportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/tools/class-stats-report.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclientsclasshelpscoutphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-helpscout.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadmintoolsclassstatsreportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/tools/class-stats-report.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/tools/class-stats-report.php      2022-03-31 01:49:59 UTC (rev 11725)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/tools/class-stats-report.php        2022-03-31 08:55:05 UTC (rev 11726)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\Admin\Tools;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Template;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Clients\HelpScout;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * All functionality related to Stats_Report Tool.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -52,26 +53,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array {
</span><span class="cx" style="display: block; padding: 0 10px">         *     Array of stats.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         *     @type int $plugin_approve                     The number of plugins approved within the defined time interval.
-        *     @type int $plugin_delist                      The number of plugins delisted within the defined time interval.
-        *     @type int $plugin_new                         The number of plugins submitted within the defined time interval.
-        *     @type int $plugin_reject                      The number of plugins rejected within the defined time interval.
-        *     @type int $in_queue                           The number of plugins currently in the queue (new or pending).
-        *     @type int $in_queue_new                       The number of new plugins currently in the queue.
-        *     @type int $in_queue_pending                   The number of pending plugins currently in the queue.
-        *     @type int $in_queue_from_time_window          The number of plugins currently in the queue submitted during the specified time window.
-        *     @type int $in_queue_old                       The number of plugins currently in the queue that are older than "recently".
-        *     @type int $supportpress_queue_total_open      The number of currently open support threads.
-        *     @type int $supportpress_queue_total_open_old  The number of currently open support threads with no activity "recently".
-        *     @type int $supportpress_queue_interval_all    The number of threads (from just within the specified time window).
-        *     @type int $supportpress_queue_interval_closed The number of closed threads (from just withing the specified time window).
-        *     @type int $supportpress_queue_interval_open   The number of open threads (from just withing the specified time window).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  *     @type int $plugin_approve                        The number of plugins approved within the defined time interval.
+        *     @type int $plugin_delist                         The number of plugins delisted within the defined time interval.
+        *     @type int $plugin_new                            The number of plugins submitted within the defined time interval.
+        *     @type int $plugin_reject                         The number of plugins rejected within the defined time interval.
+        *     @type int $in_queue                              The number of plugins currently in the queue (new or pending).
+        *     @type int $in_queue_new                          The number of new plugins currently in the queue.
+        *     @type int $in_queue_pending                      The number of pending plugins currently in the queue.
+        *     @type int $in_queue_from_time_window             The number of plugins currently in the queue submitted during the specified time window.
+        *     @type int $in_queue_old                          The number of plugins currently in the queue that are older than "recently".
+        *     @type int $helpscout_queue_total_conversations   The number of ongoing Help Scout conversations.
+        *     @type int $helpscout_queue_new_conversations     The number of new Help Scout conversations.
+        *     @type int $helpscout_queue_customers             The number of unique Plugin authors contacted.
+        *     @type int $helpscout_queue_conversations_per_day The number of Help Scout conversations per day.
+        *     @type int $helpscout_queue_busiest_day           The busiest day in the Help Scout queue.
+        *     @type int $helpscout_queue_messages_received     The number of emails received in HelpScout.
+        *     @type int $helpscout_queue_replies_sent          The number of replies sent to emails.
+        *     @type int $helpscout_queue_emails_created        The number of new outgoing conversations created.
</ins><span class="cx" style="display: block; padding: 0 10px">          * }
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function get_stats( $args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $stats['as_of_date'] = strftime( '%Y-%m-%d', time() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $stats['as_of_date'] = gmdate( 'Y-m-d' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $defaults = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'date'       => $stats['as_of_date'],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -150,38 +154,30 @@
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // --------------
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // SupportPress Queue
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Help Scout Queue
</ins><span class="cx" style="display: block; padding: 0 10px">                 // --------------
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // # of currently open threads
-               $stats['supportpress_queue_total_open'] = $wpdb->get_var(
-                       "SELECT COUNT(*) FROM plugins_support_threads WHERE state = 'open'"
-               );
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // # of currently open threads with no activity in last 7 days
-               $stats['supportpress_queue_total_open_old'] = $wpdb->get_var( $wpdb->prepare(
-                       "SELECT COUNT(*) FROM plugins_support_threads WHERE state = 'open' AND dt < DATE_SUB( NOW(), INTERVAL %d DAY )",
-                       $args['recentdays']
-               ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $start_datetime = gmdate( 'Y-m-d\T00:00:00\Z', strtotime( $args['date'] ) - ( $args['num_days'] * DAY_IN_SECONDS ) );
+               $end_datetime   = gmdate( 'Y-m-d\T23:59:59\Z', strtotime( $args['date'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // # of total threads (from just those received during the time window)
-               $stats['supportpress_queue_interval_all'] = $wpdb->get_var( $wpdb->prepare(
-                       "SELECT COUNT(*) FROM plugins_support_threads WHERE state IN ( 'closed', 'open' ) AND dt < %s AND dt > DATE_SUB( %s, INTERVAL %d DAY )",
-                       $args['date'],
-                       $args['date'],
-                       absint( $args['num_days'] ) + 1
-               ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $api_payload = [
+                       'start'     => $start_datetime,
+                       'end'       => $end_datetime,
+                       'mailboxes' => HELPSCOUT_PLUGINS_MAILBOXID,
+               ];
+               
+               $company_report  = HelpScout::api( '/v2/reports/company', $api_payload );
+               $mailbox_overall = HelpScout::api( '/v2/reports/conversations', $api_payload );
+               $email_report    = HelpScout::api( '/v2/reports/email', $api_payload );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // # of open and closed threads (from just those received during the time window)
-               $sp_states = array( 'closed', 'open' );
-               foreach ( $sp_states as $sp_state ) {
-                       $stats[ 'supportpress_queue_interval_' . $sp_state ] = $wpdb->get_var( $wpdb->prepare(
-                               'SELECT COUNT(*) FROM plugins_support_threads WHERE state = %s AND dt < %s AND dt > DATE_SUB( %s, INTERVAL %d DAY )',
-                               $sp_state,
-                               $args['date'],
-                               $args['date'],
-                               absint( $args['num_days'] ) + 1
-                       ) );
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $stats['helpscout_queue_total_conversations']     = $mailbox_overall->current->totalConversations ?? 0;
+               $stats['helpscout_queue_new_conversations']       = $mailbox_overall->current->newConversations ?? 0;
+               $stats['helpscout_queue_customers']               = $mailbox_overall->current->customers ?? 0;
+               $stats['helpscout_queue_conversations_per_day']   = $mailbox_overall->current->conversationsPerDay ?? 0;
+               $stats['helpscout_queue_busiest_day']             = gmdate( 'l', strtotime( 'Sunday +' . $mailbox_overall->busiestDay->day . ' days' ) ); // Hacky? but works
+               $stats['helpscout_queue_messages_received']       = $mailbox_overall->current->messagesReceived ?? 0;
+               $stats['helpscout_queue_replies_sent']            = $company_report->current->totalReplies;
+               $stats['helpscout_queue_emails_created']          = $email_report->current->volume->emailsCreated ?? 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $stats;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -197,27 +193,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $args = array();
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( isset( $_POST['date'] ) && preg_match( '/[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/', $_POST['date'] ) ) {
-                       $args['date'] = $_POST['date'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( isset( $_REQUEST['date'] ) && preg_match( '/[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/', $_REQUEST['date'] ) ) {
+                       $args['date'] = $_REQUEST['date'];
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $args['date'] = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $args['date'] = gmdate( 'Y-m-d' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $args['num_days']   = empty( $_POST['days'] ) ? '' : absint( $_POST['days'] );
-               $args['recentdays'] = empty( $_POST['recentdays'] ) ? '' : absint( $_POST['recentdays'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $args['num_days']   = empty( $_REQUEST['days'] ) ? 7 : absint( $_REQUEST['days'] );
+               $args['recentdays'] = empty( $_REQUEST['recentdays'] ) ? 7 : absint( $_REQUEST['recentdays'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $stats = $this->get_stats( $args );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $date = strftime( '%Y-%m-%d', time() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $date = gmdate( 'Y-m-d' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $start_date = date( 'Y-m-d', strtotime( "-{$stats['num_days']} days", strtotime( $stats['date'] ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $start_date = gmdate( 'Y-m-d', strtotime( "-{$stats['num_days']} days", strtotime( $stats['date'] ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <div class="wrap stats-report">
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                <h1><?php _e( 'Plugin Repository and SupportPress Stats Report', 'wporg-plugins' ); ?></h1>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         <h1><?php _e( 'Plugin Repository and email Stats Report', 'wporg-plugins' ); ?></h1>
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                <form method="post">
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         <form method="get">
+               <input type="hidden" name="action" value="<?php echo esc_attr( $_REQUEST['action'] ); ?>"/>
</ins><span class="cx" style="display: block; padding: 0 10px">                 <table class="form-table"><tbody>
</span><span class="cx" style="display: block; padding: 0 10px">                <tr><th scope="row"><label for="date"><?php _e( 'Date', 'wporg-plugins' ); ?></label></th><td>
</span><span class="cx" style="display: block; padding: 0 10px">                <input name="date" type="text" id="date" value="<?php echo esc_attr( $args['date'] ); ?>" class="text">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -379,66 +376,73 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        </li>
</span><span class="cx" style="display: block; padding: 0 10px">                </ul>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                <h3><?php _e( 'SupportPress Queue Stats', 'wporg-plugins' ); ?></h3>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         <h3><?php _e( 'Help Scout Queue Stats', 'wporg-plugins' ); ?></h3>
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <ul style="font-family:Courier New;">
</span><span class="cx" style="display: block; padding: 0 10px">                        <li>
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                /* translators: %d: number of open tickets */
</del><span class="cx" style="display: block; padding: 0 10px">                                 printf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        __( 'Total open tickets* : %d', 'wporg-plugins' ),
-                                       esc_html( $stats['supportpress_queue_total_open'] )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'Total Conversations: %d',
+                                       esc_html( $stats['helpscout_queue_total_conversations'] )
</ins><span class="cx" style="display: block; padding: 0 10px">                                 );
</span><span class="cx" style="display: block; padding: 0 10px">                        ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        </li>
</span><span class="cx" style="display: block; padding: 0 10px">                        <li>
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                /* translators: 1: number of most recent days, 2: number of plugins with no activity */
</del><span class="cx" style="display: block; padding: 0 10px">                                 printf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        __( ' &rarr; (with no activity in last %1$d days)** : %2$d', 'wporg-plugins' ),
-                                       esc_html( $stats['recentdays'] ),
-                                       esc_html( $stats['supportpress_queue_total_open_old'] )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'New Conversations: %d',
+                                       esc_html( $stats['helpscout_queue_new_conversations'] )
</ins><span class="cx" style="display: block; padding: 0 10px">                                 );
</span><span class="cx" style="display: block; padding: 0 10px">                        ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        </li>
</span><span class="cx" style="display: block; padding: 0 10px">                        <li>
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                /* translators: %d: number of most recent days */
</del><span class="cx" style="display: block; padding: 0 10px">                                 printf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        __( 'Within defined %d day time window:', 'wporg-plugins' ),
-                                       esc_html( $stats['num_days'] )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'Customers: %d',
+                                       esc_html( $stats['helpscout_queue_customers'] )
</ins><span class="cx" style="display: block; padding: 0 10px">                                 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                ?>
-                               <ul style="margin-left:20px;margin-top:0.5em;">
-                                       <li>
-                                       <?php
-                                               /* translators: %d: total number of plugins within defined time window */
-                                               printf(
-                                                       __( 'Total : %d', 'wporg-plugins' ),
-                                                       esc_html( $stats['supportpress_queue_interval_all'] )
-                                               );
-                                       ?>
-                                       </li>
-                                       <li>
-                                       <?php
-                                               /* translators: %d: number of closed plugins within defined time window */
-                                               printf(
-                                                       __( 'Closed : %d', 'wporg-plugins' ),
-                                                       esc_html( $stats['supportpress_queue_interval_closed'] )
-                                               );
-                                       ?>
-                                       </li>
-                                       <li>
-                                       <?php
-                                               /* translators: %d: number of open plugins within defined time window */
-                                               printf(
-                                                       __( 'Open : %d', 'wporg-plugins' ),
-                                                       esc_html( $stats['supportpress_queue_interval_open'] )
-                                               );
-                                       ?>
-                                       </li>
-                               </ul>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 ?>
</ins><span class="cx" style="display: block; padding: 0 10px">                         </li>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        <li>
+                       <?php
+                               printf(
+                                       'Conversations per Day: %d',
+                                       esc_html( $stats['helpscout_queue_conversations_per_day'] )
+                               );
+                       ?>
+                       </li>
+                       <li>
+                       <?php
+                               printf(
+                                       'Busiest Day: %s',
+                                       esc_html( $stats['helpscout_queue_busiest_day'] )
+                               );
+                       ?>
+                       </li>
+                       <li>
+                       <?php
+                               printf(
+                                       'Messages Received: %d',
+                                       esc_html( $stats['helpscout_queue_messages_received'] )
+                               );
+                       ?>
+                       </li>
+                       <li>
+                       <?php
+                               printf(
+                                       'Replies Sent: %d',
+                                       esc_html( $stats['helpscout_queue_replies_sent'] )
+                               );
+                       ?>
+                       </li>
+                       <li>
+                       <?php
+                               printf(
+                                       'Emails Created: %d',
+                                       esc_html( $stats['helpscout_queue_emails_created'] )
+                               );
+                       ?>
+                       </li>
</ins><span class="cx" style="display: block; padding: 0 10px">                 </ul>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <ul style="font-style:italic;">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclientsclasshelpscoutphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-helpscout.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-helpscout.php                             (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-helpscout.php       2022-03-31 08:55:05 UTC (rev 11726)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,77 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Clients;
+
+/**
+ * Simple HelpScout client.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Clients
+ */
+class HelpScout {
+       const API_BASE = 'https://api.helpscout.net';
+
+       public static function api( $url, $args = null, $method = 'GET' ) {
+               // Verify the configuration variables are available.
+               if ( ! defined( 'HELPSCOUT_APP_ID' ) || ! defined( 'HELPSCOUT_APP_SECRET' ) ) {
+                       return false;
+               }
+
+               // Prepend API URL host-less URLs
+               if ( ! str_starts_with( $url, self::API_BASE ) ) {
+                       $url = self::API_BASE . '/' . ltrim( $url, '/' );
+               }
+
+               if ( 'GET' === $method && $args ) {
+                       $url = add_query_arg( $args, $url );
+               }
+
+               $request = wp_remote_request(
+                       $url,
+                       array(
+                               'method'  => $method,
+                               'headers' => [
+                                       'Accept'        => 'application/json',
+                                       'Authorization' => self::get_auth_string(),
+                               ],
+                               'body'    => ( 'POST' === $method && $args ) ? $args : null,
+                       )
+               );
+
+               return json_decode( wp_remote_retrieve_body( $request ) );
+       }
+
+       /**
+        * Fetch an Authorization token for accessing HelpScout Resources.
+        */
+       protected static function get_auth_string() {
+               $token = get_site_transient( __CLASS__ . 'get_auth_token' );
+               if ( $token && is_array( $token ) && $token['exp'] > time() ) {
+                       return 'BEARER ' . $token['token'];
+               }
+
+               $request = wp_remote_post(
+                       self::API_BASE . '/v2/oauth2/token',
+                       array(
+                               'body' => array(
+                                       'grant_type'    => 'client_credentials',
+                                       'client_id'     => HELPSCOUT_APP_ID,
+                                       'client_secret' => HELPSCOUT_APP_SECRET
+                               )
+                       )
+               );
+
+               $response = is_wp_error( $request ) ? false : json_decode( wp_remote_retrieve_body( $request ) );
+
+               if ( ! $response || empty( $response->access_token ) ) {
+                       return false;
+               }
+
+               // Cache the token for 1 minute less than what it's valid for.
+               $token  = $response->access_token;
+               $expiry = $response->expires_in - MINUTE_IN_SECONDS;
+
+               set_site_transient( __CLASS__ . 'get_auth_token', [ 'exp' => time() + $expiry, 'token' => $token ], $expiry );
+
+               return $token;
+       }
+
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-helpscout.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>

</body>
</html>