X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fcontacts.php;h=c33e9b620607ded477f2c6418bf8e827b6548494;hb=f8b74033a4f990e421814ea5bf8b443104e61feb;hp=3f7eb342b1c5e5139ddaa492eb13a4025308df25;hpb=85c8bf022841fb53a42e012d2e90dd23f56df2ab;p=friendica.git diff --git a/mod/contacts.php b/mod/contacts.php index 3f7eb342b1..c33e9b6206 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -6,20 +6,22 @@ use Friendica\App; use Friendica\Content\ContactSelector; use Friendica\Content\Nav; +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\DBM; +use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\GContact; 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) { @@ -38,15 +40,32 @@ 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()]); + $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 (DBM::is_result($contact)) { + if (DBA::isResult($contact)) { + if ($contact['self']) { + 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'); + } + } + $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 = ''; @@ -56,7 +75,7 @@ function contacts_init(App $a) $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"), [ '$name' => htmlentities($a->data['contact']['name']), '$photo' => $a->data['contact']['photo'], - '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/" . $a->data['contact']['id'] : $a->data['contact']['url'], + '$url' => Contact::MagicLink($a->data['contact']['url']), '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""), '$network_name' => $networkname, '$network' => L10n::t('Network:'), @@ -78,7 +97,11 @@ function contacts_init(App $a) $findpeople_widget = Widget::findPeople(); } - $groups_widget = Group::sidebarWidget('contacts', 'group', 'full', 0, $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, @@ -94,21 +117,16 @@ function contacts_init(App $a) '$baseurl' => System::baseUrl(true), '$base' => $base ]); - - $tpl = get_markup_template("contacts-end.tpl"); - $a->page['end'] .= replace_macros($tpl, [ - '$baseurl' => System::baseUrl(true), - '$base' => $base - ]); } 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()) @@ -122,16 +140,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); @@ -148,11 +162,7 @@ function contacts_batch_actions(App $a) info(L10n::tt("%d contact edited.", "%d contacts edited.", $count_actions)); } - if (x($_SESSION, 'return_url')) { - goaway('' . $_SESSION['return_url']); - } else { - goaway('contacts'); - } + goaway('contacts'); } function contacts_post(App $a) @@ -171,7 +181,7 @@ function contacts_post(App $a) return; } - if (!dba::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) { + if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) { notice(L10n::t('Could not access contact record.') . EOL); goaway('contacts'); return; // NOTREACHED @@ -179,9 +189,9 @@ 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()])) { + if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) { notice(L10n::t('Could not locate selected profile.') . EOL); return; } @@ -191,11 +201,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; } @@ -207,22 +217,22 @@ function contacts_post(App $a) `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d", intval($profile_id), intval($priority), - dbesc($info), + DBA::escape($info), intval($hidden), intval($notify), intval($fetch_further_information), - dbesc($ffi_keyword_blacklist), + DBA::escape($ffi_keyword_blacklist), intval($contact_id), intval(local_user()) ); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { info(L10n::t('Contact updated.') . EOL); } else { notice(L10n::t('Failed to update contact record.') . EOL); } - $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]); - if (DBM::is_result($contact)) { + $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]); + if (DBA::isResult($contact)) { $a->data['contact'] = $contact; } @@ -233,14 +243,14 @@ function contacts_post(App $a) function _contact_update($contact_id) { - $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]); - if (!DBM::is_result($contact)) { + $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]); + if (!DBA::isResult($contact)) { return; } $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']) { @@ -254,8 +264,8 @@ function _contact_update($contact_id) function _contact_update_profile($contact_id) { - $contact = dba::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]); - if (!DBM::is_result($contact)) { + $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user()]); + if (!DBA::isResult($contact)) { return; } @@ -264,7 +274,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; } @@ -272,7 +282,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']) { @@ -299,7 +309,7 @@ function _contact_update_profile($contact_id) $query .= ", "; } - $query .= "`" . $key . "` = '" . dbesc($value) . "'"; + $query .= "`" . $key . "` = '" . DBA::escape($value) . "'"; } if ($query == "") { @@ -318,26 +328,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 DBM::is_result($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 DBM::is_result($r); + $ignored = !Contact::isIgnoredByUser($contact_id, local_user()); + Contact::setIgnoredForUser($contact_id, local_user(), $ignored); } function _contact_archive($contact_id, $orig_record) @@ -348,7 +348,7 @@ function _contact_archive($contact_id, $orig_record) intval($contact_id), intval(local_user()) ); - return DBM::is_result($r); + return DBA::isResult($r); } function _contact_drop($orig_record) @@ -359,15 +359,15 @@ function _contact_drop($orig_record) WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", intval($a->user['uid']) ); - if (!DBM::is_result($r)) { + if (!DBA::isResult($r)) { 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 = ''; @@ -386,48 +386,46 @@ function contacts_content(App $a) $cmd = $a->argv[2]; - $orig_record = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'self' => false]); - if (!DBM::is_result($orig_record)) { + $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); @@ -438,7 +436,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')) { //