|
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
|
|
|
public function __construct() { |
|
16
|
|
|
$this->urls=[]; |
|
17
|
|
|
$this->config=Startup::getConfig(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function parse() { |
|
21
|
|
|
$routes=CacheManager::getRoutes(); |
|
22
|
|
|
foreach ( $routes as $path => $route ) { |
|
23
|
|
|
$url=$this->parseUrl($path, $route); |
|
24
|
|
|
if (isset($url)) { |
|
25
|
|
|
if(!isset($this->urls[$path])) |
|
26
|
|
|
$this->urls[$path]=$url; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function parseArray($array,$existing=true){ |
|
32
|
|
|
foreach ($array as $url){ |
|
33
|
|
|
$this->urls[$url['location']]=Url::fromArray($url,$existing); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function parseUrl($path, $route) { |
|
38
|
|
|
if (isset($route["controller"])) { |
|
39
|
|
|
$controller=$route["controller"]; |
|
40
|
|
|
$action=$route["action"]; |
|
41
|
|
|
} elseif (isset($route["get"])) { |
|
42
|
|
|
return $this->parseUrl($path,$route["get"]); |
|
43
|
|
|
} else { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
$lastModified=self::getLastModified($controller, $action); |
|
47
|
|
|
if($lastModified!==false){ |
|
48
|
|
|
$url=new Url($path, $lastModified); |
|
49
|
|
|
return $url; |
|
50
|
|
|
} |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public static function getLastModified($controller, $action) { |
|
55
|
|
|
if(\class_exists($controller)){ |
|
56
|
|
|
$classCode=UIntrospection::getClassCode($controller); |
|
57
|
|
|
$lastModified=UFileSystem::lastModified(UIntrospection::getFileName($controller)); |
|
58
|
|
|
if(\is_array($classCode)){ |
|
59
|
|
|
$reflexAction=new \ReflectionMethod($controller.'::'.$action); |
|
60
|
|
|
$views=UIntrospection::getLoadedViews($reflexAction, $classCode); |
|
61
|
|
|
foreach ( $views as $view ) { |
|
62
|
|
|
$file=ROOT . DS . "views" . DS . $view; |
|
63
|
|
|
$viewDate=UFileSystem::lastModified($file); |
|
64
|
|
|
if ($viewDate > $lastModified) |
|
65
|
|
|
$lastModified=$viewDate; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
return $lastModified; |
|
69
|
|
|
} |
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
/** |
|
73
|
|
|
* @return multitype: |
|
|
|
|
|
|
74
|
|
|
*/ |
|
75
|
|
|
public function getUrls() { |
|
76
|
|
|
return $this->urls; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.