<?php
/*
* Copyright (C) SPREAD WORKS Inc. All Rights Reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\TabaBannerManager2\Util;
use Eccube\Common\EccubeConfig;
use Plugin\TabaBannerManager2\Common\Constants;
use Psr\Container\ContainerInterface;
abstract class Util
{
/**
* テンプレートのファイルパスを取得します。
*
* @param string $file_name
* @param array $data_keys
* @param ContainerInterface $container
* @return string
*/
public static function getTemplatePath($file_name, $data_keys = array(),EccubeConfig $eccubeConfig)
{
$template_list = array();
$dir_list = array();
// テンプレートコード
$themeCode = $eccubeConfig['eccube_theme_code'];
// テンプレートディレクトリ
$pluginDataTemplateDir = $eccubeConfig['plugin_data_realdir'] . DIRECTORY_SEPARATOR . Constants::PLUGIN_CODE . DIRECTORY_SEPARATOR . 'template';
$pluginTemplateDir = $eccubeConfig['plugin_realdir'] . DIRECTORY_SEPARATOR . Constants::TEMPLATE_PATH;
$templatePluginDir = null;
// ディレクトリリスト生成
$dir_list[] = 'default';
if ($themeCode != 'default') {
$dir_list[] = $themeCode;
}
$templatePluginDir = $eccubeConfig['eccube_theme_front_dir'] . DIRECTORY_SEPARATOR . "Plugin" . DIRECTORY_SEPARATOR . Constants::PLUGIN_CODE;
foreach ($dir_list as $dir) {
$template_list[] = $pluginTemplateDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file_name;
if ($templatePluginDir) $template_list[] = $templatePluginDir . DIRECTORY_SEPARATOR . $file_name;
$template_list[] = $pluginDataTemplateDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $file_name;
foreach ($data_keys as $data_key) {
$template_list[] = $pluginTemplateDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . str_replace('.twig', '_' . $data_key . '.twig', $file_name);
if ($templatePluginDir) $template_list[] = $templatePluginDir . DIRECTORY_SEPARATOR . str_replace('.twig', '_' . $data_key . '.twig', $file_name);
$template_list[] = $pluginDataTemplateDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . str_replace('.twig', '_' . $data_key . '.twig', $file_name);
}
}
$template_count = count($template_list) - 1;
for ($i = 0; $i <= $template_count; $i ++) {
$template_list[$template_count - $i];
if (($template_path = $template_list[$template_count - $i]) && file_exists($template_path)) {
// EC-CUBE 4.2のみ
// プラグインディレクトリ
if (strpos($template_path,$pluginTemplateDir) === 0) {
return str_replace($pluginTemplateDir,'@' . Constants::PLUGIN_CODE,$template_path);
}
// プラグインデータディレクトリ
elseif (strpos($template_path,$pluginDataTemplateDir) === 0) {
return str_replace($pluginDataTemplateDir,'@PluginData/' . Constants::PLUGIN_CODE . '/template',$template_path);
}
// テンプレートディレクトリ
elseif (strpos($template_path,$templatePluginDir) === 0) {
return str_replace($templatePluginDir,'Plugin/' . Constants::PLUGIN_CODE,$template_path);
}
}
// return $template_path;
}
return Constants::TEMPLATE_PATH . '/default/' . $file_name;
}
}