Skip to content

Commit

Permalink
[fix][#33842] Atom feed renderer does not convert relative to absolut…
Browse files Browse the repository at this point in the history
…e URLs. Fixes #3754
  • Loading branch information
roland-d authored and phproberto committed Jun 24, 2014
1 parent d5552a1 commit a63881e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
10 changes: 8 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,10 +107,12 @@ 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";
}

Expand All @@ -128,7 +132,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 Down Expand Up @@ -170,12 +173,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 @@ -199,10 +203,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
*
* @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;
}

}

0 comments on commit a63881e

Please sign in to comment.