3 * @file mod/network.php
6 use Friendica\Content\ForumManager;
7 use Friendica\Core\System;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Database\DBM;
11 use Friendica\Object\Contact;
13 require_once 'include/conversation.php';
14 require_once 'include/group.php';
15 require_once 'include/contact_widgets.php';
16 require_once 'include/items.php';
17 require_once 'include/acl_selectors.php';
19 function network_init(App $a) {
21 notice(t('Permission denied.') . EOL);
25 $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
27 if (($search != '') && !empty($_GET['submit'])) {
28 goaway('search?search='.urlencode($search));
31 if (x($_GET, 'save')) {
32 $exists = dba::exists('search', array('uid' => local_user(), 'term' => $search));
34 dba::insert('search', array('uid' => local_user(), 'term' => $search));
37 if (x($_GET, 'remove')) {
38 dba::delete('search', array('uid' => local_user(), 'term' => $search));
41 $is_a_date_query = false;
42 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
44 $_GET['nets'] = 'all';
49 for ($x = 1; $x < $a->argc; $x ++) {
50 if (is_a_date_arg($a->argv[$x])) {
51 $is_a_date_query = true;
57 // convert query string to array. remove friendica args
58 $query_array = array();
59 $query_string = str_replace($a->cmd."?", "", $a->query_string);
60 parse_str($query_string, $query_array);
61 array_shift($query_array);
63 // fetch last used network view and redirect if needed
64 if (!$is_a_date_query) {
65 $sel_tabs = network_query_get_sel_tab($a);
66 $sel_nets = network_query_get_sel_net();
67 $sel_groups = network_query_get_sel_group($a);
68 $last_sel_tabs = PConfig::get(local_user(), 'network.view','tab.selected');
69 $last_sel_nets = PConfig::get(local_user(), 'network.view', 'net.selected');
70 $last_sel_groups = PConfig::get(local_user(), 'network.view', 'group.selected');
72 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
73 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
74 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
76 $net_baseurl = '/network';
79 if ($remember_group) {
80 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
81 } elseif ($sel_groups !== false) {
82 $net_baseurl .= '/' . $sel_groups;
86 // redirect if current selected tab is '/network' and
87 // last selected tab is _not_ '/network?f=&order=comment'.
88 // and this isn't a date query
90 $tab_baseurls = array(
100 'f=&order=comment', //all
101 'f=&order=post', //postord
104 'f=&star=1', //starred
105 'f=&bmark=1', //bookmarked
109 $k = array_search('active', $last_sel_tabs);
112 $net_baseurl .= $tab_baseurls[$k];
114 // parse out tab queries
116 $dest_qs = $tab_args[$k];
117 parse_str($dest_qs, $dest_qa);
118 $net_args = array_merge($net_args, $dest_qa);
120 $remember_tab = false;
122 } elseif ($sel_tabs[4] === 'active') {
123 // The '/new' tab is selected
124 $remember_group = false;
128 $net_args['nets'] = $last_sel_nets;
129 } elseif ($sel_nets!==false) {
130 $net_args['nets'] = $sel_nets;
133 if ($remember_tab || $remember_net || $remember_group) {
134 $net_args = array_merge($query_array, $net_args);
135 $net_queries = build_querystring($net_args);
137 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
139 goaway(System::baseUrl() . $redir_url);
143 // If nets is set to all, unset it
144 if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
145 unset($_GET['nets']);
148 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
150 PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
152 if (!x($a->page, 'aside')) {
153 $a->page['aside'] = '';
156 $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
157 $a->page['aside'] .= (feature_enabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : '');
158 $a->page['aside'] .= posted_date_widget('network',local_user(),false);
159 $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
160 $a->page['aside'] .= saved_searches($search);
161 $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : ''));
164 function saved_searches($search) {
166 if (!feature_enabled(local_user(),'savedsearch')) {
172 $srchurl = '/network?f='
173 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
174 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
175 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
176 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
177 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
178 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
179 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
180 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
185 $terms = dba::select('search', array('id', 'term'), array('uid' => local_user()));
188 while ($rr = dba::fetch($terms)) {
191 'term' => $rr['term'],
192 'encodedterm' => urlencode($rr['term']),
193 'delete' => t('Remove term'),
194 'selected' => ($search==$rr['term']),
198 $tpl = get_markup_template("saved_searches_aside.tpl");
199 $o = replace_macros($tpl, array(
200 '$title' => t('Saved Searches'),
202 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
210 * Return selected tab from query
213 * '/network' => $no_active = 'active'
214 * '/network?f=&order=comment' => $comment_active = 'active'
215 * '/network?f=&order=post' => $postord_active = 'active'
216 * '/network?f=&conv=1', => $conv_active = 'active'
217 * '/network/new', => $new_active = 'active'
218 * '/network?f=&star=1', => $starred_active = 'active'
219 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
220 * '/network?f=&spam=1', => $spam_active = 'active'
222 * @return Array ($no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
224 function network_query_get_sel_tab(App $a) {
226 $starred_active = '';
228 $bookmarked_active = '';
232 $postord_active = '';
234 if (($a->argc > 1 && $a->argv[1] === 'new')
235 || ($a->argc > 2 && $a->argv[2] === 'new')) {
236 $new_active = 'active';
239 if (x($_GET,'star')) {
240 $starred_active = 'active';
243 if (x($_GET,'bmark')) {
244 $bookmarked_active = 'active';
247 if (x($_GET,'conv')) {
248 $conv_active = 'active';
251 if (x($_GET,'spam')) {
252 $spam_active = 'active';
257 if (($new_active == '')
258 && ($starred_active == '')
259 && ($bookmarked_active == '')
260 && ($conv_active == '')
261 && ($spam_active == '')) {
262 $no_active = 'active';
265 if ($no_active=='active' && x($_GET,'order')) {
266 switch($_GET['order']){
267 case 'post': $postord_active = 'active'; $no_active=''; break;
268 case 'comment' : $all_active = 'active'; $no_active=''; break;
272 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
276 * @brief Return selected network from query
277 * @return string Name of the selected network
279 function network_query_get_sel_net() {
282 if (x($_GET,'nets')) {
283 $network = $_GET['nets'];
289 function network_query_get_sel_group(App $a) {
292 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
293 $group = $a->argv[1];
300 * @brief Sets the pager data and returns SQL
302 * @param App $a The global App
303 * @param integer $update Used for the automatic reloading
304 * @return string SQL with the appropriate LIMIT clause
306 function networkPager($a, $update) {
308 // only setup pagination on initial page view
313 // check if we serve a mobile device and get the user settings
316 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network');
317 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
319 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network');
320 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
323 // now that we have the user settings, see if the theme forces
324 // a maximum item number which is lower then the user choice
325 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
326 $itemspage_network = $a->force_max_items;
329 $a->set_pager_itemspage($itemspage_network);
331 return sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
335 * @brief Sets items as seen
337 * @param array $condition The array with the SQL condition
339 function networkSetSeen($condition) {
340 if (empty($condition)) {
344 $unseen = dba::exists('item', $condition);
347 $r = dba::update('item', array('unseen' => false), $condition);
352 * @brief Create the conversation HTML
354 * @param App $a The global App
355 * @param array $items Items of the conversation
356 * @param string $mode Display mode for the conversation
357 * @param integer $update Used for the automatic reloading
358 * @return string HTML of the conversation
360 function networkConversation($a, $items, $mode, $update) {
361 // Set this so that the conversation function can find out contact info for our wall-wall items
362 $a->page_contact = $a->contact;
364 $o .= conversation($a, $items, $mode, $update);
367 if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
368 $o .= scroll_loader();
370 $o .= alt_pager($a, count($items));
377 function network_content(App $a, $update = 0) {
379 $_SESSION['return_url'] = $a->query_string;
383 /// @TODO Is this really necessary? $a is already available to hooks
384 $arr = array('query' => $a->query_string);
385 call_hooks('network_content_init', $arr);
390 for ($x = 1; $x < $a->argc; $x ++) {
391 if ($a->argv[$x] === 'new') {
397 if (x($_GET,'file')) {
402 $o = networkFlatView($a, $update);
404 $o = networkThreadedView($a, $update);
411 * @brief Get the network content in flat view
413 * @param App $a The global App
414 * @param integer $update Used for the automatic reloading
415 * @return string HTML of the network content in flat view
417 function networkFlatView(App $a, $update = 0) {
419 // Rawmode is used for fetching new content at the end of the page
420 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
422 if (isset($_GET["last_id"])) {
423 $last_id = intval($_GET["last_id"]);
430 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
432 PConfig::set(local_user(), 'network.view', 'net.selected', 'all');
434 if (!$update && !$rawmode) {
435 $tabs = network_tabs($a);
438 nav_set_selected('network');
442 'allow_location' => $a->user['allow_location'],
443 'default_location' => $a->user['default-location'],
444 'nickname' => $a->user['nickname'],
445 'lockstate'=> (((is_array($a->user) &&
446 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
447 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
448 'default_perms' => get_acl_permissions($a->user),
449 'acl' => populate_acl($a->user, true),
451 'visitor' => 'block',
452 'profile_uid' => local_user(),
453 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
457 $o .= status_editor($a,$x);
459 if (!Config::get('theme','hide_eventlist')) {
460 $o .= get_birthdays();
466 $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` ",
467 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
469 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
472 $pager_sql = networkPager($a, $update);
474 // show all items unthreaded in reverse created date order
475 $items = q("SELECT %s FROM `item` $sql_post_table %s
476 WHERE %s AND `item`.`uid` = %d
477 ORDER BY `item`.`id` DESC $pager_sql ",
478 item_fieldlists(), item_joins(), item_condition(),
479 intval($_SESSION['uid'])
482 $condition = array('unseen' => true, 'uid' => local_user());
483 networkSetSeen($condition);
485 $mode = 'network-new';
486 $o .= networkConversation($a, $items, $mode, $update);
492 * @brief Get the network content in threaded view
494 * @param App $a The global App
495 * @param integer $update Used for the automatic reloading
496 * @return string HTML of the network content in flat view
498 function networkThreadedView(App $a, $update = 0) {
500 // Rawmode is used for fetching new content at the end of the page
501 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
503 if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
504 $last_received = DBM::date($_GET["last_received"]);
505 $last_commented = DBM::date($_GET["last_commented"]);
506 $last_created = DBM::date($_GET["last_created"]);
507 $last_id = intval($_GET["last_id"]);
510 $last_commented = '';
515 $datequery = $datequery2 = '';
520 for ($x = 1; $x < $a->argc; $x ++) {
521 if (is_a_date_arg($a->argv[$x])) {
523 $datequery2 = escape_tags($a->argv[$x]);
525 $datequery = escape_tags($a->argv[$x]);
526 $_GET['order'] = 'post';
528 } elseif (intval($a->argv[$x])) {
529 $group = intval($a->argv[$x]);
530 $def_acl = array('allow_gid' => '<' . $group . '>');
537 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
538 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
539 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
540 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
541 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
542 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
545 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
549 $r = dba::select('contact', array('id'), array('uid' => local_user(), 'network' => $nets), array('self' => false));
552 while ($rr = dba::fetch($r)) {
553 $str .= '<' . $rr['id'] . '>';
556 $def_acl = array('allow_cid' => $str);
559 PConfig::set(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
561 if (!$update && !$rawmode) {
562 $tabs = network_tabs($a);
566 if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
567 notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
568 "Warning: This group contains %s members from a network that doesn't allow non public messages.",
570 notice(t("Messages in this group won't be send to these receivers.").EOL);
574 nav_set_selected('network');
579 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
580 $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
581 $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
582 if (DBM::is_result($contact)) {
583 if ($contact["addr"] != '') {
584 $content = "!".$contact["addr"];
586 $content = "!".$contact["nick"]."+".$cid;
593 'allow_location' => $a->user['allow_location'],
594 'default_location' => $a->user['default-location'],
595 'nickname' => $a->user['nickname'],
596 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
597 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
598 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
599 'default_perms' => get_acl_permissions($a->user),
600 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
601 'bang' => (($group || $cid || $nets) ? '!' : ''),
602 'visitor' => 'block',
603 'profile_uid' => local_user(),
604 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
605 'content' => $content,
608 $o .= status_editor($a,$x);
612 // We don't have to deal with ACLs on this page. You're looking at everything
613 // that belongs to you, hence you can see all of it. We will filter by group if
616 $sql_post_table = "";
617 $sql_options = (($star) ? " AND `thread`.`starred` " : '');
618 $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
619 $sql_extra = $sql_options;
622 $sql_table = "`thread`";
623 $sql_parent = "`iid`";
626 $sql_table = "`item`";
627 $sql_parent = "`parent`";
628 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
631 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
634 $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
635 if (!DBM::is_result($r)) {
638 notice(t('No such group') . EOL);
643 $contacts = expand_groups(array($group));
645 if ((is_array($contacts)) && count($contacts)) {
646 $contact_str_self = "";
648 $contact_str = implode(',',$contacts);
649 $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
650 if (DBM::is_result($self)) {
651 $contact_str_self = $self["id"];
654 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
655 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
656 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
658 $sql_extra3 .= " AND false ";
659 info(t('Group is empty'));
662 $o = replace_macros(get_markup_template("section_title.tpl"),array(
663 '$title' => sprintf(t('Group: %s'), $r['name'])
667 $fields = array('id', 'name', 'network', 'writable', 'nurl',
668 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
669 $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
670 $r = dba::select('contact', $fields, $condition, array('limit' => 1));
671 if (DBM::is_result($r)) {
672 $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
676 'name' => htmlentities($r['name']),
677 'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
678 'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
679 'details' => $r['location'],
682 $entries[0]["account_type"] = Contact::getAccountType($r);
684 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
685 'contacts' => $entries,
689 if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
690 notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
694 notice(t('Invalid contact.') . EOL);
700 if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
701 $o .= get_birthdays();
706 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
709 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
713 $order_mode = "received";
716 $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` ",
717 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
718 $sql_order = "`item`.`id`";
723 $sql_extra3 .= " AND $sql_table.`mention`";
726 // Normal conversation view
727 if ($order === 'post') {
728 $ordering = "`created`";
729 if ($sql_order == "") {
730 $order_mode = "created";
733 $ordering = "`commented`";
734 if ($sql_order == "") {
735 $order_mode = "commented";
739 if ($sql_order == "") {
740 $sql_order = "$sql_table.$ordering";
743 if (($_GET["offset"] != "")) {
744 $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
747 $pager_sql = networkPager($a, $update);
749 switch ($order_mode) {
751 if ($last_received != '') {
752 $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
753 $a->set_pager_page(1);
754 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
758 if ($last_commented != '') {
759 $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
760 $a->set_pager_page(1);
761 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
765 if ($last_created != '') {
766 $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
767 $a->set_pager_page(1);
768 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
772 if (($last_id > 0) && ($sql_table == "`thread`")) {
773 $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
774 $a->set_pager_page(1);
775 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
780 // Fetch a page full of parent items for this page
782 if (Config::get("system", "like_no_comment")) {
783 $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'";
788 $r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
789 FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
790 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
791 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
792 AND NOT `item`.`moderated` AND `item`.`unseen`
793 $sql_extra3 $sql_extra $sql_nets
794 ORDER BY `item_id` DESC LIMIT 100",
798 $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
799 FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
800 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
801 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
802 AND NOT `thread`.`moderated`
803 $sql_extra2 $sql_extra3 $sql_extra $sql_nets
804 ORDER BY $sql_order DESC $pager_sql",
809 // Then fetch all the children of the parents that are on this page
811 $parents_arr = array();
815 if (DBM::is_result($r)) {
816 foreach ($r as $rr) {
817 if (!in_array($rr['item_id'],$parents_arr)) {
818 $parents_arr[] = $rr['item_id'];
822 $parents_str = implode(", ", $parents_arr);
824 // splitted into separate queries to avoid the problem with very long threads
825 // so always the last X comments are loaded
826 // This problem can occur expecially with imported facebook posts
827 $max_comments = Config::get("system", "max_comments");
828 if ($max_comments == 0) {
834 foreach ($parents_arr AS $parents) {
835 $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
836 AND `item`.`parent` = ?
837 ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
842 if (DBM::is_result($thread_items)) {
843 $items = array_merge($items, dba::inArray($thread_items));
846 $items = conv_sort($items,$ordering);
851 if ($_GET["offset"] == "") {
852 $date_offset = $items[0][$order_mode];
854 $date_offset = $_GET["offset"];
857 $a->page_offset = $date_offset;
859 // We aren't going to try and figure out at the item, group, and page
860 // level which items you've seen and which you haven't. If you're looking
861 // at the top level network page just mark everything seen.
863 if (!$group && !$cid && !$star) {
864 $condition = array('unseen' => true, 'uid' => local_user());
865 networkSetSeen($condition);
866 } elseif ($parents_str) {
867 $condition = array("`uid` = ? AND `unseen` AND `parent` IN (" . dbesc($parents_str) . ")", local_user());
868 networkSetSeen($condition);
873 $o .= networkConversation($a, $items, $mode, $update);
879 * @brief Get the network tabs menu
881 * @param App $a The global App
882 * @return string Html of the networktab
884 function network_tabs(App $a) {
886 /// @TODO fix this logic, reduce duplication
887 /// $a->page['content'] .= '<div class="tabs-wrapper">';
889 list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
890 // if no tabs are selected, defaults to comments
891 if ($no_active=='active') $all_active='active';
893 $cmd = (($datequery) ? '' : $a->cmd);
894 $len_naked_cmd = strlen(str_replace('/new','',$cmd));
899 'label' => t('Commented Order'),
900 'url' => str_replace('/new', '', $cmd) . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
901 'sel' => $all_active,
902 'title' => t('Sort by Comment Date'),
903 'id' => 'commented-order-tab',
907 'label' => t('Posted Order'),
908 'url' => str_replace('/new', '', $cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
909 'sel' => $postord_active,
910 'title' => t('Sort by Post Date'),
911 'id' => 'posted-order-tab',
916 if (feature_enabled(local_user(),'personal_tab')) {
918 'label' => t('Personal'),
919 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
920 'sel' => $conv_active,
921 'title' => t('Posts that mention or involve you'),
922 'id' => 'personal-tab',
927 if (feature_enabled(local_user(),'new_tab')) {
930 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
931 'sel' => $new_active,
932 'title' => t('Activity Stream - by date'),
933 'id' => 'activitiy-by-date-tab',
938 if (feature_enabled(local_user(),'link_tab')) {
940 'label' => t('Shared Links'),
941 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
942 'sel' => $bookmarked_active,
943 'title' => t('Interesting Links'),
944 'id' => 'shared-links-tab',
949 if (feature_enabled(local_user(),'star_posts')) {
951 'label' => t('Starred'),
952 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',
953 'sel' => $starred_active,
954 'title' => t('Favourite Posts'),
955 'id' => 'starred-posts-tab',
960 // save selected tab, but only if not in file mode
961 if (!x($_GET,'file')) {
962 PConfig::set(local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active));
965 $arr = array('tabs' => $tabs);
966 call_hooks('network_tabs', $arr);
968 $tpl = get_markup_template('common_tabs.tpl');
970 return replace_macros($tpl, array('$tabs' => $arr['tabs']));
972 // --- end item filter tabs