mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:40:16 +00:00
use reltoabs - primarily for github activity feeds
This commit is contained in:
parent
2cc02716e1
commit
d840943621
2 changed files with 41 additions and 0 deletions
|
@ -295,6 +295,11 @@ function get_atom_elements($feed,$item) {
|
|||
$res['body'] = unxmlify($item->get_content());
|
||||
$res['plink'] = unxmlify($item->get_link(0));
|
||||
|
||||
if($res['plink'])
|
||||
$base_url = implode('/', array_slice(explode('/',$res['plink']),0,3));
|
||||
else
|
||||
$base_url = '';
|
||||
|
||||
// look for a photo. We should check media size and find the best one,
|
||||
// but for now let's just find any author photo
|
||||
|
||||
|
@ -414,6 +419,8 @@ function get_atom_elements($feed,$item) {
|
|||
|
||||
if((strpos($res['body'],'<') !== false) || (strpos($res['body'],'>') !== false)) {
|
||||
|
||||
$res['body'] = reltoabs($res['body'],$base_url);
|
||||
|
||||
$res['body'] = html2bb_video($res['body']);
|
||||
|
||||
$res['body'] = oembed_html2bbcode($res['body']);
|
||||
|
|
|
@ -1065,3 +1065,37 @@ function array_xmlify($val){
|
|||
if (is_array($val)) return array_map('array_xmlify', $val);
|
||||
return xmlify((string) $val);
|
||||
}
|
||||
|
||||
|
||||
function reltoabs($text, $base)
|
||||
{
|
||||
if (empty($base))
|
||||
return $text;
|
||||
|
||||
$base = rtrim($base,'/');
|
||||
|
||||
$base2 = $base . "/";
|
||||
|
||||
// Replace links
|
||||
$pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
|
||||
$replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
|
||||
$text = preg_replace($pattern, $replace, $text);
|
||||
|
||||
$pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
|
||||
$replace = "<a\${1} href=\"" . $base . "\${2}\"";
|
||||
$text = preg_replace($pattern, $replace, $text);
|
||||
|
||||
// Replace images
|
||||
$pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
|
||||
$replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
|
||||
$text = preg_replace($pattern, $replace, $text);
|
||||
|
||||
$pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
|
||||
$replace = "<img\${1} src=\"" . $base . "\${2}\"";
|
||||
$text = preg_replace($pattern, $replace, $text);
|
||||
|
||||
|
||||
// Done
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue