Fix media with no taken On info

This commit is contained in:
2022-04-26 07:47:20 +02:00
parent 131375fc4d
commit cdef1769e7
3 changed files with 12 additions and 11 deletions

View File

@@ -120,11 +120,12 @@ class Media extends PhpObject {
else { else {
$asMediaInfo = $this->getMediaInfoFromFile($sMediaName); $asMediaInfo = $this->getMediaInfoFromFile($sMediaName);
//Converting times to DB Time Zone, by using date() //Converting times to Site Time Zone, by using date()
//Media Timezone is kept in a separate field for later conversion to Local Time
$asDbInfo = array( $asDbInfo = array(
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(), Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
'filename' => $sMediaName, 'filename' => $sMediaName,
'taken_on' => ($asMediaInfo['taken_ts'] > 0)?date(Db::TIMESTAMP_FORMAT, $asMediaInfo['taken_ts']):'0000-00-00 00:00:00', 'taken_on' => date(Db::TIMESTAMP_FORMAT, ($asMediaInfo['taken_ts'] > 0)?$asMediaInfo['taken_ts']:$asMediaInfo['file_ts']),
'posted_on' => date(Db::TIMESTAMP_FORMAT, $asMediaInfo['file_ts']), 'posted_on' => date(Db::TIMESTAMP_FORMAT, $asMediaInfo['file_ts']),
'timezone' => $asMediaInfo['timezone'], 'timezone' => $asMediaInfo['timezone'],
'width' => $asMediaInfo['width'], 'width' => $asMediaInfo['width'],
@@ -151,7 +152,6 @@ class Media extends PhpObject {
$sMediaPath = self::getMediaPath($sMediaName); $sMediaPath = self::getMediaPath($sMediaName);
$sType = self::getMediaType($sMediaName); $sType = self::getMediaType($sMediaName);
$iTimeStamp = $iTakenOn = 0;
$iPostedOn = filemtime($sMediaPath); $iPostedOn = filemtime($sMediaPath);
$sTimeZone = date_default_timezone_get(); $sTimeZone = date_default_timezone_get();
$iWidth = 0; $iWidth = 0;
@@ -224,16 +224,13 @@ class Media extends PhpObject {
//Assign the correct Time Zone to $sTakenOn if it is not already contained in it. Then get Unix Timestamp //Assign the correct Time Zone to $sTakenOn if it is not already contained in it. Then get Unix Timestamp
//Time Zone (2nd parameter) will be ignored if already contained in $sTakenOn //Time Zone (2nd parameter) will be ignored if already contained in $sTakenOn
$iTakenOn = 0;
if($sTakenOn != '') { if($sTakenOn != '') {
$oTakenOn = new \DateTime($sTakenOn, new \DateTimeZone($sTimeZone)); $oTakenOn = new \DateTime($sTakenOn, new \DateTimeZone($sTimeZone));
$iTakenOn = $oTakenOn->format('U'); $iTakenOn = $oTakenOn->format('U');
} }
//Merge timestamps
$iTimeStamp = ($iTakenOn > 0)?$iTakenOn:$iPostedOn;
return array( return array(
'timestamp' => $iTimeStamp,
'timezone' => $sTimeZone, 'timezone' => $sTimeZone,
'taken_ts' => $iTakenOn, 'taken_ts' => $iTakenOn,
'file_ts' => $iPostedOn, 'file_ts' => $iPostedOn,

View File

@@ -10,20 +10,24 @@ use \Settings;
/* Timezones /* Timezones
* --------- * ---------
* Site Time: Time Zone in which the User is viewing the Site (default PHP/SQL Timezone) * Site Time: Timestamp converted to the Timezone from which the user is viewing the Site (default PHP/SQL Timezone)
* Local Time: Time Zone in which the Spot Owner is * Local Time: Timestamp converted to the Timezone from which the content (media/post/message) has been sent (Local Timezone stored in timezone field)
* *
* - Feeds (table `feeds`): * - Feeds (table `feeds`):
* - last_update: timestamp in Site Time * - last_update: timestamp in Site Time
* - Spot Messages (table `messages`): * - Spot Messages (table `messages`):
* - unix_time: UNIX (int) in UTC * - unix_time: UNIX (int) in UTC
* - site_time: timestamp in Site Time * - site_time: timestamp in Site Time
* - iso_time: raw ISO 8601 in Local Time * - iso_time: raw ISO 8601 in UTC or Local Time (spot messages are unreliable, timezone is then calculated from GPS coordinates)
* - posted_on: timestamp in Site Time
* - timezone: Local Timezone
* - Medias (table `medias`): * - Medias (table `medias`):
* - posted_on: timestamp in Site Time * - posted_on: timestamp in Site Time
* - taken_on: timestamp in Site Time * - taken_on: timestamp in Site Time
* - timezone: Local Timezone
* - Posts (table `posts`): * - Posts (table `posts`):
* - site_time: timestamp in Site Time * - site_time: timestamp in Site Time
* - timezone: Local Timezone
*/ */
class Spot extends Main class Spot extends Main

View File

@@ -992,7 +992,7 @@ function getMediaLink(asData, sType) {
.addIcon('fa-upload fa-lg fa-fw', true) .addIcon('fa-upload fa-lg fa-fw', true)
.append(asData.posted_on_formatted); .append(asData.posted_on_formatted);
var $TakenOn = (asData.taken_on == '0000-00-00 00:00:00')?'': var $TakenOn = (asData.taken_on == asData.posted_on)?'':
$('<span>', {'class': 'lb-caption-line', title: bTimeDiff?oSpot.lang('local_time', asData.taken_on_formatted_local):''}) $('<span>', {'class': 'lb-caption-line', title: bTimeDiff?oSpot.lang('local_time', asData.taken_on_formatted_local):''})
.addIcon('fa-'+asData.subtype+'-shot fa-lg fa-fw', true) .addIcon('fa-'+asData.subtype+'-shot fa-lg fa-fw', true)
.append(asData.taken_on_formatted); .append(asData.taken_on_formatted);