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