]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge pull request #6223 from annando/ap-dba-error
[friendica.git] / mod / suggest.php
1 <?php
2 /**
3  * @file mod/suggest.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Widget;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Model\Contact;
14 use Friendica\Model\GContact;
15 use Friendica\Util\Proxy as ProxyUtils;
16
17 function suggest_init(App $a)
18 {
19         if (! local_user()) {
20                 return;
21         }
22
23         if (!empty($_GET['ignore'])) {
24                 // Check if we should do HTML-based delete confirmation
25                 if ($_REQUEST['confirm']) {
26                         // <form> can't take arguments in its "action" parameter
27                         // so add any arguments as hidden inputs
28                         $query = explode_querystring($a->query_string);
29                         $inputs = [];
30                         foreach ($query['args'] as $arg) {
31                                 if (strpos($arg, 'confirm=') === false) {
32                                         $arg_parts = explode('=', $arg);
33                                         $inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
34                                 }
35                         }
36
37                         $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
38                                 '$method' => 'get',
39                                 '$message' => L10n::t('Do you really want to delete this suggestion?'),
40                                 '$extra_inputs' => $inputs,
41                                 '$confirm' => L10n::t('Yes'),
42                                 '$confirm_url' => $query['base'],
43                                 '$confirm_name' => 'confirmed',
44                                 '$cancel' => L10n::t('Cancel'),
45                         ]);
46                         $a->error = 1; // Set $a->error so the other module functions don't execute
47                         return;
48                 }
49                 // Now check how the user responded to the confirmation query
50                 if (!$_REQUEST['canceled']) {
51                         DBA::insert('gcign', ['uid' => local_user(), 'gcid' => $_GET['ignore']]);
52                 }
53         }
54
55 }
56
57 function suggest_content(App $a)
58 {
59         $o = '';
60
61         if (! local_user()) {
62                 notice(L10n::t('Permission denied.') . EOL);
63                 return;
64         }
65
66         $_SESSION['return_path'] = $a->cmd;
67
68         $a->page['aside'] .= Widget::findPeople();
69         $a->page['aside'] .= Widget::follow();
70
71
72         $r = GContact::suggestionQuery(local_user());
73
74         if (! DBA::isResult($r)) {
75                 $o .= L10n::t('No suggestions available. If this is a new site, please try again in 24 hours.');
76                 return $o;
77         }
78
79         $id = 0;
80
81         foreach ($r as $rr) {
82
83                 $connlnk = System::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']);
84                 $ignlnk = System::baseUrl() . '/suggest?ignore=' . $rr['id'];
85                 $photo_menu = [
86                         'profile' => [L10n::t("View Profile"), Contact::magicLink($rr["url"])],
87                         'follow' => [L10n::t("Connect/Follow"), $connlnk],
88                         'hide' => [L10n::t('Ignore/Hide'), $ignlnk]
89                 ];
90
91                 $contact_details = Contact::getDetailsByURL($rr["url"], local_user(), $rr);
92
93                 $entry = [
94                         'url' => Contact::magicLink($rr['url']),
95                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
96                         'img_hover' => $rr['url'],
97                         'name' => $contact_details['name'],
98                         'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
99                         'details'       => $contact_details['location'],
100                         'tags'          => $contact_details['keywords'],
101                         'about'         => $contact_details['about'],
102                         'account_type'  => Contact::getAccountType($contact_details),
103                         'ignlnk' => $ignlnk,
104                         'ignid' => $rr['id'],
105                         'conntxt' => L10n::t('Connect'),
106                         'connlnk' => $connlnk,
107                         'photo_menu' => $photo_menu,
108                         'ignore' => L10n::t('Ignore/Hide'),
109                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
110                         'id' => ++$id,
111                 ];
112                 $entries[] = $entry;
113         }
114
115         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
116
117         $o .= Renderer::replaceMacros($tpl,[
118                 '$title' => L10n::t('Friend Suggestions'),
119                 '$contacts' => $entries,
120         ]);
121
122         return $o;
123 }