source: branches/version-2_12-dev/data/smarty_extends/function.from_to.php @ 22567

Revision 22567, 1.7 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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 */
33function smarty_function_from_to($params, &$smarty)
34{
35    require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars');
36
37    $from = null;
38    $to = null;
39    $separator = ' ~ ';
40    $escape = true;
41
42    foreach ($params as $_key => $_val) {
43        switch ($_key) {
44            case 'from':
45            case 'to':
46            case 'separator':
47            case 'escape':
48                $$_key = (string) $_val;
49                break;
50
51            default:
52                $smarty->trigger_error("from_to: extra attribute '$_key' is unknown.", E_USER_NOTICE);
53                break;
54        }
55    }
56
57    if ($escape) {
58        $from = smarty_function_escape_special_chars($from);
59        $to   = smarty_function_escape_special_chars($to);
60    }
61
62    if ($from === $to) {
63        return $from;
64    } else {
65        return $from . $separator . $to;
66    }
67}
Note: See TracBrowser for help on using the repository browser.