Global and Portable Contact
This commit is contained in:
Michael Vogel 2017-11-15 20:51:26 +01:00 committed by GitHub
commit 38847af687
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 2865 additions and 2712 deletions

View file

@ -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;
}
}
}

View file

@ -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;
}

View file

@ -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)
);
}

View file

@ -1,10 +1,14 @@
<?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;
use Friendica\Protocol\PortableContact;
function cronjobs_run(&$argv, &$argc){
global $a;
@ -14,7 +18,6 @@ function cronjobs_run(&$argv, &$argc){
require_once 'mod/nodeinfo.php';
require_once 'include/photos.php';
require_once 'include/user.php';
require_once 'include/socgraph.php';
// No parameter set? So return
if ($argc <= 1) {
@ -223,7 +226,7 @@ function cron_repair_diaspora(App $a) {
return;
}
if (!poco_reachable($contact["url"])) {
if (!PortableContact::reachable($contact["url"])) {
continue;
}
@ -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"]);
}
}

View file

@ -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,14 +47,15 @@ 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);
if ($mode == 8) {
if ($argv[2] != "") {
poco_last_updated($argv[2], true);
PortableContact::lastUpdated($argv[2], true);
}
} elseif ($mode == 7) {
if ($argc == 6) {
@ -58,9 +63,9 @@ 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]));
PortableContact::discoverSingleServer(intval($argv[2]));
} elseif ($mode == 5) {
update_server();
} elseif ($mode == 4) {
@ -73,7 +78,7 @@ function discover_poco_run(&$argv, &$argc) {
return;
}
$result = "Checking server ".$server_url." - ";
$ret = poco_check_server($server_url);
$ret = PortableContact::checkServer($server_url);
if ($ret) {
$result .= "success";
} else {
@ -81,19 +86,20 @@ 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();
PortableContact::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::discoverGsUsers();
}
}
logger('end '.$search);
@ -115,7 +121,7 @@ function update_server() {
$updated = 0;
foreach ($r AS $server) {
if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) {
if (!PortableContact::updateNeeded($server["created"], "", $server["last_failure"], $server["last_contact"])) {
continue;
}
logger('Update server status for server '.$server["url"], LOGGER_DEBUG);
@ -167,7 +173,7 @@ function discover_users() {
continue;
}
$server_url = poco_detect_server($user["url"]);
$server_url = PortableContact::detectServer($user["url"]);
$force_update = false;
if ($user["server_url"] != "") {
@ -177,7 +183,7 @@ function discover_users() {
$server_url = $user["server_url"];
}
if ((($server_url == "") && ($user["network"] == NETWORK_FEED)) || $force_update || poco_check_server($server_url, $user["network"])) {
if ((($server_url == "") && ($user["network"] == NETWORK_FEED)) || $force_update || PortableContact::checkServer($server_url, $user["network"])) {
logger('Check profile '.$user["url"]);
Worker::add(PRIORITY_LOW, "discover_poco", "check_profile", $user["url"]);
@ -222,13 +228,13 @@ function discover_directory($search) {
continue;
}
// Update the contact
poco_last_updated($jj->url);
PortableContact::lastUpdated($jj->url);
continue;
}
$server_url = poco_detect_server($jj->url);
$server_url = PortableContact::detectServer($jj->url);
if ($server_url != '') {
if (!poco_check_server($server_url)) {
if (!PortableContact::checkServer($server_url)) {
logger("Friendica server ".$server_url." doesn't answer.", LOGGER_DEBUG);
continue;
}
@ -246,7 +252,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 +293,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);
}
}
}

View file

@ -1,5 +1,7 @@
<?php
/**
* @file include/follow.php
*/
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\System;
@ -7,8 +9,8 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\PortableContact;
require_once 'include/socgraph.php';
require_once 'include/group.php';
require_once 'include/salmon.php';
require_once 'include/ostatus.php';
@ -57,7 +59,7 @@ function update_contact($id) {
);
// Update the corresponding gcontact entry
poco_last_updated($ret["url"]);
PortableContact::lastUpdated($ret["url"]);
return true;
}

View file

@ -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 (PortableContact::lastUpdated($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);

View file

@ -5,14 +5,15 @@
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\ParseUrl;
use Friendica\Util\Lock;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Protocol\DFRN;
use Friendica\Util\Lock;
require_once 'include/bbcode.php';
require_once 'include/oembed.php';
@ -24,7 +25,6 @@ require_once 'include/files.php';
require_once 'include/text.php';
require_once 'include/email.php';
require_once 'include/threads.php';
require_once 'include/socgraph.php';
require_once 'include/plaintext.php';
require_once 'include/ostatus.php';
require_once 'include/feed.php';
@ -745,10 +745,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']));
}
}

