Browse Source

file counter update

master
filesite 1 month ago
parent
commit
b02668f5c5
  1. 54
      themes/beauty/controller/CommandController.php
  2. 17
      themes/beauty/views/site/index.php

54
themes/beauty/controller/CommandController.php

@ -156,16 +156,20 @@ eof; @@ -156,16 +156,20 @@ eof;
$rootDir = __DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'];
$rootDir = realpath($rootDir);
if ($dirpath == $rootDir) {
return '';
}
if (strpos($dirpath, $rootDir) !== false) {
$dirs = str_replace($rootDir, '', $dirpath);
$dirs = preg_replace('/\/$/', '', $dirs);
$arr = explode('/', $dirs);
$num = count($arr);
if ($num >= 2) {
if ($num >= 1) {
$left = array_slice($arr, 0, $num-1);
return realpath( $rootDir . '/' . implode('/', $left) );
}else {
return $rootDir;
return '';
}
}
@ -195,9 +199,7 @@ eof; @@ -195,9 +199,7 @@ eof;
//统计文件数量
$dirId = $scanner->getId($dirpath);
$parentDir = $this->getParentDir($dirpath);
$parentId = $scanner->getId($parentDir);
$this->updateAllDirTreeCache($dirId, $parentId, $dirTree);
$this->updateAllDirTreeCache($dirId, $dirpath, $dirTree, $scanner);
$scanResults = $scanner->getScanResults();
echo 'Total directories or files: ' . count($scanResults);
@ -434,7 +436,7 @@ eof; @@ -434,7 +436,7 @@ eof;
return true;
}
protected function updateAllDirTreeCache($dirId, $parentId, $dirTree) {
protected function updateAllDirTreeCache($dirId, $dirpath, $dirTree, $scanner) {
$cacheKey = $this->allDirTreeCacheKey;
$cacheData = Common::getCache($cacheKey);
if (empty($cacheData)) {
@ -478,25 +480,33 @@ eof; @@ -478,25 +480,33 @@ eof;
$cacheData[$dirId]['audio_total'] = $audioNum;
echo "File total: {$dirId}: image {$imgNum}, video {$videoNum}, audio {$audioNum}\n";
//更新父目录数据
if (!empty($cacheData[$parentId])) {
if (isset($cacheData[$parentId]['image_total'])) {
$cacheData[$parentId]['image_total'] += $imgNum;
}else {
$cacheData[$parentId]['image_total'] = $imgNum;
}
//更新所有父目录数据
$parentDir = $this->getParentDir($dirpath);
while (!empty($parentDir)) {
//echo "{$dirpath} => {$parentDir}\n";
$parentId = $scanner->getId($parentDir);
if (!empty($cacheData[$parentId])) {
if (isset($cacheData[$parentId]['image_total'])) {
$cacheData[$parentId]['image_total'] += $imgNum;
}else {
$cacheData[$parentId]['image_total'] = $imgNum;
}
if (isset($cacheData[$parentId]['video_total'])) {
$cacheData[$parentId]['video_total'] += $videoNum;
}else {
$cacheData[$parentId]['video_total'] = $videoNum;
}
if (isset($cacheData[$parentId]['video_total'])) {
$cacheData[$parentId]['video_total'] += $videoNum;
}else {
$cacheData[$parentId]['video_total'] = $videoNum;
}
if (isset($cacheData[$parentId]['audio_total'])) {
$cacheData[$parentId]['audio_total'] += $audioNum;
}else {
$cacheData[$parentId]['audio_total'] = $audioNum;
if (isset($cacheData[$parentId]['audio_total'])) {
$cacheData[$parentId]['audio_total'] += $audioNum;
}else {
$cacheData[$parentId]['audio_total'] = $audioNum;
}
}
$dirpath = $parentDir;
$parentDir = $this->getParentDir($dirpath);
}
return Common::setCache($cacheKey, $cacheData);

17
themes/beauty/views/site/index.php

@ -97,17 +97,21 @@ eof; @@ -97,17 +97,21 @@ eof;
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['menus'])) { //只显示第一级目录
foreach ($viewData['menus'] as $index => $item) {
$fileTotal = 0;
$htmlFileTotal = '';
if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$item['id']]) ) {
$dirTotal = $viewData['dirCounters'][$item['id']];
$fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total'];
$htmlFileTotal = <<<eof
<small class="badge">{$fileTotal}</small>
eof;
}
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'active' : '';
echo <<<eof
<li class="{$selected}"><a href="{$item['path']}">
<img src="/img/beauty/folder.svg" alt="directories" width="17" class="menu-icon">
{$item['directory']}
<small class="badge">{$fileTotal}</small>
{$htmlFileTotal}
</a></li>
eof;
}
@ -279,11 +283,20 @@ eof; @@ -279,11 +283,20 @@ eof;
}
$title = !empty($dir['title']) ? $dir['title'] : $dir['directory'];
$htmlFileTotal = '';
if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$dir['id']]) ) {
$dirTotal = $viewData['dirCounters'][$dir['id']];
$fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total'];
$htmlFileTotal = <<<eof
<small class="badge">{$fileTotal}</small>
eof;
}
echo <<<eof
<div class="im_img_title">
<span class="folder_title">
<img src="/img/beauty/folder.svg" alt="folder" width="20">
{$title}
{$htmlFileTotal}
</span>
</div>
{$lockIcon}

Loading…
Cancel
Save