2016-04-18 07:04:52 +00:00
|
|
|
<?php
|
|
|
|
|
2016-07-17 04:13:59 +00:00
|
|
|
function template($title, $content, $extra_head='') {
|
2016-04-18 07:04:52 +00:00
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
|
|
|
|
<meta name="viewport" content="width=960" >
|
2016-07-17 04:13:59 +00:00
|
|
|
<?=$extra_head?>
|
|
|
|
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/normalize.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/style.css">
|
|
|
|
<script type="text/javascript" src="<?=BASEURL?>static/site.js"></script>
|
2016-04-18 07:04:52 +00:00
|
|
|
<title><?=hesc($title)?></title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="container">
|
|
|
|
<div id="content">
|
|
|
|
<?=file_get_contents(BASEDIR.'/header.htm')?>
|
|
|
|
<?=$content?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function listprojects() {
|
|
|
|
// List projects
|
|
|
|
|
|
|
|
$ls = scandir(BASEDIR.'data');
|
|
|
|
rsort($ls);
|
|
|
|
$projects = array();
|
|
|
|
foreach($ls as $dirname) {
|
|
|
|
if ($dirname[0] == '.') continue;
|
|
|
|
if (! is_dir(BASEDIR.'data/'.$dirname)) continue;
|
|
|
|
$matches = array();
|
|
|
|
|
|
|
|
if (preg_match('~(?:\d+-)?(.+)~', $dirname, $matches)) {
|
|
|
|
$projects[$dirname] = $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $projects;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildprojects($id, $projects) {
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
foreach($projects as $dirname => $projectname) {
|
|
|
|
|
|
|
|
echo sprintf("@%1d [%3d/%3d] ".$projectname."...\n", $id, ++$count, count($projects));
|
|
|
|
|
|
|
|
$pr = new CProject($dirname, $projectname);
|
|
|
|
$pr->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildcommon() {
|
|
|
|
|
|
|
|
echo "@0 [ 0/ ?] Common files...\n";
|
|
|
|
|
|
|
|
$projects = listprojects();
|
|
|
|
|
|
|
|
// Build all projects
|
|
|
|
|
|
|
|
$plist = array();
|
|
|
|
|
|
|
|
$handles = array();
|
|
|
|
$handle_lookup = array();
|
|
|
|
|
|
|
|
$alphasort = [];
|
|
|
|
|
|
|
|
foreach($projects as $dirname => $projectname) {
|
|
|
|
|
|
|
|
$pr = new CProject($dirname, $projectname);
|
|
|
|
$pr->genHomeImage(); // thumbnail
|
|
|
|
|
|
|
|
$plist[] = $pr;
|
|
|
|
|
|
|
|
if (is_null($pr->homeimage)) {
|
|
|
|
$handle_lookup[$projectname] = null;
|
|
|
|
} else {
|
|
|
|
$handle_lookup[$projectname] = count($handles);
|
|
|
|
$handles[] = $pr->homeimage;
|
|
|
|
}
|
|
|
|
|
|
|
|
$alphasort[] = [$pr->projname, count($plist)-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
usort($alphasort, function($a, $b) {
|
|
|
|
return strcasecmp($a[0], $b[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$alphaidx = [];
|
|
|
|
|
|
|
|
foreach($alphasort as $a) {
|
|
|
|
$alphaidx[ $a[1] ] = count($alphaidx);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build homepage spritesheet
|
|
|
|
|
|
|
|
if (count($handles)) {
|
|
|
|
mkspritesheet($handles, BASEDIR.'wwwroot/logos.jpg', INDEX_THUMB_W, INDEX_THUMB_H);
|
|
|
|
array_map('imagedestroy', $handles); // free
|
|
|
|
}
|
|
|
|
|
2017-04-23 05:58:11 +00:00
|
|
|
// Cache-busting stylesheet
|
|
|
|
|
|
|
|
$style = '.homeimage-sprite { background-image: url("logos.jpg?'.md5_file(BASEDIR.'wwwroot/logos.jpg').'"); }';
|
|
|
|
|
2016-04-18 07:04:52 +00:00
|
|
|
// Build index page
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php if (file_exists(BASEDIR.'homepage_blurb.htm')) { ?>
|
|
|
|
<!-- homepage blurb {{ -->
|
|
|
|
<?=file_get_contents(BASEDIR.'homepage_blurb.htm')?>
|
|
|
|
<!-- }} -->
|
|
|
|
<?php } ?>
|
|
|
|
|
2017-04-23 05:58:11 +00:00
|
|
|
<style type="text/css">
|
|
|
|
<?php echo $style; ?>
|
|
|
|
</style>
|
|
|
|
|
2016-04-18 07:04:52 +00:00
|
|
|
<table id="projtable-main" class="projtable">
|
|
|
|
<?php foreach ($plist as $i => $pr) { ?>
|
|
|
|
<tr class="<?=$pr->getClassAttr()?>"
|
|
|
|
data-sort-mt="-<?=$pr->lastupdate?>"
|
|
|
|
data-sort-ct="<?=$i?>"
|
|
|
|
data-sort-al="<?=$alphaidx[$i]?>"
|
2016-04-18 08:02:53 +00:00
|
|
|
data-sort-nr="-<?=$pr->numreleases?>"
|
|
|
|
data-sort-nf="-<?=$pr->numDownloads()?>"
|
|
|
|
data-sort-ls="-<?=$pr->lifespan?>"
|
2016-04-18 07:04:52 +00:00
|
|
|
>
|
|
|
|
<td>
|
2016-07-17 04:13:59 +00:00
|
|
|
<a href="<?=hesc(BASEURL.urlencode($pr->projname))?>/"><?=(is_null($handle_lookup[$pr->projname]) ? '<div class="no-image"></div>' : '<div class="homeimage homeimage-sprite" style="background-position:0 -'.($handle_lookup[$pr->projname]*INDEX_THUMB_H).'px"></div>')?></a>
|
2016-04-18 07:04:52 +00:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<strong><?=hesc(str_replace('_', ' ', $pr->projname))?></strong><?php if (SHOW_BLURBS) { ?>,
|
|
|
|
<?=hesc($pr->shortdesc)?>
|
|
|
|
<?php } ?>
|
2016-07-17 04:13:59 +00:00
|
|
|
<a href="<?=hesc(BASEURL.urlencode($pr->projname))?>/" class="article-read-more">more...</a>
|
2016-04-18 07:04:52 +00:00
|
|
|
<?php if (strlen($pr->subtag) || count($pr->tags)) { ?>
|
|
|
|
<br>
|
|
|
|
<small>
|
|
|
|
<?=hesc($pr->subtag)?>
|
|
|
|
<?php if (strlen($pr->subtag) && count($pr->tags)) { ?>
|
|
|
|
::
|
|
|
|
<?php } ?>
|
|
|
|
<?php foreach($pr->tags as $tag) { ?>
|
|
|
|
<a class="tag tag-link" data-tag="<?=hesc($tag)?>"><?=hesc($tag)?></a>
|
|
|
|
<?php } ?>
|
|
|
|
</small>
|
|
|
|
<?php } ?>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php } ?>
|
|
|
|
</table>
|
|
|
|
<?php
|
|
|
|
|
2016-07-17 04:13:59 +00:00
|
|
|
$extra_head = '<link rel="canonical" href="'.hesc(BASEURL).'">';
|
|
|
|
|
|
|
|
$index = template(SITE_TITLE, ob_get_clean(), $extra_head);
|
2016-04-18 07:04:52 +00:00
|
|
|
file_put_contents(BASEDIR.'wwwroot/index.html', $index);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
}
|
|
|
|
|
2016-07-17 04:13:59 +00:00
|
|
|
function redirecthtml($target) {
|
|
|
|
ob_start();
|
2016-04-18 07:04:52 +00:00
|
|
|
?>
|
2016-07-17 04:13:59 +00:00
|
|
|
<meta http-equiv="refresh" content="0; url=<?=hesc($target)?>">
|
|
|
|
<a href="<?=hesc($target)?>">Moved »</a>
|
2016-04-18 07:04:52 +00:00
|
|
|
<?php
|
2016-07-17 04:13:59 +00:00
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildredirects($redirects) {
|
|
|
|
foreach($redirects as $oldname => $newname) {
|
2017-10-27 23:43:49 +00:00
|
|
|
|
|
|
|
$page = redirecthtml(BASEURL.$newname.'/');
|
|
|
|
|
|
|
|
// old format
|
2016-04-18 07:04:52 +00:00
|
|
|
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'.html', $page);
|
2017-10-27 23:43:49 +00:00
|
|
|
|
|
|
|
// new format
|
|
|
|
mkdir(BASEDIR.'wwwroot/'.$oldname);
|
|
|
|
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'/index.html', $page);
|
2016-04-18 07:04:52 +00:00
|
|
|
}
|
|
|
|
}
|