|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* GpsLab component. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Peter Gribanov <[email protected]> |
|
8
|
|
|
* @copyright Copyright (c) 2011, Peter Gribanov |
|
9
|
|
|
* @license http://opensource.org/licenses/MIT |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace GpsLab\Component\Sitemap\Url; |
|
13
|
|
|
|
|
14
|
|
|
final class ChangeFreq |
|
15
|
|
|
{ |
|
16
|
|
|
public const ALWAYS = 'always'; |
|
17
|
|
|
|
|
18
|
|
|
public const HOURLY = 'hourly'; |
|
19
|
|
|
|
|
20
|
|
|
public const DAILY = 'daily'; |
|
21
|
|
|
|
|
22
|
|
|
public const WEEKLY = 'weekly'; |
|
23
|
|
|
|
|
24
|
|
|
public const MONTHLY = 'monthly'; |
|
25
|
|
|
|
|
26
|
|
|
public const YEARLY = 'yearly'; |
|
27
|
|
|
|
|
28
|
|
|
public const NEVER = 'never'; |
|
29
|
|
|
|
|
30
|
|
|
private const CHANGE_FREQ_PRIORITY = [ |
|
31
|
|
|
'1.0' => ChangeFreq::HOURLY, |
|
32
|
|
|
'0.9' => ChangeFreq::DAILY, |
|
33
|
|
|
'0.8' => ChangeFreq::DAILY, |
|
34
|
|
|
'0.7' => ChangeFreq::WEEKLY, |
|
35
|
|
|
'0.6' => ChangeFreq::WEEKLY, |
|
36
|
|
|
'0.5' => ChangeFreq::WEEKLY, |
|
37
|
|
|
'0.4' => ChangeFreq::MONTHLY, |
|
38
|
|
|
'0.3' => ChangeFreq::MONTHLY, |
|
39
|
|
|
'0.2' => ChangeFreq::YEARLY, |
|
40
|
|
|
'0.1' => ChangeFreq::YEARLY, |
|
41
|
|
|
'0.0' => ChangeFreq::NEVER, |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \DateTimeInterface $last_mod |
|
46
|
|
|
* |
|
47
|
|
|
* @return string|null |
|
48
|
|
|
*/ |
|
49
|
16 |
|
public static function getByLastMod(\DateTimeInterface $last_mod): ?string |
|
50
|
|
|
{ |
|
51
|
16 |
|
if ($last_mod < new \DateTime('-1 year')) { |
|
52
|
4 |
|
return ChangeFreq::YEARLY; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
12 |
|
if ($last_mod < new \DateTime('-1 month')) { |
|
56
|
4 |
|
return ChangeFreq::MONTHLY; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
8 |
|
if ($last_mod < new \DateTime('-1 week')) { |
|
60
|
4 |
|
return ChangeFreq::WEEKLY; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
return null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $priority |
|
68
|
|
|
* |
|
69
|
|
|
* @return string|null |
|
70
|
|
|
*/ |
|
71
|
41 |
|
public static function getByPriority(string $priority): ?string |
|
72
|
|
|
{ |
|
73
|
41 |
|
return self::CHANGE_FREQ_PRIORITY[$priority] ?? null; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|