Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1550 строки
45KB

  1. <?php
  2. require_once "include/bbcode.php";
  3. require_once "include/acl_selectors.php";
  4. /*
  5. * Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
  6. * is identical to the code in mod/message.php for 'item_extract_images' and
  7. * 'item_redir_and_replace_images'
  8. */
  9. if (! function_exists('item_extract_images')) {
  10. function item_extract_images($body) {
  11. $saved_image = array();
  12. $orig_body = $body;
  13. $new_body = '';
  14. $cnt = 0;
  15. $img_start = strpos($orig_body, '[img');
  16. $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
  17. $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
  18. while (($img_st_close !== false) && ($img_end !== false)) {
  19. $img_st_close++; // make it point to AFTER the closing bracket
  20. $img_end += $img_start;
  21. if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
  22. // This is an embedded image
  23. $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
  24. $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
  25. $cnt++;
  26. } else {
  27. $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
  28. }
  29. $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
  30. if ($orig_body === false) {
  31. // in case the body ends on a closing image tag
  32. $orig_body = '';
  33. }
  34. $img_start = strpos($orig_body, '[img');
  35. $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
  36. $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
  37. }
  38. $new_body = $new_body . $orig_body;
  39. return array('body' => $new_body, 'images' => $saved_image);
  40. }}
  41. if (! function_exists('item_redir_and_replace_images')) {
  42. function item_redir_and_replace_images($body, $images, $cid) {
  43. $origbody = $body;
  44. $newbody = '';
  45. $cnt = 1;
  46. $pos = get_bb_tag_pos($origbody, 'url', 1);
  47. while ($pos !== false && $cnt < 1000) {
  48. $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
  49. $replace = '[url=' . z_path() . '/redir/' . $cid
  50. . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
  51. $newbody .= substr($origbody, 0, $pos['start']['open']);
  52. $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
  53. $origbody = substr($origbody, $pos['end']['close']);
  54. if ($origbody === false) {
  55. $origbody = '';
  56. }
  57. $subject = preg_replace($search, $replace, $subject);
  58. $newbody .= $subject;
  59. $cnt++;
  60. $pos = get_bb_tag_pos($origbody, 'url', 1);
  61. }
  62. $newbody .= $origbody;
  63. $cnt = 0;
  64. foreach ($images as $image) {
  65. /*
  66. * We're depending on the property of 'foreach' (specified on the PHP website) that
  67. * it loops over the array starting from the first element and going sequentially
  68. * to the last element.
  69. */
  70. $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
  71. $cnt++;
  72. }
  73. return $newbody;
  74. }}
  75. /**
  76. * Render actions localized
  77. */
  78. function localize_item(&$item) {
  79. $extracted = item_extract_images($item['body']);
  80. if ($extracted['images']) {
  81. $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
  82. }
  83. /// @Separted ???
  84. $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
  85. if (activity_match($item['verb'], ACTIVITY_LIKE)
  86. || activity_match($item['verb'], ACTIVITY_DISLIKE)
  87. || activity_match($item['verb'], ACTIVITY_ATTEND)
  88. || activity_match($item['verb'], ACTIVITY_ATTENDNO)
  89. || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
  90. /// @TODO may hurt performance
  91. $r = q("SELECT * FROM `item`, `contact`
  92. WHERE `item`.`contact-id`=`contact`.`id`
  93. AND `item`.`uri`='%s'",
  94. dbesc($item['parent-uri']));
  95. if (!dbm::is_result($r)) {
  96. return;
  97. }
  98. $obj = $r[0];
  99. $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
  100. $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
  101. switch ($obj['verb']) {
  102. case ACTIVITY_POST:
  103. switch ($obj['object-type']) {
  104. case ACTIVITY_OBJ_EVENT:
  105. $post_type = t('event');
  106. break;
  107. default:
  108. $post_type = t('status');
  109. }
  110. break;
  111. default:
  112. if ($obj['resource-id']) {
  113. $post_type = t('photo');
  114. $m = array();
  115. preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
  116. $rr['plink'] = $m[1];
  117. } else {
  118. $post_type = t('status');
  119. }
  120. }
  121. $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
  122. if (activity_match($item['verb'], ACTIVITY_LIKE)) {
  123. $bodyverb = t('%1$s likes %2$s\'s %3$s');
  124. }
  125. elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
  126. $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
  127. }
  128. elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
  129. $bodyverb = t('%1$s attends %2$s\'s %3$s');
  130. }
  131. elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
  132. $bodyverb = t('%1$s doesn\'t attend %2$s\'s %3$s');
  133. }
  134. elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
  135. $bodyverb = t('%1$s attends maybe %2$s\'s %3$s');
  136. }
  137. $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
  138. }
  139. if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
  140. if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
  141. $Aname = $item['author-name'];
  142. $Alink = $item['author-link'];
  143. $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
  144. $obj = parse_xml_string($xmlhead.$item['object']);
  145. $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
  146. $Bname = $obj->title;
  147. $Blink = ""; $Bphoto = "";
  148. foreach ($links->link as $l) {
  149. $atts = $l->attributes();
  150. switch ($atts['rel']) {
  151. case "alternate": $Blink = $atts['href'];
  152. case "photo": $Bphoto = $atts['href'];
  153. }
  154. }
  155. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  156. $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
  157. if ($Bphoto != "") {
  158. $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
  159. }
  160. $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
  161. }
  162. if (stristr($item['verb'], ACTIVITY_POKE)) {
  163. $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
  164. if (! $verb) {
  165. return;
  166. }
  167. if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
  168. return;
  169. }
  170. $Aname = $item['author-name'];
  171. $Alink = $item['author-link'];
  172. $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
  173. $obj = parse_xml_string($xmlhead.$item['object']);
  174. $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
  175. $Bname = $obj->title;
  176. $Blink = "";
  177. $Bphoto = "";
  178. foreach ($links->link as $l) {
  179. $atts = $l->attributes();
  180. switch ($atts['rel']) {
  181. case "alternate": $Blink = $atts['href'];
  182. case "photo": $Bphoto = $atts['href'];
  183. }
  184. }
  185. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  186. $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
  187. if ($Bphoto != "") {
  188. $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
  189. }
  190. /*
  191. * we can't have a translation string with three positions but no distinguishable text
  192. * So here is the translate string.
  193. */
  194. $txt = t('%1$s poked %2$s');
  195. // now translate the verb
  196. $poked_t = trim(sprintf($txt, "", ""));
  197. $txt = str_replace( $poked_t, t($verb), $txt);
  198. // then do the sprintf on the translation string
  199. $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
  200. }
  201. if (stristr($item['verb'], ACTIVITY_MOOD)) {
  202. $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#') + 1));
  203. if (! $verb) {
  204. return;
  205. }
  206. $Aname = $item['author-name'];
  207. $Alink = $item['author-link'];
  208. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  209. $txt = t('%1$s is currently %2$s');
  210. $item['body'] = sprintf($txt, $A, t($verb));
  211. }
  212. if (activity_match($item['verb'], ACTIVITY_TAG)) {
  213. /// @TODO may hurt performance "joining" two tables + asterisk
  214. $r = q("SELECT * FROM `item`, `contact`
  215. WHERE `item`.`contact-id`=`contact`.`id`
  216. AND `item`.`uri`='%s'",
  217. dbesc($item['parent-uri']));
  218. if (!dbm::is_result($r)) {
  219. return;
  220. }
  221. $obj = $r[0];
  222. $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
  223. $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
  224. switch ($obj['verb']) {
  225. case ACTIVITY_POST:
  226. switch ($obj['object-type']) {
  227. case ACTIVITY_OBJ_EVENT:
  228. $post_type = t('event');
  229. break;
  230. default:
  231. $post_type = t('status');
  232. }
  233. break;
  234. default:
  235. if ($obj['resource-id']) {
  236. $post_type = t('photo');
  237. $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
  238. $rr['plink'] = $m[1];
  239. } else {
  240. $post_type = t('status');
  241. }
  242. // Let's break everthing ... ;-)
  243. break;
  244. }
  245. $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
  246. $parsedobj = parse_xml_string($xmlhead.$item['object']);
  247. $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
  248. $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
  249. }
  250. if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
  251. if ($item['object-type'] == "") {
  252. return;
  253. }
  254. $Aname = $item['author-name'];
  255. $Alink = $item['author-link'];
  256. $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
  257. $obj = parse_xml_string($xmlhead.$item['object']);
  258. if (strlen($obj->id)) {
  259. $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
  260. dbesc($obj->id),
  261. intval($item['uid'])
  262. );
  263. if (dbm::is_result($r) && $r[0]['plink']) {
  264. $target = $r[0];
  265. $Bname = $target['author-name'];
  266. $Blink = $target['author-link'];
  267. $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
  268. $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
  269. $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
  270. $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
  271. }
  272. }
  273. }
  274. $matches = null;
  275. if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
  276. foreach ($matches as $mtch) {
  277. if (! strpos($mtch[1], 'zrl=')) {
  278. $item['body'] = str_replace($mtch[0], '@[url=' . zrl($mtch[1]) . ']', $item['body']);
  279. }
  280. }
  281. }
  282. // add zrl's to public images
  283. $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
  284. if (preg_match($photo_pattern, $item['body'])) {
  285. $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
  286. $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
  287. }
  288. // add sparkle links to appropriate permalinks
  289. $x = stristr($item['plink'],'/display/');
  290. if ($x) {
  291. $sparkle = false;
  292. $y = best_link_url($item, $sparkle, true);
  293. if (strstr($y, '/redir/')) {
  294. $item['plink'] = $y . '?f=&url=' . $item['plink'];
  295. }
  296. }
  297. }
  298. /**
  299. * Count the total of comments on this item and its desendants
  300. * @TODO proper type-hint + doc-tag
  301. */
  302. function count_descendants($item) {
  303. $total = count($item['children']);
  304. if ($total > 0) {
  305. foreach ($item['children'] as $child) {
  306. if (! visible_activity($child)) {
  307. $total --;
  308. }
  309. $total += count_descendants($child);
  310. }
  311. }
  312. return $total;
  313. }
  314. function visible_activity($item) {
  315. /*
  316. * likes (etc.) can apply to other things besides posts. Check if they are post children,
  317. * in which case we handle them specially
  318. */
  319. $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
  320. foreach ($hidden_activities as $act) {
  321. if (activity_match($item['verb'], $act)) {
  322. return false;
  323. }
  324. }
  325. if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
  326. if (! (($item['self']) && ($item['uid'] == local_user()))) {
  327. return false;
  328. }
  329. }
  330. return true;
  331. }
  332. /**
  333. * @brief SQL query for items
  334. */
  335. function item_query() {
  336. return "SELECT " . item_fieldlists() . " FROM `item` " .
  337. item_joins() . " WHERE " . item_condition();
  338. }
  339. /**
  340. * @brief List of all data fields that are needed for displaying items
  341. */
  342. function item_fieldlists() {
  343. /*
  344. These Fields are not added below (yet). They are here to for bug search.
  345. `item`.`type`,
  346. `item`.`extid`,
  347. `item`.`received`,
  348. `item`.`changed`,
  349. `item`.`moderated`,
  350. `item`.`target-type`,
  351. `item`.`target`,
  352. `item`.`resource-id`,
  353. `item`.`tag`,
  354. `item`.`inform`,
  355. `item`.`pubmail`,
  356. `item`.`visible`,
  357. `item`.`spam`,
  358. `item`.`bookmark`,
  359. `item`.`unseen`,
  360. `item`.`deleted`,
  361. `item`.`origin`,
  362. `item`.`forum_mode`,
  363. `item`.`last-child`,
  364. `item`.`mention`,
  365. `item`.`global`,
  366. `item`.`gcontact-id`,
  367. `item`.`shadow`,
  368. */
  369. return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
  370. `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
  371. `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
  372. `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
  373. `item`.`commented`, `item`.`created`, `item`.`edited`,
  374. `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
  375. `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
  376. `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
  377. `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
  378. `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
  379. `item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
  380. `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
  381. `author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
  382. `contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
  383. `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`";
  384. }
  385. /**
  386. * @brief SQL join for contacts that are needed for displaying items
  387. */
  388. function item_joins() {
  389. return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND
  390. (NOT `contact`.`blocked` OR `contact`.`pending`)
  391. LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id`
  392. LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id`";
  393. }
  394. /**
  395. * @brief SQL condition for items that are needed for displaying items
  396. */
  397. function item_condition() {
  398. return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
  399. }
  400. if (!function_exists('conversation')) {
  401. /**
  402. * "Render" a conversation or list of items for HTML display.
  403. * There are two major forms of display:
  404. * - Sequential or unthreaded ("New Item View" or search results)
  405. * - conversation view
  406. * The $mode parameter decides between the various renderings and also
  407. * figures out how to determine page owner and other contextual items
  408. * that are based on unique features of the calling module.
  409. *
  410. */
  411. function conversation(App $a, $items, $mode, $update, $preview = false) {
  412. require_once 'include/bbcode.php';
  413. require_once 'include/Contact.php';
  414. require_once 'mod/proxy.php';
  415. $ssl_state = ((local_user()) ? true : false);
  416. $profile_owner = 0;
  417. $page_writeable = false;
  418. $live_update_div = '';
  419. $arr_blocked = null;
  420. if (local_user()) {
  421. $str_blocked = get_pconfig(local_user(), 'system', 'blocked');
  422. if ($str_blocked) {
  423. $arr_blocked = explode(',', $str_blocked);
  424. for ($x = 0; $x < count($arr_blocked); $x ++) {
  425. $arr_blocked[$x] = trim($arr_blocked[$x]);
  426. }
  427. }
  428. }
  429. $previewing = (($preview) ? ' preview ' : '');
  430. if ($mode === 'network') {
  431. $profile_owner = local_user();
  432. $page_writeable = true;
  433. if (!$update) {
  434. /*
  435. * The special div is needed for liveUpdate to kick in for this page.
  436. * We only launch liveUpdate if you aren't filtering in some incompatible
  437. * way and also you aren't writing a comment (discovered in javascript).
  438. */
  439. $live_update_div = '<div id="live-network"></div>' . "\r\n"
  440. . "<script> var profile_uid = " . $_SESSION['uid']
  441. . "; var netargs = '" . substr($a->cmd, 8)
  442. . '?f='
  443. . ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
  444. . ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
  445. . ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
  446. . ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
  447. . ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
  448. . ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
  449. . ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
  450. . ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
  451. . ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
  452. . ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
  453. . ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
  454. . ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
  455. . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  456. }
  457. } elseif ($mode === 'profile') {
  458. $profile_owner = $a->profile['profile_uid'];
  459. $page_writeable = can_write_wall($a,$profile_owner);
  460. if (!$update) {
  461. $tab = notags(trim($_GET['tab']));
  462. $tab = ( $tab ? $tab : 'posts' );
  463. if ($tab === 'posts') {
  464. /*
  465. * This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
  466. * because browser prefetching might change it on us. We have to deliver it with the page.
  467. */
  468. $live_update_div = '<div id="live-profile"></div>' . "\r\n"
  469. . "<script> var profile_uid = " . $a->profile['profile_uid']
  470. . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  471. }
  472. }
  473. } elseif ($mode === 'notes') {
  474. $profile_owner = local_user();
  475. $page_writeable = true;
  476. if (!$update) {
  477. $live_update_div = '<div id="live-notes"></div>' . "\r\n"
  478. . "<script> var profile_uid = " . local_user()
  479. . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  480. }
  481. } elseif ($mode === 'display') {
  482. $profile_owner = $a->profile['uid'];
  483. $page_writeable = can_write_wall($a,$profile_owner);
  484. if (!$update) {
  485. $live_update_div = '<div id="live-display"></div>' . "\r\n"
  486. . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
  487. . " var profile_page = 1; </script>";
  488. }
  489. } elseif ($mode === 'community') {
  490. $profile_owner = 0;
  491. $page_writeable = false;
  492. if (!$update) {
  493. $live_update_div = '<div id="live-community"></div>' . "\r\n"
  494. . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  495. }
  496. } elseif ($mode === 'search') {
  497. $live_update_div = '<div id="live-search"></div>' . "\r\n";
  498. }
  499. $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
  500. if ($update) {
  501. $return_url = $_SESSION['return_url'];
  502. } else {
  503. $return_url = $_SESSION['return_url'] = $a->query_string;
  504. }
  505. $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
  506. call_hooks('conversation_start',$cb);
  507. $items = $cb['items'];
  508. $cmnt_tpl = get_markup_template('comment_item.tpl');
  509. $hide_comments_tpl = get_markup_template('hide_comments.tpl');
  510. $conv_responses = array(
  511. 'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
  512. 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
  513. );
  514. // array with html for each thread (parent+comments)
  515. $threads = array();
  516. $threadsid = -1;
  517. $page_template = get_markup_template("conversation.tpl");
  518. if ($items && count($items)) {
  519. if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
  520. /*
  521. * "New Item View" on network page or search page results
  522. * - just loop through the items and format them minimally for display
  523. */
  524. /// @TODO old lost code?
  525. // $tpl = get_markup_template('search_item.tpl');
  526. $tpl = 'search_item.tpl';
  527. foreach ($items as $item) {
  528. if ($arr_blocked) {
  529. $blocked = false;
  530. foreach ($arr_blocked as $b) {
  531. if ($b && link_compare($item['author-link'], $b)) {
  532. $blocked = true;
  533. break;
  534. }
  535. }
  536. if ($blocked) {
  537. continue;
  538. }
  539. }
  540. $threadsid++;
  541. $comment = '';
  542. $owner_url = '';
  543. $owner_name = '';
  544. $sparkle = '';
  545. if ($mode === 'search' || $mode === 'community') {
  546. if (((activity_match($item['verb'], ACTIVITY_LIKE)) || (activity_match($item['verb'], ACTIVITY_DISLIKE)))
  547. && ($item['id'] != $item['parent']))
  548. continue;
  549. $nickname = $item['nickname'];
  550. } else {
  551. $nickname = $a->user['nickname'];
  552. }
  553. // prevent private email from leaking.
  554. if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
  555. continue;
  556. }
  557. $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
  558. if ($item['author-link'] && (! $item['author-name'])) {
  559. $profile_name = $item['author-link'];
  560. }
  561. $tags = array();
  562. $hashtags = array();
  563. $mentions = array();
  564. $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
  565. intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
  566. foreach ($taglist as $tag) {
  567. if ($tag["url"] == "") {
  568. $tag["url"] = $searchpath . strtolower($tag["term"]);
  569. }
  570. if ($tag["type"] == TERM_HASHTAG) {
  571. $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
  572. $prefix = "#";
  573. } elseif ($tag["type"] == TERM_MENTION) {
  574. $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
  575. $prefix = "@";
  576. }
  577. $tags[] = $prefix."<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
  578. }
  579. $sp = false;
  580. $profile_link = best_link_url($item,$sp);
  581. if ($profile_link === 'mailbox') {
  582. $profile_link = '';
  583. }
  584. if ($sp) {
  585. $sparkle = ' sparkle';
  586. } else {
  587. $profile_link = zrl($profile_link);
  588. }
  589. if (!x($item, 'author-thumb') OR ($item['author-thumb'] == "")) {
  590. $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
  591. if ($author_contact["thumb"]) {
  592. $item['author-thumb'] = $author_contact["thumb"];
  593. } else {
  594. $item['author-thumb'] = $item['author-avatar'];
  595. }
  596. }
  597. if (!isset($item['owner-thumb']) OR ($item['owner-thumb'] == "")) {
  598. $owner_contact = get_contact_details_by_url($item['owner-link'], $profile_owner);
  599. if ($owner_contact["thumb"]) {
  600. $item['owner-thumb'] = $owner_contact["thumb"];
  601. } else {
  602. $item['owner-thumb'] = $item['owner-avatar'];
  603. }
  604. }
  605. $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
  606. call_hooks('render_location',$locate);
  607. $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
  608. localize_item($item);
  609. if ($mode === 'network-new') {
  610. $dropping = true;
  611. } else {
  612. $dropping = false;
  613. }
  614. $drop = array(
  615. 'dropping' => $dropping,
  616. 'pagedrop' => $page_dropping,
  617. 'select' => t('Select'),
  618. 'delete' => t('Delete'),
  619. );
  620. $star = false;
  621. $isstarred = "unstarred";
  622. $lock = false;
  623. $likebuttons = false;
  624. $shareable = false;
  625. $body = prepare_body($item, true, $preview);
  626. list($categories, $folders) = get_cats_and_terms($item);
  627. if ($a->theme['template_engine'] === 'internal') {
  628. $profile_name_e = template_escape($profile_name);
  629. $item['title_e'] = template_escape($item['title']);
  630. $body_e = template_escape($body);
  631. $tags_e = template_escape($tags);
  632. $hashtags_e = template_escape($hashtags);
  633. $mentions_e = template_escape($mentions);
  634. $location_e = template_escape($location);
  635. $owner_name_e = template_escape($owner_name);
  636. } else {
  637. $profile_name_e = $profile_name;
  638. $item['title_e'] = $item['title'];
  639. $body_e = $body;
  640. $tags_e = $tags;
  641. $hashtags_e = $hashtags;
  642. $mentions_e = $mentions;
  643. $location_e = $location;
  644. $owner_name_e = $owner_name;
  645. }
  646. if ($item['item_network'] == "") {
  647. $item['item_network'] = $item['network'];
  648. }
  649. $tmp_item = array(
  650. 'template' => $tpl,
  651. 'id' => (($preview) ? 'P0' : $item['item_id']),
  652. 'network' => $item['item_network'],
  653. 'network_name' => network_to_name($item['item_network'], $profile_link),
  654. 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
  655. 'profile_url' => $profile_link,
  656. 'item_photo_menu' => item_photo_menu($item),
  657. 'name' => $profile_name_e,
  658. 'sparkle' => $sparkle,
  659. 'lock' => $lock,
  660. 'thumb' => App::remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
  661. 'title' => $item['title_e'],
  662. 'body' => $body_e,
  663. 'tags' => $tags_e,
  664. 'hashtags' => $hashtags_e,
  665. 'mentions' => $mentions_e,
  666. 'txt_cats' => t('Categories:'),
  667. 'txt_folders' => t('Filed under:'),
  668. 'has_cats' => ((count($categories)) ? 'true' : ''),
  669. 'has_folders' => ((count($folders)) ? 'true' : ''),
  670. 'categories' => $categories,
  671. 'folders' => $folders,
  672. 'text' => strip_tags($body_e),
  673. 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
  674. 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
  675. 'location' => $location_e,
  676. 'indent' => '',
  677. 'owner_name' => $owner_name_e,
  678. 'owner_url' => $owner_url,
  679. 'owner_photo' => App::remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
  680. 'plink' => get_plink($item),
  681. 'edpost' => false,
  682. 'isstarred' => $isstarred,
  683. 'star' => $star,
  684. 'drop' => $drop,
  685. 'vote' => $likebuttons,
  686. 'like' => '',
  687. 'dislike' => '',
  688. 'comment' => '',
  689. //'conv' => (($preview) ? '' : array('href'=> 'display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
  690. 'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
  691. 'previewing' => $previewing,
  692. 'wait' => t('Please wait'),
  693. 'thread_level' => 1,
  694. );
  695. $arr = array('item' => $item, 'output' => $tmp_item);
  696. call_hooks('display_item', $arr);
  697. $threads[$threadsid]['id'] = $item['item_id'];
  698. $threads[$threadsid]['network'] = $item['item_network'];
  699. $threads[$threadsid]['items'] = array($arr['output']);
  700. }
  701. } else {
  702. // Normal View
  703. $page_template = get_markup_template("threaded_conversation.tpl");
  704. require_once 'object/Conversation.php';
  705. require_once 'object/Item.php';
  706. $conv = new Conversation($mode, $preview);
  707. /*
  708. * get all the topmost parents
  709. * this shouldn't be needed, as we should have only them in our array
  710. * But for now, this array respects the old style, just in case
  711. */
  712. $threads = array();
  713. foreach ($items as $item) {
  714. if ($arr_blocked) {
  715. $blocked = false;
  716. foreach ($arr_blocked as $b) {
  717. if ($b && link_compare($item['author-link'], $b)) {
  718. $blocked = true;
  719. break;
  720. }
  721. }
  722. if ($blocked) {
  723. continue;
  724. }
  725. }
  726. // Can we put this after the visibility check?
  727. builtin_activity_puller($item, $conv_responses);
  728. // Only add what is visible
  729. if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
  730. continue;
  731. }
  732. if (! visible_activity($item)) {
  733. continue;
  734. }
  735. call_hooks('display_item', $arr);
  736. $item['pagedrop'] = $page_dropping;
  737. if ($item['id'] == $item['parent']) {
  738. $item_object = new Item($item);
  739. $conv->add_thread($item_object);
  740. }
  741. }
  742. $threads = $conv->get_template_data($conv_responses);
  743. if (!$threads) {
  744. logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
  745. $threads = array();
  746. }
  747. }
  748. }
  749. $o = replace_macros($page_template, array(
  750. '$baseurl' => App::get_baseurl($ssl_state),
  751. '$return_path' => $a->query_string,
  752. '$live_update' => $live_update_div,
  753. '$remove' => t('remove'),
  754. '$mode' => $mode,
  755. '$user' => $a->user,
  756. '$threads' => $threads,
  757. '$dropping' => ($page_dropping && feature_enabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False),
  758. ));
  759. return $o;
  760. }}
  761. function best_link_url($item, &$sparkle, $ssl_state = false) {
  762. $best_url = '';
  763. $sparkle = false;
  764. $clean_url = normalise_link($item['author-link']);
  765. if (local_user()) {
  766. $r = q("SELECT `id` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s' AND NOT `pending` LIMIT 1",
  767. dbesc(NETWORK_DFRN), intval(local_user()), dbesc(normalise_link($clean_url)));
  768. if (dbm::is_result($r)) {
  769. $best_url = 'redir/' . $r[0]['id'];
  770. $sparkle = true;
  771. }
  772. }
  773. if (! $best_url) {
  774. if (strlen($item['author-link'])) {
  775. $best_url = $item['author-link'];
  776. } else {
  777. $best_url = $item['url'];
  778. }
  779. }
  780. return $best_url;
  781. }
  782. if (! function_exists('item_photo_menu')) {
  783. function item_photo_menu($item) {
  784. $ssl_state = false;
  785. if (local_user()) {
  786. $ssl_state = true;
  787. }
  788. $sub_link = '';
  789. $poke_link = '';
  790. $contact_url = '';
  791. $pm_url = '';
  792. $status_link = '';
  793. $photos_link = '';
  794. $posts_link = '';
  795. $network = '';
  796. if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
  797. $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
  798. }
  799. $sparkle = false;
  800. $profile_link = best_link_url($item, $sparkle, $ssl_state);
  801. if ($profile_link === 'mailbox') {
  802. $profile_link = '';
  803. }
  804. $cid = 0;
  805. $network = '';
  806. $rel = 0;
  807. $r = q("SELECT `id`, `network`, `rel` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
  808. intval(local_user()), dbesc(normalise_link($item['author-link'])));
  809. if (dbm::is_result($r)) {
  810. $cid = $r[0]['id'];
  811. $network = $r[0]['network'];
  812. $rel = $r[0]['rel'];
  813. }
  814. if ($sparkle) {
  815. $status_link = $profile_link . '?url=status';
  816. $photos_link = $profile_link . '?url=photos';
  817. $profile_link = $profile_link . '?url=profile';
  818. $zurl = '';
  819. } else {
  820. $profile_link = zrl($profile_link);
  821. }
  822. if ($cid && !$item['self']) {
  823. $poke_link = 'poke/?f=&c=' . $cid;
  824. $contact_url = 'contacts/' . $cid;
  825. $posts_link = 'contacts/' . $cid . '/posts';
  826. if (in_array($network, array(NETWORK_DFRN, NETWORK_DIASPORA))) {
  827. $pm_url = 'message/new/' . $cid;
  828. }
  829. }
  830. if (local_user()) {
  831. $menu = array(
  832. t('Follow Thread') => $sub_link,
  833. t('View Status') => $status_link,
  834. t('View Profile') => $profile_link,
  835. t('View Photos') => $photos_link,
  836. t('Network Posts') => $posts_link,
  837. t('View Contact') => $contact_url,
  838. t('Send PM') => $pm_url
  839. );
  840. if ($network == NETWORK_DFRN) {
  841. $menu[t("Poke")] = $poke_link;
  842. }
  843. if ((($cid == 0) OR ($rel == CONTACT_IS_FOLLOWER)) AND
  844. in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
  845. $menu[t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
  846. }
  847. } else {
  848. $menu = array(t('View Profile') => $item['author-link']);
  849. }
  850. $args = array('item' => $item, 'menu' => $menu);
  851. call_hooks('item_photo_menu', $args);
  852. $menu = $args['menu'];
  853. $o = '';
  854. foreach ($menu as $k => $v) {
  855. if (strpos($v, 'javascript:') === 0) {
  856. $v = substr($v, 11);
  857. $o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
  858. } elseif ($v!='') {
  859. $o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
  860. }
  861. }
  862. return $o;
  863. }}
  864. if (! function_exists('builtin_activity_puller')) {
  865. /**
  866. * @brief Checks item to see if it is one of the builtin activities (like/dislike, event attendance, consensus items, etc.)
  867. * Increments the count of each matching activity and adds a link to the author as needed.
  868. *
  869. * @param array $item
  870. * @param array &$conv_responses (already created with builtin activity structure)
  871. * @return void
  872. */
  873. function builtin_activity_puller($item, &$conv_responses) {
  874. foreach ($conv_responses as $mode => $v) {
  875. $url = '';
  876. $sparkle = '';
  877. switch ($mode) {
  878. case 'like':
  879. $verb = ACTIVITY_LIKE;
  880. break;
  881. case 'dislike':
  882. $verb = ACTIVITY_DISLIKE;
  883. break;
  884. case 'attendyes':
  885. $verb = ACTIVITY_ATTEND;
  886. break;
  887. case 'attendno':
  888. $verb = ACTIVITY_ATTENDNO;
  889. break;
  890. case 'attendmaybe':
  891. $verb = ACTIVITY_ATTENDMAYBE;
  892. break;
  893. default:
  894. return;
  895. break;
  896. }
  897. if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
  898. $url = $item['author-link'];
  899. if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) {
  900. $url = 'redir/' . $item['contact-id'];
  901. $sparkle = ' class="sparkle" ';
  902. } else {
  903. $url = zrl($url);
  904. }
  905. $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
  906. if (! $item['thr-parent']) {
  907. $item['thr-parent'] = $item['parent-uri'];
  908. }
  909. if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l']))
  910. && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) {
  911. $conv_responses[$mode][$item['thr-parent'] . '-l'] = array();
  912. }
  913. // only list each unique author once
  914. if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
  915. continue;
  916. }
  917. if (! isset($conv_responses[$mode][$item['thr-parent']])) {
  918. $conv_responses[$mode][$item['thr-parent']] = 1;
  919. } else {
  920. $conv_responses[$mode][$item['thr-parent']] ++;
  921. }
  922. if (public_contact() == $item['author-id']) {
  923. $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
  924. }
  925. $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
  926. // there can only be one activity verb per item so if we found anything, we can stop looking
  927. return;
  928. }
  929. }
  930. }}
  931. if (! function_exists('format_like')) {
  932. /**
  933. * Format the vote text for a profile item
  934. * @param int $cnt = number of people who vote the item
  935. * @param array $arr = array of pre-linked names of likers/dislikers
  936. * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
  937. * @param int $id = item id
  938. * @return formatted text
  939. */
  940. function format_like($cnt, array $arr, $type, $id) {
  941. $o = '';
  942. $expanded = '';
  943. if ($cnt == 1) {
  944. $likers = $arr[0];
  945. // Phrase if there is only one liker. In other cases it will be uses for the expanded
  946. // list which show all likers
  947. switch ($type) {
  948. case 'like' :
  949. $phrase = sprintf( t('%s likes this.'), $likers);
  950. break;
  951. case 'dislike' :
  952. $phrase = sprintf( t('%s doesn\'t like this.'), $likers);
  953. break;
  954. case 'attendyes' :
  955. $phrase = sprintf( t('%s attends.'), $likers);
  956. break;
  957. case 'attendno' :
  958. $phrase = sprintf( t('%s doesn\'t attend.'), $likers);
  959. break;
  960. case 'attendmaybe' :
  961. $phrase = sprintf( t('%s attends maybe.'), $likers);
  962. break;
  963. }
  964. }
  965. if ($cnt > 1) {
  966. $total = count($arr);
  967. if ($total >= MAX_LIKERS) {
  968. $arr = array_slice($arr, 0, MAX_LIKERS - 1);
  969. }
  970. if ($total < MAX_LIKERS) {
  971. $last = t('and') . ' ' . $arr[count($arr)-1];
  972. $arr2 = array_slice($arr, 0, -1);
  973. $str = implode(', ', $arr2) . ' ' . $last;
  974. }
  975. if ($total >= MAX_LIKERS) {
  976. $str = implode(', ', $arr);
  977. $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
  978. }
  979. $likers = $str;
  980. $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
  981. switch ($type) {
  982. case 'like':
  983. $phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
  984. $explikers = sprintf( t('%s like this.'), $likers);
  985. break;
  986. case 'dislike':
  987. $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
  988. $explikers = sprintf( t('%s don\'t like this.'), $likers);
  989. break;
  990. case 'attendyes':
  991. $phrase = sprintf( t('<span %1$s>%2$d people</span> attend'), $spanatts, $cnt);
  992. $explikers = sprintf( t('%s attend.'), $likers);
  993. break;
  994. case 'attendno':
  995. $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t attend'), $spanatts, $cnt);
  996. $explikers = sprintf( t('%s don\'t attend.'), $likers);
  997. break;
  998. case 'attendmaybe':
  999. $phrase = sprintf( t('<span %1$s>%2$d people</span> attend maybe'), $spanatts, $cnt);
  1000. $explikers = sprintf( t('%s anttend maybe.'), $likers);
  1001. break;
  1002. }
  1003. $expanded .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</div>';
  1004. }
  1005. $phrase .= EOL ;
  1006. $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
  1007. '$phrase' => $phrase,
  1008. '$type' => $type,
  1009. '$id' => $id
  1010. ));
  1011. $o .= $expanded;
  1012. return $o;
  1013. }}
  1014. function status_editor(App $a, $x, $notes_cid = 0, $popup = false) {
  1015. $o = '';
  1016. $geotag = (x($x, 'allow_location') ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
  1017. $tpl = get_markup_template('jot-header.tpl');
  1018. $a->page['htmlhead'] .= replace_macros($tpl, array(
  1019. '$newpost' => 'true',
  1020. '$baseurl' => App::get_baseurl(true),
  1021. '$geotag' => $geotag,
  1022. '$nickname' => $x['nickname'],
  1023. '$ispublic' => t('Visible to <strong>everybody</strong>'),
  1024. '$linkurl' => t('Please enter a link URL:'),
  1025. '$vidurl' => t("Please enter a video link/URL:"),
  1026. '$audurl' => t("Please enter an audio link/URL:"),
  1027. '$term' => t('Tag term:'),
  1028. '$fileas' => t('Save to Folder:'),
  1029. '$whereareu' => t('Where are you right now?'),
  1030. '$delitems' => t('Delete item(s)?')
  1031. ));
  1032. $tpl = get_markup_template('jot-end.tpl');
  1033. $a->page['end'] .= replace_macros($tpl, array(
  1034. '$newpost' => 'true',
  1035. '$baseurl' => App::get_baseurl(true),
  1036. '$geotag' => $geotag,
  1037. '$nickname' => $x['nickname'],
  1038. '$ispublic' => t('Visible to <strong>everybody</strong>'),
  1039. '$linkurl' => t('Please enter a link URL:'),
  1040. '$vidurl' => t("Please enter a video link/URL:"),
  1041. '$audurl' => t("Please enter an audio link/URL:"),
  1042. '$term' => t('Tag term:'),
  1043. '$fileas' => t('Save to Folder:'),
  1044. '$whereareu' => t('Where are you right now?')
  1045. ));
  1046. $jotplugins = '';
  1047. call_hooks('jot_tool', $jotplugins);
  1048. // Private/public post links for the non-JS ACL form
  1049. $private_post = 1;
  1050. if (x($_REQUEST, 'public')) {
  1051. $private_post = 0;
  1052. }
  1053. $query_str = $a->query_string;
  1054. if (strpos($query_str, 'public=1') !== false) {
  1055. $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
  1056. }
  1057. /*
  1058. * I think $a->query_string may never have ? in it, but I could be wrong
  1059. * It looks like it's from the index.php?q=[etc] rewrite that the web
  1060. * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
  1061. */
  1062. if (strpos($query_str, '?') === false) {
  1063. $public_post_link = '?public=1';
  1064. } else {
  1065. $public_post_link = '&public=1';
  1066. }
  1067. // $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
  1068. $tpl = get_markup_template("jot.tpl");
  1069. $o .= replace_macros($tpl,array(
  1070. '$return_path' => $query_str,
  1071. '$action' => 'item',
  1072. '$share' => (x($x,'button') ? $x['button'] : t('Share')),
  1073. '$upload' => t('Upload photo'),
  1074. '$shortupload' => t('upload photo'),
  1075. '$attach' => t('Attach file'),
  1076. '$shortattach' => t('attach file'),
  1077. '$weblink' => t('Insert web link'),
  1078. '$shortweblink' => t('web link'),
  1079. '$video' => t('Insert video link'),
  1080. '$shortvideo' => t('video link'),
  1081. '$audio' => t('Insert audio link'),
  1082. '$shortaudio' => t('audio link'),
  1083. '$setloc' => t('Set your location'),
  1084. '$shortsetloc' => t('set location'),
  1085. '$noloc' => t('Clear browser location'),
  1086. '$shortnoloc' => t('clear location'),
  1087. '$title' => $x['title'],
  1088. '$placeholdertitle' => t('Set title'),
  1089. '$category' => $x['category'],
  1090. '$placeholdercategory' => (feature_enabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''),
  1091. '$wait' => t('Please wait'),
  1092. '$permset' => t('Permission settings'),
  1093. '$shortpermset' => t('permissions'),
  1094. '$ptyp' => (($notes_cid) ? 'note' : 'wall'),
  1095. '$content' => $x['content'],
  1096. '$post_id' => $x['post_id'],
  1097. '$baseurl' => App::get_baseurl(true),
  1098. '$defloc' => $x['default_location'],
  1099. '$visitor' => $x['visitor'],
  1100. '$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
  1101. '$public' => t('Public post'),
  1102. '$jotnets' => $jotnets,
  1103. '$lockstate' => $x['lockstate'],
  1104. '$bang' => $x['bang'],
  1105. '$profile_uid' => $x['profile_uid'],
  1106. '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
  1107. '$jotplugins' => $jotplugins,
  1108. '$notes_cid' => $notes_cid,
  1109. '$sourceapp' => t($a->sourcename),
  1110. '$cancel' => t('Cancel'),
  1111. '$rand_num' => random_digits(12),
  1112. // ACL permissions box
  1113. '$acl' => $x['acl'],
  1114. '$acl_data' => $x['acl_data'],
  1115. '$group_perms' => t('Post to Groups'),
  1116. '$contact_perms' => t('Post to Contacts'),
  1117. '$private' => t('Private post'),
  1118. '$is_private' => $private_post,
  1119. '$public_link' => $public_post_link,
  1120. //jot nav tab (used in some themes)
  1121. '$message' => t('Message'),
  1122. '$browser' => t('Browser'),
  1123. ));
  1124. if ($popup == true) {
  1125. $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
  1126. }
  1127. return $o;
  1128. }
  1129. function get_item_children($arr, $parent) {
  1130. $children = array();
  1131. $a = get_app();
  1132. foreach ($arr as $item) {
  1133. if ($item['id'] != $item['parent']) {
  1134. if (get_config('system', 'thread_allow') && $a->theme_thread_allow) {
  1135. // Fallback to parent-uri if thr-parent is not set
  1136. $thr_parent = $item['thr-parent'];
  1137. if ($thr_parent == '') {
  1138. $thr_parent = $item['parent-uri'];
  1139. }
  1140. if ($thr_parent == $parent['uri']) {
  1141. $item['children'] = get_item_children($arr, $item);
  1142. $children[] = $item;
  1143. }
  1144. } elseif ($item['parent'] == $parent['id']) {
  1145. $children[] = $item;
  1146. }
  1147. }
  1148. }
  1149. return $children;
  1150. }
  1151. /// @TODO Add type-hint
  1152. function sort_item_children($items) {
  1153. $result = $items;
  1154. usort($result, 'sort_thr_created_rev');
  1155. foreach ($result as $k => $i) {
  1156. if (count($result[$k]['children'])) {
  1157. $result[$k]['children'] = sort_item_children($result[$k]['children']);
  1158. }
  1159. }
  1160. return $result;
  1161. }
  1162. /// @TODO Add type-hint
  1163. function add_children_to_list($children, &$arr) {
  1164. foreach ($children as $y) {
  1165. $arr[] = $y;
  1166. if (count($y['children'])) {
  1167. add_children_to_list($y['children'], $arr);
  1168. }
  1169. }
  1170. }
  1171. /// @TODO Add type-hint
  1172. function conv_sort($arr, $order) {
  1173. if ((!(is_array($arr) && count($arr)))) {
  1174. return array();
  1175. }
  1176. $parents = array();
  1177. $children = array();
  1178. $newarr = array();
  1179. /*
  1180. * This is a preparation for having two different items with the same uri in one thread
  1181. * This will otherwise lead to an endless loop.
  1182. */
  1183. foreach ($arr as $x) {
  1184. if (!isset($newarr[$x['uri']])) {
  1185. $newarr[$x['uri']] = $x;
  1186. }
  1187. }
  1188. $arr = $newarr;
  1189. foreach ($arr as $x) {
  1190. if ($x['id'] == $x['parent']) {
  1191. $parents[] = $x;
  1192. }
  1193. }
  1194. if (stristr($order, 'created')) {
  1195. usort($parents, 'sort_thr_created');
  1196. } elseif (stristr($order, 'commented')) {
  1197. usort($parents, 'sort_thr_commented');
  1198. }
  1199. if (count($parents)) {
  1200. foreach ($parents as $i => $_x) {
  1201. $parents[$i]['children'] = get_item_children($arr, $_x);
  1202. }
  1203. }
  1204. /// @TODO Old-lost code?
  1205. /*foreach ($arr as $x) {
  1206. if ($x['id'] != $x['parent']) {
  1207. $p = find_thread_parent_index($parents,$x);
  1208. if ($p !== false)
  1209. $parents[$p]['children'][] = $x;
  1210. }
  1211. }*/
  1212. if (count($parents)) {
  1213. foreach ($parents as $k => $v) {
  1214. if (count($parents[$k]['children'])) {
  1215. $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
  1216. /// @TODO Old-lost code?
  1217. /*$y = $parents[$k]['children'];
  1218. usort($y,'sort_thr_created_rev');
  1219. $parents[$k]['children'] = $y;*/
  1220. }
  1221. }
  1222. }
  1223. $ret = array();
  1224. if (count($parents)) {
  1225. foreach ($parents as $x) {
  1226. $ret[] = $x;
  1227. if (count($x['children'])) {
  1228. add_children_to_list($x['children'], $ret);
  1229. /// @TODO Old-lost code?
  1230. /*foreach ($x['children'] as $y)
  1231. $ret[] = $y;*/
  1232. }
  1233. }
  1234. }
  1235. return $ret;
  1236. }
  1237. /// @TODO Add type-hint
  1238. function sort_thr_created($a, $b) {
  1239. return strcmp($b['created'], $a['created']);
  1240. }
  1241. /// @TODO Add type-hint
  1242. function sort_thr_created_rev($a, $b) {
  1243. return strcmp($a['created'], $b['created']);
  1244. }
  1245. /// @TODO Add type-hint
  1246. function sort_thr_commented($a, $b) {
  1247. return strcmp($b['commented'], $a['commented']);
  1248. }
  1249. /// @TODO Add type-hint
  1250. function find_thread_parent_index($arr, $x) {
  1251. foreach ($arr as $k => $v) {
  1252. if ($v['id'] == $x['parent']) {
  1253. return $k;
  1254. }
  1255. }
  1256. return false;
  1257. }
  1258. /// @TODO Add type-hint
  1259. function render_location_dummy($item) {
  1260. if ($item['location'] != "") {
  1261. return $item['location'];
  1262. }
  1263. if ($item['coord'] != "") {
  1264. return $item['coord'];
  1265. }
  1266. }
  1267. /// @TODO Add type-hint
  1268. function get_responses($conv_responses, $response_verbs, $ob, $item) {
  1269. $ret = array();
  1270. foreach ($response_verbs as $v) {
  1271. $ret[$v] = array();
  1272. $ret[$v]['count'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri']] : '');
  1273. $ret[$v]['list'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : '');
  1274. $ret[$v]['self'] = ((x($conv_responses[$v], $item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0');
  1275. if (count($ret[$v]['list']) > MAX_LIKERS) {
  1276. $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
  1277. array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
  1278. . (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
  1279. } else {
  1280. $ret[$v]['list_part'] = '';
  1281. }
  1282. $ret[$v]['button'] = get_response_button_text($v, $ret[$v]['count']);
  1283. $ret[$v]['title'] = $conv_responses[$v]['title'];
  1284. }
  1285. $count = 0;
  1286. foreach ($ret as $key) {
  1287. if ($key['count'] == true) {
  1288. $count++;
  1289. }
  1290. }
  1291. $ret['count'] = $count;
  1292. return $ret;
  1293. }
  1294. function get_response_button_text($v, $count) {
  1295. switch ($v) {
  1296. case 'like':
  1297. return tt('Like', 'Likes', $count, 'noun');
  1298. break;
  1299. case 'dislike':
  1300. return tt('Dislike', 'Dislikes', $count, 'noun');
  1301. break;
  1302. case 'attendyes':
  1303. return tt('Attending', 'Attending', $count, 'noun');
  1304. break;
  1305. case 'attendno':
  1306. return tt('Not Attending', 'Not Attending', $count, 'noun');
  1307. break;
  1308. case 'attendmaybe':
  1309. return tt('Undecided', 'Undecided', $count, 'noun');
  1310. break;
  1311. }
  1312. }