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.
 
 
 
 
 
 

884 lines
28 KiB

  1. <?php
  2. function network_init(&$a) {
  3. if(! local_user()) {
  4. notice( t('Permission denied.') . EOL);
  5. return;
  6. }
  7. $is_a_date_query = false;
  8. if($a->argc > 1) {
  9. for($x = 1; $x < $a->argc; $x ++) {
  10. if(is_a_date_arg($a->argv[$x])) {
  11. $is_a_date_query = true;
  12. break;
  13. }
  14. }
  15. }
  16. // convert query string to array and remove first element (which is friendica args)
  17. $query_array = array();
  18. parse_str($a->query_string, $query_array);
  19. array_shift($query_array);
  20. // fetch last used network view and redirect if needed
  21. if(! $is_a_date_query) {
  22. $sel_tabs = network_query_get_sel_tab($a);
  23. $sel_nets = network_query_get_sel_net();
  24. $sel_groups = network_query_get_sel_group($a);
  25. $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected');
  26. $last_sel_nets = get_pconfig(local_user(), 'network.view', 'net.selected');
  27. $last_sel_groups = get_pconfig(local_user(), 'network.view', 'group.selected');
  28. $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
  29. $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
  30. $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
  31. $net_baseurl = '/network';
  32. $net_args = array();
  33. if($remember_group) {
  34. $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
  35. }
  36. else if($sel_groups !== false) {
  37. $net_baseurl .= '/' . $sel_groups;
  38. }
  39. if($remember_tab) {
  40. // redirect if current selected tab is '/network' and
  41. // last selected tab is _not_ '/network?f=&order=comment'.
  42. // and this isn't a date query
  43. $tab_baseurls = array(
  44. '', //all
  45. '', //postord
  46. '', //conv
  47. '/new', //new
  48. '', //starred
  49. '', //bookmarked
  50. '', //spam
  51. );
  52. $tab_args = array(
  53. 'f=&order=comment', //all
  54. 'f=&order=post', //postord
  55. 'f=&conv=1', //conv
  56. '', //new
  57. 'f=&star=1', //starred
  58. 'f=&bmark=1', //bookmarked
  59. 'f=&spam=1', //spam
  60. );
  61. $k = array_search('active', $last_sel_tabs);
  62. $net_baseurl .= $tab_baseurls[$k];
  63. // parse out tab queries
  64. $dest_qa = array();
  65. $dest_qs = $tab_args[$k];
  66. parse_str( $dest_qs, $dest_qa);
  67. $net_args = array_merge($net_args, $dest_qa);
  68. }
  69. else if($sel_tabs[4] === 'active') {
  70. // The '/new' tab is selected
  71. $net_baseurl .= '/new';
  72. }
  73. if($remember_net) {
  74. $net_args['nets'] = $last_sel_nets;
  75. }
  76. if($remember_tab || $remember_net || $remember_group) {
  77. $net_args = array_merge($query_array, $net_args);
  78. $net_queries = build_querystring($net_args);
  79. // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible
  80. //if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($net_baseurl, "/",1)===false){
  81. // $net_baseurl .= "/".$a->argv[1];
  82. //}
  83. $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
  84. goaway($a->get_baseurl() . $redir_url);
  85. }
  86. }
  87. /* $sel_tabs = network_query_get_sel_tab($a);
  88. $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected');
  89. if (is_array($last_sel_tabs)){
  90. $tab_urls = array(
  91. '/network?f=&order=comment',//all
  92. '/network?f=&order=post', //postord
  93. '/network?f=&conv=1', //conv
  94. '/network/new', //new
  95. '/network?f=&star=1', //starred
  96. '/network?f=&bmark=1', //bookmarked
  97. '/network?f=&spam=1', //spam
  98. );
  99. // redirect if current selected tab is 'no_active' and
  100. // last selected tab is _not_ 'all_active'.
  101. // and this isn't a date query
  102. if ($sel_tabs[0] == 'active' && $last_sel_tabs[0]!='active' && (! $is_a_date_query)) {
  103. $k = array_search('active', $last_sel_tabs);
  104. // merge tab querystring with request querystring
  105. $dest_qa = array();
  106. list($dest_url,$dest_qs) = explode("?", $tab_urls[$k]);
  107. parse_str( $dest_qs, $dest_qa);
  108. $dest_qa = array_merge($query_array, $dest_qa);
  109. $dest_qs = build_querystring($dest_qa);
  110. // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible
  111. if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($dest_url, "/",1)===false){
  112. $dest_url .= "/".$a->argv[1];
  113. }
  114. goaway($a->get_baseurl() . $dest_url."?".$dest_qs);
  115. }
  116. }*/
  117. if(x($_GET['nets']) && $_GET['nets'] === 'all')
  118. unset($_GET['nets']);
  119. $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
  120. set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
  121. require_once('include/group.php');
  122. require_once('include/contact_widgets.php');
  123. require_once('include/items.php');
  124. if(! x($a->page,'aside'))
  125. $a->page['aside'] = '';
  126. $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
  127. if(x($_GET,'save')) {
  128. $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
  129. intval(local_user()),
  130. dbesc($search)
  131. );
  132. if(! count($r)) {
  133. q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
  134. intval(local_user()),
  135. dbesc($search)
  136. );
  137. }
  138. }
  139. if(x($_GET,'remove')) {
  140. q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
  141. intval(local_user()),
  142. dbesc($search)
  143. );
  144. }
  145. // search terms header
  146. if(x($_GET,'search')) {
  147. $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
  148. }
  149. $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network',true,$group_id) : '');
  150. $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false);
  151. $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
  152. $a->page['aside'] .= saved_searches($search);
  153. $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
  154. }
  155. function saved_searches($search) {
  156. if(! feature_enabled(local_user(),'savedsearch'))
  157. return '';
  158. $a = get_app();
  159. $srchurl = '/network?f='
  160. . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
  161. . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
  162. . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
  163. . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
  164. . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
  165. . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
  166. . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
  167. . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
  168. ;
  169. $o = '';
  170. $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
  171. intval(local_user())
  172. );
  173. $saved = array();
  174. if(count($r)) {
  175. foreach($r as $rr) {
  176. $saved[] = array(
  177. 'id' => $rr['id'],
  178. 'term' => $rr['term'],
  179. 'encodedterm' => urlencode($rr['term']),
  180. 'delete' => t('Remove term'),
  181. 'selected' => ($search==$rr['term']),
  182. );
  183. }
  184. }
  185. $tpl = get_markup_template("saved_searches_aside.tpl");
  186. $o = replace_macros($tpl, array(
  187. '$title' => t('Saved Searches'),
  188. '$add' => t('add'),
  189. '$searchbox' => search($search,'netsearch-box',$srchurl,true),
  190. '$saved' => $saved,
  191. ));
  192. return $o;
  193. }
  194. /**
  195. * Return selected tab from query
  196. *
  197. * urls -> returns
  198. * '/network' => $no_active = 'active'
  199. * '/network?f=&order=comment' => $comment_active = 'active'
  200. * '/network?f=&order=post' => $postord_active = 'active'
  201. * '/network?f=&conv=1', => $conv_active = 'active'
  202. * '/network/new', => $new_active = 'active'
  203. * '/network?f=&star=1', => $starred_active = 'active'
  204. * '/network?f=&bmark=1', => $bookmarked_active = 'active'
  205. * '/network?f=&spam=1', => $spam_active = 'active'
  206. *
  207. * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
  208. */
  209. function network_query_get_sel_tab($a) {
  210. $no_active='';
  211. $starred_active = '';
  212. $new_active = '';
  213. $bookmarked_active = '';
  214. $all_active = '';
  215. $search_active = '';
  216. $conv_active = '';
  217. $spam_active = '';
  218. $postord_active = '';
  219. if(($a->argc > 1 && $a->argv[1] === 'new')
  220. || ($a->argc > 2 && $a->argv[2] === 'new')) {
  221. $new_active = 'active';
  222. }
  223. if(x($_GET,'search')) {
  224. $search_active = 'active';
  225. }
  226. if(x($_GET,'star')) {
  227. $starred_active = 'active';
  228. }
  229. if(x($_GET,'bmark')) {
  230. $bookmarked_active = 'active';
  231. }
  232. if(x($_GET,'conv')) {
  233. $conv_active = 'active';
  234. }
  235. if(x($_GET,'spam')) {
  236. $spam_active = 'active';
  237. }
  238. if (($new_active == '')
  239. && ($starred_active == '')
  240. && ($bookmarked_active == '')
  241. && ($conv_active == '')
  242. && ($search_active == '')
  243. && ($spam_active == '')) {
  244. $no_active = 'active';
  245. }
  246. if ($no_active=='active' && x($_GET,'order')) {
  247. switch($_GET['order']){
  248. case 'post': $postord_active = 'active'; $no_active=''; break;
  249. case 'comment' : $all_active = 'active'; $no_active=''; break;
  250. }
  251. }
  252. return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
  253. }
  254. /**
  255. * Return selected network from query
  256. */
  257. function network_query_get_sel_net() {
  258. $network = false;
  259. if(x($_GET,'nets')) {
  260. $network = $_GET['nets'];
  261. }
  262. return $network;
  263. }
  264. function network_query_get_sel_group($a) {
  265. $group = false;
  266. if($a->argc >= 2 && is_numeric($a->argv[1])) {
  267. $group = $a->argv[1];
  268. }
  269. return $group;
  270. }
  271. function network_content(&$a, $update = 0) {
  272. require_once('include/conversation.php');
  273. if(! local_user()) {
  274. $_SESSION['return_url'] = $a->query_string;
  275. return login(false);
  276. }
  277. $arr = array('query' => $a->query_string);
  278. call_hooks('network_content_init', $arr);
  279. $datequery = $datequery2 = '';
  280. $group = 0;
  281. $nouveau = false;
  282. if($a->argc > 1) {
  283. for($x = 1; $x < $a->argc; $x ++) {
  284. if(is_a_date_arg($a->argv[$x])) {
  285. if($datequery)
  286. $datequery2 = escape_tags($a->argv[$x]);
  287. else {
  288. $datequery = escape_tags($a->argv[$x]);
  289. $_GET['order'] = 'post';
  290. }
  291. }
  292. elseif($a->argv[$x] === 'new') {
  293. $nouveau = true;
  294. }
  295. elseif(intval($a->argv[$x])) {
  296. $group = intval($a->argv[$x]);
  297. $def_acl = array('allow_gid' => '<' . $group . '>');
  298. }
  299. }
  300. }
  301. $o = '';
  302. // item filter tabs
  303. // TODO: fix this logic, reduce duplication
  304. //$a->page['content'] .= '<div class="tabs-wrapper">';
  305. list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
  306. // if no tabs are selected, defaults to comments
  307. if ($no_active=='active') $all_active='active';
  308. //echo "<pre>"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme();
  309. $cmd = (($datequery) ? '' : $a->cmd);
  310. $len_naked_cmd = strlen(str_replace('/new','',$cmd));
  311. // tabs
  312. $tabs = array(
  313. array(
  314. 'label' => t('Commented Order'),
  315. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
  316. 'sel'=>$all_active,
  317. 'title'=> t('Sort by Comment Date'),
  318. ),
  319. array(
  320. 'label' => t('Posted Order'),
  321. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
  322. 'sel'=>$postord_active,
  323. 'title' => t('Sort by Post Date'),
  324. ),
  325. /* array(
  326. 'label' => t('Personal'),
  327. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
  328. 'sel' => $conv_active,
  329. 'title' => t('Posts that mention or involve you'),
  330. ),*/
  331. /* array(
  332. 'label' => t('New'),
  333. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
  334. 'sel' => $new_active,
  335. 'title' => t('Activity Stream - by date'),
  336. ),*/
  337. /* array(
  338. 'label' => t('Starred'),
  339. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
  340. 'sel'=>$starred_active,
  341. 'title' => t('Favourite Posts'),
  342. ),*/
  343. /* array(
  344. 'label' => t('Shared Links'),
  345. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
  346. 'sel'=>$bookmarked_active,
  347. 'title'=> t('Interesting Links'),
  348. ), */
  349. // array(
  350. // 'label' => t('Spam'),
  351. // 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
  352. // 'sel'=> $spam_active,
  353. // 'title' => t('Posts flagged as SPAM'),
  354. // ),
  355. );
  356. if(feature_enabled(local_user(),'personal_tab')) {
  357. $tabs[] = array(
  358. 'label' => t('Personal'),
  359. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
  360. 'sel' => $conv_active,
  361. 'title' => t('Posts that mention or involve you'),
  362. );
  363. }
  364. if(feature_enabled(local_user(),'new_tab')) {
  365. $tabs[] = array(
  366. 'label' => t('New'),
  367. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
  368. 'sel' => $new_active,
  369. 'title' => t('Activity Stream - by date'),
  370. );
  371. }
  372. if(feature_enabled(local_user(),'link_tab')) {
  373. $tabs[] = array(
  374. 'label' => t('Shared Links'),
  375. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
  376. 'sel'=>$bookmarked_active,
  377. 'title'=> t('Interesting Links'),
  378. );
  379. }
  380. if(feature_enabled(local_user(),'star_posts')) {
  381. $tabs[] = array(
  382. 'label' => t('Starred'),
  383. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
  384. 'sel'=>$starred_active,
  385. 'title' => t('Favourite Posts'),
  386. );
  387. }
  388. // Not yet implemented
  389. /* if(feature_enabled(local_user(),'spam_filter')) {
  390. $tabs[] = array(
  391. 'label' => t('Spam'),
  392. 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1',
  393. 'sel'=> $spam_active,
  394. 'title' => t('Posts flagged as SPAM'),
  395. );
  396. }*/
  397. // save selected tab, but only if not in search or file mode
  398. if(!x($_GET,'search') && !x($_GET,'file')) {
  399. set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
  400. }
  401. $arr = array('tabs' => $tabs);
  402. call_hooks('network_tabs', $arr);
  403. $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs']));
  404. // --- end item filter tabs
  405. $contact_id = $a->cid;
  406. require_once('include/acl_selectors.php');
  407. $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
  408. $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
  409. $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
  410. $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
  411. $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
  412. $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
  413. $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
  414. $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
  415. $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
  416. $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
  417. $file = ((x($_GET,'file')) ? $_GET['file'] : '');
  418. if(x($_GET,'search') || x($_GET,'file'))
  419. $nouveau = true;
  420. if($cid)
  421. $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
  422. if($nets) {
  423. $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
  424. intval(local_user()),
  425. dbesc($nets)
  426. );
  427. $str = '';
  428. if(count($r))
  429. foreach($r as $rr)
  430. $str .= '<' . $rr['id'] . '>';
  431. if(strlen($str))
  432. $def_acl = array('allow_cid' => $str);
  433. }
  434. set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
  435. if(! $update) {
  436. if($group) {
  437. if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  438. notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
  439. 'Warning: This group contains %s members from an insecure network.',
  440. $t), $t ) . EOL);
  441. notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
  442. }
  443. }
  444. nav_set_selected('network');
  445. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  446. $x = array(
  447. 'is_owner' => true,
  448. 'allow_location' => $a->user['allow_location'],
  449. 'default_location' => $a->user['default-location'],
  450. 'nickname' => $a->user['nickname'],
  451. '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'),
  452. 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), $celeb),
  453. 'bang' => (($group || $cid || $nets) ? '!' : ''),
  454. 'visitor' => 'block',
  455. 'profile_uid' => local_user()
  456. );
  457. $o .= status_editor($a,$x);
  458. }
  459. // We don't have to deal with ACLs on this page. You're looking at everything
  460. // that belongs to you, hence you can see all of it. We will filter by group if
  461. // desired.
  462. $sql_options = (($star) ? " and starred = 1 " : '');
  463. $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
  464. $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
  465. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
  466. if($group) {
  467. $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  468. intval($group),
  469. intval($_SESSION['uid'])
  470. );
  471. if(! count($r)) {
  472. if($update)
  473. killme();
  474. notice( t('No such group') . EOL );
  475. goaway($a->get_baseurl(true) . '/network');
  476. // NOTREACHED
  477. }
  478. $contacts = expand_groups(array($group));
  479. if((is_array($contacts)) && count($contacts)) {
  480. $contact_str = implode(',',$contacts);
  481. }
  482. else {
  483. $contact_str = ' 0 ';
  484. info( t('Group is empty'));
  485. }
  486. $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) ";
  487. $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
  488. }
  489. elseif($cid) {
  490. $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
  491. AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
  492. intval($cid)
  493. );
  494. if(count($r)) {
  495. $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
  496. $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
  497. if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  498. notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
  499. }
  500. }
  501. else {
  502. notice( t('Invalid contact.') . EOL);
  503. goaway($a->get_baseurl(true) . '/network');
  504. // NOTREACHED
  505. }
  506. }
  507. if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) {
  508. $o .= get_birthdays();
  509. $o .= get_events();
  510. }
  511. $sql_extra3 = '';
  512. if($datequery) {
  513. $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
  514. }
  515. if($datequery2) {
  516. $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
  517. }
  518. $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
  519. $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
  520. $sql_table = "`item`";
  521. if(x($_GET,'search')) {
  522. $search = escape_tags($_GET['search']);
  523. if(strpos($search,'#') === 0) {
  524. $tag = true;
  525. $search = substr($search,1);
  526. }
  527. if (get_config('system','only_tag_search'))
  528. $tag = true;
  529. /*if (get_config('system','use_fulltext_engine')) {
  530. if(strpos($search,'#') === 0)
  531. $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ",
  532. dbesc(protect_sprintf($search))
  533. );
  534. else
  535. $sql_extra .= sprintf(" AND (MATCH(`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode)) ",
  536. dbesc(protect_sprintf($search)),
  537. dbesc(protect_sprintf($search))
  538. );
  539. } else {
  540. $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ",
  541. dbesc(protect_sprintf('%' . $search . '%')),
  542. dbesc(protect_sprintf('%]' . $search . '[%'))
  543. );
  544. }*/
  545. if($tag) {
  546. $sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ",
  547. dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG));
  548. $sql_table = "`term` LEFT JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` ";
  549. } else {
  550. if (get_config('system','use_fulltext_engine'))
  551. $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
  552. else
  553. $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
  554. }
  555. }
  556. if(strlen($file)) {
  557. $sql_extra .= file_tag_file_query('item',unxmlify($file));
  558. }
  559. if($conv) {
  560. $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
  561. $myurl = substr($myurl,strpos($myurl,'://')+3);
  562. $myurl = str_replace('www.','',$myurl);
  563. $diasp_url = str_replace('/profile/','/u/',$myurl);
  564. /*if (get_config('system','use_fulltext_engine'))
  565. $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ",
  566. //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (`author-link` IN ('https://%s', 'http://%s') OR MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ",
  567. //$sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
  568. dbesc(protect_sprintf($myurl)),
  569. dbesc(protect_sprintf($myurl)),
  570. dbesc(protect_sprintf($diasp_url))
  571. );
  572. else
  573. $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ",
  574. dbesc(protect_sprintf('%' . $myurl)),
  575. dbesc(protect_sprintf('%' . $myurl . ']%')),
  576. dbesc(protect_sprintf('%' . $diasp_url . ']%'))
  577. );*/
  578. $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where `author-link` IN ('https://%s', 'http://%s') OR `mention`)",
  579. dbesc(protect_sprintf($myurl)),
  580. dbesc(protect_sprintf($myurl))
  581. );
  582. }
  583. if($update) {
  584. // only setup pagination on initial page view
  585. $pager_sql = '';
  586. }
  587. else {
  588. if( (! get_config('alt_pager', 'global')) && (! get_pconfig(local_user(),'system','alt_pager')) ) {
  589. $r = q("SELECT COUNT(*) AS `total`
  590. FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  591. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  592. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  593. $sql_extra2 $sql_extra3
  594. $sql_extra $sql_nets ",
  595. intval($_SESSION['uid'])
  596. );
  597. if(count($r)) {
  598. $a->set_pager_total($r[0]['total']);
  599. }
  600. }
  601. $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
  602. $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
  603. if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
  604. $itemspage_network = $a->force_max_items;
  605. $a->set_pager_itemspage($itemspage_network);
  606. $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
  607. }
  608. $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
  609. if($nouveau) {
  610. // "New Item View" - show all items unthreaded in reverse created date order
  611. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  612. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  613. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  614. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  615. FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  616. WHERE `item`.`uid` = %d AND `item`.`visible` = 1
  617. AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  618. $simple_update
  619. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  620. $sql_extra $sql_nets
  621. ORDER BY `item`.`received` DESC $pager_sql ",
  622. intval($_SESSION['uid'])
  623. );
  624. $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets";
  625. }
  626. else {
  627. // Normal conversation view
  628. if($order === 'post')
  629. $ordering = "`created`";
  630. else
  631. $ordering = "`commented`";
  632. // Fetch a page full of parent items for this page
  633. if($update) {
  634. $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
  635. FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  636. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
  637. (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "')
  638. and `item`.`moderated` = 0 and `item`.`unseen` = 1
  639. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  640. $sql_extra3 $sql_extra $sql_nets ",
  641. intval(local_user())
  642. );
  643. }
  644. else {
  645. $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
  646. FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  647. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  648. AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  649. AND `item`.`parent` = `item`.`id`
  650. $sql_extra3 $sql_extra $sql_nets
  651. ORDER BY `item`.$ordering DESC $pager_sql ",
  652. intval(local_user())
  653. );
  654. }
  655. // Then fetch all the children of the parents that are on this page
  656. $parents_arr = array();
  657. $parents_str = '';
  658. if(count($r)) {
  659. foreach($r as $rr)
  660. if(! in_array($rr['item_id'],$parents_arr))
  661. $parents_arr[] = $rr['item_id'];
  662. $parents_str = implode(', ', $parents_arr);
  663. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  664. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
  665. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  666. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  667. FROM $sql_table LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  668. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  669. AND `item`.`moderated` = 0
  670. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  671. AND `item`.`parent` IN ( %s )
  672. $sql_extra ",
  673. intval(local_user()),
  674. dbesc($parents_str)
  675. );
  676. $items = conv_sort($items,$ordering);
  677. } else {
  678. $items = array();
  679. }
  680. if($parents_str)
  681. $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
  682. }
  683. // We aren't going to try and figure out at the item, group, and page
  684. // level which items you've seen and which you haven't. If you're looking
  685. // at the top level network page just mark everything seen.
  686. // The $update_unseen is a bit unreliable if you have stuff coming into your stream from a new contact -
  687. // and other feeds that bring in stuff from the past. One can't find it all.
  688. // I'm reviving this block to mark everything seen on page 1 of the network as a temporary measure.
  689. // The correct solution is to implement a network notifications box just like the system notifications popup
  690. // with the ability in the popup to "mark all seen".
  691. // Several people are complaining because there are unseen messages they can't find and as time goes
  692. // on they just get buried deeper. It has happened to me a couple of times also.
  693. if((! $group) && (! $cid) && (! $star)) {
  694. $r = q("UPDATE `item` SET `unseen` = 0
  695. WHERE `unseen` = 1 AND `uid` = %d",
  696. intval(local_user())
  697. );
  698. }
  699. else {
  700. if($update_unseen)
  701. $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
  702. }
  703. // Set this so that the conversation function can find out contact info for our wall-wall items
  704. $a->page_contact = $a->contact;
  705. $mode = (($nouveau) ? 'network-new' : 'network');
  706. $o .= conversation($a,$items,$mode,$update);
  707. if(! $update) {
  708. if( get_config('alt_pager', 'global') || get_pconfig(local_user(),'system','alt_pager') ) {
  709. $o .= alt_pager($a,count($items));
  710. }
  711. else {
  712. $o .= paginate($a);
  713. }
  714. }
  715. return $o;
  716. }