3 * @copyright Copyright (C) 2010-2023, 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\Database\Database;
34 use Friendica\Module\Contact;
35 use Friendica\Module\Response;
36 use Friendica\Network\HTTPException\BadRequestException;
37 use Friendica\Network\HTTPException\ForbiddenException;
38 use Friendica\Util\Profiler;
39 use Friendica\Util\Strings;
40 use Psr\Log\LoggerInterface;
43 * GUI for advanced contact details manipulation
45 class Advanced extends BaseModule
52 public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, App\Page $page, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, array $server, array $parameters = [])
54 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
59 if (!DI::userSession()->isAuthenticated()) {
60 throw new ForbiddenException($this->t('Permission denied.'));
64 protected function post(array $request = [])
66 $cid = $this->parameters['id'];
68 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]);
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 $poll = $_POST['poll'] ?? '';
77 $photo = $_POST['photo'] ?? '';
78 $nurl = Strings::normaliseLink($url);
80 $r = $this->dba->update(
89 ['id' => $contact['id'], 'uid' => DI::userSession()->getLocalUserId()]
93 $this->logger->notice('Updating photo.', ['photo' => $photo]);
95 Model\Contact::updateAvatar($contact['id'], $photo, true);
99 DI::sysmsg()->addNotice($this->t('Contact update failed.'));
103 protected function content(array $request = []): string
105 $cid = $this->parameters['id'];
107 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]);
108 if (empty($contact)) {
109 throw new BadRequestException($this->t('Contact not found.'));
112 $this->page['aside'] = Widget\VCard::getHTML($contact);
114 $returnaddr = "contact/$cid";
116 // This data is fetched automatically for most networks.
117 // Editing does only makes sense for mail and feed contacts.
118 if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
119 $readonly = 'readonly';
124 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
126 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
127 return Renderer::replaceMacros($tpl, [
128 '$tab_str' => $tab_str,
129 '$returnaddr' => $returnaddr,
130 '$return' => $this->t('Return to contact editor'),
131 '$contact_id' => $contact['id'],
132 '$lbl_submit' => $this->t('Submit'),
134 '$name' => ['name', $this->t('Name'), $contact['name'], '', '', $readonly],
135 '$nick' => ['nick', $this->t('Account Nickname'), $contact['nick'], '', '', 'readonly'],
136 '$url' => ['url', $this->t('Account URL'), $contact['url'], '', '', 'readonly'],
137 'poll' => ['poll', $this->t('Poll/Feed URL'), $contact['poll'], '', '', ($contact['network'] == Protocol::FEED) ? '' : 'readonly'],
138 'photo' => ['photo', $this->t('New photo from this URL'), '', '', '', $readonly],