X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FContact.php;h=020e3906a0297edf7e741bdc9cc20a666babe285;hb=8632c903276c44d575076ac3167e3bc7ea64bd31;hp=183a1bd16dffccf5a46bae4de0922d0d895ec9b3;hpb=5dfee31108fc92a7abca5f99b8fdf1b34aec5dd5;p=friendica.git diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 183a1bd16d..020e3906a0 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -11,7 +11,6 @@ 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\Worker; @@ -67,7 +66,7 @@ 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)); } DI::baseUrl()->redirect('contact'); @@ -101,14 +100,6 @@ class Contact extends BaseModule Hook::callAll('contact_edit_post', $_POST); - $profile_id = intval($_POST['profile-assign'] ?? 0); - if ($profile_id) { - if (!DBA::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) { - notice(DI::l10n()->t('Could not locate selected profile.') . EOL); - return; - } - } - $hidden = !empty($_POST['hidden']); $notify = !empty($_POST['notify']); @@ -125,7 +116,6 @@ class Contact extends BaseModule $info = Strings::escapeHtml(trim($_POST['info'] ?? '')); $r = DBA::update('contact', [ - 'profile-id' => $profile_id, 'priority' => $priority, 'info' => $info, 'hidden' => $hidden, @@ -246,8 +236,10 @@ class Contact extends BaseModule $a = DI::app(); - $nets = $_GET['nets'] ?? ''; - $rel = $_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(DI::page()['aside'])) { DI::page()['aside'] = ''; @@ -278,7 +270,7 @@ class Contact extends BaseModule if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) { DI::baseUrl()->redirect('profile/' . $contact['nick']); } else { - DI::baseUrl()->redirect('profile/' . $contact['nick'] . '?tab=profile'); + DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile'); } } @@ -325,6 +317,12 @@ class Contact extends BaseModule $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(); @@ -336,12 +334,7 @@ class Contact extends BaseModule $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets); $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel); - } - - if ($contact['uid'] != 0) { - $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id); - } else { - $groups_widget = null; + $groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group); } DI::page()['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget; @@ -351,7 +344,6 @@ class Contact extends BaseModule '$baseurl' => DI::baseUrl()->get(true), ]); - $sort_type = 0; $o = ''; Nav::setSelected('contact'); @@ -382,7 +374,7 @@ class Contact extends BaseModule if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) { self::updateContactFromProbe($contact_id); - DI::baseUrl()->redirect('crepair/' . $contact_id); + DI::baseUrl()->redirect('contact/' . $contact_id . '/advanced/'); // NOTREACHED } @@ -554,20 +546,13 @@ class Contact extends BaseModule $poll_interval = ContactSelector::pollInterval($contact['priority'], !$poll_enabled); } - $profile_select = null; - if ($contact['network'] == Protocol::DFRN) { - $profile_select = ContactSelector::profileAssign($contact['profile-id'], $contact['network'] !== Protocol::DFRN); - } - // Load contactact related actions like hide, suggest, delete and others $contact_actions = self::getContactActions($contact); if ($contact['uid'] != 0) { - $lbl_vis1 = DI::l10n()->t('Profile Visibility'); $lbl_info1 = DI::l10n()->t('Contact Information / Notes'); $contact_settings_label = DI::l10n()->t('Contact Settings'); } else { - $lbl_vis1 = null; $lbl_info1 = null; $contact_settings_label = null; } @@ -577,8 +562,6 @@ class Contact extends BaseModule '$header' => DI::l10n()->t('Contact'), '$tab_str' => $tab_str, '$submit' => DI::l10n()->t('Submit'), - '$lbl_vis1' => $lbl_vis1, - '$lbl_vis2' => DI::l10n()->t('Please choose the profile you would like to display to %s when viewing your profile securely.', $contact['name']), '$lbl_info1' => $lbl_info1, '$lbl_info2' => DI::l10n()->t('Their personal note'), '$reason' => trim(Strings::escapeTags($contact['reason'])), @@ -599,7 +582,6 @@ class Contact extends BaseModule '$updpub' => DI::l10n()->t('Update public posts'), '$last_update' => $last_update, '$udnow' => DI::l10n()->t('Update now'), - '$profile_select' => $profile_select, '$contact_id' => $contact['id'], '$block_text' => ($contact['blocked'] ? DI::l10n()->t('Unblock') : DI::l10n()->t('Block')), '$ignore_text' => ($contact['readonly'] ? DI::l10n()->t('Unignore') : DI::l10n()->t('Ignore')), @@ -644,39 +626,116 @@ class Contact extends BaseModule return $arr['output']; } - $select_uid = local_user(); + $sql_values = [local_user()]; // @TODO: Replace with parameter from router $type = $a->argv[1] ?? ''; switch ($type) { case 'blocked': - $sql_extra = sprintf(" AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = %d and `user-contact`.`blocked`)", intval(local_user())); - $select_uid = 0; + $sql_extra = " AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = ? and `user-contact`.`blocked`)"; + // This makes the query look for contact.uid = 0 + array_unshift($sql_values, 0); break; case 'hidden': $sql_extra = " AND `hidden` AND NOT `blocked` AND NOT `pending`"; break; case 'ignored': - $sql_extra = sprintf(" AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = %d and `user-contact`.`ignored`)", intval(local_user())); - $select_uid = 0; + $sql_extra = " AND EXISTS(SELECT `id` from `user-contact` WHERE `contact`.`id` = `user-contact`.`cid` and `user-contact`.`uid` = ? and `user-contact`.`ignored`)"; + // This makes the query look for contact.uid = 0 + array_unshift($sql_values, 0); break; case 'archived': $sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`"; break; case 'pending': - $sql_extra = sprintf(" AND `pending` AND NOT `archive` AND ((`rel` = %d) - OR EXISTS (SELECT `id` FROM `intro` WHERE `contact-id` = `contact`.`id` AND NOT `ignore`))", Model\Contact::SHARING); + $sql_extra = " AND `pending` AND NOT `archive` AND ((`rel` = ?) + OR EXISTS (SELECT `id` FROM `intro` WHERE `contact-id` = `contact`.`id` AND NOT `ignore`))"; + $sql_values[] = Model\Contact::SHARING; break; default: $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`"; + break; + } + + $searching = false; + $search_hdr = null; + if ($search) { + $searching = true; + $search_hdr = $search; + $search_txt = preg_quote($search); + $sql_extra .= " AND (name REGEXP ? OR url REGEXP ? OR nick REGEXP ?)"; + $sql_values[] = $search_txt; + $sql_values[] = $search_txt; + $sql_values[] = $search_txt; } - $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM); + if ($nets) { + $sql_extra .= " AND network = ? "; + $sql_values[] = $nets; + } - $search = Strings::escapeTags(trim($_GET['search'] ?? '')); - $nets = Strings::escapeTags(trim($_GET['nets'] ?? '')); - $rel = Strings::escapeTags(trim($_GET['rel'] ?? '')); + switch ($rel) { + case 'followers': + $sql_extra .= " AND `rel` IN (?, ?)"; + $sql_values[] = Model\Contact::FOLLOWER; + $sql_values[] = Model\Contact::FRIEND; + break; + case 'following': + $sql_extra .= " AND `rel` IN (?, ?)"; + $sql_values[] = Model\Contact::SHARING; + $sql_values[] = Model\Contact::FRIEND; + break; + case 'mutuals': + $sql_extra .= " AND `rel` = ?"; + $sql_values[] = Model\Contact::FRIEND; + break; + } + + if ($group) { + $sql_extra = " AND EXISTS(SELECT `id` FROM `group_member` WHERE `gid` = ? AND `contact`.`id` = `contact-id`)"; + $sql_values[] = $group; + } + + $sql_extra .= Widget::unavailableNetworks(); + + $total = 0; + $stmt = DBA::p("SELECT COUNT(*) AS `total` + FROM `contact` + WHERE `uid` = ? + AND `self` = 0 + AND NOT `deleted` + $sql_extra", + $sql_values + ); + if (DBA::isResult($stmt)) { + $total = DBA::fetch($stmt)['total']; + } + DBA::close($stmt); + + $pager = new Pager(DI::args()->getQueryString()); + + $sql_values[] = $pager->getStart(); + $sql_values[] = $pager->getItemsPerPage(); + + $contacts = []; + + $stmt = DBA::p("SELECT * + FROM `contact` + WHERE `uid` = ? + AND `self` = 0 + AND NOT `deleted` + $sql_extra + ORDER BY `name` ASC + LIMIT ?, ?", + $sql_values + ); + while ($contact = DBA::fetch($stmt)) { + $contact['blocked'] = Model\Contact::isBlockedByUser($contact['id'], local_user()); + $contact['readonly'] = Model\Contact::isIgnoredByUser($contact['id'], local_user()); + $contacts[] = self::getContactTemplateVars($contact); + } + DBA::close($stmt); $tabs = [ [ @@ -737,58 +796,8 @@ class Contact extends BaseModule ], ]; - $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl'); - $t = Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]); - - $total = 0; - $searching = false; - $search_hdr = null; - if ($search) { - $searching = true; - $search_hdr = $search; - $search_txt = DBA::escape(Strings::protectSprintf(preg_quote($search))); - $sql_extra .= " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') "; - } - - if ($nets) { - $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets)); - } - - switch ($rel) { - case 'followers': $sql_extra .= " AND `rel` IN (1, 3)"; break; - case 'following': $sql_extra .= " AND `rel` IN (2, 3)"; break; - case 'mutuals': $sql_extra .= " AND `rel` = 3"; break; - } - - $sql_extra .= " AND NOT `deleted` "; - - $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : ''); - - $sql_extra3 = Widget::unavailableNetworks(); - - $r = q("SELECT COUNT(*) AS `total` FROM `contact` - WHERE `uid` = %d AND `self` = 0 $sql_extra $sql_extra2 $sql_extra3", - intval($select_uid) - ); - if (DBA::isResult($r)) { - $total = $r[0]['total']; - } - $pager = new Pager(DI::args()->getQueryString()); - - $contacts = []; - - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT %d , %d ", - intval($select_uid), - $pager->getStart(), - $pager->getItemsPerPage() - ); - if (DBA::isResult($r)) { - foreach ($r as $rr) { - $rr['blocked'] = Model\Contact::isBlockedByUser($rr['id'], local_user()); - $rr['readonly'] = Model\Contact::isIgnoredByUser($rr['id'], local_user()); - $contacts[] = self::getContactTemplateVars($rr); - } - } + $tabs_tpl = Renderer::getMarkupTemplate('common_tabs.tpl'); + $tabs_html = Renderer::replaceMacros($tabs_tpl, ['$tabs' => $tabs]); switch ($rel) { case 'followers': $header = DI::l10n()->t('Followers'); break; @@ -810,7 +819,7 @@ class Contact extends BaseModule $tpl = Renderer::getMarkupTemplate('contacts-template.tpl'); $o .= Renderer::replaceMacros($tpl, [ '$header' => $header, - '$tabs' => $t, + '$tabs' => $tabs_html, '$total' => $total, '$search' => $search_hdr, '$desc' => DI::l10n()->t('Search your contacts'), @@ -901,7 +910,7 @@ class Contact extends BaseModule if (!empty($contact['uid'])) { $tabs[] = ['label' => DI::l10n()->t('Advanced'), - 'url' => 'crepair/' . $contact['id'], + 'url' => 'contact/' . $contact['id'] . '/advanced/', 'sel' => (($active_tab == 6) ? 'active' : ''), 'title' => DI::l10n()->t('Advanced Contact Settings'), 'id' => 'advanced-tab', @@ -948,7 +957,7 @@ class Contact extends BaseModule $profiledata = Model\Contact::getDetailsByURL($contact['url']); - Model\Profile::load($a, '', 0, $profiledata, true); + Model\Profile::load($a, '', $profiledata, true); $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update); } @@ -970,7 +979,7 @@ class Contact extends BaseModule $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']); } - Model\Profile::load($a, '', 0, $profiledata, true); + Model\Profile::load($a, '', $profiledata, true); $o .= Model\Contact::getPostsFromUrl($contact['url']); }