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