Skip to content

Commit 0c0aad0

Browse files
committed
First complete version of an integrated panel area, adds new panel.limit config option to set the number of items to display, improved cache handling, other misc improvements.
1 parent 104dfc0 commit 0c0aad0

File tree

12 files changed

+209
-106
lines changed

12 files changed

+209
-106
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ If you want to explore the data returned via the plugin to the snippet or that y
5656
| dateformat | `M d, Y` | No | Adjust date format per PHP datetime formats |
5757
| excludereplies | `true` | No | Exclude replies from results? |
5858
| onlymedia | `false` | No | Only show posts with media attachments? |
59+
| panel.limit | `12` | No | Number of results to display in the Panel Area |
5960

6061
Date formatting follows the [available format options from PHP](https://php.net/manual/en/function.date.php).
6162

@@ -71,6 +72,9 @@ Example Config:
7172
'cache' => true,
7273
'cachettl' => 300 // 5 minutes
7374
'onlymedia' => true,
75+
'panel' => [
76+
'limit' => 6
77+
]
7478
]
7579
]
7680
```

src/Helpers/CacheKey.php renamed to classes/CacheKey.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Scottboms\Mastodon\Helpers;
3+
namespace Scottboms\Mastodon;
44

55
use Exception;
66

@@ -32,4 +32,4 @@ public static function forAccountInfo(string $username, string $server): string
3232

3333
return "account-info-{$username}@{$server}";
3434
}
35-
}
35+
}

classes/Feed.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Kirby\Toolkit\Collection;
1212
use Kirby\Toolkit\Obj;
1313
use Kirby\Toolkit\Str;
14-
use Scottboms\Mastodon\Helpers\CacheKey;
14+
use Scottboms\Mastodon\CacheKey;
1515

1616
use function option;
1717

@@ -87,7 +87,7 @@ protected function getUserId(): ?string
8787
}
8888

8989
/*
90-
* factory constructor method
90+
* factory constructor
9191
* @var Array
9292
*/
9393
public static function build(array $options = []): self
@@ -128,11 +128,14 @@ public function getAccountInfo(): array
128128
'id' => $json['id'] ?? null,
129129
'username' => $json['username'] ?? null,
130130
'display_name' => $json['display_name'] ?? null,
131+
'server' => $this->options['server'] ?? null,
131132
'avatar_static' => $json['avatar_static'] ?? null,
132-
'uri' => $json['uri'] ?? null,
133+
'url' => $json['url'] ?? null,
133134
'note' => $json['note'] ?? null,
134135
'followers_count' => $json['followers_count'] ?? null,
135136
'following_count' => $json['following_count'] ?? null,
137+
'statuses_count' => $json['statuses_count'] ?? null,
138+
'last_status_at' => $json['last_status_at'] ?? null,
136139
];
137140

138141
// cache the result
@@ -208,17 +211,11 @@ public static function getFeed($feedUrl, array $options = []): array|string
208211
/*
209212
* @var Bool
210213
*/
211-
public static function clearFeedCache(array $options = []): bool
214+
public static function clearCache(array $options = []): bool
212215
{
213-
$instance = static::build($options);
214216
$cache = kirby()->cache('scottboms.mastodon');
215-
216-
$server = $instance->options['server'];
217-
$userId = $instance->options['userid'];
218-
219-
$cacheKey = CacheKey::forFeed($server, $userId);
220-
221-
return $cache->remove($cacheKey);
217+
// flush the entire cache
218+
return (bool) $cache->flush();
222219
}
223220

224221
/*

index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
load([
1515
'Scottboms\Mastodon\Feed' => __DIR__ . '/classes/Feed.php',
16-
'Scottboms\Mastodon\Helpers\CacheKey' => __DIR__ . '/src/Helpers/CacheKey.php',
16+
'Scottboms\Mastodon\CacheKey' => __DIR__ . '/classes/CacheKey.php',
1717
]);
1818

1919
use Scottboms\Mastodon\Feed;
@@ -43,21 +43,24 @@
4343
'limit' => 20,
4444
'dateformat' => 'M d, Y',
4545
'excludereplies' => true,
46-
'onlymedia' => false
46+
'onlymedia' => false,
47+
'panel' => [
48+
'limit' => 12
49+
],
4750
],
4851
'api' => [
4952
'routes' => require __DIR__ . '/lib/routes.php'
5053
],
5154
'autoload' => [
5255
'psr-4' => [
53-
'Scottboms\\Mastodon\\' => __DIR__ . '/src',
56+
'Scottboms\\Mastodon\\' => __DIR__ . '/classes',
5457
]
5558
],
5659
'areas' => [
5760
'mastodon-feed' => function ($kirby) {
5861
return [
5962
'label' => 'Mastodon Feed',
60-
'icon' => 'rss',
63+
'icon' => 'mastodon',
6164
'breadcrumbLabel' => function() {
6265
return 'Mastodon Feed';
6366
},
@@ -78,16 +81,15 @@
7881
throw new Exception('Feed did not return a valid collection.');
7982
}
8083

81-
// debug:
82-
//print_r($items->toArray());
83-
//die();
84+
$panelLimit = (int) option('scottboms.mastodon-feed.panel.limit', 12);
85+
$panelLimit = max(1, $panelLimit);
8486

8587
return [
8688
'component' => 'k-mastodon-feed-view',
8789
'props' => [
8890
'status' => 'Mastodon feed loaded',
8991
'account' => $account,
90-
'items' => $items->limit(5)->values() // limit to 5 items
92+
'items' => $items->limit($panelLimit)->values(),
9193
]
9294
];
9395

@@ -102,7 +104,7 @@
102104
];
103105
}
104106

105-
// you can return data from your Feed class here
107+
// return data from feed class
106108
return [
107109
'component' => 'k-mastodon-feed-view',
108110
'title' => 'Mastodon Feed',

0 commit comments

Comments
 (0)