Skip to content

Commit

Permalink
! The datePublished should be in ISO 8601 (inc tz) for best acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
Spuds committed Jan 11, 2024
1 parent 1b34eb6 commit 50e042b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sources/subs/Likes.subs.php
Expand Up @@ -11,7 +11,7 @@
*
*/

use BBC\ParserWrapper;
use BBC\ParserWrapper;

/**
* Updates the like value for a post/member combo if there are no problems with
Expand Down
41 changes: 39 additions & 2 deletions sources/subs/Metadata.integrate.php
Expand Up @@ -240,8 +240,8 @@ public function getPostSchema()
'url' => $this->data['href'],
'articleBody' => $this->data['html_body'],
'articleSection' => $board_info['name'] ?? '',
'datePublished' => $this->data['time'],
'dateModified' => !empty($this->data['modified']['name']) ? $this->data['modified']['time'] : $this->data['time'],
'datePublished' => $this->utc_time($this->data['timestamp']),
'dateModified' => !empty($this->data['modified']['name']) ? $this->utc_time($this->data['modified']['timestamp']) : $this->utc_time($this->data['timestamp']),
'interactionStatistic' => array(
'@type' => 'InteractionCounter',
'interactionType' => 'https://schema.org/ReplyAction',
Expand Down Expand Up @@ -274,6 +274,43 @@ public function getPostSchema()
return $smd;
}

/**
* Convert a given timestamp to UTC time in the format of Atom date format.
*
* This method takes a timestamp as input and converts it to UTC time in the format of
* Atom date format (YYYY-MM-DDTHH:MM:SS+00:00).
*
* It considers the user's time offset, system's time offset, and the default timezone setting
* from the modifications/settings administration panel.
*
* @param int $timestamp The timestamp to convert to UTC time.
* @return string The UTC time in the format of Atom date format.
*/
private function utc_time($timestamp)
{
global $user_info, $modSettings;

// We do not receive raw unix time from prepareDisplayContext_callback, so back it out
if (!empty($user_info['time_offset']))
{
$timestamp -= ($modSettings['time_offset'] + $user_info['time_offset']) * 3600;
}

// Using the system timezone offset, format the date
try
{
$tz = empty($modSettings['default_timezone']) ? 'UTC' : $modSettings['default_timezone'];
$date = new DateTime( '@'.$timestamp, new DateTimeZone($tz));
}
catch (Exception $e)
{
return standardTime($timestamp);
}

// Something like 2012-12-21T11:11:00+00:00
return $date->format(DateTimeInterface::ATOM);
}

/**
* Checks the post for any attachments to use as an image. Will use the
* first below post attachment, failing that the first ILA, failing that nothing
Expand Down
1 change: 1 addition & 0 deletions themes/default/GenericControls.template.php
Expand Up @@ -193,6 +193,7 @@ function elk_editor() {
$(function() {
elk_editor();
});
</script>';
}

Expand Down

0 comments on commit 50e042b

Please sign in to comment.