#9837: Nightly images webpage buggy -------------------------+------------------------- Reporter: kneekoo | Owner: haiku-web Type: bug | Status: new Priority: normal | Milestone: Component: Website/CMS | Version: Keywords: | Blocked By: Blocking: | Has a Patch: 0 Platform: All | -------------------------+------------------------- [http://www.haiku-files.org/haiku/development/] I noticed some builds have '''''"xz zip"''''' while others have '''''"zip xz"'''''. I nagged the people in #haiku-dev and I got asked if I'm willing to fix it, which I agreed to do. So I got the source code and found out several bugs, outdated PHP code and instead of a quick fix I decided to rewrite the whole thing. Here's my proposal as a replacement to the current page: {{{ <?php function format_bytes($size) { $units = array(' B', ' KiB', ' MiB', ' GiB', ' TiB'); for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; return round($size, 2).$units[$i]; } function scanDirectory($dirName) { $revisions = array(); // add or remove release types in the $key array and the HTML will automatically be adjusted to them // format: "filestamp" => "label" $key = array("anyboot" => "Anyboot", "vmware" => "VMDK", "raw" => "Raw", "cd" => "ISO"); $types = implode("|", array_keys($key)); if ($listing = scandir($dirName)) { foreach ($listing as $file) { if ($data = preg_match("/haiku- nightly-(r|hrev)([0-9]+)-x86gcc2hybrid-($types)\.(tar\.xz|zip)/", $file, $matches)) { $date = date("Y-m-j", filemtime($dirName.'/'.$file)); $extension = $matches[4] == "tar.xz" ? "xz" : $matches[4]; $size = format_bytes(filesize($dirName.'/'.$file)); if (!array_key_exists($matches[2], $revisions)) { $revisions[$matches[2]] = array("link" => "<a href='http://dev.haiku- os.org/changeset/".$matches[2]."'>".$matches[1].$matches[2]."</a>"); foreach($key as $type) $revisions[$matches[2]][$type] = array(); } $package = "<a href=\"./$file\" title=\"$size $date\">$extension</a>"; $revisions[$matches[2]][$key[$matches[3]]][] = $package; } } ?> <table> <tr> <th>Revision</th> <?php foreach($key as $name) echo " <th>$name</th>\n"; ?> </tr> <?php foreach($revisions as $build => $data) { ?> <tr> <td><?php echo $data['link']; ?></td> <?php foreach($key as $name) { ?> <td><?php echo implode(" ", $data[$name]); ?></td> <?php } ?> </tr> <?php } ?> </table> <?php } } ?> }}} The old code uses ereg, it produces some PHP notices and the HTML formatting is not perfect, while my rewrite takes generates perfect HTML formatting and has more compact PHP code. I tested the code against 6 different (full) builds available on the nightlies page and everything's peachy. ''<mmadia> when you're done, make a new ticket on dev.haiku-os.org. thanks. <kneekoo> ok'' -- Ticket URL: <http://dev.haiku-os.org/ticket/9837> Haiku <http://dev.haiku-os.org> Haiku - the operating system.