]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
244427e986b2b7ad262e7179ee78b510289e7c94
[friendica.git] / mod / suggest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Content\ContactSelector;
24 use Friendica\Content\Widget;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
27 use Friendica\DI;
28 use Friendica\Model\Contact;
29 use Friendica\Model\GContact;
30
31 function suggest_init(App $a)
32 {
33         if (! local_user()) {
34                 return;
35         }
36 }
37
38 function suggest_post(App $a)
39 {
40         if (!empty($_POST['ignore']) && !empty($_POST['confirm'])) {
41                 DBA::insert('gcign', ['uid' => local_user(), 'gcid' => $_POST['ignore']]);
42                 notice(DI::l10n()->t('Contact suggestion successfully ignored.'));
43         }
44
45         DI::baseUrl()->redirect('suggest');
46 }
47
48 function suggest_content(App $a)
49 {
50         $o = '';
51
52         if (! local_user()) {
53                 notice(DI::l10n()->t('Permission denied.'));
54                 return;
55         }
56
57         $_SESSION['return_path'] = DI::args()->getCommand();
58
59         DI::page()['aside'] .= Widget::findPeople();
60         DI::page()['aside'] .= Widget::follow();
61
62
63         $contacts = Contact::getSuggestions(local_user());
64         if (!DBA::isResult($contacts)) {
65                 $o .= DI::l10n()->t('No suggestions available. If this is a new site, please try again in 24 hours.');
66                 return $o;
67         }
68
69
70         if (!empty($_GET['ignore'])) {
71                 // <form> can't take arguments in its "action" parameter
72                 // so add any arguments as hidden inputs
73                 $query = explode_querystring(DI::args()->getQueryString());
74                 $inputs = [];
75                 foreach ($query['args'] as $arg) {
76                         if (strpos($arg, 'confirm=') === false) {
77                                 $arg_parts = explode('=', $arg);
78                                 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
79                         }
80                 }
81
82                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
83                         '$method' => 'post',
84                         '$message' => DI::l10n()->t('Do you really want to delete this suggestion?'),
85                         '$extra_inputs' => $inputs,
86                         '$confirm' => DI::l10n()->t('Yes'),
87                         '$confirm_url' => $query['base'],
88                         '$confirm_name' => 'confirm',
89                         '$cancel' => DI::l10n()->t('Cancel'),
90                 ]);
91         }
92
93         $id = 0;
94         $entries = [];
95
96         foreach ($contacts as $contact) {
97                 $entry = [
98                         'url'          => Contact::magicLink($contact['url']),
99                         'itemurl'      => $contact['addr'] ?: $contact['url'],
100                         'name'         => $contact['name'],
101                         'thumb'        => Contact::getThumb($contact),
102                         'img_hover'    => $contact['url'],
103                         'details'      => $contact['location'],
104                         'tags'         => $contact['keywords'],
105                         'about'        => $contact['about'],
106                         'account_type' => Contact::getAccountType($contact),
107                         'network'      => ContactSelector::networkToName($contact['network'], $contact['url']),
108                         'photo_menu'   => Contact::photoMenu($contact),
109                         'id'           => ++$id,
110                 ];
111                 $entries[] = $entry;
112         }
113
114         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
115
116         $o .= Renderer::replaceMacros($tpl,[
117                 '$title' => DI::l10n()->t('Friend Suggestions'),
118                 '$contacts' => $entries,
119         ]);
120
121         return $o;
122 }