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.

306 lines
10 KiB

11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. function network_init(&$a) {
  3. if(! local_user()) {
  4. notice( t('Permission denied.') . EOL);
  5. return;
  6. }
  7. $group_id = (($a->argc > 1 && intval($a->argv[1])) ? intval($a->argv[1]) : 0);
  8. require_once('include/group.php');
  9. if(! x($a->page,'aside'))
  10. $a->page['aside'] = '';
  11. $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
  12. $srchurl = '/network' . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '');
  13. $a->page['aside'] .= search($search,'netsearch-box',$srchurl);
  14. $a->page['aside'] .= '<div id="network-new-link">';
  15. $a->page['aside'] .= '<div id="network-view-link">';
  16. if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new') || x($_GET,'search'))
  17. $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . '">' . t('Normal View') . '</a></div>';
  18. else {
  19. $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('New Item View') . '</a></div>';
  20. if(x($_GET,'star'))
  21. $a->page['aside'] .= '<div id="network-star-link">'
  22. . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd
  23. . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">'
  24. . t('View Any Items') . '</a>'
  25. . '<span class="network-star icon starred"></span>'
  26. . '<span class="network-star icon unstarred"></span>'
  27. . '<div class="clear"></div></div>';
  28. else
  29. $a->page['aside'] .= '<div id="network-star-link">'
  30. . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd
  31. . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1" >'
  32. . t('View Starred Items') . '</a>'
  33. . '<span class="network-star icon starred"></span>'
  34. . '<div class="clear"></div></div>';
  35. }
  36. $a->page['aside'] .= '</div>';
  37. $a->page['aside'] .= group_side('network','network',true,$group_id);
  38. }
  39. function network_content(&$a, $update = 0) {
  40. require_once('include/conversation.php');
  41. if(! local_user())
  42. return login(false);
  43. $o = '';
  44. $contact_id = $a->cid;
  45. $group = 0;
  46. $nouveau = false;
  47. require_once('include/acl_selectors.php');
  48. $cid = ((x($_GET['cid'])) ? intval($_GET['cid']) : 0);
  49. $star = ((x($_GET['star'])) ? intval($_GET['star']) : 0);
  50. if(($a->argc > 2) && $a->argv[2] === 'new')
  51. $nouveau = true;
  52. if($a->argc > 1) {
  53. if($a->argv[1] === 'new')
  54. $nouveau = true;
  55. else {
  56. $group = intval($a->argv[1]);
  57. $def_acl = array('allow_gid' => '<' . $group . '>');
  58. }
  59. }
  60. if(x($_GET,'search'))
  61. $nouveau = true;
  62. if($cid)
  63. $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
  64. if(! $update) {
  65. if(group) {
  66. if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  67. notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
  68. 'Warning: This group contains %s members from an insecure network.',
  69. $t), $t ) . EOL);
  70. notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
  71. }
  72. }
  73. $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
  74. $_SESSION['return_url'] = $a->cmd;
  75. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  76. $x = array(
  77. 'is_owner' => true,
  78. 'allow_location' => $a->user['allow_location'],
  79. 'default_location' => $a->user['default_location'],
  80. 'nickname' => $a->user['nickname'],
  81. 'lockstate' => ((($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']))))) ? 'lock' : 'unlock'),
  82. 'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
  83. 'bang' => (($group || $cid) ? '!' : ''),
  84. 'visitor' => 'block',
  85. 'profile_uid' => local_user()
  86. );
  87. $o .= status_editor($a,$x);
  88. // The special div is needed for liveUpdate to kick in for this page.
  89. // We only launch liveUpdate if you are on the front page, you aren't
  90. // filtering by group and also you aren't writing a comment (the last
  91. // criteria is discovered in javascript).
  92. $o .= '<div id="live-network"></div>' . "\r\n";
  93. $o .= "<script> var profile_uid = " . $_SESSION['uid']
  94. . "; var netargs = '" . substr($a->cmd,8)
  95. . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '')
  96. . ((x($_GET,'search')) ? '?search=' . $_GET['search'] : '')
  97. . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
  98. . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  99. }
  100. // We aren't going to try and figure out at the item, group, and page
  101. // level which items you've seen and which you haven't. If you're looking
  102. // at the top level network page just mark everything seen.
  103. if((! $group) && (! $cid) && (! $star)) {
  104. $r = q("UPDATE `item` SET `unseen` = 0
  105. WHERE `unseen` = 1 AND `uid` = %d",
  106. intval($_SESSION['uid'])
  107. );
  108. }
  109. // We don't have to deal with ACL's on this page. You're looking at everything
  110. // that belongs to you, hence you can see all of it. We will filter by group if
  111. // desired.
  112. $star_sql = (($star) ? " AND `starred` = 1 " : '');
  113. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql ) ";
  114. if($group) {
  115. $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  116. intval($group),
  117. intval($_SESSION['uid'])
  118. );
  119. if(! count($r)) {
  120. if($update)
  121. killme();
  122. notice( t('No such group') . EOL );
  123. goaway($a->get_baseurl() . '/network');
  124. // NOTREACHED
  125. }
  126. $contacts = expand_groups(array($group));
  127. if((is_array($contacts)) && count($contacts)) {
  128. $contact_str = implode(',',$contacts);
  129. }
  130. else {
  131. $contact_str = ' 0 ';
  132. info( t('Group is empty'));
  133. }
  134. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' )) ";
  135. $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
  136. }
  137. elseif($cid) {
  138. $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d
  139. AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
  140. intval($cid)
  141. );
  142. if(count($r)) {
  143. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND `contact-id` IN ( " . intval($cid) . " )) ";
  144. $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
  145. if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  146. notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
  147. }
  148. }
  149. else {
  150. notice( t('Invalid contact.') . EOL);
  151. goaway($a->get_baseurl() . '/network');
  152. // NOTREACHED
  153. }
  154. }
  155. if((! $group) && (! $cid) && (! $update))
  156. $o .= get_birthdays();
  157. $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
  158. if(x($_GET,'search'))
  159. $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
  160. $r = q("SELECT COUNT(*) AS `total`
  161. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  162. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  163. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  164. $sql_extra2
  165. $sql_extra ",
  166. intval($_SESSION['uid'])
  167. );
  168. if(count($r)) {
  169. $a->set_pager_total($r[0]['total']);
  170. $a->set_pager_itemspage(40);
  171. }
  172. if($nouveau) {
  173. // "New Item View" - show all items unthreaded in reverse created date order
  174. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  175. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  176. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  177. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  178. FROM `item`, `contact`
  179. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  180. AND `contact`.`id` = `item`.`contact-id`
  181. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  182. $sql_extra
  183. ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
  184. intval($_SESSION['uid']),
  185. intval($a->pager['start']),
  186. intval($a->pager['itemspage'])
  187. );
  188. }
  189. else {
  190. // Normal conversation view
  191. // First fetch a known number of parent items
  192. $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
  193. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  194. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  195. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  196. AND `item`.`parent` = `item`.`id`
  197. $sql_extra
  198. ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
  199. intval(local_user()),
  200. intval($a->pager['start']),
  201. intval($a->pager['itemspage'])
  202. );
  203. // Then fetch all the children of the parents that are on this page
  204. $parents_arr = array();
  205. $parents_str = '';
  206. if(count($r)) {
  207. foreach($r as $rr)
  208. $parents_arr[] = $rr['item_id'];
  209. $parents_str = implode(', ', $parents_arr);
  210. $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  211. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  212. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  213. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  214. FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
  215. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  216. AND `contact`.`id` = `item`.`contact-id`
  217. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  218. AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
  219. $sql_extra
  220. ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
  221. intval(local_user()),
  222. dbesc($parents_str)
  223. );
  224. }
  225. }
  226. // Set this so that the conversation function can find out contact info for our wall-wall items
  227. $a->page_contact = $a->contact;
  228. $mode = (($nouveau) ? 'network-new' : 'network');
  229. $o .= conversation($a,$r,$mode,$update);
  230. if(! $update) {
  231. $o .= paginate($a);
  232. $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>';
  233. }
  234. return $o;
  235. }