Making WordPress.org

Changeset 373


Ignore:
Timestamp:
02/05/2014 08:52:43 AM (11 years ago)
Author:
nacin
Message:

Trac Notifications: Updates to the preferences form for focuses, new tickets, and subcomponents. see #127, #287, #300.

File:
1 edited

Legend:

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

    r322 r373  
    3434        $this->trac_subdomain = $trac;
    3535        if ( function_exists( 'add_db_table' ) ) {
    36             $tables = array( 'ticket', '_ticket_subs', '_notifications', 'ticket_change', 'component', 'milestone' );
     36            $tables = array( 'ticket', '_ticket_subs', '_notifications', 'ticket_change', 'component', 'milestone', 'ticket_custom' );
    3737            foreach ( $tables as $table ) {
    3838                add_db_table( 'trac_' . $trac, $table );
     
    8080    }
    8181
     82    function get_trac_ticket_focuses( $ticket_id ) {
     83        return $this->trac->get_var( $this->trac->prepare( "SELECT value FROM ticket_custom WHERE ticket = %d AND name = 'focuses'", $ticket_id ) );
     84    }
     85
    8286    function get_trac_ticket_participants( $ticket_id ) {
    8387        return $this->trac->get_col( $this->trac->prepare( "SELECT DISTINCT author FROM ticket_change WHERE ticket = %d", $ticket_id ) );
     
    8892    }
    8993
     94    function get_trac_focuses() {
     95        return array( 'accessibility', 'administration', 'docs', 'javascript', 'multisite', 'performance', 'rtl', 'template', 'ui' );
     96    }
     97
     98    function make_components_tree( $components ) {
     99        $tree = array();
     100        $subcomponents = array(
     101            'Comments' => array( 'Pings/Trackbacks' ),
     102            'Editor' => array( 'Autosave', 'Press This', 'Quick/Bulk Edit', 'TinyMCE' ),
     103            'Formatting' => array( 'Charset', 'Shortcodes' ),
     104            'Media' => array( 'Embeds', 'Gallery', 'Upload' ),
     105            'Permalinks' => array( 'Canonical', 'Rewrite Rules' ),
     106            'Posts, Post Types' => array( 'Post Formats', 'Post Thumbnails', 'Revisions' ),
     107            'Themes' => array( 'Appearance', 'Widgets', 'Menus' ),
     108            'Users' => array( 'Role/Capability', 'Login and Registration' )
     109        );
     110        foreach ( $components as $component ) {
     111            if ( false === $tree[ $component ] ) {
     112                continue;
     113            } elseif ( isset( $subcomponents[ $component ] ) ) {
     114                $tree[ $component ] = $subcomponents[ $component ];
     115                foreach ( $subcomponents[ $component ] as $subcomponent ) {
     116                    $tree[ $subcomponent ] = false;
     117                }
     118            } else {
     119                $tree[ $component ] = true;
     120            }
     121        }
     122        $tree = array_filter( $tree );
     123        return $tree;
     124    }
     125
    90126    function get_trac_components() {
    91         return $this->trac->get_col( "SELECT name FROM component ORDER BY name ASC" );
     127        return $this->trac->get_col( "SELECT name FROM component WHERE name <> 'WordPress.org site' ORDER BY name ASC" );
    92128    }
    93129
     
    101137    function get_trac_notifications_for_user( $username ) {
    102138        $rows = $this->trac->get_results( $this->trac->prepare( "SELECT type, value FROM _notifications WHERE username = %s ORDER BY type ASC, value ASC", $username ) );
    103         $notifications = array( 'component' => array(), 'milestone' => array() );
     139        $notifications = array( 'component' => array(), 'milestone' => array(), 'focus' => array(), 'newticket' => array() );
    104140
    105141        foreach ( $rows as $row ) {
    106142            $notifications[ $row->type ][ $row->value ] = true;
    107143        }
     144        $notifications['newticket'] = ! empty( $notifications['newticket']['1'] );
     145
    108146        return $notifications;
    109147    }
     
    206244        }
    207245
     246        $focuses = explode( ', ', $this->get_trac_ticket_focuses( $ticket_id ) );
     247
    208248        $notifications = $this->get_trac_notifications_for_user( $username );
    209249
     
    226266            $reasons['participant'] = 'you have commented';
    227267        }
     268
     269        $intersected_focuses = array();
     270        foreach ( $focuses as $focus ) {
     271            if ( ! empty( $notifications['focus'][ $focus ] ) ) {
     272                $intersected_focuses[] = $focus;
     273            }
     274        }
     275        if ( $intersected_focuses ) {
     276            if ( count( $intersected_focuses ) === 1 ) {
     277                $reasons['focus'] = sprintf( 'you subscribe to the %s focus', $intersected_focuses[0] );
     278            } else {
     279                $reasons['focus'] = 'you subscribe to the ' . wp_sprintf( '%l focuses', $intersected_focuses );
     280            }
     281        }
     282
    228283        if ( ! empty( $notifications['component'][ $ticket->component ] ) ) {
    229284            $reasons['component'] = sprintf( 'you subscribe to the %s component', $ticket->component );
     
    334389    function notification_settings_page() {
    335390        if ( ! is_user_logged_in() ) {
    336             return 'Please log in to save your notification preferences.';
     391            return 'Please <a href="//wordpress.org/support/bb-login.php">log in</a> to save your notification preferences.';
    337392        }
    338393
     
    340395        $components = $this->get_trac_components();
    341396        $milestones = $this->get_trac_milestones();
     397        $focuses = $this->get_trac_focuses();
    342398
    343399        $username = wp_get_current_user()->user_login;
     
    347403            check_admin_referer( 'save-trac-notifications', 'trac-nonce' );
    348404
    349             foreach ( array( 'milestone', 'component' ) as $type ) {
    350                 foreach ( $_POST[ $type ] as $value => $on ) {
     405            foreach ( array( 'milestone', 'component', 'focus' ) as $type ) {
     406                foreach ( $_POST['notifications'][ $type ] as $value => $on ) {
    351407                    if ( empty( $notifications[ $type ][ $value ] ) ) {
    352408                        $this->trac->insert( '_notifications', compact( 'username', 'type', 'value' ) );
     
    356412
    357413                foreach ( $notifications[ $type ] as $value => $on ) {
    358                     if ( empty( $_POST[ $type ][ $value ] ) ) {
     414                    if ( empty( $_POST['notifications'][ $type ][ $value ] ) ) {
    359415                        $this->trac->delete( '_notifications', compact( 'username', 'type', 'value' ) );
    360416                        unset( $notifications[ $type ][ $value ] );
     
    362418                }
    363419            }
     420            if ( empty( $_POST['notifications']['newticket'] ) && ! empty( $notifications['newticket'] ) ) {
     421                    $this->trac->delete( '_notifications', array( 'username' => $username, 'type' => 'newticket' ) );
     422            } elseif ( ! empty( $_POST['notifications']['newticket'] ) && empty( $notifications['newticket'] ) ) {
     423                $this->trac->insert( '_notifications', array( 'username' => $username, 'type' => 'newticket', 'value' => '1' ) );
     424            }
    364425        }
    365426        ?>
    366427
    367428        <style>
    368         #components, #milestones, p.save-changes {
     429        #focuses, #components, #milestones, p.save-changes {
    369430            clear: both;
    370431        }
     
    372433            padding-top: 1em;
    373434        }
    374         #components li,
    375         #milestones li {
     435        #focuses li {
     436            display: inline-block !important;
     437            list-style: none;
     438            min-width: 15%;
     439            margin-right: 30px;
     440        }
     441        #components > ul {
     442            float: left;
     443            width: 24%;
     444            margin: 0 0 0 1% !important;
     445            margin: 0;
     446            padding: 0;
     447        }
     448        #components > ul > li {
     449            list-style: none;
     450        }
     451        #milestones > ul > li {
    376452            float: left;
    377453            width: 25%;
     
    402478        echo '<form method="post" action="">';
    403479        wp_nonce_field( 'save-trac-notifications', 'trac-nonce', false );
     480        echo '<h3>New Tickets</h3>';
     481        $checked = checked( $notifications['newticket'], true, false );
     482        echo '<ul><li style="list-style:none"><label><input type="checkbox" ' . $checked . 'name="notifications[newticket]" /> Receive all new ticket notifications.</label><br /><em>To receive comments to a ticket, you will need to star it, unless it matches one of your other preferences below.</em></li></ul>';
     483        echo '<div id="focuses">';
     484        echo '<h3>Focuses</h3>';
     485        echo '<ul>';
     486        foreach ( $focuses as $focus ) {
     487            $checked = checked( ! empty( $notifications['focus'][ $focus ] ), true, false );
     488            echo '<li><label><input type="checkbox" ' . $checked . 'name="notifications[focus][' . esc_attr( $focus ) . ']" /> ' . $focus . '</label></li>';
     489        }
     490        echo '</ul>';
     491        echo '</div>';
    404492        echo '<div id="components">';
    405493        echo '<h3>Components</h3>';
    406494        echo '<p class="select-all"><a href="#" data-action="select-all">select all</a> &bull; <a href="#" data-action="clear-all">clear all</a></p>';
    407         echo '<ul>';
    408         foreach ( $components as $component ) {
     495        echo "<ul>\n";
     496        $components_tree = $this->make_components_tree( $components );
     497        $breakpoints = array( 'Export', 'Media', 'Script Loader' );
     498        foreach ( $components_tree as $component => $subcomponents ) {
     499            if ( in_array( $component, $breakpoints ) ) {
     500                echo '</ul><ul>';
     501            }
    409502            $checked = checked( ! empty( $notifications['component'][ $component ] ), true, false );
    410             echo '<li><label><input type="checkbox" ' . $checked . 'name="component[' . esc_attr( $component ) . ']" /> ' . $component . '</label></li>';
     503            echo '<li><label><input type="checkbox" ' . $checked . 'name="notifications[component][' . esc_attr( $component ) . ']" /> ' . $component . "</label>\n";
     504            if ( is_array( $subcomponents ) ) {
     505                echo "<ul>\n";
     506                foreach ( $subcomponents as $subcomponent ) {
     507                    $i++;
     508                    $checked = checked( ! empty( $notifications['component'][ $subcomponent ] ), true, false );
     509                    echo '<li><label><input type="checkbox" ' . $checked . 'name="notifications[component][' . esc_attr( $subcomponent ) . ']" /> ' . $subcomponent . "</label></li>\n";
     510                }
     511                echo "</ul>\n";
     512            }
     513            echo "</li>\n";
    411514        }
    412515        echo '</ul>';
     
    425528                $class = ' class="' . $class . '"';
    426529            }
    427             echo  '<li' . $class . '><label><input type="checkbox" ' . $checked . 'name="milestone[' . esc_attr( $milestone->name ) . ']" /> ' . $milestone->name . '</label></li>';
     530            echo  '<li' . $class . '><label><input type="checkbox" ' . $checked . 'name="notifications[milestone][' . esc_attr( $milestone->name ) . ']" /> ' . $milestone->name . '</label></li>';
    428531        }
    429532        echo '<li id="show-completed"><a href="#">Show recently completed&hellip;</a></li>';
Note: See TracChangeset for help on using the changeset viewer.