<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index()
{
/* Get Instagram posts
$instagramPostIdsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/instagramPosts?token=863f1ccdb97de3b924e07b600ce0f5');
$instagramPostIdsJson = json_decode($instagramPostIdsJsonPath, true);
/* Open empty array to fill in all posts
$allInstagramPosts = array();
foreach ($instagramPostIdsJson['entries'] as $postId) {
$instagramJsonPath = @file_get_contents('https://api.instagram.com/oembed?url=https://www.instagram.com/p/' . $postId['id'] . '/');
$instagramJson = json_decode($instagramJsonPath, true);
array_push($allInstagramPosts, $instagramJson);
} */
/* Get slider from api */
$sliderJson = ['entries' => []];
try {
$sliderJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/homeSlider?token=863f1ccdb97de3b924e07b600ce0f5');
if ($sliderJsonPath !== false) {
$sliderJson = json_decode($sliderJsonPath, true) ?: ['entries' => []];
}
} catch (\Exception $e) {
error_log('API Error in DefaultController (slider): ' . $e->getMessage());
}
/* Get news from api */
$newsJson = ['entries' => []];
try {
$newsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/news?token=863f1ccdb97de3b924e07b600ce0f5');
if ($newsJsonPath !== false) {
$newsJson = json_decode($newsJsonPath, true) ?: ['entries' => []];
}
} catch (\Exception $e) {
error_log('API Error in DefaultController (news): ' . $e->getMessage());
}
/* Get sponsors from api */
$sponsorsJson = ['entries' => []];
try {
$sponsorsJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/collections/get/sponsors?token=863f1ccdb97de3b924e07b600ce0f5');
if ($sponsorsJsonPath !== false) {
$sponsorsJson = json_decode($sponsorsJsonPath, true) ?: ['entries' => []];
}
} catch (\Exception $e) {
error_log('API Error in DefaultController (sponsors): ' . $e->getMessage());
}
/* Get meta from api */
$metaJson = null;
try {
$metaJsonPath = @file_get_contents('https://api.ctc-rheda.de/api/singletons/get/home?token=863f1ccdb97de3b924e07b600ce0f5');
if ($metaJsonPath !== false) {
$metaJson = json_decode($metaJsonPath, true);
}
} catch (\Exception $e) {
error_log('API Error in DefaultController (meta): ' . $e->getMessage());
}
// Fallback if API is not available
if ($metaJson === null) {
$metaJson = [
'title' => 'Startseite',
'description' => 'Cor Tennis Club Rheda e.V.',
'keywords' => 'Tennis, CTC, Rheda, Startseite'
];
}
return $this->render('pages/home.html.twig', [
//'instagramPosts' => $allInstagramPosts,
'sliderItems' => $sliderJson['entries'],
'newsItems' => $newsJson['entries'],
'sponsorItems' => $sponsorsJson['entries'],
'page' => array(
'title' => 'Startseite',
'navigationMode' => 'default',
'description' => 'Cor Tennis Club Rheda e.V.',
'meta' => $metaJson
)
]);
}
}