View file

@ -5,9 +5,10 @@
use Friendica\App;
use Friendica\Core\Cache;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
use Friendica\Util\Lock;
use Friendica\Util\XML;
@ -19,7 +20,6 @@ require_once 'include/bbcode.php';
require_once 'include/items.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
require_once 'include/socgraph.php';
require_once 'include/Photo.php';
require_once 'include/follow.php';
require_once 'include/api.php';
@ -225,9 +225,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;

View file

@ -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"]));

View file

@ -41,7 +41,7 @@ function handle_pubsubhubbub($id) {
$rr = $r[0];
/// @todo Check server status with poco_check_server()
/// @todo Check server status with PortableContact::checkServer()
// Before this can be done we need a way to safely detect the server url.
logger("Generate feed of user ".$rr['nickname']." to ".$rr['callback_url']." - last updated ".$rr['last_update'], LOGGER_DEBUG);

View file

@ -8,12 +8,12 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\PortableContact;
require_once 'include/queue_fn.php';
require_once 'include/datetime.php';
require_once 'include/items.php';
require_once 'include/bbcode.php';
require_once 'include/socgraph.php';
function queue_run(&$argv, &$argc)
{
@ -99,7 +99,7 @@ function queue_run(&$argv, &$argc)
return;
}
$server = poco_detect_server($c[0]['url']);
$server = PortableContact::detectServer($c[0]['url']);
if ($server != "") {
$vital = Cache::get($cachekey_server.$server);
@ -107,7 +107,7 @@ function queue_run(&$argv, &$argc)
if (is_null($vital)) {
logger("Check server ".$server." (".$c[0]["network"].")");
$vital = poco_check_server($server, $c[0]["network"], true);
$vital = PortableContact::checkServer($server, $c[0]["network"], true);
Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR);
}

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,15 @@
<?php
/**
* @file include/update_gcontact.php
*/
use Friendica\Core\Config;
use Friendica\Network\Probe;
use Friendica\Database\DBM;
use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact;
function update_gcontact_run(&$argv, &$argc) {
global $a;
require_once 'include/socgraph.php';
logger('update_gcontact: start');
if (($argc > 1) && (intval($argv[1]))) {
@ -34,7 +35,7 @@ function update_gcontact_run(&$argv, &$argc) {
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
if ($r[0]["server_url"] != "")
poco_check_server($r[0]["server_url"], $r[0]["network"]);
PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]);
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
dbesc(datetime_convert()), intval($contact_id));

View file

@ -1,13 +1,15 @@
<?php
/**
* @file mod/allfriends.php
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
require_once('include/socgraph.php');
require_once('include/Contact.php');
require_once('include/contact_selectors.php');
require_once('mod/contacts.php');
require_once 'include/Contact.php';
require_once 'include/contact_selectors.php';
require_once 'mod/contacts.php';
function allfriends_content(App $a) {
@ -39,12 +41,12 @@ function allfriends_content(App $a) {
$a->page['aside'] = "";
profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"]));
$total = count_all_friends(local_user(), $cid);
$total = GlobalContact::countAllFriends(local_user(), $cid);
if(count($total))
$a->set_pager_total($total);
$r = all_friends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
$r = GlobalContact::allFriends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']);
if (! DBM::is_result($r)) {
$o .= t('No friends to display.');

View file

@ -1,12 +1,14 @@
<?php
/**
* @file include/common.php
*/
use Friendica\App;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
require_once('include/socgraph.php');
require_once('include/Contact.php');
require_once('include/contact_selectors.php');
require_once('mod/contacts.php');
require_once 'include/Contact.php';
require_once 'include/contact_selectors.php';
require_once 'mod/contacts.php';
function common_content(App $a) {
@ -83,23 +85,23 @@ function common_content(App $a) {
}
if ($cid) {
$t = count_common_friends($uid, $cid);
$t = GlobalContact::countCommonFriends($uid, $cid);
} else {
$t = count_common_friends_zcid($uid, $zcid);
$t = GlobalContact::countCommonFriendsZcid($uid, $zcid);
}
if (count($t)) {
$a->set_pager_total($t);
} else {
notice( t('No contacts in common.') . EOL);
notice(t('No contacts in common.') . EOL);
return $o;
}
if ($cid) {
$r = common_friends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
$r = GlobalContact::commonFriends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
} else {
$r = common_friends_zcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
$r = GlobalContact::commonFriendsZcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
}

View file

@ -4,10 +4,10 @@ use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
require_once 'include/Contact.php';
require_once 'include/socgraph.php';
require_once 'include/contact_selectors.php';
require_once 'mod/proxy.php';
require_once 'include/Photo.php';
@ -312,7 +312,7 @@ function _contact_update_profile($contact_id) {
update_contact_avatar($data['photo'], local_user(), $contact_id, true);
// Update the entry in the gcontact table
update_gcontact_from_probe($data["url"]);
GlobalContact::updateFromProbe($data["url"]);
}
function _contact_block($contact_id, $orig_record) {
@ -561,12 +561,12 @@ function contacts_content(App $a) {
$nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
//$common = count_common_friends(local_user(),$contact['id']);
//$common = GlobalContact::countCommonFriends(local_user(),$contact['id']);
//$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
$polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
//$x = count_all_friends(local_user(), $contact['id']);
//$x = GlobalContact::countAllFriends(local_user(), $contact['id']);
//$all_friends = (($x) ? t('View all contacts') : '');
// tabs
@ -878,7 +878,7 @@ function contacts_tab($a, $contact_id, $active_tab) {
);
// Show this tab only if there is visible friend list
$x = count_all_friends(local_user(), $contact_id);
$x = GlobalContact::countAllFriends(local_user(), $contact_id);
if ($x)
$tabs[] = array('label'=>t('Contacts'),
'url' => "allfriends/".$contact_id,
@ -888,7 +888,7 @@ function contacts_tab($a, $contact_id, $active_tab) {
'accesskey' => 't');
// Show this tab only if there is visible common friend list
$common = count_common_friends(local_user(),$contact_id);
$common = GlobalContact::countCommonFriends(local_user(), $contact_id);
if ($common)
$tabs[] = array('label'=>t('Common Friends'),
'url' => "common/loc/".local_user()."/".$contact_id,

View file

@ -1,13 +1,16 @@
<?php
/**
* @file mod/dirfind.php
*/
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact;
require_once 'include/contact_widgets.php';
require_once 'include/socgraph.php';
require_once 'include/Contact.php';
require_once 'include/contact_selectors.php';
require_once 'mod/contacts.php';
@ -79,7 +82,7 @@ function dirfind_content(App $a, $prefix = "") {
// Add the contact to the global contacts if it isn't already in our system
if (($contact["cid"] == 0) && ($contact["zid"] == 0) && ($contact["gid"] == 0)) {
update_gcontact($user_data);
GlobalContact::update($user_data);
}
} elseif ($local) {
@ -142,7 +145,7 @@ function dirfind_content(App $a, $prefix = "") {
$j->items_page = $perpage;
$j->page = $a->pager['page'];
foreach ($results AS $result) {
if (poco_alternate_ostatus_url($result["url"])) {
if (PortableContact::alternateOStatusUrl($result["url"])) {
continue;
}

View file

@ -74,38 +74,44 @@ function fsuggest_post(App $a) {
function fsuggest_content(App $a) {
require_once('include/acl_selectors.php');
function fsuggest_content(App $a)
{
require_once 'include/acl_selectors.php';
if (! local_user()) {
notice( t('Permission denied.') . EOL);
notice(t('Permission denied.') . EOL);
return;
}
if($a->argc != 2)
if ($a->argc != 2) {
return;
}
$contact_id = intval($a->argv[1]);
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
$r = q(
"SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id),
intval(local_user())
);
if (! DBM::is_result($r)) {
notice( t('Contact not found.') . EOL);
notice(t('Contact not found.') . EOL);
return;
}
$contact = $r[0];
$o = '<h3>' . t('Suggest Friends') . '</h3>';
$o .= '<div id="fsuggest-desc" >' . sprintf( t('Suggest a friend for %s'), $contact['name']) . '</div>';
$o .= '<div id="fsuggest-desc" >' . sprintf(t('Suggest a friend for %s'), $contact['name']) . '</div>';
$o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >';
$o .= contact_selector('suggest','suggest-select', false,
array('size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true));
$o .= contact_selector(
'suggest',
'suggest-select',
array('size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true),
false
);
$o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . t('Submit') . '" /></div>';

View file

@ -10,9 +10,9 @@
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Model\GlobalContact;
require_once("include/socgraph.php");
require_once("include/Contact.php");
require_once "include/Contact.php";
function hovercard_init(App $a) {
// Just for testing purposes
@ -48,7 +48,7 @@ function hovercard_content() {
}
// if it's the url containing https it should be converted to http
$nurl = normalise_link(clean_contact_url($profileurl));
$nurl = normalise_link(GlobalContact::cleanContactUrl($profileurl));
if($nurl) {
// Search for contact data
$contact = get_contact_details_by_url($nurl);

View file

@ -20,6 +20,7 @@ use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora;
@ -737,7 +738,7 @@ function item_post(App $a) {
$datarray['postopts'] = $postopts;
$datarray['origin'] = $origin;
$datarray['moderated'] = $allow_moderated;
$datarray['gcontact-id'] = get_gcontact_id(array("url" => $datarray['author-link'], "network" => $datarray['network'],
$datarray['gcontact-id'] = GlobalContact::getId(array("url" => $datarray['author-link'], "network" => $datarray['network'],
"photo" => $datarray['author-avatar'], "name" => $datarray['author-name']));
$datarray['object'] = $object;
@ -1132,9 +1133,8 @@ function item_content(App $a) {
*
* @return boolean true if replaced, false if not replaced
*/
function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") {
require_once 'include/socgraph.php';
function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "")
{
$replaced = false;
$r = null;
$tag_type = '@';
@ -1239,7 +1239,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
if (!DBM::is_result($r)) {
$probed = Probe::uri($name);
if ($result['network'] != NETWORK_PHANTOM) {
update_gcontact($probed);
GlobalContact::update($probed);
$r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($probed["url"])));
}

View file

@ -1,14 +1,15 @@
<?php
/**
* @file mod/match.php
*/
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM;
require_once('include/text.php');
require_once('include/socgraph.php');
require_once('include/contact_widgets.php');
require_once('mod/proxy.php');
require_once 'include/text.php';
require_once 'include/contact_widgets.php';
require_once 'mod/proxy.php';
/**
* @brief Controller for /match.
@ -16,11 +17,12 @@ require_once('mod/proxy.php');
* It takes keywords from your profile and queries the directory server for
* matching keywords from other profiles.
*
* @param App $a
* @param App $a App
*
* @return void|string
*/
function match_content(App $a) {
function match_content(App $a)
{
$o = '';
if (! local_user()) {
return;
@ -31,46 +33,50 @@ function match_content(App $a) {
$_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
$r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
$r = q(
"SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
intval(local_user())
);
if (! DBM::is_result($r)) {
return;
}
if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
notice( t('No keywords to match. Please add keywords to your default profile.') . EOL);
if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
notice(t('No keywords to match. Please add keywords to your default profile.') . EOL);
return;
}
$params = array();
$tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
if($tags) {
if ($tags) {
$params['s'] = $tags;
if($a->pager['page'] != 1)
if ($a->pager['page'] != 1) {
$params['p'] = $a->pager['page'];
}
if(strlen(Config::get('system','directory')))
if (strlen(Config::get('system', 'directory'))) {
$x = post_url(get_server().'/msearch', $params);
else
} else {
$x = post_url(System::baseUrl() . '/msearch', $params);
}
$j = json_decode($x);
if($j->total) {
if ($j->total) {
$a->set_pager_total($j->total);
$a->set_pager_itemspage($j->items_page);
}
if(count($j->results)) {
if (count($j->results)) {
$id = 0;
foreach($j->results as $jj) {
foreach ($j->results as $jj) {
$match_nurl = normalise_link($jj->url);
$match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
$match = q(
"SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
intval(local_user()),
dbesc($match_nurl));
dbesc($match_nurl)
);
if (!count($match)) {
$jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
@ -102,19 +108,18 @@ function match_content(App $a) {
}
}
$tpl = get_markup_template('viewcontact_template.tpl');
$o .= replace_macros($tpl,array(
'$title' => t('Profile Match'),
'$contacts' => $entries,
'$paginate' => paginate($a),
));
$tpl = get_markup_template('viewcontact_template.tpl');
$o .= replace_macros(
$tpl,
array(
'$title' => t('Profile Match'),
'$contacts' => $entries,
'$paginate' => paginate($a))
);
} else {
info(t('No matches') . EOL);
}
else {
info( t('No matches') . EOL);
}
}
return $o;

View file

@ -1,45 +1,44 @@
<?php
/**
* @file mod/nogroup.php
*/
use Friendica\App;
use Friendica\Database\DBM;
require_once('include/Contact.php');
require_once('include/socgraph.php');
require_once('include/contact_selectors.php');
function nogroup_init(App $a) {
require_once 'include/Contact.php';
require_once 'include/contact_selectors.php';
function nogroup_init(App $a)
{
if (! local_user()) {
return;
}
require_once('include/group.php');
require_once('include/contact_widgets.php');
require_once 'include/group.php';
require_once 'include/contact_widgets.php';
if (! x($a->page,'aside')) {
if (! x($a->page, 'aside')) {
$a->page['aside'] = '';
}
$a->page['aside'] .= group_side('contacts','group','extended',0,$contact_id);
$a->page['aside'] .= group_side('contacts', 'group', 'extended', 0, $contact_id);
}
function nogroup_content(App $a) {
function nogroup_content(App $a)
{
if (! local_user()) {
notice( t('Permission denied.') . EOL);
notice(t('Permission denied.') . EOL);
return '';
}
require_once('include/Contact.php');
require_once 'include/Contact.php';
$r = contacts_not_grouped(local_user());
if (DBM::is_result($r)) {
$a->set_pager_total($r[0]['total']);
}
$r = contacts_not_grouped(local_user(),$a->pager['start'],$a->pager['itemspage']);
$r = contacts_not_grouped(local_user(), $a->pager['start'], $a->pager['itemspage']);
if (DBM::is_result($r)) {
foreach ($r as $rr) {
$contact_details = get_contact_details_by_url($rr['url'], local_user(), $rr);
$contacts[] = array(
@ -64,12 +63,13 @@ function nogroup_content(App $a) {
}
$tpl = get_markup_template("nogroup-template.tpl");
$o .= replace_macros($tpl, array(
$o .= replace_macros(
$tpl,
array(
'$header' => t('Contacts who are not members of a group'),
'$contacts' => $contacts,
'$paginate' => paginate($a),
));
'$paginate' => paginate($a))
);
return $o;
}

View file

@ -7,6 +7,7 @@ use Friendica\App;
use Friendica\Core\Cache;
use Friendica\Core\Config;
use Friendica\Database\DBM;
use Friendica\Protocol\PortableContact;
function poco_init(App $a) {
$system_mode = false;
@ -32,9 +33,8 @@ function poco_init(App $a) {
$global = false;
if ($a->argc > 1 && $a->argv[1] === '@server') {
require_once 'include/socgraph.php';
// List of all servers that this server knows
$ret = poco_serverlist();
$ret = PortableContact::serverlist();
header('Content-type: application/json');
echo json_encode($ret);
killme();

View file

@ -1,15 +1,17 @@
<?php
/**
* @file mod/profiles.php
*/
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
require_once 'include/Contact.php';
require_once 'include/socgraph.php';
function profiles_init(App $a) {
@ -507,7 +509,7 @@ function profiles_post(App $a) {
Worker::add(PRIORITY_LOW, 'profile_update', local_user());
// Update the global contact for the user
update_gcontact_for_user(local_user());
GlobalContact::updateForUser(local_user());
}
}
}
@ -752,7 +754,6 @@ function profiles_content(App $a) {
return $o;
} else {
// If we don't support multi profiles, don't display this list.
if (!feature_enabled(local_user(), 'multi_profiles')) {
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",

View file

@ -1,14 +1,16 @@
<?php
/**
* @file mod/settings.php
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
require_once('include/group.php');
require_once('include/socgraph.php');
require_once 'include/group.php';
function get_theme_config_file($theme) {
$a = get_app();
@ -650,7 +652,7 @@ function settings_post(App $a) {
Worker::add(PRIORITY_LOW, 'profile_update', local_user());
// Update the global contact for the user
update_gcontact_for_user(local_user());
GlobalContact::updateForUser(local_user());
//$_SESSION['theme'] = $theme;
if ($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {

View file

@ -1,11 +1,13 @@
<?php
/**
* @file mod/suggest.php
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
require_once('include/socgraph.php');
require_once('include/contact_widgets.php');
require_once 'include/contact_widgets.php';
function suggest_init(App $a) {
if (! local_user()) {
@ -66,7 +68,7 @@ function suggest_content(App $a) {
$a->page['aside'] .= follow_widget();
$r = suggestion_query(local_user());
$r = GlobalContact::suggestionQuery(local_user());
if (! DBM::is_result($r)) {
$o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');

1004
src/Model/GlobalContact.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,7 @@ use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Model\GlobalContact;
use Friendica\Database\DBM;
use Friendica\Util\XML;
@ -23,7 +24,6 @@ use ostatus;
require_once "include/Contact.php";
require_once "include/enotify.php";
require_once "include/threads.php";
require_once "include/socgraph.php";
require_once "include/items.php";
require_once "include/tags.php";
require_once "include/files.php";
@ -1675,9 +1675,9 @@ class DFRN
$poco["photo"] = $author["avatar"];
$poco["hide"] = $hide;
$poco["contact-type"] = $contact["contact-type"];
$gcid = update_gcontact($poco);
$gcid = GlobalContact::update($poco);
link_gcontact($gcid, $importer["uid"], $contact["id"]);
GlobalContact::link($gcid, $importer["uid"], $contact["id"]);
}
return($author);

View file

@ -16,6 +16,7 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
use Friendica\Network\Probe;
use Friendica\Util\XML;
@ -26,7 +27,6 @@ require_once 'include/items.php';
require_once 'include/bb2diaspora.php';
require_once 'include/Contact.php';
require_once 'include/Photo.php';
require_once 'include/socgraph.php';
require_once 'include/group.php';
require_once 'include/datetime.php';
require_once 'include/queue_fn.php';
@ -2246,9 +2246,9 @@ class Diaspora
"addr" => $author, "nick" => $nick, "keywords" => $keywords,
"hide" => !$searchable, "nsfw" => $nsfw);
$gcid = update_gcontact($gcontact);
$gcid = GlobalContact::update($gcontact);
link_gcontact($gcid, $importer["uid"], $contact["id"]);
GlobalContact::link($gcid, $importer["uid"], $contact["id"]);
logger("Profile of contact ".$contact["id"]." stored for user ".$importer["uid"], LOGGER_DEBUG);

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,19 @@
<?php
/**
* @file src/Worker/OnePoll.php
*/
namespace Friendica\Worker;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Protocol\PortableContact;
use dba;
require_once 'include/follow.php';
Class OnePoll {
Class OnePoll
{
public static function execute($contact_id = 0, $command = '') {
global $a;
@ -16,7 +21,6 @@ Class OnePoll {
require_once 'include/items.php';
require_once 'include/Contact.php';
require_once 'include/email.php';
require_once 'include/socgraph.php';
require_once 'include/queue_fn.php';
logger('onepoll: start');
@ -72,7 +76,7 @@ Class OnePoll {
);
if (DBM::is_result($r)) {
if (!$r[0]['total']) {
poco_load($contact['id'], $importer_uid, 0, $contact['poco']);
PortableContact::loadWorker($contact['id'], $importer_uid, 0, $contact['poco']);
}
}
}
@ -80,8 +84,8 @@ Class OnePoll {
/// @TODO Check why we don't poll the Diaspora feed at the moment (some guid problem in the items?)
/// @TODO Check whether this is possible with Redmatrix
if ($contact["network"] == NETWORK_DIASPORA) {
if (poco_do_update($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) {
$last_updated = poco_last_updated($contact["url"]);
if (PortableContact::updateNeeded($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) {
$last_updated = PortableContact::lastUpdated($contact["url"]);
$updated = datetime_convert();
if ($last_updated) {
$fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
@ -116,7 +120,7 @@ Class OnePoll {
// Update the contact entry
if (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN)) {
if (!poco_reachable($contact['url'])) {
if (!PortableContact::reachable($contact['url'])) {
logger("Skipping probably dead contact ".$contact['url']);
return;
}

View file

@ -14,9 +14,9 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\GlobalContact;
require_once "include/plugin.php";
require_once "include/socgraph.php";
require_once "mod/proxy.php";
function vier_init(App $a) {
@ -138,8 +138,7 @@ function vier_community_info() {
// comunity_profiles
if ($show_profiles) {
$r = suggestion_query(local_user(), 0, 9);
$r = GlobalContact::suggestionQuery(local_user(), 0, 9);
$tpl = get_markup_template('ch_directory_item.tpl');
if (DBM::is_result($r)) {