aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-06-30 19:04:42 +0000
committerMario <mario@mariovavti.com>2021-06-30 19:04:42 +0000
commit458fa7bfeb79ddfe3a07a00648652ebc26e245b3 (patch)
tree28bcf2d349aaaeb869f3534de34b6a33633157b1 /Zotlabs/Lib
parentc8d9238c58a61a9ffea81d50e5a35693388f6369 (diff)
downloadvolse-hubzilla-458fa7bfeb79ddfe3a07a00648652ebc26e245b3.tar.gz
volse-hubzilla-458fa7bfeb79ddfe3a07a00648652ebc26e245b3.tar.bz2
volse-hubzilla-458fa7bfeb79ddfe3a07a00648652ebc26e245b3.zip
port fixes from as_actor_store()
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r--Zotlabs/Lib/Activity.php119
1 files changed, 62 insertions, 57 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 2b723bb57..784de3d2c 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -1533,8 +1533,9 @@ class Activity {
static function actor_store($url, $person_obj) {
- if (!is_array($person_obj))
+ if (!is_array($person_obj)) {
return;
+ }
$inbox = $person_obj['inbox'];
@@ -1545,11 +1546,14 @@ class Activity {
}
$name = $person_obj['name'];
- if (!$name)
+ if (!$name) {
$name = $person_obj['preferredUsername'];
- if (!$name)
+ }
+ if (!$name) {
$name = t('Unknown');
+ }
+ $icon = z_root() . '/' . get_default_profile_photo(300);
if ($person_obj['icon']) {
if (is_array($person_obj['icon'])) {
if (array_key_exists('url', $person_obj['icon']))
@@ -1614,84 +1618,85 @@ class Activity {
}
}
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ $m = parse_url($url);
+ if($m) {
+ $hostname = $m['host'];
+ $baseurl = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : '');
+ $site_url = $m['scheme'] . '://' . $m['host'];
+ }
+
+ $r = q("select * from xchan join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s'",
dbesc($url)
);
- if (!$r) {
- // create a new record
-
- xchan_store_lowlevel(
- [
- 'xchan_hash' => $url,
- 'xchan_guid' => $url,
- 'xchan_pubkey' => $pubkey,
- 'xchan_addr' => '',
- 'xchan_url' => $profile,
- 'xchan_name' => $name,
- 'xchan_name_date' => datetime_convert(),
- 'xchan_network' => 'activitypub'
- ]
- );
- }
- else {
+ if($r) {
// Record exists. Cache existing records for one week at most
// then refetch to catch updated profile photos, names, etc.
-
- $d = datetime_convert('UTC', 'UTC', 'now - 1 week');
- if ($r[0]['xchan_name_date'] > $d)
+ $d = datetime_convert('UTC', 'UTC', 'now - 3 days');
+ if($r[0]['hubloc_updated'] > $d) {
return;
+ }
- // update existing record
- q("update xchan set xchan_name = '%s', xchan_pubkey = '%s', xchan_network = '%s', xchan_name_date = '%s' where xchan_hash = '%s'",
- dbesc($name),
- dbesc($pubkey),
- dbesc('activitypub'),
+ q("UPDATE site SET site_update = '%s', site_dead = 0 WHERE site_url = '%s'",
dbesc(datetime_convert()),
+ dbesc($site_url)
+ );
+
+ // update existing xchan record
+ q("update xchan set xchan_name = '%s', xchan_guid = '%s', xchan_pubkey = '%s', xchan_network = 'activitypub', xchan_name_date = '%s' where xchan_hash = '%s'",
+ dbesc(escape_tags($name)),
+ dbesc(escape_tags($url)),
+ dbesc(escape_tags($pubkey)),
+ dbescdate(datetime_convert()),
dbesc($url)
);
- }
- if ($collections) {
- set_xconfig($url, 'activitypub', 'collections', $collections);
+ // update existing hubloc record
+ q("update hubloc set hubloc_guid = '%s', hubloc_network = 'activitypub', hubloc_url = '%s', hubloc_host = '%s', hubloc_callback = '%s', hubloc_updated = '%s', hubloc_id_url = '%s' where hubloc_hash = '%s'",
+ dbesc(escape_tags($url)),
+ dbesc(escape_tags($baseurl)),
+ dbesc(escape_tags($hostname)),
+ dbesc(escape_tags($inbox)),
+ dbescdate(datetime_convert()),
+ dbesc(escape_tags($profile)),
+ dbesc($url)
+ );
}
+ else {
+ // create a new record
- $r = q("select * from hubloc where hubloc_hash = '%s' limit 1",
- dbesc($url)
- );
-
- $m = parse_url($url);
- if ($m) {
- $hostname = $m['host'];
- $site_url = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : '');
- }
+ xchan_store_lowlevel(
+ [
+ 'xchan_hash' => escape_tags($url),
+ 'xchan_guid' => escape_tags($url),
+ 'xchan_pubkey' => escape_tags($pubkey),
+ 'xchan_addr' => '',
+ 'xchan_url' => escape_tags($profile),
+ 'xchan_name' => escape_tags($name),
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_network' => 'activitypub'
+ ]
+ );
- if (!$r) {
hubloc_store_lowlevel(
[
- 'hubloc_guid' => $url,
- 'hubloc_hash' => $url,
+ 'hubloc_guid' => escape_tags($url),
+ 'hubloc_hash' => escape_tags($url),
'hubloc_addr' => '',
'hubloc_network' => 'activitypub',
- 'hubloc_url' => $site_url,
- 'hubloc_host' => $hostname,
- 'hubloc_callback' => $inbox,
+ 'hubloc_url' => escape_tags($baseurl),
+ 'hubloc_host' => escape_tags($hostname),
+ 'hubloc_callback' => escape_tags($inbox),
'hubloc_updated' => datetime_convert(),
'hubloc_primary' => 1,
- 'hubloc_id_url' => $profile
+ 'hubloc_id_url' => escape_tags($profile)
]
);
}
- q("UPDATE site SET site_update = '%s', site_dead = 0 WHERE site_url = '%s' AND site_update < %s - INTERVAL %s",
- dbesc(datetime_convert()),
- dbesc($site_url),
- db_utcnow(),
- db_quoteinterval('1 DAY')
- );
-
- if (!$icon)
- $icon = z_root() . '/' . get_default_profile_photo(300);
+ if ($collections) {
+ set_xconfig($url, 'activitypub', 'collections', $collections);
+ }
$photos = import_xchan_photo($icon, $url);
q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",