fix bad 'ast update' time guess; allow sorting by numfiles, numfiles, longest support lifespan
This commit is contained in:
parent
39789220a8
commit
4f6ce8695c
@ -3,15 +3,21 @@
|
|||||||
class CProject {
|
class CProject {
|
||||||
|
|
||||||
private $dir;
|
private $dir;
|
||||||
|
|
||||||
public $projname;
|
public $projname;
|
||||||
public $shortdesc = '(no description)';
|
public $shortdesc = '(no description)';
|
||||||
public $subtag = '';
|
public $subtag = '';
|
||||||
public $lastupdate = 0;
|
public $lastupdate = 0;
|
||||||
|
public $numreleases = 0;
|
||||||
|
|
||||||
private $longdesc = '';
|
private $longdesc = '';
|
||||||
private $prefix_html = '';
|
private $prefix_html = '';
|
||||||
private $images = array();
|
private $images = array();
|
||||||
private $downloads = array();
|
private $downloads = array();
|
||||||
private $downloads_hashes = array();
|
private $downloads_hashes = array();
|
||||||
|
|
||||||
|
public $lifespan = 0;
|
||||||
|
|
||||||
public $tags = array();
|
public $tags = array();
|
||||||
|
|
||||||
public $homeimage = null;
|
public $homeimage = null;
|
||||||
@ -29,31 +35,47 @@ class CProject {
|
|||||||
|
|
||||||
if ($file == 'README.txt') {
|
if ($file == 'README.txt') {
|
||||||
|
|
||||||
|
$this->longdesc = file_get_contents($this->dir.'README.txt');
|
||||||
|
|
||||||
// Guess 'last update' time
|
// Guess 'last update' time
|
||||||
$matches = [];
|
$matches = [];
|
||||||
if (preg_match('~\n(\d\d\d\d-\d\d-\d\d)~', $this->longdesc, $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)
|
// Use first date entry (assumed to be a CHANGELOG)
|
||||||
$this->lastupdate = strtotime($matches[1]);
|
$this->lastupdate = strtotime($matches[1]);
|
||||||
$found_real_lastupdate = true;
|
$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();
|
$matches = array();
|
||||||
if (preg_match('~Written in ([^\\r\\n]+)~', $this->longdesc, $matches)) {
|
if (preg_match('~Written in ([^\\r\\n]+)~', $this->longdesc, $matches)) {
|
||||||
$this->subtag = rtrim($matches[1], ' .');
|
$this->subtag = rtrim($matches[1], ' .');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find tags
|
||||||
if (preg_match('~Tags: ([^\\r\\n]+)~', $this->longdesc, $matches)) {
|
if (preg_match('~Tags: ([^\\r\\n]+)~', $this->longdesc, $matches)) {
|
||||||
$this->tags = array_map('trim', explode(',', $matches[1]));
|
$this->tags = array_map('trim', explode(',', $matches[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract short description
|
||||||
$parts = explode("\n", $this->longdesc);
|
$parts = explode("\n", $this->longdesc);
|
||||||
$this->shortdesc = array_shift($parts);
|
$this->shortdesc = array_shift($parts);
|
||||||
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
|
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
|
||||||
|
|
||||||
// Filter longdesc
|
// Filters for longdesc
|
||||||
$this->longdesc = str_replace("\r", "", $this->longdesc); // filter windows CR
|
$this->longdesc = str_replace("\r", "", $this->longdesc); // filter windows CR
|
||||||
|
|
||||||
$prefix_html = '';
|
$prefix_html = '';
|
||||||
@ -112,6 +134,10 @@ class CProject {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function numDownloads() {
|
||||||
|
return count($this->downloads);
|
||||||
|
}
|
||||||
|
|
||||||
public function write() {
|
public function write() {
|
||||||
|
|
||||||
// Generate image thumbnails
|
// Generate image thumbnails
|
||||||
@ -197,7 +223,7 @@ class CProject {
|
|||||||
<?php if (count($this->images)) { ?>
|
<?php if (count($this->images)) { ?>
|
||||||
<div class="projimg">
|
<div class="projimg">
|
||||||
<?php foreach($this->images as $idx => $origname) { ?>
|
<?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 } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -125,6 +125,9 @@ function buildcommon() {
|
|||||||
data-sort-mt="-<?=$pr->lastupdate?>"
|
data-sort-mt="-<?=$pr->lastupdate?>"
|
||||||
data-sort-ct="<?=$i?>"
|
data-sort-ct="<?=$i?>"
|
||||||
data-sort-al="<?=$alphaidx[$i]?>"
|
data-sort-al="<?=$alphaidx[$i]?>"
|
||||||
|
data-sort-nr="-<?=$pr->numreleases?>"
|
||||||
|
data-sort-nf="-<?=$pr->numDownloads()?>"
|
||||||
|
data-sort-ls="-<?=$pr->lifespan?>"
|
||||||
>
|
>
|
||||||
<td>
|
<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>
|
<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>
|
||||||
|
@ -73,26 +73,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var sort_update = function(sort_by) {
|
var sort_update = function(sort_by) {
|
||||||
switch(sort_by) {
|
|
||||||
case 'a':
|
|
||||||
default: {
|
|
||||||
sort_rows(function(el) {
|
sort_rows(function(el) {
|
||||||
return el.getAttribute('data-sort-ct');
|
return el.getAttribute(sort_by);
|
||||||
});
|
});
|
||||||
} 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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window.sortUpdate = sort_update;
|
window.sortUpdate = sort_update;
|
||||||
|
Reference in New Issue
Block a user