aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r--Zotlabs/Lib/Activity.php45
-rw-r--r--Zotlabs/Lib/ActivityStreams.php20
-rw-r--r--Zotlabs/Lib/ZotURL.php91
3 files changed, 134 insertions, 22 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index bcbe53df7..9aaf6d866 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -2,10 +2,7 @@
namespace Zotlabs\Lib;
-use Zotlabs\Lib\Libzot;
-use Zotlabs\Lib\Libsync;
-use Zotlabs\Lib\ActivityStreams;
-use Zotlabs\Lib\Group;
+use Zotlabs\Zot6\HTTPSig;
class Activity {
@@ -43,6 +40,46 @@ class Activity {
}
+ static function fetch($url,$channel = null) {
+ $redirects = 0;
+ if(! check_siteallowed($url)) {
+ logger('blacklisted: ' . $url);
+ return null;
+ }
+ if(! $channel) {
+ $channel = get_sys_channel();
+ }
+
+ logger('fetch: ' . $url, LOGGER_DEBUG);
+
+ if(strpos($url,'x-zot:') === 0) {
+ $x = ZotURL::fetch($url,$channel);
+ }
+ else {
+ $m = parse_url($url);
+ $headers = [
+ 'Accept' => 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+ 'Host' => $m['host'],
+ '(request-target)' => 'get ' . get_request_string($url),
+ 'Date' => datetime_convert('UTC','UTC','now','D, d M Y H:i:s') . ' UTC'
+ ];
+ $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),false);
+ $x = z_fetch_url($url, true, $redirects, [ 'headers' => $h ] );
+ }
+
+ if($x['success']) {
+ $y = json_decode($x['body'],true);
+ logger('returned: ' . json_encode($y,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
+ return json_decode($x['body'], true);
+ }
+ else {
+ logger('fetch failed: ' . $url);
+ }
+ return null;
+ }
+
+
+
static function fetch_person($x) {
return self::fetch_profile($x);
diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php
index 49978031e..a357b6d69 100644
--- a/Zotlabs/Lib/ActivityStreams.php
+++ b/Zotlabs/Lib/ActivityStreams.php
@@ -263,24 +263,8 @@ class ActivityStreams {
return self::fetch($url);
}
- static function fetch($url) {
- $redirects = 0;
- if(! check_siteallowed($url)) {
- logger('blacklisted: ' . $url);
- return null;
- }
- logger('fetch: ' . $url, LOGGER_DEBUG);
- $x = z_fetch_url($url, true, $redirects,
- [ 'headers' => [ 'Accept: application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ]]);
- if($x['success']) {
- $y = json_decode($x['body'],true);
- logger('returned: ' . json_encode($y,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
- return json_decode($x['body'], true);
- }
- else {
- logger('fetch failed: ' . $url);
- }
- return null;
+ static function fetch($url,$channel = null) {
+ return Activity::fetch($url,$channel);
}
static function is_an_actor($s) {
diff --git a/Zotlabs/Lib/ZotURL.php b/Zotlabs/Lib/ZotURL.php
new file mode 100644
index 000000000..d1c705fcb
--- /dev/null
+++ b/Zotlabs/Lib/ZotURL.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+use Zotlabs\Zot6\HTTPSig;
+
+
+class ZotURL {
+
+ static public function fetch($url,$channel) {
+
+ $ret = [ 'success' => false ];
+
+ if(strpos($url,'x-zot:') !== 0) {
+ return $ret;
+ }
+
+
+ if(! $url) {
+ return $ret;
+ }
+
+ $portable_url = substr($url,6);
+ $u = explode('/',$portable_url);
+ $portable_id = $u[0];
+
+ $hosts = self::lookup($portable_id);
+
+ if(! $hosts) {
+ return $ret;
+ }
+
+ foreach($hosts as $h) {
+ $newurl = $h . '/id/' . $portable_url;
+
+ $m = parse_url($newurl);
+
+ $data = json_encode([ 'zot_token' => random_string() ]);
+
+ if($channel && $m) {
+
+ $headers = [
+ 'Accept' => 'application/x-zot+json',
+ 'Content-Type' => 'application/x-zot+json',
+ 'X-Zot-Token' => random_string(),
+ 'Digest' => HTTPSig::generate_digest_header($data),
+ 'Host' => $m['host'],
+ '(request-target)' => 'post ' . get_request_string($newurl)
+ ];
+ $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),false);
+ }
+ else {
+ $h = [ 'Accept: application/x-zot+json' ];
+ }
+
+ $result = [];
+
+ $redirects = 0;
+ $x = z_post_url($newurl,$data,$redirects, [ 'headers' => $h ] );
+ if($x['success']) {
+ return $x;
+ }
+ }
+
+ return $ret;
+
+ }
+
+ static public function is_zoturl($s) {
+
+ if(strpos($url,'x-zot:') === 0) {
+ return true;
+ }
+ return false;
+ }
+
+
+ static public function lookup($portable_id) {
+
+ $r = q("select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc",
+ dbesc($portable_id)
+ );
+
+ if(! $r) {
+ // extend to network lookup
+ return false;
+ }
+ return ids_to_array($r,'hubloc_url');
+ }
+
+} \ No newline at end of file