]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge pull request #4241 from annando/network-update
[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\Core\System;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Contact;
10 use Friendica\Model\GContact;
11 use Friendica\Model\Profile;
12
13 require_once 'include/contact_widgets.php';
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 = array();
27                         foreach ($query['args'] as $arg) {
28                                 if (strpos($arg, 'confirm=') === false) {
29                                         $arg_parts = explode('=', $arg);
30                                         $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
31                                 }
32                         }
33
34                         $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
35                                 '$method' => 'get',
36                                 '$message' => t('Do you really want to delete this suggestion?'),
37                                 '$extra_inputs' => $inputs,
38                                 '$confirm' => t('Yes'),
39                                 '$confirm_url' => $query['base'],
40                                 '$confirm_name' => 'confirmed',
41                                 '$cancel' => 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', array('uid' => local_user(), 'gcid' => $_GET['ignore']));
49                 }
50         }
51
52 }
53
54
55
56
57
58 function suggest_content(App $a) {
59
60         require_once("mod/proxy.php");
61
62         $o = '';
63         if (! local_user()) {
64                 notice( t('Permission denied.') . EOL);
65                 return;
66         }
67
68         $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
69
70         $a->page['aside'] .= findpeople_widget();
71         $a->page['aside'] .= follow_widget();
72
73
74         $r = GContact::suggestionQuery(local_user());
75
76         if (! DBM::is_result($r)) {
77                 $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');
78                 return $o;
79         }
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 = array(
86                         'profile' => array(t("View Profile"), Profile::zrl($rr["url"])),
87                         'follow' => array(t("Connect/Follow"), $connlnk),
88                         'hide' => array(t('Ignore/Hide'), $ignlnk)
89                 );
90
91                 $contact_details = Contact::getDetailsByURL($rr["url"], local_user(), $rr);
92
93                 $entry = array(
94                         'url' => Profile::zrl($rr['url']),
95                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
96                         'img_hover' => $rr['url'],
97                         'name' => $contact_details['name'],
98                         'thumb' => proxy_url($contact_details['thumb'], false, PROXY_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' => t('Connect'),
106                         'connlnk' => $connlnk,
107                         'photo_menu' => $photo_menu,
108                         'ignore' => t('Ignore/Hide'),
109                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
110                         'id' => ++$id,
111                 );
112                 $entries[] = $entry;
113         }
114
115         $tpl = get_markup_template('viewcontact_template.tpl');
116
117         $o .= replace_macros($tpl,array(
118                 '$title' => t('Friend Suggestions'),
119                 '$contacts' => $entries,
120         ));
121
122         return $o;
123 }