datatable.directory codebase
				https://datatable.directory/
			
			
		
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							139 lines
						
					
					
						
							3.8 KiB
						
					
					
				
			
		
		
	
	
							139 lines
						
					
					
						
							3.8 KiB
						
					
					
				| <?php
 | |
| 
 | |
| 
 | |
| namespace App\Http\Controllers;
 | |
| 
 | |
| 
 | |
| use App\Models\Table;
 | |
| use App\Models\User;
 | |
| use XMLWriter;
 | |
| 
 | |
| /**
 | |
|  * This controller is responsible for producing a XML sitemap
 | |
|  */
 | |
| class SitemapController extends Controller
 | |
| {
 | |
|     /**
 | |
|      * Render a sitemap to the browser
 | |
|      */
 | |
|     public function sitemap()
 | |
|     {
 | |
|         ob_end_clean();
 | |
| 
 | |
|         // Redirect output to a client’s web browser
 | |
|         header("Content-Type: text/xml; charset=utf-8");
 | |
|         // Cache headers
 | |
|         header('Cache-Control: max-age=0');
 | |
|         // IE9
 | |
|         header('Cache-Control: max-age=1');
 | |
|         // Other IE headers
 | |
|         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
 | |
|         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
 | |
|         header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
 | |
|         header('Pragma: no-cache'); // HTTP/1.0
 | |
| 
 | |
|         $xmlWriter = new XMLWriter();
 | |
|         $xmlWriter->openURI('php://output');
 | |
|         $xmlWriter->startDocument('1.0', 'UTF-8');
 | |
|         $xmlWriter->setIndent(true);
 | |
|         {
 | |
|             $xmlWriter->startElement('urlset');
 | |
|             {
 | |
|                 $xmlWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
 | |
|                 foreach ($this->iterateTables() as $entry) {
 | |
|                     $xmlWriter->startElement('url');
 | |
|                     $xmlWriter->writeElement('loc', $entry->url);
 | |
| 
 | |
|                     if (isset($entry->priority)) {
 | |
|                         $xmlWriter->writeElement('priority', $entry->priority);
 | |
|                     }
 | |
| 
 | |
|                     if (isset($entry->changefreq)) {
 | |
|                         $xmlWriter->writeElement('changefreq', $entry->changefreq);
 | |
|                     }
 | |
| 
 | |
|                     if (isset($entry->lastmodified)) {
 | |
|                         $xmlWriter->writeElement('lastmod', $entry->lastmodified->format(\DateTime::W3C));
 | |
|                     }
 | |
|                     $xmlWriter->endElement();
 | |
|                 }
 | |
|             }
 | |
|             $xmlWriter->endElement();
 | |
|         }
 | |
|         $xmlWriter->endDocument();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Go through all tables and other links and return objects
 | |
|      * that can be turned into sitemap entries.
 | |
|      *
 | |
|      * @return \Generator|object[]
 | |
|      */
 | |
|     private function iterateTables()
 | |
|     {
 | |
|         $prio_info = .9;
 | |
|         $prio_user = .8;
 | |
|         $prio_table = .7;
 | |
|         $prio_table_rev = .6;
 | |
|         $prio_misc = .5;
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('dash'),
 | |
|             'priority' => 1,
 | |
|         ];
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('terms'),
 | |
|             'priority' => $prio_info,
 | |
|         ];
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('faq'),
 | |
|             'priority' => $prio_info,
 | |
|         ];
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('donate'),
 | |
|             'priority' => $prio_info,
 | |
|         ];
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('privacy'),
 | |
|             'priority' => $prio_info,
 | |
|         ];
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('login'),
 | |
|             'priority' => $prio_misc,
 | |
|         ];
 | |
| 
 | |
|         yield (object)[
 | |
|             'url' => route('register'),
 | |
|             'priority' => $prio_misc,
 | |
|         ];
 | |
| 
 | |
|         // User profiles
 | |
|         foreach (User::all() as $user) {
 | |
|             yield (object)[
 | |
|                 'url' => route('profile.view', $user->name),
 | |
|                 'lastmodified' => $user->updated_at,
 | |
|                 'priority' => $prio_user,
 | |
|             ];
 | |
|         }
 | |
| 
 | |
|         // Tables
 | |
|         foreach (Table::all() as $table) {
 | |
|             yield (object)[
 | |
|                 'url' => $table->viewRoute,
 | |
|                 'lastmodified' => $table->updated_at,
 | |
|                 'priority' => $prio_table,
 | |
|             ];
 | |
| 
 | |
|             yield (object)[
 | |
|                 'url' => $table->revisionsRoute,
 | |
|                 'lastmodified' => $table->updated_at,
 | |
|                 'priority' => $prio_table_rev,
 | |
|             ];
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 |