Browse Source

file counter update

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

24
themes/beauty/controller/CommandController.php

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

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

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

Loading…
Cancel
Save