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