]> git.mxchange.org Git - friendica.git/blob - mod/network.php
Issue 9358: liking and commenting on the community page now gives a feedback
[friendica.git] / mod / network.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Content\ForumManager;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Content\Text\HTML;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Hook;
30 use Friendica\Core\Logger;
31 use Friendica\Core\Renderer;
32 use Friendica\Database\DBA;
33 use Friendica\DI;
34 use Friendica\Model\Contact;
35 use Friendica\Model\Group;
36 use Friendica\Model\Item;
37 use Friendica\Model\Post\Category;
38 use Friendica\Model\Profile;
39 use Friendica\Model\User;
40 use Friendica\Module\Contact as ModuleContact;
41 use Friendica\Module\Security\Login;
42 use Friendica\Util\DateTimeFormat;
43 use Friendica\Util\Strings;
44
45 function network_init(App $a)
46 {
47         if (!local_user()) {
48                 notice(DI::l10n()->t('Permission denied.'));
49                 return;
50         }
51
52         $is_a_date_query = false;
53
54         $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
55
56         $cid = 0;
57         if (!empty($_GET['contactid'])) {
58                 $cid = $_GET['contactid'];
59                 $_GET['nets'] = '';
60                 $group_id = 0;
61         }
62
63         if ($a->argc > 1) {
64                 for ($x = 1; $x < $a->argc; $x ++) {
65                         if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
66                                 $is_a_date_query = true;
67                                 break;
68                         }
69                 }
70         }
71
72         // convert query string to array. remove friendica args
73         $query_array = [];
74         parse_str(parse_url(DI::args()->getQueryString(), PHP_URL_QUERY), $query_array);
75
76         // fetch last used network view and redirect if needed
77         if (!$is_a_date_query) {
78                 $sel_nets = $_GET['nets'] ?? '';
79                 $sel_tabs = network_query_get_sel_tab($a);
80                 $sel_groups = network_query_get_sel_group($a);
81                 $last_sel_tabs = DI::pConfig()->get(local_user(), 'network.view', 'tab.selected');
82
83                 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
84
85                 $net_baseurl = '/network';
86                 $net_args = [];
87
88                 if ($sel_groups !== false) {
89                         $net_baseurl .= '/' . $sel_groups;
90                 }
91
92                 if ($remember_tab) {
93                         // redirect if current selected tab is '/network' and
94                         // last selected tab is _not_ '/network?order=activity'.
95                         // and this isn't a date query
96
97                         $tab_args = [
98                                 'order=activity', //all
99                                 'order=post',     //postord
100                                 'conv=1',         //conv
101                                 'star=1',         //starred
102                         ];
103
104                         $k = array_search('active', $last_sel_tabs);
105
106                         if ($k != 3) {
107                                 // parse out tab queries
108                                 $dest_qa = [];
109                                 $dest_qs = $tab_args[$k];
110                                 parse_str($dest_qs, $dest_qa);
111                                 $net_args = array_merge($net_args, $dest_qa);
112                         } else {
113                                 $remember_tab = false;
114                         }
115                 }
116
117                 if ($sel_nets) {
118                         $net_args['nets'] = $sel_nets;
119                 }
120
121                 if ($remember_tab) {
122                         $net_args = array_merge($query_array, $net_args);
123                         $net_queries = http_build_query($net_args);
124
125                         $redir_url = ($net_queries ? $net_baseurl . '?' . $net_queries : $net_baseurl);
126
127                         DI::baseUrl()->redirect($redir_url);
128                 }
129         }
130
131         if (empty(DI::page()['aside'])) {
132                 DI::page()['aside'] = '';
133         }
134
135         if (!empty($a->argv[1]) && in_array($a->argv[1], ['person', 'organisation', 'news', 'community'])) {
136                 $accounttype = $a->argv[1];
137         } else {
138                 $accounttype = '';
139         }
140
141         DI::page()['aside'] .= Widget::accounts('network', $accounttype);
142         DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
143         DI::page()['aside'] .= ForumManager::widget(local_user(), $cid);
144         DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false);
145         DI::page()['aside'] .= Widget::networks('network', $_GET['nets'] ?? '');
146         DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
147         DI::page()['aside'] .= Widget::fileAs('network', $_GET['file'] ?? '');
148 }
149
150 /**
151  * Return selected tab from query
152  *
153  * urls -> returns
154  *        '/network'                => $no_active = 'active'
155  *        '/network?order=activity' => $activity_active = 'active'
156  *        '/network?order=post'     => $postord_active = 'active'
157  *        '/network?conv=1',        => $conv_active = 'active'
158  *        '/network?star=1',        => $starred_active = 'active'
159  *
160  * @param App $a
161  * @return array ($no_active, $activity_active, $postord_active, $conv_active, $starred_active);
162  */
163 function network_query_get_sel_tab(App $a)
164 {
165         $no_active = '';
166         $starred_active = '';
167         $all_active = '';
168         $conv_active = '';
169         $postord_active = '';
170
171         if (!empty($_GET['star'])) {
172                 $starred_active = 'active';
173         }
174
175         if (!empty($_GET['conv'])) {
176                 $conv_active = 'active';
177         }
178
179         if (($starred_active == '') && ($conv_active == '')) {
180                 $no_active = 'active';
181         }
182
183         if ($no_active == 'active' && !empty($_GET['order'])) {
184                 switch($_GET['order']) {
185                         case 'post' :     $postord_active = 'active'; $no_active=''; break;
186                         case 'activity' : $all_active     = 'active'; $no_active=''; break;
187                 }
188         }
189
190         return [$no_active, $all_active, $postord_active, $conv_active, $starred_active];
191 }
192
193 function network_query_get_sel_group(App $a)
194 {
195         $group = false;
196
197         if ($a->argc >= 2 && is_numeric($a->argv[1])) {
198                 $group = $a->argv[1];
199         }
200
201         return $group;
202 }
203
204 /**
205  * Sets the pager data and returns SQL
206  *
207  * @param App     $a      The global App
208  * @param Pager   $pager
209  * @return string SQL with the appropriate LIMIT clause
210  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
211  */
212 function networkPager(App $a, Pager $pager)
213 {
214         if (DI::mode()->isMobile()) {
215                 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
216                         DI::config()->get('system', 'itemspage_network_mobile'));
217         } else {
218                 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
219                         DI::config()->get('system', 'itemspage_network'));
220         }
221
222         //  now that we have the user settings, see if the theme forces
223         //  a maximum item number which is lower then the user choice
224         if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
225                 $itemspage_network = $a->force_max_items;
226         }
227
228         $pager->setItemsPerPage($itemspage_network);
229 }
230
231 /**
232  * Sets items as seen
233  *
234  * @param array $condition The array with the SQL condition
235  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
236  */
237 function networkSetSeen($condition)
238 {
239         if (empty($condition)) {
240                 return;
241         }
242
243         $unseen = Item::exists($condition);
244
245         if ($unseen) {
246                 Item::update(['unseen' => false], $condition);
247         }
248 }
249
250 /**
251  * Create the conversation HTML
252  *
253  * @param App     $a      The global App
254  * @param array   $items  Items of the conversation
255  * @param Pager   $pager
256  * @param string  $mode   Display mode for the conversation
257  * @param integer $update Used for the automatic reloading
258  * @param string  $ordering
259  * @return string HTML of the conversation
260  * @throws ImagickException
261  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
262  */
263 function networkConversation(App $a, $items, Pager $pager, $mode, $update, $ordering = '')
264 {
265         // Set this so that the conversation function can find out contact info for our wall-wall items
266         $a->page_contact = $a->contact;
267
268         if (!is_array($items)) {
269                 Logger::info('Expecting items to be an array.', ['items' => $items]);
270                 $items = [];
271         }
272
273         $o = conversation($a, $items, $mode, $update, false, $ordering, local_user());
274
275         if (!$update) {
276                 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
277                         $o .= HTML::scrollLoader();
278                 } else {
279                         $o .= $pager->renderMinimal(count($items));
280                 }
281         }
282
283         return $o;
284 }
285
286 function network_content(App $a, $update = 0, $parent = 0)
287 {
288         if (!local_user()) {
289                 return Login::form();
290         }
291
292         /// @TODO Is this really necessary? $a is already available to hooks
293         $arr = ['query' => DI::args()->getQueryString()];
294         Hook::callAll('network_content_init', $arr);
295
296         if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
297                 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
298                 $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
299         } else {
300                 $o = '';
301         }
302
303         switch ($a->argv[1] ?? '') {
304                 case 'person':
305                         $account = User::ACCOUNT_TYPE_PERSON;
306                         break;
307                 case 'organisation':
308                         $account = User::ACCOUNT_TYPE_ORGANISATION;
309                         break;
310                 case 'news':
311                         $account = User::ACCOUNT_TYPE_NEWS;
312                         break;
313                 case 'community':
314                         $account = User::ACCOUNT_TYPE_COMMUNITY;
315                         break;
316                 default:
317                         $account = null;
318                 break;
319         }
320
321         if (!empty($_GET['file'])) {
322                 $o .= networkFlatView($a, $update, $account);
323         } else {
324                 $o .= networkThreadedView($a, $update, $parent, $account);
325         }
326
327         if (!$update && ($o === '')) {
328                 notice(DI::l10n()->t("No items found"));
329         }
330
331         return $o;
332 }
333
334 /**
335  * Get the network content in flat view
336  *
337  * @param App     $a      The global App
338  * @param integer $update Used for the automatic reloading
339  * @return string HTML of the network content in flat view
340  * @throws ImagickException
341  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
342  * @global Pager  $pager
343  */
344 function networkFlatView(App $a, $update, $account)
345 {
346         global $pager;
347         // Rawmode is used for fetching new content at the end of the page
348         $rawmode = (isset($_GET['mode']) && ($_GET['mode'] == 'raw'));
349
350         $o = '';
351
352         $file = $_GET['file'] ?? '';
353
354         if (!$update && !$rawmode) {
355                 $tabs = network_tabs($a);
356                 $o .= $tabs;
357
358                 Nav::setSelected('network');
359
360                 $x = [
361                         'is_owner' => true,
362                         'allow_location' => $a->user['allow_location'],
363                         'default_location' => $a->user['default-location'],
364                         'nickname' => $a->user['nickname'],
365                         'lockstate' => (is_array($a->user) &&
366                         (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
367                         strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
368                         'default_perms' => ACL::getDefaultUserPermissions($a->user),
369                         'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true),
370                         'bang' => '',
371                         'visitor' => 'block',
372                         'profile_uid' => local_user(),
373                         'content' => '',
374                 ];
375
376                 $o .= status_editor($a, $x);
377
378                 if (!DI::config()->get('theme', 'hide_eventlist')) {
379                         $o .= Profile::getBirthdays();
380                         $o .= Profile::getEventsReminderHTML();
381                 }
382         }
383
384         $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
385
386         networkPager($a, $pager);
387
388         if (strlen($file)) {
389                 $item_params = ['order' => ['uri-id' => true]];
390                 $term_condition = ['name' => $file, 'type' => Category::FILE, 'uid' => local_user()];
391                 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
392                 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
393
394                 $posts = [];
395                 while ($term = DBA::fetch($result)) {
396                         $posts[] = $term['uri-id'];
397                 }
398                 DBA::close($result);
399
400                 if (count($posts) == 0) {
401                         return '';
402                 }
403                 $item_condition = ['uid' => local_user(), 'uri-id' => $posts];
404         } else {
405                 $item_params = ['order' => ['id' => true]];
406                 $item_condition = ['uid' => local_user()];
407                 $item_params['limit'] = [$pager->getStart(), $pager->getItemsPerPage()];
408
409                 networkSetSeen(['unseen' => true, 'uid' => local_user()]);
410         }
411
412         if (!empty($account)) {
413                 $item_condition['contact-type'] = $account;
414         }
415
416         $result = Item::selectForUser(local_user(), [], $item_condition, $item_params);
417         $items = Item::inArray($result);
418         $o .= networkConversation($a, $items, $pager, 'network-new', $update);
419
420         return $o;
421 }
422
423 /**
424  * Get the network content in threaded view
425  *
426  * @param  App     $a      The global App
427  * @param  integer $update Used for the automatic reloading
428  * @param  integer $parent
429  * @return string HTML of the network content in flat view
430  * @throws ImagickException
431  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
432  * @global Pager   $pager
433  */
434 function networkThreadedView(App $a, $update, $parent, $account)
435 {
436         /// @TODO this will have to be converted to a static property of the converted Module\Network class
437         global $pager;
438
439         // Rawmode is used for fetching new content at the end of the page
440         $rawmode = (isset($_GET['mode']) AND ($_GET['mode'] == 'raw'));
441
442         $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
443         $last_commented = isset($_GET['last_commented']) ? DateTimeFormat::utc($_GET['last_commented']) : '';
444         $last_created = isset($_GET['last_created']) ? DateTimeFormat::utc($_GET['last_created']) : '';
445         $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0;
446
447         $datequery = $datequery2 = '';
448
449         $gid = 0;
450
451         $default_permissions = [];
452
453         if ($a->argc > 1) {
454                 for ($x = 1; $x < $a->argc; $x ++) {
455                         if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
456                                 if ($datequery) {
457                                         $datequery2 = Strings::escapeHtml($a->argv[$x]);
458                                 } else {
459                                         $datequery = Strings::escapeHtml($a->argv[$x]);
460                                         $_GET['order'] = 'post';
461                                 }
462                         } elseif (intval($a->argv[$x])) {
463                                 $gid = intval($a->argv[$x]);
464                                 $default_permissions['allow_gid'] = [$gid];
465                         }
466                 }
467         }
468
469         $o = '';
470
471         $cid   = intval($_GET['contactid'] ?? 0);
472         $star  = intval($_GET['star']      ?? 0);
473         $conv  = intval($_GET['conv']      ?? 0);
474         $order = Strings::escapeTags(($_GET['order'] ?? '') ?: 'activity');
475         $nets  =        $_GET['nets']      ?? '';
476
477         $allowedCids = [];
478         if ($cid) {
479                 $allowedCids[] = (int) $cid;
480         } elseif ($nets) {
481                 $condition = [
482                         'uid'     => local_user(),
483                         'network' => $nets,
484                         'self'    => false,
485                         'blocked' => false,
486                         'pending' => false,
487                         'archive' => false,
488                         'rel'     => [Contact::SHARING, Contact::FRIEND],
489                 ];
490                 $contactStmt = DBA::select('contact', ['id'], $condition);
491                 while ($contact = DBA::fetch($contactStmt)) {
492                         $allowedCids[] = (int) $contact['id'];
493                 }
494                 DBA::close($contactStmt);
495         }
496
497         if (count($allowedCids)) {
498                 $default_permissions['allow_cid'] = $allowedCids;
499         }
500
501         if (!$update && !$rawmode) {
502                 $tabs = network_tabs($a);
503                 $o .= $tabs;
504
505                 Nav::setSelected('network');
506
507                 $content = '';
508
509                 if ($cid) {
510                         // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
511                         $condition = ["`id` = ? AND (`forum` OR `prv`)", $cid];
512                         $contact = DBA::selectFirst('contact', ['addr'], $condition);
513                         if (!empty($contact['addr'])) {
514                                 $content = '!' . $contact['addr'];
515                         }
516                 }
517
518                 $x = [
519                         'is_owner' => true,
520                         'allow_location' => $a->user['allow_location'],
521                         'default_location' => $a->user['default-location'],
522                         'nickname' => $a->user['nickname'],
523                         'lockstate' => ($gid || $cid || $nets || (is_array($a->user) &&
524                         (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
525                         strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
526                         'default_perms' => ACL::getDefaultUserPermissions($a->user),
527                         'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true, $default_permissions),
528                         'bang' => (($gid || $cid || $nets) ? '!' : ''),
529                         'visitor' => 'block',
530                         'profile_uid' => local_user(),
531                         'content' => $content,
532                 ];
533
534                 $o .= status_editor($a, $x);
535         }
536
537         $conditionFields = ['uid' => local_user()];
538         $conditionStrings = [];
539
540         if (!empty($account)) {
541                 $conditionFields['contact-type'] = $account;
542         }
543
544         if ($star) {
545                 $conditionFields['starred'] = true;
546         }
547         if ($conv) {
548                 $conditionFields['mention'] = true;
549         }
550         if ($nets) {
551                 $conditionFields['network'] = $nets;
552         }
553
554         if ($datequery) {
555                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
556         }
557         if ($datequery2) {
558                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
559         }
560
561         if ($gid) {
562                 $group = DBA::selectFirst('group', ['name'], ['id' => $gid, 'uid' => local_user()]);
563                 if (!DBA::isResult($group)) {
564                         if ($update) {
565                                 exit();
566                         }
567                         notice(DI::l10n()->t('No such group'));
568                         DI::baseUrl()->redirect('network/0');
569                         // NOTREACHED
570                 }
571
572                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]);
573
574                 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
575                         '$title' => DI::l10n()->t('Group: %s', $group['name'])
576                 ]) . $o;
577         } elseif ($cid) {
578                 $contact = Contact::getById($cid);
579                 if (DBA::isResult($contact)) {
580                         $conditionFields['contact-id'] = $cid;
581
582                         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
583                                 'contacts' => [ModuleContact::getContactTemplateVars($contact)],
584                                 'id' => 'network',
585                         ]) . $o;
586                 } else {
587                         notice(DI::l10n()->t('Invalid contact.'));
588                         DI::baseUrl()->redirect('network');
589                         // NOTREACHED
590                 }
591         } elseif (!$update && !DI::config()->get('theme', 'hide_eventlist')) {
592                 $o .= Profile::getBirthdays();
593                 $o .= Profile::getEventsReminderHTML();
594         }
595
596         // Normal conversation view
597         if ($order === 'post') {
598                 $ordering = '`received`';
599                 $order_mode = 'received';
600         } else {
601                 $ordering = '`commented`';
602                 $order_mode = 'commented';
603         }
604
605         $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
606
607         networkPager($a, $pager);
608
609         if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
610                 $pager->setPage(1);
611         }
612
613         // Currently only the order modes "received" and "commented" are in use
614         switch ($order_mode) {
615                 case 'received':
616                         if ($last_received != '') {
617                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $last_received]);
618                         }
619                         break;
620                 case 'commented':
621                         if ($last_commented != '') {
622                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $last_commented]);
623                         }
624                         break;
625                 case 'created':
626                         if ($last_created != '') {
627                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $last_created]);
628                         }
629                         break;
630                 case 'uriid':
631                         if ($last_uriid > 0) {
632                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $last_uriid]);
633                         }
634                         break;
635         }
636
637         // Fetch a page full of parent items for this page
638         if ($update) {
639                 if (!empty($parent)) {
640                         // Load only a single thread
641                         $conditionFields['parent'] = $parent;
642                 } elseif ($order === 'post') {
643                         // Only load new toplevel posts
644                         $conditionFields['unseen'] = true;
645                         $conditionFields['gravity'] = GRAVITY_PARENT;
646                 } else {
647                         // Load all unseen items
648                         $conditionFields['unseen'] = true;
649                 }
650
651                 $params = ['order' => [$order_mode => true], 'limit' => 100];
652                 $table = 'network-item-view';
653         } else {
654                 $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
655                 $table = 'network-thread-view';
656         }
657         $r = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
658
659         return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r);
660 }
661
662 function network_display_post($a, $pager, $mark_all, $update, $ordering, $items)
663 {
664         $parents_str = '';
665
666         if (DBA::isResult($items)) {
667                 $parents_arr = [];
668
669                 foreach ($items as $item) {
670                         if (!in_array($item['parent'], $parents_arr) && ($item['parent'] > 0)) {
671                                 $parents_arr[] = $item['parent'];
672                         }
673                 }
674                 $parents_str = implode(', ', $parents_arr);
675         }
676
677         $pager->setQueryString(DI::args()->getQueryString());
678
679         // We aren't going to try and figure out at the item, group, and page
680         // level which items you've seen and which you haven't. If you're looking
681         // at the top level network page just mark everything seen.
682
683         if ($mark_all) {
684                 $condition = ['unseen' => true, 'uid' => local_user()];
685                 networkSetSeen($condition);
686         } elseif ($parents_str) {
687                 $condition = ["`uid` = ? AND `unseen` AND `parent` IN (" . DBA::escape($parents_str) . ")", local_user()];
688                 networkSetSeen($condition);
689         }
690
691         return networkConversation($a, $items, $pager, 'network', $update, $ordering);
692 }
693
694 /**
695  * Get the network tabs menu
696  *
697  * @param App $a The global App
698  * @return string Html of the networktab
699  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
700  */
701 function network_tabs(App $a)
702 {
703         // item filter tabs
704         /// @TODO fix this logic, reduce duplication
705         /// DI::page()['content'] .= '<div class="tabs-wrapper">';
706         list($no_active, $all_active, $post_active, $conv_active, $starred_active) = network_query_get_sel_tab($a);
707
708         // if no tabs are selected, defaults to activitys
709         if ($no_active == 'active') {
710                 $all_active = 'active';
711         }
712
713         $cmd = DI::args()->getCommand();
714
715         $def_param = [];
716         if (!empty($_GET['contactid'])) {
717                 $def_param['contactid'] = $_GET['contactid'];
718         }
719
720         // tabs
721         $tabs = [
722                 [
723                         'label' => DI::l10n()->t('Latest Activity'),
724                         'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'activity'])),
725                         'sel'   => $all_active,
726                         'title' => DI::l10n()->t('Sort by latest activity'),
727                         'id'    => 'activity-order-tab',
728                         'accesskey' => 'e',
729                 ],
730                 [
731                         'label' => DI::l10n()->t('Latest Posts'),
732                         'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'post'])),
733                         'sel'   => $post_active,
734                         'title' => DI::l10n()->t('Sort by post received date'),
735                         'id'    => 'post-order-tab',
736                         'accesskey' => 't',
737                 ],
738         ];
739
740         $tabs[] = [
741                 'label' => DI::l10n()->t('Personal'),
742                 'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['conv' => true])),
743                 'sel'   => $conv_active,
744                 'title' => DI::l10n()->t('Posts that mention or involve you'),
745                 'id'    => 'personal-tab',
746                 'accesskey' => 'r',
747         ];
748
749         $tabs[] = [
750                 'label' => DI::l10n()->t('Starred'),
751                 'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['star' => true])),
752                 'sel'   => $starred_active,
753                 'title' => DI::l10n()->t('Favourite Posts'),
754                 'id'    => 'starred-posts-tab',
755                 'accesskey' => 'm',
756         ];
757
758         // save selected tab, but only if not in file mode
759         if (empty($_GET['file'])) {
760                 DI::pConfig()->set(local_user(), 'network.view', 'tab.selected', [
761                         $all_active, $post_active, $conv_active, $starred_active
762                 ]);
763         }
764
765         $arr = ['tabs' => $tabs];
766         Hook::callAll('network_tabs', $arr);
767
768         $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
769
770         return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
771
772         // --- end item filter tabs
773 }