diff options
-rw-r--r-- | Zotlabs/Module/Connedit.php | 23 | ||||
-rw-r--r-- | include/hubloc.php | 18 | ||||
-rw-r--r-- | include/text.php | 28 |
3 files changed, 49 insertions, 20 deletions
diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index 8288886cd..e23a751d9 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -826,27 +826,10 @@ class Connedit extends \Zotlabs\Web\Controller { } } - $locstr = ''; - - $locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' - and hubloc_deleted = 0 and site_dead = 0", - dbesc($contact['xchan_hash']) - ); - - if($locs) { - foreach($locs as $l) { - if(!($l['location'])) - continue; - if(strpos($locstr,$l['location']) !== false) - continue; - if(strlen($locstr)) - $locstr .= ', '; - $locstr .= $l['location']; - } - } - else + $locstr = locations_by_netid($contact['xchan_hash']); + if(! $locstr) $locstr = $contact['xchan_url']; - + $clone_warn = ''; $clonable = (in_array($contact['xchan_network'],['zot','rss']) ? true : false); if(! $clonable) { diff --git a/include/hubloc.php b/include/hubloc.php index 0daa5908c..0d1a2e560 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -257,6 +257,24 @@ function hubloc_mark_as_down($posturl) { } +/** + * @brief return comma separated string of non-dead clone locations (net addresses) for a given netid + * + * @param string $netid network identity (typically xchan_hash or hubloc_hash) + * @return string + */ + +function locations_by_netid($netid) { + + $locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0", + dbesc($netid) + ); + + return array_elm_to_str($locs,'location',', '); + +} + + function ping_site($url) { diff --git a/include/text.php b/include/text.php index 8ec6ebace..10bbc751a 100644 --- a/include/text.php +++ b/include/text.php @@ -3261,3 +3261,31 @@ function purify_filename($s) { return ''; return $s; } + + +/** + * @brief array_elm_to_str($arr,$elm,$delim = ',') extract unique individual elements from an array of arrays and return them as a string separated by a delimiter + * + * empty elements (evaluated after trim()) are ignored. + * @param $arr array + * @param $elm array key to extract from sub-array + * @param $delim string default ',' + * @returns string + */ + +function array_elm_to_str($arr,$elm,$delim = ',') { + + $tmp = []; + if($arr && is_array($arr)) { + foreach($arr as $x) { + if(is_array($x) && array_key_exists($elm,$x)) { + $z = trim($x[$elm]); + if(($z) && (! in_array($z,$tmp))) { + $tmp[] = $z; + } + } + } + } + return implode($tmp,$delim); +} + |