Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1052 lines
32 KiB

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