From 7ce4175876ce13727432dc839938bb8e486ef406 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 12 Apr 2023 09:29:51 +0200 Subject: initial commit directory sync rewrite - should work but still requires lots of cleanup --- Zotlabs/Module/Dirsearch.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index c0df8a1e3..633ae69f0 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -215,9 +215,11 @@ class Dirsearch extends Controller { if($sync) { $spkt = array('transactions' => array()); - $r = q("select * from updates where ud_date >= '%s' and ud_guid != '' and ud_addr != '' order by ud_date desc", + + $r = q("select * from updates where ud_date >= '%s' order by ud_date desc", dbesc($sync) ); + if($r) { foreach($r as $rr) { $flags = array(); @@ -235,6 +237,7 @@ class Dirsearch extends Controller { ); } } + json_return_and_die($spkt); } else { -- cgit v1.2.3 From 261762448e99a722d2a5e262610a66c5c1c72293 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 12 Apr 2023 11:36:34 +0200 Subject: use url instead of addr for updates and clean up local_dir_update() and update_modtime() --- Zotlabs/Module/Dirsearch.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 633ae69f0..001bd87a7 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -222,19 +222,19 @@ class Dirsearch extends Controller { if($r) { foreach($r as $rr) { - $flags = array(); + $flags = []; if($rr['ud_flags'] & UPDATE_FLAGS_DELETED) $flags[] = 'deleted'; if($rr['ud_flags'] & UPDATE_FLAGS_FORCED) $flags[] = 'forced'; - $spkt['transactions'][] = array( + $spkt['transactions'][] = [ 'hash' => $rr['ud_hash'], 'address' => $rr['ud_addr'], 'transaction_id' => $rr['ud_guid'], 'timestamp' => $rr['ud_date'], 'flags' => $flags - ); + ]; } } -- cgit v1.2.3 From aa06400a50122dc7a8472e4c6144ac8ba6cbcc51 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 12 Apr 2023 17:50:39 +0200 Subject: deprecate flags and transaction_id and only return results which are currently updated --- Zotlabs/Module/Dirsearch.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 001bd87a7..837783e8b 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -216,24 +216,18 @@ class Dirsearch extends Controller { if($sync) { $spkt = array('transactions' => array()); - $r = q("select * from updates where ud_date >= '%s' order by ud_date desc", + $r = q("SELECT * FROM updates WHERE ud_flags = 0 AND ud_date >= '%s' ORDER BY ud_date DESC", dbesc($sync) ); if($r) { foreach($r as $rr) { - $flags = []; - if($rr['ud_flags'] & UPDATE_FLAGS_DELETED) - $flags[] = 'deleted'; - if($rr['ud_flags'] & UPDATE_FLAGS_FORCED) - $flags[] = 'forced'; - $spkt['transactions'][] = [ 'hash' => $rr['ud_hash'], 'address' => $rr['ud_addr'], - 'transaction_id' => $rr['ud_guid'], - 'timestamp' => $rr['ud_date'], - 'flags' => $flags + 'host' => $rr['ud_guid'], + 'transaction_id' => $rr['ud_guid'], // deprecated 2023-04-12 + 'timestamp' => $rr['ud_date'] ]; } } -- cgit v1.2.3 From bdf1b23198ed958942f30c7103995231afd2f5da Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 12 Apr 2023 18:24:44 +0200 Subject: reset ud_last if we had contact and some cleanup --- Zotlabs/Module/Dirsearch.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 837783e8b..45cb48c11 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -216,7 +216,8 @@ class Dirsearch extends Controller { if($sync) { $spkt = array('transactions' => array()); - $r = q("SELECT * FROM updates WHERE ud_flags = 0 AND ud_date >= '%s' ORDER BY ud_date DESC", + $r = q("SELECT * FROM updates WHERE ud_flags = 0 AND ud_last = '%s' AND ud_date >= '%s' ORDER BY ud_date DESC", + dbesc(NULL_DATE), dbesc($sync) ); -- cgit v1.2.3 From f851c272fa5cc95f11bfaa0b5399028c6d91247e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 26 Apr 2023 12:50:37 +0200 Subject: enable dir admins to flag or hide entries --- Zotlabs/Module/Dirsearch.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 45cb48c11..62bf99b67 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -25,7 +25,6 @@ class Dirsearch extends Controller { json_return_and_die($ret); } - $access_token = $_REQUEST['t'] ?? ''; $token = get_config('system','realm_token'); @@ -42,7 +41,6 @@ class Dirsearch extends Controller { $sql_extra = ''; - $tables = array('name','address','locale','region','postcode','country','gender','marital','sexual','keywords'); if(isset($_REQUEST['query']) && $_REQUEST['query']) { @@ -85,9 +83,7 @@ class Dirsearch extends Controller { // by default use a safe search - $safe = ((x($_REQUEST,'safe'))); // ? intval($_REQUEST['safe']) : 1 ); - if ($safe === false) - $safe = 1; + $safe = $_REQUEST['safe'] ?? 1; if(array_key_exists('sync',$_REQUEST)) { if($_REQUEST['sync']) @@ -177,9 +173,15 @@ class Dirsearch extends Controller { $sql_extra .= " and xchan_addr like '%%" . \App::get_hostname() . "' "; } - $safesql = (($safe > 0) ? " and xchan_censored = 0 and xchan_selfcensored = 0 " : ''); + $safesql = ''; + if($safe > 0) + $safesql = " and xchan_censored = 0 and xchan_selfcensored = 0 "; + + if($safe < 1) + $safesql = " and xchan_censored < 2 and xchan_selfcensored < 2 "; + if($safe < 0) - $safesql = " and ( xchan_censored = 1 OR xchan_selfcensored = 1 ) "; + $safesql = " and xchan_censored < 3 and xchan_selfcensored < 2 "; if($forums) $safesql .= " and xchan_pubforum = " . ((intval($forums)) ? '1 ' : '0 '); -- cgit v1.2.3 From d79290df75b214f50f0d9ec586a7b855e3a86106 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 26 Apr 2023 17:58:35 +0200 Subject: dirsync update column --- Zotlabs/Module/Dirsearch.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 62bf99b67..22b030edf 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -218,7 +218,7 @@ class Dirsearch extends Controller { if($sync) { $spkt = array('transactions' => array()); - $r = q("SELECT * FROM updates WHERE ud_flags = 0 AND ud_last = '%s' AND ud_date >= '%s' ORDER BY ud_date DESC", + $r = q("SELECT * FROM updates WHERE ud_update = 0 AND ud_last = '%s' AND ud_date >= '%s' ORDER BY ud_date DESC", dbesc(NULL_DATE), dbesc($sync) ); @@ -230,7 +230,8 @@ class Dirsearch extends Controller { 'address' => $rr['ud_addr'], 'host' => $rr['ud_guid'], 'transaction_id' => $rr['ud_guid'], // deprecated 2023-04-12 - 'timestamp' => $rr['ud_date'] + 'timestamp' => $rr['ud_date'], + 'flags' => $rr['ud_flags'] ]; } } -- cgit v1.2.3 From bdb25315b6f01f1963b21f6e0c0bd5ec2959c62e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 26 Apr 2023 23:01:56 +0200 Subject: initial commit for directory flags federation --- Zotlabs/Module/Dirsearch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 22b030edf..d4af0f91a 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -228,8 +228,8 @@ class Dirsearch extends Controller { $spkt['transactions'][] = [ 'hash' => $rr['ud_hash'], 'address' => $rr['ud_addr'], - 'host' => $rr['ud_guid'], - 'transaction_id' => $rr['ud_guid'], // deprecated 2023-04-12 + 'host' => $rr['ud_host'], + 'transaction_id' => $rr['ud_host'], // deprecated 2023-04-12 'timestamp' => $rr['ud_date'], 'flags' => $rr['ud_flags'] ]; -- cgit v1.2.3 From 13946b2b761d38bd7623cf2704616309922b75d7 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 28 Apr 2023 10:03:05 +0200 Subject: fix and document edge case --- Zotlabs/Module/Dirsearch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index d4af0f91a..acf1b64e4 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -229,7 +229,7 @@ class Dirsearch extends Controller { 'hash' => $rr['ud_hash'], 'address' => $rr['ud_addr'], 'host' => $rr['ud_host'], - 'transaction_id' => $rr['ud_host'], // deprecated 2023-04-12 + 'transaction_id' => $rr['ud_host'], // deprecated 2023-04-12 - can be removed after dir servers at version >= 8.4 'timestamp' => $rr['ud_date'], 'flags' => $rr['ud_flags'] ]; -- cgit v1.2.3 From ffbaa7e4dcda787897263c6cc4d13671f1fc6ed6 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 3 May 2023 15:25:47 +0200 Subject: when flagging an entry also flag its xtags and improved keywords query in dirsearch --- Zotlabs/Module/Dirsearch.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index acf1b64e4..7380a551e 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -40,6 +40,8 @@ class Dirsearch extends Controller { } $sql_extra = ''; + $keywords_query = ''; + $hub_query = ''; $tables = array('name','address','locale','region','postcode','country','gender','marital','sexual','keywords'); @@ -98,10 +100,10 @@ class Dirsearch extends Controller { $hub = \App::get_hostname(); } - if($hub) + if($hub) { $hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') "; - else - $hub_query = ''; + } + $sort_order = ((x($_REQUEST,'order')) ? $_REQUEST['order'] : ''); @@ -127,9 +129,12 @@ class Dirsearch extends Controller { $sql_extra .= $this->dir_query_build($joiner,'xprof_marital',$marital); if($sexual) $sql_extra .= $this->dir_query_build($joiner,'xprof_sexual',$sexual); - if($keywords) - $sql_extra .= $this->dir_query_build($joiner,'xprof_keywords',$keywords); + if($keywords) { + $keywords_arr = explode(',', $keywords); + stringify_array_elms($keywords_arr, true); + $keywords_query = " AND xchan_hash IN (SELECT xtag_hash FROM xtag WHERE xtag_term IN (" . protect_sprintf(implode(',', $keywords_arr)) . ")) "; + } // we only support an age range currently. You must set both agege // (greater than or equal) and agele (less than or equal) @@ -265,7 +270,7 @@ class Dirsearch extends Controller { xprof.xprof_hometown as hometown, xprof.xprof_keywords as keywords from xchan left join xprof on xchan_hash = xprof_hash left join hubloc on (hubloc_id_url = xchan_url and hubloc_hash = xchan_hash) - where hubloc_primary = 1 and hubloc_updated > %s - INTERVAL %s and ( $logic $sql_extra ) $hub_query and xchan_network = 'zot6' and xchan_system = 0 and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0 + where hubloc_primary = 1 and hubloc_updated > %s - INTERVAL %s and ( $logic $sql_extra ) $hub_query $keywords_query and xchan_network = 'zot6' and xchan_system = 0 and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0 $safesql $order $qlimit", db_utcnow(), db_quoteinterval('30 DAY') -- cgit v1.2.3 From 383d0e17f2c596e991156b773cf0bc115269e941 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 7 May 2023 09:52:27 +0200 Subject: fix directory search --- Zotlabs/Module/Dirsearch.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index 7380a551e..c31d5f0ee 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -15,8 +15,7 @@ class Dirsearch extends Controller { $ret = array('success' => false); - // logger('request: ' . print_r($_REQUEST,true)); - + // logger('request: ' . print_r($_REQUEST,true)); $dirmode = intval(get_config('system','directory_mode')); @@ -129,8 +128,12 @@ class Dirsearch extends Controller { $sql_extra .= $this->dir_query_build($joiner,'xprof_marital',$marital); if($sexual) $sql_extra .= $this->dir_query_build($joiner,'xprof_sexual',$sexual); - - if($keywords) { + if($keywords && $name) { + // this is a general search + $sql_extra .= $this->dir_query_build($joiner,'xprof_keywords',$keywords); + } + if($keywords && !$name) { + // this is a search for keywords only $keywords_arr = explode(',', $keywords); stringify_array_elms($keywords_arr, true); $keywords_query = " AND xchan_hash IN (SELECT xtag_hash FROM xtag WHERE xtag_term IN (" . protect_sprintf(implode(',', $keywords_arr)) . ")) "; -- cgit v1.2.3 From f995b2822fcc3faa1b7da09367506610bc233e88 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 7 May 2023 10:03:27 +0200 Subject: exclude deleted hublocs --- Zotlabs/Module/Dirsearch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module/Dirsearch.php') diff --git a/Zotlabs/Module/Dirsearch.php b/Zotlabs/Module/Dirsearch.php index c31d5f0ee..7efac6345 100644 --- a/Zotlabs/Module/Dirsearch.php +++ b/Zotlabs/Module/Dirsearch.php @@ -100,7 +100,7 @@ class Dirsearch extends Controller { } if($hub) { - $hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') "; + $hub_query = " and xchan_hash in (select hubloc_hash from hubloc where hubloc_deleted = 0 and hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') "; } -- cgit v1.2.3