Skip to content

Instantly share code, notes, and snippets.

@tomoe-mami
Created March 20, 2013 00:30
Show Gist options
  • Save tomoe-mami/5201395 to your computer and use it in GitHub Desktop.
Save tomoe-mami/5201395 to your computer and use it in GitHub Desktop.
Atom feed for recent commits in git.enlightenment.org. Cgit only provides per repo feed. This stupid php script combines 10 feeds of recently updated repo into one feed. The entries are not sorted from most recent to the oldest one, it just import whatever it is in the original per repo feed. If you're using a decent feed aggregator, this should…
<?php
$base_url = 'http://git.enlightenment.org';
$atom_ns_uri = 'http://www.w3.org/2005/Atom';
$list_dom = new DOMDocument;
$html = file_get_contents($base_url . '/?s=idle');
libxml_use_internal_errors(true);
$list_dom->loadHTML($html);
$list_dom->encoding = 'utf-8';
$list_xpath = new DOMXPath($list_dom);
$repo_links = $list_xpath->query('(//td[@class="toplevel-repo"]/a)[position() <= 10]');
if ($repo_links instanceOf DOMNodeList && $repo_links->length)
{
$new_feed = new DOMDocument;
$new_feed->xmlVersion = '1.0';
$new_feed->xmlStandalone = true;
$new_feed->encoding = 'utf-8';
$root = $new_feed->appendChild($new_feed->createElement('feed'));
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', $atom_ns_uri);
$root->appendChild($new_feed->createElement('title', 'Enlightenment Commits'));
$alt = $root->appendChild($new_feed->createElement('link'));
$alt->setAttribute('rel', 'alternate');
$alt->setAttribute('type', 'text/html');
$alt->setAttribute('href', $base_url);
foreach ($repo_links as $link)
{
$orig_feed = new DOMDocument;
$orig_feed->load($base_url . $link->getAttribute('href') . 'atom');
$orig_xpath = new DOMXPath($orig_feed);
$orig_xpath->registerNamespace('_', $atom_ns_uri);
$orig_entries = $orig_xpath->query('(/_:feed/_:entry)[position() <= 20]');
if ($orig_entries instanceOf DOMNodeList && $orig_entries->length)
{
foreach ($orig_entries as $entry)
{
$node = $new_feed->importNode($entry, true);
$root->appendChild($node);
}
}
}
}
header('Content-Type: application/atom+xml');
$new_feed->save('php://output');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment