app/Plugin/TabaBannerManager2/Util/Util.php line 25

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
  4.  *
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Plugin\TabaBannerManager2\Util;
  9. use Eccube\Common\EccubeConfig;
  10. use Plugin\TabaBannerManager2\Common\Constants;
  11. use Psr\Container\ContainerInterface;
  12. abstract class Util
  13. {
  14.     /**
  15.      * テンプレートのファイルパスを取得します。
  16.      *
  17.      * @param string $file_name
  18.      * @param array $data_keys
  19.      * @param ContainerInterface $container
  20.      * @return string
  21.      */
  22.     public static function getTemplatePath($file_name$data_keys = array(),EccubeConfig $eccubeConfig)
  23.     {
  24.         $template_list = array();
  25.         $dir_list = array();
  26.         // テンプレートコード
  27.         $themeCode $eccubeConfig['eccube_theme_code'];
  28.         // テンプレートディレクトリ
  29.         $pluginDataTemplateDir $eccubeConfig['plugin_data_realdir'] . DIRECTORY_SEPARATOR Constants::PLUGIN_CODE DIRECTORY_SEPARATOR 'template';
  30.         $pluginTemplateDir $eccubeConfig['plugin_realdir'] . DIRECTORY_SEPARATOR Constants::TEMPLATE_PATH;
  31.         $templatePluginDir null;
  32.         // ディレクトリリスト生成
  33.         $dir_list[] = 'default';
  34.         if ($themeCode != 'default') {
  35.             $dir_list[] = $themeCode;
  36.         }
  37.         $templatePluginDir $eccubeConfig['eccube_theme_front_dir'] . DIRECTORY_SEPARATOR "Plugin" DIRECTORY_SEPARATOR Constants::PLUGIN_CODE;
  38.         foreach ($dir_list as $dir) {
  39.             $template_list[] = $pluginTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR $file_name;
  40.             if ($templatePluginDir$template_list[] = $templatePluginDir DIRECTORY_SEPARATOR $file_name;
  41.             $template_list[] = $pluginDataTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR $file_name;
  42.             foreach ($data_keys as $data_key) {
  43.                 $template_list[] = $pluginTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR str_replace('.twig''_' $data_key '.twig'$file_name);
  44.                 if ($templatePluginDir$template_list[] = $templatePluginDir DIRECTORY_SEPARATOR str_replace('.twig''_' $data_key '.twig'$file_name);
  45.                 $template_list[] = $pluginDataTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR str_replace('.twig''_' $data_key '.twig'$file_name);
  46.             }
  47.         }
  48.         
  49.         $template_count count($template_list) - 1;
  50.         for ($i 0$i <= $template_count$i ++) {
  51.             $template_list[$template_count $i];
  52.             if (($template_path $template_list[$template_count $i]) && file_exists($template_path)) {
  53.                 // EC-CUBE 4.2のみ
  54.                 // プラグインディレクトリ
  55.                 if (strpos($template_path,$pluginTemplateDir) === 0) {
  56.                     return str_replace($pluginTemplateDir,'@' Constants::PLUGIN_CODE,$template_path);
  57.                 }
  58.                 // プラグインデータディレクトリ
  59.                 elseif (strpos($template_path,$pluginDataTemplateDir) === 0) {
  60.                     return str_replace($pluginDataTemplateDir,'@PluginData/' Constants::PLUGIN_CODE '/template',$template_path);
  61.                 }
  62.                 // テンプレートディレクトリ
  63.                 elseif (strpos($template_path,$templatePluginDir) === 0) {
  64.                     return str_replace($templatePluginDir,'Plugin/' Constants::PLUGIN_CODE,$template_path);
  65.                 }
  66.             }
  67.             // return $template_path;
  68.         }
  69.         return Constants::TEMPLATE_PATH '/default/' $file_name;
  70.     }
  71. }