]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
eliminate dup identical hashtags in posts
[friendica.git] / mod / contacts.php
1 <?php
2
3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5
6 function contacts_init(&$a) {
7         if(! local_user())
8                 return;
9
10         $contact_id = 0;
11
12         if(($a->argc == 2) && intval($a->argv[1])) {
13                 $contact_id = intval($a->argv[1]);
14                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
15                         intval(local_user()),
16                         intval($contact_id)
17                 );
18                 if(! count($r)) {
19                         $contact_id = 0;
20                 }
21         }
22
23         require_once('include/group.php');
24         require_once('include/contact_widgets.php');
25
26         if(! x($a->page,'aside'))
27                 $a->page['aside'] = '';
28
29         if($contact_id) {
30                         $a->data['contact'] = $r[0];
31                         $o .= '<div class="vcard">';
32                         $o .= '<div class="fn">' . $a->data['contact']['name'] . '</div>';
33                         $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->data['contact']['photo'] . '" alt="' . $a->data['contact']['name'] . '" /></div>';
34                         $o .= '</div>';
35                         $a->page['aside'] .= $o;
36
37         }       
38         else
39                 $a->page['aside'] .= follow_widget();
40
41         $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
42
43         $a->page['aside'] .= findpeople_widget();
44
45 }
46
47 function contacts_post(&$a) {
48         
49         if(! local_user())
50                 return;
51
52         $contact_id = intval($a->argv[1]);
53         if(! $contact_id)
54                 return;
55
56         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
57                 intval($contact_id),
58                 intval(local_user())
59         );
60
61         if(! count($orig_record)) {
62                 notice( t('Could not access contact record.') . EOL);
63                 goaway($a->get_baseurl() . '/contacts');
64                 return; // NOTREACHED
65         }
66
67         call_hooks('contact_edit_post', $_POST);
68
69         $profile_id = intval($_POST['profile-assign']);
70         if($profile_id) {
71                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
72                         intval($profile_id),
73                         intval(local_user())
74                 );
75                 if(! count($r)) {
76                         notice( t('Could not locate selected profile.') . EOL);
77                         return;
78                 }
79         }
80
81         $hidden = intval($_POST['hidden']);
82
83         $priority = intval($_POST['poll']);
84         if($priority > 5 || $priority < 0)
85                 $priority = 0;
86
87         $info = escape_tags(trim($_POST['info']));
88
89         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
90                 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
91                 intval($profile_id),
92                 intval($priority),
93                 dbesc($info),
94                 intval($hidden),
95                 intval($contact_id),
96                 intval(local_user())
97         );
98         if($r)
99                 info( t('Contact updated.') . EOL);
100         else
101                 notice( t('Failed to update contact record.') . EOL);
102         return;
103
104 }
105
106
107
108 function contacts_content(&$a) {
109
110         $sort_type = 0;
111         $o = '';
112         nav_set_selected('contacts');
113
114         $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
115
116         if(! local_user()) {
117                 notice( t('Permission denied.') . EOL);
118                 return;
119         }
120
121         if($a->argc == 3) {
122
123                 $contact_id = intval($a->argv[1]);
124                 if(! $contact_id)
125                         return;
126
127                 $cmd = $a->argv[2];
128
129                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
130                         intval($contact_id),
131                         intval(local_user())
132                 );
133
134                 if(! count($orig_record)) {
135                         notice( t('Could not access contact record.') . EOL);
136                         goaway($a->get_baseurl() . '/contacts');
137                         return; // NOTREACHED
138                 }
139
140                 if($cmd === 'update') {
141
142                         // pull feed and consume it, which should subscribe to the hub.
143                         proc_run('php',"include/poller.php","$contact_id");
144                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
145                         // NOTREACHED
146                 }
147
148                 if($cmd === 'block') {
149                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
150                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
151                                 intval($blocked),
152                                 intval($contact_id),
153                                 intval(local_user())
154                         );
155                         if($r) {
156                                 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
157                                 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
158                         }
159                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
160                         return; // NOTREACHED
161                 }
162
163                 if($cmd === 'ignore') {
164                         $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
165                         $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
166                                 intval($readonly),
167                                 intval($contact_id),
168                                 intval(local_user())
169                         );
170                         if($r) {
171                                 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
172                         }
173                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
174                         return; // NOTREACHED
175                 }
176
177                 if($cmd === 'drop') {
178
179                         // create an unfollow slap
180
181                         if($orig_record[0]['network'] === NETWORK_OSTATUS) {
182                                 $tpl = get_markup_template('follow_slap.tpl');
183                                 $slap = replace_macros($tpl, array(
184                                         '$name' => $a->user['username'],
185                                         '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
186                                         '$photo' => $a->contact['photo'],
187                                         '$thumb' => $a->contact['thumb'],
188                                         '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
189                                         '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
190                                         '$title' => '',
191                                         '$type' => 'text',
192                                         '$content' => t('stopped following'),
193                                         '$nick' => $a->user['nickname'],
194                                         '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
195                                         '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
196                                 ));
197
198                                 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
199                                         require_once('include/salmon.php');
200                                         slapper($a->user,$orig_record[0]['notify'],$slap);
201                                 }
202                         }
203                         elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
204                                 require_once('include/diaspora.php');
205                                 diaspora_unshare($a->user,$orig_record[0]);
206                         }
207                         elseif($orig_record[0]['network'] === NETWORK_DFRN) {
208                                 require_once('include/items.php');
209                                 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
210                         }
211
212                         contact_remove($orig_record[0]['id']);
213                         info( t('Contact has been removed.') . EOL );
214                         goaway($a->get_baseurl() . '/contacts');
215                         return; // NOTREACHED
216                 }
217         }
218
219         if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
220
221                 $contact_id = $a->data['contact']['id'];
222                 $contact = $a->data['contact'];
223
224                 $tpl = get_markup_template('contact_head.tpl');
225                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
226
227                 require_once('include/contact_selectors.php');
228
229                 $tpl = get_markup_template("contact_edit.tpl");
230
231                 switch($contact['rel']) {
232                         case CONTACT_IS_FRIEND:
233                                 $dir_icon = 'images/lrarrow.gif';
234                                 $relation_text = t('You are mutual friends with %s');
235                                 break;
236                         case CONTACT_IS_FOLLOWER;
237                                 $dir_icon = 'images/larrow.gif';
238                                 $relation_text = t('You are sharing with %s');
239                                 break;
240         
241                         case CONTACT_IS_SHARING;
242                                 $dir_icon = 'images/rarrow.gif';
243                                 $relation_text = t('%s is sharing with you');
244                                 break;
245                         default:
246                                 break;
247                 }
248
249                 $relation_text = sprintf($relation_text,$contact['name']);
250
251                 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
252                         $url = "redir/{$contact['id']}";
253                         $sparkle = ' class="sparkle" ';
254                 }
255                 else { 
256                         $url = $contact['url'];
257                         $sparkle = '';
258                 }
259
260                 $insecure = t('Private communications are not available for this contact.');
261
262                 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00') 
263                                 ? t('Never') 
264                                 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
265
266                 if($contact['last-update'] !== '0000-00-00 00:00:00')
267                         $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
268
269                 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
270
271                 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
272
273                 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
274
275                 $common = count_common_friends(local_user(),$contact['id']);
276                 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
277
278                 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : ''); 
279
280                 $x = count_all_friends(local_user(), $contact['id']);
281                 $all_friends = (($x) ? t('View all contacts') : '');
282
283                 // tabs
284                 $tabs = array(
285                         array(
286                                 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
287                                 'url'   => $a->get_baseurl() . '/contacts/' . $contact_id . '/block',
288                                 'sel'   => '',
289                         ),
290                         array(
291                                 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
292                                 'url'   => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore',
293                                 'sel'   => '',
294                         ),
295                         array(
296                                 'label' => t('Repair'),
297                                 'url'   => $a->get_baseurl() . '/crepair/' . $contact_id,
298                                 'sel'   => '',
299                         )
300                 );
301                 $tab_tpl = get_markup_template('common_tabs.tpl');
302                 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
303
304
305                 $o .= replace_macros($tpl,array(
306                         '$header' => t('Contact Editor'),
307                         '$tab_str' => $tab_str,
308                         '$submit' => t('Submit'),
309                         '$lbl_vis1' => t('Profile Visibility'),
310                         '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
311                         '$lbl_info1' => t('Contact Information / Notes'),
312                         '$infedit' => t('Edit contact notes'),
313                         '$common_text' => $common_text,
314                         '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'],
315                         '$all_friends' => $all_friends,
316                         '$relation_text' => $relation_text,
317                         '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
318                         '$blockunblock' => t('Block/Unblock contact'),
319                         '$ignorecont' => t('Ignore contact'),
320                         '$lblcrepair' => t("Repair URL settings"),
321                         '$lblrecent' => t('View conversations'),
322                         '$lblsuggest' => $lblsuggest,
323                         '$delete' => t('Delete contact'),
324                         '$nettype' => $nettype,
325                         '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
326                         '$poll_enabled' => $poll_enabled,
327                         '$lastupdtext' => t('Last update:'),
328                         '$updpub' => t('Update public posts'),
329                         '$last_update' => $last_update,
330                         '$udnow' => t('Update now'),
331                         '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
332                         '$contact_id' => $contact['id'],
333                         '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
334                         '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
335                         '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
336                         '$info' => $contact['info'],
337                         '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
338                         '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
339                         '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
340                         '$photo' => $contact['photo'],
341                         '$name' => $contact['name'],
342                         '$dir_icon' => $dir_icon,
343                         '$alt_text' => $alt_text,
344                         '$sparkle' => $sparkle,
345                         '$url' => $url
346
347                 ));
348
349                 $arr = array('contact' => $contact,'output' => $o);
350
351                 call_hooks('contact_edit', $arr);
352
353                 return $arr['output'];
354
355         }
356
357
358         if(($a->argc == 2) && ($a->argv[1] === 'all'))
359                 $sql_extra = '';
360         else
361                 $sql_extra = " AND `blocked` = 0 ";
362
363         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
364
365         $tpl = get_markup_template("contacts-top.tpl");
366         $o .= replace_macros($tpl,array(
367                 '$header' => t('Contacts'),
368                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
369                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
370                 '$search' => $search,
371                 '$desc' => t('Search your contacts'),
372                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
373                 '$submit' => t('Find'),
374                 '$cmd' => $a->cmd
375
376
377         )); 
378
379         if($search)
380                 $search = dbesc($search.'*');
381         $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
382
383         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); 
384
385         
386         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
387                 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
388                 intval($_SESSION['uid']));
389         if(count($r))
390                 $a->set_pager_total($r[0]['total']);
391
392         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
393                 intval($_SESSION['uid']),
394                 intval($a->pager['start']),
395                 intval($a->pager['itemspage'])
396         );
397
398         if(count($r)) {
399
400                 $tpl = get_markup_template("contact_template.tpl");
401
402                 foreach($r as $rr) {
403                         if($rr['self'])
404                                 continue;
405
406                         switch($rr['rel']) {
407                                 case CONTACT_IS_FRIEND:
408                                         $dir_icon = 'images/lrarrow.gif';
409                                         $alt_text = t('Mutual Friendship');
410                                         break;
411                                 case  CONTACT_IS_FOLLOWER;
412                                         $dir_icon = 'images/larrow.gif';
413                                         $alt_text = t('is a fan of yours');
414                                         break;
415                                 case CONTACT_IS_SHARING;
416                                         $dir_icon = 'images/rarrow.gif';
417                                         $alt_text = t('you are a fan of');
418                                         break;
419                                 default:
420                                         break;
421                         }
422                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
423                                 $url = "redir/{$rr['id']}";
424                                 $sparkle = ' class="sparkle" ';
425                         }
426                         else { 
427                                 $url = $rr['url'];
428                                 $sparkle = '';
429                         }
430
431
432                         $o .= replace_macros($tpl, array(
433                                 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
434                                 '$edit_hover' => t('Edit contact'),
435                                 '$contact_photo_menu' => contact_photo_menu($rr),
436                                 '$id' => $rr['id'],
437                                 '$alt_text' => $alt_text,
438                                 '$dir_icon' => $dir_icon,
439                                 '$thumb' => $rr['thumb'], 
440                                 '$name' => $rr['name'],
441                                 '$username' => $rr['name'],
442                                 '$sparkle' => $sparkle,
443                                 '$url' => $url
444                         ));
445                 }
446
447                 $o .= '<div id="contact-edit-end"></div>';
448
449         }
450         $o .= paginate($a);
451         return $o;
452 }