|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Retour plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* Retour allows you to intelligently redirect legacy URLs, so that you don't |
|
6
|
|
|
* lose SEO value when rebuilding & restructuring a website |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://nystudio107.com/ |
|
|
|
|
|
|
9
|
|
|
* @copyright Copyright (c) 2018 nystudio107 |
|
|
|
|
|
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace nystudio107\retour\models; |
|
13
|
|
|
|
|
14
|
|
|
use craft\base\Model; |
|
15
|
|
|
use craft\behaviors\EnvAttributeParserBehavior; |
|
16
|
|
|
use craft\validators\ArrayValidator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
|
|
|
|
|
19
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
20
|
|
|
* @package Retour |
|
|
|
|
|
|
21
|
|
|
* @since 3.0.0 |
|
|
|
|
|
|
22
|
|
|
*/ |
|
|
|
|
|
|
23
|
|
|
class Settings extends Model |
|
24
|
|
|
{ |
|
25
|
|
|
// Public Properties |
|
26
|
|
|
// ========================================================================= |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
|
|
|
|
|
29
|
|
|
* @var string The public-facing name of the plugin |
|
30
|
|
|
*/ |
|
31
|
|
|
public string $pluginName = 'Retour'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
|
|
|
|
|
34
|
|
|
* @var bool Controls whether Retour automatically creates static redirects |
|
35
|
|
|
* when an entry's URI changes. |
|
36
|
|
|
*/ |
|
37
|
|
|
public bool $createUriChangeRedirects = true; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
|
|
|
|
|
40
|
|
|
* @var string Should the legacy URL be matched by path (e.g. |
|
41
|
|
|
* `/new-recipes/`) or by full URL (e.g.: |
|
42
|
|
|
* `http://example.com/de/new-recipes/`)? |
|
43
|
|
|
*/ |
|
44
|
|
|
public string $uriChangeRedirectSrcMatch = 'pathonly'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
|
|
|
|
|
47
|
|
|
* @var bool Should the query string be stripped from all 404 URLs before |
|
48
|
|
|
* their evaluation? |
|
49
|
|
|
*/ |
|
50
|
|
|
public bool $alwaysStripQueryString = false; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
|
|
|
|
|
53
|
|
|
* @var bool Should the query string be preserved and passed along to the |
|
54
|
|
|
* redirected URL? |
|
55
|
|
|
*/ |
|
56
|
|
|
public bool $preserveQueryString = false; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
|
|
|
|
|
59
|
|
|
* @var bool Should `no-cache` headers be set on the redirect response to prevent client-side caching? |
|
60
|
|
|
*/ |
|
61
|
|
|
public bool $setNoCacheHeaders = true; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
|
|
|
|
|
64
|
|
|
* @var bool Should the anonymous ip address of the client causing a 404 be |
|
65
|
|
|
* recorded? |
|
66
|
|
|
*/ |
|
67
|
|
|
public bool $recordRemoteIp = true; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
|
|
|
|
|
70
|
|
|
* @var int How many static redirects to display in the Control Panel |
|
71
|
|
|
*/ |
|
72
|
|
|
public int $staticRedirectDisplayLimit = 100; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
|
|
|
|
|
75
|
|
|
* @var int How many dynamic redirects to display in the Control Panel |
|
76
|
|
|
*/ |
|
77
|
|
|
public int $dynamicRedirectDisplayLimit = 100; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
|
|
|
|
|
80
|
|
|
* @var bool Should the query string be stripped from the saved statistics |
|
81
|
|
|
* source URLs? |
|
82
|
|
|
*/ |
|
83
|
|
|
public bool $stripQueryStringFromStats = true; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
|
|
|
|
|
86
|
|
|
* @var int How many stats should be stored |
|
87
|
|
|
*/ |
|
88
|
|
|
public int $statsStoredLimit = 1000; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
|
|
|
|
|
91
|
|
|
* @var int Dashboard data live refresh interval |
|
92
|
|
|
*/ |
|
93
|
|
|
public int $refreshIntervalSecs = 5; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
|
|
|
|
|
96
|
|
|
* @var bool Whether the Statistics should be trimmed after each new |
|
97
|
|
|
* statistic is recorded |
|
98
|
|
|
*/ |
|
99
|
|
|
public bool $automaticallyTrimStatistics = true; |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
|
|
|
|
|
102
|
|
|
* @var bool Whether statistics should be kept to track how many times |
|
103
|
|
|
* a redirect has been followed |
|
104
|
|
|
*/ |
|
105
|
|
|
public $enableStatistics = true; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
|
|
|
|
|
108
|
|
|
* @var int The number of milliseconds required between trimming of |
|
109
|
|
|
* statistics |
|
110
|
|
|
*/ |
|
111
|
|
|
public int $statisticsRateLimitMs = 3600000; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
|
|
|
|
|
114
|
|
|
* @var int How many stats to display in the Control Panel |
|
115
|
|
|
*/ |
|
116
|
|
|
public int $statsDisplayLimit = 1000; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
|
|
|
|
|
119
|
|
|
* @var bool Determines whether the Retour API endpoint should be enabled for anonymous frontend access |
|
120
|
|
|
*/ |
|
121
|
|
|
public bool $enableApiEndpoint = false; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
|
|
|
|
|
124
|
|
|
* @var array [Regular expressions](https://regexr.com/) to match URLs to |
|
125
|
|
|
* exclude from Retour |
|
126
|
|
|
*/ |
|
127
|
|
|
public array $excludePatterns = [ |
|
128
|
|
|
]; |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
|
|
|
|
|
131
|
|
|
* @var array Additional headers to add to redirected requests |
|
132
|
|
|
*/ |
|
133
|
|
|
public array $additionalHeaders = [ |
|
134
|
|
|
]; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
|
|
|
|
|
137
|
|
|
* @var string The delimiter between data column values for importing CSV files (normally `,`) |
|
138
|
|
|
*/ |
|
139
|
|
|
public string $csvColumnDelimiter = ','; |
|
140
|
|
|
|
|
141
|
|
|
// Public Methods |
|
142
|
|
|
// ========================================================================= |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
|
|
|
|
|
145
|
|
|
* @inheritdoc |
|
146
|
|
|
*/ |
|
|
|
|
|
|
147
|
|
|
public function rules(): array |
|
148
|
|
|
{ |
|
149
|
|
|
return [ |
|
150
|
|
|
['pluginName', 'string'], |
|
151
|
|
|
['pluginName', 'default', 'value' => 'Retour'], |
|
152
|
|
|
[ |
|
153
|
|
|
[ |
|
154
|
|
|
'createUriChangeRedirects', |
|
155
|
|
|
'alwaysStripQueryString', |
|
156
|
|
|
'preserveQueryString', |
|
157
|
|
|
'stripQueryStringFromStats', |
|
158
|
|
|
'recordRemoteIp', |
|
159
|
|
|
], |
|
160
|
|
|
'boolean', |
|
161
|
|
|
], |
|
162
|
|
|
['uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly'], |
|
163
|
|
|
['uriChangeRedirectSrcMatch', 'string'], |
|
164
|
|
|
['uriChangeRedirectSrcMatch', 'in', 'range' => [ |
|
165
|
|
|
'pathonly', |
|
166
|
|
|
'fullurl', |
|
167
|
|
|
]], |
|
168
|
|
|
['staticRedirectDisplayLimit', 'integer', 'min' => 1], |
|
169
|
|
|
['staticRedirectDisplayLimit', 'default', 'value' => 100], |
|
170
|
|
|
['dynamicRedirectDisplayLimit', 'integer', 'min' => 1], |
|
171
|
|
|
['dynamicRedirectDisplayLimit', 'default', 'value' => 100], |
|
172
|
|
|
['statsStoredLimit', 'integer', 'min' => 1], |
|
173
|
|
|
['statsStoredLimit', 'default', 'value' => 1000], |
|
174
|
|
|
['refreshIntervalSecs', 'integer', 'min' => 0], |
|
175
|
|
|
['refreshIntervalSecs', 'default', 'value' => 3], |
|
176
|
|
|
['statsDisplayLimit', 'integer', 'min' => 1], |
|
177
|
|
|
['statsDisplayLimit', 'default', 'value' => 1000], |
|
178
|
|
|
[ |
|
179
|
|
|
[ |
|
180
|
|
|
'excludePatterns', |
|
181
|
|
|
'additionalHeaders', |
|
182
|
|
|
], |
|
183
|
|
|
ArrayValidator::class, |
|
184
|
|
|
], |
|
185
|
|
|
]; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
|
|
|
|
|
189
|
|
|
* @return array |
|
190
|
|
|
*/ |
|
191
|
|
|
public function behaviors(): array |
|
192
|
|
|
{ |
|
193
|
|
|
return [ |
|
194
|
|
|
'parser' => [ |
|
195
|
|
|
'class' => EnvAttributeParserBehavior::class, |
|
196
|
|
|
'attributes' => [ |
|
197
|
|
|
], |
|
198
|
|
|
], |
|
199
|
|
|
]; |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|