source: branches/version-2_13-dev/data/smarty_extends/function.html_checkboxes_ex.php @ 23605

Revision 23605, 5.0 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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 {html_checkboxes} function plugin
11 *
12 * File:       function.html_checkboxes.php<br>
13 * Type:       function<br>
14 * Name:       html_checkboxes<br>
15 * Date:       24.Feb.2003<br>
16 * Purpose:    Prints out a list of checkbox input types<br>
17 * Input:<br>
18 *           - name       (optional) - string default "checkbox"
19 *           - values     (required) - array
20 *           - options    (optional) - associative array
21 *           - checked    (optional) - array default not set
22 *           - separator  (optional) - ie <br> or &nbsp;
23 *           - output     (optional) - the output next to each checkbox
24 *           - assign     (optional) - assign the output as an array to this variable
25 * Examples:
26 * <pre>
27 * {html_checkboxes values=$ids output=$names}
28 * {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
29 * {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
30 * </pre>
31 * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
32 *      (Smarty online manual)
33 * @author     Christopher Kvarme <christopher.kvarme@flashjab.com>
34 * @author credits to Monte Ohrt <monte at ohrt dot com>
35 * @version    1.0
36 * @param array
37 * @param Smarty
38 * @return string
39 * @uses smarty_function_escape_special_chars()
40 */
41function smarty_function_html_checkboxes_ex($params, &$smarty)
42{
43    require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
44
45    $name = 'checkbox';
46    $values = null;
47    $options = null;
48    $selected = null;
49    $separator = '';
50    $labels = true;
51    $label_ids = true;
52    $output = null;
53
54    $extra = '';
55
56    foreach ($params as $_key => $_val) {
57        switch ($_key) {
58    case 'tags':
59    $$_key = split("\|", $_val);
60    break;
61            case 'name':
62            case 'separator':
63                $$_key = $_val;
64                break;
65
66            case 'labels':
67    case 'label_ids':
68                $$_key = (bool)$_val;
69                break;
70
71            case 'options':
72                $$_key = (array)$_val;
73                break;
74
75            case 'values':
76            case 'output':
77                $$_key = array_values((array)$_val);
78                break;
79
80            case 'checked':
81            case 'selected':
82                $selected = array_map('strval', array_values((array)$_val));
83                break;
84
85            case 'checkboxes':
86                $smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
87                $options = (array)$_val;
88                break;
89
90            case 'assign':
91                break;
92
93            default:
94                if (!is_array($_val)) {
95                    $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
96                } else {
97                    $smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
98                }
99                break;
100        }
101    }
102
103    if (!isset($options) && !isset($values))
104        return ''; /* raise error here? */
105
106    settype($selected, 'array');
107    $_html_result = array();
108
109    if (isset($options)) {
110        foreach ($options as $_key=>$_val)
111            $_html_result[] = smarty_function_html_checkboxes_output_ex($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $tags);
112    } else {
113        foreach ($values as $_i=>$_key) {
114            $_val = isset($output[$_i]) ? $output[$_i] : '';
115            $_html_result[] = smarty_function_html_checkboxes_output_ex($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $tags);
116        }
117
118    }
119
120    if (!empty($params['assign'])) {
121        $smarty->assign($params['assign'], $_html_result);
122    } else {
123        return implode("\n",$_html_result);
124    }
125}
126
127/**
128 * @param string $name
129 * @param string $extra
130 * @param string $separator
131 * @param boolean $labels
132 * @param boolean $label_ids
133 */
134function smarty_function_html_checkboxes_output_ex($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $tags)
135{
136    $_output = '';
137
138    $_output .= '<input type="checkbox" name="'
139        . smarty_function_escape_special_chars($name) . '[]" value="'
140        . smarty_function_escape_special_chars($value) . '"';
141
142    if ($labels && $label_ids) {
143    $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value));
144    $_output .= ' id="' . $_id . '"';
145    }
146
147    if (in_array((string)$value, $selected)) {
148        $_output .= ' checked="checked"';
149    }
150    $_output .= $extra . ' />';
151
152    $_output .= $tags[0];
153
154    if ($labels) {
155    if ($label_ids) {
156    $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value));
157    $_output .= '<label for="' . $_id . '">';
158    } else {
159    $_output .= '<label>';
160    }
161    }
162
163    // 値を挿入
164    $_output .= $output;
165
166    $_output .= $tags[1];
167
168    if ($labels) $_output .= '</label>';
169    $_output .=  $separator;
170
171    return $_output;
172}
Note: See TracBrowser for help on using the repository browser.