]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact.php
Ensure that cached avatar fields are set
[friendica.git] / src / Module / Contact.php
index 563adef74a836dbc53470c06b44bd9bdef773195..e9f00a1b653d6086e0a46b471324ac72a4f795b8 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module;
 
@@ -17,6 +36,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model;
+use Friendica\Model\Contact as ModelContact;
 use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Network\HTTPException\NotFoundException;
@@ -93,28 +113,20 @@ class Contact extends BaseModule
                }
 
                if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false])) {
-                       notice(DI::l10n()->t('Could not access contact record.') . EOL);
+                       notice(DI::l10n()->t('Could not access contact record.'));
                        DI::baseUrl()->redirect('contact');
                        return; // NOTREACHED
                }
 
                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']);
 
                $fetch_further_information = intval($_POST['fetch_further_information'] ?? 0);
 
-               $ffi_keyword_blacklist = Strings::escapeHtml(trim($_POST['ffi_keyword_blacklist'] ?? ''));
+               $ffi_keyword_denylist = Strings::escapeHtml(trim($_POST['ffi_keyword_denylist'] ?? ''));
 
                $priority = intval($_POST['poll'] ?? 0);
                if ($priority > 5 || $priority < 0) {
@@ -124,20 +136,17 @@ class Contact extends BaseModule
                $info = Strings::escapeHtml(trim($_POST['info'] ?? ''));
 
                $r = DBA::update('contact', [
-                       'profile-id' => $profile_id,
                        'priority'   => $priority,
                        'info'       => $info,
                        'hidden'     => $hidden,
                        'notify_new_posts' => $notify,
                        'fetch_further_information' => $fetch_further_information,
-                       'ffi_keyword_blacklist'     => $ffi_keyword_blacklist],
+                       'ffi_keyword_denylist'     => $ffi_keyword_denylist],
                        ['id' => $contact_id, 'uid' => local_user()]
                );
 
-               if (DBA::isResult($r)) {
-                       info(DI::l10n()->t('Contact updated.') . EOL);
-               } else {
-                       notice(DI::l10n()->t('Failed to update contact record.') . EOL);
+               if (!DBA::isResult($r)) {
+                       notice(DI::l10n()->t('Failed to update contact record.'));
                }
 
                $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
@@ -157,10 +166,9 @@ class Contact extends BaseModule
                        return;
                }
 
-               $uid = $contact['uid'];
-
                if ($contact['network'] == Protocol::OSTATUS) {
-                       $result = Model\Contact::createFromProbe($uid, $contact['url'], false, $contact['network']);
+                       $user = Model\User::getById($contact['uid']);
+                       $result = Model\Contact::createFromProbe($user, $contact['url'], false, $contact['network']);
 
                        if ($result['success']) {
                                DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
@@ -271,6 +279,8 @@ class Contact extends BaseModule
                        if ($contact['network'] == Protocol::PHANTOM) {
                                $contact = false;
                        }
+
+                       $contact = ModelContact::checkAvatarCacheArray($contact);
                }
 
                if (DBA::isResult($contact)) {
@@ -279,7 +289,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');
                                }
                        }
 
@@ -357,7 +367,7 @@ class Contact extends BaseModule
                Nav::setSelected('contact');
 
                if (!local_user()) {
-                       notice(DI::l10n()->t('Permission denied.') . EOL);
+                       notice(DI::l10n()->t('Permission denied.'));
                        return Login::form();
                }
 
@@ -383,7 +393,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
                        }
 
@@ -391,7 +401,7 @@ class Contact extends BaseModule
                                self::blockContact($contact_id);
 
                                $blocked = Model\Contact::isBlockedByUser($contact_id, local_user());
-                               info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')) . EOL);
+                               info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')));
 
                                DI::baseUrl()->redirect('contact/' . $contact_id);
                                // NOTREACHED
@@ -401,7 +411,7 @@ class Contact extends BaseModule
                                self::ignoreContact($contact_id);
 
                                $ignored = Model\Contact::isIgnoredByUser($contact_id, local_user());
-                               info(($ignored ? DI::l10n()->t('Contact has been ignored') : DI::l10n()->t('Contact has been unignored')) . EOL);
+                               info(($ignored ? DI::l10n()->t('Contact has been ignored') : DI::l10n()->t('Contact has been unignored')));
 
                                DI::baseUrl()->redirect('contact/' . $contact_id);
                                // NOTREACHED
@@ -411,7 +421,7 @@ class Contact extends BaseModule
                                $r = self::archiveContact($contact_id, $orig_record);
                                if ($r) {
                                        $archived = (($orig_record['archive']) ? 0 : 1);
-                                       info((($archived) ? DI::l10n()->t('Contact has been archived') : DI::l10n()->t('Contact has been unarchived')) . EOL);
+                                       info((($archived) ? DI::l10n()->t('Contact has been archived') : DI::l10n()->t('Contact has been unarchived')));
                                }
 
                                DI::baseUrl()->redirect('contact/' . $contact_id);
