]> git.mxchange.org Git - friendica.git/blobdiff - mod/network.php
Revert "Use last entry for Content-Type"
[friendica.git] / mod / network.php
index 6a7b8db5f7b4afd176ecf5a4a1da7a2f92a2dcd6..ef6b0b324e2aa123b73a6a90667af8cd788e927f 100644 (file)
@@ -36,6 +36,7 @@ use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Post\Category;
 use Friendica\Model\Profile;
+use Friendica\Model\User;
 use Friendica\Module\Contact as ModuleContact;
 use Friendica\Module\Security\Login;
 use Friendica\Util\DateTimeFormat;
@@ -48,8 +49,6 @@ function network_init(App $a)
                return;
        }
 
-       Hook::add('head', __FILE__, 'network_infinite_scroll_head');
-
        $is_a_date_query = false;
 
        $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
@@ -133,6 +132,13 @@ function network_init(App $a)
                DI::page()['aside'] = '';
        }
 
+       if (!empty(User::getAccountTypeByString($a->argv[1] ?? ''))) {
+               $accounttype = $a->argv[1];
+       } else {
+               $accounttype = '';
+       }
+
+       DI::page()['aside'] .= Widget::accounts('network', $accounttype);
        DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
        DI::page()['aside'] .= ForumManager::widget(local_user(), $cid);
        DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false);
@@ -287,10 +293,19 @@ function network_content(App $a, $update = 0, $parent = 0)
        $arr = ['query' => DI::args()->getQueryString()];
        Hook::callAll('network_content_init', $arr);
 
+       if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
+               $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
+               $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
+       } else {
+               $o = '';
+       }
+
+       $account = User::getAccountTypeByString($a->argv[1] ?? '');
+
        if (!empty($_GET['file'])) {
-               $o = networkFlatView($a, $update);
+               $o .= networkFlatView($a, $update, $account);
        } else {
-               $o = networkThreadedView($a, $update, $parent);
+               $o .= networkThreadedView($a, $update, $parent, $account);
        }
 
        if (!$update && ($o === '')) {
@@ -310,7 +325,7 @@ function network_content(App $a, $update = 0, $parent = 0)
  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  * @global Pager  $pager
  */
-function networkFlatView(App $a, $update = 0)
+function networkFlatView(App $a, $update, $account)
 {
        global $pager;
        // Rawmode is used for fetching new content at the end of the page
@@ -378,6 +393,10 @@ function networkFlatView(App $a, $update = 0)
                networkSetSeen(['unseen' => true, 'uid' => local_user()]);
        }
 
+       if (!empty($account)) {
+               $item_condition['contact-type'] = $account;
+       }
+
        $result = Item::selectForUser(local_user(), [], $item_condition, $item_params);
        $items = Item::inArray($result);
        $o .= networkConversation($a, $items, $pager, 'network-new', $update);
@@ -396,7 +415,7 @@ function networkFlatView(App $a, $update = 0)
  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  * @global Pager   $pager
  */
-function networkThreadedView(App $a, $update, $parent)
+function networkThreadedView(App $a, $update, $parent, $account)
 {
        /// @TODO this will have to be converted to a static property of the converted Module\Network class
        global $pager;
@@ -499,24 +518,28 @@ function networkThreadedView(App $a, $update, $parent)
                $o .= status_editor($a, $x);
        }
 
-       $condition1 = ['uid' => local_user()];
-       $condition2 = [];
+       $conditionFields = ['uid' => local_user()];
+       $conditionStrings = [];
+
+       if (!empty($account)) {
+               $conditionFields['contact-type'] = $account;
+       }
 
        if ($star) {
-               $condition1['starred'] = true;
+               $conditionFields['starred'] = true;
        }
        if ($conv) {
-               $condition1['mention'] = true;
+               $conditionFields['mention'] = true;
        }
        if ($nets) {
-               $condition1['network'] = $nets;
+               $conditionFields['network'] = $nets;
        }
 
        if ($datequery) {
-               $condition2 = DBA::mergeConditions($condition2, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
+               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
        }
        if ($datequery2) {
-               $condition2 = DBA::mergeConditions($condition2, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
+               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
        }
 
        if ($gid) {
@@ -530,7 +553,7 @@ function networkThreadedView(App $a, $update, $parent)
                        // NOTREACHED
                }
 
-               $condition2 = DBA::mergeConditions($condition2, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]);
+               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]);
 
                $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
                        '$title' => DI::l10n()->t('Group: %s', $group['name'])
