]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Move $pager and $page_offset out of App
[friendica.git] / mod / photos.php
index ef6428d7ab563309dbfcb835553ff116cd1e245f..b8f00c358aae3fce05efd10833a853571e439c97 100644 (file)
@@ -6,6 +6,7 @@
 use Friendica\App;
 use Friendica\Content\Feature;
 use Friendica\Content\Nav;
+use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
 use Friendica\Core\Addon;
@@ -25,8 +26,8 @@ use Friendica\Object\Image;
 use Friendica\Protocol\DFRN;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
-use Friendica\Util\Temporal;
 use Friendica\Util\Security;
+use Friendica\Util\Temporal;
 
 require_once 'include/items.php';
 
@@ -1135,16 +1136,18 @@ function photos_content(App $a)
        if ($datatype === 'album') {
                $album = hex2bin($datum);
 
+               $total = 0;
                $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
                        AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
                        intval($owner_uid),
                        DBA::escape($album)
                );
                if (DBA::isResult($r)) {
-                       $a->setPagerTotal(count($r));
-                       $a->setPagerItemsPage(20);
+                       $total = count($r);
                }
 
+               $pager = new Pager($a->query_string, $total, 20);
+
                /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
                $order_field = defaults($_GET, 'order', '');
                if ($order_field === 'posted') {
@@ -1160,8 +1163,8 @@ function photos_content(App $a)
                        AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
                        intval($owner_uid),
                        DBA::escape($album),
-                       intval($a->pager['start']),
-                       intval($a->pager['itemspage'])
+                       $pager->getStart(),
+                       $pager->getItemsPerPage()
                );
 
                // edit album name
@@ -1230,7 +1233,7 @@ function photos_content(App $a)
                                '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
                                '$order' => $order,
                                '$edit' => $edit,
-                               '$paginate' => paginate($a),
+                               '$paginate' => $pager->renderFull(),
                        ]);
 
                return $o;
@@ -1391,9 +1394,9 @@ function photos_content(App $a)
                        $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
 
                        $condition = ["`parent` = ? AND `parent` != `id`",  $link_item['parent']];
-                       $a->setPagerTotal(DBA::count('item', $condition));
+                       $pager = new Pager($a->query_string, DBA::count('item', $condition));
 
-                       $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
+                       $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
                        $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
                        $items = Item::inArray($result);
 
@@ -1608,7 +1611,7 @@ function photos_content(App $a)
                        }
                        $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
 
-                       $paginate = paginate($a);
+                       $paginate = $pager->renderFull();
                }
 
                $photo_tpl = get_markup_template('photo_view.tpl');
@@ -1653,8 +1656,7 @@ function photos_content(App $a)
        );
 
        if (DBA::isResult($r)) {
-               $a->setPagerTotal(count($r));
-               $a->setPagerItemsPage(20);
+               $pager = new Pager($a->query_string, count($r), 20);
        }
 
        $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
@@ -1665,8 +1667,8 @@ function photos_content(App $a)
                intval($a->data['user']['uid']),
                DBA::escape('Contact Photos'),
                DBA::escape(L10n::t('Contact Photos')),
-               intval($a->pager['start']),
-               intval($a->pager['itemspage'])
+               $pager->getStart(),
+               $pager->getItemsPerPage()
        );
 
        $photos = [];
@@ -1709,7 +1711,7 @@ function photos_content(App $a)
                '$can_post' => $can_post,
                '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
                '$photos' => $photos,
-               '$paginate' => paginate($a),
+               '$paginate' => $pager->renderFull(),
        ]);
 
        return $o;