4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
7 use Friendica\Database\DBM;
9 require_once 'include/conversation.php';
10 require_once 'include/group.php';
11 require_once 'include/contact_widgets.php';
12 require_once 'include/items.php';
13 require_once 'include/ForumManager.php';
14 require_once 'include/acl_selectors.php';
16 function network_init(App $a) {
18 notice(t('Permission denied.') . EOL);
22 $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
24 if (($search != '') && !empty($_GET['submit'])) {
25 goaway('search?search='.urlencode($search));
28 if (x($_GET, 'save')) {
29 $exists = dba::exists('search', array('uid' => local_user(), 'term' => $search));
31 dba::insert('search', array('uid' => local_user(), 'term' => $search));
34 if (x($_GET, 'remove')) {
35 dba::delete('search', array('uid' => local_user(), 'term' => $search));
38 $is_a_date_query = false;
39 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
41 $_GET['nets'] = 'all';
46 for ($x = 1; $x < $a->argc; $x ++) {
47 if (is_a_date_arg($a->argv[$x])) {
48 $is_a_date_query = true;
54 // convert query string to array. remove friendica args
55 $query_array = array();
56 $query_string = str_replace($a->cmd."?", "", $a->query_string);
57 parse_str($query_string, $query_array);
58 array_shift($query_array);
60 // fetch last used network view and redirect if needed
61 if (!$is_a_date_query) {
62 $sel_tabs = network_query_get_sel_tab($a);
63 $sel_nets = network_query_get_sel_net();
64 $sel_groups = network_query_get_sel_group($a);
65 $last_sel_tabs = PConfig::get(local_user(), 'network.view','tab.selected');
66 $last_sel_nets = PConfig::get(local_user(), 'network.view', 'net.selected');
67 $last_sel_groups = PConfig::get(local_user(), 'network.view', 'group.selected');
69 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
70 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
71 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
73 $net_baseurl = '/network';
76 if ($remember_group) {
77 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
78 } elseif ($sel_groups !== false) {
79 $net_baseurl .= '/' . $sel_groups;
83 // redirect if current selected tab is '/network' and
84 // last selected tab is _not_ '/network?f=&order=comment'.
85 // and this isn't a date query
87 $tab_baseurls = array(
97 'f=&order=comment', //all
98 'f=&order=post', //postord
101 'f=&star=1', //starred
102 'f=&bmark=1', //bookmarked
106 $k = array_search('active', $last_sel_tabs);
109 $net_baseurl .= $tab_baseurls[$k];
111 // parse out tab queries
113 $dest_qs = $tab_args[$k];
114 parse_str($dest_qs, $dest_qa);
115 $net_args = array_merge($net_args, $dest_qa);
117 $remember_tab = false;
119 } elseif ($sel_tabs[4] === 'active') {
120 // The '/new' tab is selected
121 $remember_group = false;
125 $net_args['nets'] = $last_sel_nets;
126 } elseif ($sel_nets!==false) {
127 $net_args['nets'] = $sel_nets;
130 if ($remember_tab || $remember_net || $remember_group) {
131 $net_args = array_merge($query_array, $net_args);
132 $net_queries = build_querystring($net_args);
134 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
136 goaway(System::baseUrl() . $redir_url);
140 // If nets is set to all, unset it
141 if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
142 unset($_GET['nets']);
145 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
147 PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
149 if (!x($a->page, 'aside')) {
150 $a->page['aside'] = '';
153 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
154 $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? ForumManager::widget(local_user(),$cid) : '');
155 $a->page['aside'] .= posted_date_widget('network',local_user(),false);
156 $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
157 $a->page['aside'] .= saved_searches($search);
158 $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : ''));
161 function saved_searches($search) {
163 if (!feature_enabled(local_user(),'savedsearch')) {
169 $srchurl = '/network?f='
170 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
171 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
172 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
173 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
174 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
175 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
176 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
177 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
182 $terms = dba::select('search', array('id', 'term'), array('uid' => local_user()));
185 while ($rr = dba::fetch($terms)) {
188 'term' => $rr['term'],
189 'encodedterm' => urlencode($rr['term']),
190 'delete' => t('Remove term'),
191 'selected' => ($search==$rr['term']),
195 $tpl = get_markup_template("saved_searches_aside.tpl");
196 $o = replace_macros($tpl, array(
197 '$title' => t('Saved Searches'),
199 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
207 * Return selected tab from query
210 * '/network' => $no_active = 'active'
211 * '/network?f=&order=comment' => $comment_active = 'active'
212 * '/network?f=&order=post' => $postord_active = 'active'
213 * '/network?f=&conv=1', => $conv_active = 'active'
214 * '/network/new', => $new_active = 'active'
215 * '/network?f=&star=1', => $starred_active = 'active'
216 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
217 * '/network?f=&spam=1', => $spam_active = 'active'
219 * @return Array ($no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
221 function network_query_get_sel_tab(App $a) {
223 $starred_active = '';
225 $bookmarked_active = '';
229 $postord_active = '';
231 if (($a->argc > 1 && $a->argv[1] === 'new')
232 || ($a->argc > 2 && $a->argv[2] === 'new')) {
233 $new_active = 'active';
236 if (x($_GET,'star')) {
237 $starred_active = 'active';
240 if (x($_GET,'bmark')) {
241 $bookmarked_active = 'active';
244 if (x($_GET,'conv')) {
245 $conv_active = 'active';
248 if (x($_GET,'spam')) {
249 $spam_active = 'active';
254 if (($new_active == '')
255 && ($starred_active == '')
256 && ($bookmarked_active == '')
257 && ($conv_active == '')
258 && ($spam_active == '')) {
259 $no_active = 'active';
262 if ($no_active=='active' && x($_GET,'order')) {
263 switch($_GET['order']){
264 case 'post': $postord_active = 'active'; $no_active=''; break;
265 case 'comment' : $all_active = 'active'; $no_active=''; break;
269 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
273 * @brief Return selected network from query
274 * @return string Name of the selected network
276 function network_query_get_sel_net() {
279 if (x($_GET,'nets')) {
280 $network = $_GET['nets'];
286 function network_query_get_sel_group(App $a) {
289 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
290 $group = $a->argv[1];
297 * @brief Sets the pager data and returns SQL
299 * @param App $a The global App
300 * @param integer $update Used for the automatic reloading
301 * @return string SQL with the appropriate LIMIT clause
303 function networkPager($a, $update) {
305 // only setup pagination on initial page view
310 // check if we serve a mobile device and get the user settings
313 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network');
314 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
316 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network');
317 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
320 // now that we have the user settings, see if the theme forces
321 // a maximum item number which is lower then the user choice
322 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
323 $itemspage_network = $a->force_max_items;
326 $a->set_pager_itemspage($itemspage_network);
328 return sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
332 * @brief Sets items as seen
334 * @param array $condition The array with the SQL condition
336 function networkSetSeen($condition) {
337 if (empty($condition)) {
341 $unseen = dba::exists('item', $condition);
344 $r = dba::update('item', array('unseen' => false), $condition);
349 * @brief Create the conversation HTML
351 * @param App $a The global App
352 * @param array $items Items of the conversation
353 * @param string $mode Display mode for the conversation
354 * @param integer $update Used for the automatic reloading
355 * @return string HTML of the conversation
357 function networkConversation($a, $items, $mode, $update) {
358 // Set this so that the conversation function can find out contact info for our wall-wall items
359 $a->page_contact = $a->contact;
361 $o .= conversation($a, $items, $mode, $update);
364 if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
365 $o .= scroll_loader();
367 $o .= alt_pager($a, count($items));
374 function network_content(App $a, $update = 0) {
376 $_SESSION['return_url'] = $a->query_string;
380 /// @TODO Is this really necessary? $a is already available to hooks
381 $arr = array('query' => $a->query_string);
382 call_hooks('network_content_init', $arr);
387 for ($x = 1; $x < $a->argc; $x ++) {
388 if ($a->argv[$x] === 'new') {
394 if (x($_GET,'file')) {
399 $o = networkFlatView($a, $update);
401 $o = networkThreadedView($a, $update);
408 * @brief Get the network content in flat view
410 * @param App $a The global App
411 * @param integer $update Used for the automatic reloading
412 * @return string HTML of the network content in flat view
414 function networkFlatView(App $a, $update = 0) {
416 // Rawmode is used for fetching new content at the end of the page
417 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
419 if (isset($_GET["last_id"])) {
420 $last_id = intval($_GET["last_id"]);
427 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
429 PConfig::set(local_user(), 'network.view', 'net.selected', 'all');
431 if (!$update && !$rawmode) {
432 $tabs = network_tabs($a);
435 nav_set_selected('network');
439 'allow_location' => $a->user['allow_location'],
440 'default_location' => $a->user['default-location'],
441 'nickname' => $a->user['nickname'],
442 'lockstate'=> (((is_array($a->user) &&
443 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
444 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
445 'default_perms' => get_acl_permissions($a->user),
446 'acl' => populate_acl($a->user, true),
448 'visitor' => 'block',
449 'profile_uid' => local_user(),
450 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
454 $o .= status_editor($a,$x);
456 if (!Config::get('theme','hide_eventlist')) {
457 $o .= get_birthdays();
463 $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
464 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
466 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
469 $pager_sql = networkPager($a, $update);
471 // show all items unthreaded in reverse created date order
472 $items = q("SELECT %s FROM `item` $sql_post_table %s
473 WHERE %s AND `item`.`uid` = %d
474 ORDER BY `item`.`id` DESC $pager_sql ",
475 item_fieldlists(), item_joins(), item_condition(),
476 intval($_SESSION['uid'])
479 $condition = array('unseen' => true, 'uid' => local_user());
480 networkSetSeen($condition);
482 $mode = 'network-new';
483 $o .= networkConversation($a, $items, $mode, $update);
489 * @brief Get the network content in threaded view
491 * @param App $a The global App
492 * @param integer $update Used for the automatic reloading
493 * @return string HTML of the network content in flat view
495 function networkThreadedView(App $a, $update = 0) {
497 // Rawmode is used for fetching new content at the end of the page
498 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
500 if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
501 $last_received = DBM::date($_GET["last_received"]);
502 $last_commented = DBM::date($_GET["last_commented"]);
503 $last_created = DBM::date($_GET["last_created"]);
504 $last_id = intval($_GET["last_id"]);
507 $last_commented = '';
512 $datequery = $datequery2 = '';
517 for ($x = 1; $x < $a->argc; $x ++) {
518 if (is_a_date_arg($a->argv[$x])) {
520 $datequery2 = escape_tags($a->argv[$x]);
522 $datequery = escape_tags($a->argv[$x]);
523 $_GET['order'] = 'post';
525 } elseif (intval($a->argv[$x])) {
526 $group = intval($a->argv[$x]);
527 $def_acl = array('allow_gid' => '<' . $group . '>');
534 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
535 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
536 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
537 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
538 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
539 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
542 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
546 $r = dba::select('contact', array('id'), array('uid' => local_user(), 'network' => $nets), array('self' => false));
549 while ($rr = dba::fetch($r)) {
550 $str .= '<' . $rr['id'] . '>';
553 $def_acl = array('allow_cid' => $str);
556 PConfig::set(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
558 if (!$update && !$rawmode) {
559 $tabs = network_tabs($a);
563 if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
564 notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
565 "Warning: This group contains %s members from a network that doesn't allow non public messages.",
567 notice(t("Messages in this group won't be send to these receivers.").EOL);
571 nav_set_selected('network');
576 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
577 $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
578 $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
579 if (DBM::is_result($contact)) {
580 if ($contact["addr"] != '') {
581 $content = "!".$contact["addr"];
583 $content = "!".$contact["nick"]."+".$cid;
590 'allow_location' => $a->user['allow_location'],
591 'default_location' => $a->user['default-location'],
592 'nickname' => $a->user['nickname'],
593 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
594 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
595 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
596 'default_perms' => get_acl_permissions($a->user),
597 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
598 'bang' => (($group || $cid || $nets) ? '!' : ''),
599 'visitor' => 'block',
600 'profile_uid' => local_user(),
601 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
602 'content' => $content,
605 $o .= status_editor($a,$x);
609 // We don't have to deal with ACLs on this page. You're looking at everything
610 // that belongs to you, hence you can see all of it. We will filter by group if
613 $sql_post_table = "";
614 $sql_options = (($star) ? " AND `thread`.`starred` " : '');
615 $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
616 $sql_extra = $sql_options;
619 $sql_table = "`thread`";
620 $sql_parent = "`iid`";
623 $sql_table = "`item`";
624 $sql_parent = "`parent`";
625 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
628 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
631 $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
632 if (!DBM::is_result($r)) {
635 notice(t('No such group') . EOL);
640 $contacts = expand_groups(array($group));
642 if ((is_array($contacts)) && count($contacts)) {
643 $contact_str_self = "";
645 $contact_str = implode(',',$contacts);
646 $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
647 if (DBM::is_result($self)) {
648 $contact_str_self = $self["id"];
651 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
652 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
653 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
655 $sql_extra3 .= " AND false ";
656 info(t('Group is empty'));
659 $o = replace_macros(get_markup_template("section_title.tpl"),array(
660 '$title' => sprintf(t('Group: %s'), $r['name'])
664 $fields = array('id', 'name', 'network', 'writable', 'nurl',
665 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
666 $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
667 $r = dba::select('contact', $fields, $condition, array('limit' => 1));
668 if (DBM::is_result($r)) {
669 $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
673 'name' => htmlentities($r['name']),
674 'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
675 'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
676 'details' => $r['location'],
679 $entries[0]["account_type"] = account_type($r);
681 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
682 'contacts' => $entries,
686 if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
687 notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
691 notice(t('Invalid contact.') . EOL);
697 if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
698 $o .= get_birthdays();
703 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
706 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
710 $order_mode = "received";
713 $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
714 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
715 $sql_order = "`item`.`id`";
720 $sql_extra3 .= " AND $sql_table.`mention`";
723 // Normal conversation view
724 if ($order === 'post') {
725 $ordering = "`created`";
726 if ($sql_order == "") {
727 $order_mode = "created";
730 $ordering = "`commented`";
731 if ($sql_order == "") {
732 $order_mode = "commented";
736 if ($sql_order == "") {
737 $sql_order = "$sql_table.$ordering";
740 if (($_GET["offset"] != "")) {
741 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
744 $pager_sql = networkPager($a, $update);
746 switch ($order_mode) {
748 if ($last_received != '') {
749 $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
750 $a->set_pager_page(1);
751 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
755 if ($last_commented != '') {
756 $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
757 $a->set_pager_page(1);
758 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
762 if ($last_created != '') {
763 $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
764 $a->set_pager_page(1);
765 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
769 if (($last_id > 0) && ($sql_table == "`thread`")) {
770 $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
771 $a->set_pager_page(1);
772 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
777 // Fetch a page full of parent items for this page
779 if (Config::get("system", "like_no_comment")) {
780 $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'";
785 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
786 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
787 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
788 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
789 AND NOT `item`.`moderated` AND `item`.`unseen`
790 $sql_extra3 $sql_extra $sql_nets
791 ORDER BY `item_id` DESC LIMIT 100",
795 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
796 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
797 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
798 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
799 AND NOT `thread`.`moderated`
800 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
801 ORDER BY $sql_order DESC $pager_sql",
806 // Then fetch all the children of the parents that are on this page
808 $parents_arr = array();
812 if (DBM::is_result($r)) {
813 foreach ($r as $rr) {
814 if (!in_array($rr['item_id'],$parents_arr)) {
815 $parents_arr[] = $rr['item_id'];
819 $parents_str = implode(", ", $parents_arr);
821 // splitted into separate queries to avoid the problem with very long threads
822 // so always the last X comments are loaded
823 // This problem can occur expecially with imported facebook posts
824 $max_comments = Config::get("system", "max_comments");
825 if ($max_comments == 0) {
831 foreach ($parents_arr AS $parents) {
832 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
833 AND `item`.`parent` = ?
834 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
839 if (DBM::is_result($thread_items)) {
840 $items = array_merge($items, dba::inArray($thread_items));
843 $items = conv_sort($items,$ordering);
848 if ($_GET["offset"] == "") {
849 $date_offset = $items[0][$order_mode];
851 $date_offset = $_GET["offset"];
854 $a->page_offset = $date_offset;
856 // We aren't going to try and figure out at the item, group, and page
857 // level which items you've seen and which you haven't. If you're looking
858 // at the top level network page just mark everything seen.
860 if (!$group && !$cid && !$star) {
861 $condition = array('unseen' => true, 'uid' => local_user());
862 networkSetSeen($condition);
863 } elseif ($parents_str) {
864 $condition = array("`uid` = ? AND `unseen` AND `parent` IN (" . dbesc($parents_str) . ")", local_user());
865 networkSetSeen($condition);
870 $o .= networkConversation($a, $items, $mode, $update);
876 * @brief Get the network tabs menu
878 * @param App $a The global App
879 * @return string Html of the networktab
881 function network_tabs(App $a) {
883 /// @TODO fix this logic, reduce duplication
884 /// $a->page['content'] .= '<div class="tabs-wrapper">';
886 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
887 // if no tabs are selected, defaults to comments
888 if ($no_active=='active') $all_active='active';
890 $cmd = (($datequery) ? '' : $a->cmd);
891 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
896 'label' => t('Commented Order'),
897 'url' => str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
898 'sel' => $all_active,
899 'title' => t('Sort by Comment Date'),
900 'id' => 'commented-order-tab',
904 'label' => t('Posted Order'),
905 'url' => str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
906 'sel' => $postord_active,
907 'title' => t('Sort by Post Date'),
908 'id' => 'posted-order-tab',
913 if (feature_enabled(local_user(),'personal_tab')) {
915 'label' => t('Personal'),
916 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
917 'sel' => $conv_active,
918 'title' => t('Posts that mention or involve you'),
919 'id' => 'personal-tab',
924 if (feature_enabled(local_user(),'new_tab')) {
927 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
928 'sel' => $new_active,
929 'title' => t('Activity Stream - by date'),
930 'id' => 'activitiy-by-date-tab',
935 if (feature_enabled(local_user(),'link_tab')) {
937 'label' => t('Shared Links'),
938 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
939 'sel' => $bookmarked_active,
940 'title' => t('Interesting Links'),
941 'id' => 'shared-links-tab',
946 if (feature_enabled(local_user(),'star_posts')) {
948 'label' => t('Starred'),
949 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
950 'sel' => $starred_active,
951 'title' => t('Favourite Posts'),
952 'id' => 'starred-posts-tab',
957 // save selected tab, but only if not in file mode
958 if (!x($_GET,'file')) {
959 PConfig::set(local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active));
962 $arr = array('tabs' => $tabs);
963 call_hooks('network_tabs', $arr);
965 $tpl = get_markup_template('common_tabs.tpl');
967 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
969 // --- end item filter tabs