-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
58 lines (57 loc) · 2.03 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
<?php
Kirby::plugin('texnixe/pagemethods', [
'pageMethods' => [
'getIndex' => function($collection) {
if($collection->has($this)) {
$index = $collection->indexOf($this);
return $index;
}
},
'getRootParent' => function() {
if($this->depth() == 1 && !$this->isHomePage()) {
return $this;
}
return $this->parents()->last();
},
'hasParents' => function(): bool {
return $this->parents()->count();
},
'maxDepth' => function() {
$depth = [];
if($this->index()->count() > 1) {
foreach($this->index() as $p) {
$depth[] = $p->depth();
}
return max($depth);
}
return null;
},
'canonicalUrl' => function() {
return $this->url() . r(params() || $this->isHomePage(), '/') . kirby()->request()->params();
},
'getPrev' => function($siblings, $sort = [], $status = false) {
if($sort) $siblings = call(array($siblings, 'sortBy'), $sort);
$index = $siblings->indexOf($this);
if($index === false or $index === 0) return null;
if($status) {
$siblings = $siblings->limit($index);
$siblings = $siblings->{$status}();
return $siblings->last();
} else {
return $siblings->nth($index - 1);
}
},
'getNext' => function($siblings, $sort = [], $status = false) {
if($sort) $siblings = call([$siblings, 'sortBy'], $sort);
$index = $siblings->indexOf($this);
if($index === false) return null;
if($status) {
$siblings = $siblings->offset($index+1);
$siblings = $siblings->{$status}();
return $siblings->first();
} else {
return $siblings->nth($index + 1);
}
},
]
]);