use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact;
use Friendica\Util\Network;
+use Friendica\Database\DBM;
require_once 'mod/contacts.php';
/// @TODO These 2 SELECTs are not checked on validity with DBM::is_result()
$count = q("SELECT count(*) AS `total` FROM `gcontact`
- LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
- AND `contact`.`network` = `gcontact`.`network`
- 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`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
- `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
- intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
+ WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s') AND
+ ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
+ (`url` LIKE '%s' OR `name` LIKE '%s' OR `location` LIKE '%s' OR
+ `addr` LIKE '%s' OR `about` LIKE '%s' OR `keywords` LIKE '%s') $extra_sql",
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)));
- $results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`
+ $results = q("SELECT `nurl`
FROM `gcontact`
- LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
- AND `contact`.`network` = `gcontact`.`network`
- 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`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
- `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql
- GROUP BY `gcontact`.`nurl`
- ORDER BY `gcontact`.`updated` DESC LIMIT %d, %d",
- intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
+ WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s') AND
+ ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
+ (`url` LIKE '%s' OR `name` LIKE '%s' OR `location` LIKE '%s' OR
+ `addr` LIKE '%s' OR `about` LIKE '%s' OR `keywords` LIKE '%s') $extra_sql
+ GROUP BY `nurl`
+ ORDER BY `updated` DESC LIMIT %d, %d",
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
$j->items_page = $perpage;
$j->page = $a->pager['page'];
foreach ($results AS $result) {
- if (PortableContact::alternateOStatusUrl($result["url"])) {
+ if (PortableContact::alternateOStatusUrl($result["nurl"])) {
continue;
}
- $result = Contact::getDetailsByURL($result["url"], local_user(), $result);
+ $urlparts = parse_url($result["nurl"]);
+
+ // Ignore results that look strange.
+ // For historic reasons the gcontact table does contain some garbage.
+ if (!empty($urlparts['query']) || !empty($urlparts['fragment'])) {
+ continue;
+ }
+
+ $result = Contact::getDetailsByURL($result["nurl"], local_user());
if ($result["name"] == "") {
- $urlparts = parse_url($result["url"]);
$result["name"] = end(explode("/", $urlparts["path"]));
}
if ($jj->cid > 0) {
$connlnk = "";
$conntxt = "";
- $contact = q("SELECT * FROM `contact` WHERE `id` = %d",
- intval($jj->cid));
- if ($contact) {
- $photo_menu = Contact::photoMenu($contact[0]);
- $details = _contact_detail_for_template($contact[0]);
+ $contact = dba::selectFirst('contact', [], ['id' => $jj->cid]);
+ if (DBM::is_result($contact)) {
+ $photo_menu = Contact::photoMenu($contact);
+ $details = _contact_detail_for_template($contact);
$alt_text = $details['alt_text'];
} else {
$photo_menu = [];
}
$sparkle = false;
- if ($contact['network'] === NETWORK_DFRN) {
+ if (($contact['network'] === NETWORK_DFRN) && !$contact['self']) {
$sparkle = true;
$profile_link = System::baseUrl() . '/redir/' . $contact['id'];
} else {
$profile_link = $profile_link . '?url=profile';
}
- if (in_array($contact['network'], [NETWORK_DFRN, NETWORK_DIASPORA])) {
+ if (in_array($contact['network'], [NETWORK_DFRN, NETWORK_DIASPORA]) && !$contact['self']) {
$pm_url = System::baseUrl() . '/message/new/' . $contact['id'];
}
- if ($contact['network'] == NETWORK_DFRN) {
+ if (($contact['network'] == NETWORK_DFRN) && !$contact['self']) {
$poke_link = System::baseUrl() . '/poke/?f=&c=' . $contact['id'];
}
$contact_url = System::baseUrl() . '/contacts/' . $contact['id'];
$posts_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/posts';
- $contact_drop_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
+
+ if (!$contact['self']) {
+ $contact_drop_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
+ }
/**
* Menu array:
*/
public static function searchByName($search, $mode = '')
{
- if ($search) {
- // check supported networks
- if (Config::get('system', 'diaspora_enabled')) {
- $diaspora = NETWORK_DIASPORA;
- } else {
- $diaspora = NETWORK_DFRN;
- }
+ if (empty($search)) {
+ return [];
+ }
- if (!Config::get('system', 'ostatus_disabled')) {
- $ostatus = NETWORK_OSTATUS;
- } else {
- $ostatus = NETWORK_DFRN;
- }
+ // check supported networks
+ if (Config::get('system', 'diaspora_enabled')) {
+ $diaspora = NETWORK_DIASPORA;
+ } else {
+ $diaspora = NETWORK_DFRN;
+ }
- // check if we search only communities or every contact
- if ($mode === "community") {
- $extra_sql = " AND `community`";
- } else {
- $extra_sql = "";
- }
+ if (!Config::get('system', 'ostatus_disabled')) {
+ $ostatus = NETWORK_OSTATUS;
+ } else {
+ $ostatus = NETWORK_DFRN;
+ }
- $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))
- );
+ // check if we search only communities or every contact
+ if ($mode === "community") {
+ $extra_sql = " AND `community`";
+ } else {
+ $extra_sql = "";
+ }
+
+ $search .= "%";
+
+ $results = dba::p("SELECT `nurl` FROM `gcontact`
+ WHERE NOT `hide` AND `network` IN (?, ?, ?) AND
+ ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
+ (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
+ GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000",
+ NETWORK_DFRN, $ostatus, $diaspora, $search, $search, $search
+ );
+
+ $gcontacts = [];
+ while ($result = dba::fetch($results)) {
+ $urlparts = parse_url($result["nurl"]);
+
+ // Ignore results that look strange.
+ // For historic reasons the gcontact table does contain some garbage.
+ if (!empty($urlparts['query']) || !empty($urlparts['fragment'])) {
+ continue;
+ }
- return $results;
+ $gcontacts[] = Contact::getDetailsByURL($result["nurl"], local_user());
}
+ return $gcontacts;
}
/**