Passed
Push — master ( 367555...dfeadf )
by Jean-Christophe
04:46
created

SeoController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 10
eloc 23
dl 0
loc 56
ccs 25
cts 30
cp 0.8333
rs 10
c 0
b 0
f 0

8 Methods

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