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.

674 lines
22 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. /**
  3. * Render actions localized
  4. */
  5. function localize_item(&$item){
  6. if ($item['verb']=="http://activitystrea.ms/schema/1.0/like" ||
  7. $item['verb']=="http://activitystrea.ms/schema/1.0/dislike"){
  8. $r = q("SELECT * from `item`,`contact` WHERE
  9. `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
  10. dbesc($item['parent-uri']));
  11. if(count($r)==0) return;
  12. $obj=$r[0];
  13. $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  14. $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
  15. $post_type = (($obj['resource-id']) ? t('photo') : t('status'));
  16. $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
  17. switch($item['verb']){
  18. case "http://activitystrea.ms/schema/1.0/like":
  19. $bodyverb = t('%1$s likes %2$s\'s %3$s');
  20. break;
  21. case "http://activitystrea.ms/schema/1.0/dislike":
  22. $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
  23. break;
  24. }
  25. $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
  26. }
  27. if ($item['verb']=='http://activitystrea.ms/schema/1.0/make-friend'){
  28. if ($item['object-type']=="" || $item['object-type']!='http://activitystrea.ms/schema/1.0/person') return;
  29. $Aname = $item['author-name'];
  30. $Alink = $item['author-link'];
  31. $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
  32. $obj = parse_xml_string($xmlhead.$item['object']);
  33. $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
  34. $Bname = $obj->title;
  35. $Blink = ""; $Bphoto = "";
  36. foreach ($links->link as $l){
  37. $atts = $l->attributes();
  38. switch($atts['rel']){
  39. case "alternate": $Blink = $atts['href'];
  40. case "photo": $Bphoto = $atts['href'];
  41. }
  42. }
  43. $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
  44. $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
  45. if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
  46. $item['body'] = sprintf(t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
  47. }
  48. }
  49. /**
  50. * "Render" a conversation or list of items for HTML display.
  51. * There are two major forms of display:
  52. * - Sequential or unthreaded ("New Item View" or search results)
  53. * - conversation view
  54. * The $mode parameter decides between the various renderings and also
  55. * figures out how to determine page owner and other contextual items
  56. * that are based on unique features of the calling module.
  57. *
  58. */
  59. function conversation(&$a, $items, $mode, $update) {
  60. require_once('bbcode.php');
  61. $profile_owner = 0;
  62. $page_writeable = false;
  63. if($mode === 'network') {
  64. $profile_owner = local_user();
  65. $page_writeable = true;
  66. }
  67. if($mode === 'profile') {
  68. $profile_owner = $a->profile['profile_uid'];
  69. $page_writeable = can_write_wall($a,$profile_owner);
  70. }
  71. if($mode === 'display') {
  72. $profile_owner = $a->profile['uid'];
  73. $page_writeable = can_write_wall($a,$profile_owner);
  74. }
  75. if($update)
  76. $return_url = $_SESSION['return_url'];
  77. else
  78. $return_url = $_SESSION['return_url'] = $a->cmd;
  79. // find all the authors involved in remote conversations
  80. // We will use a local profile photo if they are one of our contacts
  81. // otherwise we have to get the photo from the item owner's site
  82. $author_contacts = extract_item_authors($items,local_user());
  83. $cmnt_tpl = load_view_file('view/comment_item.tpl');
  84. $like_tpl = load_view_file('view/like.tpl');
  85. $noshare_tpl = load_view_file('view/like_noshare.tpl');
  86. $tpl = load_view_file('view/wall_item.tpl');
  87. $wallwall = load_view_file('view/wallwall_item.tpl');
  88. $alike = array();
  89. $dlike = array();
  90. if(count($items)) {
  91. if($mode === 'network-new' || $mode === 'search') {
  92. // "New Item View" on network page or search page results
  93. // - just loop through the items and format them minimally for display
  94. $tpl = load_view_file('view/search_item.tpl');
  95. $droptpl = load_view_file('view/wall_fake_drop.tpl');
  96. foreach($items as $item) {
  97. $comment = '';
  98. $owner_url = '';
  99. $owner_photo = '';
  100. $owner_name = '';
  101. $sparkle = '';
  102. if($mode === 'search') {
  103. if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
  104. && ($item['id'] != $item['parent']))
  105. continue;
  106. $nickname = $item['nickname'];
  107. }
  108. else
  109. $nickname = $a->user['nickname'];
  110. $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
  111. $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
  112. $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  113. if($profile_link === 'mailbox')
  114. $profile_link = '';
  115. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  116. if(strlen($item['author-link'])) {
  117. if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
  118. $profile_link = $redirect_url;
  119. $sparkle = ' sparkle';
  120. }
  121. elseif(isset($author_contacts[$item['author-link']])) {
  122. $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
  123. $sparkle = ' sparkle';
  124. }
  125. }
  126. $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  127. $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  128. if($coord) {
  129. if($location)
  130. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  131. else
  132. $location = '<span class="smalltext">' . $coord . '</span>';
  133. }
  134. $drop = '';
  135. $dropping = false;
  136. if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  137. $dropping = true;
  138. $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
  139. //
  140. localize_item($item);
  141. $drop = replace_macros($droptpl,array('$id' => $item['id']));
  142. $lock = '<div class="wall-item-lock"></div>';
  143. $o .= replace_macros($tpl,array(
  144. '$id' => $item['item_id'],
  145. '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
  146. '$profile_url' => $profile_link,
  147. '$item_photo_menu' => item_photo_menu($item),
  148. '$name' => $profile_name,
  149. '$sparkle' => $sparkle,
  150. '$lock' => $lock,
  151. '$thumb' => $profile_avatar,
  152. '$title' => $item['title'],
  153. '$body' => smilies(bbcode($item['body'])),
  154. '$ago' => relative_date($item['created']),
  155. '$location' => $location,
  156. '$indent' => '',
  157. '$owner_url' => $owner_url,
  158. '$owner_photo' => $owner_photo,
  159. '$owner_name' => $owner_name,
  160. '$drop' => $drop,
  161. '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
  162. ));
  163. }
  164. return $o;
  165. }
  166. // Normal View
  167. // Figure out how many comments each parent has
  168. // (Comments all have gravity of 6)
  169. // Store the result in the $comments array
  170. $comments = array();
  171. foreach($items as $item) {
  172. if(intval($item['gravity']) == 6) {
  173. if(! x($comments,$item['parent']))
  174. $comments[$item['parent']] = 1;
  175. else
  176. $comments[$item['parent']] += 1;
  177. }
  178. }
  179. // map all the like/dislike activities for each parent item
  180. // Store these in the $alike and $dlike arrays
  181. foreach($items as $item) {
  182. like_puller($a,$item,$alike,'like');
  183. like_puller($a,$item,$dlike,'dislike');
  184. }
  185. $comments_collapsed = false;
  186. $blowhard = 0;
  187. $blowhard_count = 0;
  188. foreach($items as $item) {
  189. $comment = '';
  190. $template = $tpl;
  191. $commentww = '';
  192. $sparkle = '';
  193. $owner_url = $owner_photo = $owner_name = '';
  194. // We've already parsed out like/dislike for special treatment. We can ignore them now
  195. if(((activity_match($item['verb'],ACTIVITY_LIKE))
  196. || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
  197. && ($item['id'] != $item['parent']))
  198. continue;
  199. $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
  200. // Take care of author collapsing and comment collapsing
  201. // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
  202. // If there are more than two comments, squash all but the last 2.
  203. if($toplevelpost) {
  204. $item_writeable = (($item['writable'] || $item['self']) ? true : false);
  205. if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile')) {
  206. $blowhard_count ++;
  207. if($blowhard_count == 3) {
  208. $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
  209. . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\');" >'
  210. . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
  211. . $item['parent'] . '" style="display: none;" >';
  212. }
  213. }
  214. else {
  215. $blowhard = $item['cid'];
  216. if($blowhard_count >= 3)
  217. $o .= '</div>';
  218. $blowhard_count = 0;
  219. }
  220. $comments_seen = 0;
  221. $comments_collapsed = false;
  222. }
  223. else
  224. $comments_seen ++;
  225. $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
  226. if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
  227. if(! $comments_collapsed) {
  228. $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
  229. . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >'
  230. . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
  231. . '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
  232. $comments_collapsed = true;
  233. }
  234. }
  235. if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
  236. $o .= '</div>';
  237. }
  238. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  239. $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  240. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  241. ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
  242. : '<div class="wall-item-lock"></div>');
  243. // Top-level wall post not written by the wall owner (wall-to-wall)
  244. // First figure out who owns it.
  245. $osparkle = '';
  246. if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
  247. if($item['type'] === 'wall') {
  248. // On the network page, I am the owner. On the display page it will be the profile owner.
  249. // This will have been stored in $a->page_contact by our calling page.
  250. // Put this person on the left of the wall-to-wall notice.
  251. $owner_url = $a->page_contact['url'];
  252. $owner_photo = $a->page_contact['thumb'];
  253. $owner_name = $a->page_contact['name'];
  254. $template = $wallwall;
  255. $commentww = 'ww';
  256. }
  257. if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
  258. // Could be anybody.
  259. $owner_url = $item['owner-link'];
  260. $owner_photo = $item['owner-avatar'];
  261. $owner_name = $item['owner-name'];
  262. $template = $wallwall;
  263. $commentww = 'ww';
  264. // If it is our contact, use a friendly redirect link
  265. if((link_compare($item['owner-link'],$item['url']))
  266. && ($item['network'] === 'dfrn')) {
  267. $owner_url = $redirect_url;
  268. $osparkle = ' sparkle';
  269. }
  270. }
  271. }
  272. $likebuttons = '';
  273. if($page_writeable) {
  274. if($toplevelpost) {
  275. $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
  276. '$id' => $item['id'],
  277. '$likethis' => t("I like this \x28toggle\x29"),
  278. '$nolike' => t("I don't like this \x28toggle\x29"),
  279. '$share' => t('Share'),
  280. '$wait' => t('Please wait')
  281. ));
  282. }
  283. if(($show_comment_box) || (($show_comment_box == false) && ($item['last-child']))) {
  284. $comment = replace_macros($cmnt_tpl,array(
  285. '$return_path' => '',
  286. '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
  287. '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
  288. '$id' => $item['item_id'],
  289. '$parent' => $item['parent'],
  290. '$profile_uid' => $profile_owner,
  291. '$mylink' => $a->contact['url'],
  292. '$mytitle' => t('This is you'),
  293. '$myphoto' => $a->contact['thumb'],
  294. '$comment' => t('Comment'),
  295. '$submit' => t('Submit'),
  296. '$ww' => (($mode === 'network') ? $commentww : '')
  297. ));
  298. }
  299. }
  300. $edpost = ((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1))
  301. ? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id']
  302. . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
  303. : '');
  304. $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
  305. $photo = $item['photo'];
  306. $thumb = $item['thumb'];
  307. // Post was remotely authored.
  308. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  309. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  310. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
  311. if($mode === 'profile') {
  312. if(local_user() && ($item['contact-uid'] == local_user()) && ($item['network'] === 'dfrn') && (! $item['self'] )) {
  313. $profile_link = $redirect_url;
  314. $sparkle = ' sparkle';
  315. }
  316. else {
  317. $profile_link = $item['url'];
  318. $sparkle = '';
  319. }
  320. }
  321. elseif(strlen($item['author-link'])) {
  322. $profile_link = $item['author-link'];
  323. if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
  324. $profile_link = $redirect_url;
  325. $sparkle = ' sparkle';
  326. }
  327. elseif(isset($author_contacts[$item['author-link']])) {
  328. $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
  329. $sparkle = ' sparkle';
  330. }
  331. }
  332. else
  333. $profile_link = $item['url'];
  334. if($profile_link === 'mailbox')
  335. $profile_link = '';
  336. $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
  337. $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
  338. $location = (($item['location']) ? '<a target="map" title="' . $item['location']
  339. . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  340. $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
  341. . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  342. if($coord) {
  343. if($location)
  344. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  345. else
  346. $location = '<span class="smalltext">' . $coord . '</span>';
  347. }
  348. $indent = (($toplevelpost) ? '' : ' comment');
  349. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  350. $indent .= ' shiny';
  351. //
  352. localize_item($item);
  353. // Build the HTML
  354. $tmp_item = replace_macros($template,array(
  355. '$id' => $item['item_id'],
  356. '$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
  357. '$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
  358. '$to' => t('to'),
  359. '$wall' => t('Wall-to-Wall'),
  360. '$vwall' => t('via Wall-To-Wall:'),
  361. '$profile_url' => $profile_link,
  362. '$item_photo_menu' => item_photo_menu($item),
  363. '$name' => $profile_name,
  364. '$thumb' => $profile_avatar,
  365. '$osparkle' => $osparkle,
  366. '$sparkle' => $sparkle,
  367. '$title' => $item['title'],
  368. '$body' => smilies(bbcode($item['body'])),
  369. '$ago' => relative_date($item['created']),
  370. '$lock' => $lock,
  371. '$location' => $location,
  372. '$indent' => $indent,
  373. '$owner_url' => $owner_url,
  374. '$owner_photo' => $owner_photo,
  375. '$owner_name' => $owner_name,
  376. '$plink' => get_plink($item),
  377. '$edpost' => $edpost,
  378. '$drop' => $drop,
  379. '$vote' => $likebuttons,
  380. '$like' => $like,
  381. '$dislike' => $dislike,
  382. '$comment' => $comment
  383. ));
  384. $arr = array('item' => $item, 'output' => $tmp_item);
  385. call_hooks('display_item', $arr);
  386. $o .= $arr['output'];
  387. }
  388. }
  389. // if author collapsing is in force but didn't get closed, close it off now.
  390. if($blowhard_count >= 3)
  391. $o .= '</div>';
  392. return $o;
  393. }
  394. if(! function_exists('extract_item_authors')) {
  395. function extract_item_authors($arr,$uid) {
  396. if((! $uid) || (! is_array($arr)) || (! count($arr)))
  397. return array();
  398. $urls = array();
  399. foreach($arr as $rr) {
  400. if(! in_array("'" . dbesc($rr['author-link']) . "'",$urls))
  401. $urls[] = "'" . dbesc($rr['author-link']) . "'";
  402. }
  403. // pre-quoted, don't put quotes on %s
  404. if(count($urls)) {
  405. $r = q("SELECT `id`,`network`,`url` FROM `contact` WHERE `uid` = %d AND `url` IN ( %s ) AND `self` = 0 AND `blocked` = 0 ",
  406. intval($uid),
  407. implode(',',$urls)
  408. );
  409. if(count($r)) {
  410. $ret = array();
  411. $authors = array();
  412. foreach($r as $rr){
  413. if ($rr['network']=='dfrn')
  414. $ret[$rr['url']] = $rr['id'];
  415. $authors[$r['url']]= $rr;
  416. }
  417. $a->authors = $authors;
  418. return $ret;
  419. }
  420. }
  421. return array();
  422. }}
  423. if(! function_exists('item_photo_menu')){
  424. function item_photo_menu($item){
  425. $a = get_app();
  426. if (!isset($a->authors)){
  427. $rr = q("SELECT `id`, `network`, `url` FROM `contact` WHERE `uid`=%d AND `self`=0 AND `blocked`=0 ", intval(local_user()));
  428. $authors = array();
  429. foreach($rr as $r) $authors[$r['url']]= $r;
  430. $a->authors = $authors;
  431. }
  432. $contact_url="";
  433. $pm_url="";
  434. $status_link="";
  435. $photos_link="";
  436. $posts_link="";
  437. $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  438. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  439. if($profile_link === 'mailbox')
  440. $profile_link = '';
  441. // $item['contact-uid'] is only set on profile page and indicates the uid of the user who owns the profile.
  442. $profile_owner = ((x($item,'contact-uid')) && intval($item['contact-uid']) ? intval($item['contact-uid']) : 0);
  443. // So we are checking that this is a logged in user on some page that *isn't* a profile page
  444. // OR a profile page where the viewer owns the profile.
  445. // Then check if we can use a sparkle (redirect) link to the profile by virtue of it being our contact
  446. // or a friend's contact that we both have a connection to.
  447. if((local_user() && ($profile_owner == 0))
  448. || ($profile_owner && $profile_owner == local_user())) {
  449. if(strlen($item['author-link']) && link_compare($item['author-link'],$item['url'])) {
  450. $redir = $redirect_url;
  451. $cid = $item['cid'];
  452. }
  453. elseif(isset($a->authors[$item['author-link']])) {
  454. $redir = $a->get_baseurl() . '/redir/' . $a->authors[$item['author-link']]['id'];
  455. $cid = $a->authors[$item['author-link']]['id'];
  456. }
  457. if($item['author-link'] === 'mailbox')
  458. $cid = $item['cid'];
  459. if((isset($cid)) && (! $item['self'])) {
  460. $contact_url = $a->get_baseurl() . '/contacts/' . $cid;
  461. $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
  462. if($item['network'] === 'dfrn') {
  463. $status_link = $redir . "?url=status";
  464. $profile_link = $redir . "?url=profile";
  465. $photos_link = $redir . "?url=photos";
  466. $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
  467. }
  468. }
  469. }
  470. $menu = Array(
  471. t("View status") => $status_link,
  472. t("View profile") => $profile_link,
  473. t("View photos") => $photos_link,
  474. t("View recent") => $posts_link,
  475. t("Edit contact") => $contact_url,
  476. t("Send PM") => $pm_url,
  477. );
  478. $args = array($item, &$menu);
  479. call_hooks('item_photo_menu', $args);
  480. $o = "";
  481. foreach($menu as $k=>$v){
  482. if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
  483. }
  484. return $o;
  485. }}
  486. if(! function_exists('like_puller')) {
  487. function like_puller($a,$item,&$arr,$mode) {
  488. $url = '';
  489. $sparkle = '';
  490. $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
  491. if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
  492. $url = $item['author-link'];
  493. if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
  494. $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
  495. $sparkle = ' class="sparkle" ';
  496. }
  497. if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
  498. $arr[$item['parent'] . '-l'] = array();
  499. if(! isset($arr[$item['parent']]))
  500. $arr[$item['parent']] = 1;
  501. else
  502. $arr[$item['parent']] ++;
  503. $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
  504. }
  505. return;
  506. }}
  507. // Format the like/dislike text for a profile item
  508. // $cnt = number of people who like/dislike the item
  509. // $arr = array of pre-linked names of likers/dislikers
  510. // $type = one of 'like, 'dislike'
  511. // $id = item id
  512. // returns formatted text
  513. if(! function_exists('format_like')) {
  514. function format_like($cnt,$arr,$type,$id) {
  515. $o = '';
  516. if($cnt == 1)
  517. $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
  518. else {
  519. $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
  520. $o .= (($type === 'like') ?
  521. sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
  522. :
  523. sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
  524. $o .= EOL ;
  525. $total = count($arr);
  526. if($total >= MAX_LIKERS)
  527. $arr = array_slice($arr, 0, MAX_LIKERS - 1);
  528. if($total < MAX_LIKERS)
  529. $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
  530. $str = implode(', ', $arr);
  531. if($total >= MAX_LIKERS)
  532. $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
  533. $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
  534. $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
  535. }
  536. return $o;
  537. }}