blob: a9127fdd41404e134a4e5cf2a7df6040fa4e44ec [file] [log] [blame]
<?php
class Build {
var $date;
var $ts;
var $link;
var $title;
var $text;
var $status;
var $num;
}
class BuildFeed {
var $posts = array ();
function __construct($file_or_url) {
$file_or_url = $this->resolveFile ( $file_or_url );
if (! ($x = simplexml_load_file ( $file_or_url )))
return;
foreach ( $x->entry as $item ) {
$post = new Build ();
$post->date = ( string ) $item->published;
$post->ts = strtotime ( $item->published );
$post->link = ( string ) $item->link['href'];
$post->title = ( string ) $item->title;
$match = array();
preg_match('/\#(?P<num>\d+) \((?P<message>.+)\)/', $item->title, $match);
$post->num = ( string ) $match['num'];
$message = $match['message'];
$post->text = ( string ) $message;
$post->status = ( string ) $this->parseStatus ($message);
// Create summary as a shortened body and remove images,
// extraneous line breaks, etc.
#$post->summary = $this->summarizeText ( $post->text );
$this->posts [] = $post;
}
}
private function resolveFile($file_or_url) {
if (! preg_match ( '|^https?:|', $file_or_url ))
$feed_uri = $_SERVER ['DOCUMENT_ROOT'] . '/shared/xml/' . $file_or_url;
else
$feed_uri = $file_or_url;
return $feed_uri;
}
private function summarizeText($summary) {
$summary = strip_tags ( $summary );
// Truncate summary line to 100 characters
$max_len = 100;
if (strlen ( $summary ) > $max_len)
$summary = substr ( $summary, 0, $max_len ) . '...';
return $summary;
}
private function parseStatus($text) {
$status = "success";
if (strpos($text, 'fail') !== false) {
$status = 'unstable';
}
if (strpos($text, 'broken') !== false) {
$status = 'failed';
}
return $status;
}
private function parseBuildNumber($text) {
}
}
?>