PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/add-ons/smarty/plugins/function.html_text.php

https://github.com/jcplat/console-seolan
PHP | 134 lines | 89 code | 17 blank | 28 comment | 8 complexity | 6d94a6e09dabb228b1db1780332bd567 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage actindo_plugins
  6. */
  7. /**
  8. * Smarty {html_text} function plugin
  9. *
  10. * File: function.html_text.php<br>
  11. * Type: function<br>
  12. * Name: html_text<br>
  13. * Date: 29.Nov.2005<br>
  14. * Purpose: Prints out a input type=text<br>
  15. * Input:<br>
  16. * - name (required) - string
  17. * - type (optional) - string default "text"
  18. * - class (optional) - string default "txt"
  19. * - size (optional) - int default 30
  20. * - maxlength (optional) - int default not set
  21. * - value (optional) - int, get from assigned variables by default
  22. * - image (optional) - URL for image in textfield (size should be 16x16)
  23. * @author Patrick Prasse <pprasse@actindo.de>
  24. * @version $Revision: 1.5 $
  25. * @param array
  26. * @param Smarty
  27. * @return string
  28. * @uses smarty_function_escape_special_chars()
  29. */
  30. function smarty_function_html_text($params, &$smarty)
  31. {
  32. global $_smarty_pp_autocomplete_js_output;
  33. require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
  34. require_once $smarty->_get_plugin_filepath('shared','get_var');
  35. $name = '';
  36. $type = 'text';
  37. $class = 'txt';
  38. $size = 30;
  39. $value = null;
  40. $default = null;
  41. $extra = null;
  42. $pp_autocomplete = 0;
  43. foreach($params as $_key => $_val) {
  44. switch(strtolower($_key)) {
  45. case 'extra':
  46. case 'name':
  47. case 'type':
  48. case 'value':
  49. case 'class':
  50. case 'default':
  51. $$_key = $_val;
  52. break;
  53. case 'onkeyup':
  54. $onKeyUp = trim( $_val );
  55. break;
  56. case 'onkeydown':
  57. $onKeyDown = trim( $_val );
  58. break;
  59. case 'onkeypress':
  60. $onKeyPress = trim( $_val );
  61. break;
  62. case 'onblur':
  63. $onBlur = trim( $_val );
  64. break;
  65. case 'acurl':
  66. $acURL = trim( $_val );
  67. break;
  68. case 'size':
  69. case 'pp_autocomplete':
  70. case 'disabled':
  71. $$_key = (int)$_val;
  72. break;
  73. case 'image':
  74. $extra .= ' style="background-image: url('.$_val.'); background-repeat: no-repeat; background-position: 0px 1px; padding-left: 18px;"';
  75. break;
  76. default:
  77. if(!is_array($_val)) {
  78. $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
  79. } else {
  80. $smarty->trigger_error("html_select: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
  81. }
  82. break;
  83. }
  84. }
  85. if( $disabled )
  86. $extra .= ' disabled="disabled"';
  87. if( !isset($value) )
  88. {
  89. $value = smarty_function_get_var( $name, $smarty );
  90. if( is_null($value) )
  91. $value = $default;
  92. }
  93. $_html_result = '';
  94. if( $pp_autocomplete )
  95. {
  96. if( !$_smarty_pp_autocomplete_js_output )
  97. {
  98. require_once $smarty->_get_plugin_filepath('block','javascript');
  99. $_html_result .= '<script language="JavaScript" type="text/javascript" src="fetch.php?mod=main&what=autocomplete.js"></script>';
  100. $_smarty_pp_autocomplete_js_output = TRUE;
  101. }
  102. $onBlur = (!empty($onBlur)?$onBlur.';':'')."ac_blur(this);";
  103. $onKeyUp = "autocomplete(this,event,'keyup');".$onKeyUp;
  104. $onKeyDown = "autocomplete(this,event,'keydown');".$onKeyDown;
  105. $onKeyPress = "autocomplete(this,event,'keypress');".$onKeyPress;
  106. $_html_result .= "\n".smarty_block_javascript( array(), "ac_fields[ac_fields.length] = '{$name}';\n", $smarty );
  107. $extra .= ' autocomplete="off"';
  108. }
  109. foreach( compact('onBlur','onKeyUp','onKeyDown','onKeyPress','acURL') as $n => $v )
  110. {
  111. if( !is_null($v) )
  112. $extra .= sprintf( " %s=\"%s\"", $n, smarty_function_escape_special_chars($v) );
  113. }
  114. $_html_result .= '<input type="'.$type.'" class="'.$class.'" name="'.smarty_function_escape_special_chars($name).'" value="'.smarty_function_escape_special_chars($value).'" size="'.$size.'" '.$extra.'>';
  115. return $_html_result;
  116. }
  117. ?>