]> git.mxchange.org Git - friendica.git/blob - mod/suggest.php
Rename 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\Content\Widget;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10 use Friendica\Model\Contact;
11 use Friendica\Model\GContact;
12 use Friendica\Model\Profile;
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 function suggest_content(App $a) {
54
55         require_once("mod/proxy.php");
56
57         $o = '';
58         if (! local_user()) {
59                 notice( t('Permission denied.') . EOL);
60                 return;
61         }
62
63         $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
64
65         $a->page['aside'] .= Widget::findPeople();
66         $a->page['aside'] .= Widget::follow();
67
68
69         $r = GContact::suggestionQuery(local_user());
70
71         if (! DBM::is_result($r)) {
72                 $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');
73                 return $o;
74         }
75
76         foreach ($r as $rr) {
77
78                 $connlnk = System::baseUrl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']);
79                 $ignlnk = System::baseUrl() . '/suggest?ignore=' . $rr['id'];
80                 $photo_menu = array(
81                         'profile' => array(t("View Profile"), Profile::zrl($rr["url"])),
82                         'follow' => array(t("Connect/Follow"), $connlnk),
83                         'hide' => array(t('Ignore/Hide'), $ignlnk)
84                 );
85
86                 $contact_details = Contact::getDetailsByURL($rr["url"], local_user(), $rr);
87
88                 $entry = array(
89                         'url' => Profile::zrl($rr['url']),
90                         'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
91                         'img_hover' => $rr['url'],
92                         'name' => $contact_details['name'],
93                         'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
94                         'details'       => $contact_details['location'],
95                         'tags'          => $contact_details['keywords'],
96                         'about'         => $contact_details['about'],
97                         'account_type'  => Contact::getAccountType($contact_details),
98                         'ignlnk' => $ignlnk,
99                         'ignid' => $rr['id'],
100                         'conntxt' => t('Connect'),
101                         'connlnk' => $connlnk,
102                         'photo_menu' => $photo_menu,
103                         'ignore' => t('Ignore/Hide'),
104                         'network' => ContactSelector::networkToName($rr['network'], $rr['url']),
105                         'id' => ++$id,
106                 );
107                 $entries[] = $entry;
108         }
109
110         $tpl = get_markup_template('viewcontact_template.tpl');
111
112         $o .= replace_macros($tpl,array(
113                 '$title' => t('Friend Suggestions'),
114                 '$contacts' => $entries,
115         ));
116
117         return $o;
118 }