Changeset 11372 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac.php
- Timestamp:
- 12/15/2021 04:38:09 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-trac-watcher/trac.php
r11371 r11372 1 1 <?php 2 2 namespace WordPressdotorg\Trac\Watcher\Trac; 3 use function WordPressdotorg\Trac\Watcher\SVN\get_svns; 4 use SimpleXmlElement; 3 5 4 6 add_action( 'import_trac_feeds', function() { 5 // Trac RSS feed import from profiles.w.org to be moved here. 7 8 foreach ( get_svns() as $svn ) { 9 if ( empty( $svn['trac'] ) || empty( $svn['trac_table'] ) ) { 10 continue; 11 } 12 13 import_trac_feed( $svn ); 14 } 6 15 } ); 16 17 function import_trac_feed( $svn ) { 18 global $wpdb; 19 20 $feed_url = $svn['trac'] . '/timeline?ticket=on&changeset=on&milestone=on&wiki=on&max=50&daysback=5&format=rss'; 21 22 $feed = wp_remote_retrieve_body( wp_remote_get( $feed_url, array( 'timeout' => 60 ) ) ); 23 if ( ! $feed ) { 24 return; 25 } 26 27 $xml = new SimpleXmlElement( $feed ); 28 if ( ! isset( $xml->channel->item ) ) { 29 return; 30 } 31 32 $trac_table = $svn['trac_table']; // Not user input, safe. 33 34 foreach ( $xml->channel->item as $item ) { 35 $dc = $item->children( 'http://purl.org/dc/elements/1.1/' ); 36 $md5_id = md5( strip_tags( $item->title . $dc->creator . $item->pubDate ) ); 37 38 if ( $wpdb->get_var( $wpdb->prepare( "SELECT md5_id FROM {$trac_table} WHERE md5_id = %s LIMIT 1", $md5_id ) ) ) { 39 // if this entry is already in our database, that means all the previous ones should be too 40 break; 41 } 42 43 $wpdb->insert( 44 $trac_table, 45 [ 46 'md5_id' => $md5_id, 47 'description' => trim( strip_tags( (string) $item->description, '<a><strike>' ) ), 48 'summary' => (string) $item->summary, 49 'category' => (string) $item->category, 50 'username' => (string) $dc->creator, 51 'link' => (string) $item->link, 52 'pubdate' => gmdate( 'Y-m-d H:i:s', strtotime( (string) $item->pubDate ) ), 53 'title' => (string) $item->title, 54 ] 55 ); 56 } 57 } 7 58 8 59 function format_trac_markup( $message ) {
Note: See TracChangeset
for help on using the changeset viewer.