@@ -452,7 +462,7 @@ class Contact extends BaseModule
                                }
 
                                self::dropContact($orig_record);
-                               info(DI::l10n()->t('Contact has been removed.') . EOL);
+                               info(DI::l10n()->t('Contact has been removed.'));
 
                                DI::baseUrl()->redirect('contact');
                                // NOTREACHED
@@ -503,7 +513,7 @@ class Contact extends BaseModule
                                $relation_text = '';
                        }
 
-                       if (!in_array($contact['network'], Protocol::FEDERATED)) {
+                       if (!in_array($contact['network'], array_merge(Protocol::FEDERATED, [Protocol::TWITTER]))) {
                                $relation_text = '';
                        }
 
@@ -555,20 +565,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;
                        }
@@ -578,8 +581,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'])),
@@ -589,7 +590,6 @@ class Contact extends BaseModule
                                '$visit'          => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']),
                                '$blockunblock'   => DI::l10n()->t('Block/Unblock contact'),
                                '$ignorecont'     => DI::l10n()->t('Ignore contact'),
-                               '$lblcrepair'     => DI::l10n()->t('Repair URL settings'),
                                '$lblrecent'      => DI::l10n()->t('View conversations'),
                                '$lblsuggest'     => $lblsuggest,
                                '$nettype'        => $nettype,
@@ -600,7 +600,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')),
@@ -614,7 +613,7 @@ class Contact extends BaseModule
                                '$hidden'         => ['hidden', DI::l10n()->t('Hide this contact from others'), ($contact['hidden'] == 1), DI::l10n()->t('Replies/likes to your public posts <strong>may</strong> still be visible')],
                                '$notify'         => ['notify', DI::l10n()->t('Notification for new posts'), ($contact['notify_new_posts'] == 1), DI::l10n()->t('Send a notification of every new post of this contact')],
                                '$fetch_further_information' => $fetch_further_information,
-                               '$ffi_keyword_blacklist' => ['ffi_keyword_blacklist', DI::l10n()->t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], DI::l10n()->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
+                               '$ffi_keyword_denylist' => ['ffi_keyword_denylist', DI::l10n()->t('Keyword Deny List'), $contact['ffi_keyword_denylist'], DI::l10n()->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
                                '$photo'          => $contact['photo'],
                                '$name'           => $contact['name'],
                                '$dir_icon'       => $dir_icon,
@@ -716,15 +715,14 @@ class Contact extends BaseModule
                        $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_extra
+                       " . Widget::unavailableNetworks(),
                        $sql_values
                );
                if (DBA::isResult($stmt)) {
@@ -732,7 +730,7 @@ class Contact extends BaseModule
                }
                DBA::close($stmt);
 
-               $pager = new Pager(DI::args()->getQueryString());
+               $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
 
                $sql_values[] = $pager->getStart();
                $sql_values[] = $pager->getItemsPerPage();
@@ -929,7 +927,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',
@@ -974,10 +972,15 @@ class Contact extends BaseModule
                if (DBA::isResult($contact)) {
                        DI::page()['aside'] = '';
 
-                       $profiledata = Model\Contact::getDetailsByURL($contact['url']);
+                       $profiledata = Model\Contact::getByURL($contact['url'], false);
+
+                       Model\Profile::load($a, '', $profiledata, true);
 
-                       Model\Profile::load($a, '', 0, $profiledata, true);
-                       $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
+                       if ($contact['uid'] == 0) {
+                               $o .= Model\Contact::getPostsFromId($contact['id'], true, $update);
+                       } else {
+                               $o .= Model\Contact::getPostsFromUrl($contact['url'], true, $update);
+                       }
                }
 
                return $o;
@@ -992,14 +995,19 @@ class Contact extends BaseModule
                if (DBA::isResult($contact)) {
                        DI::page()['aside'] = '';
 
-                       $profiledata = Model\Contact::getDetailsByURL($contact['url']);
+                       $profiledata = Model\Contact::getByURL($contact['url'], false);
 
                        if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) {
                                $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
                        }
 
-                       Model\Profile::load($a, '', 0, $profiledata, true);
-                       $o .= Model\Contact::getPostsFromUrl($contact['url']);
+                       Model\Profile::load($a, '', $profiledata, true);
+
+                       if ($contact['uid'] == 0) {
+                               $o .= Model\Contact::getPostsFromId($contact['id']);
+                       } else {
+                               $o .= Model\Contact::getPostsFromUrl($contact['url']);
+                       }
                }
 
                return $o;