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.
 
 
 
 
 
 

282 lines
8.9 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',true);
  17. }
  18. function network_content(&$a, $update = 0) {
  19. require_once('include/conversation.php');
  20. if(! local_user())
  21. return login(false);
  22. $o = '';
  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. if(group) {
  39. if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  40. $plural_form = sprintf( tt('%d member', '%d members', $t), $t);
  41. notice( sprintf( t('Warning: This group contains %s from an insecure network.'), $plural_form ) . EOL);
  42. notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
  43. }
  44. }
  45. $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
  46. $_SESSION['return_url'] = $a->cmd;
  47. $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
  48. $tpl = load_view_file('view/jot-header.tpl');
  49. $a->page['htmlhead'] .= replace_macros($tpl, array(
  50. '$baseurl' => $a->get_baseurl(),
  51. '$geotag' => $geotag,
  52. '$nickname' => $a->user['nickname'],
  53. '$linkurl' => t('Please enter a link URL:'),
  54. '$utubeurl' => t('Please enter a YouTube link:'),
  55. '$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
  56. '$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
  57. '$whereareu' => t('Where are you right now?'),
  58. '$title' => t('Enter a title for this item')
  59. ));
  60. $tpl = load_view_file("view/jot.tpl");
  61. 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'])))))
  62. $lockstate = 'lock';
  63. else
  64. $lockstate = 'unlock';
  65. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  66. $jotplugins = '';
  67. $jotnets = '';
  68. call_hooks('jot_tool', $jotplugins);
  69. call_hooks('jot_networks', $jotnets);
  70. $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
  71. $o .= replace_macros($tpl,array(
  72. '$return_path' => $a->cmd,
  73. '$action' => 'item',
  74. '$share' => t('Share'),
  75. '$upload' => t('Upload photo'),
  76. '$weblink' => t('Insert web link'),
  77. '$youtube' => t('Insert YouTube video'),
  78. '$video' => t('Insert Vorbis [.ogg] video'),
  79. '$audio' => t('Insert Vorbis [.ogg] audio'),
  80. '$setloc' => t('Set your location'),
  81. '$noloc' => t('Clear browser location'),
  82. '$title' => t('Set title'),
  83. '$wait' => t('Please wait'),
  84. '$permset' => t('Permission settings'),
  85. '$content' => '',
  86. '$post_id' => '',
  87. '$baseurl' => $a->get_baseurl(),
  88. '$defloc' => $a->user['default-location'],
  89. '$visitor' => 'block',
  90. '$emailcc' => t('CC: email addresses'),
  91. '$jotnets' => $jotnets,
  92. '$emtitle' => t('Example: bob@example.com, mary@example.com'),
  93. '$lockstate' => $lockstate,
  94. '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
  95. '$bang' => (($group) ? '!' : ''),
  96. '$profile_uid' => local_user()
  97. ));
  98. // The special div is needed for liveUpdate to kick in for this page.
  99. // We only launch liveUpdate if you are on the front page, you aren't
  100. // filtering by group and also you aren't writing a comment (the last
  101. // criteria is discovered in javascript).
  102. $o .= '<div id="live-network"></div>' . "\r\n";
  103. $o .= "<script> var profile_uid = " . $_SESSION['uid']
  104. . "; var netargs = '" . substr($a->cmd,8)
  105. . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  106. }
  107. // We aren't going to try and figure out at the item, group, and page level
  108. // which items you've seen and which you haven't. You're looking at some
  109. // subset of items, so just mark everything seen.
  110. $r = q("UPDATE `item` SET `unseen` = 0
  111. WHERE `unseen` = 1 AND `uid` = %d",
  112. intval($_SESSION['uid'])
  113. );
  114. // We don't have to deal with ACL's on this page. You're looking at everything
  115. // that belongs to you, hence you can see all of it. We will filter by group if
  116. // desired.
  117. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
  118. if($group) {
  119. $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  120. intval($group),
  121. intval($_SESSION['uid'])
  122. );
  123. if(! count($r)) {
  124. if($update)
  125. killme();
  126. notice( t('No such group') . EOL );
  127. goaway($a->get_baseurl() . '/network');
  128. return; // NOTREACHED
  129. }
  130. $contacts = expand_groups(array($group));
  131. if((is_array($contacts)) && count($contacts)) {
  132. $contact_str = implode(',',$contacts);
  133. }
  134. else {
  135. $contact_str = ' 0 ';
  136. notice( t('Group is empty'));
  137. }
  138. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
  139. $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
  140. }
  141. if((! $group) && (! $update))
  142. $o .= get_birthdays();
  143. $r = q("SELECT COUNT(*) AS `total`
  144. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  145. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  146. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  147. $sql_extra ",
  148. intval($_SESSION['uid'])
  149. );
  150. if(count($r)) {
  151. $a->set_pager_total($r[0]['total']);
  152. $a->set_pager_itemspage(40);
  153. }
  154. if($nouveau) {
  155. // "New Item View" - show all items unthreaded in reverse created date order
  156. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  157. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  158. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  159. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  160. FROM `item`, `contact`
  161. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  162. AND `contact`.`id` = `item`.`contact-id`
  163. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  164. $sql_extra
  165. ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
  166. intval($_SESSION['uid']),
  167. intval($a->pager['start']),
  168. intval($a->pager['itemspage'])
  169. );
  170. }
  171. else {
  172. // Normal conversation view
  173. // First fetch a known number of parent items
  174. $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
  175. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  176. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  177. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  178. AND `item`.`parent` = `item`.`id`
  179. $sql_extra
  180. ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
  181. intval(local_user()),
  182. intval($a->pager['start']),
  183. intval($a->pager['itemspage'])
  184. );
  185. // Then fetch all the children of the parents that are on this page
  186. $parents_arr = array();
  187. $parents_str = '';
  188. if(count($r)) {
  189. foreach($r as $rr)
  190. $parents_arr[] = $rr['item_id'];
  191. $parents_str = implode(', ', $parents_arr);
  192. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  193. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  194. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  195. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  196. FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
  197. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  198. AND `contact`.`id` = `item`.`contact-id`
  199. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  200. AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
  201. $sql_extra
  202. ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
  203. intval(local_user()),
  204. dbesc($parents_str)
  205. );
  206. }
  207. }
  208. // Set this so that the conversation function can find out contact info for our wall-wall items
  209. $a->page_contact = $a->contact;
  210. $mode = (($nouveau) ? 'network-new' : 'network');
  211. $o .= conversation($a,$r,$mode,$update);
  212. if(! $update) {
  213. $o .= paginate($a);
  214. $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>';
  215. }
  216. return $o;
  217. }