diff options
author | Stefan Parviainen <saparvia@caterva.eu> | 2014-12-22 22:57:58 +0100 |
---|---|---|
committer | Stefan Parviainen <saparvia@caterva.eu> | 2014-12-22 22:57:58 +0100 |
commit | 83eb7a10e27a634dc64f093a885e9cb0d9f05eed (patch) | |
tree | 5e2860f5f04cdf56355715f9dd77cba145c7b55d /include/Contact.php | |
parent | c819c276f0bed98c2215ca0e5815ec8fb0f548c5 (diff) | |
download | volse-hubzilla-83eb7a10e27a634dc64f093a885e9cb0d9f05eed.tar.gz volse-hubzilla-83eb7a10e27a634dc64f093a885e9cb0d9f05eed.tar.bz2 volse-hubzilla-83eb7a10e27a634dc64f093a885e9cb0d9f05eed.zip |
Option to check that a random profile works before returning it
Diffstat (limited to 'include/Contact.php')
-rw-r--r-- | include/Contact.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/include/Contact.php b/include/Contact.php index 4fd43db44..4b45a2392 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -581,12 +581,29 @@ function contact_remove($channel_id, $abook_id) { function random_profile() { $randfunc = db_getfunc('rand'); - $r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_connected > %s - interval %s order by $randfunc limit 1", - db_utcnow(), db_quoteinterval('30 day') - ); - if($r) - return $r[0]['xchan_url']; + + $checkrandom = get_config('randprofile','check'); // False by default + $retryrandom = intval(get_config('randprofile','retry')); + if($retryrandom === false) $retryrandom = 5; + + for($i = 0; $i < $retryrandom; $i++) { + $r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_connected > %s - interval %s order by $randfunc limit 1", + db_utcnow(), db_quoteinterval('30 day') + ); + + if(!$r) return ''; // Couldn't get a random channel + + if($checkrandom) { + if(z_fetch_url($r[0]['xchan_url'])['success']) + return $r[0]['xchan_url']; + else + logger('Random channel turned out to be bad.'); + } + else { + return $r[0]['xchan_url']; + } + + } return ''; } - |