]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge pull request #8952 from annando/contact-template
[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\Widget;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\Contact;
28 use Friendica\Module\Contact as ModuleContact;
29
30 function suggest_init(App $a)
31 {
32         if (! local_user()) {
33                 return;
34         }
35 }
36
37 function suggest_post(App $a)
38 {
39         if (!empty($_POST['ignore']) && !empty($_POST['confirm'])) {
40                 DBA::insert('gcign', ['uid' => local_user(), 'gcid' => $_POST['ignore']]);
41                 notice(DI::l10n()->t('Contact suggestion successfully ignored.'));
42         }
43
44         DI::baseUrl()->redirect('suggest');
45 }
46
47 function suggest_content(App $a)
48 {
49         $o = '';
50
51         if (! local_user()) {
52                 notice(DI::l10n()->t('Permission denied.'));
53                 return;
54         }
55
56         $_SESSION['return_path'] = DI::args()->getCommand();
57
58         DI::page()['aside'] .= Widget::findPeople();
59         DI::page()['aside'] .= Widget::follow();
60
61
62         $contacts = Contact::getSuggestions(local_user());
63         if (!DBA::isResult($contacts)) {
64                 $o .= DI::l10n()->t('No suggestions available. If this is a new site, please try again in 24 hours.');
65                 return $o;
66         }
67
68
69         if (!empty($_GET['ignore'])) {
70                 // <form> can't take arguments in its "action" parameter
71                 // so add any arguments as hidden inputs
72                 $query = explode_querystring(DI::args()->getQueryString());
73                 $inputs = [];
74                 foreach ($query['args'] as $arg) {
75                         if (strpos($arg, 'confirm=') === false) {
76                                 $arg_parts = explode('=', $arg);
77                                 $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
78                         }
79                 }
80
81                 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
82                         '$method' => 'post',
83                         '$message' => DI::l10n()->t('Do you really want to delete this suggestion?'),
84                         '$extra_inputs' => $inputs,
85                         '$confirm' => DI::l10n()->t('Yes'),
86                         '$confirm_url' => $query['base'],
87                         '$confirm_name' => 'confirm',
88                         '$cancel' => DI::l10n()->t('Cancel'),
89                 ]);
90         }
91
92         $entries = [];
93         foreach ($contacts as $contact) {
94                 $entries[] = ModuleContact::getContactTemplateVars($contact);
95         }
96
97         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
98
99         $o .= Renderer::replaceMacros($tpl,[
100                 '$title' => DI::l10n()->t('Friend Suggestions'),
101                 '$contacts' => $entries,
102         ]);
103
104         return $o;
105 }