1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ubiquity\seo; |
4
|
|
|
|
5
|
|
|
use Ubiquity\cache\CacheManager; |
6
|
|
|
use Ubiquity\utils\base\UIntrospection; |
7
|
|
|
use Ubiquity\utils\base\UFileSystem; |
8
|
|
|
use Ubiquity\controllers\Startup; |
9
|
|
|
|
10
|
|
|
class UrlParser { |
11
|
|
|
public static $frequencies = [ 'always','hourly','daily','weekly','monthly','yearly','never' ]; |
12
|
|
|
private $urls; |
13
|
|
|
private $config; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* |
17
|
|
|
* @return mixed |
18
|
|
|
*/ |
19
|
|
|
public function getConfig() { |
20
|
|
|
return $this->config; |
21
|
|
|
} |
22
|
|
|
|
23
|
1 |
|
public function __construct() { |
24
|
1 |
|
$this->urls = [ ]; |
25
|
1 |
|
$this->config = Startup::getConfig (); |
26
|
1 |
|
} |
27
|
|
|
|
28
|
1 |
|
public function parse() { |
29
|
1 |
|
$routes = CacheManager::getRoutes (); |
30
|
1 |
|
foreach ( $routes as $path => $route ) { |
31
|
1 |
|
$url = $this->parseUrl ( $path, $route ); |
32
|
1 |
|
if (isset ( $url )) { |
33
|
1 |
|
if (! isset ( $this->urls [$path] )) |
34
|
1 |
|
$this->urls [$path] = $url; |
35
|
|
|
} |
36
|
|
|
} |
37
|
1 |
|
} |
38
|
|
|
|
39
|
1 |
|
public function parseArray($array, $existing = true) { |
40
|
1 |
|
foreach ( $array as $url ) { |
41
|
1 |
|
$this->urls [$url ['location']] = Url::fromArray ( $url, $existing ); |
42
|
|
|
} |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
protected function parseUrl($path, $route) { |
46
|
1 |
|
if (isset ( $route ["controller"] )) { |
47
|
1 |
|
$controller = $route ["controller"]; |
48
|
1 |
|
$action = $route ["action"]; |
49
|
|
|
} elseif (isset ( $route ["get"] )) { |
50
|
|
|
return $this->parseUrl ( $path, $route ["get"] ); |
51
|
|
|
} else { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
1 |
|
$lastModified = self::getLastModified ( $controller, $action ); |
55
|
1 |
|
if ($lastModified !== false) { |
56
|
1 |
|
$url = new Url ( $path, $lastModified ); |
57
|
1 |
|
return $url; |
58
|
|
|
} |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public static function getLastModified($controller, $action) { |
63
|
1 |
|
if (\class_exists ( $controller )) { |
64
|
1 |
|
$classCode = UIntrospection::getClassCode ( $controller ); |
65
|
1 |
|
$lastModified = UFileSystem::lastModified ( UIntrospection::getFileName ( $controller ) ); |
66
|
1 |
|
if (\is_array ( $classCode )) { |
67
|
1 |
|
$reflexAction = new \ReflectionMethod ( $controller . '::' . $action ); |
68
|
1 |
|
$views = UIntrospection::getLoadedViews ( $reflexAction, $classCode ); |
69
|
1 |
|
$baseView=\ROOT.\DS."views".\DS; |
70
|
1 |
|
foreach ( $views as $view ) { |
71
|
1 |
|
$file = $baseView. $view; |
72
|
1 |
|
if(\file_exists($file)){ |
73
|
1 |
|
$viewDate = UFileSystem::lastModified ( $file ); |
74
|
1 |
|
if ($viewDate > $lastModified){ |
75
|
|
|
$lastModified = $viewDate; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
1 |
|
return $lastModified; |
81
|
|
|
} |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
1 |
|
public function getUrls() { |
90
|
1 |
|
return $this->urls; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|