aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2023-04-12 11:36:34 +0200
committerMario Vavti <mario@mariovavti.com>2023-04-12 11:36:34 +0200
commit261762448e99a722d2a5e262610a66c5c1c72293 (patch)
treeb875acafe519323011d900ccdc9a5c751a2e58be /Zotlabs/Lib
parent7ce4175876ce13727432dc839938bb8e486ef406 (diff)
downloadvolse-hubzilla-261762448e99a722d2a5e262610a66c5c1c72293.tar.gz
volse-hubzilla-261762448e99a722d2a5e262610a66c5c1c72293.tar.bz2
volse-hubzilla-261762448e99a722d2a5e262610a66c5c1c72293.zip
use url instead of addr for updates and clean up local_dir_update() and update_modtime()
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r--Zotlabs/Lib/Libzot.php37
-rw-r--r--Zotlabs/Lib/Libzotdir.php132
2 files changed, 75 insertions, 94 deletions
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php
index b41ba043a..4323dae48 100644
--- a/Zotlabs/Lib/Libzot.php
+++ b/Zotlabs/Lib/Libzot.php
@@ -649,7 +649,7 @@ class Libzot {
* * \e string \b message (optional) error string only if success is false
*/
- static function import_xchan($arr, $ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) {
+ static function import_xchan($arr, $ud_flags = 0, $ud_arr = null) {
$ret = ['success' => false];
@@ -665,7 +665,7 @@ class Libzot {
*/
call_hooks('import_xchan', $arr);
- $dirmode = intval(get_config('system', 'directory_mode'));
+ $dirmode = intval(get_config('system', 'directory_mode', DIRECTORY_MODE_NORMAL));
$changed = false;
$what = '';
@@ -696,7 +696,7 @@ class Libzot {
return $ret;
}
- logger('import_xchan: ' . $xchan_hash, LOGGER_DEBUG);
+ hz_syslog('import_xchan: ' . $xchan_hash, LOGGER_DEBUG);
if (isset($arr['signing_algorithm']) && $arr['signing_algorithm']) {
set_xconfig($xchan_hash, 'system', 'signing_algorithm', $arr['signing_algorithm']);
@@ -787,8 +787,8 @@ class Libzot {
dbesc($xchan_hash)
);
- logger('Update: existing: ' . print_r($r[0], true), LOGGER_DATA, LOG_DEBUG);
- logger('Update: new: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG);
+ hz_syslog('Update: existing: ' . print_r($r[0], true), LOGGER_DATA, LOG_DEBUG);
+ hz_syslog('Update: new: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG);
$what .= 'xchan ';
$changed = true;
}
@@ -928,20 +928,16 @@ class Libzot {
$ret['message'] .= $s['message'];
}
- // Which entries in the update table are we interested in updating?
-
- $address = (($ud_arr && $ud_arr['ud_addr']) ? $ud_arr['ud_addr'] : $arr['primary_location']['address']);
-
-
- // Are we a directory server of some kind?
$other_realm = false;
$realm = get_directory_realm();
- if (array_key_exists('site', $arr)
- && array_key_exists('realm', $arr['site'])
- && (strpos($arr['site']['realm'], $realm) === false))
+ if (array_key_exists('site', $arr) && array_key_exists('realm', $arr['site']) && (strpos($arr['site']['realm'], $realm) === false)) {
$other_realm = true;
+ }
+ $address = $arr['primary_location']['url'];
+
+ // Are we a directory server of some kind?
if ($dirmode != DIRECTORY_MODE_NORMAL) {
@@ -977,16 +973,9 @@ class Libzot {
}
}
- if ($changed/* || ($ud_flags == UPDATE_FLAGS_FORCED)*/) {
- $guid = random_string() . '@' . \App::get_hostname();
- Libzotdir::update_modtime($xchan_hash, $guid, $address, $ud_flags);
- }
- elseif (!$ud_flags) {
- // nothing changed but we still need to update the updates record
- q("update updates set ud_flags = 0, ud_date = '%s' where ud_hash = '%s'",
- dbesc(datetime_convert()),
- dbesc($xchan_hash)
- );
+ if ($ud_arr) {
+ // Always update updates if we were provided an ud_arr
+ Libzotdir::update_modtime($xchan_hash, $address);
}
if (!x($ret, 'message')) {
diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php
index ed2095059..b27f87a5f 100644
--- a/Zotlabs/Lib/Libzotdir.php
+++ b/Zotlabs/Lib/Libzotdir.php
@@ -338,7 +338,7 @@ class Libzotdir {
$success = false;
$zf = [];
- $href = Webfinger::zot_url(punify($ud['ud_addr']));
+ $href = ((strpos($ud['ud_addr'], '://') === false) ? Webfinger::zot_url(punify($ud['ud_addr'])) : punify($ud['ud_addr']));
if($href) {
$zf = Zotfinger::exec($href);
}
@@ -374,85 +374,78 @@ class Libzotdir {
*/
static function local_dir_update($uid, $force) {
+ logger('local_dir_update uid: ' . $uid, LOGGER_DEBUG);
-
- logger('local_dir_update: uid: ' . $uid, LOGGER_DEBUG);
-
- $p = q("select channel.channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1",
+ $p = q("select channel.channel_hash, channel_address, channel_timezone, profile.*, xchan.xchan_hidden, xchan.xchan_url from profile left join channel on channel_id = uid left join xchan on channel_hash = xchan_hash where profile.uid = %d and profile.is_default = 1",
intval($uid)
);
- $profile = array();
+ if (!$p) {
+ logger('profile not found');
+ return;
+ }
+
+ $profile = [];
$profile['encoding'] = 'zot';
- if ($p) {
- $hash = $p[0]['channel_hash'];
-
- $profile['description'] = $p[0]['pdesc'];
- $profile['birthday'] = $p[0]['dob'];
- if ($age = age($p[0]['dob'],$p[0]['channel_timezone'],''))
- $profile['age'] = $age;
-
- $profile['gender'] = $p[0]['gender'];
- $profile['marital'] = $p[0]['marital'];
- $profile['sexual'] = $p[0]['sexual'];
- $profile['locale'] = $p[0]['locality'];
- $profile['region'] = $p[0]['region'];
- $profile['postcode'] = $p[0]['postal_code'];
- $profile['country'] = $p[0]['country_name'];
- $profile['about'] = $p[0]['about'];
- $profile['homepage'] = $p[0]['homepage'];
- $profile['hometown'] = $p[0]['hometown'];
-
- if ($p[0]['keywords']) {
- $tags = array();
- $k = explode(' ', $p[0]['keywords']);
- if ($k)
- foreach ($k as $kk)
- if (trim($kk))
- $tags[] = trim($kk);
-
- if ($tags)
- $profile['keywords'] = $tags;
- }
+ $hash = $p[0]['channel_hash'];
+
+ $profile['description'] = $p[0]['pdesc'];
+ $profile['birthday'] = $p[0]['dob'];
+ if ($age = age($p[0]['dob'],$p[0]['channel_timezone'],''))
+ $profile['age'] = $age;
+
+ $profile['gender'] = $p[0]['gender'];
+ $profile['marital'] = $p[0]['marital'];
+ $profile['sexual'] = $p[0]['sexual'];
+ $profile['locale'] = $p[0]['locality'];
+ $profile['region'] = $p[0]['region'];
+ $profile['postcode'] = $p[0]['postal_code'];
+ $profile['country'] = $p[0]['country_name'];
+ $profile['about'] = $p[0]['about'];
+ $profile['homepage'] = $p[0]['homepage'];
+ $profile['hometown'] = $p[0]['hometown'];
+
+ if ($p[0]['keywords']) {
+ $tags = array();
+ $k = explode(' ', $p[0]['keywords']);
+ if ($k)
+ foreach ($k as $kk)
+ if (trim($kk))
+ $tags[] = trim($kk);
+
+ if ($tags)
+ $profile['keywords'] = $tags;
+ }
- $hidden = (1 - intval($p[0]['publish']));
+ $hidden = (1 - intval($p[0]['publish']));
- logger('hidden: ' . $hidden);
+ logger('hidden: ' . $hidden);
- $r = q("select xchan_hidden from xchan where xchan_hash = '%s'",
- dbesc($p[0]['channel_hash'])
+ if(intval($p[0]['xchan_hidden']) !== $hidden) {
+ q("update xchan set xchan_hidden = %d where xchan_hash = '%s'",
+ intval($hidden),
+ dbesc($hash)
);
+ }
- if(intval($r[0]['xchan_hidden']) != $hidden) {
- $r = q("update xchan set xchan_hidden = %d where xchan_hash = '%s'",
- intval($hidden),
- dbesc($hash)
- );
- }
-
- $arr = [ 'channel_id' => $uid, 'hash' => $hash, 'profile' => $profile ];
- call_hooks('local_dir_update', $arr);
-
- $address = channel_reddress($p[0]);
-
- if (perm_is_allowed($uid, '', 'view_profile')) {
- self::import_directory_profile($hash, $arr['profile'], $address, 0);
- }
- else {
- // they may have made it private
- q("delete from xprof where xprof_hash = '%s'",
- dbesc($hash)
- );
- q("delete from xtag where xtag_hash = '%s'",
- dbesc($hash)
- );
- }
+ $arr = [ 'channel_id' => $uid, 'hash' => $hash, 'profile' => $profile ];
+ call_hooks('local_dir_update', $arr);
+ if (perm_is_allowed($uid, '', 'view_profile')) {
+ self::import_directory_profile($hash, $arr['profile'], $p[0]['xchan_url'], 0, 1);
+ }
+ else {
+ // they may have made it private
+ q("delete from xprof where xprof_hash = '%s'",
+ dbesc($hash)
+ );
+ q("delete from xtag where xtag_hash = '%s'",
+ dbesc($hash)
+ );
}
- $ud_hash = random_string() . '@' . \App::get_hostname();
- self::update_modtime($hash, $ud_hash, channel_reddress($p[0]), 0);
+ self::update_modtime($hash, $p[0]['xchan_url']);
}
@@ -609,7 +602,7 @@ class Libzotdir {
call_hooks('import_directory_profile', $d);
if (($d['update']) && (! $suppress_update))
- self::update_modtime($arr['xprof_hash'],random_string() . '@' . \App::get_hostname(), $addr, $ud_flags);
+ self::update_modtime($arr['xprof_hash'], $addr);
return $d['update'];
}
@@ -662,12 +655,11 @@ class Libzotdir {
* @brief
*
* @param string $hash
- * @param string $guid
* @param string $addr
* @param int $flags (optional) default 0
*/
- static function update_modtime($hash, $guid, $addr, $flags = 0) {
+ static function update_modtime($hash, $addr, $flags = 0) {
$dirmode = intval(get_config('system', 'directory_mode'));
@@ -675,7 +667,7 @@ class Libzotdir {
return;
}
- if (empty($hash) || empty($guid) || empty($addr)) {
+ if (empty($hash) || empty($addr)) {
return;
}