src/Controller/Pages/ObjectController.php line 134

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Pages;
  3. use App\Controller\Objects\HomeFacebookItem;
  4. use App\Kernel;
  5. use App\Controller\AbstractKasController;
  6. use App\Controller\AbstractKasModel;
  7. use App\Controller\Database;
  8. use App\Controller\PageInfo;
  9. use Symfony\Bundle\FrameworkBundle\Console\Application;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\Cache\Adapter\MemcachedAdapter;
  12. use Symfony\Component\Console\Input\ArrayInput;
  13. use Symfony\Component\Console\Output\BufferedOutput;
  14. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  15. use Symfony\Component\HttpFoundation\RequestStack;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\VarDumper;
  19. use Doctrine\DBAL\ParameterType;
  20. class ObjectController extends AbstractKasController
  21. {
  22.     public function __construct(RequestStack $requestStackDatabase $dbPageInfo $pageInfo)
  23.     {
  24.         parent::__construct($requestStack$db$pageInfo);
  25.         $this->request $requestStack->getCurrentRequest();
  26.         $this->model = new ObjectModel($db);
  27.     }
  28.     /**
  29.      * @Route("/vbazenu")
  30.      * @return \HttpResponse
  31.      * @throws \ErrorException
  32.      * @throws \Psr\Cache\InvalidArgumentException
  33.      * @throws \Symfony\Component\Cache\Exception\CacheException
  34.      */
  35.     public function vbazenu():Response {
  36.         $client MemcachedAdapter::createConnection(getenv('MC_SRV'));
  37.         $cache  = new MemcachedAdapter($client'vbazenu',  0);
  38.         $item   $cache->getItem('cache_vbazenu');
  39.         if (!$item->isHit()) {
  40.             /*$aqualink = 'http://78.111.121.60:2001/SystemConnector/GetZoneInfo';
  41.             $ch = curl_init();
  42.             $optArray = array(
  43.                 CURLOPT_URL => $aqualink,
  44.                 CURLOPT_RETURNTRANSFER => true
  45.             );
  46.             curl_setopt_array($ch, $optArray);
  47.             $result = curl_exec($ch);
  48.             $json = json_decode($result, true);
  49.             $count = (int)$json[0]['PeopleCount'];*/
  50.             $count rand(050);
  51.             $item
  52.                 ->set($count)
  53.                 ->expiresAfter(60); // in seconds
  54.             $cache->save($item);
  55.         } else {
  56.             $count $item->get();
  57.         }
  58.         return new Response($count);
  59.     }
  60.     /**
  61.      * @Route("/zimni-stadion-rocknet-arena/fotogalerie")
  62.      * @Route("/fotbalovy-stadion/fotogalerie")
  63.      * @Route("/aquasvet/fotogalerie")
  64.      * @Route("/kino-svet/fotogalerie")
  65.      * @Route("/mestske-divadlo/fotogalerie")
  66.      * @Route("/mestska-sportovni-hala/fotogalerie")
  67.      * @Route("/atleticky-stadion/fotogalerie")
  68.      * @Route("/in-line-draha/fotogalerie")
  69.      * @Route("/sportovni-areal-tomase-ze-stitneho/fotogalerie")
  70.      * @Route("/letni-kino/fotogalerie")
  71.      * @Route("/hriste/fotogalerie")
  72.      * @Route("/zimni-stadion-treninkova-hala/fotogalerie")
  73.      * @return Response
  74.      * @throws \Facebook\Exceptions\FacebookSDKException
  75.      */
  76.     public function fotogalerie(): Response
  77.     {
  78.         //$n = $this->pageInfo->getNavbar();
  79.         //dump($n);
  80.         $link $this->request->getRequestUri();
  81.         $link str_replace('/fotogalerie'''$link);
  82.         $objectinfo $this->model->getObjectInfo($link);
  83.         //pokud nenalezeno, tak 404
  84.         if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
  85.             'pageinfo' => $this->pageInfo
  86.         ]);
  87.         $model = new HomeModel($this->db);
  88.         $top_events $model->getTopEvents(); //dump($top_events);
  89.         $facebook_feed $model->getFacebookFeed();
  90.         return $this->render('/pages/gallery.html.twig', [
  91.             'pageinfo' => $this->pageInfo,
  92.             'objectinfo' => $objectinfo,
  93.             'top_events' => $top_events,
  94.             'facebook_feed' => $facebook_feed
  95.         ]);
  96.     }
  97.     /**
  98.      * @Route("/zimni-stadion-rocknet-arena")
  99.      * @Route("/fotbalovy-stadion")
  100.      * @Route("/aquasvet")
  101.      * @Route("/kino-svet")
  102.      * @Route("/mestske-divadlo")
  103.      * @Route("/mestska-sportovni-hala")
  104.      * @Route("/atleticky-stadion")
  105.      * @Route("/in-line-draha")
  106.      * @Route("/sportovni-areal-tomase-ze-stitneho")
  107.      * @Route("/letni-kino")
  108.      * @Route("/hriste")
  109.      * @Route("/zimni-stadion-treninkova-hala")
  110.      * @Route("/zarizeni/zimni-stadion-rocknet-arena")
  111.      * @Route("/zarizeni/fotbalovy-stadion")
  112.      * @Route("/zarizeni/aquasvet")
  113.      * @Route("/zarizeni/kino-svet")
  114.      * @Route("/zarizeni/mestske-divadlo")
  115.      * @Route("/zarizeni/mestska-sportovni-hala")
  116.      * @Route("/zarizeni/atleticky-stadion")
  117.      * @Route("/zarizeni/in-line-draha")
  118.      * @Route("/zarizeni/sportovni-areal-tomase-ze-stitneho")
  119.      * @Route("/zarizeni/letni-kino")
  120.      * @Route("/zarizeni/hriste")
  121.      * @Route("/zarizeni/zimni-stadion-treninkova-hala")
  122.      * @return Response
  123.      * @throws \Facebook\Exceptions\FacebookSDKException
  124.      */
  125.     public function object(): Response
  126.     {
  127.         //$n = $this->pageInfo->getNavbar();
  128.         //dump($n);
  129.         $link $this->request->getRequestUri();
  130.         if (str_starts_with($link'/zarizeni')) {
  131.             $link str_replace('/zarizeni/''/'$link);
  132.         }
  133.         $objectinfo $this->model->getObjectInfo($link);
  134.         //pokud nenalezeno, tak 404
  135.         if (!$objectinfo->isFound()) return $this->render('/pages/404.html.twig', [
  136.             'pageinfo' => $this->pageInfo
  137.         ]);
  138.         $html $objectinfo->getHtml(); //files/www_html
  139.         $html2 $objectinfo->getHtml2();
  140.        /*if ($html=='' && $html2=='') $twig = '/pages/object2.html.twig';
  141.        else*/ $twig '/pages/object.html.twig';
  142.         return $this->render($twig, [
  143.             'pageinfo' => $this->pageInfo,
  144.             'objectinfo' => $objectinfo,
  145.             'html' => $html,
  146.             'html2' => $html2
  147.         ]);
  148.     }
  149.     /**
  150.      * @Route("/soubor-{id64}")
  151.      * @return Response
  152.      * @throws \Facebook\Exceptions\FacebookSDKException
  153.      */
  154.     public function download($id64): Response
  155.     {
  156.         $id base64_decode($id64);
  157.         $id substr($id4, -4);
  158.         if ((int)$id==0) return $this->render('/pages/404.html.twig', [
  159.             'pageinfo' => $this->pageInfo
  160.         ]);
  161.         $filename $folder '';
  162.         $this->model->getFileInfo($id$filename$folder);
  163.         if ($filename == '' || $folder == '') {
  164.             return $this->render('/pages/404.html.twig', [
  165.                 'pageinfo' => $this->pageInfo
  166.             ]);
  167.         }
  168.         $file_path getenv('APP_DIR').'private/data/files/www_objects/'.$folder.'/'.$filename;
  169.         if (!file_exists($file_path)) {
  170.             return $this->render('/pages/404.html.twig', [
  171.                 'pageinfo' => $this->pageInfo
  172.             ]);
  173.         }
  174.         header('Content-Description: File Transfer');
  175.         header('Content-Type: application/octet-stream');
  176.         header('Content-Disposition: attachment; filename="'.$filename.'"');
  177.         header('Content-Transfer-Encoding: binary');
  178.         header('Expires: 0');
  179.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  180.         header('Pragma: public');
  181.         header('Content-Length: ' filesize($file_path));
  182.         ob_clean();
  183.         flush();
  184.         readfile($file_path);
  185.         exit();
  186.     }
  187. }
  188. ?>