Beispiel #1
0
 /**
  * Returns generated text from the Robot model.
  *
  * @return string
  */
 public function generateTxt()
 {
     $robots = "";
     foreach (Robot::all() as $robot) {
         $robots .= 'User-agent: ' . $robot->agent . PHP_EOL;
         foreach ($robot->directives as $directive) {
             $robots .= $directive->type . ': ' . $directive->data . PHP_EOL;
         }
         $robots .= PHP_EOL;
     }
     return $robots;
 }
Beispiel #2
0
 /**
  * Returns generated text from the Robot model.
  *
  * @return string
  */
 public function generateTxt()
 {
     $robots = "";
     foreach (Robot::all() as $robot) {
         $robots .= 'User-agent: ' . $robot->agent . PHP_EOL;
         foreach ($robot->directives as $directive) {
             $robots .= $directive->type . ': ' . $directive->data . PHP_EOL;
         }
         $robots .= PHP_EOL;
     }
     /*
      * Compatability with RainLab.Sitemap
      */
     if (class_exists('\\RainLab\\Sitemap\\Classes\\DefinitionItem')) {
         $url = URL::to('/sitemap.xml');
         $robots .= 'Sitemap: ' . $url;
     }
     return $robots;
 }
Beispiel #3
0
<?php

use Cms\Classes\Page;
use Mohsin\Txt\Models\Robot;
use Mohsin\Txt\Models\Human;
use Mohsin\Txt\Models\Setting;
Route::get('robots.txt', function () {
    if (!Setting::get('use_robots') || !Robot::first()) {
        return Redirect::to(Page::url(Setting::get('redirectpage')));
    }
    return Response::make(Robot::first()->generateTxt(), 200, array('Content-Type' => 'text/plain'));
});
Route::get('humans.txt', function () {
    if (!Setting::get('use_humans') || !Human::first()) {
        return Redirect::to(Page::url(Setting::get('redirectpage')));
    }
    return Response::make(Human::first()->generateTxt(), 200, array('Content-Type' => 'text/plain'));
});