diff --git a/themes/beauty/controller/CommandController.php b/themes/beauty/controller/CommandController.php index 0edf361..52e816f 100644 --- a/themes/beauty/controller/CommandController.php +++ b/themes/beauty/controller/CommandController.php @@ -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; //统计文件数量 $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; 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; $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); diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index e460715..4022189 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -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 = <<{$fileTotal} +eof; } + $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'active' : ''; echo << directories {$item['directory']} - {$fileTotal} + {$htmlFileTotal} 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 = <<{$fileTotal} +eof; + } echo << folder {$title} + {$htmlFileTotal} {$lockIcon}