Set a default directory server from a hard-wired list if one was not previously chosen.

This commit is contained in:
friendica 2014-04-25 18:10:23 -07:00
parent d6620522c2
commit 3e8e67df2c
8 changed files with 39 additions and 45 deletions

View file

@ -67,6 +67,14 @@ define ( 'DIRECTORY_MODE_STANDALONE', 0x0100);
define ( 'DIRECTORY_REALM', 'RED_GLOBAL');
define ( 'DIRECTORY_FALLBACK_MASTER', 'https://zothub.com');
$DIRECTORY_FALLBACK_SERVERS = array(
'https://zothub.com',
'https://zotid.net',
'https://redmatrix.nl',
'https://whogotzot.com',
'https://red.mariovavti.com'
);
/**
*

View file

@ -3,10 +3,31 @@
require_once('include/permissions.php');
function find_upstream_directory($dirmode) {
global $DIRECTORY_FALLBACK_SERVERS;
$preferred = get_config('system','directory_server');
if($preferred)
return array('url' => $preferred);
return '';
if(! $preferred) {
/**
* No directory has yet been set. For most sites, pick one at random
* from our list of directory servers. However, if we're a directory
* server ourself, point at the local instance
* We will then set this value so this should only ever happen once.
* Ideally there will be an admin setting to change to a different
* directory server if you don't like our choice or if circumstances change.
*/
$dirmode = intval(get_config('system','directory_mode'));
if($dirmode == DIRECTORY_MODE_NORMAL) {
$toss = mt_rand(0,count($DIRECTORY_FALLBACK_SERVERS));
$preferred = $DIRECTORY_FALLBACK_SERVERS[$toss];
set_config('system','directory_server',$preferred);
}
else{
set_config('system','directory_server',z_root());
}
}
return array('url' => $preferred);
}
function dir_sort_links() {

View file

@ -48,13 +48,7 @@ function directory_run($argv, $argc){
}
$directory = find_upstream_directory($dirmode);
if($directory) {
$url = $directory['url'] . '/post';
}
else {
$url = DIRECTORY_FALLBACK_MASTER . '/post';
}
$url = $directory['url'] . '/post';
// ensure the upstream directory is updated

View file

@ -370,13 +370,7 @@ function update_suggestions() {
}
else {
$directory = find_upstream_directory($dirmode);
if($directory) {
$url = $directory['url'] . '/sitelist';
}
else {
$url = DIRECTORY_FALLBACK_MASTER . '/sitelist';
}
$url = $directory['url'] . '/sitelist';
}
if(! $url)
return;

View file

@ -304,13 +304,7 @@ function navbar_complete(&$a) {
if(! $url) {
require_once("include/dir_fns.php");
$directory = find_upstream_directory($dirmode);
if($directory) {
$url = $directory['url'] . '/dirsearch';
}
else {
$url = DIRECTORY_FALLBACK_MASTER . '/dirsearch';
}
$url = $directory['url'] . '/dirsearch';
}
if($url) {

View file

@ -56,14 +56,9 @@ function directory_content(&$a) {
}
if(! $url) {
$directory = find_upstream_directory($dirmode);
if($directory) {
$url = $directory['url'] . '/dirsearch';
}
else {
$url = DIRECTORY_FALLBACK_MASTER . '/dirsearch';
}
$url = $directory['url'] . '/dirsearch';
}
logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);
$contacts = array();

View file

@ -23,13 +23,7 @@ function dirprofile_init(&$a) {
}
if(! $url) {
$directory = find_upstream_directory($dirmode);
if($directory) {
$url = $directory['url'] . '/dirsearch';
}
else {
$url = DIRECTORY_FALLBACK_MASTER . '/dirsearch';
}
$url = $directory['url'] . '/dirsearch';
}
logger('mod_directory: URL = ' . $url, LOGGER_DEBUG);

View file

@ -9,13 +9,7 @@ function pubsites_content(&$a) {
}
if(! $url) {
$directory = find_upstream_directory($dirmode);
if($directory) {
$url = $directory['url'] . '/dirsearch';
}
else {
$url = DIRECTORY_FALLBACK_MASTER . '/dirsearch';
}
$url = $directory['url'] . '/dirsearch';
}
$url .= '/sites';