Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#33842] Fixed, the atom feed does not convert relative URLs to absolute URLs. #3754

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions libraries/joomla/document/feed/renderer/atom.php
Expand Up @@ -79,6 +79,7 @@ public function render($name = '', $params = null, $content = null)
{
$feed .= " xml:lang=\"" . $data->language . "\"";
}

$feed .= ">\n";
$feed .= " <title type=\"text\">" . $feed_title . "</title>\n";
$feed .= " <subtitle type=\"text\">" . htmlspecialchars($data->description, ENT_COMPAT, 'UTF-8') . "</subtitle>\n";
Expand All @@ -97,6 +98,7 @@ public function render($name = '', $params = null, $content = null)
$feed .= " <category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
}
}

$feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
$feed .= " <id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n";
$feed .= " <updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
Expand All @@ -105,18 +107,20 @@ public function render($name = '', $params = null, $content = null)
{
$feed .= " <author>\n";
$feed .= " <name>" . $data->editor . "</name>\n";

if ($data->editorEmail != "")
{
$feed .= " <email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
}

$feed .= " </author>\n";
}

$feed .= " <generator uri=\"http://joomla.org\" version=\"1.6\">" . $data->getGenerator() . "</generator>\n";
$feed .= ' <link rel="self" type="application/atom+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";

for ($i = 0, $count = count($data->items); $i < $count; $i++)
{

if (!preg_match('/[\x80-\xFF]/', $data->items[$i]->link))
{
$itemlink = $data->items[$i]->link;
Expand Down Expand Up @@ -158,12 +162,13 @@ public function render($name = '', $params = null, $content = null)
{
$feed .= " <email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
}

$feed .= " </author>\n";
}

if ($data->items[$i]->description != "")
{
$feed .= " <summary type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</summary>\n";
$feed .= " <summary type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</summary>\n";
$feed .= " <content type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</content>\n";
}

Expand All @@ -187,10 +192,12 @@ public function render($name = '', $params = null, $content = null)
$feed .= " <link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\""
. $data->items[$i]->enclosure->type . "\" length=\"" . $data->items[$i]->enclosure->length . "\" />\n";
}

$feed .= " </entry>\n";
}

$feed .= "</feed>\n";

return $feed;
}
}
22 changes: 4 additions & 18 deletions libraries/joomla/document/feed/renderer/rss.php
Expand Up @@ -108,6 +108,7 @@ public function render($name = '', $params = null, $content = null)
{
$feed .= " <description><![CDATA[" . $data->image->description . "]]></description>\n";
}

$feed .= " </image>\n";
}

Expand Down Expand Up @@ -181,7 +182,6 @@ public function render($name = '', $params = null, $content = null)

for ($i = 0, $count = count($data->items); $i < $count; $i++)
{

if (!preg_match('/[\x80-\xFF]/', $data->items[$i]->link))
{
$itemlink = $data->items[$i]->link;
Expand All @@ -195,6 +195,7 @@ public function render($name = '', $params = null, $content = null)
{
$itemlink = str_replace(' ', '%20', $url . $itemlink);
}

$feed .= " <item>\n";
$feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
$feed .= " <link>" . str_replace(' ', '%20', $itemlink) . "</link>\n";
Expand Down Expand Up @@ -263,25 +264,10 @@ public function render($name = '', $params = null, $content = null)

$feed .= " </item>\n";
}

$feed .= " </channel>\n";
$feed .= "</rss>\n";
return $feed;
}

/**
* Convert links in a text from relative to absolute
*
* @param string $text The text processed
*
* @return string Text with converted links
*
* @since 11.1
*/
public function _relToAbs($text)
{
$base = JUri::base();
$text = preg_replace("/(href|src)=\"(?!http|ftp|https|mailto|data)([^\"]*)\"/", "$1=\"$base\$2\"", $text);

return $text;
return $feed;
}
}
18 changes: 18 additions & 0 deletions libraries/joomla/document/renderer.php
Expand Up @@ -72,4 +72,22 @@ public function getContentType()
{
return $this->_mime;
}

/**
* Convert links in a text from relative to absolute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write in somewhere in this docblock that it's used for the feed renderers for future reference please

*
* @param string $text The text processed
*
* @return string Text with converted links
*
* @since 11.1
*/
protected function _relToAbs($text)
{
$base = JUri::base();
$text = preg_replace("/(href|src)=\"(?!http|ftp|https|mailto|data)([^\"]*)\"/", "$1=\"$base\$2\"", $text);

return $text;
}

}