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.
 
 
 
 
 
 

548 lines
16 KiB

  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. require_once('include/contact_widgets.php');
  10. if(! x($a->page,'aside'))
  11. $a->page['aside'] = '';
  12. $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
  13. if(x($_GET,'save')) {
  14. $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
  15. intval(local_user()),
  16. dbesc($search)
  17. );
  18. if(! count($r)) {
  19. q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
  20. intval(local_user()),
  21. dbesc($search)
  22. );
  23. }
  24. }
  25. if(x($_GET,'remove')) {
  26. q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
  27. intval(local_user()),
  28. dbesc($search)
  29. );
  30. }
  31. // search terms header
  32. if(x($_GET,'search')) {
  33. $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
  34. }
  35. $a->page['aside'] .= group_side('network','network',true,$group_id);
  36. $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
  37. $a->page['aside'] .= saved_searches($search);
  38. $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
  39. }
  40. function saved_searches($search) {
  41. $a = get_app();
  42. $srchurl = '/network?f='
  43. . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
  44. . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
  45. . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
  46. . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
  47. . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
  48. . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
  49. . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
  50. . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
  51. ;
  52. $o = '';
  53. $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
  54. intval(local_user())
  55. );
  56. $saved = array();
  57. if(count($r)) {
  58. foreach($r as $rr) {
  59. $saved[] = array(
  60. 'id' => $rr['id'],
  61. 'term' => $rr['term'],
  62. 'encodedterm' => urlencode($rr['term']),
  63. 'delete' => t('Remove term'),
  64. 'selected' => ($search==$rr['term']),
  65. );
  66. }
  67. }
  68. $tpl = get_markup_template("saved_searches_aside.tpl");
  69. $o = replace_macros($tpl, array(
  70. '$title' => t('Saved Searches'),
  71. '$add' => t('add'),
  72. '$searchbox' => search($search,'netsearch-box',$srchurl,true),
  73. '$saved' => $saved,
  74. ));
  75. return $o;
  76. }
  77. function network_content(&$a, $update = 0) {
  78. require_once('include/conversation.php');
  79. if(! local_user()) {
  80. $_SESSION['return_url'] = $a->query_string;
  81. return login(false);
  82. }
  83. $o = '';
  84. // item filter tabs
  85. // TODO: fix this logic, reduce duplication
  86. //$a->page['content'] .= '<div class="tabs-wrapper">';
  87. $starred_active = '';
  88. $new_active = '';
  89. $bookmarked_active = '';
  90. $all_active = '';
  91. $search_active = '';
  92. $conv_active = '';
  93. $spam_active = '';
  94. if(($a->argc > 1 && $a->argv[1] === 'new')
  95. || ($a->argc > 2 && $a->argv[2] === 'new')) {
  96. $new_active = 'active';
  97. }
  98. if(x($_GET,'search')) {
  99. $search_active = 'active';
  100. }
  101. if(x($_GET,'star')) {
  102. $starred_active = 'active';
  103. }
  104. if(x($_GET,'bmark')) {
  105. $bookmarked_active = 'active';
  106. }
  107. if(x($_GET,'conv')) {
  108. $conv_active = 'active';
  109. }
  110. if(x($_GET,'spam')) {
  111. $spam_active = 'active';
  112. }
  113. if (($new_active == '')
  114. && ($starred_active == '')
  115. && ($bookmarked_active == '')
  116. && ($conv_active == '')
  117. && ($search_active == '')
  118. && ($spam_active == '')) {
  119. $all_active = 'active';
  120. }
  121. $postord_active = '';
  122. if($all_active && x($_GET,'order') && $_GET['order'] !== 'comment') {
  123. $all_active = '';
  124. $postord_active = 'active';
  125. }
  126. // tabs
  127. $tabs = array(
  128. array(
  129. 'label' => t('Commented Order'),
  130. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?f=&cid=' . $_GET['cid'] : ''),
  131. 'sel'=>$all_active,
  132. ),
  133. array(
  134. 'label' => t('Posted Order'),
  135. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
  136. 'sel'=>$postord_active,
  137. ),
  138. array(
  139. 'label' => t('Personal'),
  140. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
  141. 'sel' => $conv_active,
  142. ),
  143. array(
  144. 'label' => t('New'),
  145. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
  146. 'sel' => $new_active,
  147. ),
  148. array(
  149. 'label' => t('Starred'),
  150. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
  151. 'sel'=>$starred_active,
  152. ),
  153. array(
  154. 'label' => t('Shared Links'),
  155. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
  156. 'sel'=>$bookmarked_active,
  157. ),
  158. // array(
  159. // 'label' => t('Spam'),
  160. // 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
  161. // 'sel'=> $spam_active,
  162. // ),
  163. );
  164. $tpl = get_markup_template('common_tabs.tpl');
  165. $o .= replace_macros($tpl, array('$tabs'=>$tabs));
  166. // --- end item filter tabs
  167. $contact_id = $a->cid;
  168. $group = 0;
  169. $nouveau = false;
  170. require_once('include/acl_selectors.php');
  171. $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
  172. $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
  173. $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
  174. $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
  175. $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
  176. $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
  177. $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
  178. $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
  179. $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
  180. $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
  181. $file = ((x($_GET,'file')) ? $_GET['file'] : '');
  182. if(($a->argc > 2) && $a->argv[2] === 'new')
  183. $nouveau = true;
  184. if($a->argc > 1) {
  185. if($a->argv[1] === 'new')
  186. $nouveau = true;
  187. else {
  188. $group = intval($a->argv[1]);
  189. $def_acl = array('allow_gid' => '<' . $group . '>');
  190. }
  191. }
  192. if(x($_GET,'search') || x($_GET,'file'))
  193. $nouveau = true;
  194. if($cid)
  195. $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
  196. if($nets) {
  197. $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
  198. intval(local_user()),
  199. dbesc($nets)
  200. );
  201. $str = '';
  202. if(count($r))
  203. foreach($r as $rr)
  204. $str .= '<' . $rr['id'] . '>';
  205. if(strlen($str))
  206. $def_acl = array('allow_cid' => $str);
  207. }
  208. if(! $update) {
  209. if($group) {
  210. if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  211. notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
  212. 'Warning: This group contains %s members from an insecure network.',
  213. $t), $t ) . EOL);
  214. notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
  215. }
  216. }
  217. nav_set_selected('network');
  218. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  219. $x = array(
  220. 'is_owner' => true,
  221. 'allow_location' => $a->user['allow_location'],
  222. 'default_location' => $a->user['default-location'],
  223. 'nickname' => $a->user['nickname'],
  224. 'lockstate' => ((($group) || ($cid) || ($nets) || (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'),
  225. 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), $celeb),
  226. 'bang' => (($group || $cid || $nets) ? '!' : ''),
  227. 'visitor' => 'block',
  228. 'profile_uid' => local_user()
  229. );
  230. $o .= status_editor($a,$x);
  231. }
  232. // We don't have to deal with ACL's on this page. You're looking at everything
  233. // that belongs to you, hence you can see all of it. We will filter by group if
  234. // desired.
  235. $sql_options = (($star) ? " and starred = 1 " : '');
  236. $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
  237. $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
  238. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
  239. if($group) {
  240. $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  241. intval($group),
  242. intval($_SESSION['uid'])
  243. );
  244. if(! count($r)) {
  245. if($update)
  246. killme();
  247. notice( t('No such group') . EOL );
  248. goaway($a->get_baseurl(true) . '/network');
  249. // NOTREACHED
  250. }
  251. $contacts = expand_groups(array($group));
  252. if((is_array($contacts)) && count($contacts)) {
  253. $contact_str = implode(',',$contacts);
  254. }
  255. else {
  256. $contact_str = ' 0 ';
  257. info( t('Group is empty'));
  258. }
  259. $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' ) and deleted = 0 ) ";
  260. $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
  261. }
  262. elseif($cid) {
  263. $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
  264. AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
  265. intval($cid)
  266. );
  267. if(count($r)) {
  268. $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
  269. $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
  270. if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  271. notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
  272. }
  273. }
  274. else {
  275. notice( t('Invalid contact.') . EOL);
  276. goaway($a->get_baseurl(true) . '/network');
  277. // NOTREACHED
  278. }
  279. }
  280. if((! $group) && (! $cid) && (! $update)) {
  281. $o .= get_birthdays();
  282. $o .= get_events();
  283. }
  284. if(! $update) {
  285. // The special div is needed for liveUpdate to kick in for this page.
  286. // We only launch liveUpdate if you aren't filtering in some incompatible
  287. // way and also you aren't writing a comment (discovered in javascript).
  288. $o .= '<div id="live-network"></div>' . "\r\n";
  289. $o .= "<script> var profile_uid = " . $_SESSION['uid']
  290. . "; var netargs = '" . substr($a->cmd,8)
  291. . '?f='
  292. . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
  293. . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
  294. . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
  295. . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
  296. . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
  297. . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
  298. . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
  299. . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
  300. . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
  301. . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
  302. . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
  303. . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
  304. . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
  305. }
  306. $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
  307. if(x($_GET,'search')) {
  308. $search = escape_tags($_GET['search']);
  309. $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
  310. dbesc(preg_quote($search)),
  311. dbesc('\\]' . preg_quote($search) . '\\[')
  312. );
  313. }
  314. if(strlen($file)) {
  315. $sql_extra .= file_tag_file_query('item',unxmlify($file));
  316. }
  317. if($conv) {
  318. $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
  319. $myurl = substr($myurl,strpos($myurl,'://')+3);
  320. $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
  321. $diasp_url = str_replace('/profile/','/u/',$myurl);
  322. $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` regexp '%s' or `tag` regexp '%s' or tag regexp '%s' )) ",
  323. dbesc($myurl . '$'),
  324. dbesc($myurl . '\\]'),
  325. dbesc($diasp_url . '\\]')
  326. );
  327. }
  328. if($update) {
  329. // only setup pagination on initial page view
  330. $pager_sql = '';
  331. }
  332. else {
  333. $r = q("SELECT COUNT(*) AS `total`
  334. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  335. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  336. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  337. $sql_extra2
  338. $sql_extra $sql_nets ",
  339. intval($_SESSION['uid'])
  340. );
  341. if(count($r)) {
  342. $a->set_pager_total($r[0]['total']);
  343. $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
  344. $a->set_pager_itemspage(((intval($itemspage_network)) ? $itemspage_network : 40));
  345. }
  346. $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
  347. }
  348. $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
  349. if($nouveau) {
  350. // "New Item View" - show all items unthreaded in reverse created date order
  351. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  352. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  353. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  354. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  355. FROM `item`, `contact`
  356. WHERE `item`.`uid` = %d AND `item`.`visible` = 1
  357. AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  358. $simple_update
  359. AND `contact`.`id` = `item`.`contact-id`
  360. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  361. $sql_extra $sql_nets
  362. ORDER BY `item`.`received` DESC $pager_sql ",
  363. intval($_SESSION['uid'])
  364. );
  365. }
  366. else {
  367. // Normal conversation view
  368. if($order === 'post')
  369. $ordering = "`created`";
  370. else
  371. $ordering = "`commented`";
  372. // Fetch a page full of parent items for this page
  373. if($update) {
  374. $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
  375. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  376. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  377. and `item`.`moderated` = 0 and `item`.`unseen` = 1
  378. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  379. $sql_extra $sql_nets ",
  380. intval(local_user())
  381. );
  382. }
  383. else {
  384. $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
  385. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  386. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  387. AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  388. AND `item`.`parent` = `item`.`id`
  389. $sql_extra $sql_nets
  390. ORDER BY `item`.$ordering DESC $pager_sql ",
  391. intval(local_user())
  392. );
  393. }
  394. // Then fetch all the children of the parents that are on this page
  395. $parents_arr = array();
  396. $parents_str = '';
  397. if(count($r)) {
  398. foreach($r as $rr)
  399. if(! in_array($rr['item_id'],$parents_arr))
  400. $parents_arr[] = $rr['item_id'];
  401. $parents_str = implode(', ', $parents_arr);
  402. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  403. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  404. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  405. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  406. FROM `item`, `contact`
  407. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  408. AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id`
  409. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  410. AND `item`.`parent` IN ( %s )
  411. $sql_extra ",
  412. intval(local_user()),
  413. dbesc($parents_str)
  414. );
  415. $items = conv_sort($items,$ordering);
  416. } else {
  417. $items = array();
  418. }
  419. }
  420. // We aren't going to try and figure out at the item, group, and page
  421. // level which items you've seen and which you haven't. If you're looking
  422. // at the top level network page just mark everything seen.
  423. if((! $group) && (! $cid) && (! $star)) {
  424. $r = q("UPDATE `item` SET `unseen` = 0
  425. WHERE `unseen` = 1 AND `uid` = %d",
  426. intval(local_user())
  427. );
  428. }
  429. // Set this so that the conversation function can find out contact info for our wall-wall items
  430. $a->page_contact = $a->contact;
  431. $mode = (($nouveau) ? 'network-new' : 'network');
  432. $o .= conversation($a,$items,$mode,$update);
  433. if(! $update) {
  434. $o .= paginate($a);
  435. }
  436. return $o;
  437. }