]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge branch 'develop' into issue/3878-move-Contact-to-src
[friendica.git] / mod / suggest.php
1 <?php
2 /**
3  * @file mod/suggest.php
4  */
5 use Friendica\App;
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\GlobalContact;
9 use Friendica\Object\Contact;
10
11 require_once 'include/contact_widgets.php';
12
13 function suggest_init(App $a) {
14         if (! local_user()) {
15                 return;
16         }
17
18         if (x($_GET,'ignore') && intval($_GET['ignore'])) {
19                 // Check if we should do HTML-based delete confirmation
20                 if ($_REQUEST['confirm']) {
21                         // <form> can't take arguments in its "action" parameter
22                         // so add any arguments as hidden inputs
23                         $query = explode_querystring($a->query_string);
24                         $inputs = array();
25                         foreach ($query['args'] as $arg) {
26                                 if (strpos($arg, 'confirm=') === false) {
27                                         $arg_parts = explode('=', $arg);
28                                         $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
29                                 }
30                         }
31
32                         $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
33                                 '$method' => 'get',
34                                 '$message' => t('Do you really want to delete this suggestion?'),
35                                 '$extra_inputs' => $inputs,
36                                 '$confirm' => t('Yes'),
37                                 '$confirm_url' => $query['base'],
38                                 '$confirm_name' => 'confirmed',
39                                 '$cancel' => t('Cancel'),
40                         ));
41                         $a->error = 1; // Set $a->error so the other module functions don't execute
42                         return;
43                 }
44                 // Now check how the user responded to the confirmation query
45                 if (!$_REQUEST['canceled']) {
46                         dba::insert('gcign', array('uid' => local_user(), 'gcid' => $_GET['ignore']));
47                 }
48         }
49
50 }
51
52
53
54
55
56 function suggest_content(App $a) {
57
58         require_once("mod/proxy.php");
59
60         $o = '';
61         if (! local_user()) {
62                 notice( t('Permission denied.') . EOL);
63                 return;
64         }
65
66         $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
67
68         $a->page['aside'] .= findpeople_widget();
69         $a->page['aside'] .= follow_widget();
70
71
72         $r = GlobalContact::suggestionQuery(local_user());
73
74         if (! DBM::is_result($r)) {
75                 $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');
76                 return $o;
77         }
78
79         require_once 'include/contact_selectors.php';
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"), 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' => 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' => network_to_name($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 }