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.
 
 
 
 
 
 

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