Skip to content

Commit 0ea635b

Browse files
committed
Sort directories before files and update design
1 parent 5b77b74 commit 0ea635b

File tree

4 files changed

+31
-41
lines changed

4 files changed

+31
-41
lines changed

src/functions.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
if ($SplFileInfo->isDir())
8181
{
8282
if (isset($_GET['order_by']) && in_array($_GET['order_by'], [
83-
'type',
8483
'filename',
8584
'size',
8685
'owner',
@@ -104,7 +103,6 @@
104103
sort($paths);
105104

106105
if (isset($_GET['order_by']) && in_array($_GET['order_by'], [
107-
'type',
108106
'filename',
109107
'size',
110108
'owner',
@@ -130,15 +128,25 @@
130128
$paths = array_reverse($paths);
131129
}
132130

133-
$count = count($paths);
131+
$dirs = [];
132+
$files = [];
134133

135-
for ($i = 0; $i < $count; $i++)
134+
foreach ($paths as $path)
136135
{
137-
$paths[$i]['mTime'] = date('Y-m-d H:i:s', $paths[$i]['mTime']);
138-
$paths[$i]['size'] = strpos($paths[$i]['size'], 'item') !== false
139-
? $paths[$i]['size']
140-
: $GLOBALS['function_size_conversion']($paths[$i]['size']);
136+
$path['mTime'] = date('Y-m-d H:i:s', $path['mTime']);
137+
$path['size'] = $path['isDir']
138+
? $path['size'] . ' item' . ($path['size'] < 2 ? '' : 's')
139+
: $GLOBALS['function_size_conversion']($path['size']);
140+
141+
if ($path['isDir'])
142+
{
143+
$dirs[] = $path;
144+
}
145+
else
146+
{
147+
$files[] = $path;
148+
}
141149
}
142150

143-
return $paths;
151+
return array_merge($dirs, $files);
144152
};

src/pages/_template.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
min-width: 20px;
9191
display: block;
9292
}
93+
td span {
94+
color: gray;
95+
min-width: 30px;
96+
display: inline-block;
97+
text-indent: 0;
98+
}
9399
.date {
94100
float: right;
95101
font-size: .875rem;
@@ -140,31 +146,6 @@
140146
</p>
141147

142148
<script type="text/javascript">
143-
function addClass(el, className)
144-
{
145-
if (el.classList)
146-
{
147-
el.classList.add(className);
148-
}
149-
else
150-
{
151-
el.className += ' ' + className;
152-
}
153-
}
154-
155-
function removeClass(el, className)
156-
{
157-
if (el.classList)
158-
{
159-
el.classList.remove(className);
160-
}
161-
else
162-
{
163-
el.className = el.className.replace(new RegExp('(^|\\b)' +
164-
className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
165-
}
166-
}
167-
168149
var uris = document.getElementsByClassName('uri');
169150

170151
for (var i = 0; i < uris.length; i++)
@@ -174,15 +155,15 @@ className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
174155
{
175156
if (uris[i].getAttribute('data-id') <= this.getAttribute('data-id'))
176157
{
177-
addClass(uris[i], 'active');
158+
uris[i].classList.add('active');
178159
}
179160
}
180161
}, true);
181162

182163
uris[i].addEventListener('mouseout', function () {
183164
for (var i = 0; i < uris.length; i++)
184165
{
185-
removeClass(uris[i], 'active');
166+
uris[i].classList.remove('active');
186167
}
187168
}, true);
188169
}

src/pages/default.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<table>
1010
<thead>
1111
<tr>
12-
<?= $function_order_link('type', 'Type') ?>
1312
<?= $function_order_link('filename', 'Name') ?>
1413
<?= $function_order_link('size', 'Size') ?>
1514
<?= $function_order_link('owner', 'Owner') ?>
@@ -21,13 +20,15 @@
2120
<tbody>
2221
<?php if(empty($paths)): ?>
2322
<tr>
24-
<td colspan="7">This directory is empty.</td>
23+
<td colspan="6">This directory is empty.</td>
2524
</tr>
2625
<?php endif ?>
2726
<?php foreach($paths as $path): ?>
2827
<tr>
29-
<td><?= $path['type'] ?></td>
30-
<td><a href="<?= $path['href'] ?>"><?= $path['filename'] ?></a></td>
28+
<td>
29+
<span><?= $path['type'] ?></span>
30+
<a href="<?= $path['href'] ?>"><?= $path['filename'] ?></a>
31+
</td>
3132
<td><?= $path['size'] ?></td>
3233
<td><?= $path['owner'] ?></td>
3334
<td><?= $path['group'] ?></td>

src/server_router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
'realPath' => $SplFileInfo->getRealPath(),
123123
'filename' => $SplFileInfo->getFilename(),
124124
'isDir' => $SplFileInfo->isDir(),
125-
'size' => $SplFileInfo->isDir() ? iterator_count($fi) . ' items' : $SplFileInfo->getSize(),
125+
'size' => $SplFileInfo->isDir() ? iterator_count($fi) : $SplFileInfo->getSize(),
126126
'owner' => $SplFileInfo->getOwner(),
127127
'group' => $SplFileInfo->getGroup(),
128128
'perms' => substr(sprintf('%o', $SplFileInfo->getPerms()), -4),

0 commit comments

Comments
 (0)