3 * @copyright Copyright (C) 2010-2022, 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;
35 use Friendica\Module\Contact;
36 use Friendica\Module\Response;
37 use Friendica\Network\HTTPException\BadRequestException;
38 use Friendica\Network\HTTPException\ForbiddenException;
39 use Friendica\Util\Profiler;
40 use Friendica\Util\Strings;
41 use Psr\Log\LoggerInterface;
44 * GUI for advanced contact details manipulation
46 class Advanced extends BaseModule
53 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 = [])
55 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
60 if (!Session::isAuthenticated()) {
61 throw new ForbiddenException($this->t('Permission denied.'));
65 protected function post(array $request = [])
67 $cid = $this->parameters['id'];
69 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => Session::getLocalUser()]);
70 if (empty($contact)) {
71 throw new BadRequestException($this->t('Contact not found.'));
74 $name = ($_POST['name'] ?? '') ?: $contact['name'];
75 $nick = $_POST['nick'] ?? '';
76 $url = $_POST['url'] ?? '';
77 $poll = $_POST['poll'] ?? '';
78 $photo = $_POST['photo'] ?? '';
79 $nurl = Strings::normaliseLink($url);
81 $r = $this->dba->update(
90 ['id' => $contact['id'], 'uid' => Session::getLocalUser()]
94 $this->logger->notice('Updating photo.', ['photo' => $photo]);
96 Model\Contact::updateAvatar($contact['id'], $photo, true);
100 DI::sysmsg()->addNotice($this->t('Contact update failed.'));
104 protected function content(array $request = []): string
106 $cid = $this->parameters['id'];
108 $contact = Model\Contact::selectFirst([], ['id' => $cid, 'uid' => Session::getLocalUser()]);
109 if (empty($contact)) {
110 throw new BadRequestException($this->t('Contact not found.'));
113 $this->page['aside'] = Widget\VCard::getHTML($contact);
115 $returnaddr = "contact/$cid";
117 // This data is fetched automatically for most networks.
118 // Editing does only makes sense for mail and feed contacts.
119 if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
120 $readonly = 'readonly';
125 $tab_str = Contact::getTabsHTML($contact, Contact::TAB_ADVANCED);
127 $tpl = Renderer::getMarkupTemplate('contact/advanced.tpl');
128 return Renderer::replaceMacros($tpl, [
129 '$tab_str' => $tab_str,
130 '$returnaddr' => $returnaddr,
131 '$return' => $this->t('Return to contact editor'),
132 '$contact_id' => $contact['id'],
133 '$lbl_submit' => $this->t('Submit'),
135 '$name' => ['name', $this->t('Name'), $contact['name'], '', '', $readonly],
136 '$nick' => ['nick', $this->t('Account Nickname'), $contact['nick'], '', '', 'readonly'],
137 '$url' => ['url', $this->t('Account URL'), $contact['url'], '', '', 'readonly'],
138 'poll' => ['poll', $this->t('Poll/Feed URL'), $contact['poll'], '', '', ($contact['network'] == Protocol::FEED) ? '' : 'readonly'],
139 'photo' => ['photo', $this->t('New photo from this URL'), '', '', '', $readonly],