1: <?php
2: /**
3: *
4: * @package Legacy
5: * @version $Id: function.xoops_textarea.php,v 1.3 2008/09/25 15:12:35 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: * [ToDo]
11: * 1) We may have to move this file to other module with following namespace or
12: * package.
13: * 2) 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_textarea
24: * Version: 1.0
25: * Date: Nov 2, 2005
26: * Author: minahito
27: * Purpose: textarea tag with sanitize.
28: * Input: name = form 'name'.
29: * value = preset value. Set raw value without htmlspecialchars().
30: * class = form 'class'.
31: * id = form 'id'. If it's empty, ID is defined automatically by prefix & name.
32: * cols = amount of cols. (default 50)
33: * rows = amount of rows. (default 5)
34: * readonly = if it's true, textarea becomes readonly.
35: *
36: * Examples: {xoops_textarea name=message cols=40 rows=6 value=$message}
37: * -------------------------------------------------------------
38: */
39:
40: define ('XOOPS_TEXTAREA_DEFID_PREFIX', 'legacy_xoopsform_');
41: define ('XOOPS_TEXTAREA_DEFAULT_COLS', '50');
42: define ('XOOPS_TEXTAREA_DEFAULT_ROWS', '5');
43:
44: function smarty_function_xoops_textarea($params, &$smarty)
45: {
46: static $textFilter;
47: if (!isset($textFilter)) {
48: $root =& XCube_Root::getSingleton();
49: $textFilter = $root->getTextFilter();
50: }
51: if (isset($params['name'])) {
52: //
53: // Fetch major elements from $params.
54: //
55: $name = trim($params['name']);
56: $class = isset($params['class']) ? trim($params['class']) : null;
57: $style = isset($params['style']) ? trim($params['style']) : null;
58: $cols = isset($params['cols']) ? intval($params['cols']) : XOOPS_TEXTAREA_DEFAULT_COLS;
59: $rows = isset($params['rows']) ? intval($params['rows']) : XOOPS_TEXTAREA_DEFAULT_ROWS;
60: $value = isset($params['value']) ? $textFilter->toEdit($params['value']) : null;
61: $id = isset($params['id']) ? trim($params['id']) : XOOPS_TEXTAREA_DEFID_PREFIX . $name;
62: $readonly = isset($params['readonly']) ? (bool)(trim($params['readonly'])) : false;
63:
64: //
65: // Build string.
66: //
67: $string = "<textarea name=\"$name\" cols=\"$cols\" rows=\"$rows\"";
68:
69: if ($class) {
70: $string .= " class=\"$class\"";
71: }
72:
73: if ($style) {
74: $string .= " style=\"$style\"";
75: }
76:
77: $string .= " id=\"$id\"";
78:
79: if($readonly) {
80: $string .= ' readonly="readonly"';
81: }
82:
83: $string .= '>' . $value . '</textarea>';
84:
85: //
86: // Output.
87: //
88: print $string;
89: }
90: }
91:
92: ?>
93: