From d62b4bd248ac995b745893187dbce6f0c107cb34 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 10 Jun 2014 11:42:51 +0000 Subject: [PATCH] touched up tag comparision in file view --- codepot/src/codepot/views/file_home.php | 33 ++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/codepot/src/codepot/views/file_home.php b/codepot/src/codepot/views/file_home.php index 9270e4a1..06f6b857 100644 --- a/codepot/src/codepot/views/file_home.php +++ b/codepot/src/codepot/views/file_home.php @@ -53,18 +53,43 @@ if (empty($files)) } else { + function comp_tag ($a, $b) + { + $x = explode ('.', $a); + $y = explode ('.', $b); + $cx = count($x); + $cy = count($y); + $max = max($cx, $cy); + + for ($i = 0; $i < $max; $i++) + { + if (is_numeric($x[$i]) && is_numeric($y[$i])) + { + $q = (int)$x[$i] - (int)$y[$i]; + } + else + { + $q = strcmp($x[$i], $y[$i]); + } + if ($q != 0) return $q; + } + + return ($cx > $cy)? 1: + ($cx < $cy)? -1: 0; + } + function comp_files ($a, $b) { - //$cmp = strcmp ($b->tag, $a->tag); - $cmp = version_compare ($b->tag, $a->tag); + //$cmp = version_compare ($b->tag, $a->tag); + $cmp = comp_tag ($b->tag, $a->tag); if ($cmp == 0) { - return strcmp ($a->name, $b->name); + $cmp = strcmp ($a->name, $b->name); } return $cmp; } - usort ($files, 'comp_files'); + usort ($files, 'comp_files'); print ''; print '';