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