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;
24 use Friendica\App\Page;
25 use Friendica\BaseModule;
26 use Friendica\Content\Widget;
27 use Friendica\Core\L10n;
28 use Friendica\Core\Protocol;
29 use Friendica\Core\Renderer;
30 use Friendica\Core\Session;
31 use Friendica\Database\Database;
33 use Friendica\Module\Contact;
34 use Friendica\Network\HTTPException\BadRequestException;
35 use Friendica\Network\HTTPException\ForbiddenException;
36 use Friendica\Util\Strings;
37 use Psr\Log\LoggerInterface;
40 * GUI for advanced contact details manipulation
42 class Advanced extends BaseModule
46 /** @var LoggerInterface */
51 public function __construct(Database $dba, LoggerInterface $logger, Page $page, L10n $l10n, array $parameters = [])
53 parent::__construct($l10n, $parameters);
56 $this->logger = $logger;
59 if (!Session::isAuthenticated()) {
60 throw new ForbiddenException($this->t('Permission denied.'));
64 public function post()
66 $cid = $this->parameters['id'];
68 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
69 if (empty($contact)) {
70 throw new BadRequestException($this->t('Contact not found.'));
73 $name = ($_POST['name'] ?? '') ?: $contact['name'];
74 $nick = $_POST['nick'] ?? '';
75 $url = $_POST['url'] ?? '';
76 $alias = $_POST['alias'] ?? '';
77 $request = $_POST['request'] ?? '';
78 $confirm = $_POST['confirm'] ?? '';
79 $notify = $_POST['notify'] ?? '';
80 $poll = $_POST['poll'] ?? '';
81 $attag = $_POST['attag'] ?? '';
82 $photo = $_POST['photo'] ?? '';
83 $nurl = Strings::normaliseLink($url);
85 $r = $this->dba->update(
93 'request' => $request,
94 'confirm' => $confirm,
99 ['id' => $contact['id'], 'uid' => local_user()]
103 $this->logger->notice('Updating photo.', ['photo' => $photo]);
105 Model\Contact::updateAvatar($contact['id'], $photo, true);
109 notice($this->t('Contact update failed.'));
113 public function content(): string
115 $cid = $this->parameters['id'];
117 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => local_user()]);
118 if (empty($contact)) {
119 throw new BadRequestException($this->t('Contact not found.'));
122 $this->page['aside'] = Widget\VCard::getHTML($contact);
124 $warning = $this->t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
125 $info = $this->t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
127 $returnaddr = "contact/$cid";
129 // This data is fetched automatically for most networks.
130 // Editing does only makes sense for mail and feed contacts.
131 if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
132 $readonly = 'readonly';
137 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
139 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
140 return Renderer::replaceMacros($tpl, [
141 '$tab_str' => $tab_str,
142 '$warning' => $warning,
144 '$returnaddr' => $returnaddr,
145 '$return' => $this->t('Return to contact editor'),
146 '$contact_id' => $contact['id'],
147 '$lbl_submit' => $this->t('Submit'),
149 '$name' => ['name', $this->t('Name'), $contact['name'], '', '', $readonly],
150 '$nick' => ['nick', $this->t('Account Nickname'), $contact['nick'], '', '', $readonly],
151 '$attag' => ['attag', $this->t('@Tagname - overrides Name/Nickname'), $contact['attag']],
152 '$url' => ['url', $this->t('Account URL'), $contact['url'], '', '', $readonly],
153 '$alias' => ['alias', $this->t('Account URL Alias'), $contact['alias'], '', '', $readonly],
154 '$request' => ['request', $this->t('Friend Request URL'), $contact['request'], '', '', $readonly],
155 'confirm' => ['confirm', $this->t('Friend Confirm URL'), $contact['confirm'], '', '', $readonly],
156 'notify' => ['notify', $this->t('Notification Endpoint URL'), $contact['notify'], '', '', $readonly],
157 'poll' => ['poll', $this->t('Poll/Feed URL'), $contact['poll'], '', '', $readonly],
158 'photo' => ['photo', $this->t('New photo from this URL'), '', '', '', $readonly],