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.
 
 
 
 
 
 

1613 lines
51 KiB

  1. <?php
  2. // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
  3. // is identical to the code in mod/message.php for 'item_extract_images' and
  4. // 'item_redir_and_replace_images'
  5. if(! function_exists('item_extract_images')) {
  6. function item_extract_images($body) {
  7. $saved_image = array();
  8. $orig_body = $body;
  9. $new_body = '';
  10. $cnt = 0;
  11. $img_start = strpos($orig_body, '[img');
  12. $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
  13. $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
  14. while(($img_st_close !== false) && ($img_end !== false)) {
  15. $img_st_close++; // make it point to AFTER the closing bracket
  16. $img_end += $img_start;
  17. if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
  18. // This is an embedded image
  19. $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
  20. $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
  21. $cnt++;
  22. }
  23. else
  24. $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
  25. $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
  26. if($orig_body === false) // in case the body ends on a closing image tag
  27. $orig_body = '';
  28. $img_start = strpos($orig_body, '[img');
  29. $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
  30. $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
  31. }
  32. $new_body = $new_body . $orig_body;
  33. return array('body' => $new_body, 'images' => $saved_image);
  34. }}
  35. if(! function_exists('item_redir_and_replace_images')) {
  36. function item_redir_and_replace_images($body, $images, $cid) {
  37. $origbody = $body;
  38. $newbody = '';
  39. for($i = 0; $i < count($images); $i++) {
  40. $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
  41. $replace = '[url=' . z_path() . '/redir/' . $cid
  42. . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
  43. $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]');
  44. $process_part = substr($origbody, 0, $img_end);
  45. $origbody = substr($origbody, $img_end);
  46. $process_part = preg_replace($search, $replace, $process_part);
  47. $newbody = $newbody . $process_part;
  48. }
  49. $newbody = $newbody . $origbody;
  50. $cnt = 0;
  51. foreach($images as $image) {
  52. // We're depending on the property of 'foreach' (specified on the PHP website) that
  53. // it loops over the array starting from the first element and going sequentially
  54. // to the last element
  55. $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
  56. $cnt++;
  57. }
  58. return $newbody;
  59. }}
  60. /**
  61. * Render actions localized
  62. */
  63. function localize_item(&$item){
  64. $extracted = item_extract_images($item['body']);
  65. if($extracted['images'])
  66. $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
  67. $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
  68. if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
  69. $r = q("SELECT * from `item`,`contact` WHERE
  70. `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
  71. dbesc($item['parent-uri']));
  72. if(count($r)==0) return;
  73. $obj=$r[0];
  74. $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  75. $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
  76. switch($obj['verb']){
  77. case ACTIVITY_POST:
  78. switch ($obj['object-type']){
  79. case ACTIVITY_OBJ_EVENT:
  80. $post_type = t('event');
  81. break;
  82. default:
  83. $post_type = t('status');
  84. }
  85. break;
  86. default:
  87. if($obj['resource-id']){
  88. $post_type = t('photo');
  89. $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
  90. $rr['plink'] = $m[1];
  91. } else {
  92. $post_type = t('status');
  93. }
  94. }
  95. $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
  96. switch($item['verb']){
  97. case ACTIVITY_LIKE :
  98. $bodyverb = t('%1$s likes %2$s\'s %3$s');
  99. break;
  100. case ACTIVITY_DISLIKE:
  101. $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
  102. break;
  103. }
  104. $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
  105. }
  106. if ($item['verb']=== ACTIVITY_FRIEND){
  107. if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
  108. $Aname = $item['author-name'];
  109. $Alink = $item['author-link'];
  110. $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
  111. $obj = parse_xml_string($xmlhead.$item['object']);
  112. $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
  113. $Bname = $obj->title;
  114. $Blink = ""; $Bphoto = "";
  115. foreach ($links->link as $l){
  116. $atts = $l->attributes();
  117. switch($atts['rel']){
  118. case "alternate": $Blink = $atts['href'];
  119. case "photo": $Bphoto = $atts['href'];
  120. }
  121. }
  122. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  123. $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
  124. if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
  125. $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
  126. }
  127. if (stristr($item['verb'],ACTIVITY_POKE)) {
  128. $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
  129. if(! $verb)
  130. return;
  131. if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
  132. $Aname = $item['author-name'];
  133. $Alink = $item['author-link'];
  134. $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
  135. $obj = parse_xml_string($xmlhead.$item['object']);
  136. $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
  137. $Bname = $obj->title;
  138. $Blink = ""; $Bphoto = "";
  139. foreach ($links->link as $l){
  140. $atts = $l->attributes();
  141. switch($atts['rel']){
  142. case "alternate": $Blink = $atts['href'];
  143. case "photo": $Bphoto = $atts['href'];
  144. }
  145. }
  146. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  147. $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
  148. if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
  149. // we can't have a translation string with three positions but no distinguishable text
  150. // So here is the translate string.
  151. $txt = t('%1$s poked %2$s');
  152. // now translate the verb
  153. $txt = str_replace( t('poked'), t($verb), $txt);
  154. // then do the sprintf on the translation string
  155. $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
  156. }
  157. if ($item['verb']===ACTIVITY_TAG){
  158. $r = q("SELECT * from `item`,`contact` WHERE
  159. `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
  160. dbesc($item['parent-uri']));
  161. if(count($r)==0) return;
  162. $obj=$r[0];
  163. $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
  164. $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
  165. switch($obj['verb']){
  166. case ACTIVITY_POST:
  167. switch ($obj['object-type']){
  168. case ACTIVITY_OBJ_EVENT:
  169. $post_type = t('event');
  170. break;
  171. default:
  172. $post_type = t('status');
  173. }
  174. break;
  175. default:
  176. if($obj['resource-id']){
  177. $post_type = t('photo');
  178. $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
  179. $rr['plink'] = $m[1];
  180. } else {
  181. $post_type = t('status');
  182. }
  183. }
  184. $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
  185. $parsedobj = parse_xml_string($xmlhead.$item['object']);
  186. $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
  187. $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
  188. }
  189. if ($item['verb']=== ACTIVITY_FAVORITE){
  190. if ($item['object-type']== "")
  191. return;
  192. $Aname = $item['author-name'];
  193. $Alink = $item['author-link'];
  194. $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
  195. $obj = parse_xml_string($xmlhead.$item['object']);
  196. if(strlen($obj->id)) {
  197. $r = q("select * from item where uri = '%s' and uid = %d limit 1",
  198. dbesc($obj->id),
  199. intval($item['uid'])
  200. );
  201. if(count($r) && $r[0]['plink']) {
  202. $target = $r[0];
  203. $Bname = $target['author-name'];
  204. $Blink = $target['author-link'];
  205. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  206. $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
  207. $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
  208. $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
  209. }
  210. }
  211. }
  212. $matches = null;
  213. if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
  214. foreach($matches as $mtch) {
  215. if(! strpos($mtch[1],'zrl='))
  216. $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
  217. }
  218. }
  219. // add zrl's to public images
  220. if(preg_match_all('/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
  221. foreach($matches as $mtch) {
  222. $item['body'] = str_replace($mtch[0],'[url=' . zrl($mtch[1] . '/photos/' . $mtch[2] . '/image/' . $mtch[3] ,true) . '][img' . $mtch[4] . ']h' . $mtch[5] . '[/img][/url]',$item['body']);
  223. }
  224. }
  225. // add sparkle links to appropriate permalinks
  226. $x = stristr($item['plink'],'/display/');
  227. if($x) {
  228. $sparkle = false;
  229. $y = best_link_url($item,$sparkle,true);
  230. if(strstr($y,'/redir/'))
  231. $item['plink'] = $y . '?f=&url=' . $item['plink'];
  232. }
  233. }
  234. /**
  235. * Recursively prepare a thread for HTML
  236. */
  237. function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $thread_level=1) {
  238. $result = array();
  239. $wall_template = 'wall_thread.tpl';
  240. $wallwall_template = 'wallwall_thread.tpl';
  241. $items_seen = 0;
  242. $nb_items = count($items);
  243. foreach($items as $item) {
  244. // prevent private email reply to public conversation from leaking.
  245. if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
  246. // Don't count it as a visible item
  247. $nb_items--;
  248. continue;
  249. }
  250. $items_seen++;
  251. $alike = array();
  252. $dlike = array();
  253. $comment = '';
  254. $template = $wall_template;
  255. $commentww = '';
  256. $sparkle = '';
  257. $owner_url = $owner_photo = $owner_name = '';
  258. $buttons = '';
  259. $dropping = false;
  260. $star = false;
  261. $isstarred = "unstarred";
  262. $photo = $item['photo'];
  263. $thumb = $item['thumb'];
  264. $indent = '';
  265. $osparkle = '';
  266. $lastcollapsed = false;
  267. $firstcollapsed = false;
  268. $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
  269. $item_writeable = (($item['writable'] || $item['self']) ? true : false);
  270. $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
  271. $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  272. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  273. ? t('Private Message')
  274. : false);
  275. $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
  276. $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
  277. if(local_user() && link_compare($a->contact['url'],$item['author-link']))
  278. $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
  279. else
  280. $edpost = false;
  281. if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  282. $dropping = true;
  283. $drop = array(
  284. 'dropping' => $dropping,
  285. 'select' => t('Select'),
  286. 'delete' => t('Delete'),
  287. );
  288. $filer = (($profile_owner == local_user()) ? t("save to folder") : false);
  289. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  290. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  291. if($item['author-link'] && (! $item['author-name']))
  292. $profile_name = $item['author-link'];
  293. $sp = false;
  294. $profile_link = best_link_url($item,$sp);
  295. if($profile_link === 'mailbox')
  296. $profile_link = '';
  297. if($sp)
  298. $sparkle = ' sparkle';
  299. else
  300. $profile_link = zrl($profile_link);
  301. $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  302. if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
  303. $profile_avatar = $a->contacts[$normalised]['thumb'];
  304. else
  305. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
  306. $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
  307. call_hooks('render_location',$locate);
  308. $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
  309. $tags=array();
  310. foreach(explode(',',$item['tag']) as $tag){
  311. $tag = trim($tag);
  312. if ($tag!="") $tags[] = bbcode($tag);
  313. }
  314. like_puller($a,$item,$alike,'like');
  315. like_puller($a,$item,$dlike,'dislike');
  316. $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
  317. $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
  318. if($toplevelpost) {
  319. if((! $item['self']) && ($mode !== 'profile')) {
  320. if($item['wall']) {
  321. // On the network page, I am the owner. On the display page it will be the profile owner.
  322. // This will have been stored in $a->page_contact by our calling page.
  323. // Put this person as the wall owner of the wall-to-wall notice.
  324. $owner_url = zrl($a->page_contact['url']);
  325. $owner_photo = $a->page_contact['thumb'];
  326. $owner_name = $a->page_contact['name'];
  327. $template = $wallwall_template;
  328. $commentww = 'ww';
  329. }
  330. }
  331. else if($item['owner-link']) {
  332. $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
  333. $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
  334. $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
  335. if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
  336. // The author url doesn't match the owner (typically the contact)
  337. // and also doesn't match the contact alias.
  338. // The name match is a hack to catch several weird cases where URLs are
  339. // all over the park. It can be tricked, but this prevents you from
  340. // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
  341. // well that it's the same Bob Smith.
  342. // But it could be somebody else with the same name. It just isn't highly likely.
  343. $owner_url = $item['owner-link'];
  344. $owner_photo = $item['owner-avatar'];
  345. $owner_name = $item['owner-name'];
  346. $template = $wallwall_template;
  347. $commentww = 'ww';
  348. // If it is our contact, use a friendly redirect link
  349. if((link_compare($item['owner-link'],$item['url']))
  350. && ($item['network'] === NETWORK_DFRN)) {
  351. $owner_url = $redirect_url;
  352. $osparkle = ' sparkle';
  353. }
  354. else
  355. $owner_url = zrl($owner_url);
  356. }
  357. }
  358. if($profile_owner == local_user()) {
  359. $isstarred = (($item['starred']) ? "starred" : "unstarred");
  360. $star = array(
  361. 'do' => t("add star"),
  362. 'undo' => t("remove star"),
  363. 'toggle' => t("toggle star status"),
  364. 'classdo' => (($item['starred']) ? "hidden" : ""),
  365. 'classundo' => (($item['starred']) ? "" : "hidden"),
  366. 'starred' => t('starred'),
  367. 'tagger' => t("add tag"),
  368. 'classtagger' => "",
  369. );
  370. }
  371. } else {
  372. $indent = 'comment';
  373. // Collapse comments
  374. if(($nb_items > 2) || ($thread_level > 2)) {
  375. if($items_seen == 1) {
  376. $firstcollapsed = true;
  377. }
  378. if($thread_level > 2) {
  379. if($items_seen == $nb_items)
  380. $lastcollapsed = true;
  381. }
  382. else if($items_seen == ($nb_items - 2)) {
  383. $lastcollapsed = true;
  384. }
  385. }
  386. }
  387. if($page_writeable) {
  388. $buttons = array(
  389. 'like' => array( t("I like this \x28toggle\x29"), t("like")),
  390. 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
  391. );
  392. if ($shareable) $buttons['share'] = array( t('Share this'), t('share'));
  393. if($show_comment_box) {
  394. $qc = $qcomment = null;
  395. if(in_array('qcomment',$a->plugins)) {
  396. $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
  397. $qcomment = (($qc) ? explode("\n",$qc) : null);
  398. }
  399. $comment = replace_macros($cmnt_tpl,array(
  400. '$return_path' => '',
  401. '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
  402. '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
  403. '$id' => $item['item_id'],
  404. '$parent' => $item['item_id'],
  405. '$qcomment' => $qcomment,
  406. '$profile_uid' => $profile_owner,
  407. '$mylink' => $a->contact['url'],
  408. '$mytitle' => t('This is you'),
  409. '$myphoto' => $a->contact['thumb'],
  410. '$comment' => t('Comment'),
  411. '$submit' => t('Submit'),
  412. '$edbold' => t('Bold'),
  413. '$editalic' => t('Italic'),
  414. '$eduline' => t('Underline'),
  415. '$edquote' => t('Quote'),
  416. '$edcode' => t('Code'),
  417. '$edimg' => t('Image'),
  418. '$edurl' => t('Link'),
  419. '$edvideo' => t('Video'),
  420. '$preview' => t('Preview'),
  421. '$ww' => (($mode === 'network') ? $commentww : '')
  422. ));
  423. }
  424. }
  425. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  426. $indent .= ' shiny';
  427. localize_item($item);
  428. $body = prepare_body($item,true);
  429. $tmp_item = array(
  430. // collapse comments in template. I don't like this much...
  431. 'comment_firstcollapsed' => $firstcollapsed,
  432. 'comment_lastcollapsed' => $lastcollapsed,
  433. // template to use to render item (wall, walltowall, search)
  434. 'template' => $template,
  435. 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
  436. 'tags' => $tags,
  437. 'body' => template_escape($body),
  438. 'text' => strip_tags(template_escape($body)),
  439. 'id' => $item['item_id'],
  440. 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
  441. 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
  442. 'to' => t('to'),
  443. 'wall' => t('Wall-to-Wall'),
  444. 'vwall' => t('via Wall-To-Wall:'),
  445. 'profile_url' => $profile_link,
  446. 'item_photo_menu' => item_photo_menu($item),
  447. 'name' => template_escape($profile_name),
  448. 'thumb' => $profile_avatar,
  449. 'osparkle' => $osparkle,
  450. 'sparkle' => $sparkle,
  451. 'title' => template_escape($item['title']),
  452. 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
  453. 'lock' => $lock,
  454. 'location' => template_escape($location),
  455. 'indent' => $indent,
  456. 'owner_url' => $owner_url,
  457. 'owner_photo' => $owner_photo,
  458. 'owner_name' => template_escape($owner_name),
  459. 'plink' => get_plink($item),
  460. 'edpost' => $edpost,
  461. 'isstarred' => $isstarred,
  462. 'star' => $star,
  463. 'filer' => $filer,
  464. 'drop' => $drop,
  465. 'vote' => $buttons,
  466. 'like' => $like,
  467. 'dislike' => $dislike,
  468. 'comment' => $comment,
  469. 'previewing' => $previewing,
  470. 'wait' => t('Please wait'),
  471. );
  472. $arr = array('item' => $item, 'output' => $tmp_item);
  473. call_hooks('display_item', $arr);
  474. $item_result = $arr['output'];
  475. if($firstcollapsed) {
  476. $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$nb_items),$nb_items );
  477. $item_result['hide_text'] = t('show more');
  478. }
  479. $item_result['children'] = array();
  480. // Show children of children only if enabled
  481. if(count($item['children'])
  482. && (($thread_level < 2) || get_config('system','thread_allow'))) {
  483. $thread_level++;
  484. $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, $thread_level);
  485. }
  486. $item_result['private'] = $item['private'];
  487. $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : '');
  488. $result[] = $item_result;
  489. }
  490. return $result;
  491. }
  492. /**
  493. * "Render" a conversation or list of items for HTML display.
  494. * There are two major forms of display:
  495. * - Sequential or unthreaded ("New Item View" or search results)
  496. * - conversation view
  497. * The $mode parameter decides between the various renderings and also
  498. * figures out how to determine page owner and other contextual items
  499. * that are based on unique features of the calling module.
  500. *
  501. */
  502. if(!function_exists('conversation')) {
  503. function conversation(&$a, $items, $mode, $update, $preview = false, $thr_c = false) {
  504. require_once('bbcode.php');
  505. $ssl_state = ((local_user()) ? true : false);
  506. $profile_owner = 0;
  507. $page_writeable = false;
  508. $previewing = (($preview) ? ' preview ' : '');
  509. if($mode === 'network') {
  510. $profile_owner = local_user();
  511. $page_writeable = true;
  512. }
  513. if($mode === 'profile') {
  514. $profile_owner = $a->profile['profile_uid'];
  515. $page_writeable = can_write_wall($a,$profile_owner);
  516. }
  517. if($mode === 'notes') {
  518. $profile_owner = local_user();
  519. $page_writeable = true;
  520. }
  521. if($mode === 'display') {
  522. $profile_owner = $a->profile['uid'];
  523. $page_writeable = can_write_wall($a,$profile_owner);
  524. }
  525. if($mode === 'community') {
  526. $profile_owner = 0;
  527. $page_writeable = false;
  528. }
  529. if($update)
  530. $return_url = $_SESSION['return_url'];
  531. else
  532. $return_url = $_SESSION['return_url'] = $a->query_string;
  533. load_contact_links(local_user());
  534. $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
  535. call_hooks('conversation_start',$cb);
  536. $items = $cb['items'];
  537. $cmnt_tpl = get_markup_template('comment_item.tpl');
  538. $tpl = 'wall_item.tpl';
  539. $wallwall = 'wallwall_item.tpl';
  540. $hide_comments_tpl = get_markup_template('hide_comments.tpl');
  541. $alike = array();
  542. $dlike = array();
  543. // array with html for each thread (parent+comments)
  544. $threads = array();
  545. $threadsid = -1;
  546. if($items && count($items)) {
  547. if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
  548. // "New Item View" on network page or search page results
  549. // - just loop through the items and format them minimally for display
  550. //$tpl = get_markup_template('search_item.tpl');
  551. $tpl = 'search_item.tpl';
  552. foreach($items as $item) {
  553. $threadsid++;
  554. $comment = '';
  555. $owner_url = '';
  556. $owner_photo = '';
  557. $owner_name = '';
  558. $sparkle = '';
  559. if($mode === 'search' || $mode === 'community') {
  560. if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
  561. && ($item['id'] != $item['parent']))
  562. continue;
  563. $nickname = $item['nickname'];
  564. }
  565. else
  566. $nickname = $a->user['nickname'];
  567. // prevent private email from leaking.
  568. if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
  569. continue;
  570. $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
  571. if($item['author-link'] && (! $item['author-name']))
  572. $profile_name = $item['author-link'];
  573. $sp = false;
  574. $profile_link = best_link_url($item,$sp);
  575. if($profile_link === 'mailbox')
  576. $profile_link = '';
  577. if($sp)
  578. $sparkle = ' sparkle';
  579. else
  580. $profile_link = zrl($profile_link);
  581. $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  582. if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
  583. $profile_avatar = $a->contacts[$normalised]['thumb'];
  584. else
  585. $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
  586. $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
  587. call_hooks('render_location',$locate);
  588. $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
  589. localize_item($item);
  590. if($mode === 'network-new')
  591. $dropping = true;
  592. else
  593. $dropping = false;
  594. $drop = array(
  595. 'dropping' => $dropping,
  596. 'select' => t('Select'),
  597. 'delete' => t('Delete'),
  598. );
  599. $star = false;
  600. $isstarred = "unstarred";
  601. $lock = false;
  602. $likebuttons = false;
  603. $shareable = false;
  604. $body = prepare_body($item,true);
  605. //$tmp_item = replace_macros($tpl,array(
  606. $tmp_item = array(
  607. 'template' => $tpl,
  608. 'id' => (($preview) ? 'P0' : $item['item_id']),
  609. 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
  610. 'profile_url' => $profile_link,
  611. 'item_photo_menu' => item_photo_menu($item),
  612. 'name' => template_escape($profile_name),
  613. 'sparkle' => $sparkle,
  614. 'lock' => $lock,
  615. 'thumb' => $profile_avatar,
  616. 'title' => template_escape($item['title']),
  617. 'body' => template_escape($body),
  618. 'text' => strip_tags(template_escape($body)),
  619. 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
  620. 'location' => template_escape($location),
  621. 'indent' => '',
  622. 'owner_name' => template_escape($owner_name),
  623. 'owner_url' => $owner_url,
  624. 'owner_photo' => $owner_photo,
  625. 'plink' => get_plink($item),
  626. 'edpost' => false,
  627. 'isstarred' => $isstarred,
  628. 'star' => $star,
  629. 'drop' => $drop,
  630. 'vote' => $likebuttons,
  631. 'like' => '',
  632. 'dislike' => '',
  633. 'comment' => '',
  634. 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
  635. 'previewing' => $previewing,
  636. 'wait' => t('Please wait'),
  637. );
  638. $arr = array('item' => $item, 'output' => $tmp_item);
  639. call_hooks('display_item', $arr);
  640. $threads[$threadsid]['id'] = $item['item_id'];
  641. $threads[$threadsid]['items'] = array($arr['output']);
  642. }
  643. }
  644. else
  645. {
  646. // Normal View
  647. // Threaded comments, $thr_c is used for now since we don't know what other parts of friendica uses this function
  648. // Better not rely on the new code for stuff we haven't examined yet
  649. if($thr_c) {
  650. // get all the topmost parents
  651. // this shouldn't be needed, as we should have only them in ou array
  652. // But for now, this array respects the old style, just in case
  653. $threads = array();
  654. foreach($items as $item) {
  655. if($item['id'] == $item['parent']) {
  656. $threads[] = $item;
  657. }
  658. }
  659. $threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner);
  660. }
  661. else {
  662. // Figure out how many comments each parent has
  663. // (Comments all have gravity of 6)
  664. // Store the result in the $comments array
  665. $comments = array();
  666. foreach($items as $item) {
  667. if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
  668. if(! x($comments,$item['parent']))
  669. $comments[$item['parent']] = 1;
  670. else
  671. $comments[$item['parent']] += 1;
  672. } elseif(! x($comments,$item['parent']))
  673. $comments[$item['parent']] = 0; // avoid notices later on
  674. }
  675. // map all the like/dislike activities for each parent item
  676. // Store these in the $alike and $dlike arrays
  677. foreach($items as $item) {
  678. like_puller($a,$item,$alike,'like');
  679. like_puller($a,$item,$dlike,'dislike');
  680. }
  681. $comments_collapsed = false;
  682. $comments_seen = 0;
  683. $comment_lastcollapsed = false;
  684. $comment_firstcollapsed = false;
  685. $blowhard = 0;
  686. $blowhard_count = 0;
  687. foreach($items as $item) {
  688. $comment = '';
  689. $template = $tpl;
  690. $commentww = '';
  691. $sparkle = '';
  692. $owner_url = $owner_photo = $owner_name = '';
  693. // We've already parsed out like/dislike for special treatment. We can ignore them now
  694. if(((activity_match($item['verb'],ACTIVITY_LIKE))
  695. || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
  696. && ($item['id'] != $item['parent']))
  697. continue;
  698. $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
  699. // Take care of author collapsing and comment collapsing
  700. // (author collapsing is currently disabled)
  701. // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
  702. // If there are more than two comments, squash all but the last 2.
  703. if($toplevelpost) {
  704. $item_writeable = (($item['writable'] || $item['self']) ? true : false);
  705. $comments_seen = 0;
  706. $comments_collapsed = false;
  707. $comment_lastcollapsed = false;
  708. $comment_firstcollapsed = false;
  709. $threadsid++;
  710. $threads[$threadsid]['id'] = $item['item_id'];
  711. $threads[$threadsid]['private'] = $item['private'];
  712. $threads[$threadsid]['items'] = array();
  713. }
  714. else {
  715. // prevent private email reply to public conversation from leaking.
  716. if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
  717. continue;
  718. $comments_seen ++;
  719. $comment_lastcollapsed = false;
  720. $comment_firstcollapsed = false;
  721. }
  722. $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
  723. // Show comment box on every writable item
  724. $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
  725. if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
  726. if (!$comments_collapsed){
  727. $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
  728. $threads[$threadsid]['hide_text'] = t('show more');
  729. $comments_collapsed = true;
  730. $comment_firstcollapsed = true;
  731. }
  732. }
  733. if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
  734. $comment_lastcollapsed = true;
  735. }
  736. $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
  737. $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  738. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  739. ? t('Private Message')
  740. : false);
  741. // Top-level wall post not written by the wall owner (wall-to-wall)
  742. // First figure out who owns it.
  743. $osparkle = '';
  744. if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
  745. if($item['wall']) {
  746. // On the network page, I am the owner. On the display page it will be the profile owner.
  747. // This will have been stored in $a->page_contact by our calling page.
  748. // Put this person as the wall owner of the wall-to-wall notice.
  749. $owner_url = zrl($a->page_contact['url']);
  750. $owner_photo = $a->page_contact['thumb'];
  751. $owner_name = $a->page_contact['name'];
  752. $template = $wallwall;
  753. $commentww = 'ww';
  754. }
  755. if((! $item['wall']) && $item['owner-link']) {
  756. $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
  757. $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
  758. $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
  759. if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
  760. // The author url doesn't match the owner (typically the contact)
  761. // and also doesn't match the contact alias.
  762. // The name match is a hack to catch several weird cases where URLs are
  763. // all over the park. It can be tricked, but this prevents you from
  764. // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
  765. // well that it's the same Bob Smith.
  766. // But it could be somebody else with the same name. It just isn't highly likely.
  767. $owner_url = $item['owner-link'];
  768. $owner_photo = $item['owner-avatar'];
  769. $owner_name = $item['owner-name'];
  770. $template = $wallwall;
  771. $commentww = 'ww';
  772. // If it is our contact, use a friendly redirect link
  773. if((link_compare($item['owner-link'],$item['url']))
  774. && ($item['network'] === NETWORK_DFRN)) {
  775. $owner_url = $redirect_url;
  776. $osparkle = ' sparkle';
  777. }
  778. else
  779. $owner_url = zrl($owner_url);
  780. }
  781. }
  782. }
  783. $likebuttons = '';
  784. $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false);
  785. if($page_writeable) {
  786. /* if($toplevelpost) { */
  787. $likebuttons = array(
  788. 'like' => array( t("I like this \x28toggle\x29"), t("like")),
  789. 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
  790. );
  791. if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
  792. /* } */
  793. $qc = $qcomment = null;
  794. if(in_array('qcomment',$a->plugins)) {
  795. $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
  796. $qcomment = (($qc) ? explode("\n",$qc) : null);
  797. }
  798. if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
  799. $comment = replace_macros($cmnt_tpl,array(
  800. '$return_path' => '',
  801. '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
  802. '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
  803. '$id' => $item['item_id'],
  804. '$parent' => $item['item_id'],
  805. '$qcomment' => $qcomment,
  806. '$profile_uid' => $profile_owner,
  807. '$mylink' => $a->contact['url'],
  808. '$mytitle' => t('This is you'),
  809. '$myphoto' => $a->contact['thumb'],
  810. '$comment' => t('Comment'),
  811. '$submit' => t('Submit'),
  812. '$edbold' => t('Bold'),
  813. '$editalic' => t('Italic'),
  814. '$eduline' => t('Underline'),
  815. '$edquote' => t('Quote'),
  816. '$edcode' => t('Code'),
  817. '$edimg' => t('Image'),
  818. '$edurl' => t('Link'),
  819. '$edvideo' => t('Video'),
  820. '$preview' => t('Preview'),
  821. '$ww' => (($mode === 'network') ? $commentww : '')
  822. ));
  823. }
  824. }
  825. if(local_user() && link_compare($a->contact['url'],$item['author-link']))
  826. $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
  827. else
  828. $edpost = false;
  829. $drop = '';
  830. $dropping = false;
  831. if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  832. $dropping = true;
  833. $drop = array(
  834. 'dropping' => $dropping,
  835. 'select' => t('Select'),
  836. 'delete' => t('Delete'),
  837. );
  838. $star = false;
  839. $filer = false;
  840. $isstarred = "unstarred";
  841. if ($profile_owner == local_user()) {
  842. if($toplevelpost) {
  843. $isstarred = (($item['starred']) ? "starred" : "unstarred");
  844. $star = array(
  845. 'do' => t("add star"),
  846. 'undo' => t("remove star"),
  847. 'toggle' => t("toggle star status"),
  848. 'classdo' => (($item['starred']) ? "hidden" : ""),
  849. 'classundo' => (($item['starred']) ? "" : "hidden"),
  850. 'starred' => t('starred'),
  851. 'tagger' => t("add tag"),
  852. 'classtagger' => "",
  853. );
  854. }
  855. $filer = t("save to folder");
  856. }
  857. $photo = $item['photo'];
  858. $thumb = $item['thumb'];
  859. // Post was remotely authored.
  860. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  861. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  862. if($item['author-link'] && (! $item['author-name']))
  863. $profile_name = $item['author-link'];
  864. $sp = false;
  865. $profile_link = best_link_url($item,$sp);
  866. if($profile_link === 'mailbox')
  867. $profile_link = '';
  868. if($sp)
  869. $sparkle = ' sparkle';
  870. else
  871. $profile_link = zrl($profile_link);
  872. $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  873. if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
  874. $profile_avatar = $a->contacts[$normalised]['thumb'];
  875. else
  876. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
  877. $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
  878. $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
  879. $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
  880. call_hooks('render_location',$locate);
  881. $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
  882. $indent = (($toplevelpost) ? '' : ' comment');
  883. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  884. $indent .= ' shiny';
  885. //
  886. localize_item($item);
  887. $tags=array();
  888. foreach(explode(',',$item['tag']) as $tag){
  889. $tag = trim($tag);
  890. if ($tag!="") $tags[] = bbcode($tag);
  891. }
  892. // Build the HTML
  893. $body = prepare_body($item,true);
  894. //$tmp_item = replace_macros($template,
  895. $tmp_item = array(
  896. // collapse comments in template. I don't like this much...
  897. 'comment_firstcollapsed' => $firstcollapsed,
  898. 'comment_lastcollapsed' => $lastcollapsed,
  899. // template to use to render item (wall, walltowall, search)
  900. 'template' => $template,
  901. 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
  902. 'tags' => $tags,
  903. 'body' => template_escape($body),
  904. 'text' => strip_tags(template_escape($body)),
  905. 'id' => $item['item_id'],
  906. 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
  907. 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner-name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
  908. 'to' => t('to'),
  909. 'wall' => t('Wall-to-Wall'),
  910. 'vwall' => t('via Wall-To-Wall:'),
  911. 'profile_url' => $profile_link,
  912. 'item_photo_menu' => item_photo_menu($item),
  913. 'name' => template_escape($profile_name),
  914. 'thumb' => $profile_avatar,
  915. 'osparkle' => $osparkle,
  916. 'sparkle' => $sparkle,
  917. 'title' => template_escape($item['title']),
  918. 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
  919. 'lock' => $lock,
  920. 'location' => template_escape($location),
  921. 'indent' => $indent,
  922. 'owner_url' => $owner_url,
  923. 'owner_photo' => $owner_photo,
  924. 'owner_name' => template_escape($owner_name),
  925. 'plink' => get_plink($item),
  926. 'edpost' => $edpost,
  927. 'isstarred' => $isstarred,
  928. 'star' => $star,
  929. 'filer' => $filer,
  930. 'drop' => $drop,
  931. 'vote' => $likebuttons,
  932. 'like' => $like,
  933. 'dislike' => $dislike,
  934. 'comment' => $comment,
  935. 'previewing' => $previewing,
  936. 'wait' => t('Please wait'),
  937. );
  938. $arr = array('item' => $item, 'output' => $tmp_item);
  939. call_hooks('display_item', $arr);
  940. $threads[$threadsid]['items'][] = $arr['output'];
  941. }
  942. }
  943. }
  944. }
  945. $page_template = get_markup_template("conversation.tpl");
  946. if($thr_c)
  947. $page_template = get_markup_template("threaded_conversation.tpl");
  948. $o = replace_macros($page_template, array(
  949. '$baseurl' => $a->get_baseurl($ssl_state),
  950. '$mode' => $mode,
  951. '$user' => $a->user,
  952. '$threads' => $threads,
  953. '$dropping' => ($dropping?t('Delete Selected Items'):False),
  954. ));
  955. return $o;
  956. }}
  957. function best_link_url($item,&$sparkle,$ssl_state = false) {
  958. $a = get_app();
  959. $best_url = '';
  960. $sparkle = false;
  961. $clean_url = normalise_link($item['author-link']);
  962. if((local_user()) && (local_user() == $item['uid'])) {
  963. if(isset($a->contacts) && x($a->contacts,$clean_url)) {
  964. if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
  965. $best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
  966. $sparkle = true;
  967. }
  968. else
  969. $best_url = $a->contacts[$clean_url]['url'];
  970. }
  971. }
  972. if(! $best_url) {
  973. if(strlen($item['author-link']))
  974. $best_url = $item['author-link'];
  975. else
  976. $best_url = $item['url'];
  977. }
  978. return $best_url;
  979. }
  980. if(! function_exists('item_photo_menu')){
  981. function item_photo_menu($item){
  982. $a = get_app();
  983. $ssl_state = false;
  984. if(local_user()) {
  985. $ssl_state = true;
  986. if(! count($a->contacts))
  987. load_contact_links(local_user());
  988. }
  989. $poke_link="";
  990. $contact_url="";
  991. $pm_url="";
  992. $status_link="";
  993. $photos_link="";
  994. $posts_link="";
  995. $sparkle = false;
  996. $profile_link = best_link_url($item,$sparkle,$ssl_state);
  997. if($profile_link === 'mailbox')
  998. $profile_link = '';
  999. if($sparkle) {
  1000. $cid = intval(basename($profile_link));
  1001. $status_link = $profile_link . "?url=status";
  1002. $photos_link = $profile_link . "?url=photos";
  1003. $profile_link = $profile_link . "?url=profile";
  1004. $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
  1005. $zurl = '';
  1006. }
  1007. else {
  1008. $profile_link = zrl($profile_link);
  1009. if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
  1010. $cid = $item['contact-id'];
  1011. }
  1012. else {
  1013. $cid = 0;
  1014. }
  1015. }
  1016. if(($cid) && (! $item['self'])) {
  1017. $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
  1018. $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
  1019. $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
  1020. $clean_url = normalise_link($item['author-link']);
  1021. if((local_user()) && (local_user() == $item['uid'])) {
  1022. if(isset($a->contacts) && x($a->contacts,$clean_url)) {
  1023. if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
  1024. $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
  1025. }
  1026. }
  1027. }
  1028. }
  1029. $menu = Array(
  1030. t("View Status") => $status_link,
  1031. t("View Profile") => $profile_link,
  1032. t("View Photos") => $photos_link,
  1033. t("Network Posts") => $posts_link,
  1034. t("Edit Contact") => $contact_url,
  1035. t("Send PM") => $pm_url,
  1036. t("Poke") => $poke_link
  1037. );
  1038. $args = array('item' => $item, 'menu' => $menu);
  1039. call_hooks('item_photo_menu', $args);
  1040. $menu = $args['menu'];
  1041. $o = "";
  1042. foreach($menu as $k=>$v){
  1043. if ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
  1044. }
  1045. return $o;
  1046. }}
  1047. if(! function_exists('like_puller')) {
  1048. function like_puller($a,$item,&$arr,$mode) {
  1049. $url = '';
  1050. $sparkle = '';
  1051. $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
  1052. if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
  1053. $url = $item['author-link'];
  1054. if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
  1055. $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
  1056. $sparkle = ' class="sparkle" ';
  1057. }
  1058. else
  1059. $url = zrl($url);
  1060. if(! $item['thr-parent'])
  1061. $item['thr-parent'] = $item['parent-uri'];
  1062. if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
  1063. $arr[$item['thr-parent'] . '-l'] = array();
  1064. if(! isset($arr[$item['thr-parent']]))
  1065. $arr[$item['thr-parent']] = 1;
  1066. else
  1067. $arr[$item['thr-parent']] ++;
  1068. $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
  1069. }
  1070. return;
  1071. }}
  1072. // Format the like/dislike text for a profile item
  1073. // $cnt = number of people who like/dislike the item
  1074. // $arr = array of pre-linked names of likers/dislikers
  1075. // $type = one of 'like, 'dislike'
  1076. // $id = item id
  1077. // returns formatted text
  1078. if(! function_exists('format_like')) {
  1079. function format_like($cnt,$arr,$type,$id) {
  1080. $o = '';
  1081. if($cnt == 1)
  1082. $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
  1083. else {
  1084. $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
  1085. $o .= (($type === 'like') ?
  1086. sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
  1087. :
  1088. sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
  1089. $o .= EOL ;
  1090. $total = count($arr);
  1091. if($total >= MAX_LIKERS)
  1092. $arr = array_slice($arr, 0, MAX_LIKERS - 1);
  1093. if($total < MAX_LIKERS)
  1094. $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
  1095. $str = implode(', ', $arr);
  1096. if($total >= MAX_LIKERS)
  1097. $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
  1098. $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
  1099. $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
  1100. }
  1101. return $o;
  1102. }}
  1103. function status_editor($a,$x, $notes_cid = 0, $popup=false) {
  1104. $o = '';
  1105. $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
  1106. $plaintext = false;
  1107. if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
  1108. $plaintext = true;
  1109. $tpl = get_markup_template('jot-header.tpl');
  1110. $a->page['htmlhead'] .= replace_macros($tpl, array(
  1111. '$newpost' => 'true',
  1112. '$baseurl' => $a->get_baseurl(true),
  1113. '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
  1114. '$geotag' => $geotag,
  1115. '$nickname' => $x['nickname'],
  1116. '$ispublic' => t('Visible to <strong>everybody</strong>'),
  1117. '$linkurl' => t('Please enter a link URL:'),
  1118. '$vidurl' => t("Please enter a video link/URL:"),
  1119. '$audurl' => t("Please enter an audio link/URL:"),
  1120. '$term' => t('Tag term:'),
  1121. '$fileas' => t('Save to Folder:'),
  1122. '$whereareu' => t('Where are you right now?')
  1123. ));
  1124. $tpl = get_markup_template('jot-end.tpl');
  1125. $a->page['end'] .= replace_macros($tpl, array(
  1126. '$newpost' => 'true',
  1127. '$baseurl' => $a->get_baseurl(true),
  1128. '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
  1129. '$geotag' => $geotag,
  1130. '$nickname' => $x['nickname'],
  1131. '$ispublic' => t('Visible to <strong>everybody</strong>'),
  1132. '$linkurl' => t('Please enter a link URL:'),
  1133. '$vidurl' => t("Please enter a video link/URL:"),
  1134. '$audurl' => t("Please enter an audio link/URL:"),
  1135. '$term' => t('Tag term:'),
  1136. '$fileas' => t('Save to Folder:'),
  1137. '$whereareu' => t('Where are you right now?')
  1138. ));
  1139. $tpl = get_markup_template("jot.tpl");
  1140. $jotplugins = '';
  1141. $jotnets = '';
  1142. $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
  1143. $mail_enabled = false;
  1144. $pubmail_enabled = false;
  1145. if(($x['is_owner']) && (! $mail_disabled)) {
  1146. $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
  1147. intval(local_user())
  1148. );
  1149. if(count($r)) {
  1150. $mail_enabled = true;
  1151. if(intval($r[0]['pubmail']))
  1152. $pubmail_enabled = true;
  1153. }
  1154. }
  1155. if($mail_enabled) {
  1156. $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
  1157. $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
  1158. }
  1159. call_hooks('jot_tool', $jotplugins);
  1160. call_hooks('jot_networks', $jotnets);
  1161. if($notes_cid)
  1162. $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
  1163. $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
  1164. $o .= replace_macros($tpl,array(
  1165. '$return_path' => $a->query_string,
  1166. '$action' => $a->get_baseurl(true) . '/item',
  1167. '$share' => (x($x,'button') ? $x['button'] : t('Share')),
  1168. '$upload' => t('Upload photo'),
  1169. '$shortupload' => t('upload photo'),
  1170. '$attach' => t('Attach file'),
  1171. '$shortattach' => t('attach file'),
  1172. '$weblink' => t('Insert web link'),
  1173. '$shortweblink' => t('web link'),
  1174. '$video' => t('Insert video link'),
  1175. '$shortvideo' => t('video link'),
  1176. '$audio' => t('Insert audio link'),
  1177. '$shortaudio' => t('audio link'),
  1178. '$setloc' => t('Set your location'),
  1179. '$shortsetloc' => t('set location'),
  1180. '$noloc' => t('Clear browser location'),
  1181. '$shortnoloc' => t('clear location'),
  1182. '$title' => "",
  1183. '$placeholdertitle' => t('Set title'),
  1184. '$category' => "",
  1185. '$placeholdercategory' => t('Categories (comma-separated list)'),
  1186. '$wait' => t('Please wait'),
  1187. '$permset' => t('Permission settings'),
  1188. '$shortpermset' => t('permissions'),
  1189. '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
  1190. '$content' => '',
  1191. '$post_id' => '',
  1192. '$baseurl' => $a->get_baseurl(true),
  1193. '$defloc' => $x['default_location'],
  1194. '$visitor' => $x['visitor'],
  1195. '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
  1196. '$emailcc' => t('CC: email addresses'),
  1197. '$public' => t('Public post'),
  1198. '$jotnets' => $jotnets,
  1199. '$emtitle' => t('Example: bob@example.com, mary@example.com'),
  1200. '$lockstate' => $x['lockstate'],
  1201. '$acl' => $x['acl'],
  1202. '$bang' => $x['bang'],
  1203. '$profile_uid' => $x['profile_uid'],
  1204. '$preview' => t('Preview'),
  1205. ));
  1206. if ($popup==true){
  1207. $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
  1208. }
  1209. return $o;
  1210. }
  1211. function get_item_children($arr, $parent) {
  1212. $children = array();
  1213. foreach($arr as $item) {
  1214. if(($item['id'] != $item['parent']) && ($item['thr-parent'] == $parent['uri'])) {
  1215. $item['children'] = get_item_children($arr, $item);
  1216. $children[] = $item;
  1217. }
  1218. }
  1219. return $children;
  1220. }
  1221. function sort_item_children($items) {
  1222. $result = $items;
  1223. usort($result,'sort_thr_created_rev');
  1224. foreach($result as $k => $i) {
  1225. if(count($result[$k]['children'])) {
  1226. $result[$k]['children'] = sort_item_children($result[$k]['children']);
  1227. }
  1228. }
  1229. return $result;
  1230. }
  1231. function add_children_to_list($children, &$arr) {
  1232. foreach($children as $y) {
  1233. $arr[] = $y;
  1234. if(count($y['children']))
  1235. add_children_to_list($y['children'], $arr);
  1236. }
  1237. }
  1238. function conv_sort($arr,$order) {
  1239. if((!(is_array($arr) && count($arr))))
  1240. return array();
  1241. $parents = array();
  1242. $children = array();
  1243. foreach($arr as $x)
  1244. if($x['id'] == $x['parent'])
  1245. $parents[] = $x;
  1246. if(stristr($order,'created'))
  1247. usort($parents,'sort_thr_created');
  1248. elseif(stristr($order,'commented'))
  1249. usort($parents,'sort_thr_commented');
  1250. if(count($parents))
  1251. foreach($parents as $i=>$_x)
  1252. $parents[$i]['children'] = get_item_children($arr, $_x);
  1253. /*foreach($arr as $x) {
  1254. if($x['id'] != $x['parent']) {
  1255. $p = find_thread_parent_index($parents,$x);
  1256. if($p !== false)
  1257. $parents[$p]['children'][] = $x;
  1258. }
  1259. }*/
  1260. if(count($parents)) {
  1261. foreach($parents as $k => $v) {
  1262. if(count($parents[$k]['children'])) {
  1263. $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
  1264. /*$y = $parents[$k]['children'];
  1265. usort($y,'sort_thr_created_rev');
  1266. $parents[$k]['children'] = $y;*/
  1267. }
  1268. }
  1269. }
  1270. $ret = array();
  1271. if(count($parents)) {
  1272. foreach($parents as $x) {
  1273. $ret[] = $x;
  1274. if(count($x['children']))
  1275. add_children_to_list($x['children'], $ret);
  1276. /*foreach($x['children'] as $y)
  1277. $ret[] = $y;*/
  1278. }
  1279. }
  1280. return $ret;
  1281. }
  1282. function sort_thr_created($a,$b) {
  1283. return strcmp($b['created'],$a['created']);
  1284. }
  1285. function sort_thr_created_rev($a,$b) {
  1286. return strcmp($a['created'],$b['created']);
  1287. }
  1288. function sort_thr_commented($a,$b) {
  1289. return strcmp($b['commented'],$a['commented']);
  1290. }
  1291. function find_thread_parent_index($arr,$x) {
  1292. foreach($arr as $k => $v)
  1293. if($v['id'] == $x['parent'])
  1294. return $k;
  1295. return false;
  1296. }
  1297. function render_location_google($item) {
  1298. $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  1299. $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  1300. if($coord) {
  1301. if($location)
  1302. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  1303. else
  1304. $location = '<span class="smalltext">' . $coord . '</span>';
  1305. }
  1306. return $location;
  1307. }