<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\Controller;
use Eccube\Entity\Page;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Repository\PageRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class UserDataController extends AbstractController
{
/**
* @var PageRepository
*/
protected $pageRepository;
/**
* @var DeviceTypeRepository
*/
protected $deviceTypeRepository;
/**
* UserDataController constructor.
*
* @param PageRepository $pageRepository
* @param DeviceTypeRepository $deviceTypeRepository
*/
public function __construct(
PageRepository $pageRepository,
DeviceTypeRepository $deviceTypeRepository
)
{
$this->pageRepository = $pageRepository;
$this->deviceTypeRepository = $deviceTypeRepository;
}
/**
* @Route("/%eccube_user_data_route%/{route}", name="user_data", requirements={"route": "([0-9a-zA-Z_\-]+\/?)+(?<!\/)"}, methods={"GET"})
*/
public function index(Request $request, $route)
{
$Page = $this->pageRepository->findOneBy(
[
'url' => $route,
'edit_type' => Page::EDIT_TYPE_USER,
]
);
if (null === $Page) {
throw new NotFoundHttpException();
}
$file = sprintf('@user_data/%s.twig', $Page->getFileName());
$event = new EventArgs(
[
'Page' => $Page,
'file' => $file,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
if ($file == "@user_data/faq_ret.twig") {
$search_word = $request->get('search_word');
// ①ファイルを読み込む
$dir = "/home/xb006434/xb006434.xbiz.jp/public_html/app/template/user_data/";
$files = array("faq_products" => "商品について","faq_pay" => "お支払いについて",
"faq_delivery" => "配送について","faq_service" => "サービスについて","faq_other" => "その他について");
$matches = array();
foreach($files as $k => $v){
$f = $dir.$k.".twig";
$html = file_get_contents($f);
preg_match_all('/<details class="accordion-006">(.*?)<\/details>/s', $html, $tmp);
if(!empty($tmp[0])){
foreach($tmp[0] as $t){
if(preg_match("/{$search_word}/", $t)){
$t1 = preg_replace("/{$search_word}/",'<span class="match">'.$search_word.'</span>', $t);
$t2 = preg_replace('/<details class="accordion-006">/','<details class="accordion-006" open>', $t1);
$matches[$k][] = $t2;
}
}
}
}
if(count($matches) > 0){
$args["files"] = $files;
$args["matches"] = $matches;
}
return $this->render($file,["files" => $files,"matches" => $matches]);
}
return $this->render($file);
}
}