3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Contact;
25 use Friendica\App\Page;
26 use Friendica\BaseModule;
27 use Friendica\Content\Widget;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Protocol;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session;
32 use Friendica\Database\Database;
34 use Friendica\Module\Contact;
35 use Friendica\Network\HTTPException\BadRequestException;
36 use Friendica\Network\HTTPException\ForbiddenException;
37 use Friendica\Util\Profiler;
38 use Friendica\Util\Strings;
39 use Psr\Log\LoggerInterface;
42 * GUI for advanced contact details manipulation
44 class Advanced extends BaseModule
51 public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Database $dba, array $server, array $parameters = [])
53 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
58 if (!Session::isAuthenticated()) {
59 throw new ForbiddenException($this->t('Permission denied.'));
63 protected function post(array $request = [], array $post = [])
65 $cid = $this->parameters['id'];
67 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
68 if (empty($contact)) {
69 throw new BadRequestException($this->t('Contact not found.'));
72 $name = ($_POST['name'] ?? '') ?: $contact['name'];
73 $nick = $_POST['nick'] ?? '';
74 $url = $_POST['url'] ?? '';
75 $alias = $_POST['alias'] ?? '';
76 $request = $_POST['request'] ?? '';
77 $confirm = $_POST['confirm'] ?? '';
78 $notify = $_POST['notify'] ?? '';
79 $poll = $_POST['poll'] ?? '';
80 $attag = $_POST['attag'] ?? '';
81 $photo = $_POST['photo'] ?? '';
82 $nurl = Strings::normaliseLink($url);
84 $r = $this->dba->update(
92 'request' => $request,
93 'confirm' => $confirm,
98 ['id' => $contact['id'], 'uid' => local_user()]
102 $this->logger->notice('Updating photo.', ['photo' => $photo]);
104 Model\Contact::updateAvatar($contact['id'], $photo, true);
108 notice($this->t('Contact update failed.'));
112 protected function content(array $request = []): string
114 $cid = $this->parameters['id'];
116 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
117 if (empty($contact)) {
118 throw new BadRequestException($this->t('Contact not found.'));
121 $this->page['aside'] = Widget\VCard::getHTML($contact);
123 $warning = $this->t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
124 $info = $this->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
126 $returnaddr = "contact/$cid";
128 // This data is fetched automatically for most networks.
129 // Editing does only makes sense for mail and feed contacts.
130 if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
131 $readonly = 'readonly';
136 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
138 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
139 return Renderer::replaceMacros($tpl, [
140 '$tab_str' => $tab_str,
141 '$warning' => $warning,
143 '$returnaddr' => $returnaddr,
144 '$return' => $this->t('Return to contact editor'),
145 '$contact_id' => $contact['id'],
146 '$lbl_submit' => $this->t('Submit'),
148 '$name' => ['name', $this->t('Name'), $contact['name'], '', '', $readonly],
149 '$nick' => ['nick', $this->t('Account Nickname'), $contact['nick'], '', '', $readonly],
150 '$attag' => ['attag', $this->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
151 '$url' => ['url', $this->t('Account URL'), $contact['url'], '', '', $readonly],
152 '$alias' => ['alias', $this->t('Account URL Alias'), $contact['alias'], '', '', $readonly],
153 '$request' => ['request', $this->t('Friend Request URL'), $contact['request'], '', '', $readonly],
154 'confirm' => ['confirm', $this->t('Friend Confirm URL'), $contact['confirm'], '', '', $readonly],
155 'notify' => ['notify', $this->t('Notification Endpoint URL'), $contact['notify'], '', '', $readonly],
156 'poll' => ['poll', $this->t('Poll/Feed URL'), $contact['poll'], '', '', $readonly],
157 'photo' => ['photo', $this->t('New photo from this URL'), '', '', '', $readonly],