Changeset 373
- Timestamp:
- 02/05/2014 08:52:43 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-notifications.php
r322 r373 34 34 $this->trac_subdomain = $trac; 35 35 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' ); 37 37 foreach ( $tables as $table ) { 38 38 add_db_table( 'trac_' . $trac, $table ); … … 80 80 } 81 81 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 82 86 function get_trac_ticket_participants( $ticket_id ) { 83 87 return $this->trac->get_col( $this->trac->prepare( "SELECT DISTINCT author FROM ticket_change WHERE ticket = %d", $ticket_id ) ); … … 88 92 } 89 93 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 90 126 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" ); 92 128 } 93 129 … … 101 137 function get_trac_notifications_for_user( $username ) { 102 138 $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() ); 104 140 105 141 foreach ( $rows as $row ) { 106 142 $notifications[ $row->type ][ $row->value ] = true; 107 143 } 144 $notifications['newticket'] = ! empty( $notifications['newticket']['1'] ); 145 108 146 return $notifications; 109 147 } … … 206 244 } 207 245 246 $focuses = explode( ', ', $this->get_trac_ticket_focuses( $ticket_id ) ); 247 208 248 $notifications = $this->get_trac_notifications_for_user( $username ); 209 249 … … 226 266 $reasons['participant'] = 'you have commented'; 227 267 } 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 228 283 if ( ! empty( $notifications['component'][ $ticket->component ] ) ) { 229 284 $reasons['component'] = sprintf( 'you subscribe to the %s component', $ticket->component ); … … 334 389 function notification_settings_page() { 335 390 if ( ! is_user_logged_in() ) { 336 return 'Please log into save your notification preferences.';391 return 'Please <a href="//wordpress.org/support/bb-login.php">log in</a> to save your notification preferences.'; 337 392 } 338 393 … … 340 395 $components = $this->get_trac_components(); 341 396 $milestones = $this->get_trac_milestones(); 397 $focuses = $this->get_trac_focuses(); 342 398 343 399 $username = wp_get_current_user()->user_login; … … 347 403 check_admin_referer( 'save-trac-notifications', 'trac-nonce' ); 348 404 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 ) { 351 407 if ( empty( $notifications[ $type ][ $value ] ) ) { 352 408 $this->trac->insert( '_notifications', compact( 'username', 'type', 'value' ) ); … … 356 412 357 413 foreach ( $notifications[ $type ] as $value => $on ) { 358 if ( empty( $_POST[ $type ][ $value ] ) ) {414 if ( empty( $_POST['notifications'][ $type ][ $value ] ) ) { 359 415 $this->trac->delete( '_notifications', compact( 'username', 'type', 'value' ) ); 360 416 unset( $notifications[ $type ][ $value ] ); … … 362 418 } 363 419 } 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 } 364 425 } 365 426 ?> 366 427 367 428 <style> 368 # components, #milestones, p.save-changes {429 #focuses, #components, #milestones, p.save-changes { 369 430 clear: both; 370 431 } … … 372 433 padding-top: 1em; 373 434 } 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 { 376 452 float: left; 377 453 width: 25%; … … 402 478 echo '<form method="post" action="">'; 403 479 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>'; 404 492 echo '<div id="components">'; 405 493 echo '<h3>Components</h3>'; 406 494 echo '<p class="select-all"><a href="#" data-action="select-all">select all</a> • <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 } 409 502 $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"; 411 514 } 412 515 echo '</ul>'; … … 425 528 $class = ' class="' . $class . '"'; 426 529 } 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>'; 428 531 } 429 532 echo '<li id="show-completed"><a href="#">Show recently completed…</a></li>';
Note: See TracChangeset
for help on using the changeset viewer.