Merge pull request #1791 from annando/1507-new-poco
Improved Local Directory
This commit is contained in:
commit
cd8be48ca7
19 changed files with 1341 additions and 133 deletions
|
@ -358,6 +358,10 @@ function admin_page_site_post(&$a){
|
|||
$poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0);
|
||||
$maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
|
||||
$maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
|
||||
$poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
|
||||
$poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0);
|
||||
$poco_discovery_since = ((x($_POST,'poco_discovery_since')) ? intval(trim($_POST['poco_discovery_since'])) : 30);
|
||||
$poco_local_search = ((x($_POST,'poco_local_search')) ? intval(trim($_POST['poco_local_search'])) : false);
|
||||
$dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
|
||||
$ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
|
||||
$ostatus_poll_interval = ((x($_POST,'ostatus_poll_interval')) ? intval(trim($_POST['ostatus_poll_interval'])) : 0);
|
||||
|
@ -380,8 +384,8 @@ function admin_page_site_post(&$a){
|
|||
$old_pager = ((x($_POST,'old_pager')) ? True : False);
|
||||
$only_tag_search = ((x($_POST,'only_tag_search')) ? True : False);
|
||||
$rino = ((x($_POST,'rino')) ? intval($_POST['rino']) : 0);
|
||||
|
||||
|
||||
|
||||
|
||||
if($ssl_policy != intval(get_config('system','ssl_policy'))) {
|
||||
if($ssl_policy == SSL_POLICY_FULL) {
|
||||
q("update `contact` set
|
||||
|
@ -427,6 +431,10 @@ function admin_page_site_post(&$a){
|
|||
set_config('system','poll_interval',$poll_interval);
|
||||
set_config('system','maxloadavg',$maxloadavg);
|
||||
set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
|
||||
set_config('system','poco_completion',$poco_completion);
|
||||
set_config('system','poco_discovery',$poco_discovery);
|
||||
set_config('system','poco_discovery_since',$poco_discovery_since);
|
||||
set_config('system','poco_local_search',$poco_local_search);
|
||||
set_config('config','sitename',$sitename);
|
||||
set_config('config','hostname',$hostname);
|
||||
set_config('config','sender_email', $sender_email);
|
||||
|
@ -434,7 +442,7 @@ function admin_page_site_post(&$a){
|
|||
set_config('system','suppress_tags',$suppress_tags);
|
||||
set_config('system','shortcut_icon',$shortcut_icon);
|
||||
set_config('system','touch_icon',$touch_icon);
|
||||
|
||||
|
||||
if ($banner==""){
|
||||
// don't know why, but del_config doesn't work...
|
||||
q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
|
||||
|
@ -582,6 +590,20 @@ function admin_page_site(&$a) {
|
|||
"1440" => t("Daily")
|
||||
);
|
||||
|
||||
$poco_discovery_choices = array(
|
||||
"0" => t("Disabled"),
|
||||
"1" => t("Users"),
|
||||
"2" => t("Users, Global Contacts"),
|
||||
"3" => t("Users, Global Contacts/fallback"),
|
||||
);
|
||||
|
||||
$poco_discovery_since_choices = array(
|
||||
"30" => t("One month"),
|
||||
"91" => t("Three months"),
|
||||
"182" => t("Half a year"),
|
||||
"365" => t("One year"),
|
||||
);
|
||||
|
||||
/* get user names to make the install a personal install of X */
|
||||
$user_names = array();
|
||||
$user_names['---'] = t('Multi user instance');
|
||||
|
@ -630,6 +652,7 @@ function admin_page_site(&$a) {
|
|||
'$upload' => t('File upload'),
|
||||
'$corporate' => t('Policies'),
|
||||
'$advanced' => t('Advanced'),
|
||||
'$portable_contacts' => t('Auto Discovered Contact Directory'),
|
||||
'$performance' => t('Performance'),
|
||||
'$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'),
|
||||
'$baseurl' => $a->get_baseurl(true),
|
||||
|
@ -687,6 +710,11 @@ function admin_page_site(&$a) {
|
|||
'$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
|
||||
'$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
|
||||
|
||||
'$poco_completion' => array('poco_completion', t("Periodical check of global contacts"), get_config('system','poco_completion'), t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")),
|
||||
'$poco_discovery' => array('poco_discovery', t("Discover contacts from other servers"), (string) intval(get_config('system','poco_discovery')), t("Periodically query other servers for contacts. You can choose between 'users': the users on the remote system, 'Global Contacts': active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren't available. The fallback increases the server load, so the recommened setting is 'Users, Global Contacts'."), $poco_discovery_choices),
|
||||
'$poco_discovery_since' => array('poco_discovery_since', t("Timeframe for fetching global contacts"), (string) intval(get_config('system','poco_discovery_since')), t("When the discovery is activated, this value defines the timeframe for the activity of the global contacts that are fetched from other servers."), $poco_discovery_since_choices),
|
||||
'$poco_local_search' => array('poco_local_search', t("Search the local directory"), get_config('system','poco_local_search'), t("Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.")),
|
||||
|
||||
'$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")),
|
||||
'$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system','suppress_language'), t("Suppress language information in meta information about a posting.")),
|
||||
'$suppress_tags' => array('suppress_tags', t("Suppress Tags"), get_config('system','suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")),
|
||||
|
|
|
@ -16,11 +16,20 @@ function dirfind_init(&$a) {
|
|||
|
||||
function dirfind_content(&$a) {
|
||||
|
||||
$community = false;
|
||||
|
||||
$local = get_config('system','poco_local_search');
|
||||
|
||||
$search = notags(trim($_REQUEST['search']));
|
||||
|
||||
if(strpos($search,'@') === 0)
|
||||
$search = substr($search,1);
|
||||
|
||||
|
||||
if(strpos($search,'!') === 0) {
|
||||
$search = substr($search,1);
|
||||
$community = true;
|
||||
}
|
||||
|
||||
$o = '';
|
||||
|
||||
$o .= replace_macros(get_markup_template("section_title.tpl"),array(
|
||||
|
@ -29,16 +38,67 @@ function dirfind_content(&$a) {
|
|||
|
||||
if($search) {
|
||||
|
||||
$p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
|
||||
|
||||
if(strlen(get_config('system','directory_submit_url')))
|
||||
$x = fetch_url('http://dir.friendica.com/lsearch?f=' . $p . '&search=' . urlencode($search));
|
||||
if ($local) {
|
||||
|
||||
//TODO fallback local search if global dir not available.
|
||||
// else
|
||||
// $x = post_url($a->get_baseurl() . '/lsearch', $params);
|
||||
if ($community)
|
||||
$extra_sql = " AND `community`";
|
||||
else
|
||||
$extra_sql = "";
|
||||
|
||||
$j = json_decode($x);
|
||||
$perpage = 80;
|
||||
$startrec = (($a->pager['page']) * $perpage) - $perpage;
|
||||
|
||||
$count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
|
||||
(`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
|
||||
`about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
|
||||
dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
|
||||
dbesc(escape_tags($search)), dbesc(escape_tags($search)));
|
||||
|
||||
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`keywords`
|
||||
FROM `gcontact`
|
||||
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`uid` = %d
|
||||
WHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND
|
||||
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND
|
||||
(`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR
|
||||
`gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') $extra_sql
|
||||
GROUP BY `gcontact`.`nurl`
|
||||
ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
|
||||
intval(local_user()), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA),
|
||||
dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)),
|
||||
dbesc(escape_tags($search)), dbesc(escape_tags($search)),
|
||||
intval($startrec), intval($perpage));
|
||||
$j = new stdClass();
|
||||
$j->total = $count[0]["total"];
|
||||
$j->items_page = $perpage;
|
||||
$j->page = $a->pager['page'];
|
||||
foreach ($results AS $result) {
|
||||
if ($result["name"] == "") {
|
||||
$urlparts = parse_url($result["url"]);
|
||||
$result["name"] = end(explode("/", $urlparts["path"]));
|
||||
}
|
||||
|
||||
$objresult = new stdClass();
|
||||
$objresult->cid = $result["cid"];
|
||||
$objresult->name = $result["name"];
|
||||
$objresult->url = $result["url"];
|
||||
$objresult->photo = $result["photo"];
|
||||
$objresult->tags = $result["keywords"];
|
||||
|
||||
$j->results[] = $objresult;
|
||||
}
|
||||
|
||||
// Add found profiles from the global directory to the local directory
|
||||
proc_run('php','include/discover_poco.php', "dirsearch", urlencode($search));
|
||||
} else {
|
||||
|
||||
$p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
|
||||
|
||||
if(strlen(get_config('system','directory_submit_url')))
|
||||
$x = fetch_url('http://dir.friendica.com/lsearch?f=' . $p . '&search=' . urlencode($search));
|
||||
|
||||
$j = json_decode($x);
|
||||
}
|
||||
|
||||
if($j->total) {
|
||||
$a->set_pager_total($j->total);
|
||||
|
@ -46,21 +106,32 @@ function dirfind_content(&$a) {
|
|||
}
|
||||
|
||||
if(count($j->results)) {
|
||||
|
||||
|
||||
$tpl = get_markup_template('match.tpl');
|
||||
foreach($j->results as $jj) {
|
||||
|
||||
|
||||
// If We already know this contact then don't show the "connect" button
|
||||
if ($jj->cid > 0) {
|
||||
$connlnk = "";
|
||||
$conntxt = "";
|
||||
} else {
|
||||
$connlnk = $a->get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url);
|
||||
$conntxt = t('Connect');
|
||||
}
|
||||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$url' => zrl($jj->url),
|
||||
'$name' => $jj->name,
|
||||
'$photo' => $jj->photo,
|
||||
'$tags' => $jj->tags
|
||||
'$photo' => proxy_url($jj->photo),
|
||||
'$tags' => $jj->tags,
|
||||
'$conntxt' => $conntxt,
|
||||
'$connlnk' => $connlnk,
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
info( t('No matches') . EOL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,21 @@ function completeurl($url, $scheme) {
|
|||
return($complete);
|
||||
}
|
||||
|
||||
function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = true) {
|
||||
|
||||
$data = Cache::get("parse_url:".$no_guessing.":".$do_oembed.":".$url);
|
||||
if (!is_null($data)) {
|
||||
$data = unserialize($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
$data = parseurl_getsiteinfo($url, $no_guessing, $do_oembed);
|
||||
|
||||
Cache::set("parse_url:".$no_guessing.":".$do_oembed.":".$url,serialize($data));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true, $count = 1) {
|
||||
require_once("include/network.php");
|
||||
|
||||
|
|
40
mod/poco.php
40
mod/poco.php
|
@ -61,12 +61,16 @@ function poco_init(&$a) {
|
|||
$update_limit = date("Y-m-d H:i:s",strtotime($_GET['updatedSince']));
|
||||
|
||||
if ($global) {
|
||||
$r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `network` IN ('%s')",
|
||||
//$r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND `network` IN ('%s')",
|
||||
$r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND `network` IN ('%s', '%s', '%s')",
|
||||
dbesc($update_limit),
|
||||
dbesc(NETWORK_DFRN)
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS)
|
||||
);
|
||||
} elseif($system_mode) {
|
||||
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '')
|
||||
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s')
|
||||
AND (`success_update` >= `failure_update` OR `last-item` >= `failure_update`)
|
||||
AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) ",
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
|
@ -75,7 +79,8 @@ function poco_init(&$a) {
|
|||
);
|
||||
} else {
|
||||
$r = q("SELECT count(*) AS `total` FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
|
||||
AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra",
|
||||
AND (`success_update` >= `failure_update` OR `last-item` >= `failure_update`)
|
||||
AND `network` IN ('%s', '%s', '%s', '%s') $sql_extra",
|
||||
intval($user['uid']),
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
|
@ -93,19 +98,25 @@ function poco_init(&$a) {
|
|||
$startIndex = 0;
|
||||
$itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
|
||||
|
||||
|
||||
if ($global) {
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s') LIMIT %d, %d",
|
||||
logger("Start global query", LOGGER_DEBUG);
|
||||
//$r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s') AND ((`last_contact` >= `last_failure`) OR (`updated` > `last_failure`)) LIMIT %d, %d",
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `updated` > '%s' AND `network` IN ('%s', '%s', '%s') AND `updated` > `last_failure`
|
||||
ORDER BY `updated` DESC LIMIT %d, %d",
|
||||
dbesc($update_limit),
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc(NETWORK_OSTATUS),
|
||||
intval($startIndex),
|
||||
intval($itemsPerPage)
|
||||
);
|
||||
} elseif($system_mode) {
|
||||
logger("Start system mode query", LOGGER_DEBUG);
|
||||
$r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`, `profile`.`gender` AS `pgender`,
|
||||
`profile`.`address` AS `paddress`, `profile`.`region` AS `pregion`, `profile`.`postal-code` AS `ppostalcode`, `profile`.`country-name` AS `pcountry`
|
||||
FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
|
||||
WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') AND `profile`.`is-default`
|
||||
WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s') AND `profile`.`is-default`
|
||||
AND ((`contact`.`success_update` >= `contact`.`failure_update`) OR (`contact`.`last-item` >= `contact`.`failure_update`))
|
||||
AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d",
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
|
@ -115,8 +126,10 @@ function poco_init(&$a) {
|
|||
intval($itemsPerPage)
|
||||
);
|
||||
} else {
|
||||
logger("Start query for user ".$user['nickname'], LOGGER_DEBUG);
|
||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `hidden` = 0 AND `archive` = 0
|
||||
AND `network` IN ('%s', '%s', '%s', '%s', '') $sql_extra LIMIT %d, %d",
|
||||
AND (`success_update` >= `failure_update` OR `last-item` >= `failure_update`)
|
||||
AND `network` IN ('%s', '%s', '%s', '%s') $sql_extra LIMIT %d, %d",
|
||||
intval($user['uid']),
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
|
@ -126,6 +139,7 @@ function poco_init(&$a) {
|
|||
intval($itemsPerPage)
|
||||
);
|
||||
}
|
||||
logger("Query done", LOGGER_DEBUG);
|
||||
|
||||
$ret = array();
|
||||
if(x($_GET,'sorted'))
|
||||
|
@ -206,13 +220,19 @@ function poco_init(&$a) {
|
|||
if (($rr['keywords'] == "") AND isset($rr['pub_keywords']))
|
||||
$rr['keywords'] = $rr['pub_keywords'];
|
||||
|
||||
$about = Cache::get("about:".$rr['updated'].":".$rr['nurl']);
|
||||
if (is_null($about)) {
|
||||
$about = bbcode($rr['about'], false, false);
|
||||
Cache::set("about:".$rr['updated'].":".$rr['nurl'],$about);
|
||||
}
|
||||
|
||||
$entry = array();
|
||||
if($fields_ret['id'])
|
||||
$entry['id'] = (int)$rr['id'];
|
||||
if($fields_ret['displayName'])
|
||||
$entry['displayName'] = $rr['name'];
|
||||
if($fields_ret['aboutMe'])
|
||||
$entry['aboutMe'] = bbcode($rr['about'], false, false);
|
||||
$entry['aboutMe'] = $about;
|
||||
if($fields_ret['currentLocation'])
|
||||
$entry['currentLocation'] = $rr['location'];
|
||||
if($fields_ret['gender'])
|
||||
|
@ -295,6 +315,8 @@ function poco_init(&$a) {
|
|||
else
|
||||
http_status_exit(500);
|
||||
|
||||
logger("End of poco", LOGGER_DEBUG);
|
||||
|
||||
if($format === 'xml') {
|
||||
header('Content-type: text/xml');
|
||||
echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret)));
|
||||
|
|
|
@ -120,6 +120,10 @@ function search_content(&$a) {
|
|||
require_once('mod/dirfind.php');
|
||||
return dirfind_content($a);
|
||||
}
|
||||
if(strpos($search,'!') === 0) {
|
||||
require_once('mod/dirfind.php');
|
||||
return dirfind_content($a);
|
||||
}
|
||||
|
||||
if(! $search)
|
||||
return $o;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue