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;
14 function fsuggest_post(App $a)
24 $contact_id = intval($a->argv[1]);
25 if (empty($contact_id)) {
29 // We do query the "uid" as well to ensure that it is our contact
30 if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
31 notice(L10n::t('Contact not found.') . EOL);
35 $suggest_contact_id = intval($_POST['suggest']);
36 if (empty($suggest_contact_id)) {
40 // We do query the "uid" as well to ensure that it is our contact
41 $contact = DBA::selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => local_user()]);
42 if (!DBA::isResult($contact)) {
43 notice(L10n::t('Suggested contact not found.') . EOL);
47 $note = Strings::escapeHtml(trim(defaults($_POST, 'note', '')));
49 $fields = ['uid' => local_user(),'cid' => $contact_id, 'name' => $contact['name'],
50 'url' => $contact['url'], 'request' => $contact['request'],
51 'photo' => $contact['avatar'], 'note' => $note, 'created' => DateTimeFormat::utcNow()];
52 DBA::insert('fsuggest', $fields);
54 Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', DBA::lastInsertId());
56 info(L10n::t('Friend suggestion sent.') . EOL);
59 function fsuggest_content(App $a)
62 notice(L10n::t('Permission denied.') . EOL);
70 $contact_id = intval($a->argv[1]);
72 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
73 if (! DBA::isResult($contact)) {
74 notice(L10n::t('Contact not found.') . EOL);
78 $o = '<h3>' . L10n::t('Suggest Friends') . '</h3>';
80 $o .= '<div id="fsuggest-desc" >' . L10n::t('Suggest a friend for %s', $contact['name']) . '</div>';
82 $o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >';
84 $o .= ACL::getSuggestContactSelectHTML(
87 ['size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true]
91 $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . L10n::t('Submit') . '" /></div>';