aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Activity.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/Activity.php')
-rw-r--r--Zotlabs/Lib/Activity.php60
1 files changed, 51 insertions, 9 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 216dfab1a..0f9160bf7 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -2,6 +2,7 @@
namespace Zotlabs\Lib;
+use App;
use Zotlabs\Access\PermissionLimits;
use Zotlabs\Access\PermissionRoles;
use Zotlabs\Access\Permissions;
@@ -246,28 +247,69 @@ class Activity {
}
-
- static function encode_item_collection($items, $id, $type, $extra = null) {
+ static function paged_collection_init($total, $id, $type = 'OrderedCollection') {
$ret = [
'id' => z_root() . '/' . $id,
'type' => $type,
- 'totalItems' => count($items),
+ 'totalItems' => $total,
];
- if ($extra)
- $ret = array_merge($ret, $extra);
+
+ $numpages = $total / App::$pager['itemspage'];
+ $lastpage = (($numpages > intval($numpages)) ? intval($numpages) + 1 : $numpages);
+
+ $ret['first'] = z_root() . '/' . App::$query_string . '?page=1';
+ $ret['last'] = z_root() . '/' . App::$query_string . '?page=' . $lastpage;
+
+ return $ret;
+
+ }
+
+ static function encode_item_collection($items, $id, $type, $total = 0) {
+
+ if ($total > 100) {
+ $ret = [
+ 'id' => z_root() . '/' . $id,
+ 'type' => $type . 'Page',
+ ];
+
+ $numpages = $total / App::$pager['itemspage'];
+ $lastpage = (($numpages > intval($numpages)) ? intval($numpages) + 1 : $numpages);
+
+ $stripped = preg_replace('/([&|\?]page=[0-9]*)/', '', $id);
+ $stripped = rtrim($stripped, '/');
+
+ $ret['partOf'] = z_root() . '/' . $stripped;
+
+ if (App::$pager['page'] < $lastpage) {
+ $ret['next'] = z_root() . '/' . $stripped . '?page=' . (intval(App::$pager['page']) + 1);
+ }
+ if (App::$pager['page'] > 1) {
+ $ret['prev'] = z_root() . '/' . $stripped . '?page=' . (intval(App::$pager['page']) - 1);
+ }
+ }
+ else {
+ $ret = [
+ 'id' => z_root() . '/' . $id,
+ 'type' => $type,
+ 'totalItems' => $total,
+ ];
+ }
if ($items) {
$x = [];
foreach ($items as $i) {
- $t = self::encode_activity($i);
- if ($t)
+ $t = ((get_iconfig($i['id'], 'activitypub', 'rawmsg')) ? get_iconfig($i['id'], 'activitypub', 'rawmsg') : self::encode_activity($i));
+ if ($t) {
$x[] = $t;
+ }
}
- if ($type === 'OrderedCollection')
+ if ($type === 'OrderedCollection') {
$ret['orderedItems'] = $x;
- else
+ }
+ else {
$ret['items'] = $x;
+ }
}
return $ret;