Browse Source

parse date from filename

master
filesite 5 months ago
parent
commit
d2fd4ef881
  1. 25
      plugins/Common.php
  2. 3
      themes/beauty/views/site/index.php

25
plugins/Common.php

@ -580,4 +580,29 @@ Class Common {
return false; return false;
} }
//从字符串中解析时间戳、日期,返回Y-m-d格式的日期字符串
public static function getDateFromString($str) {
$date = '';
try {
preg_match('/^.*(\d{13}).*$/', $str, $matches); //单位毫秒的时间戳
if (empty($matches[1])) { //再尝试单位秒的时间戳
preg_match('/^.*(\d{10}).*$/', $str, $matches);
if (empty($matches[1])) { //再尝试Y-m-d格式的日期
preg_match('/^.*(\d{4}[012]{2}\d{2}).*$/', $str, $matches);
if (!empty($matches[1])) {
$date = date('Y-m-d', strtotime($matches[1]));
}
}else {
$date = date('Y-m-d', (int)$matches[1]);
}
}else {
$date = date('Y-m-d', (int)$matches[1] / 1000);
}
}catch(Exception $e) {}
return $date;
}
} }

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

@ -228,7 +228,8 @@ eof;
$title = !empty($file['title']) ? $file['title'] : $file['filename']; $title = !empty($file['title']) ? $file['title'] : $file['filename'];
//图片、视频显示文件修改日期 //图片、视频显示文件修改日期
if (!empty($file['fstat']['mtime']) && !empty($file['fstat']['ctime'])) { $title = Common::getDateFromString($file['filename']);
if (empty($title) && !empty($file['fstat']['mtime']) && !empty($file['fstat']['ctime'])) {
$title = date('Y-m-d', min($file['fstat']['mtime'], $file['fstat']['ctime'])); $title = date('Y-m-d', min($file['fstat']['mtime'], $file['fstat']['ctime']));
} }

Loading…
Cancel
Save