-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
90 lines (79 loc) · 2.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
Kirby::plugin('zvaehn/recent-changes', [
'sections' => [
'recentChanges' => [
'props' => [
'headline' => function ($headline = 'Recent Changes') {
return $headline;
},
'image' => function ($image = false) {
return $image;
},
'dateFormat' => function ($dateFormat = 'd.m.Y') {
return $dateFormat;
},
'sortBy' => function ($sortBy = 'modified desc') {
return explode(" ", $sortBy);
},
'filterBy' => function ($filterBy = false) {
if($filterBy) {
return explode(" ", $filterBy);
}
return false;
},
'limit' => function ($limit = 10) {
return $limit;
},
],
'methods' => [
'getIndex' => function() {
$index = site()->index();
if($this->filterBy()) {
$index = $index->filterBy(...$this->filterBy());
}
$index = $index->sortBy(...$this->sortBy());
$index = $index->limit($this->limit());
return $index;
},
'getThumbUrl' => function($page) {
$image = false;
// do we want to have a custom image?
if($this->image()) {
if($field = $page->{$this->image()}()) {
$image = $field->toFile();
}
}
// if the custom image is invalid or not found
if(!$image) {
$image = $page->image();
}
// Generate a thumb or return an empty string if the page has no image
return $image ? $image->thumb(array('width' => 48))->url() : '';
},
],
'computed' => [
'items' => function() {
$items = array();
foreach ($this->getIndex() as $page) {
$item = array(
'image' => array(
'url' => $this->getThumbUrl($page),
'back' => 'pattern',
),
'text' => $page->title()->value(),
'info' => date($this->dateFormat(), $page->modified()),
// 'flag' => array(
// 'icon' => 'edit',
// 'click' => 'editClickHandler', // https://getkirby.com/docs/reference/plugins/ui/list-item#events
// ),
'link' => $page->panelUrl(),
'target' => '_blank'
);
array_push($items, $item);
}
return $items;
}
],
]
]
]);