app/Plugin/TabaCMS2/Util/Util.php line 27

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\TabaCMS2\Util;
  9. use Eccube\Common\EccubeConfig;
  10. use Plugin\TabaCMS2\Common\Constants;
  11. use Psr\Container\ContainerInterface;
  12. abstract class Util
  13. {
  14.     /**
  15.      * テンプレートのファイルパスを取得します。
  16.      * EC-CUBE4.1の場合は@で参照するパスを返却します。
  17.      * 第4引数の $pathFLg を true に設定した場合、EC-CUBE4.1であっても物理パスで返却します。
  18.      *
  19.      * @param string $file_name
  20.      * @param array $data_keys
  21.      * @param ContainerInterface $container
  22.      * @param boolean $pathFLg
  23.      * @return string
  24.      */
  25.     public static function getTemplatePath($file_name$data_keys = array(), EccubeConfig $eccubeConfig,$pathFLg false)
  26.     {
  27.         $template_list = array();
  28.         $dir_list = array();
  29.         // テンプレートコード
  30.         $themeCode $eccubeConfig['eccube_theme_code'];
  31.         // テンプレートディレクトリ
  32.         $pluginDataTemplateDir $eccubeConfig['plugin_data_realdir'] . DIRECTORY_SEPARATOR Constants::PLUGIN_CODE DIRECTORY_SEPARATOR 'template';
  33.         $pluginTemplateDir $eccubeConfig['plugin_realdir'] . DIRECTORY_SEPARATOR Constants::TEMPLATE_PATH;
  34.         $templatePluginDir null;
  35.         // ディレクトリリスト生成
  36.         $dir_list[] = 'default';
  37.         if ($themeCode != 'default') {
  38.             $dir_list[] = $themeCode;
  39.         }
  40.         $templatePluginDir $eccubeConfig['eccube_theme_front_dir'] . DIRECTORY_SEPARATOR "Plugin" DIRECTORY_SEPARATOR Constants::PLUGIN_CODE;
  41.         foreach ($dir_list as $dir) {
  42.             $template_list[] = $pluginTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR $file_name;
  43.             if ($templatePluginDir$template_list[] = $templatePluginDir DIRECTORY_SEPARATOR $file_name;
  44.             $template_list[] = $pluginDataTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR $file_name;
  45.             foreach ($data_keys as $data_key) {
  46.                 $template_list[] = $pluginTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR str_replace('.twig''_' $data_key '.twig'$file_name);
  47.                 if ($templatePluginDir$template_list[] = $templatePluginDir DIRECTORY_SEPARATOR str_replace('.twig''_' $data_key '.twig'$file_name);
  48.                 $template_list[] = $pluginDataTemplateDir DIRECTORY_SEPARATOR $dir DIRECTORY_SEPARATOR str_replace('.twig''_' $data_key '.twig'$file_name);
  49.             }
  50.         }
  51.         $template_count count($template_list) - 1;
  52.         for ($i 0$i <= $template_count$i ++) {
  53.             $template_list[$template_count $i];
  54.             if (($template_path $template_list[$template_count $i]) && file_exists($template_path)) {
  55.                 // EC-CUBE 4.2のみ
  56.                 if (!$pathFLg) {
  57.                     // プラグインディレクトリ
  58.                     if (strpos($template_path,$pluginTemplateDir) === 0) {
  59.                         return str_replace($pluginTemplateDir,'@' Constants::PLUGIN_CODE,$template_path);
  60.                     }
  61.                     // プラグインデータディレクトリ
  62.                     elseif (strpos($template_path,$pluginDataTemplateDir) === 0) {
  63.                         return str_replace($pluginDataTemplateDir,'@PluginData/' Constants::PLUGIN_CODE '/template',$template_path);
  64.                     }
  65.                     // テンプレートディレクトリ
  66.                     elseif (strpos($template_path,$templatePluginDir) === 0) {
  67.                         return str_replace($templatePluginDir,'Plugin/' Constants::PLUGIN_CODE,$template_path);
  68.                     }
  69.                 }
  70.                 return $template_path;
  71.             }
  72.         }
  73.         return Constants::TEMPLATE_PATH '/default/' $file_name;
  74.     }
  75.     public static function removeTag($html,$tag) {
  76.         $html preg_replace('/< *'.$tag.'\b[^>]*>(.*?)< *\/ *'.$tag.'*>/is',"$1"$html);
  77.         return preg_replace('/< *'.$tag.'\b[^>]*>/is',"$1"$html);
  78.     }
  79.     public static function removeJS($html)
  80.     {
  81.         $html preg_replace('/< *script\b[^>]*>(.*?)< *\/ *script *>/is'""$html);
  82.         $event_list = array(
  83.             "onBlur",
  84.             "onFocus",
  85.             "onChange",
  86.             "onSelect",
  87.             "onSelectStart",
  88.             "onSubmit",
  89.             "onReset",
  90.             "onAbort",
  91.             "onError",
  92.             "onLoad",
  93.             "onUnload",
  94.             "onClick",
  95.             "onDblClick",
  96.             "onKeyUp",
  97.             "onKeyDown",
  98.             "onKeyPress",
  99.             "onMouseOut",
  100.             "onMouseOver",
  101.             "onMouseUp",
  102.             "onMouseDown",
  103.             "onMouseMove",
  104.             "onDragDrop"
  105.         );
  106.         foreach ($event_list as $event) {
  107.             // $html = preg_replace('/' . $event . ' *= *[\"\'][^\"\']+[\"\']/is',"",$html);
  108.             // $html = preg_replace('/' . $event . '[ \r\n]*=[ \r\n]*[\"\'][^\"\']*[\"\']/is',"",$html);
  109.             $html preg_replace('/' $event '[\s\r\n]*=[\s\r\n]*\"[^\"]*\"/is'""$html);
  110.             $html preg_replace('/' $event "[\s\r\n]*=[\s\r\n]*\'[^\']*\'/is"""$html);
  111.         }
  112.         return $html;
  113.     }
  114. }