| Revision 21526,
1.7 KB
checked in by Seasoft, 14 years ago
(diff) |
|
#1613 (ソース整形・ソースコメントの改善)
- Zend Framework PHP 標準コーディング規約への準拠を高めた。(主に「Switch」の項)
|
-
Property svn:eol-style set to
LF
-
Property svn:keywords set to
Id
-
Property svn:mime-type set to
text/x-httpd-php; charset=UTF-8
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Smarty plugin |
|---|
| 4 | * @package Smarty |
|---|
| 5 | * @subpackage plugins |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * Smarty {from_to} function plugin |
|---|
| 11 | * |
|---|
| 12 | * Type: function<br> |
|---|
| 13 | * Name: from_to<br> |
|---|
| 14 | * Date: 2008/09/07<br> |
|---|
| 15 | * Input: |
|---|
| 16 | * <pre> |
|---|
| 17 | * - from (required) - string |
|---|
| 18 | * - to (required) - string |
|---|
| 19 | * - separator (optional) - string default " ~ ". ie "-", "~<br />". 常にエスケープせずに出力するので注意. |
|---|
| 20 | * - escape (optional) - string default true. other false. エスケープするか否か。 |
|---|
| 21 | * </pre> |
|---|
| 22 | * Examples: |
|---|
| 23 | * <pre> |
|---|
| 24 | * {html_radios from="-1" to="2"} → -1 ~ 2 |
|---|
| 25 | * {html_radios from="B" to="a" separator="~<br />"} → B~<br />a |
|---|
| 26 | * </pre> |
|---|
| 27 | * @author Seasoft 塚田将久 |
|---|
| 28 | * @param array |
|---|
| 29 | * @param Smarty |
|---|
| 30 | * @return string |
|---|
| 31 | * @uses smarty_function_escape_special_chars() |
|---|
| 32 | */ |
|---|
| 33 | function smarty_function_from_to($params, &$smarty) { |
|---|
| 34 | require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars'); |
|---|
| 35 | |
|---|
| 36 | $from = null; |
|---|
| 37 | $to = null; |
|---|
| 38 | $separator = ' ~ '; |
|---|
| 39 | $escape = true; |
|---|
| 40 | |
|---|
| 41 | foreach ($params as $_key => $_val) { |
|---|
| 42 | switch ($_key) { |
|---|
| 43 | case 'from': |
|---|
| 44 | case 'to': |
|---|
| 45 | case 'separator': |
|---|
| 46 | case 'escape': |
|---|
| 47 | $$_key = (string) $_val; |
|---|
| 48 | break; |
|---|
| 49 | |
|---|
| 50 | default: |
|---|
| 51 | $smarty->trigger_error("from_to: extra attribute '$_key' is unknown.", E_USER_NOTICE); |
|---|
| 52 | break; |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if ($escape) { |
|---|
| 57 | $from = smarty_function_escape_special_chars($from); |
|---|
| 58 | $to = smarty_function_escape_special_chars($to); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if ($from === $to) { |
|---|
| 62 | return $from; |
|---|
| 63 | } else { |
|---|
| 64 | return $from . $separator . $to; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.