src/Controller/DefaultController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. class DefaultController extends AbstractController
  6. {
  7.     /**
  8.      * @Route("/", name="home")
  9.      */
  10.     public function index()
  11.     {
  12.         /* Get Instagram posts
  13.         $instagramPostIdsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/instagramPosts?token=863f1ccdb97de3b924e07b600ce0f5');
  14.         $instagramPostIdsJson = json_decode($instagramPostIdsJsonPath, true);
  15.         /* Open empty array to fill in all posts
  16.         $allInstagramPosts = array();
  17.         foreach ($instagramPostIdsJson['entries'] as $postId) {
  18.             $instagramJsonPath = @file_get_contents('https://api.instagram.com/oembed?url=https://www.instagram.com/p/' . $postId['id'] . '/');
  19.             $instagramJson = json_decode($instagramJsonPath, true);
  20.             array_push($allInstagramPosts, $instagramJson);
  21.         } */
  22.         /* Get slider from api */
  23.         $sliderJson = ['entries' => []];
  24.         try {
  25.             $sliderJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/homeSlider?token=863f1ccdb97de3b924e07b600ce0f5');
  26.             if ($sliderJsonPath !== false) {
  27.                 $sliderJson json_decode($sliderJsonPathtrue) ?: ['entries' => []];
  28.             }
  29.         } catch (\Exception $e) {
  30.             error_log('API Error in DefaultController (slider): ' $e->getMessage());
  31.         }
  32.         /* Get news from api */
  33.         $newsJson = ['entries' => []];
  34.         try {
  35.             $newsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
  36.             if ($newsJsonPath !== false) {
  37.                 $newsJson json_decode($newsJsonPathtrue) ?: ['entries' => []];
  38.             }
  39.         } catch (\Exception $e) {
  40.             error_log('API Error in DefaultController (news): ' $e->getMessage());
  41.         }
  42.         /* Get sponsors from api */
  43.         $sponsorsJson = ['entries' => []];
  44.         try {
  45.             $sponsorsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/sponsors?token=863f1ccdb97de3b924e07b600ce0f5');
  46.             if ($sponsorsJsonPath !== false) {
  47.                 $sponsorsJson json_decode($sponsorsJsonPathtrue) ?: ['entries' => []];
  48.             }
  49.         } catch (\Exception $e) {
  50.             error_log('API Error in DefaultController (sponsors): ' $e->getMessage());
  51.         }
  52.         /* Get meta from api */
  53.         $metaJson null;
  54.         try {
  55.             $metaJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/singletons/get/home?token=863f1ccdb97de3b924e07b600ce0f5');
  56.             if ($metaJsonPath !== false) {
  57.                 $metaJson json_decode($metaJsonPathtrue);
  58.             }
  59.         } catch (\Exception $e) {
  60.             error_log('API Error in DefaultController (meta): ' $e->getMessage());
  61.         }
  62.         
  63.         // Fallback if API is not available
  64.         if ($metaJson === null) {
  65.             $metaJson = [
  66.                 'title' => 'Startseite',
  67.                 'description' => 'Cor Tennis Club Rheda e.V.',
  68.                 'keywords' => 'Tennis, CTC, Rheda, Startseite'
  69.             ];
  70.         }
  71.         return $this->render('pages/home.html.twig', [
  72.             //'instagramPosts' => $allInstagramPosts,
  73.             'sliderItems' => $sliderJson['entries'],
  74.             'newsItems' => $newsJson['entries'],
  75.             'sponsorItems' => $sponsorsJson['entries'],
  76.             'page' => array(
  77.                 'title' => 'Startseite',
  78.                 'navigationMode' => 'default',
  79.                 'description' => 'Cor Tennis Club Rheda e.V.',
  80.                 'meta' => $metaJson
  81.             )
  82.         ]);
  83.     }
  84. }