]> git.mxchange.org Git - friendica.git/blob - include/contact_widgets.php
Rearranged the contact menu so that it fits the menu at the conversations.
[friendica.git] / include / contact_widgets.php
1 <?php
2
3 function follow_widget($value = "") {
4
5         return replace_macros(get_markup_template('follow.tpl'),array(
6                 '$connect' => t('Add New Contact'),
7                 '$desc' => t('Enter address or web location'),
8                 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
9                 '$value' => $value,
10                 '$follow' => t('Connect')
11         ));
12
13 }
14
15 function findpeople_widget() {
16         require_once('include/Contact.php');
17
18         $a = get_app();
19
20         if(get_config('system','invitation_only')) {
21                 $x = get_pconfig(local_user(),'system','invites_remaining');
22                 if($x || is_site_admin()) {
23                         $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">' 
24                         . sprintf( tt('%d invitation available','%d invitations available',$x), $x) 
25                         . '</div>' . $inv;
26                 }
27         }
28  
29         return replace_macros(get_markup_template('peoplefind.tpl'),array(
30                 '$findpeople' => t('Find People'),
31                 '$desc' => t('Enter name or interest'),
32                 '$label' => t('Connect/Follow'),
33                 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
34                 '$findthem' => t('Find'),
35                 '$suggest' => t('Friend Suggestions'),
36                 '$similar' => t('Similar Interests'),
37                 '$random' => t('Random Profile'),
38                 '$inv' => t('Invite Friends')
39         ));
40
41 }
42
43
44 function networks_widget($baseurl,$selected = '') {
45
46         $a = get_app();
47
48         if(! local_user())
49                 return '';
50
51         if(! feature_enabled(local_user(),'networks'))
52                 return '';
53
54         $r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND `self` = 0 ORDER BY `network`",
55                 intval(local_user())
56         );
57
58         $nets = array();
59         if(count($r)) {
60                 require_once('include/contact_selectors.php');
61                 foreach($r as $rr) {
62                                 if($rr['network'])
63                                         $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
64                 }
65         }
66
67         if(count($nets) < 2)
68                 return '';
69
70         return replace_macros(get_markup_template('nets.tpl'),array(
71                 '$title' => t('Networks'),
72                 '$desc' => '',
73                 '$sel_all' => (($selected == '') ? 'selected' : ''),
74                 '$all' => t('All Networks'),
75                 '$nets' => $nets,
76                 '$base' => $baseurl,
77
78         ));
79 }
80
81 function fileas_widget($baseurl,$selected = '') {
82         $a = get_app();
83         if(! local_user())
84                 return '';
85
86         if(! feature_enabled(local_user(),'filing'))
87                 return '';
88
89         $saved = get_pconfig(local_user(),'system','filetags');
90         if(! strlen($saved))
91                 return;
92
93         $matches = false;
94         $terms = array();
95     $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER);
96     if($cnt) {
97                 foreach($matches as $mtch) {
98                         $unescaped = xmlify(file_tag_decode($mtch[1]));
99                         $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
100                 }
101         }
102
103         return replace_macros(get_markup_template('fileas_widget.tpl'),array(
104                 '$title' => t('Saved Folders'),
105                 '$desc' => '',
106                 '$sel_all' => (($selected == '') ? 'selected' : ''),
107                 '$all' => t('Everything'),
108                 '$terms' => $terms,
109                 '$base' => $baseurl,
110
111         ));
112 }
113
114 function categories_widget($baseurl,$selected = '') {
115
116         $a = get_app();
117
118         if(! feature_enabled($a->profile['profile_uid'],'categories'))
119                 return '';
120
121         $saved = get_pconfig($a->profile['profile_uid'],'system','filetags');
122         if(! strlen($saved))
123                 return;
124
125         $matches = false;
126         $terms = array();
127         $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);
128         if($cnt) {
129                 foreach($matches as $mtch) {
130                         $unescaped = xmlify(file_tag_decode($mtch[1]));
131                         $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
132                 }
133         }
134
135         return replace_macros(get_markup_template('categories_widget.tpl'),array(
136                 '$title' => t('Categories'),
137                 '$desc' => '',
138                 '$sel_all' => (($selected == '') ? 'selected' : ''),
139                 '$all' => t('Everything'),
140                 '$terms' => $terms,
141                 '$base' => $baseurl,
142
143         ));
144 }
145
146 function common_friends_visitor_widget($profile_uid) {
147
148         $a = get_app();
149
150         if(local_user() == $profile_uid)
151                 return;
152
153         $cid = $zcid = 0;
154
155         if(is_array($_SESSION['remote'])) {
156                 foreach($_SESSION['remote'] as $visitor) {
157                         if($visitor['uid'] == $profile_uid) {
158                                 $cid = $visitor['cid'];
159                                 break;
160                         }
161                 }
162         }
163
164         if(! $cid) {
165                 if(get_my_url()) {
166                         $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
167                                 dbesc(normalise_link(get_my_url())),
168                                 intval($profile_uid)
169                         );
170                         if(count($r))
171                                 $cid = $r[0]['id'];
172                         else {
173                                 $r = q("select id from gcontact where nurl = '%s' limit 1",
174                                         dbesc(normalise_link(get_my_url()))
175                                 );
176                                 if(count($r))
177                                         $zcid = $r[0]['id'];
178                         }
179                 }
180         }
181
182         if($cid == 0 && $zcid == 0)
183                 return; 
184
185         require_once('include/socgraph.php');
186
187         if($cid)
188                 $t = count_common_friends($profile_uid,$cid);
189         else
190                 $t = count_common_friends_zcid($profile_uid,$zcid);
191         if(! $t)
192                 return;
193
194         if($cid)
195                 $r = common_friends($profile_uid,$cid,0,5,true);
196         else
197                 $r = common_friends_zcid($profile_uid,$zcid,0,5,true);
198
199         return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
200                 '$desc' =>  sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
201                 '$base' => $a->get_baseurl(),
202                 '$uid' => $profile_uid,
203                 '$cid' => (($cid) ? $cid : '0'),
204                 '$linkmore' => (($t > 5) ? 'true' : ''),
205                 '$more' => t('show more'),
206                 '$items' => $r
207         )); 
208
209 };