public function edit(Application $app, Request $request, $id = null) { $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC); $PageLayout = $app['eccube.repository.page_layout']->findOrCreate($id, $DeviceType); $editable = true; $builder = $app['form.factory']->createBuilder('main_edit', $PageLayout); $event = new EventArgs(array('builder' => $builder, 'DeviceType' => $DeviceType, 'PageLayout' => $PageLayout), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_PAGE_EDIT_INITIALIZE, $event); $form = $builder->getForm(); // 更新時 $fileName = null; if ($id) { // 編集不可ページはURL、ページ名、ファイル名を保持 if ($PageLayout->getEditFlg() == PageLayout::EDIT_FLG_DEFAULT) { $editable = false; $PrevPageLayout = clone $PageLayout; } // テンプレートファイルの取得 $file = $app['eccube.repository.page_layout']->getReadTemplateFile($PageLayout->getFileName(), $editable); $form->get('tpl_data')->setData($file['tpl_data']); $fileName = $PageLayout->getFileName(); } if ('POST' === $app['request']->getMethod()) { $form->handleRequest($app['request']); if ($form->isValid()) { $PageLayout = $form->getData(); if (!$editable) { $PageLayout->setUrl($PrevPageLayout->getUrl())->setFileName($PrevPageLayout->getFileName())->setName($PrevPageLayout->getName()); } // DB登録 $app['orm.em']->persist($PageLayout); $app['orm.em']->flush(); // ファイル生成・更新 $templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath($editable); $filePath = $templatePath . '/' . $PageLayout->getFileName() . '.twig'; $fs = new Filesystem(); $pageData = $form->get('tpl_data')->getData(); $pageData = Str::convertLineFeed($pageData); $fs->dumpFile($filePath, $pageData); // 更新でファイル名を変更した場合、以前のファイルを削除 if ($PageLayout->getFileName() != $fileName && !is_null($fileName)) { $oldFilePath = $templatePath . '/' . $fileName . '.twig'; if ($fs->exists($oldFilePath)) { $fs->remove($oldFilePath); } } $event = new EventArgs(array('form' => $form, 'PageLayout' => $PageLayout, 'templatePath' => $templatePath, 'filePath' => $filePath), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_PAGE_EDIT_COMPLETE, $event); $app->addSuccess('admin.register.complete', 'admin'); // twig キャッシュの削除. $finder = Finder::create()->in($app['config']['root_dir'] . '/app/cache/twig'); $fs->remove($finder); return $app->redirect($app->url('admin_content_page_edit', array('id' => $PageLayout->getId()))); } } $templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath($editable); return $app->render('Content/page_edit.twig', array('form' => $form->createView(), 'page_id' => $PageLayout->getId(), 'editable' => $editable, 'template_path' => $templatePath)); }
public function edit(Application $app, Request $request, $id = null) { $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC); $Block = $app['eccube.repository.block']->findOrCreate($id, $DeviceType); if (!$Block) { throw new NotFoundHttpException(); } $builder = $app['form.factory']->createBuilder('block', $Block); $html = ''; $previous_filename = null; $deletable = $Block->getDeletableFlg(); if ($id) { // テンプレートファイルの取得 $previous_filename = $Block->getFileName(); $file = $app['eccube.repository.block']->getReadTemplateFile($previous_filename, $deletable); $html = $file['tpl_data']; } $event = new EventArgs(array('builder' => $builder, 'DeviceType' => $DeviceType, 'Block' => $Block, 'html' => $html), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_EDIT_INITIALIZE, $event); $html = $event->getArgument('html'); $form = $builder->getForm(); $form->get('block_html')->setData($html); if ($app['request']->getMethod() === 'POST') { $form->handleRequest($app['request']); if ($form->isValid()) { $Block = $form->getData(); // DB登録 $app['orm.em']->persist($Block); $app['orm.em']->flush(); // ファイル生成・更新 $tplDir = $app['config']['block_realdir']; $filePath = $tplDir . '/' . $Block->getFileName() . '.twig'; $fs = new Filesystem(); $blockData = $form->get('block_html')->getData(); $blockData = Str::convertLineFeed($blockData); $fs->dumpFile($filePath, $blockData); // 更新でファイル名を変更した場合、以前のファイルを削除 if ($Block->getFileName() != $previous_filename && !is_null($previous_filename)) { $oldFilePath = $tplDir . '/' . $previous_filename . '.twig'; if ($fs->exists($oldFilePath)) { $fs->remove($oldFilePath); } } \Eccube\Util\Cache::clear($app, false); $event = new EventArgs(array('form' => $form, 'Block' => $Block), $request); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_EDIT_COMPLETE, $event); $app->addSuccess('admin.register.complete', 'admin'); return $app->redirect($app->url('admin_content_block_edit', array('id' => $Block->getId()))); } } return $app->render('Content/block_edit.twig', array('form' => $form->createView(), 'block_id' => $id, 'deletable' => $deletable)); }
/** * アップロードされたCSVファイルの行ごとの処理 * * @param $formFile * @return CsvImportService */ protected function getImportData($app, $formFile) { // アップロードされたCSVファイルを一時ディレクトリに保存 $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension(); $formFile->move($app['config']['csv_temp_realdir'], $this->fileName); $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName); if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID >= 70000) { // Windows 環境の PHP7 の場合はファイルエンコーディングを CP932 に合わせる // see https://github.com/EC-CUBE/ec-cube/issues/1780 setlocale(LC_ALL, ''); // 既定のロケールに設定 if (mb_detect_encoding($file) === 'UTF-8') { // UTF-8 を検出したら SJIS-win に変換 $file = mb_convert_encoding($file, 'SJIS-win', 'UTF-8'); } } else { // アップロードされたファイルがUTF-8以外は文字コード変換を行う $encode = Str::characterEncoding(substr($file, 0, 6)); if ($encode != 'UTF-8') { $file = mb_convert_encoding($file, 'UTF-8', $encode); } } $file = Str::convertLineFeed($file); $tmp = tmpfile(); fwrite($tmp, $file); rewind($tmp); $meta = stream_get_meta_data($tmp); $file = new \SplFileObject($meta['uri']); set_time_limit(0); // アップロードされたCSVファイルを行ごとに取得 $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']); $ret = $data->setHeaderRowNumber(0); return $ret !== false ? $data : false; }
/** * アップロードされたCSVファイルの行ごとの処理 * * @param $formFile * @return CsvImportService */ protected function getImportData($app, $formFile) { // アップロードされたCSVファイルを一時ディレクトリに保存 $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension(); $formFile->move($app['config']['csv_temp_realdir'], $this->fileName); $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName); // アップロードされたファイルがUTF-8以外は文字コード変換を行う $encode = Str::characterEncoding(substr($file, 0, 6)); if ($encode != 'UTF-8') { $file = mb_convert_encoding($file, 'UTF-8', $encode); } $file = Str::convertLineFeed($file); $tmp = tmpfile(); fwrite($tmp, $file); rewind($tmp); $meta = stream_get_meta_data($tmp); $file = new \SplFileObject($meta['uri']); set_time_limit(0); // アップロードされたCSVファイルを行ごとに取得 $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']); $data->setHeaderRowNumber(0); return $data; }
private function createConfigYamlFile($data) { $fs = new Filesystem(); $config_file = $this->config_path . '/config.yml'; if ($fs->exists($config_file)) { $fs->remove($config_file); } $auth_magic = Str::random(32); $allowHost = Str::convertLineFeed($data['admin_allow_hosts']); if (empty($allowHost)) { $adminAllowHosts = array(); } else { $adminAllowHosts = explode("\n", $allowHost); } $target = array('${AUTH_MAGIC}', '${SHOP_NAME}', '${ECCUBE_INSTALL}', '${FORCE_SSL}'); $replace = array($auth_magic, $data['shop_name'], '0', $data['admin_force_ssl']); $fs = new Filesystem(); $content = str_replace($target, $replace, file_get_contents($this->dist_path . '/config.yml.dist')); $fs->dumpFile($config_file, $content); $config = Yaml::Parse($config_file); $config['admin_allow_host'] = $adminAllowHosts; $yml = Yaml::dump($config); file_put_contents($config_file, $yml); return $this; }
public function index(Application $app, Request $request) { $builder = $app['form.factory']->createBuilder('admin_security'); $form = $builder->getForm(); if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); // 現在のセキュリティ情報を更新 $adminRoot = $app['config']['admin_route']; $configFile = $app['config']['root_dir'] . '/app/config/eccube/config.yml'; $config = Yaml::parse(file_get_contents($configFile)); // trim処理 $allowHost = Str::convertLineFeed($data['admin_allow_host']); if (empty($allowHost)) { $config['admin_allow_host'] = null; } else { $config['admin_allow_host'] = explode("\n", $allowHost); } if ($data['force_ssl']) { // SSL制限にチェックをいれた場合、https経由で接続されたか確認 if ($request->isSecure()) { // httpsでアクセスされたらSSL制限をチェック $config['force_ssl'] = Constant::ENABLED; } else { // httpから変更されたらfalseのまま $config['force_ssl'] = Constant::DISABLED; $data['force_ssl'] = (bool) Constant::DISABLED; } } else { $config['force_ssl'] = Constant::DISABLED; } $form = $builder->getForm(); $form->setData($data); file_put_contents($configFile, Yaml::dump($config)); if ($adminRoot != $data['admin_route_dir']) { // admin_routeが変更されればpath.ymlを更新 $pathFile = $app['config']['root_dir'] . '/app/config/eccube/path.yml'; $config = Yaml::parse(file_get_contents($pathFile)); $config['admin_route'] = $data['admin_route_dir']; file_put_contents($pathFile, Yaml::dump($config)); $app->addSuccess('admin.system.security.route.dir.complete', 'admin'); // ログアウト $this->getSecurity($app)->setToken(null); // 管理者画面へ再ログイン return $app->redirect($request->getBaseUrl() . '/' . $config['admin_route']); } $app->addSuccess('admin.system.security.save.complete', 'admin'); } } else { // セキュリティ情報の取得 $form->get('admin_route_dir')->setData($app['config']['admin_route']); $allowHost = $app['config']['admin_allow_host']; if (count($allowHost) > 0) { $form->get('admin_allow_host')->setData(Str::convertLineFeed(implode("\n", $allowHost))); } $form->get('force_ssl')->setData((bool) $app['config']['force_ssl']); } return $app->render('Setting/System/security.twig', array('form' => $form->createView())); }
public function testConvertLineFeedWithEmpty() { $this->expected = ''; $this->actual = Str::convertLineFeed($this->expected); $this->assertEquals($this->expected, $this->actual); }
/** * 文字列の先頭から指定した文字数を切り出す * 改行コードは削除する。 * @param $text * @param int $count 切り出す文字数 * @return string */ public static function clipText($text, $count) { return Str::convertLineFeed(mb_substr($text, 0, $count, 'UTF-8'), ''); }