Skip to content
Snippets Groups Projects
Select Git revision
  • 4277a99505c2fb9c26147c79b86d4b97d20fd905
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

GalleryViewThumbnail.test.js

Blame
  • FallbackController.php 4.88 KiB
    <?php
    
    namespace App\Controller;
    
    use App\Helper\LegacyHelper;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\BinaryFileResponse;
    use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
    
    class FallbackController extends AbstractController
    {
        /**
         * @Route("/", name="get_legacy_resource", priority=-2)
         * @Route("/{controller}", name="get_legacy_resource", requirements={"controller" = ".+"}, priority=-1)
         */
        public function getLegacyResourceAction(Request $request, ?string $controller = null): Response
        {
            if ($request->query->has('p') || $request->request->has('p')) {
                $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
                // TODO : the following code MUST be re-enabled with tuleap-51
    
    //            $user = $this->getUser();
    //            $link = str_replace("php/project.php", "", $controller);
    //            $link = rtrim($link, "/");
    //            $user_id = $user->getId();
    
    //          // check if capsule exists in database
    //          $cap = $this->getDoctrine()
    //                      ->getManager()
    //                      ->getRepository('AppBundle:Capsule')
    //                      ->getCapsuleByLink($link);
    //          if (!$cap instanceof Capsule) {
    //              // rediriger sur une page demandant si il est l'auteur de la capsule
    //              return $this->redirectToRoute('add_author', array('capsuleLink'=>$link, 'capsulePass'=> $pass));
    //          }
    //
    //          // if capsule exists, check if user can edit it
    //          $cap = $this->getDoctrine()
    //                      ->getManager()
    //                      ->getRepository('AppBundle:Capsule')
    //                      ->getCapsuleByLinkAndUser($link, $user_id);
    //          if (!$cap instanceof Capsule) {
    //              // rediriger sur une page lui demandant de contacter
    //              // l'administrateur de la capsule pour lui donner des droits
    //              return $this->redirectToRoute('no_edition_access');
    //          }
    //
    //          // if yes, continue
    //          $cap->setAutMaj($user);
    //          $cap->setDtMaj(new \DateTime());
    //
    //          $em = $this->getDoctrine()->getManager();
    //          $em->persist($cap);
    //          $em->flush();
            }
    
    //        if ($controller == null) {
    //            //if no controller, this is index1.php
    //            return $this->redirectToRoute('get_legacy_resource', array('controller' => 'index1.php'));
    //        }
    
            if (null === $controller) {
                return LegacyHelper::transferToLegacy(
                    $request,
                    strval($this->getParameter('app.legacy_external_prefix')),
                    strval($this->getParameter('app.legacy_url'))
                );
            }
    
            // use iframe to enhance speed but not for creation
            if (strpos($controller, 'legacy') !== 0) {
                // relative path (to app/) of the legacy code (on the same filesystem)
                //$path_to_legacy_code = $this->getParameter('kernel.root_dir').
                //$this->getParameter('legacy_root_dir');
                $originalController = $request->getPathInfo();
                $originalQueryString = $request->getQueryString();
    
                $extension = strrchr($originalController, '.');
                if ($extension != '.html' && $extension != '.php' && $extension != false) {
                    //$url = "{$path_to_legacy_code}{$originalController}";
                    $url = "{$originalController}";
                    try {
                        $legacy_helper = new LegacyHelper();
                        $mime = $legacy_helper->getMime($url, $extension);
                        $response = new BinaryFileResponse($url);
                        $response->headers->set('Content-Type', $mime ?: 'application/octet-stream');
                        return $response;
                    } catch (FileNotFoundException $e) {
                        // try normal access by url
                    }
                }
                $separator = '';
                if (!$extension) {
                    $separator = '/';
                }
    
                $app_legacy_url_external = strval($this->getParameter('app.legacy_url_external'));
    
                $url = "{$app_legacy_url_external}/" .
                    "{$originalController}{$separator}?{$originalQueryString}";
                $url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url);
    
                // TODO: fix regex
    //            $pattern = '/\/\//i';
    //            $url = preg_replace($pattern, '/', $url);
    
                return $this->render("project/edit.html.twig", [
                    'url' => $url
                ]);
            }
    
            return LegacyHelper::transferToLegacy(
                $request,
                strval($this->getParameter('app.legacy_external_prefix')),
                strval($this->getParameter('app.legacy_url'))
            );
        }
    }