Skip to content

Instantly share code, notes, and snippets.

@RudolfHattenkofer
Last active December 26, 2015 18:39
Show Gist options
  • Save RudolfHattenkofer/7196045 to your computer and use it in GitHub Desktop.
Save RudolfHattenkofer/7196045 to your computer and use it in GitHub Desktop.
RSS-Feed für TUMonline Seiten. Für DS vorkonfiguriert.
<?php
// Feed URL und Name der Überschrift hier eingeben:
$feed_url = 'http://www7.in.tum.de/um/courses/ds/ws1314/';
$config = array(
'name' => 'Vorlesung DS WS 13/14',
'desc' => 'RSS-Feed zur Vorlesung',
'url' => $feed_url,
);
/* * * * * * * * * * * * * * * * * *
* Ab hier nicht mehr bearbeiten! *
* * * * * * * * * * * * * * * * * */
// Get raw data from server
$raw_html = file_get_contents( $feed_url );
// Get news part
$with_table = explode( '<table class="content">', $raw_html )[1];
$after_table = explode( '<head>', $with_table )[1];
$news_content = explode( '<!-- End Page Content -->', $after_table )[0];
// Strip list points apart
$news_parts = explode( '<h4>', $news_content );
// Convert news to proper array
$news = array();
foreach( $news_parts as $entry ) {
if( ! strpos($entry, '</h4>') )
continue;
$parts = explode( '</h4>', $entry );
$news[] = array(
'title' => htmlspecialchars( $parts[0] ),
'content' => htmlspecialchars( $parts[1] ),
);
}
// Generate RSS
// # # # # # #
$rss_dom = new DOMDocument( '1.0', 'utf-8' );
$rss = $rss_dom->createElement( 'rss' );
$channel = $rss_dom->createElement( 'channel' );
// Set version
$rss->setAttribute( 'version', '2.0' );
// Append to DOM
$rss_dom->appendChild( $rss );
$rss->appendChild( $channel );
// Set channel stuff
$channel->appendChild( $rss_dom->createElement( 'title', $config['name'] ) );
$channel->appendChild( $rss_dom->createElement( 'description', $config['desc'] ) );
$channel->appendChild( $rss_dom->createElement( 'link', $config['url'] ) );
$channel->appendChild( $rss_dom->createElement( 'ttl', 0 ) );
foreach( $news as $entry ) {
$item = $rss_dom->createElement( 'item' );
$item->appendChild( $rss_dom->createElement( 'title', $entry['title'] ) );
$item->appendChild( $rss_dom->createElement( 'link', $feed_url ) );
$item->appendChild( $rss_dom->createElement( 'description', $entry['content'] ) );
$channel->appendChild( $item );
}
// And output it
header( 'Content-Type: application/rss+xml; charset=utf-8' );
echo $rss_dom->saveXML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment