3 * @file mod/fsuggest.php
7 use Friendica\Core\ACL;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Worker;
10 use Friendica\Database\DBA;
11 use Friendica\Util\DateTimeFormat;
12 use Friendica\Util\Strings;
13 use Friendica\Worker\Delivery;
15 function fsuggest_post(App $a)
25 $contact_id = intval($a->argv[1]);
26 if (empty($contact_id)) {
30 // We do query the "uid" as well to ensure that it is our contact
31 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
32 notice(DI::l10n()->t('Contact not found.') . EOL);
36 $suggest_contact_id = intval($_POST['suggest']);
37 if (empty($suggest_contact_id)) {
41 // We do query the "uid" as well to ensure that it is our contact
42 $contact = DBA::selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => local_user()]);
43 if (!DBA::isResult($contact)) {
44 notice(DI::l10n()->t('Suggested contact not found.') . EOL);
48 $note = Strings::escapeHtml(trim($_POST['note'] ?? ''));
50 $fields = ['uid' => local_user(),'cid' => $contact_id, 'name' => $contact['name'],
51 'url' => $contact['url'], 'request' => $contact['request'],
52 'photo' => $contact['avatar'], 'note' => $note, 'created' => DateTimeFormat::utcNow()];
53 DBA::insert('fsuggest', $fields);
55 Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, DBA::lastInsertId());
57 info(DI::l10n()->t('Friend suggestion sent.') . EOL);
60 function fsuggest_content(App $a)
63 notice(DI::l10n()->t('Permission denied.') . EOL);
71 $contact_id = intval($a->argv[1]);
73 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
74 if (! DBA::isResult($contact)) {
75 notice(DI::l10n()->t('Contact not found.') . EOL);
79 $o = '<h3>' . DI::l10n()->t('Suggest Friends') . '</h3>';
81 $o .= '<div id="fsuggest-desc" >' . DI::l10n()->t('Suggest a friend for %s', $contact['name']) . '</div>';
83 $o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >';
85 $o .= ACL::getSuggestContactSelectHTML(
88 ['size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true]
92 $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . DI::l10n()->t('Submit') . '" /></div>';