4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Core\PConfig;
7 use Friendica\Database\DBM;
8 use Friendica\Object\Contact;
10 require_once 'include/conversation.php';
11 require_once 'include/group.php';
12 require_once 'include/contact_widgets.php';
13 require_once 'include/items.php';
14 require_once 'include/ForumManager.php';
15 require_once 'include/acl_selectors.php';
17 function network_init(App $a) {
19 notice(t('Permission denied.') . EOL);
23 $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
25 if (($search != '') && !empty($_GET['submit'])) {
26 goaway('search?search='.urlencode($search));
29 if (x($_GET, 'save')) {
30 $exists = dba::exists('search', array('uid' => local_user(), 'term' => $search));
32 dba::insert('search', array('uid' => local_user(), 'term' => $search));
35 if (x($_GET, 'remove')) {
36 dba::delete('search', array('uid' => local_user(), 'term' => $search));
39 $is_a_date_query = false;
40 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
42 $_GET['nets'] = 'all';
47 for ($x = 1; $x < $a->argc; $x ++) {
48 if (is_a_date_arg($a->argv[$x])) {
49 $is_a_date_query = true;
55 // convert query string to array. remove friendica args
56 $query_array = array();
57 $query_string = str_replace($a->cmd."?", "", $a->query_string);
58 parse_str($query_string, $query_array);
59 array_shift($query_array);
61 // fetch last used network view and redirect if needed
62 if (!$is_a_date_query) {
63 $sel_tabs = network_query_get_sel_tab($a);
64 $sel_nets = network_query_get_sel_net();
65 $sel_groups = network_query_get_sel_group($a);
66 $last_sel_tabs = PConfig::get(local_user(), 'network.view','tab.selected');
67 $last_sel_nets = PConfig::get(local_user(), 'network.view', 'net.selected');
68 $last_sel_groups = PConfig::get(local_user(), 'network.view', 'group.selected');
70 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
71 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
72 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
74 $net_baseurl = '/network';
77 if ($remember_group) {
78 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
79 } elseif ($sel_groups !== false) {
80 $net_baseurl .= '/' . $sel_groups;
84 // redirect if current selected tab is '/network' and
85 // last selected tab is _not_ '/network?f=&order=comment'.
86 // and this isn't a date query
88 $tab_baseurls = array(
98 'f=&order=comment', //all
99 'f=&order=post', //postord
102 'f=&star=1', //starred
103 'f=&bmark=1', //bookmarked
107 $k = array_search('active', $last_sel_tabs);
110 $net_baseurl .= $tab_baseurls[$k];
112 // parse out tab queries
114 $dest_qs = $tab_args[$k];
115 parse_str($dest_qs, $dest_qa);
116 $net_args = array_merge($net_args, $dest_qa);
118 $remember_tab = false;
120 } elseif ($sel_tabs[4] === 'active') {
121 // The '/new' tab is selected
122 $remember_group = false;
126 $net_args['nets'] = $last_sel_nets;
127 } elseif ($sel_nets!==false) {
128 $net_args['nets'] = $sel_nets;
131 if ($remember_tab || $remember_net || $remember_group) {
132 $net_args = array_merge($query_array, $net_args);
133 $net_queries = build_querystring($net_args);
135 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
137 goaway(System::baseUrl() . $redir_url);
141 // If nets is set to all, unset it
142 if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
143 unset($_GET['nets']);
146 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
148 PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
150 if (!x($a->page, 'aside')) {
151 $a->page['aside'] = '';
154 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
155 $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? ForumManager::widget(local_user(),$cid) : '');
156 $a->page['aside'] .= posted_date_widget('network',local_user(),false);
157 $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
158 $a->page['aside'] .= saved_searches($search);
159 $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : ''));
162 function saved_searches($search) {
164 if (!feature_enabled(local_user(),'savedsearch')) {
170 $srchurl = '/network?f='
171 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
172 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
173 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
174 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
175 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
176 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
177 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
178 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
183 $terms = dba::select('search', array('id', 'term'), array('uid' => local_user()));
186 while ($rr = dba::fetch($terms)) {
189 'term' => $rr['term'],
190 'encodedterm' => urlencode($rr['term']),
191 'delete' => t('Remove term'),
192 'selected' => ($search==$rr['term']),
196 $tpl = get_markup_template("saved_searches_aside.tpl");
197 $o = replace_macros($tpl, array(
198 '$title' => t('Saved Searches'),
200 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
208 * Return selected tab from query
211 * '/network' => $no_active = 'active'
212 * '/network?f=&order=comment' => $comment_active = 'active'
213 * '/network?f=&order=post' => $postord_active = 'active'
214 * '/network?f=&conv=1', => $conv_active = 'active'
215 * '/network/new', => $new_active = 'active'
216 * '/network?f=&star=1', => $starred_active = 'active'
217 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
218 * '/network?f=&spam=1', => $spam_active = 'active'
220 * @return Array ($no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
222 function network_query_get_sel_tab(App $a) {
224 $starred_active = '';
226 $bookmarked_active = '';
230 $postord_active = '';
232 if (($a->argc > 1 && $a->argv[1] === 'new')
233 || ($a->argc > 2 && $a->argv[2] === 'new')) {
234 $new_active = 'active';
237 if (x($_GET,'star')) {
238 $starred_active = 'active';
241 if (x($_GET,'bmark')) {
242 $bookmarked_active = 'active';
245 if (x($_GET,'conv')) {
246 $conv_active = 'active';
249 if (x($_GET,'spam')) {
250 $spam_active = 'active';
255 if (($new_active == '')
256 && ($starred_active == '')
257 && ($bookmarked_active == '')
258 && ($conv_active == '')
259 && ($spam_active == '')) {
260 $no_active = 'active';
263 if ($no_active=='active' && x($_GET,'order')) {
264 switch($_GET['order']){
265 case 'post': $postord_active = 'active'; $no_active=''; break;
266 case 'comment' : $all_active = 'active'; $no_active=''; break;
270 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
274 * @brief Return selected network from query
275 * @return string Name of the selected network
277 function network_query_get_sel_net() {
280 if (x($_GET,'nets')) {
281 $network = $_GET['nets'];
287 function network_query_get_sel_group(App $a) {
290 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
291 $group = $a->argv[1];
298 * @brief Sets the pager data and returns SQL
300 * @param App $a The global App
301 * @param integer $update Used for the automatic reloading
302 * @return string SQL with the appropriate LIMIT clause
304 function networkPager($a, $update) {
306 // only setup pagination on initial page view
311 // check if we serve a mobile device and get the user settings
314 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network');
315 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
317 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network');
318 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
321 // now that we have the user settings, see if the theme forces
322 // a maximum item number which is lower then the user choice
323 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
324 $itemspage_network = $a->force_max_items;
327 $a->set_pager_itemspage($itemspage_network);
329 return sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
333 * @brief Sets items as seen
335 * @param array $condition The array with the SQL condition
337 function networkSetSeen($condition) {
338 if (empty($condition)) {
342 $unseen = dba::exists('item', $condition);
345 $r = dba::update('item', array('unseen' => false), $condition);
350 * @brief Create the conversation HTML
352 * @param App $a The global App
353 * @param array $items Items of the conversation
354 * @param string $mode Display mode for the conversation
355 * @param integer $update Used for the automatic reloading
356 * @return string HTML of the conversation
358 function networkConversation($a, $items, $mode, $update) {
359 // Set this so that the conversation function can find out contact info for our wall-wall items
360 $a->page_contact = $a->contact;
362 $o .= conversation($a, $items, $mode, $update);
365 if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
366 $o .= scroll_loader();
368 $o .= alt_pager($a, count($items));
375 function network_content(App $a, $update = 0) {
377 $_SESSION['return_url'] = $a->query_string;
381 /// @TODO Is this really necessary? $a is already available to hooks
382 $arr = array('query' => $a->query_string);
383 call_hooks('network_content_init', $arr);
388 for ($x = 1; $x < $a->argc; $x ++) {
389 if ($a->argv[$x] === 'new') {
395 if (x($_GET,'file')) {
400 $o = networkFlatView($a, $update);
402 $o = networkThreadedView($a, $update);
409 * @brief Get the network content in flat view
411 * @param App $a The global App
412 * @param integer $update Used for the automatic reloading
413 * @return string HTML of the network content in flat view
415 function networkFlatView(App $a, $update = 0) {
417 // Rawmode is used for fetching new content at the end of the page
418 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
420 if (isset($_GET["last_id"])) {
421 $last_id = intval($_GET["last_id"]);
428 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
430 PConfig::set(local_user(), 'network.view', 'net.selected', 'all');
432 if (!$update && !$rawmode) {
433 $tabs = network_tabs($a);
436 nav_set_selected('network');
440 'allow_location' => $a->user['allow_location'],
441 'default_location' => $a->user['default-location'],
442 'nickname' => $a->user['nickname'],
443 'lockstate'=> (((is_array($a->user) &&
444 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
445 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
446 'default_perms' => get_acl_permissions($a->user),
447 'acl' => populate_acl($a->user, true),
449 'visitor' => 'block',
450 'profile_uid' => local_user(),
451 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
455 $o .= status_editor($a,$x);
457 if (!Config::get('theme','hide_eventlist')) {
458 $o .= get_birthdays();
464 $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` ",
465 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
467 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
470 $pager_sql = networkPager($a, $update);
472 // show all items unthreaded in reverse created date order
473 $items = q("SELECT %s FROM `item` $sql_post_table %s
474 WHERE %s AND `item`.`uid` = %d
475 ORDER BY `item`.`id` DESC $pager_sql ",
476 item_fieldlists(), item_joins(), item_condition(),
477 intval($_SESSION['uid'])
480 $condition = array('unseen' => true, 'uid' => local_user());
481 networkSetSeen($condition);
483 $mode = 'network-new';
484 $o .= networkConversation($a, $items, $mode, $update);
490 * @brief Get the network content in threaded view
492 * @param App $a The global App
493 * @param integer $update Used for the automatic reloading
494 * @return string HTML of the network content in flat view
496 function networkThreadedView(App $a, $update = 0) {
498 // Rawmode is used for fetching new content at the end of the page
499 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
501 if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
502 $last_received = DBM::date($_GET["last_received"]);
503 $last_commented = DBM::date($_GET["last_commented"]);
504 $last_created = DBM::date($_GET["last_created"]);
505 $last_id = intval($_GET["last_id"]);
508 $last_commented = '';
513 $datequery = $datequery2 = '';
518 for ($x = 1; $x < $a->argc; $x ++) {
519 if (is_a_date_arg($a->argv[$x])) {
521 $datequery2 = escape_tags($a->argv[$x]);
523 $datequery = escape_tags($a->argv[$x]);
524 $_GET['order'] = 'post';
526 } elseif (intval($a->argv[$x])) {
527 $group = intval($a->argv[$x]);
528 $def_acl = array('allow_gid' => '<' . $group . '>');
535 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
536 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
537 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
538 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
539 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
540 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
543 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
547 $r = dba::select('contact', array('id'), array('uid' => local_user(), 'network' => $nets), array('self' => false));
550 while ($rr = dba::fetch($r)) {
551 $str .= '<' . $rr['id'] . '>';
554 $def_acl = array('allow_cid' => $str);
557 PConfig::set(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
559 if (!$update && !$rawmode) {
560 $tabs = network_tabs($a);
564 if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
565 notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
566 "Warning: This group contains %s members from a network that doesn't allow non public messages.",
568 notice(t("Messages in this group won't be send to these receivers.").EOL);
572 nav_set_selected('network');
577 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
578 $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
579 $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
580 if (DBM::is_result($contact)) {
581 if ($contact["addr"] != '') {
582 $content = "!".$contact["addr"];
584 $content = "!".$contact["nick"]."+".$cid;
591 'allow_location' => $a->user['allow_location'],
592 'default_location' => $a->user['default-location'],
593 'nickname' => $a->user['nickname'],
594 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
595 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
596 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
597 'default_perms' => get_acl_permissions($a->user),
598 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
599 'bang' => (($group || $cid || $nets) ? '!' : ''),
600 'visitor' => 'block',
601 'profile_uid' => local_user(),
602 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
603 'content' => $content,
606 $o .= status_editor($a,$x);
610 // We don't have to deal with ACLs on this page. You're looking at everything
611 // that belongs to you, hence you can see all of it. We will filter by group if
614 $sql_post_table = "";
615 $sql_options = (($star) ? " AND `thread`.`starred` " : '');
616 $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
617 $sql_extra = $sql_options;
620 $sql_table = "`thread`";
621 $sql_parent = "`iid`";
624 $sql_table = "`item`";
625 $sql_parent = "`parent`";
626 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
629 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
632 $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
633 if (!DBM::is_result($r)) {
636 notice(t('No such group') . EOL);
641 $contacts = expand_groups(array($group));
643 if ((is_array($contacts)) && count($contacts)) {
644 $contact_str_self = "";
646 $contact_str = implode(',',$contacts);
647 $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
648 if (DBM::is_result($self)) {
649 $contact_str_self = $self["id"];
652 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
653 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
654 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
656 $sql_extra3 .= " AND false ";
657 info(t('Group is empty'));
660 $o = replace_macros(get_markup_template("section_title.tpl"),array(
661 '$title' => sprintf(t('Group: %s'), $r['name'])
665 $fields = array('id', 'name', 'network', 'writable', 'nurl',
666 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
667 $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
668 $r = dba::select('contact', $fields, $condition, array('limit' => 1));
669 if (DBM::is_result($r)) {
670 $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
674 'name' => htmlentities($r['name']),
675 'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
676 'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
677 'details' => $r['location'],
680 $entries[0]["account_type"] = account_type($r);
682 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
683 'contacts' => $entries,
687 if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
688 notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
692 notice(t('Invalid contact.') . EOL);
698 if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
699 $o .= get_birthdays();
704 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
707 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
711 $order_mode = "received";
714 $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` ",
715 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
716 $sql_order = "`item`.`id`";
721 $sql_extra3 .= " AND $sql_table.`mention`";
724 // Normal conversation view
725 if ($order === 'post') {
726 $ordering = "`created`";
727 if ($sql_order == "") {
728 $order_mode = "created";
731 $ordering = "`commented`";
732 if ($sql_order == "") {
733 $order_mode = "commented";
737 if ($sql_order == "") {
738 $sql_order = "$sql_table.$ordering";
741 if (($_GET["offset"] != "")) {
742 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
745 $pager_sql = networkPager($a, $update);
747 switch ($order_mode) {
749 if ($last_received != '') {
750 $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
751 $a->set_pager_page(1);
752 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
756 if ($last_commented != '') {
757 $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
758 $a->set_pager_page(1);
759 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
763 if ($last_created != '') {
764 $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
765 $a->set_pager_page(1);
766 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
770 if (($last_id > 0) && ($sql_table == "`thread`")) {
771 $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
772 $a->set_pager_page(1);
773 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
778 // Fetch a page full of parent items for this page
780 if (Config::get("system", "like_no_comment")) {
781 $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'";
786 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
787 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
788 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
789 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
790 AND NOT `item`.`moderated` AND `item`.`unseen`
791 $sql_extra3 $sql_extra $sql_nets
792 ORDER BY `item_id` DESC LIMIT 100",
796 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
797 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
798 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
799 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
800 AND NOT `thread`.`moderated`
801 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
802 ORDER BY $sql_order DESC $pager_sql",
807 // Then fetch all the children of the parents that are on this page
809 $parents_arr = array();
813 if (DBM::is_result($r)) {
814 foreach ($r as $rr) {
815 if (!in_array($rr['item_id'],$parents_arr)) {
816 $parents_arr[] = $rr['item_id'];
820 $parents_str = implode(", ", $parents_arr);
822 // splitted into separate queries to avoid the problem with very long threads
823 // so always the last X comments are loaded
824 // This problem can occur expecially with imported facebook posts
825 $max_comments = Config::get("system", "max_comments");
826 if ($max_comments == 0) {
832 foreach ($parents_arr AS $parents) {
833 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
834 AND `item`.`parent` = ?
835 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
840 if (DBM::is_result($thread_items)) {
841 $items = array_merge($items, dba::inArray($thread_items));
844 $items = conv_sort($items,$ordering);
849 if ($_GET["offset"] == "") {
850 $date_offset = $items[0][$order_mode];
852 $date_offset = $_GET["offset"];
855 $a->page_offset = $date_offset;
857 // We aren't going to try and figure out at the item, group, and page
858 // level which items you've seen and which you haven't. If you're looking
859 // at the top level network page just mark everything seen.
861 if (!$group && !$cid && !$star) {
862 $condition = array('unseen' => true, 'uid' => local_user());
863 networkSetSeen($condition);
864 } elseif ($parents_str) {
865 $condition = array("`uid` = ? AND `unseen` AND `parent` IN (" . dbesc($parents_str) . ")", local_user());
866 networkSetSeen($condition);
871 $o .= networkConversation($a, $items, $mode, $update);
877 * @brief Get the network tabs menu
879 * @param App $a The global App
880 * @return string Html of the networktab
882 function network_tabs(App $a) {
884 /// @TODO fix this logic, reduce duplication
885 /// $a->page['content'] .= '<div class="tabs-wrapper">';
887 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
888 // if no tabs are selected, defaults to comments
889 if ($no_active=='active') $all_active='active';
891 $cmd = (($datequery) ? '' : $a->cmd);
892 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
897 'label' => t('Commented Order'),
898 'url' => str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
899 'sel' => $all_active,
900 'title' => t('Sort by Comment Date'),
901 'id' => 'commented-order-tab',
905 'label' => t('Posted Order'),
906 'url' => str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
907 'sel' => $postord_active,
908 'title' => t('Sort by Post Date'),
909 'id' => 'posted-order-tab',
914 if (feature_enabled(local_user(),'personal_tab')) {
916 'label' => t('Personal'),
917 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
918 'sel' => $conv_active,
919 'title' => t('Posts that mention or involve you'),
920 'id' => 'personal-tab',
925 if (feature_enabled(local_user(),'new_tab')) {
928 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
929 'sel' => $new_active,
930 'title' => t('Activity Stream - by date'),
931 'id' => 'activitiy-by-date-tab',
936 if (feature_enabled(local_user(),'link_tab')) {
938 'label' => t('Shared Links'),
939 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
940 'sel' => $bookmarked_active,
941 'title' => t('Interesting Links'),
942 'id' => 'shared-links-tab',
947 if (feature_enabled(local_user(),'star_posts')) {
949 'label' => t('Starred'),
950 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
951 'sel' => $starred_active,
952 'title' => t('Favourite Posts'),
953 'id' => 'starred-posts-tab',
958 // save selected tab, but only if not in file mode
959 if (!x($_GET,'file')) {
960 PConfig::set(local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active));
963 $arr = array('tabs' => $tabs);
964 call_hooks('network_tabs', $arr);
966 $tpl = get_markup_template('common_tabs.tpl');
968 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
970 // --- end item filter tabs