]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge pull request #6977 from annando/fix-reshare
[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         $entries = [];
81
82         foreach ($r as $rr) {
83
84                 $connlnk = System::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']);
85                 $ignlnk = System::baseUrl() . '/suggest?ignore=' . $rr['id'];
86                 $photo_menu = [
87                         'profile' => [L10n::t("View Profile"), Contact::magicLink($rr["url"])],
88                         'follow' => [L10n::t("Connect/Follow"), $connlnk],
89                         'hide' => [L10n::t('Ignore/Hide'), $ignlnk]
90                 ];
91
92                 $contact_details = Contact::getDetailsByURL($rr["url"], local_user(), $rr);
93
94                 $entry = [
95                         'url' => Contact::magicLink($rr['url']),
96                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
97                         'img_hover' => $rr['url'],
98                         'name' => $contact_details['name'],
99                         'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
100                         'details'       => $contact_details['location'],
101                         'tags'          => $contact_details['keywords'],
102                         'about'         => $contact_details['about'],
103                         'account_type'  => Contact::getAccountType($contact_details),
104                         'ignlnk' => $ignlnk,
105                         'ignid' => $rr['id'],
106                         'conntxt' => L10n::t('Connect'),
107                         'connlnk' => $connlnk,
108                         'photo_menu' => $photo_menu,
109                         'ignore' => L10n::t('Ignore/Hide'),
110                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
111                         'id' => ++$id,
112                 ];
113                 $entries[] = $entry;
114         }
115
116         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
117
118         $o .= Renderer::replaceMacros($tpl,[
119                 '$title' => L10n::t('Friend Suggestions'),
120                 '$contacts' => $entries,
121         ]);
122
123         return $o;
124 }