Browse Source

bug fix for empty tag file can not be parsed

master
filesite 7 months ago
parent
commit
81a874f8a6
  1. 36
      lib/DirScanner.php
  2. 17
      themes/tajian/views/layout/main.php

36
lib/DirScanner.php

@ -92,31 +92,35 @@ Class DirScanner {
//解析描述文件内容 //解析描述文件内容
//snapshot相对路径完善,支持secure_link //snapshot相对路径完善,支持secure_link
//bug fix: 允许空内容文件,如:刚创建的分类文件
private function parseDescriptionFiles($realpath) { private function parseDescriptionFiles($realpath) {
$filename = $this->getFilenameWithoutExtension($realpath); $filename = $this->getFilenameWithoutExtension($realpath);
$pathinfo = pathinfo($realpath); $pathinfo = pathinfo($realpath);
$tmp = explode('_', $filename); $tmp = explode('_', $filename);
$field = array_pop($tmp); $field = array_pop($tmp); //['title', 'snapshot']
$content = @file_get_contents($realpath); $content = @file_get_contents($realpath);
if (empty($content)) {return [];} if (!empty($content)) {
$content = trim($content); $content = trim($content);
}
$data = array(); $data = array();
if (in_array($field, ['title', 'snapshot'])) {
if ($field == 'snapshot') { //如果是快照图片,获取图片相对路径
$img_realpath = realpath("{$pathinfo['dirname']}/{$content}"); if (!empty($content) && $field == 'snapshot') {
if (file_exists($img_realpath)) { $img_realpath = realpath("{$pathinfo['dirname']}/{$content}");
$id = $this->getId($img_realpath); if (file_exists($img_realpath)) {
$fp = fopen($img_realpath, 'r'); $id = $this->getId($img_realpath);
$fstat = fstat($fp); $fp = fopen($img_realpath, 'r');
fclose($fp); $fstat = fstat($fp);
$img_filename = $this->getFilenameWithoutExtension($img_realpath); fclose($fp);
$img_pathinfo = pathinfo($img_realpath); $img_filename = $this->getFilenameWithoutExtension($img_realpath);
$extension = strtolower($img_pathinfo['extension']); $img_pathinfo = pathinfo($img_realpath);
$content = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_filename, $extension, $fstat['mtime'] ); $extension = strtolower($img_pathinfo['extension']);
} $content = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_filename, $extension, $fstat['mtime'] );
} }
} }
//返回文件数据
$data[$field] = $content; $data[$field] = $content;
return $data; return $data;

17
themes/tajian/views/layout/main.php

@ -2,6 +2,11 @@
//常用方法 //常用方法
require_once __DIR__ . '/../../../../plugins/Html.php'; require_once __DIR__ . '/../../../../plugins/Html.php';
$linkPrefix = '';
//多用户路径支持
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$linkPrefix = '/' . FSC::$app['user_id'];
}
?><!DocType html> ?><!DocType html>
<html> <html>
<head> <head>
@ -34,11 +39,11 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
<div class="app_layout_side"> <div class="app_layout_side">
<div class="menu_ls g_ls_menus"> <div class="menu_ls g_ls_menus">
<a class="this_set" href="/" title=""> <a class="this_set" href="<?=$linkPrefix?>/" title="">
<img src="/img/choice.svg" alt="星星图标" /> <img src="/img/choice.svg" alt="星星图标" />
<span>推荐</span> <span>推荐</span>
</a> </a>
<a href="/site/new" title=""> <a href="<?=$linkPrefix?>/site/new" title="">
<img src="/img/addvideos.svg" alt="添加图标" /> <img src="/img/addvideos.svg" alt="添加图标" />
<span>添加</span> <span>添加</span>
</a> </a>
@ -53,16 +58,10 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
$selectedId = !empty($viewData['cateId']) ? $viewData['cateId'] : ''; $selectedId = !empty($viewData['cateId']) ? $viewData['cateId'] : '';
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['tags'])) { //显示tags分类 if (!empty($viewData['tags'])) { //显示tags分类
$tagLink = '/list/';
//多用户路径支持
if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) {
$tagLink = '/' . FSC::$app['user_id'] . '/list/';
}
foreach($viewData['tags'] as $id => $item) { foreach($viewData['tags'] as $id => $item) {
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'this_set' : ''; $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'this_set' : '';
echo <<<eof echo <<<eof
<a href="{$tagLink}?id={$item['id']}" class="{$selected}"> <a href="{$linkPrefix}/list/?id={$item['id']}" class="{$selected}">
<img src="/img/other.svg" alt="菜单图标" /> <img src="/img/other.svg" alt="菜单图标" />
<span>{$item['name']}</span> <span>{$item['name']}</span>
</a> </a>

Loading…
Cancel
Save