Skip to content

Commit

Permalink
Fixes strict typing issues in SMF\Actions\Feed
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Jul 3, 2024
1 parent 44369f1 commit 6903062
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 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 @@ -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 @@ -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

0 comments on commit 6903062

Please sign in to comment.