-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.php
executable file
·155 lines (132 loc) · 6.52 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace daandelange\SimpleStats;
use Kirby\Cms\App;
@include_once __DIR__ . '/vendor/autoload.php';
//$stats = Stats()::list();
App::plugin('daandelange/simplestats', [
'options' => require 'src/config/options.php',
'api' => require 'src/config/api.php',
'hooks' => require 'src/config/hooks.php',
'translations' => require 'src/config/translations.php',
'pageMethods' => require 'src/config/pagemethods.php',
'routes' => require 'src/config/routes.php',
'userMethods' => require 'src/config/usermethods.php',
// New K3.6 method
'areas' => [
'simplestats' => function ($kirby) {
if(!$kirby->user() || !$kirby->user()->hasSimpleStatsPanelAccess()) return [];
return [
// label for the menu and the breadcrumb
'label' => 'Simple Stats',
// icon for the menu and breadcrumb
'icon' => 'chart',
// optional replacement for the breadcrumb label
'breadcrumbLabel' => function () {
return option('daandelange.simplestats.panel.breadcrumbLabel', 'SimpleStats - All your data are belong to us !');
},
// show / hide from the menu
'menu' => true,
'link' => 'simplestats',
// views
'views' => [
[
// the Panel patterns must not start with 'panel/',
// the `panel` slug is automatically prepended.
'pattern' => 'simplestats',
'action' => function () use ($kirby) {
// view routes return a simple array,
// which will be injected into our Vue app;
// the array can control the loaded Vue component,
// props for the component and settings for the current view
// (like breadcrumb, title, active search type etc.)
$tabs = [];
foreach([
'pagevisits' => ['label'=>'Page visits', 'icon'=>'layers'],
'visitordevices' => ['label'=>'Visitor Devices', 'icon'=>'users' ],
'referers' => ['label'=>'Referers', 'icon'=>'chart' ],
'information' => ['label'=>'Information', 'icon'=>'map' ],
] as $key=>$tabData){
$tabs[$key] = [
'name' => $key,
'label' => t('simplestats.tabs.'.$key, $tabData['label']),
'icon' => $tabData['icon'],
'columns' => [],// Needed for the panel not to crash
// 'link' => 'simplestats?tab='.$key,
//'link' => 'javascript:alert("OK")',
];
};
$timeSpan = Stats::getDbTimeSpan();
$timeFrames = Stats::fillPeriod($timeSpan['start'], $timeSpan['end'], 'Y-m-d');
// $timeFrames = [];
// $tfu = getTimeFrameUtility();
// for($period=min($timeSpan[0]); $period <= getPeriodFromTime(); $period=incrementPeriod($period) ){
// $timeFrames[] =
// }
return [
// the Vue component can be defined in the
// `index.js` of your plugin
'component' => 'k-simplestats-view',
// the document title for the current view
'title' => 'Simple Stats',
// the breadcrumb
'breadcrumb' => function () use($kirby, $tabs) {
$tabID = $kirby->request()->get('tab') ?? 'pagevisits';
return [[
'label' => array_keys($tabs, $tabID) ? $tabs[$tabID]['label'] : t('simplestats.tabs.pagevisits'),
//'link' => '/simplestats?tab='.$tabID,
]];
},
// props will be directly available in the
// Vue component. It's a super convenient way
// to send backend data to the Panel
'props' => [
'initialtab' => $kirby->request()->get('tab') ?? $tabs['pagevisits']['name'],
'tabs' => array_values($tabs),
'globaltimespan' => [
date('Y-m-d', getTimeFromPeriod($timeSpan['start'])),
date('Y-m-d', getTimeFromPeriod($timeSpan['end'])),
],
'timeframes' => $timeFrames,
],
// we can preset the search type with the
// search attribute
//'search' => 'pages'
];
}
]
]
];
},
],
// One page stats detail section
'sections' => [
'pagestats' => [
// Data that comes from blueprint
'props' => [
'headline' => function (string $headline = 'Page Stats') {
return $headline;
},
'showFullInfo' => function (bool $showFullInfo = false) {
return $showFullInfo;
},
'showTimeline' => function (bool $showTimeline = true) {
return $showTimeline;
},
'showLanguages' => function (bool $showLanguages = true) {
return $showLanguages;
},
'showTotals' => function (bool $showTotals = true) {
return $showTotals;
},
'size' => function(string $size = 'medium') {
return $size;
},
],
'computed' => [
'statsdata' => function () {
return $this->model()->getPageStats();
}
]
],
],
]);