Merge pull request #4614 from annando/dir-own-contact

Fix: In the contact search you had been able to delete your own contact
This commit is contained in:
Hypolite Petovan 2018-03-17 08:42:51 -04:00 committed by GitHub
commit d1c93e7a60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 82 deletions

View file

@ -45,6 +45,14 @@ function contacts_init(App $a)
} }
if (DBM::is_result($contact)) { if (DBM::is_result($contact)) {
if ($contact['self']) {
if (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts")) {
goaway('profile/' . $contact['nick']);
} else {
goaway('profile/' . $contact['nick'] . '?tab=profile');
}
}
$a->data['contact'] = $contact; $a->data['contact'] = $contact;
if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) { if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
@ -940,6 +948,13 @@ function _contact_detail_for_template($rr)
$sparkle = ''; $sparkle = '';
} }
if ($rr['self']) {
$dir_icon = 'images/larrow.gif';
$alt_text = L10n::t('This is you');
$url = $rr['url'];
$sparkle = '';
}
return [ return [
'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']), 'img_hover' => L10n::t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']),
'edit_hover' => L10n::t('Edit contact'), 'edit_hover' => L10n::t('Edit contact'),

View file

@ -15,6 +15,7 @@ use Friendica\Model\Profile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Database\DBM;
require_once 'mod/contacts.php'; require_once 'mod/contacts.php';
@ -113,32 +114,22 @@ function dirfind_content(App $a, $prefix = "") {
/// @TODO These 2 SELECTs are not checked on validity with DBM::is_result() /// @TODO These 2 SELECTs are not checked on validity with DBM::is_result()
$count = q("SELECT count(*) AS `total` FROM `gcontact` $count = q("SELECT count(*) AS `total` FROM `gcontact`
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s') AND
AND `contact`.`network` = `gcontact`.`network` ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
AND `contact`.`uid` = %d AND NOT `contact`.`blocked` (`url` LIKE '%s' OR `name` LIKE '%s' OR `location` LIKE '%s' OR
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s') `addr` LIKE '%s' OR `about` LIKE '%s' OR `keywords` LIKE '%s') $extra_sql",
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),
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), 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)),
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` FROM `gcontact`
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s') AND
AND `contact`.`network` = `gcontact`.`network` ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
AND `contact`.`uid` = %d AND NOT `contact`.`blocked` (`url` LIKE '%s' OR `name` LIKE '%s' OR `location` LIKE '%s' OR
AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s') `addr` LIKE '%s' OR `about` LIKE '%s' OR `keywords` LIKE '%s') $extra_sql
WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND GROUP BY `nurl`
((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND ORDER BY `updated` DESC LIMIT %d, %d",
(`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),
dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), 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)),
dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)), dbesc(escape_tags($search2)),
@ -148,14 +139,21 @@ function dirfind_content(App $a, $prefix = "") {
$j->items_page = $perpage; $j->items_page = $perpage;
$j->page = $a->pager['page']; $j->page = $a->pager['page'];
foreach ($results AS $result) { foreach ($results AS $result) {
if (PortableContact::alternateOStatusUrl($result["url"])) { if (PortableContact::alternateOStatusUrl($result["nurl"])) {
continue; 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"] == "") { if ($result["name"] == "") {
$urlparts = parse_url($result["url"]);
$result["name"] = end(explode("/", $urlparts["path"])); $result["name"] = end(explode("/", $urlparts["path"]));
} }
@ -204,11 +202,10 @@ function dirfind_content(App $a, $prefix = "") {
if ($jj->cid > 0) { if ($jj->cid > 0) {
$connlnk = ""; $connlnk = "";
$conntxt = ""; $conntxt = "";
$contact = q("SELECT * FROM `contact` WHERE `id` = %d", $contact = dba::selectFirst('contact', [], ['id' => $jj->cid]);
intval($jj->cid)); if (DBM::is_result($contact)) {
if ($contact) { $photo_menu = Contact::photoMenu($contact);
$photo_menu = Contact::photoMenu($contact[0]); $details = _contact_detail_for_template($contact);
$details = _contact_detail_for_template($contact[0]);
$alt_text = $details['alt_text']; $alt_text = $details['alt_text'];
} else { } else {
$photo_menu = []; $photo_menu = [];

View file

@ -514,7 +514,7 @@ class Contact extends BaseObject
} }
$sparkle = false; $sparkle = false;
if ($contact['network'] === NETWORK_DFRN) { if (($contact['network'] === NETWORK_DFRN) && !$contact['self']) {
$sparkle = true; $sparkle = true;
$profile_link = System::baseUrl() . '/redir/' . $contact['id']; $profile_link = System::baseUrl() . '/redir/' . $contact['id'];
} else { } else {
@ -531,18 +531,21 @@ class Contact extends BaseObject
$profile_link = $profile_link . '?url=profile'; $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']; $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']; $poke_link = System::baseUrl() . '/poke/?f=&c=' . $contact['id'];
} }
$contact_url = System::baseUrl() . '/contacts/' . $contact['id']; $contact_url = System::baseUrl() . '/contacts/' . $contact['id'];
$posts_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/posts'; $posts_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/posts';
if (!$contact['self']) {
$contact_drop_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/drop?confirm=1'; $contact_drop_link = System::baseUrl() . '/contacts/' . $contact['id'] . '/drop?confirm=1';
}
/** /**
* Menu array: * Menu array:

View file

@ -37,7 +37,10 @@ class GContact
*/ */
public static function searchByName($search, $mode = '') public static function searchByName($search, $mode = '')
{ {
if ($search) { if (empty($search)) {
return [];
}
// check supported networks // check supported networks
if (Config::get('system', 'diaspora_enabled')) { if (Config::get('system', 'diaspora_enabled')) {
$diaspora = NETWORK_DIASPORA; $diaspora = NETWORK_DIASPORA;
@ -60,33 +63,27 @@ class GContact
$search .= "%"; $search .= "%";
$results = q( $results = dba::p("SELECT `nurl` FROM `gcontact`
"SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`nick`, `gcontact`.`photo`, WHERE NOT `hide` AND `network` IN (?, ?, ?) AND
`gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`, `gcontact`.`community` ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
FROM `gcontact` (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000",
AND `contact`.`uid` = %d AND NOT `contact`.`blocked` NETWORK_DFRN, $ostatus, $diaspora, $search, $search, $search
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; $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;
} }
$gcontacts[] = Contact::getDetailsByURL($result["nurl"], local_user());
}
return $gcontacts;
} }
/** /**