fix bad 'ast update' time guess; allow sorting by numfiles, numfiles, longest support lifespan

This commit is contained in:
mappu 2016-04-18 20:02:53 +12:00
parent 39789220a8
commit 4f6ce8695c
3 changed files with 36 additions and 24 deletions

View File

@ -3,15 +3,21 @@
class CProject {
private $dir;
public $projname;
public $shortdesc = '(no description)';
public $subtag = '';
public $lastupdate = 0;
public $numreleases = 0;
private $longdesc = '';
private $prefix_html = '';
private $images = array();
private $downloads = array();
private $downloads_hashes = array();
public $lifespan = 0;
public $tags = array();
public $homeimage = null;
@ -29,31 +35,47 @@ class CProject {
if ($file == 'README.txt') {
$this->longdesc = file_get_contents($this->dir.'README.txt');
// Guess 'last update' time
$matches = [];
if (preg_match('~\n(\d\d\d\d-\d\d-\d\d)~', $this->longdesc, $matches)) {
// Use first date entry (assumed to be a CHANGELOG)
$this->lastupdate = strtotime($matches[1]);
$found_real_lastupdate = true;
}
$this->longdesc = file_get_contents($this->dir.'README.txt');
// Find number of releases
preg_match_all('~\n(\d\d\d\d-\d\d-\d\d)~', $this->longdesc, $matches, PREG_SET_ORDER);
$this->numreleases = count($matches);
// Find support lifespan (newest minus youngest)
$eldest = time();
$newest = 0;
foreach($matches as $match) {
$stamp = strtotime($match[1]);
$eldest = min($stamp, $eldest);
$newest = max($stamp, $newest);
}
$this->lifespan = floor(max(0, $newest - $eldest) / 3600); // could divide by 86400 but it doesn't matter
// Find 'written in'
$matches = array();
if (preg_match('~Written in ([^\\r\\n]+)~', $this->longdesc, $matches)) {
$this->subtag = rtrim($matches[1], ' .');
}
// Find tags
if (preg_match('~Tags: ([^\\r\\n]+)~', $this->longdesc, $matches)) {
$this->tags = array_map('trim', explode(',', $matches[1]));
}
// Extract short description
$parts = explode("\n", $this->longdesc);
$this->shortdesc = array_shift($parts);
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
// Filter longdesc
// Filters for longdesc
$this->longdesc = str_replace("\r", "", $this->longdesc); // filter windows CR
$prefix_html = '';
@ -112,6 +134,10 @@ class CProject {
}
public function numDownloads() {
return count($this->downloads);
}
public function write() {
// Generate image thumbnails
@ -197,7 +223,7 @@ class CProject {
<?php if (count($this->images)) { ?>
<div class="projimg">
<?php foreach($this->images as $idx => $origname) { ?>
<a href="srv/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="srv/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
<a href="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
<?php } ?>
</div>

View File

@ -125,6 +125,9 @@ function buildcommon() {
data-sort-mt="-<?=$pr->lastupdate?>"
data-sort-ct="<?=$i?>"
data-sort-al="<?=$alphaidx[$i]?>"
data-sort-nr="-<?=$pr->numreleases?>"
data-sort-nf="-<?=$pr->numDownloads()?>"
data-sort-ls="-<?=$pr->lifespan?>"
>
<td>
<a href="<?=hesc(urlencode($pr->projname))?>.html"><?=(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>

View File

@ -73,26 +73,9 @@
};
var sort_update = function(sort_by) {
switch(sort_by) {
case 'a':
default: {
sort_rows(function(el) {
return el.getAttribute('data-sort-ct');
});
} break;
case 'b': {
sort_rows(function(el) {
return el.getAttribute('data-sort-mt');
});
} break;
case 'c': {
sort_rows(function(el) {
return el.getAttribute('data-sort-al');
});
} break;
};
sort_rows(function(el) {
return el.getAttribute(sort_by);
});
};
window.sortUpdate = sort_update;