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.
 
 
 
 
 
 

475 regels
15 KiB

  1. <?php
  2. function network_init(&$a) {
  3. if(! local_user()) {
  4. notice( t('Permission denied.') . EOL);
  5. return;
  6. }
  7. require_once('include/group.php');
  8. if(! x($a->page,'aside'))
  9. $a->page['aside'] = '';
  10. $a->page['aside'] .= '<div id="network-new-link">';
  11. if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new'))
  12. $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '">' . t('Normal View') . '</a>';
  13. else
  14. $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . '">' . t('New Item View') . '</a>';
  15. $a->page['aside'] .= '</div>';
  16. $a->page['aside'] .= group_side('network','network');
  17. }
  18. function network_content(&$a, $update = 0) {
  19. if(! local_user())
  20. return login(false);
  21. $o = '';
  22. require_once("include/bbcode.php");
  23. $contact_id = $a->cid;
  24. $group = 0;
  25. $nouveau = false;
  26. require_once('include/acl_selectors.php');
  27. if(($a->argc > 2) && $a->argv[2] === 'new')
  28. $nouveau = true;
  29. if($a->argc > 1) {
  30. if($a->argv[1] === 'new')
  31. $nouveau = true;
  32. else {
  33. $group = intval($a->argv[1]);
  34. $group_acl = array('allow_gid' => '<' . $group . '>');
  35. }
  36. }
  37. if(! $update) {
  38. $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
  39. $_SESSION['return_url'] = $a->cmd;
  40. $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
  41. $tpl = load_view_file('view/jot-header.tpl');
  42. $a->page['htmlhead'] .= replace_macros($tpl, array(
  43. '$baseurl' => $a->get_baseurl(),
  44. '$geotag' => $geotag,
  45. '$nickname' => $a->user['nickname']
  46. ));
  47. $tpl = load_view_file("view/jot.tpl");
  48. if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))))
  49. $lockstate = 'lock';
  50. else
  51. $lockstate = 'unlock';
  52. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  53. $jotplugins = '';
  54. $jotnets = '';
  55. call_hooks('jot_tool', $jotplugins);
  56. call_hooks('jot_networks', $jotnets);
  57. $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
  58. $o .= replace_macros($tpl,array(
  59. '$return_path' => $a->cmd,
  60. '$action' => 'item',
  61. '$share' => t('Share'),
  62. '$upload' => t('Upload photo'),
  63. '$weblink' => t('Insert web link'),
  64. '$youtube' => t('Insert YouTube video'),
  65. '$setloc' => t('Set your location'),
  66. '$noloc' => t('Clear browser location'),
  67. '$wait' => t('Please wait'),
  68. '$permset' => t('Permission settings'),
  69. '$content' => '',
  70. '$post_id' => '',
  71. '$baseurl' => $a->get_baseurl(),
  72. '$defloc' => $a->user['default-location'],
  73. '$visitor' => 'block',
  74. '$emailcc' => t('CC: email addresses'),
  75. '$jotnets' => $jotnets,
  76. '$emtitle' => t('Example: bob@example.com, mary@example.com'),
  77. '$lockstate' => $lockstate,
  78. '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
  79. '$bang' => (($group) ? '!' : ''),
  80. '$profile_uid' => $_SESSION['uid']
  81. ));
  82. // The special div is needed for liveUpdate to kick in for this page.
  83. // We only launch liveUpdate if you are on the front page, you aren't
  84. // filtering by group and also you aren't writing a comment (the last
  85. // criteria is discovered in javascript).
  86. $o .= '<div id="live-network"></div>' . "\r\n";
  87. $o .= "<script> var profile_uid = " . $_SESSION['uid']
  88. . "; var netargs = '" . substr($a->cmd,8)
  89. . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  90. }
  91. // We aren't going to try and figure out at the item, group, and page level
  92. // which items you've seen and which you haven't. You're looking at some
  93. // subset of items, so just mark everything seen.
  94. $r = q("UPDATE `item` SET `unseen` = 0
  95. WHERE `unseen` = 1 AND `uid` = %d",
  96. intval($_SESSION['uid'])
  97. );
  98. // We don't have to deal with ACL's on this page. You're looking at everything
  99. // that belongs to you, hence you can see all of it. We will filter by group if
  100. // desired.
  101. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
  102. if($group) {
  103. $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  104. intval($group),
  105. intval($_SESSION['uid'])
  106. );
  107. if(! count($r)) {
  108. if($update)
  109. killme();
  110. notice( t('No such group') . EOL );
  111. goaway($a->get_baseurl() . '/network');
  112. return; // NOTREACHED
  113. }
  114. $contacts = expand_groups(array($group));
  115. if((is_array($contacts)) && count($contacts)) {
  116. $contact_str = implode(',',$contacts);
  117. }
  118. else {
  119. $contact_str = ' 0 ';
  120. notice( t('Group is empty'));
  121. }
  122. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
  123. $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
  124. }
  125. if((! $group) && (! $update))
  126. $o .= get_birthdays();
  127. $r = q("SELECT COUNT(*) AS `total`
  128. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  129. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  130. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  131. $sql_extra ",
  132. intval($_SESSION['uid'])
  133. );
  134. if(count($r))
  135. $a->set_pager_total($r[0]['total']);
  136. if($nouveau) {
  137. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  138. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
  139. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  140. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  141. FROM `item`, `contact`
  142. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  143. AND `contact`.`id` = `item`.`contact-id`
  144. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  145. $sql_extra
  146. ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
  147. intval($_SESSION['uid']),
  148. intval($a->pager['start']),
  149. intval($a->pager['itemspage'])
  150. );
  151. }
  152. else {
  153. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  154. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
  155. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  156. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  157. FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
  158. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  159. AND `contact`.`id` = `item`.`contact-id`
  160. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  161. AND `item`.`parent` = `parentitem`.`id`
  162. $sql_extra
  163. ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC LIMIT %d ,%d ",
  164. intval(local_user()),
  165. intval($a->pager['start']),
  166. intval($a->pager['itemspage'])
  167. );
  168. }
  169. $author_contacts = extract_item_authors($r,local_user());
  170. $cmnt_tpl = load_view_file('view/comment_item.tpl');
  171. $like_tpl = load_view_file('view/like.tpl');
  172. $tpl = load_view_file('view/wall_item.tpl');
  173. $wallwall = load_view_file('view/wallwall_item.tpl');
  174. $alike = array();
  175. $dlike = array();
  176. if(count($r)) {
  177. if($nouveau) {
  178. $tpl = load_view_file('view/search_item.tpl');
  179. $droptpl = load_view_file('view/wall_fake_drop.tpl');
  180. foreach($r as $item) {
  181. $comment = '';
  182. $owner_url = '';
  183. $owner_photo = '';
  184. $owner_name = '';
  185. $sparkle = '';
  186. $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
  187. $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
  188. $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  189. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  190. if(strlen($item['author-link'])) {
  191. if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
  192. $profile_link = $redirect_url;
  193. $sparkle = ' sparkle';
  194. }
  195. elseif(isset($author_contacts[$item['author-link']])) {
  196. $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
  197. $sparkle = ' sparkle';
  198. }
  199. }
  200. $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  201. $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  202. if($coord) {
  203. if($location)
  204. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  205. else
  206. $location = '<span class="smalltext">' . $coord . '</span>';
  207. }
  208. $drop = replace_macros($droptpl,array('$id' => $item['id']));
  209. $lock = '<div class="wall-item-lock"></div>';
  210. $o .= replace_macros($tpl,array(
  211. '$id' => $item['item_id'],
  212. '$linktitle' => t('View $name\'s profile'),
  213. '$profile_url' => $profile_link,
  214. '$name' => $profile_name,
  215. '$sparkle' => $sparkle,
  216. '$lock' => $lock,
  217. '$thumb' => $profile_avatar,
  218. '$title' => $item['title'],
  219. '$body' => smilies(bbcode($item['body'])),
  220. '$ago' => relative_date($item['created']),
  221. '$location' => $location,
  222. '$indent' => '',
  223. '$owner_url' => $owner_url,
  224. '$owner_photo' => $owner_photo,
  225. '$owner_name' => $owner_name,
  226. '$drop' => $drop,
  227. '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
  228. ));
  229. }
  230. $o .= paginate($a);
  231. return $o;
  232. }
  233. foreach($r as $item) {
  234. like_puller($a,$item,$alike,'like');
  235. like_puller($a,$item,$dlike,'dislike');
  236. }
  237. foreach($r as $item) {
  238. $comment = '';
  239. $template = $tpl;
  240. $commentww = '';
  241. $sparkle = '';
  242. $owner_url = $owner_photo = $owner_name = '';
  243. if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
  244. continue;
  245. $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
  246. $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  247. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  248. ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
  249. : '<div class="wall-item-lock"></div>');
  250. // Top-level wall post not written by the wall owner (wall-to-wall)
  251. // First figure out who owns it.
  252. $osparkle = '';
  253. if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
  254. if($item['type'] === 'wall') {
  255. // I do. Put me on the left of the wall-to-wall notice.
  256. $owner_url = $a->contact['url'];
  257. $owner_photo = $a->contact['thumb'];
  258. $owner_name = $a->contact['name'];
  259. $template = $wallwall;
  260. $commentww = 'ww';
  261. }
  262. if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
  263. // Could be anybody.
  264. $owner_url = $item['owner-link'];
  265. $owner_photo = $item['owner-avatar'];
  266. $owner_name = $item['owner-name'];
  267. $template = $wallwall;
  268. $commentww = 'ww';
  269. // If it is our contact, use a friendly redirect link
  270. if((link_compare($item['owner-link'],$item['url']))
  271. && ($item['network'] === 'dfrn')) {
  272. $owner_url = $redirect_url;
  273. $osparkle = ' sparkle';
  274. }
  275. }
  276. }
  277. if($update)
  278. $return_url = $_SESSION['return_url'];
  279. else
  280. $return_url = $_SESSION['return_url'] = $a->cmd;
  281. $likebuttons = '';
  282. if($item['id'] == $item['parent']) {
  283. $likebuttons = replace_macros($like_tpl,array(
  284. '$id' => $item['id'],
  285. '$likethis' => t("I like this \x28toggle\x29"),
  286. '$nolike' => t("I don't like this \x28toggle\x29"),
  287. '$wait' => t('Please wait')
  288. ));
  289. }
  290. if($item['last-child']) {
  291. $comment = replace_macros($cmnt_tpl,array(
  292. '$return_path' => '',
  293. '$jsreload' => '', // $_SESSION['return_url'],
  294. '$type' => 'net-comment',
  295. '$id' => $item['item_id'],
  296. '$parent' => $item['parent'],
  297. '$profile_uid' => $_SESSION['uid'],
  298. '$mylink' => $a->contact['url'],
  299. '$mytitle' => t('This is you'),
  300. '$myphoto' => $a->contact['thumb'],
  301. '$ww' => $commentww
  302. ));
  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(strlen($item['author-link'])) {
  312. $profile_link = $item['author-link'];
  313. if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
  314. $profile_link = $redirect_url;
  315. $sparkle = ' sparkle';
  316. }
  317. elseif(isset($author_contacts[$item['author-link']])) {
  318. $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
  319. $sparkle = ' sparkle';
  320. }
  321. }
  322. else
  323. $profile_link = $item['url'];
  324. $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
  325. $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
  326. $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
  327. $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
  328. if($coord) {
  329. if($location)
  330. $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
  331. else
  332. $location = '<span class="smalltext">' . $coord . '</span>';
  333. }
  334. $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
  335. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
  336. $indent .= ' shiny';
  337. // Build the HTML
  338. $tmp_item = replace_macros($template,array(
  339. '$id' => $item['item_id'],
  340. '$linktitle' => t('View $name\'s profile'),
  341. '$olinktitle' => t('View $owner_name\'s profile'),
  342. '$to' => t('to'),
  343. '$wall' => t('Wall-to-Wall'),
  344. '$vwall' => t('via Wall-To-Wall:'),
  345. '$profile_url' => $profile_link,
  346. '$name' => $profile_name,
  347. '$thumb' => $profile_avatar,
  348. '$osparkle' => $osparkle,
  349. '$sparkle' => $sparkle,
  350. '$title' => $item['title'],
  351. '$body' => smilies(bbcode($item['body'])),
  352. '$ago' => relative_date($item['created']),
  353. '$lock' => $lock,
  354. '$location' => $location,
  355. '$indent' => $indent,
  356. '$owner_url' => $owner_url,
  357. '$owner_photo' => $owner_photo,
  358. '$owner_name' => $owner_name,
  359. '$plink' => get_plink($item),
  360. '$drop' => $drop,
  361. '$vote' => $likebuttons,
  362. '$like' => $like,
  363. '$dislike' => $dislike,
  364. '$comment' => $comment
  365. ));
  366. $arr = array('item' => $item, 'output' => $tmp_item);
  367. call_hooks('display_item', $arr);
  368. $o .= $arr['output'];
  369. }
  370. }
  371. if(! $update) {
  372. $o .= paginate($a);
  373. $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>';
  374. }
  375. return $o;
  376. }