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.

324 lines
9.9 KiB

11 years ago
11 years ago
11 years ago
11 years ago
10 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. 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_noshare.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. '$share' => t('Share'),
  120. '$wait' => t('Please wait')
  121. ));
  122. }
  123. if($item['last-child']) {
  124. $comment = replace_macros($cmnt_tpl,array(
  125. '$return_path' => '',
  126. '$jsreload' => $_SESSION['return_url'],
  127. '$type' => 'wall-comment',
  128. '$id' => $item['item_id'],
  129. '$parent' => $item['parent'],
  130. '$profile_uid' => $a->profile['uid'],
  131. '$mylink' => $contact['url'],
  132. '$mytitle' => t('This is you'),
  133. '$myphoto' => $contact['thumb'],
  134. '$comment' => t('Comment'),
  135. '$submit' => t('Submit'),
  136. '$ww' => ''
  137. ));
  138. }
  139. }
  140. $profile_url = $item['url'];
  141. $sparkle = '';
  142. // Top-level wall post not written by the wall owner (wall-to-wall)
  143. // First figure out who owns it.
  144. $osparkle = '';
  145. if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
  146. if($item['type'] === 'wall') {
  147. // I do. Put me on the left of the wall-to-wall notice.
  148. $owner_url = $a->contact['url'];
  149. $owner_photo = $a->contact['thumb'];
  150. $owner_name = $a->contact['name'];
  151. $template = $wallwall;
  152. $commentww = 'ww';
  153. }
  154. if($item['type'] === 'remote' && ($item['owner-link'] != $item['author-link'])) {
  155. // Could be anybody.
  156. $owner_url = $item['owner-link'];
  157. $owner_photo = $item['owner-avatar'];
  158. $owner_name = $item['owner-name'];
  159. $template = $wallwall;
  160. $commentww = 'ww';
  161. // If it is our contact, use a friendly redirect link
  162. if((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === 'dfrn')) {
  163. $owner_url = $redirect_url;
  164. $osparkle = ' sparkle';
  165. }
  166. }
  167. }
  168. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  169. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  170. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
  171. $edpost = '';
  172. if((local_user()) && ($item['uid'] == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
  173. $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
  174. // Can we use our special contact URL for this author?
  175. if(strlen($item['author-link'])) {
  176. $profile_link = $item['author-link'];
  177. if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
  178. $profile_link = $redirect_url;
  179. $sparkle = ' sparkle';
  180. }
  181. elseif(isset($author_contacts[$item['author-link']])) {
  182. $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
  183. $sparkle = ' sparkle';
  184. }
  185. }
  186. if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
  187. $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
  188. else
  189. $drop = replace_macros(load_view_file('view/wall_fake_drop.tpl'), array('$id' => $item['id']));
  190. $like = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
  191. $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
  192. $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  193. $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  194. if($coord) {
  195. if($location)
  196. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  197. else
  198. $location = '<span class="smalltext">' . $coord . '</span>';
  199. }
  200. $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
  201. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  202. $indent .= ' shiny';
  203. $tmp_item = replace_macros($template,array(
  204. '$id' => $item['item_id'],
  205. '$linktitle' => t('View $name\'s profile'),
  206. '$olinktitle' => t('View $owner_name\'s profile'),
  207. '$to' => t('to'),
  208. '$wall' => t('Wall-to-Wall'),
  209. '$vwall' => t('via Wall-To-Wall:'),
  210. '$item_photo_menu' => item_photo_menu($item),
  211. '$profile_url' => $profile_link,
  212. '$name' => $profile_name,
  213. '$sparkle' => $sparkle,
  214. '$osparkle' => $osparkle,
  215. '$thumb' => $profile_avatar,
  216. '$title' => $item['title'],
  217. '$body' => smilies(bbcode($item['body'])),
  218. '$ago' => relative_date($item['created']),
  219. '$lock' => $lock,
  220. '$location' => $location,
  221. '$indent' => $indent,
  222. '$owner_url' => $owner_url,
  223. '$owner_photo' => $owner_photo,
  224. '$owner_name' => $owner_name,
  225. '$plink' => get_plink($item),
  226. '$edpost' => $edpost,
  227. '$drop' => $drop,
  228. '$vote' => $likebuttons,
  229. '$like' => $like,
  230. '$dislike' => $dislike,
  231. '$comment' => $comment
  232. ));
  233. $arr = array('item' => $item, 'output' => $tmp_item);
  234. call_hooks('display_item', $arr);
  235. $o .= $arr['output'];
  236. }
  237. }
  238. else {
  239. $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
  240. dbesc($item_id),
  241. dbesc($item_id)
  242. );
  243. if(count($r)) {
  244. if($r[0]['deleted']) {
  245. notice( t('Item has been removed.') . EOL );
  246. }
  247. else {
  248. notice( t('Permission denied.') . EOL );
  249. }
  250. }
  251. else {
  252. notice( t('Item not found.') . EOL );
  253. }
  254. }
  255. $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>';
  256. return $o;
  257. }