]> git.mxchange.org Git - friendica.git/blob - include/contact_widgets.php
Merge pull request #1028 from tugelbend/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         if(! feature_enabled(local_user(),'networks'))
51                 return '';
52
53         $r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND `self` = 0 ORDER BY `network`",
54                 intval(local_user())
55         );
56
57         $nets = array();
58         if(count($r)) {
59                 require_once('include/contact_selectors.php');
60                 foreach($r as $rr) {
61                                 if($rr['network'])
62                                         $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
63                 }
64         }
65
66         if(count($nets) < 2)
67                 return '';
68
69         return replace_macros(get_markup_template('nets.tpl'),array(
70                 '$title' => t('Networks'),
71                 '$desc' => '',
72                 '$sel_all' => (($selected == '') ? 'selected' : ''),
73                 '$all' => t('All Networks'),
74                 '$nets' => $nets,
75                 '$base' => $baseurl,
76
77         ));
78 }
79
80 function fileas_widget($baseurl,$selected = '') {
81         $a = get_app();
82         if(! local_user())
83                 return '';
84
85         if(! feature_enabled(local_user(),'filing'))
86                 return '';
87
88         $saved = get_pconfig(local_user(),'system','filetags');
89         if(! strlen($saved))
90                 return;
91
92         $matches = false;
93         $terms = array();
94     $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER);
95     if($cnt) {
96                 foreach($matches as $mtch) {
97                         $unescaped = xmlify(file_tag_decode($mtch[1]));
98                         $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
99                 }
100         }
101
102         return replace_macros(get_markup_template('fileas_widget.tpl'),array(
103                 '$title' => t('Saved Folders'),
104                 '$desc' => '',
105                 '$sel_all' => (($selected == '') ? 'selected' : ''),
106                 '$all' => t('Everything'),
107                 '$terms' => $terms,
108                 '$base' => $baseurl,
109
110         ));
111 }
112
113 function categories_widget($baseurl,$selected = '') {
114
115         $a = get_app();
116
117         if(! feature_enabled($a->profile['profile_uid'],'categories'))
118                 return '';
119
120         $saved = get_pconfig($a->profile['profile_uid'],'system','filetags');
121         if(! strlen($saved))
122                 return;
123
124         $matches = false;
125         $terms = array();
126         $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);
127         if($cnt) {
128                 foreach($matches as $mtch) {
129                         $unescaped = xmlify(file_tag_decode($mtch[1]));
130                         $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
131                 }
132         }
133
134         return replace_macros(get_markup_template('categories_widget.tpl'),array(
135                 '$title' => t('Categories'),
136                 '$desc' => '',
137                 '$sel_all' => (($selected == '') ? 'selected' : ''),
138                 '$all' => t('Everything'),
139                 '$terms' => $terms,
140                 '$base' => $baseurl,
141
142         ));
143 }
144
145 function common_friends_visitor_widget($profile_uid) {
146
147         $a = get_app();
148
149         if(local_user() == $profile_uid)
150                 return;
151
152         $cid = $zcid = 0;
153
154         if(is_array($_SESSION['remote'])) {
155                 foreach($_SESSION['remote'] as $visitor) {
156                         if($visitor['uid'] == $profile_uid) {
157                                 $cid = $visitor['cid'];
158                                 break;
159                         }
160                 }
161         }
162
163         if(! $cid) {
164                 if(get_my_url()) {
165                         $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
166                                 dbesc(normalise_link(get_my_url())),
167                                 intval($profile_uid)
168                         );
169                         if(count($r))
170                                 $cid = $r[0]['id'];
171                         else {
172                                 $r = q("select id from gcontact where nurl = '%s' limit 1",
173                                         dbesc(normalise_link(get_my_url()))
174                                 );
175                                 if(count($r))
176                                         $zcid = $r[0]['id'];
177                         }
178                 }
179         }
180
181         if($cid == 0 && $zcid == 0)
182                 return; 
183
184         require_once('include/socgraph.php');
185
186         if($cid)
187                 $t = count_common_friends($profile_uid,$cid);
188         else
189                 $t = count_common_friends_zcid($profile_uid,$zcid);
190         if(! $t)
191                 return;
192
193         if($cid)
194                 $r = common_friends($profile_uid,$cid,0,5,true);
195         else
196                 $r = common_friends_zcid($profile_uid,$zcid,0,5,true);
197
198         return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
199                 '$desc' =>  sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
200                 '$base' => $a->get_baseurl(),
201                 '$uid' => $profile_uid,
202                 '$cid' => (($cid) ? $cid : '0'),
203                 '$linkmore' => (($t > 5) ? 'true' : ''),
204                 '$more' => t('show more'),
205                 '$items' => $r
206         )); 
207
208 };