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.
 
 
 
 
 
 

317 lines
9.4 KiB

  1. <?php
  2. function display_content(&$a) {
  3. $o = '<div id="live-display"></div>' . "\r\n";
  4. $nick = (($a->argc > 1) ? $a->argv[1] : '');
  5. profile_load($a,$nick);
  6. $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
  7. if(! $item_id) {
  8. $a->error = 404;
  9. notice( t('Item not found.') . EOL);
  10. return;
  11. }
  12. require_once("include/bbcode.php");
  13. require_once('include/security.php');
  14. $groups = array();
  15. $tab = 'posts';
  16. $contact = null;
  17. $remote_contact = false;
  18. if(remote_user()) {
  19. $contact_id = $_SESSION['visitor_id'];
  20. $groups = init_groups_visitor($contact_id);
  21. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  22. intval($contact_id),
  23. intval($a->profile['uid'])
  24. );
  25. if(count($r)) {
  26. $contact = $r[0];
  27. $remote_contact = true;
  28. }
  29. }
  30. if(! $remote_contact) {
  31. if(local_user()) {
  32. $contact_id = $_SESSION['cid'];
  33. $contact = $a->contact;
  34. }
  35. }
  36. $sql_extra = "
  37. AND `allow_cid` = ''
  38. AND `allow_gid` = ''
  39. AND `deny_cid` = ''
  40. AND `deny_gid` = ''
  41. ";
  42. // Profile owner - everything is visible
  43. if(local_user() && (local_user() == $a->profile['uid'])) {
  44. $sql_extra = '';
  45. }
  46. // authenticated visitor - here lie dragons
  47. // If $remotecontact is true, we know that not only is this a remotely authenticated
  48. // person, but that it is *our* contact, which is important in multi-user mode.
  49. elseif($remote_contact) {
  50. $gs = '<<>>'; // should be impossible to match
  51. if(count($groups)) {
  52. foreach($groups as $g)
  53. $gs .= '|<' . intval($g) . '>';
  54. }
  55. $sql_extra = sprintf(
  56. " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
  57. AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
  58. AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
  59. AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
  60. intval($_SESSION['visitor_id']),
  61. intval($_SESSION['visitor_id']),
  62. dbesc($gs),
  63. dbesc($gs)
  64. );
  65. }
  66. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  67. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
  68. `contact`.`network`, `contact`.`thumb`, `contact`.`self`,
  69. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  70. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  71. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  72. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  73. AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
  74. $sql_extra
  75. ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
  76. intval($a->profile['uid']),
  77. dbesc($item_id),
  78. dbesc($item_id)
  79. );
  80. $cmnt_tpl = load_view_file('view/comment_item.tpl');
  81. $like_tpl = load_view_file('view/like.tpl');
  82. $tpl = load_view_file('view/wall_item.tpl');
  83. $wallwall = load_view_file('view/wallwall_item.tpl');
  84. $return_url = $_SESSION['return_url'] = $a->cmd;
  85. $alike = array();
  86. $dlike = array();
  87. if(count($r)) {
  88. if((local_user()) && (local_user() == $a->profile['uid'])) {
  89. q("UPDATE `item` SET `unseen` = 0
  90. WHERE `parent` = %d AND `unseen` = 1",
  91. intval($r[0]['parent'])
  92. );
  93. }
  94. foreach($r as $item) {
  95. like_puller($a,$item,$alike,'like');
  96. like_puller($a,$item,$dlike,'dislike');
  97. }
  98. $author_contacts = extract_item_authors($r,$a->profile['uid']);
  99. foreach($r as $item) {
  100. $template = $tpl;
  101. $comment = '';
  102. $owner_url = '';
  103. $owner_photo = '';
  104. $owner_name = '';
  105. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  106. if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
  107. && ($item['id'] != $item['parent']))
  108. continue;
  109. $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  110. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  111. ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
  112. : '<div class="wall-item-lock"></div>');
  113. if(can_write_wall($a,$a->profile['uid'])) {
  114. if($item['id'] == $item['parent']) {
  115. $likebuttons = replace_macros($like_tpl,array(
  116. '$id' => $item['id'],
  117. '$likethis' => t("I like this \x28toggle\x29"),
  118. '$nolike' => t("I don't like this \x28toggle\x29"),
  119. '$wait' => t('Please wait')
  120. ));
  121. }
  122. if($item['last-child']) {
  123. $comment = replace_macros($cmnt_tpl,array(
  124. '$return_path' => '',
  125. '$jsreload' => $_SESSION['return_url'],
  126. '$type' => 'wall-comment',
  127. '$id' => $item['item_id'],
  128. '$parent' => $item['parent'],
  129. '$profile_uid' => $a->profile['uid'],
  130. '$mylink' => $contact['url'],
  131. '$mytitle' => t('This is you'),
  132. '$myphoto' => $contact['thumb'],
  133. '$ww' => ''
  134. ));
  135. }
  136. }
  137. $profile_url = $item['url'];
  138. $sparkle = '';
  139. // Top-level wall post not written by the wall owner (wall-to-wall)
  140. // First figure out who owns it.
  141. $osparkle = '';
  142. if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
  143. if($item['type'] === 'wall') {
  144. // I do. Put me on the left of the wall-to-wall notice.
  145. $owner_url = $a->contact['url'];
  146. $owner_photo = $a->contact['thumb'];
  147. $owner_name = $a->contact['name'];
  148. $template = $wallwall;
  149. $commentww = 'ww';
  150. }
  151. if($item['type'] === 'remote' && ($item['owner-link'] != $item['author-link'])) {
  152. // Could be anybody.
  153. $owner_url = $item['owner-link'];
  154. $owner_photo = $item['owner-avatar'];
  155. $owner_name = $item['owner-name'];
  156. $template = $wallwall;
  157. $commentww = 'ww';
  158. // If it is our contact, use a friendly redirect link
  159. if((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === 'dfrn')) {
  160. $owner_url = $redirect_url;
  161. $osparkle = ' sparkle';
  162. }
  163. }
  164. }
  165. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  166. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  167. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
  168. // Can we use our special contact URL for this author?
  169. if(strlen($item['author-link'])) {
  170. $profile_link = $item['author-link'];
  171. if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
  172. $profile_link = $redirect_url;
  173. $sparkle = ' sparkle';
  174. }
  175. elseif(isset($author_contacts[$item['author-link']])) {
  176. $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
  177. $sparkle = ' sparkle';
  178. }
  179. }
  180. if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  181. $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
  182. else
  183. $drop = replace_macros(load_view_file('view/wall_fake_drop.tpl'), array('$id' => $item['id']));
  184. $like = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
  185. $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
  186. $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  187. $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  188. if($coord) {
  189. if($location)
  190. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  191. else
  192. $location = '<span class="smalltext">' . $coord . '</span>';
  193. }
  194. $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
  195. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  196. $indent .= ' shiny';
  197. $tmp_item = replace_macros($template,array(
  198. '$id' => $item['item_id'],
  199. '$linktitle' => t('View $name\'s profile'),
  200. '$olinktitle' => t('View $owner_name\'s profile'),
  201. '$to' => t('to'),
  202. '$wall' => t('Wall-to-Wall'),
  203. '$vwall' => t('via Wall-To-Wall:'),
  204. '$profile_url' => $profile_link,
  205. '$name' => $profile_name,
  206. '$sparkle' => $sparkle,
  207. '$osparkle' => $osparkle,
  208. '$thumb' => $profile_avatar,
  209. '$title' => $item['title'],
  210. '$body' => smilies(bbcode($item['body'])),
  211. '$ago' => relative_date($item['created']),
  212. '$lock' => $lock,
  213. '$location' => $location,
  214. '$indent' => $indent,
  215. '$owner_url' => $owner_url,
  216. '$owner_photo' => $owner_photo,
  217. '$owner_name' => $owner_name,
  218. '$plink' => get_plink($item),
  219. '$drop' => $drop,
  220. '$vote' => $likebuttons,
  221. '$like' => $like,
  222. '$dislike' => $dislike,
  223. '$comment' => $comment
  224. ));
  225. $arr = array('item' => $item, 'output' => $tmp_item);
  226. call_hooks('display_item', $arr);
  227. $o .= $arr['output'];
  228. }
  229. }
  230. else {
  231. $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
  232. dbesc($item_id),
  233. dbesc($item_id)
  234. );
  235. if(count($r)) {
  236. if($r[0]['deleted']) {
  237. notice( t('Item has been removed.') . EOL );
  238. }
  239. else {
  240. notice( t('Permission denied.') . EOL );
  241. }
  242. }
  243. else {
  244. notice( t('Item not found.') . EOL );
  245. }
  246. }
  247. $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
  248. return $o;
  249. }