4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
8 require_once 'include/conversation.php';
9 require_once 'include/group.php';
10 require_once 'include/contact_widgets.php';
11 require_once 'include/items.php';
12 require_once 'include/ForumManager.php';
13 require_once 'include/acl_selectors.php';
15 function network_init(App $a) {
17 notice(t('Permission denied.') . EOL);
21 $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
23 if (($search != '') && !empty($_GET['submit'])) {
24 goaway('search?search='.urlencode($search));
27 if (x($_GET, 'save')) {
28 $exists = dba::exists('search', array('uid' => local_user(), 'term' => $search));
30 dba::insert('search', array('uid' => local_user(), 'term' => $search));
33 if (x($_GET, 'remove')) {
34 dba::delete('search', array('uid' => local_user(), 'term' => $search));
37 $is_a_date_query = false;
38 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
40 $_GET['nets'] = 'all';
45 for ($x = 1; $x < $a->argc; $x ++) {
46 if (is_a_date_arg($a->argv[$x])) {
47 $is_a_date_query = true;
53 // convert query string to array. remove friendica args
54 $query_array = array();
55 $query_string = str_replace($a->cmd."?", "", $a->query_string);
56 parse_str($query_string, $query_array);
57 array_shift($query_array);
59 // fetch last used network view and redirect if needed
60 if (!$is_a_date_query) {
61 $sel_tabs = network_query_get_sel_tab($a);
62 $sel_nets = network_query_get_sel_net();
63 $sel_groups = network_query_get_sel_group($a);
64 $last_sel_tabs = PConfig::get(local_user(), 'network.view','tab.selected');
65 $last_sel_nets = PConfig::get(local_user(), 'network.view', 'net.selected');
66 $last_sel_groups = PConfig::get(local_user(), 'network.view', 'group.selected');
68 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
69 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
70 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
72 $net_baseurl = '/network';
75 if ($remember_group) {
76 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
77 } elseif ($sel_groups !== false) {
78 $net_baseurl .= '/' . $sel_groups;
82 // redirect if current selected tab is '/network' and
83 // last selected tab is _not_ '/network?f=&order=comment'.
84 // and this isn't a date query
86 $tab_baseurls = array(
96 'f=&order=comment', //all
97 'f=&order=post', //postord
100 'f=&star=1', //starred
101 'f=&bmark=1', //bookmarked
105 $k = array_search('active', $last_sel_tabs);
108 $net_baseurl .= $tab_baseurls[$k];
110 // parse out tab queries
112 $dest_qs = $tab_args[$k];
113 parse_str($dest_qs, $dest_qa);
114 $net_args = array_merge($net_args, $dest_qa);
116 $remember_tab = false;
118 } elseif ($sel_tabs[4] === 'active') {
119 // The '/new' tab is selected
120 $remember_group = false;
124 $net_args['nets'] = $last_sel_nets;
125 } elseif ($sel_nets!==false) {
126 $net_args['nets'] = $sel_nets;
129 if ($remember_tab || $remember_net || $remember_group) {
130 $net_args = array_merge($query_array, $net_args);
131 $net_queries = build_querystring($net_args);
133 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
135 goaway(System::baseUrl() . $redir_url);
139 // If nets is set to all, unset it
140 if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
141 unset($_GET['nets']);
144 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
146 PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
148 if (!x($a->page, 'aside')) {
149 $a->page['aside'] = '';
152 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
153 $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? ForumManager::widget(local_user(),$cid) : '');
154 $a->page['aside'] .= posted_date_widget('network',local_user(),false);
155 $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
156 $a->page['aside'] .= saved_searches($search);
157 $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : ''));
160 function saved_searches($search) {
162 if (!feature_enabled(local_user(),'savedsearch')) {
168 $srchurl = '/network?f='
169 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
170 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
171 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
172 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
173 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
174 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
175 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
176 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
181 $terms = dba::select('search', array('id', 'term'), array('uid' => local_user()));
184 while ($rr = dba::fetch($terms)) {
187 'term' => $rr['term'],
188 'encodedterm' => urlencode($rr['term']),
189 'delete' => t('Remove term'),
190 'selected' => ($search==$rr['term']),
194 $tpl = get_markup_template("saved_searches_aside.tpl");
195 $o = replace_macros($tpl, array(
196 '$title' => t('Saved Searches'),
198 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
206 * Return selected tab from query
209 * '/network' => $no_active = 'active'
210 * '/network?f=&order=comment' => $comment_active = 'active'
211 * '/network?f=&order=post' => $postord_active = 'active'
212 * '/network?f=&conv=1', => $conv_active = 'active'
213 * '/network/new', => $new_active = 'active'
214 * '/network?f=&star=1', => $starred_active = 'active'
215 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
216 * '/network?f=&spam=1', => $spam_active = 'active'
218 * @return Array ($no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
220 function network_query_get_sel_tab(App $a) {
222 $starred_active = '';
224 $bookmarked_active = '';
228 $postord_active = '';
230 if (($a->argc > 1 && $a->argv[1] === 'new')
231 || ($a->argc > 2 && $a->argv[2] === 'new')) {
232 $new_active = 'active';
235 if (x($_GET,'star')) {
236 $starred_active = 'active';
239 if (x($_GET,'bmark')) {
240 $bookmarked_active = 'active';
243 if (x($_GET,'conv')) {
244 $conv_active = 'active';
247 if (x($_GET,'spam')) {
248 $spam_active = 'active';
253 if (($new_active == '')
254 && ($starred_active == '')
255 && ($bookmarked_active == '')
256 && ($conv_active == '')
257 && ($spam_active == '')) {
258 $no_active = 'active';
261 if ($no_active=='active' && x($_GET,'order')) {
262 switch($_GET['order']){
263 case 'post': $postord_active = 'active'; $no_active=''; break;
264 case 'comment' : $all_active = 'active'; $no_active=''; break;
268 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
272 * @brief Return selected network from query
273 * @return string Name of the selected network
275 function network_query_get_sel_net() {
278 if (x($_GET,'nets')) {
279 $network = $_GET['nets'];
285 function network_query_get_sel_group(App $a) {
288 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
289 $group = $a->argv[1];
296 * @brief Sets the pager data and returns SQL
298 * @param App $a The global App
299 * @param integer $update Used for the automatic reloading
300 * @return string SQL with the appropriate LIMIT clause
302 function networkPager($a, $update) {
304 // only setup pagination on initial page view
309 // check if we serve a mobile device and get the user settings
312 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network');
313 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
315 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network');
316 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
319 // now that we have the user settings, see if the theme forces
320 // a maximum item number which is lower then the user choice
321 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
322 $itemspage_network = $a->force_max_items;
325 $a->set_pager_itemspage($itemspage_network);
327 return sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
331 * @brief Sets items as seen
333 * @param array $condition The array with the SQL condition
335 function networkSetSeen($condition) {
336 if (empty($condition)) {
340 $unseen = dba::exists('item', $condition);
343 $r = dba::update('item', array('unseen' => false), $condition);
348 * @brief Create the conversation HTML
350 * @param App $a The global App
351 * @param array $items Items of the conversation
352 * @param string $mode Display mode for the conversation
353 * @param integer $update Used for the automatic reloading
354 * @return string HTML of the conversation
356 function networkConversation($a, $items, $mode, $update) {
357 // Set this so that the conversation function can find out contact info for our wall-wall items
358 $a->page_contact = $a->contact;
360 $o .= conversation($a, $items, $mode, $update);
363 if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
364 $o .= scroll_loader();
366 $o .= alt_pager($a, count($items));
373 function network_content(App $a, $update = 0) {
375 $_SESSION['return_url'] = $a->query_string;
379 /// @TODO Is this really necessary? $a is already available to hooks
380 $arr = array('query' => $a->query_string);
381 call_hooks('network_content_init', $arr);
386 for ($x = 1; $x < $a->argc; $x ++) {
387 if ($a->argv[$x] === 'new') {
393 if (x($_GET,'file')) {
398 $o = networkFlatView($a, $update);
400 $o = networkThreadedView($a, $update);
407 * @brief Get the network content in flat view
409 * @param App $a The global App
410 * @param integer $update Used for the automatic reloading
411 * @return string HTML of the network content in flat view
413 function networkFlatView(App $a, $update = 0) {
415 // Rawmode is used for fetching new content at the end of the page
416 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
418 if (isset($_GET["last_id"])) {
419 $last_id = intval($_GET["last_id"]);
426 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
428 PConfig::set(local_user(), 'network.view', 'net.selected', 'all');
430 if (!$update && !$rawmode) {
431 $tabs = network_tabs($a);
434 nav_set_selected('network');
438 'allow_location' => $a->user['allow_location'],
439 'default_location' => $a->user['default-location'],
440 'nickname' => $a->user['nickname'],
441 'lockstate'=> (((is_array($a->user) &&
442 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
443 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
444 'default_perms' => get_acl_permissions($a->user),
445 'acl' => populate_acl($a->user, true),
447 'visitor' => 'block',
448 'profile_uid' => local_user(),
449 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
453 $o .= status_editor($a,$x);
455 if (!Config::get('theme','hide_eventlist')) {
456 $o .= get_birthdays();
462 $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` ",
463 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
465 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
468 $pager_sql = networkPager($a, $update);
470 // show all items unthreaded in reverse created date order
471 $items = q("SELECT %s FROM `item` $sql_post_table %s
472 WHERE %s AND `item`.`uid` = %d
473 ORDER BY `item`.`id` DESC $pager_sql ",
474 item_fieldlists(), item_joins(), item_condition(),
475 intval($_SESSION['uid'])
478 $condition = array('unseen' => true, 'uid' => local_user());
479 networkSetSeen($condition);
481 $mode = 'network-new';
482 $o .= networkConversation($a, $items, $mode, $update);
488 * @brief Get the network content in threaded view
490 * @param App $a The global App
491 * @param integer $update Used for the automatic reloading
492 * @return string HTML of the network content in flat view
494 function networkThreadedView(App $a, $update = 0) {
496 // Rawmode is used for fetching new content at the end of the page
497 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
499 if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
500 $last_received = dbm::date($_GET["last_received"]);
501 $last_commented = dbm::date($_GET["last_commented"]);
502 $last_created = dbm::date($_GET["last_created"]);
503 $last_id = intval($_GET["last_id"]);
506 $last_commented = '';
511 $datequery = $datequery2 = '';
516 for ($x = 1; $x < $a->argc; $x ++) {
517 if (is_a_date_arg($a->argv[$x])) {
519 $datequery2 = escape_tags($a->argv[$x]);
521 $datequery = escape_tags($a->argv[$x]);
522 $_GET['order'] = 'post';
524 } elseif (intval($a->argv[$x])) {
525 $group = intval($a->argv[$x]);
526 $def_acl = array('allow_gid' => '<' . $group . '>');
533 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
534 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
535 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
536 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
537 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
538 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
541 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
545 $r = dba::select('contact', array('id'), array('uid' => local_user(), 'network' => $nets), array('self' => false));
548 while ($rr = dba::fetch($r)) {
549 $str .= '<' . $rr['id'] . '>';
552 $def_acl = array('allow_cid' => $str);
555 PConfig::set(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
557 if (!$update && !$rawmode) {
558 $tabs = network_tabs($a);
562 if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
563 notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
564 "Warning: This group contains %s members from a network that doesn't allow non public messages.",
566 notice(t("Messages in this group won't be send to these receivers.").EOL);
570 nav_set_selected('network');
575 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
576 $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
577 $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
578 if (dbm::is_result($contact)) {
579 if ($contact["addr"] != '') {
580 $content = "@".$contact["addr"];
582 $content = "@".$contact["nick"]."+".$cid;
589 'allow_location' => $a->user['allow_location'],
590 'default_location' => $a->user['default-location'],
591 'nickname' => $a->user['nickname'],
592 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
593 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
594 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
595 'default_perms' => get_acl_permissions($a->user),
596 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
597 'bang' => (($group || $cid || $nets) ? '!' : ''),
598 'visitor' => 'block',
599 'profile_uid' => local_user(),
600 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
601 'content' => $content,
604 $o .= status_editor($a,$x);
608 // We don't have to deal with ACLs on this page. You're looking at everything
609 // that belongs to you, hence you can see all of it. We will filter by group if
612 $sql_post_table = "";
613 $sql_options = (($star) ? " AND `thread`.`starred` " : '');
614 $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
615 $sql_extra = $sql_options;
618 $sql_table = "`thread`";
619 $sql_parent = "`iid`";
622 $sql_table = "`item`";
623 $sql_parent = "`parent`";
624 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
627 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
630 $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
631 if (!dbm::is_result($r)) {
634 notice(t('No such group') . EOL);
639 $contacts = expand_groups(array($group));
641 if ((is_array($contacts)) && count($contacts)) {
642 $contact_str_self = "";
644 $contact_str = implode(',',$contacts);
645 $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
646 if (dbm::is_result($self)) {
647 $contact_str_self = $self["id"];
650 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
651 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
652 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
654 $sql_extra3 .= " AND false ";
655 info(t('Group is empty'));
658 $o = replace_macros(get_markup_template("section_title.tpl"),array(
659 '$title' => sprintf(t('Group: %s'), $r['name'])
663 $fields = array('id', 'name', 'network', 'writable', 'nurl',
664 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
665 $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
666 $r = dba::select('contact', $fields, $condition, array('limit' => 1));
667 if (dbm::is_result($r)) {
668 $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
672 'name' => htmlentities($r['name']),
673 'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
674 'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
675 'details' => $r['location'],
678 $entries[0]["account_type"] = account_type($r);
680 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
681 'contacts' => $entries,
685 if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
686 notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
690 notice(t('Invalid contact.') . EOL);
696 if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
697 $o .= get_birthdays();
702 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
705 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
709 $order_mode = "received";
712 $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` ",
713 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
714 $sql_order = "`item`.`id`";
719 $sql_extra3 .= " AND $sql_table.`mention`";
722 // Normal conversation view
723 if ($order === 'post') {
724 $ordering = "`created`";
725 if ($sql_order == "") {
726 $order_mode = "created";
729 $ordering = "`commented`";
730 if ($sql_order == "") {
731 $order_mode = "commented";
735 if ($sql_order == "") {
736 $sql_order = "$sql_table.$ordering";
739 if (($_GET["offset"] != "")) {
740 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
743 $pager_sql = networkPager($a, $update);
745 switch ($order_mode) {
747 if ($last_received != '') {
748 $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
749 $a->set_pager_page(1);
750 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
754 if ($last_commented != '') {
755 $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
756 $a->set_pager_page(1);
757 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
761 if ($last_created != '') {
762 $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
763 $a->set_pager_page(1);
764 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
768 if (($last_id > 0) && ($sql_table == "`thread`")) {
769 $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
770 $a->set_pager_page(1);
771 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
776 // Fetch a page full of parent items for this page
778 if (Config::get("system", "like_no_comment")) {
779 $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'";
784 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
785 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
786 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
787 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
788 AND NOT `item`.`moderated` AND `item`.`unseen`
789 $sql_extra3 $sql_extra $sql_nets
790 ORDER BY `item_id` DESC LIMIT 100",
794 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
795 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
796 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
797 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
798 AND NOT `thread`.`moderated`
799 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
800 ORDER BY $sql_order DESC $pager_sql",
805 // Then fetch all the children of the parents that are on this page
807 $parents_arr = array();
811 if (dbm::is_result($r)) {
812 foreach ($r as $rr) {
813 if (!in_array($rr['item_id'],$parents_arr)) {
814 $parents_arr[] = $rr['item_id'];
818 $parents_str = implode(", ", $parents_arr);
820 // splitted into separate queries to avoid the problem with very long threads
821 // so always the last X comments are loaded
822 // This problem can occur expecially with imported facebook posts
823 $max_comments = Config::get("system", "max_comments");
824 if ($max_comments == 0) {
830 foreach ($parents_arr AS $parents) {
831 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
832 AND `item`.`parent` = ?
833 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
838 if (dbm::is_result($thread_items)) {
839 $items = array_merge($items, dba::inArray($thread_items));
842 $items = conv_sort($items,$ordering);
847 if ($_GET["offset"] == "") {
848 $date_offset = $items[0][$order_mode];
850 $date_offset = $_GET["offset"];
853 $a->page_offset = $date_offset;
855 // We aren't going to try and figure out at the item, group, and page
856 // level which items you've seen and which you haven't. If you're looking
857 // at the top level network page just mark everything seen.
859 if (!$group && !$cid && !$star) {
860 $condition = array('unseen' => true, 'uid' => local_user());
861 networkSetSeen($condition);
862 } elseif ($parents_str) {
863 $condition = array("`uid` = ? AND `unseen` AND `parent` IN (" . dbesc($parents_str) . ")", local_user());
864 networkSetSeen($condition);
869 $o .= networkConversation($a, $items, $mode, $update);
875 * @brief Get the network tabs menu
877 * @param App $a The global App
878 * @return string Html of the networktab
880 function network_tabs(App $a) {
882 /// @TODO fix this logic, reduce duplication
883 /// $a->page['content'] .= '<div class="tabs-wrapper">';
885 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
886 // if no tabs are selected, defaults to comments
887 if ($no_active=='active') $all_active='active';
889 $cmd = (($datequery) ? '' : $a->cmd);
890 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
895 'label' => t('Commented Order'),
896 'url' => str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
897 'sel' => $all_active,
898 'title' => t('Sort by Comment Date'),
899 'id' => 'commented-order-tab',
903 'label' => t('Posted Order'),
904 'url' => str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
905 'sel' => $postord_active,
906 'title' => t('Sort by Post Date'),
907 'id' => 'posted-order-tab',
912 if (feature_enabled(local_user(),'personal_tab')) {
914 'label' => t('Personal'),
915 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
916 'sel' => $conv_active,
917 'title' => t('Posts that mention or involve you'),
918 'id' => 'personal-tab',
923 if (feature_enabled(local_user(),'new_tab')) {
926 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
927 'sel' => $new_active,
928 'title' => t('Activity Stream - by date'),
929 'id' => 'activitiy-by-date-tab',
934 if (feature_enabled(local_user(),'link_tab')) {
936 'label' => t('Shared Links'),
937 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
938 'sel' => $bookmarked_active,
939 'title' => t('Interesting Links'),
940 'id' => 'shared-links-tab',
945 if (feature_enabled(local_user(),'star_posts')) {
947 'label' => t('Starred'),
948 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
949 'sel' => $starred_active,
950 'title' => t('Favourite Posts'),
951 'id' => 'starred-posts-tab',
956 // save selected tab, but only if not in file mode
957 if (!x($_GET,'file')) {
958 PConfig::set(local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active));
961 $arr = array('tabs' => $tabs);
962 call_hooks('network_tabs', $arr);
964 $tpl = get_markup_template('common_tabs.tpl');
966 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
968 // --- end item filter tabs