$ git clone https://thingshare.ion.nu/thingshare.git
commit ece5a5c3dfdf7089dabeba850c10aea7766e200e
Author: Alicia <...>
Date: Sat Nov 14 00:02:31 2020 +0100
More flexible handling of URLs, with or without domain.
diff --git a/rpc.php b/rpc.php
index 795e7c0..2a2b15c 100644
--- a/rpc.php
+++ b/rpc.php
@@ -238,4 +238,18 @@ function getdisplayname($username)
$cache[$username]=$obj['displayname'];
return $obj['displayname'];
}
+
+function abslink($host, $link)
+{
+ if(!strpos($link, '://'))
+ {
+ if(substr($link,0,1)=='/')
+ {
+ return 'https://'.$host.$link;
+ }else{
+ return 'https://'.$host.'/'.$link;
+ }
+ }
+ return $link;
+}
?>
diff --git a/search.php b/search.php
index 007e7fd..829223c 100644
--- a/search.php
+++ b/search.php
@@ -85,7 +85,7 @@ foreach($results as $thing)
{
$by=htmlentities($thing['by']['name']);
$by='<a href="'.BASEURL.'/user/'.$by.'@'.$thing['peer'].'" title="'.$by.'@'.$thing['peer'].'">'.htmlentities($thing['by']['displayname']).'</a>';
- $things.='<div class="thing"><div class="boxtop">By '.$by.'</div><...><div class="boxbottom">'.htmlentities($thing['name']).'</div><img src="https://'.$thing['peer'].$thing['preview'].'" /></a></div>';
+ $things.='<div class="thing"><div class="boxtop">By '.$by.'</div><...><div class="boxbottom">'.htmlentities($thing['name']).'</div><img src="'.abslink($thing['peer'], $thing['preview']).'" /></a></div>';
}
?>
<div class="sidebar">
diff --git a/thing.php b/thing.php
index f435ddd..11c0542 100644
--- a/thing.php
+++ b/thing.php
@@ -58,7 +58,7 @@ foreach($thingobj['files'] as $file)
$type=(isset($file['type'])?$file['type']:'unknown');
$files.='<div class="thing">';
if(isset($file['preview3d'])){$files.='<div class="boxtop" style="right:0px;"><a href="#" onclick="return threedview(this,'.PREVIEW_SIZE[0].','.PREVIEW_SIZE[1].');" data-file="https://'.$thing[1].$file['preview3d'].'">3D view</a></div>';}
- $files.='<a href="https://'.$thing[1].$file['path'].'" download="'.htmlentities($file['name']).'" type="'.$type.'"><div class="boxbottom">'.htmlentities($file['name']).'</div><img src="https://'.$thing[1].$file['preview'].'" /></a></div>';
+ $files.='<a href="'.abslink($thing[1], $file['path']).'" download="'.htmlentities($file['name']).'" type="'.$type.'"><div class="boxbottom">'.htmlentities($file['name']).'</div><img src="'.abslink($thing[1], $file['preview']).'" /></a></div>';
}
$tags='';
foreach($thingobj['tags'] as $tag)