3 * @file mod/network.php
6 use Friendica\Content\Feature;
7 use Friendica\Content\ForumManager;
8 use Friendica\Core\System;
9 use Friendica\Core\Config;
10 use Friendica\Core\PConfig;
11 use Friendica\Database\DBM;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Group;
14 use Friendica\Module\Login;
16 require_once 'include/conversation.php';
17 require_once 'include/contact_widgets.php';
18 require_once 'include/items.php';
19 require_once 'include/acl_selectors.php';
21 function network_init(App $a) {
23 notice(t('Permission denied.') . EOL);
27 $search = (x($_GET, 'search') ? escape_tags($_GET['search']) : '');
29 if (($search != '') && !empty($_GET['submit'])) {
30 goaway('search?search='.urlencode($search));
33 if (x($_GET, 'save')) {
34 $exists = dba::exists('search', array('uid' => local_user(), 'term' => $search));
36 dba::insert('search', array('uid' => local_user(), 'term' => $search));
39 if (x($_GET, 'remove')) {
40 dba::delete('search', array('uid' => local_user(), 'term' => $search));
43 $is_a_date_query = false;
45 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
48 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
50 $_GET['nets'] = 'all';
54 PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
57 for ($x = 1; $x < $a->argc; $x ++) {
58 if (is_a_date_arg($a->argv[$x])) {
59 $is_a_date_query = true;
65 // convert query string to array. remove friendica args
66 $query_array = array();
67 $query_string = str_replace($a->cmd."?", "", $a->query_string);
68 parse_str($query_string, $query_array);
69 array_shift($query_array);
71 // fetch last used network view and redirect if needed
72 if (!$is_a_date_query) {
73 $sel_tabs = network_query_get_sel_tab($a);
74 $sel_nets = network_query_get_sel_net();
75 $sel_groups = network_query_get_sel_group($a);
76 $last_sel_tabs = PConfig::get(local_user(), 'network.view','tab.selected');
77 $last_sel_nets = PConfig::get(local_user(), 'network.view', 'net.selected');
78 $last_sel_groups = PConfig::get(local_user(), 'network.view', 'group.selected');
80 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
81 $remember_net = ($sel_nets === false && $last_sel_nets && $last_sel_nets !== 'all');
82 $remember_group = ($sel_groups === false && $last_sel_groups && $last_sel_groups != 0);
84 $net_baseurl = '/network';
87 if ($remember_group) {
88 $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
89 } elseif ($sel_groups !== false) {
90 $net_baseurl .= '/' . $sel_groups;
94 // redirect if current selected tab is '/network' and
95 // last selected tab is _not_ '/network?f=&order=comment'.
96 // and this isn't a date query
98 $tab_baseurls = array(
108 'f=&order=comment', //all
109 'f=&order=post', //postord
112 'f=&star=1', //starred
113 'f=&bmark=1', //bookmarked
117 $k = array_search('active', $last_sel_tabs);
120 $net_baseurl .= $tab_baseurls[$k];
122 // parse out tab queries
124 $dest_qs = $tab_args[$k];
125 parse_str($dest_qs, $dest_qa);
126 $net_args = array_merge($net_args, $dest_qa);
128 $remember_tab = false;
130 } elseif ($sel_tabs[4] === 'active') {
131 // The '/new' tab is selected
132 $remember_group = false;
136 $net_args['nets'] = $last_sel_nets;
137 } elseif ($sel_nets!==false) {
138 $net_args['nets'] = $sel_nets;
141 if ($remember_tab || $remember_net || $remember_group) {
142 $net_args = array_merge($query_array, $net_args);
143 $net_queries = build_querystring($net_args);
145 $redir_url = ($net_queries ? $net_baseurl."?".$net_queries : $net_baseurl);
147 goaway(System::baseUrl() . $redir_url);
151 // If nets is set to all, unset it
152 if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
153 unset($_GET['nets']);
157 if (!x($a->page, 'aside')) {
158 $a->page['aside'] = '';
161 $a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? Group::sidebarWidget('network/0','network','standard',$group_id) : '');
162 $a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : '');
163 $a->page['aside'] .= posted_date_widget('network',local_user(),false);
164 $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
165 $a->page['aside'] .= saved_searches($search);
166 $a->page['aside'] .= fileas_widget('network',(x($_GET, 'file') ? $_GET['file'] : ''));
169 function saved_searches($search) {
171 if (!Feature::isEnabled(local_user(),'savedsearch')) {
177 $srchurl = '/network?f='
178 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
179 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
180 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
181 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
182 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
183 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
184 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
185 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
190 $terms = dba::select('search', array('id', 'term'), array('uid' => local_user()));
193 while ($rr = dba::fetch($terms)) {
196 'term' => $rr['term'],
197 'encodedterm' => urlencode($rr['term']),
198 'delete' => t('Remove term'),
199 'selected' => ($search==$rr['term']),
203 $tpl = get_markup_template("saved_searches_aside.tpl");
204 $o = replace_macros($tpl, array(
205 '$title' => t('Saved Searches'),
207 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
215 * Return selected tab from query
218 * '/network' => $no_active = 'active'
219 * '/network?f=&order=comment' => $comment_active = 'active'
220 * '/network?f=&order=post' => $postord_active = 'active'
221 * '/network?f=&conv=1', => $conv_active = 'active'
222 * '/network/new', => $new_active = 'active'
223 * '/network?f=&star=1', => $starred_active = 'active'
224 * '/network?f=&bmark=1', => $bookmarked_active = 'active'
225 * '/network?f=&spam=1', => $spam_active = 'active'
227 * @return Array ($no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
229 function network_query_get_sel_tab(App $a) {
231 $starred_active = '';
233 $bookmarked_active = '';
237 $postord_active = '';
239 if (($a->argc > 1 && $a->argv[1] === 'new')
240 || ($a->argc > 2 && $a->argv[2] === 'new')) {
241 $new_active = 'active';
244 if (x($_GET,'star')) {
245 $starred_active = 'active';
248 if (x($_GET,'bmark')) {
249 $bookmarked_active = 'active';
252 if (x($_GET,'conv')) {
253 $conv_active = 'active';
256 if (x($_GET,'spam')) {
257 $spam_active = 'active';
262 if (($new_active == '')
263 && ($starred_active == '')
264 && ($bookmarked_active == '')
265 && ($conv_active == '')
266 && ($spam_active == '')) {
267 $no_active = 'active';
270 if ($no_active=='active' && x($_GET,'order')) {
271 switch($_GET['order']){
272 case 'post': $postord_active = 'active'; $no_active=''; break;
273 case 'comment' : $all_active = 'active'; $no_active=''; break;
277 return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active);
281 * @brief Return selected network from query
282 * @return string Name of the selected network
284 function network_query_get_sel_net() {
287 if (x($_GET,'nets')) {
288 $network = $_GET['nets'];
294 function network_query_get_sel_group(App $a) {
297 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
298 $group = $a->argv[1];
305 * @brief Sets the pager data and returns SQL
307 * @param App $a The global App
308 * @param integer $update Used for the automatic reloading
309 * @return string SQL with the appropriate LIMIT clause
311 function networkPager($a, $update) {
313 // only setup pagination on initial page view
318 // check if we serve a mobile device and get the user settings
321 $itemspage_network = PConfig::get(local_user(),'system','itemspage_mobile_network');
322 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 20);
324 $itemspage_network = PConfig::get(local_user(),'system','itemspage_network');
325 $itemspage_network = ((intval($itemspage_network)) ? $itemspage_network : 40);
328 // now that we have the user settings, see if the theme forces
329 // a maximum item number which is lower then the user choice
330 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
331 $itemspage_network = $a->force_max_items;
334 $a->set_pager_itemspage($itemspage_network);
336 return sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
340 * @brief Sets items as seen
342 * @param array $condition The array with the SQL condition
344 function networkSetSeen($condition) {
345 if (empty($condition)) {
349 $unseen = dba::exists('item', $condition);
352 $r = dba::update('item', array('unseen' => false), $condition);
357 * @brief Create the conversation HTML
359 * @param App $a The global App
360 * @param array $items Items of the conversation
361 * @param string $mode Display mode for the conversation
362 * @param integer $update Used for the automatic reloading
363 * @return string HTML of the conversation
365 function networkConversation($a, $items, $mode, $update) {
366 // Set this so that the conversation function can find out contact info for our wall-wall items
367 $a->page_contact = $a->contact;
369 $o = conversation($a, $items, $mode, $update);
372 if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
373 $o .= scroll_loader();
375 $o .= alt_pager($a, count($items));
382 function network_content(App $a, $update = 0) {
384 return Login::form();
387 /// @TODO Is this really necessary? $a is already available to hooks
388 $arr = array('query' => $a->query_string);
389 call_hooks('network_content_init', $arr);
394 for ($x = 1; $x < $a->argc; $x ++) {
395 if ($a->argv[$x] === 'new') {
401 if (x($_GET,'file')) {
406 $o = networkFlatView($a, $update);
408 $o = networkThreadedView($a, $update);
415 * @brief Get the network content in flat view
417 * @param App $a The global App
418 * @param integer $update Used for the automatic reloading
419 * @return string HTML of the network content in flat view
421 function networkFlatView(App $a, $update = 0) {
423 // Rawmode is used for fetching new content at the end of the page
424 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
426 if (isset($_GET["last_id"])) {
427 $last_id = intval($_GET["last_id"]);
434 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
436 PConfig::set(local_user(), 'network.view', 'net.selected', 'all');
438 if (!$update && !$rawmode) {
439 $tabs = network_tabs($a);
442 nav_set_selected('network');
446 'allow_location' => $a->user['allow_location'],
447 'default_location' => $a->user['default-location'],
448 'nickname' => $a->user['nickname'],
449 'lockstate'=> (((is_array($a->user) &&
450 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
451 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
452 'default_perms' => get_acl_permissions($a->user),
453 'acl' => populate_acl($a->user, true),
455 'visitor' => 'block',
456 'profile_uid' => local_user(),
457 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
461 $o .= status_editor($a,$x);
463 if (!Config::get('theme','hide_eventlist')) {
464 $o .= get_birthdays();
470 $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` ",
471 dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
473 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
476 $pager_sql = networkPager($a, $update);
478 // show all items unthreaded in reverse created date order
479 $items = q("SELECT %s FROM `item` $sql_post_table %s
480 WHERE %s AND `item`.`uid` = %d
481 ORDER BY `item`.`id` DESC $pager_sql ",
482 item_fieldlists(), item_joins(), item_condition(),
483 intval($_SESSION['uid'])
486 $condition = array('unseen' => true, 'uid' => local_user());
487 networkSetSeen($condition);
489 $mode = 'network-new';
490 $o .= networkConversation($a, $items, $mode, $update);
496 * @brief Get the network content in threaded view
498 * @param App $a The global App
499 * @param integer $update Used for the automatic reloading
500 * @return string HTML of the network content in flat view
502 function networkThreadedView(App $a, $update = 0) {
504 // Rawmode is used for fetching new content at the end of the page
505 $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
507 if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
508 $last_received = DBM::date($_GET["last_received"]);
509 $last_commented = DBM::date($_GET["last_commented"]);
510 $last_created = DBM::date($_GET["last_created"]);
511 $last_id = intval($_GET["last_id"]);
514 $last_commented = '';
519 $datequery = $datequery2 = '';
524 for ($x = 1; $x < $a->argc; $x ++) {
525 if (is_a_date_arg($a->argv[$x])) {
527 $datequery2 = escape_tags($a->argv[$x]);
529 $datequery = escape_tags($a->argv[$x]);
530 $_GET['order'] = 'post';
532 } elseif (intval($a->argv[$x])) {
533 $group = intval($a->argv[$x]);
534 $def_acl = array('allow_gid' => '<' . $group . '>');
541 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
542 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
543 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
544 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
545 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
546 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
549 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
553 $r = dba::select('contact', array('id'), array('uid' => local_user(), 'network' => $nets), array('self' => false));
556 while ($rr = dba::fetch($r)) {
557 $str .= '<' . $rr['id'] . '>';
560 $def_acl = array('allow_cid' => $str);
563 PConfig::set(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
565 if (!$update && !$rawmode) {
566 $tabs = network_tabs($a);
570 if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
571 notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
572 "Warning: This group contains %s members from a network that doesn't allow non public messages.",
574 notice(t("Messages in this group won't be send to these receivers.").EOL);
578 nav_set_selected('network');
583 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
584 $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
585 $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
586 if (DBM::is_result($contact)) {
587 if ($contact["addr"] != '') {
588 $content = "!".$contact["addr"];
590 $content = "!".$contact["nick"]."+".$cid;
597 'allow_location' => $a->user['allow_location'],
598 'default_location' => $a->user['default-location'],
599 'nickname' => $a->user['nickname'],
600 'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
601 ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
602 (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
603 'default_perms' => get_acl_permissions($a->user),
604 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
605 'bang' => (($group || $cid || $nets) ? '!' : ''),
606 'visitor' => 'block',
607 'profile_uid' => local_user(),
608 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
609 'content' => $content,
612 $o .= status_editor($a,$x);
616 // We don't have to deal with ACLs on this page. You're looking at everything
617 // that belongs to you, hence you can see all of it. We will filter by group if
620 $sql_post_table = "";
621 $sql_options = (($star) ? " AND `thread`.`starred` " : '');
622 $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
623 $sql_extra = $sql_options;
626 $sql_table = "`thread`";
627 $sql_parent = "`iid`";
630 $sql_table = "`item`";
631 $sql_parent = "`parent`";
632 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
635 $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
638 $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
639 if (!DBM::is_result($r)) {
642 notice(t('No such group') . EOL);
647 $contacts = Group::expand(array($group));
649 if ((is_array($contacts)) && count($contacts)) {
650 $contact_str_self = "";
652 $contact_str = implode(',',$contacts);
653 $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
654 if (DBM::is_result($self)) {
655 $contact_str_self = $self["id"];
658 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
659 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
660 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
662 $sql_extra3 .= " AND false ";
663 info(t('Group is empty'));
666 $o = replace_macros(get_markup_template("section_title.tpl"),array(
667 '$title' => t('Group: %s', $r['name'])
671 $fields = array('id', 'name', 'network', 'writable', 'nurl',
672 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
673 $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
674 $r = dba::select('contact', $fields, $condition, array('limit' => 1));
675 if (DBM::is_result($r)) {
676 $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
680 'name' => htmlentities($r['name']),
681 'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
682 'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
683 'details' => $r['location'],
686 $entries[0]["account_type"] = Contact::getAccountType($r);
688 $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
689 'contacts' => $entries,
693 if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
694 notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
698 notice(t('Invalid contact.') . EOL);
704 if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
705 $o .= get_birthdays();
710 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
713 $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
717 $order_mode = "received";
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 (x($_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();
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) {
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);
845 if (x($_GET, 'offset')) {
846 $date_offset = $_GET["offset"];
847 } elseif(count($items)) {
848 $date_offset = $items[0][$order_mode];
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)
883 /// @TODO fix this logic, reduce duplication
884 /// $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);
887 // if no tabs are selected, defaults to comments
888 if ($no_active == 'active') {
889 $all_active = 'active';
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::isEnabled(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::isEnabled(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::isEnabled(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::isEnabled(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