Making WordPress.org


Ignore:
Timestamp:
01/10/2014 09:55:09 PM (11 years ago)
Author:
nacin
Message:

Trac: Show a note to contributors when the ticket they are about to comment to was reported by someone new.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications.php

    r265 r267  
    88class wporg_trac_notifications {
    99
     10    protected $trac_subdomain;
     11
    1012    function __construct() {
    1113        $this->set_trac( 'core' );
     
    1618
    1719    function set_trac( $trac ) {
     20        $this->trac_subdomain = $trac;
    1821        if ( function_exists( 'add_db_table' ) ) {
    1922            $tables = array( 'ticket', '_ticket_subs', '_notifications', 'ticket_change', 'component', 'milestone' );
     
    2528    }
    2629
     30    function trac_url() {
     31        return 'https://' . $this->trac_subdomain . '.trac.wordpress.org';
     32    }
     33
    2734    function filter_allowed_http_origins( $origins ) {
    28         $origins[] = 'https://core.trac.wordpress.org';
     35        $origins[] = $this->trac_url();
    2936        return $origins;
     37    }
     38
     39    function ticket_link( $ticket ) {
     40        $status_res = $ticket->status;
     41        if ( $ticket->resolution ) {
     42            $status_res .= ': ' . $ticket->resolution;
     43        }
     44        return sprintf( '<a href="%s" class="%s ticket" title="%s">#%s</a>',
     45            $this->trac_url() . '/ticket/' . $ticket->id,
     46            $ticket->status,
     47            esc_attr( sprintf( "%s: %s (%s)", $ticket->type, $ticket->summary, $status_res ) ),
     48            $ticket->id );
    3049    }
    3150
     
    247266    </div>
    248267    <?php
     268        $this->ticket_notes( $ticket, $username );
    249269        wp_send_json_success( array( 'notifications-box' => ob_get_clean() ) );
    250270        exit;
     271    }
     272
     273    function ticket_notes( $ticket, $username ) {
     274        if ( $username != $ticket->reporter ) {
     275            $previous_tickets = $this->trac->get_results( $this->trac->prepare( "SELECT id, summary, type, status, resolution
     276                FROM ticket WHERE reporter = %s AND id <= %d LIMIT 5", $ticket->reporter, $ticket->id ) );
     277
     278            if ( count( $previous_tickets ) < 5 ) {
     279                $dashicon = '<span class="dashicons dashicons-welcome-learn-more"></span> ';
     280                $dashicon .= '<img width="36" height="36" src="//wordpress.org/grav-redirect.php?user=' . esc_attr( $ticket->reporter ) . '&amp;s=36" /> ';
     281            }
     282
     283            if ( 1 == count( $previous_tickets ) ) {
     284                $previous_comments = $this->trac->get_var( $this->trac->prepare( "SELECT ticket FROM ticket_change
     285                    WHERE field = 'comment' AND author = %s AND ticket <> %d LIMIT 1", $ticket->reporter, $ticket->id ) );
     286
     287                echo '<p class="ticket-note note-new-reporter">' . $dashicon . '<strong>Make sure ' . $ticket->reporter . ' receives a warm welcome</strong> &mdash; ';
     288
     289                if ( $previous_comments ) {
     290                    echo 'they&#8217;ve commented before, but it&#8127;s their first bug report!</p>';
     291                } else {
     292                    echo 'it&#8127;s their first bug report!</p>';
     293                }
     294
     295            } elseif ( count( $previous_tickets ) < 5 ) {
     296                $mapping = array( 2 => 'second', 3 => 'third', 4 => 'fourth' );
     297
     298                echo '<p>' . $dashicon .  '<strong>This is only ' . $ticket->reporter . '&#8217;s ' . $mapping[ count( $previous_tickets ) ] . ' ticket!</strong> Previously:';
     299
     300                foreach ( $previous_tickets as $t ) {
     301                    if ( $t->id != $ticket->id ) {
     302                        echo ' ' . $this->ticket_link( $t );
     303                    }
     304                }
     305                echo '.';
     306            }
     307        }
    251308    }
    252309
Note: See TracChangeset for help on using the changeset viewer.