Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| RobotsController | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| beforeFilter | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| index | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace App\Controller; |
| 5 | |
| 6 | use App\Utility\SettingsManager; |
| 7 | use Cake\Event\EventInterface; |
| 8 | use Cake\Http\Response; |
| 9 | |
| 10 | class RobotsController extends AppController |
| 11 | { |
| 12 | /** |
| 13 | * Configures authentication for specific actions. |
| 14 | * |
| 15 | * @param \Cake\Event\EventInterface $event The event instance. |
| 16 | * @return void |
| 17 | */ |
| 18 | public function beforeFilter(EventInterface $event): void |
| 19 | { |
| 20 | parent::beforeFilter($event); |
| 21 | $this->Authentication->addUnauthenticatedActions(['index']); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Display robots.txt content with language-specific paths |
| 26 | * |
| 27 | * @return \Cake\Http\Response |
| 28 | */ |
| 29 | public function index(): Response |
| 30 | { |
| 31 | $robotsContent = SettingsManager::read('SEO.robots', ''); |
| 32 | |
| 33 | // Get language from URL or default to 'en' |
| 34 | $lang = $this->request->getParam('lang'); |
| 35 | |
| 36 | // If no language parameter (root robots.txt request), default to 'en' |
| 37 | if (empty($lang)) { |
| 38 | $lang = 'en'; |
| 39 | } |
| 40 | |
| 41 | // Replace language placeholder with actual language code |
| 42 | $robotsContent = str_replace('{LANG}', $lang, $robotsContent); |
| 43 | |
| 44 | return $this->response |
| 45 | ->withType('text/plain') |
| 46 | ->withStringBody($robotsContent) |
| 47 | ->withCache('-1 minute', '+1 day'); // Add cache headers |
| 48 | } |
| 49 | } |