src/Eccube/Controller/UserDataController.php line 55

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Eccube\Entity\Page;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Repository\Master\DeviceTypeRepository;
  17. use Eccube\Repository\PageRepository;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. class UserDataController extends AbstractController
  22. {
  23.   /**
  24.    * @var PageRepository
  25.    */
  26.   protected $pageRepository;
  27.   /**
  28.    * @var DeviceTypeRepository
  29.    */
  30.   protected $deviceTypeRepository;
  31.   /**
  32.    * UserDataController constructor.
  33.    *
  34.    * @param PageRepository $pageRepository
  35.    * @param DeviceTypeRepository $deviceTypeRepository
  36.    */
  37.   public function __construct(
  38.     PageRepository       $pageRepository,
  39.     DeviceTypeRepository $deviceTypeRepository
  40.   )
  41.   {
  42.     $this->pageRepository $pageRepository;
  43.     $this->deviceTypeRepository $deviceTypeRepository;
  44.   }
  45.   /**
  46.    * @Route("/%eccube_user_data_route%/{route}", name="user_data", requirements={"route": "([0-9a-zA-Z_\-]+\/?)+(?<!\/)"}, methods={"GET"})
  47.    */
  48.   public function index(Request $request$route)
  49.   {
  50.     $Page $this->pageRepository->findOneBy(
  51.       [
  52.         'url' => $route,
  53.         'edit_type' => Page::EDIT_TYPE_USER,
  54.       ]
  55.     );
  56.     if (null === $Page) {
  57.       throw new NotFoundHttpException();
  58.     }
  59.     $file sprintf('@user_data/%s.twig'$Page->getFileName());
  60.     $event = new EventArgs(
  61.       [
  62.         'Page' => $Page,
  63.         'file' => $file,
  64.       ],
  65.       $request
  66.     );
  67.     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
  68.     if ($file == "@user_data/faq_ret.twig") {
  69.       $search_word $request->get('search_word');
  70.       // ①ファイルを読み込む
  71.       $dir "/home/xb006434/xb006434.xbiz.jp/public_html/app/template/user_data/";
  72.       $files = array("faq_products" => "商品について","faq_pay" => "お支払いについて",
  73.         "faq_delivery" => "配送について","faq_service" => "サービスについて","faq_other" => "その他について");
  74.       $matches = array();
  75.       foreach($files as $k => $v){
  76.         $f $dir.$k.".twig";
  77.         $html file_get_contents($f);
  78.         preg_match_all('/<details class="accordion-006">(.*?)<\/details>/s'$html$tmp);
  79.         if(!empty($tmp[0])){
  80.           foreach($tmp[0] as $t){
  81.             if(preg_match("/{$search_word}/"$t)){
  82.               $t1 preg_replace("/{$search_word}/",'<span class="match">'.$search_word.'</span>'$t);
  83.               $t2 preg_replace('/<details class="accordion-006">/','<details class="accordion-006" open>'$t1);
  84.               $matches[$k][] = $t2;
  85.             }
  86.           }
  87.         }
  88.       }
  89.       if(count($matches) > 0){
  90.         $args["files"] = $files;
  91.         $args["matches"] = $matches;
  92.       }
  93.       return $this->render($file,["files" => $files,"matches" => $matches]);
  94.     }
  95.     return $this->render($file);
  96.   }
  97. }