]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Merge pull request #3906 from zeroadam/Global-Poco-#3878
[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
10 require_once 'include/contact_widgets.php';
11
12 function suggest_init(App $a) {
13         if (! local_user()) {
14                 return;
15         }
16
17         if (x($_GET,'ignore') && intval($_GET['ignore'])) {
18                 // Check if we should do HTML-based delete confirmation
19                 if ($_REQUEST['confirm']) {
20                         // <form> can't take arguments in its "action" parameter
21                         // so add any arguments as hidden inputs
22                         $query = explode_querystring($a->query_string);
23                         $inputs = array();
24                         foreach ($query['args'] as $arg) {
25                                 if (strpos($arg, 'confirm=') === false) {
26                                         $arg_parts = explode('=', $arg);
27                                         $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
28                                 }
29                         }
30
31                         $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
32                                 '$method' => 'get',
33                                 '$message' => t('Do you really want to delete this suggestion?'),
34                                 '$extra_inputs' => $inputs,
35                                 '$confirm' => t('Yes'),
36                                 '$confirm_url' => $query['base'],
37                                 '$confirm_name' => 'confirmed',
38                                 '$cancel' => t('Cancel'),
39                         ));
40                         $a->error = 1; // Set $a->error so the other module functions don't execute
41                         return;
42                 }
43                 // Now check how the user responded to the confirmation query
44                 if (!$_REQUEST['canceled']) {
45                         dba::insert('gcign', array('uid' => local_user(), 'gcid' => $_GET['ignore']));
46                 }
47         }
48
49 }
50
51
52
53
54
55 function suggest_content(App $a) {
56
57         require_once("mod/proxy.php");
58
59         $o = '';
60         if (! local_user()) {
61                 notice( t('Permission denied.') . EOL);
62                 return;
63         }
64
65         $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
66
67         $a->page['aside'] .= findpeople_widget();
68         $a->page['aside'] .= follow_widget();
69
70
71         $r = GlobalContact::suggestionQuery(local_user());
72
73         if (! DBM::is_result($r)) {
74                 $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');
75                 return $o;
76         }
77
78         require_once 'include/contact_selectors.php';
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 = array(
85                         'profile' => array(t("View Profile"), zrl($rr["url"])),
86                         'follow' => array(t("Connect/Follow"), $connlnk),
87                         'hide' => array(t('Ignore/Hide'), $ignlnk)
88                 );
89
90                 $contact_details = get_contact_details_by_url($rr["url"], local_user(), $rr);
91
92                 $entry = array(
93                         'url' => zrl($rr['url']),
94                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
95                         'img_hover' => $rr['url'],
96                         'name' => $contact_details['name'],
97                         'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
98                         'details'       => $contact_details['location'],
99                         'tags'          => $contact_details['keywords'],
100                         'about'         => $contact_details['about'],
101                         'account_type'  => account_type($contact_details),
102                         'ignlnk' => $ignlnk,
103                         'ignid' => $rr['id'],
104                         'conntxt' => t('Connect'),
105                         'connlnk' => $connlnk,
106                         'photo_menu' => $photo_menu,
107                         'ignore' => t('Ignore/Hide'),
108                         'network' => network_to_name($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,array(
117                 '$title' => t('Friend Suggestions'),
118                 '$contacts' => $entries,
119         ));
120
121         return $o;
122 }