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