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

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

@ -2,6 +2,11 @@ @@ -2,6 +2,11 @@
//常用方法
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>
<html>
<head>
@ -34,11 +39,11 @@ require_once __DIR__ . '/../../../../plugins/Html.php'; @@ -34,11 +39,11 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
<div class="app_layout_side">
<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="星星图标" />
<span>推荐</span>
</a>
<a href="/site/new" title="">
<a href="<?=$linkPrefix?>/site/new" title="">
<img src="/img/addvideos.svg" alt="添加图标" />
<span>添加</span>
</a>
@ -53,16 +58,10 @@ require_once __DIR__ . '/../../../../plugins/Html.php'; @@ -53,16 +58,10 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
$selectedId = !empty($viewData['cateId']) ? $viewData['cateId'] : '';
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
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) {
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'this_set' : '';
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="菜单图标" />
<span>{$item['name']}</span>
</a>

Loading…
Cancel
Save