Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ControllerSeo.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\seo;
4
11
22 private $name;
23 private $urlsFile;
25 private $route;
26 private $inRobots;
27
28 public function __construct($className = null) {
29 if (isset ( $className ) && \class_exists ( $className )) {
30 $route = Router::getRouteInfoByControllerAction ( $className, "index" );
31 if ($route) {
32 $this->route = $route ["path"];
33 }
34 $ctrl = new $className ();
35 $this->name = $className;
36 $this->urlsFile = $ctrl->_getUrlsFilename ();
37 $this->siteMapTemplate = $ctrl->_getSeoTemplateFilename ();
38 }
39 }
40
45 public function getName() {
46 return $this->name;
47 }
48
53 public function getUrlsFile() {
54 return $this->urlsFile;
55 }
56
61 public function getSiteMapTemplate() {
63 }
64
69 public function getRoute() {
70 return $this->route;
71 }
72
77 public function setName($name) {
78 $this->name = $name;
79 }
80
85 public function setUrlsFile($urlsFile) {
86 $this->urlsFile = $urlsFile;
87 }
88
94 $this->siteMapTemplate = $siteMapTemplate;
95 }
96
101 public function setRoute($route) {
102 $this->route = $route;
103 }
104
105 public function getPath() {
106 if (UString::isNotNull ( $this->route ))
107 return $this->route;
108 $parts = \explode ( "\\", $this->name );
109 return end ( $parts );
110 }
111
112 public function urlExists() {
113 return CacheManager::$cache->exists ( $this->urlsFile );
114 }
115
116 public static function init() {
117 $result = [ ];
118 $config = Startup::getConfig ();
119
120 $robotsContent = "";
121 $robotsFile = Startup::getApplicationDir () . \DS . 'robots.txt';
122 if (\file_exists ( $robotsFile )) {
123 $robotsContent = UFileSystem::load ( $robotsFile );
124 }
125 $files = CacheManager::getControllersFiles ( $config, true );
126 try {
127 $restCtrls = CacheManager::getRestCache ();
128 } catch ( \Exception $e ) {
129 $restCtrls = [ ];
130 }
131
132 foreach ( $files as $file ) {
133 if (is_file ( $file )) {
134 $controllerClass = ClassUtils::getClassFullNameFromFile ( $file );
135 if (isset ( $restCtrls [$controllerClass] ) === false) {
136 if (\class_exists ( $controllerClass, true )) {
137 $reflect = new \ReflectionClass ( $controllerClass );
138 if (! $reflect->isAbstract () && $reflect->isSubclassOf ( 'Ubiquity\controllers\seo\SeoController' )) {
139 $ctrlSeo = new ControllerSeo ( $controllerClass );
140 $path = $ctrlSeo->getPath ();
141 $ctrlSeo->setInRobots ( $robotsContent !== false && (\strpos ( $robotsContent, $path ) !== false) );
142 $result [] = $ctrlSeo;
143 }
144 }
145 }
146 }
147 }
148 return $result;
149 }
150
155 public function getInRobots() {
156 return $this->inRobots;
157 }
158
163 public function setInRobots($inRobots) {
164 $this->inRobots = $inRobots;
165 }
166}
Manager for caches (Router, Rest, models).
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
Starts the framework.
Definition Startup.php:19
Base class for SEO controllers Ubiquity\seo$ControllerSeo This class is part of Ubiquity.
__construct($className=null)
setSiteMapTemplate($siteMapTemplate)
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
String utilities.
Definition UString.php:15