]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Some more avatar function replacements
[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         $r = GContact::suggestionQuery(local_user());
64
65         if (! DBA::isResult($r)) {
66                 $o .= DI::l10n()->t('No suggestions available. If this is a new site, please try again in 24 hours.');
67                 return $o;
68         }
69
70
71         if (!empty($_GET['ignore'])) {
72                 // <form> can't take arguments in its "action" parameter
73                 // so add any arguments as hidden inputs
74                 $query = explode_querystring(DI::args()->getQueryString());
75                 $inputs = [];
76                 foreach ($query['args'] as $arg) {
77                         if (strpos($arg, 'confirm=') === false) {
78                                 $arg_parts = explode('=', $arg);
79                                 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
80                         }
81                 }
82
83                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
84                         '$method' => 'post',
85                         '$message' => DI::l10n()->t('Do you really want to delete this suggestion?'),
86                         '$extra_inputs' => $inputs,
87                         '$confirm' => DI::l10n()->t('Yes'),
88                         '$confirm_url' => $query['base'],
89                         '$confirm_name' => 'confirm',
90                         '$cancel' => DI::l10n()->t('Cancel'),
91                 ]);
92         }
93
94         $id = 0;
95         $entries = [];
96
97         foreach ($r as $rr) {
98                 $connlnk = DI::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']);
99                 $ignlnk = DI::baseUrl() . '/suggest?ignore=' . $rr['id'];
100                 $photo_menu = [
101                         'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($rr["url"])],
102                         'follow' => [DI::l10n()->t("Connect/Follow"), $connlnk],
103                         'hide' => [DI::l10n()->t('Ignore/Hide'), $ignlnk]
104                 ];
105
106                 $contact_details = Contact::getByURLForUser($rr["url"], local_user()) ?: $rr;
107
108                 $entry = [
109                         'url' => Contact::magicLink($rr['url']),
110                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
111                         'img_hover' => $rr['url'],
112                         'name' => $contact_details['name'],
113                         'thumb' => Contact::getThumb($contact_details),
114                         'details'       => $contact_details['location'],
115                         'tags'          => $contact_details['keywords'],
116                         'about'         => $contact_details['about'],
117                         'account_type'  => Contact::getAccountType($contact_details),
118                         'ignlnk' => $ignlnk,
119                         'ignid' => $rr['id'],
120                         'conntxt' => DI::l10n()->t('Connect'),
121                         'connlnk' => $connlnk,
122                         'photo_menu' => $photo_menu,
123                         'ignore' => DI::l10n()->t('Ignore/Hide'),
124                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
125                         'id' => ++$id,
126                 ];
127                 $entries[] = $entry;
128         }
129
130         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
131
132         $o .= Renderer::replaceMacros($tpl,[
133                 '$title' => DI::l10n()->t('Friend Suggestions'),
134                 '$contacts' => $entries,
135         ]);
136
137         return $o;
138 }