diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-27 07:12:55 +0100 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-27 07:12:55 +0100 |
commit | f3bcaebab57a16ac25a935e85a7aae3b8c8bd58f (patch) | |
tree | 9523763a530701715b0cc48570d7bf2d87b249c5 /index.php | |
parent | 8affe69c351110b488d485bbafcb777beaca4862 (diff) |
index: add more information on symlinks
This requires the supporting CSS change of adding :first-of-type
selectors for the icons, because there may now be 2 <a> elements
on a row for links.
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -52,6 +52,13 @@ function classify($root, $dirname, $filename) { if ($filename === '..') { return [ [ 'dir', 'parent' ], $stat]; } $classes = array(); + + if (stat_is_link($stat)) { + $classes[] = 'link'; + $lstat = $stat; + $stat = stat($filepath); + } + if ($parts == 0) { // in the top-level if (stat_is_dir($stat) && is_dir($filepath.'/os')) { @@ -70,7 +77,6 @@ function classify($root, $dirname, $filename) { } } if ($filename[0] === '.' || substr($filename, -1) === '~') { $classes[] = 'hidden'; } - if (stat_is_link($stat)) { $classes[] = 'link'; } if (stat_is_dir( $stat)) { $classes[] = 'dir'; } if (stat_is_file($stat)) { $classes[] = 'file'; } @@ -78,6 +84,9 @@ function classify($root, $dirname, $filename) { if (preg_match("/\.tar(\..z|\.bz2)?$/", $filename) == 1) { $classes[] = 'tar'; } $classes[] = pathinfo($filename, PATHINFO_EXTENSION); + if (isset($lstat)) { + $stat = $lstat; + } return [ $classes, $stat ]; } @@ -143,11 +152,14 @@ if (!is_dir($root.'/'.$dirname)) { if ($filename === '..' && is_root($root,$dirname)) { continue; } list($classes, $stat) = classify($root, $dirname, $filename); echo "\t\t\t\t<tr class=\"".implode(' ', $classes)."\">"; + + echo "<td>"; + echo "<a href=\"".htmlentities($filename)."\">".htmlentities($filename)."</a>"; if (stat_is_link($stat)) { - echo "<td><a href=\"".htmlentities($filename)."\">".htmlentities($filename)."</a> -> ".htmlentities(readlink($root.'/'.$dirname.'/'.$filename))."</td>"; - } else { - echo "<td><a href=\"".htmlentities($filename)."\">".htmlentities($filename)."</a></td>"; + $target = readlink($root.'/'.$dirname.'/'.$filename); + echo " -> <a href=\"".htmlentities($target)."\">".htmlentities($target)."</a>"; } + echo "</td>"; if ($filename === '..') { echo '<td></td><td></td>'; |