GlobalContact created
Moved DirSearch and GlobalContact related functions to Friendica\Model namespace
This commit is contained in:
parent
5f25ef55d2
commit
47db624105
26 changed files with 2715 additions and 2610 deletions
|
@ -1,64 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/DirSearch.php
|
||||
* @brief This file includes the DirSearch class with directory related functions
|
||||
*/
|
||||
|
||||
use Friendica\Core\Config;
|
||||
|
||||
/**
|
||||
* @brief This class handels directory related functions
|
||||
*/
|
||||
class DirSearch {
|
||||
|
||||
/**
|
||||
* @brief Search global contact table by nick or name
|
||||
*
|
||||
* @param string $search Name or nick
|
||||
* @param string $mode Search mode (e.g. "community")
|
||||
* @return array with search results
|
||||
*/
|
||||
public static function global_search_by_name($search, $mode = '') {
|
||||
|
||||
if($search) {
|
||||
// check supported networks
|
||||
if (Config::get('system','diaspora_enabled'))
|
||||
$diaspora = NETWORK_DIASPORA;
|
||||
else
|
||||
$diaspora = NETWORK_DFRN;
|
||||
|
||||
if (!Config::get('system','ostatus_disabled'))
|
||||
$ostatus = NETWORK_OSTATUS;
|
||||
else
|
||||
$ostatus = NETWORK_DFRN;
|
||||
|
||||
// check if we search only communities or every contact
|
||||
if($mode === "community")
|
||||
$extra_sql = " AND `community`";
|
||||
else
|
||||
$extra_sql = "";
|
||||
|
||||
$search .= "%";
|
||||
|
||||
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`,
|
||||
`gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`, `gcontact`.`community`
|
||||
FROM `gcontact`
|
||||
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
|
||||
AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
|
||||
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
|
||||
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
|
||||
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
|
||||
(`gcontact`.`addr` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`nick` LIKE '%s') $extra_sql
|
||||
GROUP BY `gcontact`.`nurl`
|
||||
ORDER BY `gcontact`.`nurl` DESC
|
||||
LIMIT 1000",
|
||||
intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
|
||||
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
|
||||
dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)));
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -7,10 +7,10 @@
|
|||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
|
||||
require_once "include/contact_selectors.php";
|
||||
require_once "include/contact_widgets.php";
|
||||
require_once "include/DirSearch.php";
|
||||
require_once "include/features.php";
|
||||
require_once "mod/proxy.php";
|
||||
|
||||
|
@ -59,10 +59,9 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
|
|||
return $o;
|
||||
}
|
||||
|
||||
/// @TODO after an optional parameter, no mandadory parameter can follow
|
||||
/// @TODO find proper type-hints
|
||||
function contact_selector($selname, $selclass, $preselected = false, $options) {
|
||||
|
||||
function contact_selector($selname, $selclass, $options, $preselected = false)
|
||||
{
|
||||
$a = get_app();
|
||||
|
||||
$mutual = false;
|
||||
|
@ -779,7 +778,7 @@ function navbar_complete(App $a) {
|
|||
}
|
||||
|
||||
if ($localsearch) {
|
||||
$x = DirSearch::global_search_by_name($search, $mode);
|
||||
$x = GlobalContact::searchByName($search, $mode);
|
||||
return $x;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Core\Config;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
|
||||
require_once 'include/contact_selectors.php';
|
||||
|
||||
|
@ -248,31 +249,28 @@ function common_friends_visitor_widget($profile_uid) {
|
|||
return;
|
||||
}
|
||||
|
||||
require_once 'include/socgraph.php';
|
||||
|
||||
if ($cid) {
|
||||
$t = count_common_friends($profile_uid, $cid);
|
||||
$t = GlobalContact::countCommonFriends($profile_uid, $cid);
|
||||
} else {
|
||||
$t = count_common_friends_zcid($profile_uid, $zcid);
|
||||
$t = GlobalContact::countCommonFriendsZcid($profile_uid, $zcid);
|
||||
}
|
||||
if (! $t) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cid) {
|
||||
$r = common_friends($profile_uid, $cid, 0, 5, true);
|
||||
$r = GlobalContact::commonFriends($profile_uid, $cid, 0, 5, true);
|
||||
} else {
|
||||
$r = common_friends_zcid($profile_uid, $zcid, 0, 5, true);
|
||||
$r = GlobalContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
|
||||
}
|
||||
|
||||
return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
|
||||
'$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
|
||||
'$desc' => sprintf(tt("%d contact in common", "%d contacts in common", $t), $t),
|
||||
'$base' => System::baseUrl(),
|
||||
'$uid' => $profile_uid,
|
||||
'$cid' => (($cid) ? $cid : '0'),
|
||||
'$linkmore' => (($t > 5) ? 'true' : ''),
|
||||
'$more' => t('show more'),
|
||||
'$items' => $r
|
||||
));
|
||||
|
||||
};
|
||||
'$items' => $r)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include cronjobs.php
|
||||
*/
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
use Friendica\Network\Probe;
|
||||
|
||||
function cronjobs_run(&$argv, &$argc){
|
||||
|
@ -266,7 +269,7 @@ function cron_repair_database() {
|
|||
$r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
|
||||
if (DBM::is_result($r)) {
|
||||
foreach ($r AS $user) {
|
||||
update_gcontact_for_user($user["uid"]);
|
||||
GlobalContact::updateForUser($user["uid"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/discover_poco.php
|
||||
*/
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\PortableContact;
|
||||
|
||||
require_once 'include/socgraph.php';
|
||||
require_once 'include/datetime.php';
|
||||
|
||||
function discover_poco_run(&$argv, &$argc) {
|
||||
|
||||
function discover_poco_run(&$argv, &$argc)
|
||||
{
|
||||
/*
|
||||
This function can be called in these ways:
|
||||
- dirsearch <search pattern>: Searches for "search pattern" in the directory. "search pattern" is url encoded.
|
||||
|
@ -18,7 +22,7 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
- server <poco url>: Searches for the poco server list. "poco url" is base64 encoded.
|
||||
- update_server: Frequently check the first 250 servers for vitality.
|
||||
- update_server_directory: Discover the given server id for their contacts
|
||||
- poco_load: Load POCO data from a given POCO address
|
||||
- PortableContact::load: Load POCO data from a given POCO address
|
||||
- check_profile: Update remote profile data
|
||||
*/
|
||||
|
||||
|
@ -35,7 +39,7 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
$mode = 5;
|
||||
} elseif (($argc == 3) && ($argv[1] == "update_server_directory")) {
|
||||
$mode = 6;
|
||||
} elseif (($argc > 5) && ($argv[1] == "poco_load")) {
|
||||
} elseif (($argc > 5) && ($argv[1] == "load")) {
|
||||
$mode = 7;
|
||||
} elseif (($argc == 3) && ($argv[1] == "check_profile")) {
|
||||
$mode = 8;
|
||||
|
@ -43,7 +47,8 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
$search = "";
|
||||
$mode = 0;
|
||||
} else {
|
||||
die("Unknown or missing parameter ".$argv[1]."\n");
|
||||
logger("Unknown or missing parameter ".$argv[1]."\n");
|
||||
return;
|
||||
}
|
||||
|
||||
logger('start '.$search);
|
||||
|
@ -58,7 +63,7 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
} else {
|
||||
$url = '';
|
||||
}
|
||||
poco_load_worker(intval($argv[2]), intval($argv[3]), intval($argv[4]), $url);
|
||||
PortableContact::load(intval($argv[2]), intval($argv[3]), intval($argv[4]), $url);
|
||||
} elseif ($mode == 6) {
|
||||
poco_discover_single_server(intval($argv[2]));
|
||||
} elseif ($mode == 5) {
|
||||
|
@ -81,19 +86,19 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
}
|
||||
logger($result, LOGGER_DEBUG);
|
||||
} elseif ($mode == 3) {
|
||||
update_suggestions();
|
||||
} elseif (($mode == 2) && Config::get('system','poco_completion')) {
|
||||
GlobalContact::updateSuggestions();
|
||||
} elseif (($mode == 2) && Config::get('system', 'poco_completion')) {
|
||||
discover_users();
|
||||
} elseif (($mode == 1) && ($search != "") && Config::get('system','poco_local_search')) {
|
||||
} elseif (($mode == 1) && ($search != "") && Config::get('system', 'poco_local_search')) {
|
||||
discover_directory($search);
|
||||
gs_search_user($search);
|
||||
} elseif (($mode == 0) && ($search == "") && (Config::get('system','poco_discovery') > 0)) {
|
||||
} elseif (($mode == 0) && ($search == "") && (Config::get('system', 'poco_discovery') > 0)) {
|
||||
// Query Friendica and Hubzilla servers for their users
|
||||
poco_discover();
|
||||
|
||||
// Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
|
||||
if (!Config::get('system','ostatus_disabled'))
|
||||
gs_discover();
|
||||
if (!Config::get('system', 'ostatus_disabled'))
|
||||
GlobalContact::gsDiscover();
|
||||
}
|
||||
|
||||
logger('end '.$search);
|
||||
|
@ -246,7 +251,7 @@ function discover_directory($search) {
|
|||
|
||||
$data["server_url"] = $data["baseurl"];
|
||||
|
||||
update_gcontact($data);
|
||||
GlobalContact::update($data);
|
||||
} else {
|
||||
logger("Profile ".$jj->url." is not responding or no Friendica contact - but network ".$data["network"], LOGGER_DEBUG);
|
||||
}
|
||||
|
@ -287,7 +292,7 @@ function gs_search_user($search) {
|
|||
$contact = Probe::uri($user->site_address."/".$user->name);
|
||||
if ($contact["network"] != NETWORK_PHANTOM) {
|
||||
$contact["about"] = $user->description;
|
||||
update_gcontact($contact);
|
||||
GlobalContact::update($contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/gprobe.php
|
||||
*/
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\PortableContact;
|
||||
|
||||
require_once 'include/socgraph.php';
|
||||
require_once 'include/datetime.php';
|
||||
|
||||
function gprobe_run(&$argv, &$argc){
|
||||
function gprobe_run(&$argv, &$argc)
|
||||
{
|
||||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
$url = $argv[1];
|
||||
|
||||
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($url))
|
||||
);
|
||||
|
||||
logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
|
||||
|
||||
if (!DBM::is_result($r)) {
|
||||
|
||||
// Is it a DDoS attempt?
|
||||
$urlparts = parse_url($url);
|
||||
|
||||
|
@ -39,17 +44,19 @@ function gprobe_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
||||
update_gcontact($arr);
|
||||
GlobalContact::update($arr);
|
||||
}
|
||||
|
||||
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
$r = q(
|
||||
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($url))
|
||||
);
|
||||
}
|
||||
if (DBM::is_result($r)) {
|
||||
// Check for accessibility and do a poco discovery
|
||||
if (poco_last_updated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN))
|
||||
poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
|
||||
if (poco_last_updated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
|
||||
PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
|
||||
}
|
||||
}
|
||||
|
||||
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
|
||||
|
|
|
@ -12,6 +12,7 @@ use Friendica\Core\Config;
|
|||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
use Friendica\Protocol\DFRN;
|
||||
|
||||
require_once 'include/bbcode.php';
|
||||
|
@ -745,10 +746,10 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
* On comments the author is the better choice.
|
||||
*/
|
||||
if ($arr['parent-uri'] === $arr['uri']) {
|
||||
$arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['owner-link'], "network" => $arr['network'],
|
||||
$arr["gcontact-id"] = GlobalContact::getId(array("url" => $arr['owner-link'], "network" => $arr['network'],
|
||||
"photo" => $arr['owner-avatar'], "name" => $arr['owner-name']));
|
||||
} else {
|
||||
$arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['author-link'], "network" => $arr['network'],
|
||||
$arr["gcontact-id"] = GlobalContact::getId(array("url" => $arr['author-link'], "network" => $arr['network'],
|
||||
"photo" => $arr['author-avatar'], "name" => $arr['author-name']));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use Friendica\Core\Cache;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\Lock;
|
||||
use Friendica\Util\XML;
|
||||
|
@ -225,9 +226,9 @@ class ostatus
|
|||
$contact["generation"] = 2;
|
||||
$contact["hide"] = false; // OStatus contacts are never hidden
|
||||
$contact["photo"] = $author["author-avatar"];
|
||||
$gcid = update_gcontact($contact);
|
||||
$gcid = GlobalContact::update($contact);
|
||||
|
||||
link_gcontact($gcid, $contact["uid"], $contact["id"]);
|
||||
GlobalContact::link($gcid, $contact["uid"], $contact["id"]);
|
||||
}
|
||||
|
||||
return $author;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Model\GlobalContact;
|
||||
|
||||
/**
|
||||
* @brief Calls the post update functions
|
||||
|
@ -72,7 +73,7 @@ function post_update_1192() {
|
|||
|
||||
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
|
||||
foreach ($item_arr AS $item) {
|
||||
$gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
|
||||
$gcontact_id = GlobalContact::getId(array("url" => $item['author-link'], "network" => $item['network'],
|
||||
"photo" => $item['author-avatar'], "name" => $item['author-name']));
|
||||
q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
|
||||
intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
|
||||
|
|
2446
include/socgraph.php
2446
include/socgraph.php
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue