1: <?php
2: /**
3: *
4: * @package Legacy
5: * @version $Id: function.xoops_input.php,v 1.3 2008/09/25 15:12:36 kilica Exp $
6: * @copyright Copyright 2005-2007 XOOPS Cube Project <https://github.com/xoopscube/legacy>
7: * @license https://github.com/xoopscube/legacy/blob/master/docs/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
8: *
9: * [ToDo]
10: * 1) We may have to move this file to other module with following namespace or
11: * package.
12: * 2) This function accepts all of <input> pattern. We may have to divide it.
13: * 3) Some users and developers want free elements at $params. For example,
14: * $params['script']... This function have not impletented that yet. At
15: * implementing, we will have to define the rule about sanitizing.
16: *
17: */
18:
19: /*
20: * Smarty plugin
21: * -------------------------------------------------------------
22: * Type: function
23: * Name: xoops_input
24: * Version: 1.0
25: * Date: Nov 2, 2005
26: * Author: minahito
27: * Purpose: input tag with sanitize.
28: * Input: name = name of form 'name'
29: * key = key of the name. If this parameter is array, set it.
30: * type = "text" or other
31: * value = preset value
32: * class = form 'class'.
33: * id = form 'id'. If it's empty, ID is defined automatically by prefix & name.
34: * size = size element.
35: * maxlength = maxlength element.
36: * default = If it equals 'value', add "checked" element in the case of "select" or "radio".
37: * disabled = disabled element.
38: *
39: * Examples: {xoops_input name=text value=$message}
40: * {xoops_input name=checkbox value=1 default=$value }
41: * -------------------------------------------------------------
42: */
43:
44: define ('XOOPS_INPUT_DEFID_PREFIX', 'legacy_xoopsform_');
45:
46: function smarty_function_xoops_input($params, &$smarty)
47: {
48: if (isset($params['name'])) {
49: //
50: // Fetch major elements from $params.
51: //
52: static $textFilter;
53: if (!isset($textFilter)) {
54: $root =& XCube_Root::getSingleton();
55: $textFilter = $root->getTextFilter();
56: }
57: $name = trim($params['name']);
58: $key = isset($params['key']) ? trim($params['key']) : null;
59: $type = isset($params['type']) ? strtolower(trim($params['type'])) : 'text';
60: $value = isset($params['value']) ? $textFilter->toEdit($params['value']) : null;
61: $class = isset($params['class']) ? trim($params['class']) : null;
62: $style = isset($params['style']) ? trim($params['style']) : null;
63: $id = isset($params['id']) ? trim($params['id']) : XOOPS_INPUT_DEFID_PREFIX . $name;
64: $size = isset($params['size']) ? (int)$params['size'] : null;
65: $maxlength = isset($params['maxlength']) ? (int)$params['maxlength'] : null;
66: $default = isset($params['default']) ? trim($params['default']) : null;
67:
68: $disabled = (isset($params['disabled']) && $params['disabled']) ? true : false;
69:
70: //
71: // Build string.
72: //
73: if ($key != null) {
74: $string = '<input name="'.$name."[$key]\"";
75: }
76: else {
77: $string = "<input name=\"$name\"";
78: }
79:
80: if ($class) {
81: $string .= " class=\"$class\"";
82: }
83:
84: if ($style) {
85: $string .= " style=\"$style\"";
86: }
87:
88: if ($type == 'checkbox' || $type == 'radio') {
89: $string .= ' id="'.$id.'_'.$value.'"';
90: }else {
91: $string .= " id=\"$id\"";
92: }
93:
94: if ($type) {
95: $string .= " type=\"$type\"";
96: }
97:
98: if ($size) {
99: $string .= " size=\"$size\"";
100: }
101:
102: if($maxlength) {
103: $string .= " maxlength=\"$maxlength\"";
104: }
105:
106: if($value !== null) {
107: $string .= " value=\"$value\"";
108: }
109:
110: if (isset($params['default'])) {
111: $default = trim($params['default']);
112: if ($value == $default) {
113: if ($type == 'checkbox' || $type == 'radio') {
114: $string .= ' checked="checked"';
115: }
116: }
117: }
118:
119: if ($disabled) {
120: $string .= ' disabled="disabled"';
121: }
122:
123: $string .= ' />';
124:
125: //
126: // Output.
127: //
128: print $string;
129: }
130: }
131:
132: ?>
133: