Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarty::addPluginsDir() は非推奨になったため、Smarty::registerPlugin() を使用するよう修正 #946

Merged
merged 10 commits into from
Jul 29, 2024
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
"classmap": [
"data/class",
"data/class_extends"
],
"files": [
"data/smarty_extends/function.from_to.php",
"data/smarty_extends/function.include_php_ex.php",
"data/smarty_extends/modifier.h.php",
"data/smarty_extends/modifier.n2s.php",
"data/smarty_extends/modifier.nl2br_html.php",
"data/smarty_extends/modifier.script_escape.php",
"data/smarty_extends/modifier.u.php"
]
}
}
9 changes: 8 additions & 1 deletion data/class/SC_View.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ public function init()
$this->_smarty->registerPlugin('modifier', 'sfMultiply', array('SC_Utils_Ex', 'sfMultiply'));
$this->_smarty->registerPlugin('modifier', 'sfRmDupSlash', array('SC_Utils_Ex', 'sfRmDupSlash'));
$this->_smarty->registerPlugin('modifier', 'sfCutString', array('SC_Utils_Ex', 'sfCutString'));
$this->_smarty->addPluginsDir(array('plugins', realpath(dirname(__FILE__)) . '/../smarty_extends'));
$this->_smarty->registerPlugin('function', 'from_to', 'smarty_function_from_to');
$this->_smarty->registerPlugin('function', 'include_php_ex', 'smarty_function_include_php_ex');
$this->_smarty->registerPlugin('modifier', 'h', 'smarty_modifier_h');
$this->_smarty->registerPlugin('modifier', 'n2s', 'smarty_modifier_n2s');
$this->_smarty->registerPlugin('modifier', 'nl2br_html', 'smarty_modifier_nl2br_html');
$this->_smarty->registerPlugin('modifier', 'script_escape', 'smarty_modifier_script_escape');
$this->_smarty->registerPlugin('modifier', 'u', 'smarty_modifier_u');
$this->_smarty->registerPlugin('modifier', 'sfMbConvertEncoding', array('SC_Utils_Ex', 'sfMbConvertEncoding'));
$this->_smarty->registerPlugin('modifier', 'sfGetEnabled', array('SC_Utils_Ex', 'sfGetEnabled'));
$this->_smarty->registerPlugin('modifier', 'sfNoImageMainList', array('SC_Utils_Ex', 'sfNoImageMainList'));
Expand All @@ -63,6 +69,7 @@ public function init()
$this->_smarty->registerPlugin('modifier', 'preg_quote', 'preg_quote');
$this->_smarty->registerPlugin('modifier', 'is_numeric', 'is_numeric');
$this->_smarty->registerPlugin('modifier', 'php_uname', 'php_uname');
$this->_smarty->registerPlugin('modifier', 'array_key_exists', 'array_key_exists');
// XXX register_function で登録すると if で使用できないのではないか?
$this->_smarty->registerPlugin('function','sfIsHTTPS', array('SC_Utils_Ex', 'sfIsHTTPS'));
$this->_smarty->registerPlugin('function','sfSetErrorStyle', array('SC_Utils_Ex', 'sfSetErrorStyle'));
Expand Down
45 changes: 45 additions & 0 deletions data/smarty_extends/README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data/class/SC_View.php への追記についても言及した方が良さそうに思いますが、いかがでしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。こちらも記載しておきますね

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seasoftjapan 対応しました!

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## このディレクトリのファイルは composer.json の autoload.classmap.files に登録することで利用可能です

1. [composer.json](../../composer.json) の autoload.classmap.files に登録します。

``` json
"autoload": {
"classmap": [
"data/class",
"data/class_extends"
],
"files": [
"data/smarty_extends/function.from_to.php",
"data/smarty_extends/function.include_php_ex.php",
"data/smarty_extends/modifier.h.php",
"data/smarty_extends/modifier.n2s.php",
"data/smarty_extends/modifier.nl2br_html.php",
"data/smarty_extends/modifier.script_escape.php",
"data/smarty_extends/modifier.u.php"
]
}
```
2. [SC_View.php](../class/SC_View.php) のコンストラクタに modifier を設定します。
```diff
--- a/data/class/SC_View.php
+++ b/data/class/SC_View.php
@@ -54,7 +54,13 @@ public function init()
$this->_smarty->registerPlugin('modifier', 'sfMultiply', array('SC_Utils_Ex', 'sfMultiply'));
$this->_smarty->registerPlugin('modifier', 'sfRmDupSlash', array('SC_Utils_Ex', 'sfRmDupSlash'));
$this->_smarty->registerPlugin('modifier', 'sfCutString', array('SC_Utils_Ex', 'sfCutString'));
- $this->_smarty->addPluginsDir(array('plugins', realpath(dirname(__FILE__)) . '/../smarty_extends'));
+ $this->_smarty->registerPlugin('function', 'from_to', 'smarty_function_from_to');
+ $this->_smarty->registerPlugin('function', 'include_php_ex', 'smarty_function_include_php_ex');
+ $this->_smarty->registerPlugin('modifier', 'h', 'smarty_modifier_h');
+ $this->_smarty->registerPlugin('modifier', 'n2s', 'smarty_modifier_n2s');
+ $this->_smarty->registerPlugin('modifier', 'nl2br_html', 'smarty_modifier_nl2br_html');
+ $this->_smarty->registerPlugin('modifier', 'script_escape', 'smarty_modifier_script_escape');
+ $this->_smarty->registerPlugin('modifier', 'u', 'smarty_modifier_u');
$this->_smarty->registerPlugin('modifier', 'sfMbConvertEncoding', array('SC_Utils_Ex', 'sfMbConvertEncoding'));
$this->_smarty->registerPlugin('modifier', 'sfGetEnabled', array('SC_Utils_Ex', 'sfGetEnabled'));
$this->_smarty->registerPlugin('modifier', 'sfNoImageMainList', array('SC_Utils_Ex', 'sfNoImageMainList'));
```
3. composer dump-autoload コマンドを実行することで autoload の対象となります。
``` shell
composer dump-autoload
```
1 change: 1 addition & 0 deletions data/smarty_extends/block.marquee.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* marqueeタグで囲む。
*
* @deprecated mobile テンプレートは廃止されたため非推奨
* DoCoMoの携帯端末の場合はmarqueeを使用しない。
*
* @return string 出力
Expand Down
1 change: 1 addition & 0 deletions data/smarty_extends/modifier.numeric_emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* 数値を数字絵文字に変換する。
*
* @deprecated mobile テンプレートは廃止されたため非推奨
* 入力が0~9ではない場合、または、携帯端末からのアクセスではない場合は、
* 入力を [ と ] で囲んだ文字列を返す。
*
Expand Down
1 change: 0 additions & 1 deletion tests/class/modifier/Modifier_ScriptEscapeTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
require 'data/smarty_extends/modifier.script_escape.php';

/**
* (省略。アノテーションを認識されるのに必要なようなので記述している。)
Expand Down
Loading