]> git.mxchange.org Git - friendica.git/blob - include/conversation.php
Merge branch 'master' of git://github.com/friendika/friendika
[friendica.git] / include / conversation.php
1 <?php
2
3 /**
4  * Render actions localized
5  */
6 function localize_item(&$item){
7         
8         if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
9
10                 $r = q("SELECT * from `item`,`contact` WHERE 
11                                 `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
12                                  dbesc($item['parent-uri']));
13                 if(count($r)==0) return;
14                 $obj=$r[0];
15                 
16                 $author  = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
17                 $objauthor =  '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
18                 
19                 switch($obj['verb']){
20                         case ACTIVITY_POST:
21                                 switch ($obj['object-type']){
22                                         case ACTIVITY_OBJ_EVENT:
23                                                 $post_type = t('event');
24                                                 break;
25                                         default:
26                                                 $post_type = t('status');
27                                 }
28                                 break;
29                         default:
30                                 if($obj['resource-id']){
31                                         $post_type = t('photo');
32                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
33                                         $rr['plink'] = $m[1];
34                                 } else {
35                                         $post_type = t('status');
36                                 }
37                 }
38         
39                 $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
40                 
41                 switch($item['verb']){
42                         case ACTIVITY_LIKE :
43                                 $bodyverb = t('%1$s likes %2$s\'s %3$s');
44                                 break;
45                         case ACTIVITY_DISLIKE:
46                                 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
47                                 break;
48                 }
49                 $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
50                         
51         }
52         if ($item['verb']=== ACTIVITY_FRIEND){
53
54                 if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
55
56                 $Aname = $item['author-name'];
57                 $Alink = $item['author-link'];
58                 
59                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
60                 
61                 $obj = parse_xml_string($xmlhead.$item['object']);
62                 $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
63                 
64                 $Bname = $obj->title;
65                 $Blink = ""; $Bphoto = "";
66                 foreach ($links->link as $l){
67                         $atts = $l->attributes();
68                         switch($atts['rel']){
69                                 case "alternate": $Blink = $atts['href'];
70                                 case "photo": $Bphoto = $atts['href'];
71                         }
72                         
73                 }
74                 
75                 $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
76                 $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
77                 if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
78
79                 $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
80
81         }
82         
83 }
84
85 /**
86  * "Render" a conversation or list of items for HTML display.
87  * There are two major forms of display:
88  *      - Sequential or unthreaded ("New Item View" or search results)
89  *      - conversation view
90  * The $mode parameter decides between the various renderings and also
91  * figures out how to determine page owner and other contextual items 
92  * that are based on unique features of the calling module.
93  *
94  */
95 function conversation(&$a, $items, $mode, $update) {
96
97         require_once('bbcode.php');
98
99         $profile_owner = 0;
100         $page_writeable      = false;
101
102         if($mode === 'network') {
103                 $profile_owner = local_user();
104                 $page_writeable = true;
105         }
106
107         if($mode === 'profile') {
108                 $profile_owner = $a->profile['profile_uid'];
109                 $page_writeable = can_write_wall($a,$profile_owner);
110         }
111
112         if($mode === 'notes') {
113                 $profile_owner = $a->profile['profile_uid'];
114                 $page_writeable = true;
115         }
116
117         if($mode === 'display') {
118                 $profile_owner = $a->profile['uid'];
119                 $page_writeable = can_write_wall($a,$profile_owner);
120         }
121
122         if($mode === 'community') {
123                 $profile_owner = 0;
124                 $page_writeable = false;
125         }
126
127         if($update)
128                 $return_url = $_SESSION['return_url'];
129         else
130                 $return_url = $_SESSION['return_url'] = $a->cmd;
131
132         load_contact_links(local_user());
133
134
135         $cmnt_tpl    = get_markup_template('comment_item.tpl');
136         $like_tpl    = get_markup_template('like.tpl');
137         $noshare_tpl = get_markup_template('like_noshare.tpl');
138         $tpl         = get_markup_template('wall_item.tpl');
139         $wallwall    = get_markup_template('wallwall_item.tpl');
140         $droptpl     = get_markup_template('wall_item_drop.tpl');
141         $fakedrop    = get_markup_template('wall_fake_drop.tpl');
142
143         $alike = array();
144         $dlike = array();
145         
146         if(count($items)) {
147
148                 if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
149
150                         // "New Item View" on network page or search page results 
151                         // - just loop through the items and format them minimally for display
152
153                         $tpl = get_markup_template('search_item.tpl');
154
155                         foreach($items as $item) {
156
157                                 $comment     = '';
158                                 $owner_url   = '';
159                                 $owner_photo = '';
160                                 $owner_name  = '';
161                                 $sparkle     = '';
162
163                                 if($mode === 'search' || $mode === 'community') {
164                                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
165                                                 && ($item['id'] != $item['parent']))
166                                                 continue;
167                                         $nickname = $item['nickname'];
168                                 }
169                                 else
170                                         $nickname = $a->user['nickname'];
171                         
172                                 $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
173
174                                 $sp = false;
175                                 $profile_link = best_link_url($item,$sp);
176                                 if($sp)
177                                         $sparkle = ' sparkle';
178                                 if($profile_link === 'mailbox')
179                                         $profile_link = '';
180
181
182                                 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
183                                 if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
184                                         $profile_avatar = $a->contacts[$normalised]['thumb'];
185                                 else
186                                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
187
188                                 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
189                                 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
190                                 if($coord) {
191                                         if($location)
192                                                 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
193                                         else
194                                                 $location = '<span class="smalltext">' . $coord . '</span>';
195                                 }
196
197                                 $drop = '';
198
199                                 localize_item($item);
200                                 if($mode === 'network-new')
201                                         $t = $droptpl;
202                                 else
203                                         $t = $fakedrop;
204
205                                 $drop = replace_macros($t,array('$id' => $item['id']));
206                                 $lock = '<div class="wall-item-lock"></div>';
207                                 $star = '';
208
209                                 $body = prepare_body($item,true);
210                                 
211                                 $o .= replace_macros($tpl,array(
212                                         '$id' => $item['item_id'],
213                                         '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
214                                         '$profile_url' => $profile_link,
215                                         '$item_photo_menu' => item_photo_menu($item),
216                                         '$name' => $profile_name,
217                                         '$sparkle' => $sparkle,
218                                         '$lock' => $lock,
219                                         '$thumb' => $profile_avatar,
220                                         '$title' => $item['title'],
221                                         '$body' => $body,
222                                         '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
223                                         '$location' => $location,
224                                         '$indent' => '',
225                                         '$owner_url' => $owner_url,
226                                         '$owner_photo' => $owner_photo,
227                                         '$owner_name' => $owner_name,
228                                         '$star' => $star,
229                                         '$drop' => $drop,
230                                         '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
231                                 ));
232
233                         }
234
235                         return $o;
236                 }
237
238
239
240
241                 // Normal View
242
243
244                 // Figure out how many comments each parent has
245                 // (Comments all have gravity of 6)
246                 // Store the result in the $comments array
247
248                 $comments = array();
249                 foreach($items as $item) {
250                         if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
251                                 if(! x($comments,$item['parent']))
252                                         $comments[$item['parent']] = 1;
253                                 else
254                                         $comments[$item['parent']] += 1;
255                         }
256                 }
257
258                 // map all the like/dislike activities for each parent item 
259                 // Store these in the $alike and $dlike arrays
260
261                 foreach($items as $item) {
262                         like_puller($a,$item,$alike,'like');
263                         like_puller($a,$item,$dlike,'dislike');
264                 }
265
266                 $comments_collapsed = false;
267                 $blowhard = 0;
268                 $blowhard_count = 0;
269
270                 foreach($items as $item) {
271
272                         $comment = '';
273                         $template = $tpl;
274                         $commentww = '';
275                         $sparkle = '';
276                         $owner_url = $owner_photo = $owner_name = '';
277
278                         // We've already parsed out like/dislike for special treatment. We can ignore them now
279
280                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) 
281                                 || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
282                                 && ($item['id'] != $item['parent']))
283                                 continue;
284
285                         $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
286
287
288                         // Take care of author collapsing and comment collapsing
289                         // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
290                         // If there are more than two comments, squash all but the last 2.
291
292                         if($toplevelpost) {
293
294                                 $item_writeable = (($item['writable'] || $item['self']) ? true : false);
295
296                                 if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
297                                         $blowhard_count ++;
298                                         if($blowhard_count == 3) {
299                                                 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] 
300                                                         . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >' 
301                                                         . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-' 
302                                                         . $item['parent'] . '" style="display: none;" >';
303                                         }
304                                 }
305                                 else {
306                                         $blowhard = $item['cid'];                                       
307                                         if($blowhard_count >= 3)
308                                                 $o .= '</div>';
309                                         $blowhard_count = 0;
310                                 }
311
312                                 $comments_seen = 0;
313                                 $comments_collapsed = false;
314                         }
315                         else
316                                 $comments_seen ++;
317
318
319                         $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
320                         $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
321
322                         if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
323                                 if(! $comments_collapsed) {
324                                         $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] 
325                                                 . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >' 
326                                                 . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
327                                                 . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
328                                         $comments_collapsed = true;
329                                 }
330                         }
331                         if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
332                                 $o .= '</div>';
333                         }
334
335                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
336
337                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
338                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
339                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
340                                 : '<div class="wall-item-lock"></div>');
341
342
343                         // Top-level wall post not written by the wall owner (wall-to-wall)
344                         // First figure out who owns it. 
345
346                         $osparkle = '';
347
348                         if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
349
350                                 if($item['type'] === 'wall') {
351
352                                         // On the network page, I am the owner. On the display page it will be the profile owner.
353                                         // This will have been stored in $a->page_contact by our calling page.
354                                         // Put this person on the left of the wall-to-wall notice.
355
356                                         $owner_url = $a->page_contact['url'];
357                                         $owner_photo = $a->page_contact['thumb'];
358                                         $owner_name = $a->page_contact['name'];
359                                         $template = $wallwall;
360                                         $commentww = 'ww';      
361                                 }
362                                 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
363
364                                         // Could be anybody. 
365
366                                         $owner_url = $item['owner-link'];
367                                         $owner_photo = $item['owner-avatar'];
368                                         $owner_name = $item['owner-name'];
369                                         $template = $wallwall;
370                                         $commentww = 'ww';
371                                         // If it is our contact, use a friendly redirect link
372                                         if((link_compare($item['owner-link'],$item['url'])) 
373                                                 && ($item['network'] === 'dfrn')) {
374                                                 $owner_url = $redirect_url;
375                                                 $osparkle = ' sparkle';
376                                         }
377                                 }
378                         }
379
380
381                         $likebuttons = '';
382
383                         if($page_writeable) {
384                                 if($toplevelpost) {
385                                         $likebuttons = replace_macros((($item['private'] || ($profile_owner != local_user())) ? $noshare_tpl : $like_tpl),array(
386                                                 '$id' => $item['id'],
387                                                 '$likethis' => t("I like this \x28toggle\x29"),
388                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
389                                                 '$share' => t('Share'),
390                                                 '$wait' => t('Please wait') 
391                                         ));
392                                 }
393
394                                 if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
395                                         $comment = replace_macros($cmnt_tpl,array(
396                                                 '$return_path' => '', 
397                                                 '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
398                                                 '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
399                                                 '$id' => $item['item_id'],
400                                                 '$parent' => $item['parent'],
401                                                 '$profile_uid' =>  $profile_owner,
402                                                 '$mylink' => $a->contact['url'],
403                                                 '$mytitle' => t('This is you'),
404                                                 '$myphoto' => $a->contact['thumb'],
405                                                 '$comment' => t('Comment'),
406                                                 '$submit' => t('Submit'),
407                                                 '$ww' => (($mode === 'network') ? $commentww : '')
408                                         ));
409                                 }
410                         }
411
412                         $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
413                                         ? '<a class="editpost icon pencil" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] 
414                                                 . '" title="' . t('Edit') . '"></a>'
415                                         : '');
416
417
418                         $drop = '';
419                         $dropping = false;
420
421                         if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
422                                 $dropping = true;
423
424             $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$select' => t('Select'), '$delete' => t('Delete')));
425
426                         $star = (($profile_owner == local_user() && $toplevelpost) ? '<a href="#" id="starred-' . $item['id'] . '" onclick="dostar(' . $item['id'] . '); return false;" class="star-item icon ' . (($item['starred']) ? 'starred' : 'unstarred') . '" title="' . t('toggle star status')  . '"></a>' : '');
427
428
429                         $photo = $item['photo'];
430                         $thumb = $item['thumb'];
431
432                         // Post was remotely authored.
433
434                         $diff_author    = ((link_compare($item['url'],$item['author-link'])) ? false : true);
435
436                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
437
438                         $sp = false;
439                         $profile_link = best_link_url($item,$sp);
440                         if($sp)
441                                 $sparkle = ' sparkle';
442
443                         if($profile_link === 'mailbox')
444                                 $profile_link = '';
445
446                         $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
447                         if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
448                                 $profile_avatar = $a->contacts[$normalised]['thumb'];
449                         else
450                                 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
451
452
453
454
455
456                         $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
457                         $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
458
459                         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] 
460                                 . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
461                         $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] 
462                                 . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
463                         if($coord) {
464                                 if($location)
465                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
466                                 else
467                                         $location = '<span class="smalltext">' . $coord . '</span>';
468                         }
469
470                         $indent = (($toplevelpost) ? '' : ' comment');
471
472                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
473                                 $indent .= ' shiny'; 
474
475                         // 
476                         localize_item($item);
477
478                         // Build the HTML
479
480                         $body = prepare_body($item,true);
481
482
483                         $tmp_item = replace_macros($template,array(
484                                 '$id' => $item['item_id'],
485                                 '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
486                                 '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
487                                 '$to' => t('to'),
488                                 '$wall' => t('Wall-to-Wall'),
489                                 '$vwall' => t('via Wall-To-Wall:'),
490                                 '$profile_url' => $profile_link,
491                                 '$item_photo_menu' => item_photo_menu($item),
492                                 '$name' => $profile_name,
493                                 '$thumb' => $profile_avatar,
494                                 '$osparkle' => $osparkle,
495                                 '$sparkle' => $sparkle,
496                                 '$title' => $item['title'],
497                                 '$body' => $body,
498                                 '$ago' => ((($item['app']) && ($item['id'] == $item['parent'])) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
499                                 '$lock' => $lock,
500                                 '$location' => $location,
501                                 '$indent' => $indent,
502                                 '$owner_url' => $owner_url,
503                                 '$owner_photo' => $owner_photo,
504                                 '$owner_name' => $owner_name,
505                                 '$plink' => get_plink($item),
506                                 '$edpost' => $edpost,
507                                 '$star' => $star,
508                                 '$drop' => $drop,
509                                 '$vote' => $likebuttons,
510                                 '$like' => $like,
511                                 '$dislike' => $dislike,
512                                 '$comment' => $comment
513                         ));
514
515
516                         $arr = array('item' => $item, 'output' => $tmp_item);
517                         call_hooks('display_item', $arr);
518
519                         $o .= $arr['output'];
520
521                 }
522         }
523
524
525         // if author collapsing is in force but didn't get closed, close it off now.
526
527         if($blowhard_count >= 3)
528                 $o .= '</div>';
529
530         if($dropping)
531                 $o .= '<div id="item-delete-selected" class="fakelink" onclick="deleteCheckedItems();"><div id="item-delete-selected-icon" class="icon drophide" title="' . t('Delete Selected Items') . '" onmouseover="imgbright(this);" onmouseout="imgdull(this);" ></div><div id="item-delete-selected-desc" >' .  t('Delete Selected Items') . '</div></div><div id="item-delete-selected-end"></div>';
532
533         return $o;
534
535
536
537 if(! function_exists('load_contact_links')) {
538 function load_contact_links($uid) {
539
540         $a = get_app();
541
542         $ret = array();
543
544         if(! $uid || x($a->contacts,'empty'))
545                 return;
546
547         $r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
548                         intval($uid)
549         );
550         if(count($r)) {
551                 foreach($r as $rr){
552                         $url = normalise_link($rr['url']);
553                         $ret[$url] = $rr;
554                 }
555         }
556         else 
557                 $ret['empty'] = true;   
558         $a->contacts = $ret;
559         return;         
560 }}
561
562
563 function best_link_url($item,&$sparkle) {
564
565         $a = get_app();
566
567         $best_url = '';
568         $sparkle  = false;
569
570         $clean_url = normalise_link($item['author-link']);
571
572         if((local_user()) && (local_user() == $item['uid'])) {
573                 if(isset($a->contacts) && x($a->contacts,$clean_url)) {
574                         if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
575                                 $best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
576                                 $sparkle = true;
577                         }
578                         else
579                                 $best_url = $a->contacts[$clean_url]['url'];
580                 }
581         }
582         if(! $best_url) {
583                 if(strlen($item['author-link']))
584                         $best_url = $item['author-link'];
585                 else
586                         $best_url = $item['url'];
587         }
588
589         return $best_url;
590 }
591
592
593 if(! function_exists('item_photo_menu')){
594 function item_photo_menu($item){
595         $a = get_app();
596         
597         if (local_user() && (! count($a->contacts)))
598                 load_contact_links(local_user());
599
600         $contact_url="";
601         $pm_url="";
602         $status_link="";
603         $photos_link="";
604         $posts_link="";
605
606         $sparkle = false;
607     $profile_link = best_link_url($item,$sparkle);
608         if($profile_link === 'mailbox')
609                 $profile_link = '';
610
611         if($sparkle) {
612                 $cid = intval(basename($profile_link));
613                 $status_link = $profile_link . "?url=status";
614                 $photos_link = $profile_link . "?url=photos";
615                 $profile_link = $profile_link . "?url=profile";
616                 $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
617         }
618         else {
619                 if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
620                         $cid = $item['contact-id'];
621                 }               
622                 else {
623                         $cid = 0;
624                 }
625         }
626         if(($cid) && (! $item['self'])) {
627                 $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
628                 $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
629         }
630
631         $menu = Array(
632                 t("View status") => $status_link,
633                 t("View profile") => $profile_link,
634                 t("View photos") => $photos_link,               
635                 t("View recent") => $posts_link, 
636                 t("Edit contact") => $contact_url,
637                 t("Send PM") => $pm_url,
638         );
639         
640         
641         $args = array($item, &$menu);
642         
643         call_hooks('item_photo_menu', $args);
644         
645         $o = "";
646         foreach($menu as $k=>$v){
647                 if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
648         }
649         return $o;
650 }}
651
652 if(! function_exists('like_puller')) {
653 function like_puller($a,$item,&$arr,$mode) {
654
655         $url = '';
656         $sparkle = '';
657         $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
658
659         if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
660                 $url = $item['author-link'];
661                 if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
662                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
663                         $sparkle = ' class="sparkle" ';
664                 }
665                 if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
666                         $arr[$item['parent'] . '-l'] = array();
667                 if(! isset($arr[$item['parent']]))
668                         $arr[$item['parent']] = 1;
669                 else    
670                         $arr[$item['parent']] ++;
671                 $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
672         }
673         return;
674 }}
675
676 // Format the like/dislike text for a profile item
677 // $cnt = number of people who like/dislike the item
678 // $arr = array of pre-linked names of likers/dislikers
679 // $type = one of 'like, 'dislike'
680 // $id  = item id
681 // returns formatted text
682
683 if(! function_exists('format_like')) {
684 function format_like($cnt,$arr,$type,$id) {
685         $o = '';
686         if($cnt == 1)
687                 $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
688         else {
689                 $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
690                 $o .= (($type === 'like') ? 
691                                         sprintf( t('<span  %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
692                                          : 
693                                         sprintf( t('<span  %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) ); 
694                 $o .= EOL ;
695                 $total = count($arr);
696                 if($total >= MAX_LIKERS)
697                         $arr = array_slice($arr, 0, MAX_LIKERS - 1);
698                 if($total < MAX_LIKERS)
699                         $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
700                 $str = implode(', ', $arr);
701                 if($total >= MAX_LIKERS)
702                         $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
703                 $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
704                 $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
705         }
706         return $o;
707 }}
708
709
710 function status_editor($a,$x, $notes_cid = 0) {
711
712         $o = '';
713                 
714         $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
715
716                 $tpl = get_markup_template('jot-header.tpl');
717         
718                 $a->page['htmlhead'] .= replace_macros($tpl, array(
719                         '$baseurl' => $a->get_baseurl(),
720                         '$geotag' => $geotag,
721                         '$nickname' => $x['nickname'],
722                         '$ispublic' => t('Visible to <strong>everybody</strong>'),
723                         '$linkurl' => t('Please enter a link URL:'),
724                         '$utubeurl' => t('Please enter a YouTube link:'),
725                         '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
726                         '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
727                         '$whereareu' => t('Where are you right now?'),
728                         '$title' => t('Enter a title for this item') 
729                 ));
730
731
732                 $tpl = get_markup_template("jot.tpl");
733                 
734                 $jotplugins = '';
735                 $jotnets = '';
736
737                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
738
739                 $mail_enabled = false;
740                 $pubmail_enabled = false;
741
742                 if(($x['is_owner']) && (! $mail_disabled)) {
743                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
744                                 intval(local_user())
745                         );
746                         if(count($r)) {
747                                 $mail_enabled = true;
748                                 if(intval($r[0]['pubmail']))
749                                         $pubmail_enabled = true;
750                         }
751                 }
752
753                 if($mail_enabled) {
754                $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
755                         $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
756                 . t("Post to Email") . '</div>';
757                 }
758
759                 call_hooks('jot_tool', $jotplugins);
760                 call_hooks('jot_networks', $jotnets);
761
762                 if($notes_cid)
763                         $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
764
765                 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
766
767                 $o .= replace_macros($tpl,array(
768                         '$return_path' => $a->cmd,
769                         '$action' => 'item',
770                         '$share' => (($x['button']) ? $x['button'] : t('Share')),
771                         '$upload' => t('Upload photo'),
772                         '$attach' => t('Attach file'),
773                         '$weblink' => t('Insert web link'),
774                         '$youtube' => t('Insert YouTube video'),
775                         '$video' => t('Insert Vorbis [.ogg] video'),
776                         '$audio' => t('Insert Vorbis [.ogg] audio'),
777                         '$setloc' => t('Set your location'),
778                         '$noloc' => t('Clear browser location'),
779                         '$title' => t('Set title'),
780                         '$wait' => t('Please wait'),
781                         '$permset' => t('Permission settings'),
782                         '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
783                         '$content' => '',
784                         '$post_id' => '',
785                         '$baseurl' => $a->get_baseurl(),
786                         '$defloc' => $x['default_location'],
787                         '$visitor' => $x['visitor'],
788                         '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
789                         '$emailcc' => t('CC: email addresses'),
790                         '$public' => t('Public post'),
791                         '$jotnets' => $jotnets,
792                         '$emtitle' => t('Example: bob@example.com, mary@example.com'),
793                         '$lockstate' => $x['lockstate'],
794                         '$acl' => $x['acl'],
795                         '$bang' => $x['bang'],
796                         '$profile_uid' => $x['profile_uid'],
797                 ));
798
799         return $o;
800 }