]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge pull request #8888 from annando/rename-keywordlist
[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 use Friendica\Util\Proxy as ProxyUtils;
31
32 function suggest_init(App $a)
33 {
34         if (! local_user()) {
35                 return;
36         }
37 }
38
39 function suggest_post(App $a)
40 {
41         if (!empty($_POST['ignore']) && !empty($_POST['confirm'])) {
42                 DBA::insert('gcign', ['uid' => local_user(), 'gcid' => $_POST['ignore']]);
43                 notice(DI::l10n()->t('Contact suggestion successfully ignored.'));
44         }
45
46         DI::baseUrl()->redirect('suggest');
47 }
48
49 function suggest_content(App $a)
50 {
51         $o = '';
52
53         if (! local_user()) {
54                 notice(DI::l10n()->t('Permission denied.') . EOL);
55                 return;
56         }
57
58         $_SESSION['return_path'] = DI::args()->getCommand();
59
60         DI::page()['aside'] .= Widget::findPeople();
61         DI::page()['aside'] .= Widget::follow();
62
63
64         $r = GContact::suggestionQuery(local_user());
65
66         if (! DBA::isResult($r)) {
67                 $o .= DI::l10n()->t('No suggestions available. If this is a new site, please try again in 24 hours.');
68                 return $o;
69         }
70
71
72         if (!empty($_GET['ignore'])) {
73                 // <form> can't take arguments in its "action" parameter
74                 // so add any arguments as hidden inputs
75                 $query = explode_querystring(DI::args()->getQueryString());
76                 $inputs = [];
77                 foreach ($query['args'] as $arg) {
78                         if (strpos($arg, 'confirm=') === false) {
79                                 $arg_parts = explode('=', $arg);
80                                 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
81                         }
82                 }
83
84                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
85                         '$method' => 'post',
86                         '$message' => DI::l10n()->t('Do you really want to delete this suggestion?'),
87                         '$extra_inputs' => $inputs,
88                         '$confirm' => DI::l10n()->t('Yes'),
89                         '$confirm_url' => $query['base'],
90                         '$confirm_name' => 'confirm',
91                         '$cancel' => DI::l10n()->t('Cancel'),
92                 ]);
93         }
94
95         $id = 0;
96         $entries = [];
97
98         foreach ($r as $rr) {
99                 $connlnk = DI::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']);
100                 $ignlnk = DI::baseUrl() . '/suggest?ignore=' . $rr['id'];
101                 $photo_menu = [
102                         'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($rr["url"])],
103                         'follow' => [DI::l10n()->t("Connect/Follow"), $connlnk],
104                         'hide' => [DI::l10n()->t('Ignore/Hide'), $ignlnk]
105                 ];
106
107                 $contact_details = Contact::getByURLForUser($rr["url"], local_user()) ?: $rr;
108
109                 $entry = [
110                         'url' => Contact::magicLink($rr['url']),
111                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
112                         'img_hover' => $rr['url'],
113                         'name' => $contact_details['name'],
114                         'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
115                         'details'       => $contact_details['location'],
116                         'tags'          => $contact_details['keywords'],
117                         'about'         => $contact_details['about'],
118                         'account_type'  => Contact::getAccountType($contact_details),
119                         'ignlnk' => $ignlnk,
120                         'ignid' => $rr['id'],
121                         'conntxt' => DI::l10n()->t('Connect'),
122                         'connlnk' => $connlnk,
123                         'photo_menu' => $photo_menu,
124                         'ignore' => DI::l10n()->t('Ignore/Hide'),
125                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
126                         'id' => ++$id,
127                 ];
128                 $entries[] = $entry;
129         }
130
131         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
132
133         $o .= Renderer::replaceMacros($tpl,[
134                 '$title' => DI::l10n()->t('Friend Suggestions'),
135                 '$contacts' => $entries,
136         ]);
137
138         return $o;
139 }