function publish_html($rss) {
$cacheFile = $_SERVER["DOCUMENT_ROOT"] . "/svn/feed/html.cache";
if (file_exists($cacheFile)) {
readfile($cacheFile);
return;
}
$repository = "http://72.9.228.230:8080/svn/jsvn/tags/";
$contents = read_contents($repository);
$handle = fopen($cacheFile, "w+");
if (!$contents) {
fwrite($handle, "
Repository is temporary not responding. Try again later. |
");
fwrite($handle, emergency_html());
fclose($handle);
readfile($cacheFile);
return;
}
$items = publish_rss20($repository, $contents, $rss);
$handle = fopen($cacheFile, "w+");
for($i = 0; $i < count($items) && $i < 3; $i++) {
fwrite($handle, $items[count($items) - $i - 1]["html_description"]);
}
if (count($items) == 0) {
fwrite($handle, "repository is temporary not responding. try again later. |
");
}
fclose($handle);
readfile($cacheFile);
}
function publish_rss20($repository, $contents, $rss) {
if (preg_match_all("/(.*\..*\..*)(<\/a>)<\/li>/", $contents, $matches)) {
$items = array();
$index = 0;
for($i = 0; $i < count($matches[1]); $i++) {
$build = $matches[1][$i];
$changelog_url = $repository . $build . "/changelog.txt";
$test_url = $repository . $build . "/tests.log";
$test_results_xml_url = $repository . $build . "/results.xml";
$changelog = read_contents($changelog_url);
if (!$changelog) {
continue;
}
$standalone_name = "org.tmatesoft.svn_" . $build . ".standalone.zip";
$eclipse_name = "org.tmatesoft.svn_" . $build . ".eclipse.zip";
$src_name = "org.tmatesoft.svn_" . $build . ".src.zip";
$standalone_file = $_SERVER["DOCUMENT_ROOT"] . "/svn/" . $standalone_name;
if (!file_exists($standalone_file)) {
continue;
}
$svn_url = $repository . $build . "/";
$standalone_link = $rss . $standalone_name;
$src_url = $rss . $src_name;
$eclipse_url = $rss . $eclipse_name;
$eclipse_update_url = $rss;
ereg("^=[^\n]+\n([^=]+).*$", $changelog, $m);
$changelog_str = trim($m[1]);
$date_string = date("j M Y, H:i", filemtime($standalone_file));
$item_description = "" . $date_string . ", build: " . $build . "";
$item_description .= "ChangeLog
" . $changelog_str . "
";
$item_description .= "full changelog up to this build";
$item_description .= "tests results";
$item_description .= "Contact
Your questions and feedback are welcome at support@tmatesoft.com
";
$html_description = " " . $date_string . ", build " . $build . " |
";
$html_description .= " Changelog: |
";
$html_description .= "" . $changelog_str . " ";
$html_description .= "full changelog up to this build tests results |
";
$html_description .= " Python Tests Results | " . $build. "-tests" . " |
";
$html_description .= " Standalone Version | " . $standalone_name . " |
";
$html_description .= " Source Code Archive | " . $src_name . " |
";
$html_description .= " Eclipse Update Site Archive | " . $eclipse_name . " |
";
$html_description .= " Eclipse Update Site Location | " . $eclipse_update_url . " |
";
$html_description .= " Source Code | @svn repository |
";
$item = array();
$item["title"] = "Build '" . $build . "' published";
$item["source"] = "http://tmate.org/svn/";
$item["link"] = "http://tmate.org/svn/";
$item["author"] = "TMate Software";
$item["date"] = filemtime($standalone_file);
$item["rss_description"] = $item_description;
$item["html_description"] = $html_description;
$items[$index++] = $item;
}
}
return $items;
}
function read_contents($url) {
$fp = fsockopen("72.9.228.230", 8080, $errno, $errstr, 1);
if (!$fp) {
return false;
}
fclose($fp);
$handle = fopen($url, "rb");
if (!$handle) {
return false;
}
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
return $contents;
}
function emergency_html() {
// Open a known directory, and proceed to read its contents
$dir = $_SERVER["DOCUMENT_ROOT"] . "/svn/";
$result = "";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$entries = array();
$index = 0;
while (($file = readdir($dh)) !== false) {
$matches = array();
ereg("^.+_([0-9]+)\.standalone\.zip$", $file, $matches);
if (count($matches) > 1) {
$entries[$index++] = $matches[1];
}
}
closedir($dh);
sort($entries);
if (count($entries) > 0) {
$result = $entries[count($entries) - 1];
$result = "Latest binary version is org.tmatesoft.svn_" . $result .".standalone.zip |
";
}
}
}
return $result;
}
?>