X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FContact.php;h=020e3906a0297edf7e741bdc9cc20a666babe285;hb=8632c903276c44d575076ac3167e3bc7ea64bd31;hp=847455f498927f0d6444c5a88dcbc858cd780c18;hpb=6ceb74c3654a31f3c5bd51404121665e4bc36810;p=friendica.git diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 847455f498..020e3906a0 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -11,28 +11,25 @@ use Friendica\Content\Text\BBCode; use Friendica\Content\Widget; use Friendica\Core\ACL; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Protocol; use Friendica\Core\Renderer; -use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; +use Friendica\Module\Security\Login; use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\NotFoundException; -use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Strings; /** * Manages and show Contacts and their content - * - * @brief manages contacts */ class Contact extends BaseModule { - private static function batchActions(App $a) + private static function batchActions() { if (empty($_POST['contact_batch']) || !is_array($_POST['contact_batch'])) { return; @@ -69,15 +66,15 @@ class Contact extends BaseModule } } if ($count_actions > 0) { - info(L10n::tt('%d contact edited.', '%d contacts edited.', $count_actions)); + info(DI::l10n()->tt('%d contact edited.', '%d contacts edited.', $count_actions)); } - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } - public static function post() + public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { return; @@ -85,7 +82,7 @@ class Contact extends BaseModule // @TODO: Replace with parameter from router if ($a->argv[1] === 'batch') { - self::batchActions($a); + self::batchActions(); return; } @@ -96,38 +93,29 @@ class Contact extends BaseModule } if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) { - notice(L10n::t('Could not access contact record.') . EOL); - $a->internalRedirect('contact'); + notice(DI::l10n()->t('Could not access contact record.') . EOL); + DI::baseUrl()->redirect('contact'); return; // NOTREACHED } Hook::callAll('contact_edit_post', $_POST); - $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); - return; - } - } - $hidden = !empty($_POST['hidden']); $notify = !empty($_POST['notify']); - $fetch_further_information = intval(defaults($_POST, 'fetch_further_information', 0)); + $fetch_further_information = intval($_POST['fetch_further_information'] ?? 0); - $ffi_keyword_blacklist = Strings::escapeHtml(trim(defaults($_POST, 'ffi_keyword_blacklist', ''))); + $ffi_keyword_blacklist = Strings::escapeHtml(trim($_POST['ffi_keyword_blacklist'] ?? '')); - $priority = intval(defaults($_POST, 'poll', 0)); + $priority = intval($_POST['poll'] ?? 0); if ($priority > 5 || $priority < 0) { $priority = 0; } - $info = Strings::escapeHtml(trim(defaults($_POST, 'info', ''))); + $info = Strings::escapeHtml(trim($_POST['info'] ?? '')); $r = DBA::update('contact', [ - 'profile-id' => $profile_id, 'priority' => $priority, 'info' => $info, 'hidden' => $hidden, @@ -138,9 +126,9 @@ class Contact extends BaseModule ); if (DBA::isResult($r)) { - info(L10n::t('Contact updated.') . EOL); + info(DI::l10n()->t('Contact updated.') . EOL); } else { - notice(L10n::t('Failed to update contact record.') . EOL); + notice(DI::l10n()->t('Failed to update contact record.') . EOL); } $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]); @@ -176,71 +164,54 @@ class Contact extends BaseModule private static function updateContactFromProbe($contact_id) { - $contact = DBA::selectFirst('contact', ['uid', 'url', 'network'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]); + $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]); if (!DBA::isResult($contact)) { return; } - $uid = $contact['uid']; - - $data = Probe::uri($contact['url'], '', 0, false); - - // 'Feed' or 'Unknown' is mostly a sign of communication problems - if ((in_array($data['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($data['network'] != $contact['network'])) { - return; - } - - $updatefields = ['name', 'nick', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'network', 'alias']; - $fields = []; - - if ($data['network'] == Protocol::OSTATUS) { - $result = Model\Contact::createFromProbe($uid, $data['url'], false); - - if ($result['success']) { - $fields['subhub'] = true; - } - } - - foreach ($updatefields AS $field) { - if (!empty($data[$field])) { - $fields[$field] = $data[$field]; - } - } - - $fields['nurl'] = Strings::normaliseLink($data['url']); - - if (!empty($data['priority'])) { - $fields['priority'] = intval($data['priority']); - } - - if (empty($fields)) { - return; - } - - DBA::update('contact', $fields, ['id' => $contact_id, 'uid' => local_user()]); - // Update the entry in the contact table - Model\Contact::updateAvatar($data['photo'], local_user(), $contact_id, true); + Model\Contact::updateFromProbe($contact_id, '', true); // Update the entry in the gcontact table - Model\GContact::updateFromProbe($data['url']); + Model\GContact::updateFromProbe($contact['url']); } + /** + * Toggles the blocked status of a contact identified by id. + * + * @param $contact_id + * @throws \Exception + */ private static function blockContact($contact_id) { $blocked = !Model\Contact::isBlockedByUser($contact_id, local_user()); Model\Contact::setBlockedForUser($contact_id, local_user(), $blocked); } + /** + * Toggles the ignored status of a contact identified by id. + * + * @param $contact_id + * @throws \Exception + */ private static function ignoreContact($contact_id) { $ignored = !Model\Contact::isIgnoredByUser($contact_id, local_user()); Model\Contact::setIgnoredForUser($contact_id, local_user(), $ignored); } + /** + * Toggles the archived status of a contact identified by id. + * If the current status isn't provided, this will always archive the contact. + * + * @param $contact_id + * @param $orig_record + * @return bool + * @throws \Exception + */ private static function archiveContact($contact_id, $orig_record) { - $archived = (defaults($orig_record, 'archive', '') ? 0 : 1); + $archived = empty($orig_record['archive']); $r = DBA::update('contact', ['archive' => $archived], ['id' => $contact_id, 'uid' => local_user()]); return DBA::isResult($r); @@ -257,19 +228,21 @@ class Contact extends BaseModule Model\Contact::remove($orig_record['id']); } - public static function content($update = 0) + public static function content(array $parameters = [], $update = 0) { if (!local_user()) { return Login::form($_SERVER['REQUEST_URI']); } - $a = self::getApp(); + $a = DI::app(); - $nets = defaults($_GET, 'nets', ''); - $rel = defaults($_GET, 'rel' , ''); + $search = Strings::escapeTags(trim($_GET['search'] ?? '')); + $nets = Strings::escapeTags(trim($_GET['nets'] ?? '')); + $rel = Strings::escapeTags(trim($_GET['rel'] ?? '')); + $group = Strings::escapeTags(trim($_GET['group'] ?? '')); - if (empty($a->page['aside'])) { - $a->page['aside'] = ''; + if (empty(DI::page()['aside'])) { + DI::page()['aside'] = ''; } $contact_id = null; @@ -295,9 +268,9 @@ class Contact extends BaseModule if ($contact['self']) { // @TODO: Replace with parameter from router if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) { - $a->internalRedirect('profile/' . $contact['nick']); + DI::baseUrl()->redirect('profile/' . $contact['nick']); } else { - $a->internalRedirect('profile/' . $contact['nick'] . '?tab=profile'); + DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile'); } } @@ -309,20 +282,47 @@ class Contact extends BaseModule $network_link = ''; } + $follow_link = ''; + $unfollow_link = ''; + if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { + if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::SHARING, Model\Contact::FRIEND])) { + $unfollow_link = 'unfollow?url=' . urlencode($contact['url']); + } elseif(!$contact['pending']) { + $follow_link = 'follow?url=' . urlencode($contact['url']); + } + } + + $wallmessage_link = ''; + if ($contact['uid'] && Model\Contact::canReceivePrivateMessages($contact)) { + $wallmessage_link = 'message/new/' . $contact['id']; + } + $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [ '$name' => $contact['name'], '$photo' => $contact['photo'], '$url' => Model\Contact::magicLinkByContact($contact, $contact['url']), - '$addr' => defaults($contact, 'addr', ''), + '$addr' => $contact['addr'] ?? '', '$network_link' => $network_link, - '$network' => L10n::t('Network:'), - '$account_type' => Model\Contact::getAccountType($contact) + '$network' => DI::l10n()->t('Network:'), + '$account_type' => Model\Contact::getAccountType($contact), + '$follow' => DI::l10n()->t('Follow'), + '$follow_link' => $follow_link, + '$unfollow' => DI::l10n()->t('Unfollow'), + '$unfollow_link' => $unfollow_link, + '$wallmessage' => DI::l10n()->t('Message'), + '$wallmessage_link' => $wallmessage_link, ]); $findpeople_widget = ''; $follow_widget = ''; $networks_widget = ''; $rel_widget = ''; + + if ($contact['uid'] != 0) { + $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id); + } else { + $groups_widget = ''; + } } else { $vcard_widget = ''; $findpeople_widget = Widget::findPeople(); @@ -334,27 +334,21 @@ class Contact extends BaseModule $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets); $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel); + $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group); } - if ($contact['uid'] != 0) { - $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id); - } else { - $groups_widget = null; - } - - $a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget; + DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget; $tpl = Renderer::getMarkupTemplate('contacts-head.tpl'); - $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [ - '$baseurl' => $a->getBaseURL(true), + DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [ + '$baseurl' => DI::baseUrl()->get(true), ]); - $sort_type = 0; $o = ''; Nav::setSelected('contact'); if (!local_user()) { - notice(L10n::t('Permission denied.') . EOL); + notice(DI::l10n()->t('Permission denied.') . EOL); return Login::form(); } @@ -369,18 +363,18 @@ class Contact extends BaseModule $orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]); if (!DBA::isResult($orig_record)) { - throw new NotFoundException(L10n::t('Contact not found')); + throw new NotFoundException(DI::l10n()->t('Contact not found')); } if ($cmd === 'update' && ($orig_record['uid'] != 0)) { self::updateContactFromPoll($contact_id); - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) { self::updateContactFromProbe($contact_id); - $a->internalRedirect('crepair/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id . '/advanced/'); // NOTREACHED } @@ -388,9 +382,9 @@ class Contact extends BaseModule self::blockContact($contact_id); $blocked = Model\Contact::isBlockedByUser($contact_id, local_user()); - info(($blocked ? L10n::t('Contact has been blocked') : L10n::t('Contact has been unblocked')) . EOL); + info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')) . EOL); - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } @@ -398,9 +392,9 @@ class Contact extends BaseModule self::ignoreContact($contact_id); $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user()); - info(($ignored ? L10n::t('Contact has been ignored') : L10n::t('Contact has been unignored')) . EOL); + info(($ignored ? DI::l10n()->t('Contact has been ignored') : DI::l10n()->t('Contact has been unignored')) . EOL); - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } @@ -408,10 +402,10 @@ class Contact extends BaseModule $r = self::archiveContact($contact_id, $orig_record); if ($r) { $archived = (($orig_record['archive']) ? 0 : 1); - info((($archived) ? L10n::t('Contact has been archived') : L10n::t('Contact has been unarchived')) . EOL); + info((($archived) ? DI::l10n()->t('Contact has been archived') : DI::l10n()->t('Contact has been unarchived')) . EOL); } - $a->internalRedirect('contact/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id); // NOTREACHED } @@ -420,7 +414,7 @@ class Contact extends BaseModule if (!empty($_REQUEST['confirm'])) { //