-
-
Save robot56/dbfe8e2e5a7f8ae188cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Bukkit Build RSS Generator | |
* | |
* @author JWhy <[email protected]> | |
* @version 0.3 | |
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License | |
*/ | |
/* Channel configuration */ | |
//The paths of different download-channels. These will be appended to the API base URL | |
$channels = array( | |
'rb' => array( | |
'url' => 'projects/craftbukkit/artifacts/rb/', | |
'show_broken' => 'false', //whether to show builds marked as broken | |
'git_url' => 'https://api.github.com/repos/Bukkit/CraftBukkit/git/commits/' | |
), | |
'beta' => array( | |
'url' => 'projects/craftbukkit/artifacts/beta/', | |
'show_broken' => 'false', //whether to show builds marked as broken | |
'git_url' => 'https://api.github.com/repos/Bukkit/CraftBukkit/git/commits/' | |
), | |
'dev' => array( | |
'url' => 'projects/craftbukkit/artifacts/dev/', | |
'show_broken' => 'true', //whether to show builds marked as broken | |
'git_url' => 'https://api.github.com/repos/Bukkit/CraftBukkit/git/commits/' | |
) | |
); | |
if(!isset($_GET["channel"]))$_GET["channel"]=$args; | |
/* Check channel parameter */ | |
if(!@$_GET['channel']){ | |
print("No channel selected!<br>\nConfigured channels:"); | |
foreach($channels as $name=>$url){ | |
$script_name = $_SERVER['SCRIPT_NAME']; | |
print("<br>\n<a href=\"$script_name?channel=$name\">$name</a>"); | |
}exit(); | |
}else{ | |
$chan = $_GET['channel']; | |
header("Content-Type: application/rss+xml"); | |
} | |
if(!$channels[strtolower($chan)])die("Undefined channel: \"$chan\""); | |
$channel = $channels[strtolower($chan)]; | |
$slug = $channel['url']; //No need to edit this! | |
/* Further configuration */ | |
//Beautify RSS: true/false. Set to false to save resources (but feed source code will be in one line) | |
$reparse_dom = true; | |
//Link type in RSS feed. Put true for the detail page or false for the file download link. | |
$link_to_article = true; | |
//RSS header information | |
$rss_headers = array( | |
'title' => "CraftBukkit-Builds: $chan", | |
'link' => 'http://dl.bukkit.org/', //You should put your website url here | |
'description' => "The latest builds in the $chan-channel on dl.bukkit.org", | |
'language' => 'en-us', | |
'pubDate' => date('D, d M Y H:i:s', time()) . ' GMT', //Current time | |
'lastBuildDate' => date('D, d M Y H:i:s', time()) . ' GMT', //Current time | |
'generator' => 'BukkitDL Parser by JWhy (https://gist.github.com/JWhy/5176655)', //Yep, you MAY change that ;) | |
'webMaster' => '[email protected]', //Correct your email | |
); | |
//The base URL of the dl.bukkit.org website (no trailing slash!) | |
$webdl_url = 'http://dl.bukkit.org'; | |
//The base URL of the dl.bukkit.org API | |
$api_url = 'http://dl.bukkit.org/api/1.0/downloads/'; | |
//Will be appended to the url. Default will force dl.bukkit.org to reply with xml | |
$params = "?_accept=application/xml"; | |
/* Git message function */ | |
function getGitMessage($url, $ch){ | |
curl_setopt($ch, CURLOPT_URL, $url); | |
$json = json_decode(curl_exec($ch)); | |
return($json->message); | |
} | |
/* Load and parse XML */ | |
$channel_xml = simplexml_load_file( $api_url . $slug . $params ); | |
$items = $channel_xml->results->children(); | |
/* Create new XML object for RSS */ | |
$xml_template = "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n <channel>\n </channel>\n</rss>"; | |
$rss = simplexml_load_string($xml_template); | |
/* Fill template with latest builds */ | |
$rss_chan = $rss->channel; | |
$br = '<pre></pre> '; | |
foreach($items as $build){ | |
$link = ''; | |
$build_desc = $build->project->name . ' ' . $build->channel->name . ' ' . $build->build_number . ' (' | |
. $build->version . ')'; | |
$dl_link = $webdl_url . $build->file->url; | |
$detail_link = $webdl_url . $build->html_url; | |
$gh_commit = $build->project->github_project_url . "/commit/" . $build->commit->ref; | |
if(!$link_to_article) $link = $dl_link; | |
if($link_to_article) $link = $detail_link; | |
//Exclude broken builds if configured | |
if($build->is_broken == "False" || $channel['show_broken']){ | |
$item = $rss_chan->addChild('item'); | |
$item->addChild('title', "$build_desc released"); | |
$item->addChild('link', $link); | |
$item->addChild('guid', $dl_link); | |
$item->addChild('pubDate', date('D, d M Y H:i:s', strtotime(substr($build->created, 0, -6))) . ' GMT'); | |
$item->addChild('description', | |
"<a href=\"$dl_link\">Download</a>, <a href=\"$detail_link\">view details</a> or | |
<a href=\"$gh_commit\">view GitHub commit</a>" . $br . | |
"Download count: " . $build->download_count . $br . | |
"File size: " . (floor($build->file->size / 10000)/100) . " MB" . $br . | |
"MD5 hash: " . $build->file->checksum_md5 . $br | |
); | |
} | |
} | |
/* Beautify RSS */ | |
if($reparse_dom){ | |
$doc = new DOMDocument('1.0'); | |
$doc->preserveWhiteSpace = false; | |
$doc->loadXML($rss->asXML()); | |
$doc->formatOutput = true; | |
print($doc->saveXML()); | |
}else{ | |
print($rss->asXML()); | |
} | |
/* Close curl */ | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment