-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
112 lines (110 loc) · 4.59 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
<?php
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('bnomei/seobility', [
'options' => [
'enabled' => true,
'apikey' => null,
'expire' => 0, // has a modified check built in
'cache' => true,
'searchengine' => 'google.com',
'free' => [
'keywordcheck' => function (string $url, ?string $keyword = null, ?string $lang = null) {
$lang = $lang ?? 'en';
if (kirby()->languages()->count() > 0 && kirby()->language()->code() === 'de') {
$lang = 'de';
}
return implode([
'https://freetools.seobility.net/'.$lang.'/keywordcheck/check',
'?url=' . urlencode($url),
'&keyword=' . str_replace([',',' '], ['','+'], $keyword ?? ''),
'&crawltype=1',
'&ref=kirby3-seobility-plugin',
]);
},
],
'paid' => [
'keywordcheck' => function (string $url, ?string $keyword = null, ?string $lang = null) {
// https://www.seobility.net/static/api/documentation.html#keywordcheck
return implode([
'https://api.seobility.net/en/resellerapi/keywordcheck',
'?url=' . urlencode($url),
'&keyword=' . str_replace([',',' '], ['','+'], $keyword ?? ''),
'&apikey=' . \Bnomei\Seobility::singleton()->option('apikey'),
'&ref=kirby3-seobility-plugin',
]);
},
'ranking' => function (string $url, ?string $keyword = null, ?string $lang = null) {
// https://www.seobility.net/static/api/documentation.html#ranking
return implode([
'https://api.seobility.net/en/resellerapi/ranking',
'?url=' . urlencode($url),
'&keyword=' . str_replace([',',' '], ['','+'], $keyword ?? ''),
'&searchengine=' . \Bnomei\Seobility::singleton()->option('searchengine'),
'&apikey=' . \Bnomei\Seobility::singleton()->option('apikey'),
'&ref=kirby3-seobility-plugin',
]);
},
'termsuggestion' => function (string $url, ?string $keyword = null, ?string $lang = null) {
// https://www.seobility.net/static/api/documentation.html#termsuggestion
return implode([
'https://api.seobility.net/en/resellerapi/termsuggestion',
'?url=' . urlencode($url),
'&keyword=' . str_replace([',',' '], ['','+'], $keyword ?? ''),
'&searchengine=' . \Bnomei\Seobility::singleton()->option('searchengine'),
'&apikey=' . \Bnomei\Seobility::singleton()->option('apikey'),
'&ref=kirby3-seobility-plugin',
]);
},
],
],
'fields' => [
'keywordcheck' => [
'props' => [],
'computed' => [
'url' => function () {
return \Bnomei\Seobility::singleton()->keywordcheck($this->model)['url'];
},
'score' => function () {
return $this->model()->keywordcheckScore();
},
'paid' => function () {
return !empty(\Bnomei\Seobility::singleton()->option('apikey'));
},
],
],
'ranking' => [
'props' => [],
'computed' => [],
],
'termsuggestion' => [
'props' => [],
'computed' => [],
],
],
'pageMethods' => [
'keywordcheckScore' => function () {
return \Bnomei\Seobility::singleton()->keywordcheck($this)['score'];
},
],
'api' => [
'routes' => [
[
'pattern' => 'seobility/(:any)',
'action' => function (string $endpoint) {
$id = urldecode(get('id'));
$lang = get('lang');
if ($lang == 'false') {
$lang = null;
}
$id = explode('?', ltrim(str_replace(['/pages/','/_drafts/','+',' '], ['/','/','/','/'], $id), '/'))[0];
$page = page($id);
return $page ? \Bnomei\Seobility::singleton()->{$endpoint}(
$page,
null, // auto
$page->url($lang)
) : [];
},
],
],
],
]);