@@ -538,7 +561,7 @@ function networkThreadedView(App $a, $update, $parent)
        } elseif ($cid) {
                $contact = Contact::getById($cid);
                if (DBA::isResult($contact)) {
-                       $condition1['contact-id'] = $cid;
+                       $conditionFields['contact-id'] = $cid;
 
                        $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
                                'contacts' => [ModuleContact::getContactTemplateVars($contact)],
@@ -575,22 +598,22 @@ function networkThreadedView(App $a, $update, $parent)
        switch ($order_mode) {
                case 'received':
                        if ($last_received != '') {
-                               $condition2 = DBA::mergeConditions($condition2, ["`received` < ?", $last_received]);
+                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $last_received]);
                        }
                        break;
                case 'commented':
                        if ($last_commented != '') {
-                               $condition2 = DBA::mergeConditions($condition2, ["`commented` < ?", $last_commented]);
+                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $last_commented]);
                        }
                        break;
                case 'created':
                        if ($last_created != '') {
-                               $condition2 = DBA::mergeConditions($condition2, ["`created` < ?", $last_created]);
+                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $last_created]);
                        }
                        break;
                case 'uriid':
                        if ($last_uriid > 0) {
-                               $condition2 = DBA::mergeConditions($condition2, ["`uri-id` < ?", $last_uriid]);
+                               $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $last_uriid]);
                        }
                        break;
        }
@@ -599,14 +622,14 @@ function networkThreadedView(App $a, $update, $parent)
        if ($update) {
                if (!empty($parent)) {
                        // Load only a single thread
-                       $condition1['id'] = $parent;
+                       $conditionFields['parent'] = $parent;
                } elseif ($order === 'post') {
                        // Only load new toplevel posts
-                       $condition1['unseen'] = true;
-                       $condition1['gravity'] = GRAVITY_PARENT;
+                       $conditionFields['unseen'] = true;
+                       $conditionFields['gravity'] = GRAVITY_PARENT;
                } else {
                        // Load all unseen items
-                       $condition1['unseen'] = true;
+                       $conditionFields['unseen'] = true;
                }
 
                $params = ['order' => [$order_mode => true], 'limit' => 100];
@@ -615,7 +638,7 @@ function networkThreadedView(App $a, $update, $parent)
                $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
                $table = 'network-thread-view';
        }
-       $r = DBA::selectToArray($table, [], DBA::mergeConditions($condition1, $condition2), $params);
+       $r = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
 
        return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r);
 }
@@ -635,9 +658,7 @@ function network_display_post($a, $pager, $mark_all, $update, $ordering, $items)
                $parents_str = implode(', ', $parents_arr);
        }
 
-       $query_string = DI::args()->getQueryString();
-
-       $pager->setQueryString($query_string);
+       $pager->setQueryString(DI::args()->getQueryString());
 
        // We aren't going to try and figure out at the item, group, and page
        // level which items you've seen and which you haven't. If you're looking
@@ -734,34 +755,3 @@ function network_tabs(App $a)
 
        // --- end item filter tabs
 }
-
-/**
- * Network hook into the HTML head to enable infinite scroll.
- *
- * Since the HTML head is built after the module content has been generated, we need to retrieve the base query string
- * of the page to make the correct asynchronous call. This is obtained through the Pager that was instantiated in
- * networkThreadedView or networkFlatView.
- *
- * @param App     $a
- * @param  string $htmlhead The head tag HTML string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @global Pager  $pager
- */
-function network_infinite_scroll_head(App $a, &$htmlhead)
-{
-       /// @TODO this will have to be converted to a static property of the converted Module\Network class
-       /**
-        * @var $pager Pager
-        */
-       global $pager;
-
-       if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')
-               && ($_GET['mode'] ?? '') != 'minimal'
-       ) {
-               $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
-               $htmlhead .= Renderer::replaceMacros($tpl, [
-                       '$pageno'     => $pager->getPage(),
-                       '$reload_uri' => $pager->getBaseQueryString()
-               ]);
-       }
-}