Skip to content

Commit

Permalink
Fixes some issues in SMF\Actions\Feed and SMF\Tasks\ExportProfileData
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
  • Loading branch information
Sesquipedalian committed Jul 3, 2024
1 parent 44369f1 commit 461eb1c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
78 changes: 39 additions & 39 deletions Sources/Actions/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public function getXmlMembers(): array
$row = filter_var($row, FILTER_CALLBACK, ['options' => '\\SMF\\Utils::cleanXml']);

// Create a GUID for each member using the tag URI scheme
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member'];
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', (int) $row['date_registered']) . ':member=' . $row['id_member'];

// Make the data look rss-ish.
if ($this->format == 'rss' || $this->format == 'rss2') {
Expand All @@ -599,7 +599,7 @@ public function getXmlMembers(): array
],
[
'tag' => 'pubDate',
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', $row['date_registered']),
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', (int) $row['date_registered']),
],
[
'tag' => 'guid',
Expand Down Expand Up @@ -649,11 +649,11 @@ public function getXmlMembers(): array
],
[
'tag' => 'published',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['date_registered']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $row['date_registered']),
],
[
'tag' => 'updated',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['last_login']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $row['last_login']),
],
[
'tag' => 'id',
Expand All @@ -676,7 +676,7 @@ public function getXmlMembers(): array
],
[
'tag' => 'time',
'attributes' => ['label' => Lang::$txt['date_registered'], 'UTC' => Time::gmstrftime('%F %T', $row['date_registered'])],
'attributes' => ['label' => Lang::$txt['date_registered'], 'UTC' => Time::gmstrftime('%F %T', (int) $row['date_registered'])],
'content' => Utils::htmlspecialchars(strip_tags(Time::create('@' . $row['date_registered'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false))),
],
[
Expand Down Expand Up @@ -807,7 +807,7 @@ function ($a, $b) {
}

// Create a GUID for this topic using the tag URI scheme
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic'];
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', (int) $row['poster_time']) . ':topic=' . $row['id_topic'];

// Being news, this actually makes sense in rss format.
if ($this->format == 'rss' || $this->format == 'rss2') {
Expand Down Expand Up @@ -856,7 +856,7 @@ function ($a, $b) {
],
[
'tag' => 'pubDate',
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', $row['poster_time']),
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', (int) $row['poster_time']),
],
[
'tag' => 'guid',
Expand Down Expand Up @@ -958,11 +958,11 @@ function ($a, $b) {
],
[
'tag' => 'published',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $row['poster_time']),
],
[
'tag' => 'updated',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? (int) $row['poster_time'] : (int) $row['modified_time']),
],
[
'tag' => 'id',
Expand Down Expand Up @@ -1029,7 +1029,7 @@ function ($a, $b) {
'content' => [
[
'tag' => 'time',
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', $row['poster_time'])],
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', (int) $row['poster_time'])],
'content' => Utils::htmlspecialchars(strip_tags(Time::create('@' . $row['poster_time'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false))),
],
[
Expand Down Expand Up @@ -1247,7 +1247,7 @@ function ($a, $b) {
}

// Create a GUID for this post using the tag URI scheme
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg'];
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', (int) $row['poster_time']) . ':msg=' . $row['id_msg'];

// Doesn't work as well as news, but it kinda does..
if ($this->format == 'rss' || $this->format == 'rss2') {
Expand Down Expand Up @@ -1296,7 +1296,7 @@ function ($a, $b) {
],
[
'tag' => 'pubDate',
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', $row['poster_time']),
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', (int) $row['poster_time']),
],
[
'tag' => 'guid',
Expand Down Expand Up @@ -1398,11 +1398,11 @@ function ($a, $b) {
],
[
'tag' => 'published',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $row['poster_time']),
],
[
'tag' => 'updated',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? (int) $row['poster_time'] : (int) $row['modified_time']),
],
[
'tag' => 'id',
Expand Down Expand Up @@ -1469,7 +1469,7 @@ function ($a, $b) {
'content' => [
[
'tag' => 'time',
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', $row['poster_time'])],
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', (int) $row['poster_time'])],
'content' => Utils::htmlspecialchars(strip_tags(Time::create('@' . $row['poster_time'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false))),
],
[
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public function getXmlProfile(): array
$profile = filter_var($profile, FILTER_CALLBACK, ['options' => '\\SMF\\Utils::cleanXml']);

// Create a GUID for this member using the tag URI scheme
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', $profile['registered_timestamp']) . ':member=' . $profile['id'];
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', (int) $profile['registered_timestamp']) . ':member=' . $profile['id'];

if ($this->format == 'rss' || $this->format == 'rss2') {
$data[] = [
Expand All @@ -1637,7 +1637,7 @@ public function getXmlProfile(): array
],
[
'tag' => 'pubDate',
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', $profile['registered_timestamp']),
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', (int) $profile['registered_timestamp']),
],
[
'tag' => 'guid',
Expand Down Expand Up @@ -1718,11 +1718,11 @@ public function getXmlProfile(): array
],
[
'tag' => 'published',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $profile['registered_timestamp']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $profile['registered_timestamp']),
],
[
'tag' => 'updated',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $profile['last_login_timestamp']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $profile['last_login_timestamp']),
],
[
'tag' => 'id',
Expand Down Expand Up @@ -1770,12 +1770,12 @@ public function getXmlProfile(): array
],
[
'tag' => 'last-login',
'attributes' => ['label' => Lang::$txt['lastLoggedIn'], 'UTC' => Time::gmstrftime('%F %T', $profile['last_login_timestamp'])],
'attributes' => ['label' => Lang::$txt['lastLoggedIn'], 'UTC' => Time::gmstrftime('%F %T', (int) $profile['last_login_timestamp'])],
'content' => Time::create('@' . $profile['last_login_timestamp'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false),
],
[
'tag' => 'registered',
'attributes' => ['label' => Lang::$txt['date_registered'], 'UTC' => Time::gmstrftime('%F %T', $profile['registered_timestamp'])],
'attributes' => ['label' => Lang::$txt['date_registered'], 'UTC' => Time::gmstrftime('%F %T', (int) $profile['registered_timestamp'])],
'content' => Time::create('@' . $profile['registered_timestamp'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false),
],
[
Expand Down Expand Up @@ -1978,7 +1978,7 @@ public function getXmlPosts(): array
// Old SMF versions autolinked during output rather than input,
// so maintain expected behaviour for those old messages.
if (version_compare($row['version'], '3.0', '<')) {
$row['body'] = Autolinker::load(true)->makeLinks($row[$this->format === 'smf' ? 'body_html' : 'body']);
$row['body'] = Autolinker::load(true)->makeLinks($row['body']);
}

// If using our own format, we want both the raw and the parsed content.
Expand Down Expand Up @@ -2008,7 +2008,7 @@ function ($a, $b) {
}

// Create a GUID for this post using the tag URI scheme
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg'];
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', (int) $row['poster_time']) . ':msg=' . $row['id_msg'];

if ($this->format == 'rss' || $this->format == 'rss2') {
// Only one attachment allowed in RSS.
Expand Down Expand Up @@ -2056,7 +2056,7 @@ function ($a, $b) {
],
[
'tag' => 'pubDate',
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', $row['poster_time']),
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', (int) $row['poster_time']),
],
[
'tag' => 'guid',
Expand Down Expand Up @@ -2153,11 +2153,11 @@ function ($a, $b) {
],
[
'tag' => 'published',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['poster_time']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $row['poster_time']),
],
[
'tag' => 'updated',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? $row['poster_time'] : $row['modified_time']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', empty($row['modified_time']) ? (int) $row['poster_time'] : (int) $row['modified_time']),
],
[
'tag' => 'id',
Expand Down Expand Up @@ -2323,12 +2323,12 @@ function ($a, $b) {
],
[
'tag' => 'time',
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', $row['poster_time'])],
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', (int) $row['poster_time'])],
'content' => Utils::htmlspecialchars(strip_tags(Time::create('@' . $row['poster_time'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false))),
],
[
'tag' => 'modified_time',
'attributes' => !empty($row['modified_time']) ? ['label' => Lang::$txt['modified_time'], 'UTC' => Time::gmstrftime('%F %T', $row['modified_time'])] : null,
'attributes' => !empty($row['modified_time']) ? ['label' => Lang::$txt['modified_time'], 'UTC' => Time::gmstrftime('%F %T', (int) $row['modified_time'])] : null,
'content' => !empty($row['modified_time']) ? Utils::htmlspecialchars(strip_tags(Time::create('@' . $row['modified_time'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false))) : null,
],
[
Expand Down Expand Up @@ -2421,15 +2421,15 @@ public function getXmlPMs(): array
);

while ($row = Db::$db->fetch_assoc($request)) {
$this->start_after = $row['id_pm'];
$this->start_after = (int) $row['id_pm'];

// If any control characters slipped in somehow, kill the evil things
$row = filter_var($row, FILTER_CALLBACK, ['options' => '\\SMF\\Utils::cleanXml']);

// Old SMF versions autolinked during output rather than input,
// so maintain expected behaviour for those old messages.
if (version_compare($row['version'], '3.0', '<')) {
$row['body'] = Autolinker::load(true)->makeLinks($row[$this->format === 'smf' ? 'body_html' : 'body']);
$row['body'] = Autolinker::load(true)->makeLinks($row['body']);
}

// If using our own format, we want both the raw and the parsed content.
Expand All @@ -2438,7 +2438,7 @@ public function getXmlPMs(): array
$recipients = array_combine(explode(',', $row['id_members_to']), explode($separator, $row['to_names']));

// Create a GUID for this post using the tag URI scheme
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', $row['msgtime']) . ':pm=' . $row['id_pm'];
$guid = 'tag:' . $this->host . ',' . gmdate('Y-m-d', (int) $row['msgtime']) . ':pm=' . $row['id_pm'];

if ($this->format == 'rss' || $this->format == 'rss2') {
$item = [
Expand All @@ -2453,7 +2453,7 @@ public function getXmlPMs(): array
],
[
'tag' => 'pubDate',
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', $row['msgtime']),
'content' => gmdate('D, d M Y H:i:s \\G\\M\\T', (int) $row['msgtime']),
],
[
'tag' => 'title',
Expand Down Expand Up @@ -2518,7 +2518,7 @@ public function getXmlPMs(): array
],
[
'tag' => 'updated',
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', $row['msgtime']),
'content' => Time::gmstrftime('%Y-%m-%dT%H:%M:%SZ', (int) $row['msgtime']),
],
[
'tag' => 'title',
Expand Down Expand Up @@ -2575,7 +2575,7 @@ public function getXmlPMs(): array
],
[
'tag' => 'sent_date',
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', $row['msgtime'])],
'attributes' => ['label' => Lang::$txt['date'], 'UTC' => Time::gmstrftime('%F %T', (int) $row['msgtime'])],
'content' => Utils::htmlspecialchars(strip_tags(Time::create('@' . $row['msgtime'], new \DateTimeZone(Config::$modSettings['default_timezone']))->format(null, false))),
],
[
Expand Down Expand Up @@ -2717,7 +2717,7 @@ public static function build(string $format, array $data, array $metadata, strin

// Sanitize feed metadata values.
foreach ($metadata as $mkey => $mvalue) {
$metadata[$mkey] = self::cdataParse(self::fixPossibleUrl($mvalue));
$metadata[$mkey] = self::cdataParse(self::fixPossibleUrl((string) $mvalue));
}

$ns_string = '';
Expand Down Expand Up @@ -3086,7 +3086,7 @@ protected static function dumpTags(array $data, int $i, string $format = '', arr

if (!empty($attrs)) {
foreach ($attrs as $attr_key => $attr_value) {
Utils::$context['feed']['items'] .= ' ' . $attr_key . '="' . self::fixPossibleUrl($attr_value) . '"';
Utils::$context['feed']['items'] .= ' ' . $attr_key . '="' . self::fixPossibleUrl((string) $attr_value) . '"';
}
}

Expand All @@ -3103,12 +3103,12 @@ protected static function dumpTags(array $data, int $i, string $format = '', arr
Utils::$context['feed']['items'] .= "\n" . str_repeat("\t", $i);
}
// A string with returns in it.... show this as a multiline element.
elseif (str_contains($val, "\n")) {
Utils::$context['feed']['items'] .= "\n" . (!empty($element['cdata']) || $forceCdata ? self::cdataParse(self::fixPossibleUrl($val), $ns, $forceCdata) : self::fixPossibleUrl($val)) . "\n" . str_repeat("\t", $i);
elseif (is_string($val) && str_contains($val, "\n")) {
Utils::$context['feed']['items'] .= "\n" . (!empty($element['cdata']) || $forceCdata ? self::cdataParse(self::fixPossibleUrl((string) $val), $ns, $forceCdata) : self::fixPossibleUrl((string) $val)) . "\n" . str_repeat("\t", $i);
}
// A simple string.
else {
Utils::$context['feed']['items'] .= !empty($element['cdata']) || $forceCdata ? self::cdataParse(self::fixPossibleUrl($val), $ns, $forceCdata) : self::fixPossibleUrl($val);
Utils::$context['feed']['items'] .= !empty($element['cdata']) || $forceCdata ? self::cdataParse(self::fixPossibleUrl((string) $val), $ns, $forceCdata) : self::fixPossibleUrl((string) $val);
}

// Ending tag.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Tasks/ExportProfileData.php
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ public static function post_parseAttachBBC(array &$attachContext): void
static $dltokens;

if (empty($dltokens[Utils::$context['xmlnews_uid']])) {
$idhash = hash_hmac('sha1', Utils::$context['xmlnews_uid'], Config::getAuthSecret());
$idhash = hash_hmac('sha1', (string) Utils::$context['xmlnews_uid'], Config::getAuthSecret());

$dltokens[Utils::$context['xmlnews_uid']] = hash_hmac('sha1', $idhash, Config::getAuthSecret());
}
Expand All @@ -1963,7 +1963,7 @@ public static function post_parseAttachBBC(array &$attachContext): void
/**
* Adjusts the format of the HTML produced by the attach BBCode.
*/
public static function attach_bbc_validate(string &$returnContext, array $currentAttachment, array $tag, array $data, array $disabled, array $params): void
public static function attach_bbc_validate(string &$returnContext, array $currentAttachment, array $tag, array|string $data, array $disabled, array $params): void
{
$orig_link = '<a href="' . $currentAttachment['orig_href'] . '" class="bbc_link">' . Lang::$txt['export_download_original'] . '</a>';

Expand Down

0 comments on commit 461eb1c

Please sign in to comment.