diff --git a/lib/CProject.php b/lib/CProject.php index 3a3a393..7a99bbb 100644 --- a/lib/CProject.php +++ b/lib/CProject.php @@ -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 { images)) { ?>
images as $idx => $origname) { ?> - +
diff --git a/lib/template.php b/lib/template.php index 61f23f7..6faa8e0 100644 --- a/lib/template.php +++ b/lib/template.php @@ -125,6 +125,9 @@ function buildcommon() { data-sort-mt="-lastupdate?>" data-sort-ct="" data-sort-al="" + data-sort-nr="-numreleases?>" + data-sort-nf="-numDownloads()?>" + data-sort-ls="-lifespan?>" > projname]) ? '
' : '
')?>
diff --git a/static/site.js b/static/site.js index 783a4ae..8864376 100644 --- a/static/site.js +++ b/static/site.js @@ -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;