-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got the robots.txt and sitemap plugins working
- Loading branch information
1 parent
711c7dc
commit d190d27
Showing
10 changed files
with
113 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace AntCMS; | ||
|
||
class PluginController | ||
{ | ||
public static array $plugins = []; | ||
|
||
/** | ||
* Registers all plugin routes & sets up needed info for the plugin controller | ||
*/ | ||
public static function init(): void | ||
{ | ||
$list = scandir(antPluginPath); | ||
if (count($list) >= 2 && $list[0] === '.' && $list[1] === '..') { | ||
unset($list[0]); | ||
unset($list[1]); | ||
} | ||
|
||
foreach($list as $pluginName) { | ||
$className = "\AntCMS\\Plugins\\$pluginName\\Controller"; | ||
if(class_exists($className)) { | ||
new $className(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace AntCMS\Plugins\Robotstxt; | ||
|
||
use Flight; | ||
use AntCMS\Config; | ||
use AntCMS\Tools; | ||
|
||
class Controller | ||
{ | ||
public function __construct() | ||
{ | ||
Flight::route("GET /robots.txt", function (): void { | ||
$protocol = Config::currentConfig('forceHTTPS') ? 'https' : Flight::request()->scheme; | ||
$baseURL = Config::currentConfig('baseURL'); | ||
|
||
echo 'User-agent: *' . PHP_EOL; | ||
echo 'Sitemap: ' . $protocol . '://' . Tools::repairURL($baseURL . '/sitemap.xml' . PHP_EOL); | ||
Flight::response()->setHeader('Content-Type', 'text/plain'); | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace AntCMS\Plugins\Sitemap; | ||
|
||
use Flight; | ||
use AntCMS\Config; | ||
use AntCMS\Tools; | ||
use AntCMS\Pages; | ||
|
||
class Controller | ||
{ | ||
public function __construct() | ||
{ | ||
Flight::route("GET /sitemap.xml", function (): void { | ||
$protocol = Config::currentConfig('forceHTTPS') ? 'https' : Flight::request()->scheme; | ||
$baseURL = Config::currentConfig('baseURL'); | ||
|
||
$pages = Pages::getPages(); | ||
|
||
if (extension_loaded('dom')) { | ||
$domDocument = new \DOMDocument('1.0', 'UTF-8'); | ||
$domDocument->formatOutput = true; | ||
|
||
$domElement = $domDocument->createElement('urlset'); | ||
$domElement->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); | ||
$domDocument->appendChild($domElement); | ||
|
||
$urls = []; | ||
foreach ($pages as $key => $value) { | ||
$urls[$key]['url'] = $value['functionalPagePath']; | ||
$urls[$key]['lastchange'] = date('Y-m-d', filemtime($value['fullPagePath'])); | ||
} | ||
|
||
foreach ($urls as $url) { | ||
$element = $domDocument->createElement('url'); | ||
|
||
$loc = $domDocument->createElement('loc', $protocol . '://' . Tools::repairURL($baseURL . $url['url'])); | ||
$element->appendChild($loc); | ||
|
||
$lastmod = $domDocument->createElement('lastmod', $url['lastchange']); | ||
$element->appendChild($lastmod); | ||
|
||
$domElement->appendChild($element); | ||
} | ||
|
||
echo $domDocument->saveXML(); | ||
Flight::response()->header('Content-Type', 'application/xml'); | ||
} else { | ||
Flight::halt(503, "AntCMS is unable to generate a sitemap without having the DOM extension loadded in PHP."); | ||
} | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters