|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\controllers\seo; |
|
4
|
|
|
|
|
5
|
|
|
use Ubiquity\controllers\Controller; |
|
6
|
|
|
use Ubiquity\seo\UrlParser; |
|
7
|
|
|
use Ubiquity\utils\http\UResponse; |
|
8
|
|
|
use Ubiquity\cache\CacheManager; |
|
9
|
|
|
use Ubiquity\controllers\Startup; |
|
10
|
|
|
use Ubiquity\seo\ControllerSeo; |
|
11
|
|
|
|
|
12
|
|
|
class SeoController extends Controller { |
|
13
|
|
|
const SEO_PREFIX = 'seo'; |
|
14
|
|
|
protected $urlsKey = 'urls'; |
|
15
|
|
|
protected $seoTemplateFilename = '@framework/Seo/sitemap.xml.html'; |
|
16
|
|
|
|
|
17
|
1 |
|
public function index() { |
|
18
|
1 |
|
$config = Startup::getConfig (); |
|
19
|
1 |
|
$base = \rtrim ( $config ['siteUrl'], '/' ); |
|
20
|
1 |
|
UResponse::asXml (); |
|
21
|
1 |
|
UResponse::noCache (); |
|
22
|
1 |
|
$urls = $this->_getArrayUrls (); |
|
23
|
1 |
|
if (\is_array ( $urls )) { |
|
24
|
1 |
|
$parser = new UrlParser (); |
|
25
|
1 |
|
$parser->parseArray ( $urls ); |
|
26
|
1 |
|
$this->loadView ( $this->seoTemplateFilename, [ 'urls' => $parser->getUrls (),'base' => $base ] ); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function _refresh() { |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getPath() { |
|
34
|
|
|
$seo = new ControllerSeo ( \get_class ( $this ) ); |
|
35
|
|
|
return $seo->getPath (); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function _save($array) { |
|
39
|
1 |
|
CacheManager::$cache->store ( $this->_getUrlsFilename (), $array ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function _getArrayUrls() { |
|
43
|
1 |
|
$key = $this->_getUrlsFilename (); |
|
44
|
1 |
|
if (! CacheManager::$cache->exists ( $key )) { |
|
45
|
1 |
|
$this->_save ( [ ] ); |
|
46
|
|
|
} |
|
47
|
1 |
|
return CacheManager::$cache->fetch ( $key ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function _getUrlsFilename() { |
|
55
|
1 |
|
return self::getUrlsFileName ( $this->urlsKey ); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public static function getUrlsFileName($urlsKey) { |
|
59
|
1 |
|
return self::SEO_PREFIX . \DS . $urlsKey; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function _getSeoTemplateFilename() { |
|
67
|
1 |
|
return $this->seoTemplateFilename; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|