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.
 
 
 
 
 
 

798 lines
25 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'] .= 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. $a = get_app();
  157. $srchurl = '/network?f='
  158. . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
  159. . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
  160. . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
  161. . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
  162. . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
  163. . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
  164. . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
  165. . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
  166. ;
  167. $o = '';
  168. $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
  169. intval(local_user())
  170. );
  171. $saved = array();
  172. if(count($r)) {
  173. foreach($r as $rr) {
  174. $saved[] = array(
  175. 'id' => $rr['id'],
  176. 'term' => $rr['term'],
  177. 'encodedterm' => urlencode($rr['term']),
  178. 'delete' => t('Remove term'),
  179. 'selected' => ($search==$rr['term']),
  180. );
  181. }
  182. }
  183. $tpl = get_markup_template("saved_searches_aside.tpl");
  184. $o = replace_macros($tpl, array(
  185. '$title' => t('Saved Searches'),
  186. '$add' => t('add'),
  187. '$searchbox' => search($search,'netsearch-box',$srchurl,true),
  188. '$saved' => $saved,
  189. ));
  190. return $o;
  191. }
  192. /**
  193. * Return selected tab from query
  194. *
  195. * urls -> returns
  196. * '/network' => $no_active = 'active'
  197. * '/network?f=&order=comment' => $comment_active = 'active'
  198. * '/network?f=&order=post' => $postord_active = 'active'
  199. * '/network?f=&conv=1', => $conv_active = 'active'
  200. * '/network/new', => $new_active = 'active'
  201. * '/network?f=&star=1', => $starred_active = 'active'
  202. * '/network?f=&bmark=1', => $bookmarked_active = 'active'
  203. * '/network?f=&spam=1', => $spam_active = 'active'
  204. *
  205. * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
  206. */
  207. function network_query_get_sel_tab($a) {
  208. $no_active='';
  209. $starred_active = '';
  210. $new_active = '';
  211. $bookmarked_active = '';
  212. $all_active = '';
  213. $search_active = '';
  214. $conv_active = '';
  215. $spam_active = '';
  216. $postord_active = '';
  217. if(($a->argc > 1 && $a->argv[1] === 'new')
  218. || ($a->argc > 2 && $a->argv[2] === 'new')) {
  219. $new_active = 'active';
  220. }
  221. if(x($_GET,'search')) {
  222. $search_active = 'active';
  223. }
  224. if(x($_GET,'star')) {
  225. $starred_active = 'active';
  226. }
  227. if(x($_GET,'bmark')) {
  228. $bookmarked_active = 'active';
  229. }
  230. if(x($_GET,'conv')) {
  231. $conv_active = 'active';
  232. }
  233. if(x($_GET,'spam')) {
  234. $spam_active = 'active';
  235. }
  236. if (($new_active == '')
  237. && ($starred_active == '')
  238. && ($bookmarked_active == '')
  239. && ($conv_active == '')
  240. && ($search_active == '')
  241. && ($spam_active == '')) {
  242. $no_active = 'active';
  243. }
  244. if ($no_active=='active' && x($_GET,'order')) {
  245. switch($_GET['order']){
  246. case 'post': $postord_active = 'active'; $no_active=''; break;
  247. case 'comment' : $all_active = 'active'; $no_active=''; break;
  248. }
  249. }
  250. return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
  251. }
  252. /**
  253. * Return selected network from query
  254. */
  255. function network_query_get_sel_net() {
  256. $network = false;
  257. if(x($_GET,'nets')) {
  258. $network = $_GET['nets'];
  259. }
  260. return $network;
  261. }
  262. function network_query_get_sel_group($a) {
  263. $group = false;
  264. if($a->argc >= 2 && is_numeric($a->argv[1])) {
  265. $group = $a->argv[1];
  266. }
  267. return $group;
  268. }
  269. function network_content(&$a, $update = 0) {
  270. require_once('include/conversation.php');
  271. if(! local_user()) {
  272. $_SESSION['return_url'] = $a->query_string;
  273. return login(false);
  274. }
  275. $arr = array('query' => $a->query_string);
  276. call_hooks('network_content_init', $arr);
  277. $datequery = $datequery2 = '';
  278. $group = 0;
  279. $nouveau = false;
  280. if($a->argc > 1) {
  281. for($x = 1; $x < $a->argc; $x ++) {
  282. if(is_a_date_arg($a->argv[$x])) {
  283. if($datequery)
  284. $datequery2 = escape_tags($a->argv[$x]);
  285. else {
  286. $datequery = escape_tags($a->argv[$x]);
  287. $_GET['order'] = 'post';
  288. }
  289. }
  290. elseif($a->argv[$x] === 'new') {
  291. $nouveau = true;
  292. }
  293. elseif(intval($a->argv[$x])) {
  294. $group = intval($a->argv[$x]);
  295. $def_acl = array('allow_gid' => '<' . $group . '>');
  296. }
  297. }
  298. }
  299. $o = '';
  300. // item filter tabs
  301. // TODO: fix this logic, reduce duplication
  302. //$a->page['content'] .= '<div class="tabs-wrapper">';
  303. list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
  304. // if no tabs are selected, defaults to comments
  305. if ($no_active=='active') $all_active='active';
  306. //echo "<pre>"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme();
  307. $cmd = (($datequery) ? '' : $a->cmd);
  308. $len_naked_cmd = strlen(str_replace('/new','',$cmd));
  309. // tabs
  310. $tabs = array(
  311. array(
  312. 'label' => t('Commented Order'),
  313. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
  314. 'sel'=>$all_active,
  315. 'title'=> t('Sort by Comment Date'),
  316. ),
  317. array(
  318. 'label' => t('Posted Order'),
  319. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
  320. 'sel'=>$postord_active,
  321. 'title' => t('Sort by Post Date'),
  322. ),
  323. array(
  324. 'label' => t('Personal'),
  325. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
  326. 'sel' => $conv_active,
  327. 'title' => t('Posts that mention or involve you'),
  328. ),
  329. array(
  330. 'label' => t('New'),
  331. 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
  332. 'sel' => $new_active,
  333. 'title' => t('Activity Stream - by date'),
  334. ),
  335. array(
  336. 'label' => t('Starred'),
  337. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
  338. 'sel'=>$starred_active,
  339. 'title' => t('Favourite Posts'),
  340. ),
  341. array(
  342. 'label' => t('Shared Links'),
  343. 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
  344. 'sel'=>$bookmarked_active,
  345. 'title'=> t('Interesting Links'),
  346. ),
  347. // array(
  348. // 'label' => t('Spam'),
  349. // 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
  350. // 'sel'=> $spam_active,
  351. // 'title' => t('Posts flagged as SPAM'),
  352. // ),
  353. );
  354. // save selected tab, but only if not in search or file mode
  355. if(!x($_GET,'search') && !x($_GET,'file')) {
  356. set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) );
  357. }
  358. $arr = array('tabs' => $tabs);
  359. call_hooks('network_tabs', $arr);
  360. $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs']));
  361. // --- end item filter tabs
  362. $contact_id = $a->cid;
  363. require_once('include/acl_selectors.php');
  364. $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
  365. $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
  366. $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
  367. $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
  368. $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
  369. $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
  370. $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
  371. $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
  372. $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
  373. $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
  374. $file = ((x($_GET,'file')) ? $_GET['file'] : '');
  375. if(x($_GET,'search') || x($_GET,'file'))
  376. $nouveau = true;
  377. if($cid)
  378. $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
  379. if($nets) {
  380. $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
  381. intval(local_user()),
  382. dbesc($nets)
  383. );
  384. $str = '';
  385. if(count($r))
  386. foreach($r as $rr)
  387. $str .= '<' . $rr['id'] . '>';
  388. if(strlen($str))
  389. $def_acl = array('allow_cid' => $str);
  390. }
  391. set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
  392. if(! $update) {
  393. if($group) {
  394. if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  395. notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
  396. 'Warning: This group contains %s members from an insecure network.',
  397. $t), $t ) . EOL);
  398. notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
  399. }
  400. }
  401. nav_set_selected('network');
  402. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  403. $x = array(
  404. 'is_owner' => true,
  405. 'allow_location' => $a->user['allow_location'],
  406. 'default_location' => $a->user['default-location'],
  407. 'nickname' => $a->user['nickname'],
  408. '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'),
  409. 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), $celeb),
  410. 'bang' => (($group || $cid || $nets) ? '!' : ''),
  411. 'visitor' => 'block',
  412. 'profile_uid' => local_user()
  413. );
  414. $o .= status_editor($a,$x);
  415. }
  416. // We don't have to deal with ACL's on this page. You're looking at everything
  417. // that belongs to you, hence you can see all of it. We will filter by group if
  418. // desired.
  419. $sql_options = (($star) ? " and starred = 1 " : '');
  420. $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
  421. $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
  422. $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
  423. if($group) {
  424. $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  425. intval($group),
  426. intval($_SESSION['uid'])
  427. );
  428. if(! count($r)) {
  429. if($update)
  430. killme();
  431. notice( t('No such group') . EOL );
  432. goaway($a->get_baseurl(true) . '/network');
  433. // NOTREACHED
  434. }
  435. $contacts = expand_groups(array($group));
  436. if((is_array($contacts)) && count($contacts)) {
  437. $contact_str = implode(',',$contacts);
  438. }
  439. else {
  440. $contact_str = ' 0 ';
  441. info( t('Group is empty'));
  442. }
  443. $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 ) ";
  444. $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
  445. }
  446. elseif($cid) {
  447. $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
  448. AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
  449. intval($cid)
  450. );
  451. if(count($r)) {
  452. $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
  453. $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
  454. if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
  455. notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
  456. }
  457. }
  458. else {
  459. notice( t('Invalid contact.') . EOL);
  460. goaway($a->get_baseurl(true) . '/network');
  461. // NOTREACHED
  462. }
  463. }
  464. if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) {
  465. $o .= get_birthdays();
  466. $o .= get_events();
  467. }
  468. $sql_extra3 = '';
  469. if($datequery) {
  470. $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
  471. }
  472. if($datequery2) {
  473. $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
  474. }
  475. $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
  476. $sql_extra3 = (($nouveau) ? '' : $sql_extra3);
  477. if(x($_GET,'search')) {
  478. $search = escape_tags($_GET['search']);
  479. if (get_config('system','use_fulltext_engine')) {
  480. if(strpos($search,'#') === 0)
  481. $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ",
  482. dbesc(protect_sprintf($search))
  483. );
  484. else
  485. $sql_extra .= sprintf(" AND (MATCH(`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ",
  486. dbesc(protect_sprintf($search)),
  487. dbesc(protect_sprintf($search))
  488. );
  489. } else {
  490. $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ",
  491. dbesc(protect_sprintf('%' . $search . '%')),
  492. dbesc(protect_sprintf('%]' . $search . '[%'))
  493. );
  494. }
  495. }
  496. if(strlen($file)) {
  497. $sql_extra .= file_tag_file_query('item',unxmlify($file));
  498. }
  499. if($conv) {
  500. $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
  501. $myurl = substr($myurl,strpos($myurl,'://')+3);
  502. $myurl = str_replace('www.','',$myurl);
  503. $diasp_url = str_replace('/profile/','/u/',$myurl);
  504. if (get_config('system','use_fulltext_engine'))
  505. $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))) ",
  506. dbesc(protect_sprintf($myurl)),
  507. dbesc(protect_sprintf($myurl)),
  508. dbesc(protect_sprintf($diasp_url))
  509. );
  510. else
  511. $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' )) ",
  512. dbesc(protect_sprintf('%' . $myurl)),
  513. dbesc(protect_sprintf('%' . $myurl . ']%')),
  514. dbesc(protect_sprintf('%' . $diasp_url . ']%'))
  515. );
  516. }
  517. if($update) {
  518. // only setup pagination on initial page view
  519. $pager_sql = '';
  520. }
  521. else {
  522. if(! get_pconfig(local_user(),'system','alt_pager')) {
  523. $r = q("SELECT COUNT(*) AS `total`
  524. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  525. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  526. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  527. $sql_extra2 $sql_extra3
  528. $sql_extra $sql_nets ",
  529. intval($_SESSION['uid'])
  530. );
  531. if(count($r)) {
  532. $a->set_pager_total($r[0]['total']);
  533. }
  534. }
  535. $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
  536. $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
  537. if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network))
  538. $itemspage_network = $a->force_max_items;
  539. $a->set_pager_itemspage($itemspage_network);
  540. $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
  541. }
  542. $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
  543. if($nouveau) {
  544. // "New Item View" - show all items unthreaded in reverse created date order
  545. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  546. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
  547. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  548. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  549. FROM `item`, `contact`
  550. WHERE `item`.`uid` = %d AND `item`.`visible` = 1
  551. AND `item`.`deleted` = 0 and `item`.`moderated` = 0
  552. $simple_update
  553. AND `contact`.`id` = `item`.`contact-id`
  554. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  555. $sql_extra $sql_nets
  556. ORDER BY `item`.`received` DESC $pager_sql ",
  557. intval($_SESSION['uid'])
  558. );
  559. $update_unseen = ' WHERE uid = ' . intval($_SESSION['uid']) . " AND unseen = 1 $sql_extra $sql_nets";
  560. }
  561. else {
  562. // Normal conversation view
  563. if($order === 'post')
  564. $ordering = "`created`";
  565. else
  566. $ordering = "`commented`";
  567. // Fetch a page full of parent items for this page
  568. if($update) {
  569. $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
  570. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  571. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
  572. (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "')
  573. and `item`.`moderated` = 0 and `item`.`unseen` = 1
  574. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  575. $sql_extra3 $sql_extra $sql_nets ",
  576. intval(local_user())
  577. );
  578. }
  579. else {
  580. $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
  581. FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  582. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  583. AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  584. AND `item`.`parent` = `item`.`id`
  585. $sql_extra3 $sql_extra $sql_nets
  586. ORDER BY `item`.$ordering DESC $pager_sql ",
  587. intval(local_user())
  588. );
  589. }
  590. // Then fetch all the children of the parents that are on this page
  591. $parents_arr = array();
  592. $parents_str = '';
  593. if(count($r)) {
  594. foreach($r as $rr)
  595. if(! in_array($rr['item_id'],$parents_arr))
  596. $parents_arr[] = $rr['item_id'];
  597. $parents_str = implode(', ', $parents_arr);
  598. $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
  599. `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, `contact`.`writable`,
  600. `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
  601. `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
  602. FROM `item`, `contact`
  603. WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
  604. AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id`
  605. AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
  606. AND `item`.`parent` IN ( %s )
  607. $sql_extra ",
  608. intval(local_user()),
  609. dbesc($parents_str)
  610. );
  611. $items = conv_sort($items,$ordering);
  612. } else {
  613. $items = array();
  614. }
  615. if($parents_str)
  616. $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )';
  617. }
  618. // We aren't going to try and figure out at the item, group, and page
  619. // level which items you've seen and which you haven't. If you're looking
  620. // at the top level network page just mark everything seen.
  621. /* if((! $group) && (! $cid) && (! $star)) {
  622. $r = q("UPDATE `item` SET `unseen` = 0
  623. WHERE `unseen` = 1 AND `uid` = %d",
  624. intval(local_user())
  625. );
  626. }*/
  627. if($update_unseen)
  628. $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
  629. // Set this so that the conversation function can find out contact info for our wall-wall items
  630. $a->page_contact = $a->contact;
  631. $mode = (($nouveau) ? 'network-new' : 'network');
  632. $o .= conversation($a,$items,$mode,$update);
  633. if(! $update) {
  634. if(! get_pconfig(local_user(),'system','alt_pager')) {
  635. $o .= paginate($a);
  636. }
  637. else {
  638. $o .= alt_pager($a,count($items));
  639. }
  640. }
  641. return $o;
  642. }