]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
if no FB image and fb link is on our site, use Friendika logo for fb image. Otherwise...
[friendica.git] / mod / contacts.php
1 <?php
2
3 require_once('include/Contact.php');
4
5 function contacts_init(&$a) {
6         require_once('include/group.php');
7         if(! x($a->page,'aside'))
8                 $a->page['aside'] = '';
9         $a->page['aside'] .= group_side();
10
11         if($a->config['register_policy'] != REGISTER_CLOSED)
12                 $a->page['aside'] .= '<div class="side-link" id="side-invite-link" ><a href="invite" >' . t("Invite Friends") . '</a></div>';
13
14         if(strlen(get_config('system','directory_submit_url')))
15                 $a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >' . t('Find People With Shared Interests') . '</a></div>';
16
17         $tpl = get_markup_template('follow.tpl');
18         $a->page['aside'] .= replace_macros($tpl,array(
19                 '$label' => t('Connect/Follow'),
20                 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
21                 '$follow' => t('Follow')
22         ));
23
24
25
26 }
27
28 function contacts_post(&$a) {
29         
30         if(! local_user())
31                 return;
32
33         $contact_id = intval($a->argv[1]);
34         if(! $contact_id)
35                 return;
36
37         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
38                 intval($contact_id),
39                 intval(local_user())
40         );
41
42         if(! count($orig_record)) {
43                 notice( t('Could not access contact record.') . EOL);
44                 goaway($a->get_baseurl() . '/contacts');
45                 return; // NOTREACHED
46         }
47
48         call_hooks('contact_edit_post', $_POST);
49
50         $profile_id = intval($_POST['profile-assign']);
51         if($profile_id) {
52                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
53                         intval($profile_id),
54                         intval(local_user())
55                 );
56                 if(! count($r)) {
57                         notice( t('Could not locate selected profile.') . EOL);
58                         return;
59                 }
60         }
61 logger('contact_edit ' . print_r($_POST,true));
62
63         $priority = intval($_POST['poll']);
64         if($priority == (-1))
65                 
66         if($priority > 5 || $priority < 0)
67                 $priority = 0;
68
69         $rating = intval($_POST['reputation']);
70         if($rating > 5 || $rating < 0)
71                 $rating = 0;
72
73         $reason = notags(trim($_POST['reason']));
74
75         $info = escape_tags(trim($_POST['info']));
76
77         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
78                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
79                 intval($profile_id),
80                 intval($priority),
81                 intval($rating),
82                 dbesc($reason),
83                 dbesc($info),
84                 intval($contact_id),
85                 intval(local_user())
86         );
87         if($r)
88                 notice( t('Contact updated.') . EOL);
89         else
90                 notice( t('Failed to update contact record.') . EOL);
91         return;
92
93 }
94
95
96
97 function contacts_content(&$a) {
98
99         $sort_type = 0;
100         $o = '';
101         $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
102
103         $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
104
105         if(! local_user()) {
106                 notice( t('Permission denied.') . EOL);
107                 return;
108         }
109
110         if($a->argc == 3) {
111
112                 $contact_id = intval($a->argv[1]);
113                 if(! $contact_id)
114                         return;
115
116                 $cmd = $a->argv[2];
117
118                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
119                         intval($contact_id),
120                         intval(local_user())
121                 );
122
123                 if(! count($orig_record)) {
124                         notice( t('Could not access contact record.') . EOL);
125                         goaway($a->get_baseurl() . '/contacts');
126                         return; // NOTREACHED
127                 }
128
129                 if($cmd === 'update') {
130
131                         // pull feed and consume it, which should subscribe to the hub.
132                         proc_run('php',"include/poller.php","$contact_id");
133                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
134                         // NOTREACHED
135                 }
136
137                 if($cmd === 'block') {
138                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
139                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
140                                         intval($blocked),
141                                         intval($contact_id),
142                                         intval(local_user())
143                         );
144                         if($r) {
145                                 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
146                                 notice( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
147                         }
148                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
149                         return; // NOTREACHED
150                 }
151
152                 if($cmd === 'ignore') {
153                         $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
154                         $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
155                                         intval($readonly),
156                                         intval($contact_id),
157                                         intval(local_user())
158                         );
159                         if($r) {
160                                 notice( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
161                         }
162                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
163                         return; // NOTREACHED
164                 }
165
166                 if($cmd === 'drop') {
167
168                         // create an unfollow slap
169
170                         if($orig_record[0]['network'] === 'stat') {
171                                 $tpl = get_markup_template('follow_slap.tpl');
172                                 $slap = replace_macros($tpl, array(
173                                         '$name' => $a->user['username'],
174                                         '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
175                                         '$photo' => $a->contact['photo'],
176                                         '$thumb' => $a->contact['thumb'],
177                                         '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
178                                         '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
179                                         '$title' => '',
180                                         '$type' => 'text',
181                                         '$content' => t('stopped following'),
182                                         '$nick' => $a->user['nickname'],
183                                         '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
184                                         '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
185                                 ));
186
187                                 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
188                                         require_once('include/salmon.php');
189                                         slapper($a->user,$orig_record[0]['notify'],$slap);
190                                 }
191                         }
192
193                         if($orig_record[0]['network'] === 'dfrn') {
194                                 require_once('include/items.php');
195                                 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
196                         }
197
198
199                         contact_remove($contact_id);
200                         notice( t('Contact has been removed.') . EOL );
201                         goaway($a->get_baseurl() . '/contacts');
202                         return; // NOTREACHED
203                 }
204         }
205
206         if(($a->argc == 2) && intval($a->argv[1])) {
207
208                 $contact_id = intval($a->argv[1]);
209                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
210                         intval(local_user()),
211                         intval($contact_id)
212                 );
213                 if(! count($r)) {
214                         notice( t('Contact not found.') . EOL);
215                         return;
216                 }
217
218                 $tpl = get_markup_template('contact_head.tpl');
219                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
220
221                 require_once('include/contact_selectors.php');
222
223                 $tpl = get_markup_template("contact_edit.tpl");
224
225                 switch($r[0]['rel']) {
226                         case REL_BUD:
227                                 $dir_icon = 'images/lrarrow.gif';
228                                 $alt_text = t('Mutual Friendship');
229                                 break;
230                         case REL_VIP;
231                                 $dir_icon = 'images/larrow.gif';
232                                 $alt_text = t('is a fan of yours');
233                                 break;
234         
235                         case REL_FAN;
236                                 $dir_icon = 'images/rarrow.gif';
237                                 $alt_text = t('you are a fan of');
238                                 break;
239                         default:
240                                 break;
241                 }
242
243                 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
244                         $url = "redir/{$r[0]['id']}";
245                         $sparkle = ' class="sparkle" ';
246                 }
247                 else { 
248                         $url = $r[0]['url'];
249                         $sparkle = '';
250                 }
251
252                 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" />&nbsp;'
253                         . t('Private communications are not available for this contact.') . '</p></div>';
254
255                 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00') 
256                                 ? t('Never') 
257                                 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
258
259                 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
260                         $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
261
262                 $o .= replace_macros($tpl,array(
263                         '$header' => t('Contact Editor'),
264                         '$submit' => t('Submit'),
265                         '$lbl_vis1' => t('Profile Visibility'),
266                         '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
267                         '$lbl_info1' => t('Contact Information / Notes'),
268                         '$lbl_rep1' => t('Online Reputation'),
269                         '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
270                         '$lbl_rep3' => t('You may help them choose whether or not to interact with this person by providing a <em>reputation</em> to guide them.'),
271                         '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
272                         '$visit' => t('Visit $name\'s profile'),
273                         '$blockunblock' => t('Block/Unblock contact'),
274                         '$ignorecont' => t('Ignore contact'),
275                         '$altcrepair' => t('Repair contact URL settings'),
276                         '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
277                         '$lblrecent' => t('View conversations'),
278                         '$delete' => t('Delete contact'),
279                         '$poll_interval' => contact_poll_interval($r[0]['priority']),
280                         '$lastupdtext' => t('Last updated: '),
281                         '$updpub' => t('Update public posts: '),
282                         '$last_update' => $last_update,
283                         '$udnow' => t('Update now'),
284                         '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
285                         '$contact_id' => $r[0]['id'],
286                         '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
287                         '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
288                         '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK) ? $insecure : ''),
289                         '$info' => $r[0]['info'],
290                         '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
291                         '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
292                         '$rating' => contact_reputation($r[0]['rating']),
293                         '$reason' => $r[0]['reason'],
294                         '$groups' => '', // group_selector(),
295                         '$photo' => $r[0]['photo'],
296                         '$name' => $r[0]['name'],
297                         '$dir_icon' => $dir_icon,
298                         '$alt_text' => $alt_text,
299                         '$sparkle' => $sparkle,
300                         '$url' => $url
301
302                 ));
303
304                 $arr = array('contact' => $r[0],'output' => $o);
305
306                 call_hooks('contact_edit', $arr);
307
308                 return $arr['output'];
309
310         }
311
312
313         if(($a->argc == 2) && ($a->argv[1] === 'all'))
314                 $sql_extra = '';
315         else
316                 $sql_extra = " AND `blocked` = 0 ";
317
318         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
319
320         $tpl = get_markup_template("contacts-top.tpl");
321         $o .= replace_macros($tpl,array(
322                 '$header' => t('Contacts'),
323                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
324                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
325                 '$search' => $search,
326                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
327                 '$submit' => t('Find'),
328                 '$cmd' => $a->cmd
329
330
331         )); 
332
333         if($search)
334                 $search = dbesc($search.'*');
335         $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
336
337         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); 
338
339         
340         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
341                 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
342                 intval($_SESSION['uid']));
343         if(count($r))
344                 $a->set_pager_total($r[0]['total']);
345
346         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
347                 intval($_SESSION['uid']),
348                 intval($a->pager['start']),
349                 intval($a->pager['itemspage'])
350         );
351
352         if(count($r)) {
353
354                 $tpl = get_markup_template("contact_template.tpl");
355
356                 foreach($r as $rr) {
357                         if($rr['self'])
358                                 continue;
359
360                         switch($rr['rel']) {
361                                 case REL_BUD:
362                                         $dir_icon = 'images/lrarrow.gif';
363                                         $alt_text = t('Mutual Friendship');
364                                         break;
365                                 case  REL_VIP;
366                                         $dir_icon = 'images/larrow.gif';
367                                         $alt_text = t('is a fan of yours');
368                                         break;
369                                 case REL_FAN;
370                                         $dir_icon = 'images/rarrow.gif';
371                                         $alt_text = t('you are a fan of');
372                                         break;
373                                 default:
374                                         break;
375                         }
376                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
377                                 $url = "redir/{$rr['id']}";
378                                 $sparkle = ' class="sparkle" ';
379                         }
380                         else { 
381                                 $url = $rr['url'];
382                                 $sparkle = '';
383                         }
384
385
386                         $o .= replace_macros($tpl, array(
387                                 '$img_hover' => t('Visit $username\'s profile'),
388                                 '$edit_hover' => t('Edit contact'),
389                                 '$id' => $rr['id'],
390                                 '$alt_text' => $alt_text,
391                                 '$dir_icon' => $dir_icon,
392                                 '$thumb' => $rr['thumb'], 
393                                 '$name' => substr($rr['name'],0,20),
394                                 '$username' => $rr['name'],
395                                 '$sparkle' => $sparkle,
396                                 '$url' => $url
397                         ));
398                 }
399
400                 $o .= '<div id="contact-edit-end"></div>';
401
402         }
403         $o .= paginate($a);
404         return $o;
405 }