X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fcontacts.php;h=1604f0b6605ec43d6f0e936972ad2394a45c11f2;hb=e28799181927582b8c8784476c4a36e1d8e49b5a;hp=52363d742c78a7392f434be494c4ff223ae953d3;hpb=413424064c30c3b799f03ed728ab0a3f8f5eb424;p=friendica.git diff --git a/mod/contacts.php b/mod/contacts.php index 52363d742c..1604f0b660 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -10,6 +10,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Content\Widget; use Friendica\Core\Addon; use Friendica\Core\L10n; +use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; @@ -19,8 +20,8 @@ use Friendica\Model\Group; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; - -require_once 'mod/proxy.php'; +use Friendica\Util\Proxy as ProxyUtils; +use Friendica\Core\ACL; function contacts_init(App $a) { @@ -39,14 +40,23 @@ function contacts_init(App $a) $contact_id = null; $contact = null; - if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) { + if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations']))) { $contact_id = intval($a->argv[1]); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]); + + if (!DBA::isResult($contact)) { + $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0]); + } + + // Don't display contacts that are about to be deleted + if ($contact['network'] == Protocol::PHANTOM) { + $contact = false; + } } if (DBA::isResult($contact)) { if ($contact['self']) { - if (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts")) { + if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) { goaway('profile/' . $contact['nick']); } else { goaway('profile/' . $contact['nick'] . '?tab=profile'); @@ -55,7 +65,7 @@ function contacts_init(App $a) $a->data['contact'] = $contact; - if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) { + if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != Protocol::DFRN)) { $networkname = format_network_name($a->data['contact']['network'], $a->data['contact']['url']); } else { $networkname = ''; @@ -87,7 +97,11 @@ function contacts_init(App $a) $findpeople_widget = Widget::findPeople(); } - $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 'everyone', $contact_id); + if ($contact['uid'] != 0) { + $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 'everyone', $contact_id); + } else { + $groups_widget = null; + } $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"), [ '$vcard_widget' => $vcard_widget, @@ -113,11 +127,12 @@ function contacts_init(App $a) function contacts_batch_actions(App $a) { - $contacts_id = $_POST['contact_batch']; - if (!is_array($contacts_id)) { + if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) { return; } + $contacts_id = $_POST['contact_batch']; + $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0", implode(",", $contacts_id), intval(local_user()) @@ -131,16 +146,12 @@ function contacts_batch_actions(App $a) $count_actions++; } if (x($_POST, 'contacts_batch_block')) { - $r = _contact_block($contact_id, $orig_record); - if ($r) { - $count_actions++; - } + _contact_block($contact_id); + $count_actions++; } if (x($_POST, 'contacts_batch_ignore')) { - $r = _contact_ignore($contact_id, $orig_record); - if ($r) { - $count_actions++; - } + _contact_ignore($contact_id); + $count_actions++; } if (x($_POST, 'contacts_batch_archive')) { $r = _contact_archive($contact_id, $orig_record); @@ -188,7 +199,7 @@ function contacts_post(App $a) Addon::callHooks('contact_edit_post', $_POST); - $profile_id = intval($_POST['profile-assign']); + $profile_id = intval(defaults($_POST, 'profile-assign', 0)); if ($profile_id) { if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) { notice(L10n::t('Could not locate selected profile.') . EOL); @@ -200,11 +211,11 @@ function contacts_post(App $a) $notify = intval($_POST['notify']); - $fetch_further_information = intval($_POST['fetch_further_information']); + $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0)); - $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist'])); + $ffi_keyword_blacklist = escape_tags(trim(defaults($_POST, 'ffi_keyword_blacklist', ''))); - $priority = intval($_POST['poll']); + $priority = intval(defaults($_POST, 'poll', 0)); if ($priority > 5 || $priority < 0) { $priority = 0; } @@ -249,7 +260,7 @@ function _contact_update($contact_id) $uid = $contact["uid"]; - if ($contact["network"] == NETWORK_OSTATUS) { + if ($contact["network"] == Protocol::OSTATUS) { $result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]); if ($result['success']) { @@ -273,7 +284,7 @@ function _contact_update_profile($contact_id) $data = Probe::uri($contact["url"], "", 0, false); // "Feed" or "Unknown" is mostly a sign of communication problems - if ((in_array($data["network"], [NETWORK_FEED, NETWORK_PHANTOM])) && ($data["network"] != $contact["network"])) { + if ((in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM])) && ($data["network"] != $contact["network"])) { return; } @@ -281,7 +292,7 @@ function _contact_update_profile($contact_id) "poco", "network", "alias"]; $update = []; - if ($data["network"] == NETWORK_OSTATUS) { + if ($data["network"] == Protocol::OSTATUS) { $result = Contact::createFromProbe($uid, $data["url"], false); if ($result['success']) { @@ -327,26 +338,16 @@ function _contact_update_profile($contact_id) GContact::updateFromProbe($data["url"]); } -function _contact_block($contact_id, $orig_record) +function _contact_block($contact_id) { - $blocked = (($orig_record['blocked']) ? 0 : 1); - $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d", - intval($blocked), - intval($contact_id), - intval(local_user()) - ); - return DBA::isResult($r); + $blocked = !Contact::isBlockedByUser($contact_id, local_user()); + Contact::setBlockedForUser($contact_id, local_user(), $blocked); } -function _contact_ignore($contact_id, $orig_record) +function _contact_ignore($contact_id) { - $readonly = (($orig_record['readonly']) ? 0 : 1); - $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d", - intval($readonly), - intval($contact_id), - intval(local_user()) - ); - return DBA::isResult($r); + $ignored = !Contact::isIgnoredByUser($contact_id, local_user()); + Contact::setIgnoredForUser($contact_id, local_user(), $ignored); } function _contact_archive($contact_id, $orig_record) @@ -372,11 +373,11 @@ function _contact_drop($orig_record) return; } - Contact::terminateFriendship($r[0], $orig_record); + Contact::terminateFriendship($r[0], $orig_record, true); Contact::remove($orig_record['id']); } -function contacts_content(App $a) +function contacts_content(App $a, $update = 0) { $sort_type = 0; $o = ''; @@ -395,48 +396,46 @@ function contacts_content(App $a) $cmd = $a->argv[2]; - $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]); + $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false]); if (!DBA::isResult($orig_record)) { notice(L10n::t('Could not access contact record.') . EOL); goaway('contacts'); return; // NOTREACHED } - if ($cmd === 'update') { + if ($cmd === 'update' && ($orig_record['uid'] != 0)) { _contact_update($contact_id); goaway('contacts/' . $contact_id); // NOTREACHED } - if ($cmd === 'updateprofile') { + if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) { _contact_update_profile($contact_id); goaway('crepair/' . $contact_id); // NOTREACHED } if ($cmd === 'block') { - $r = _contact_block($contact_id, $orig_record); - if ($r) { - $blocked = (($orig_record['blocked']) ? 0 : 1); - info((($blocked) ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL); - } + _contact_block($contact_id); + + $blocked = Contact::isBlockedByUser($contact_id, local_user()); + info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL); goaway('contacts/' . $contact_id); return; // NOTREACHED } if ($cmd === 'ignore') { - $r = _contact_ignore($contact_id, $orig_record); - if ($r) { - $readonly = (($orig_record['readonly']) ? 0 : 1); - info((($readonly) ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL); - } + _contact_ignore($contact_id); + + $ignored = Contact::isIgnoredByUser($contact_id, local_user()); + info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL); goaway('contacts/' . $contact_id); return; // NOTREACHED } - if ($cmd === 'archive') { + if ($cmd === 'archive' && ($orig_record['uid'] != 0)) { $r = _contact_archive($contact_id, $orig_record); if ($r) { $archived = (($orig_record['archive']) ? 0 : 1); @@ -447,7 +446,7 @@ function contacts_content(App $a) return; // NOTREACHED } - if ($cmd === 'drop') { + if ($cmd === 'drop' && ($orig_record['uid'] != 0)) { // Check if we should do HTML-based delete confirmation if (x($_REQUEST, 'confirm')) { //