/deprecated/includes/fields/textarea.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. function ninja_forms_register_field_textarea() { 
  3. $args = array( 
  4. 'name' => __( 'Textarea', 'ninja-forms' ),  
  5. 'sidebar' => 'template_fields',  
  6. 'edit_function' => '',  
  7. 'edit_options' => array( 
  8. array( 
  9. 'type' => 'textarea',  
  10. 'name' => 'default_value',  
  11. 'label' => __( 'Default Value', 'ninja-forms' ),  
  12. 'width' => 'wide',  
  13. 'class' => 'widefat',  
  14. ),  
  15. array( 
  16. 'type' => 'checkbox',  
  17. 'name' => 'textarea_rte',  
  18. 'label' => __( 'Show Rich Text Editor', 'ninja-forms' ),  
  19. ),  
  20. array( 
  21. 'type' => 'checkbox',  
  22. 'name' => 'textarea_media',  
  23. 'label' => __( 'Show Media Upload Button', 'ninja-forms' ),  
  24. ),  
  25. array( 
  26. 'type' => 'checkbox',  
  27. 'name' => 'disable_rte_mobile',  
  28. 'label' => __( 'Disable Rich Text Editor on Mobile', 'ninja-forms' ),  
  29. ),  
  30. ),  
  31. 'display_function' => 'ninja_forms_field_textarea_display',  
  32. 'save_function' => '',  
  33. 'group' => 'standard_fields',  
  34. 'edit_label' => true,  
  35. 'edit_label_pos' => true,  
  36. 'edit_req' => true,  
  37. 'edit_custom_class' => true,  
  38. 'edit_help' => true,  
  39. 'edit_desc' => true,  
  40. 'edit_meta' => false,  
  41. 'edit_conditional' => true,  
  42. 'conditional' => array( 
  43. 'value' => array( 
  44. 'type' => 'textarea',  
  45. ),  
  46. ),  
  47. 'edit_sub_value' => 'nf_field_textarea_edit_sub_value',  
  48. 'pre_process' => 'nf_field_textarea_pre_process',  
  49. ); 
  50.  
  51. ninja_forms_register_field('_textarea', $args); 
  52.  
  53. add_action('init', 'ninja_forms_register_field_textarea'); 
  54.  
  55. function ninja_forms_field_textarea_display( $field_id, $data, $form_id = '' ) { 
  56. if(isset($data['default_value'])) { 
  57. $default_value = $data['default_value']; 
  58. }else{ 
  59. $default_value = ''; 
  60.  
  61. $default_value = htmlspecialchars_decode( $default_value ); 
  62.  
  63. if(isset($data['textarea_rte'])) { 
  64. $textarea_rte = $data['textarea_rte']; 
  65. }else{ 
  66. $textarea_rte = 0; 
  67.  
  68. if( isset ( $data['textarea_media'] ) AND $data['textarea_media'] == 1 ) { 
  69. $textarea_media = true; 
  70. }else{ 
  71. $textarea_media = false; 
  72.  
  73. if ( isset( $data['disable_rte_mobile'] ) AND 1 == $data['disable_rte_mobile'] AND wp_is_mobile() ) { 
  74. $textarea_rte = 0; 
  75.  
  76. if( isset( $data['input_limit'] ) ) { 
  77. $input_limit = $data['input_limit']; 
  78. }else{ 
  79. $input_limit = ''; 
  80.  
  81. if( isset( $data['input_limit_type'] ) ) { 
  82. $input_limit_type = $data['input_limit_type']; 
  83. }else{ 
  84. $input_limit_type = ''; 
  85.  
  86. if( isset( $data['input_limit_msg'] ) ) { 
  87. $input_limit_msg = $data['input_limit_msg']; 
  88. }else{ 
  89. $input_limit_msg = ''; 
  90.  
  91. $field_class = ninja_forms_get_field_class( $field_id, $form_id ); 
  92.  
  93. $default_value = filter_var( $default_value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ); 
  94. $default_value = filter_var( $default_value, FILTER_SANITIZE_SPECIAL_CHARS ); 
  95.  
  96. if($textarea_rte == 1) { 
  97. $settings = array( 'media_buttons' => $textarea_media ); 
  98. $args = apply_filters( 'ninja_forms_textarea_rte', $settings ); 
  99. wp_editor( $default_value, 'ninja_forms_field_'.$field_id, $args ); 
  100. }else{ 
  101. ?> 
  102. <textarea name="ninja_forms_field_<?php echo $field_id;?>" id="ninja_forms_field_<?php echo $field_id;?>" class="<?php echo $field_class;?>" rel="<?php echo $field_id;?>" data-input-limit="<?php echo $input_limit;?>" data-input-limit-type="<?php echo $input_limit_type;?>" data-input-limit-msg="<?php echo $input_limit_msg;?>"><?php echo $default_value;?></textarea> 
  103. <?php 
  104.  
  105. /** 
  106. * Edit submission value output function 
  107. * 
  108. * @since 2.7 
  109. * @return void 
  110. */ 
  111. function nf_field_textarea_edit_sub_value( $field_id, $user_value ) { 
  112. ?> 
  113. <textarea name="fields[<?php echo $field_id; ?>]"><?php echo $user_value; ?></textarea> 
  114. <?php 
  115.  
  116. /** 
  117. * Make sure we strip nested script tags from our values 
  118. * 
  119. * @since 2.9.19 
  120. * @return void 
  121. */ 
  122. function nf_field_textarea_pre_process( $field_id, $user_value ) { 
  123. global $ninja_forms_processing; 
  124.  
  125. if( is_string( $user_value ) ) { 
  126. while (false !== strpos($user_value, '<script') 
  127. || false !== strpos($user_value, '<script') 
  128. || false !== strpos($user_value, '</script') 
  129. || false !== strpos($user_value, '</script') 
  130. || false !== strpos($user_value, '<textarea') 
  131. || false !== strpos($user_value, '<textarea') 
  132. || false !== strpos($user_value, '</textarea') 
  133. || false !== strpos($user_value, '</textarea') 
  134. ) { 
  135.  
  136. $user_value = str_replace('<script', '', $user_value); 
  137. $user_value = str_replace('<script', '', $user_value); 
  138. $user_value = str_replace('</script', '', $user_value); 
  139. $user_value = str_replace('</script', '', $user_value); 
  140.  
  141. $user_value = str_replace('<textarea', '', $user_value); 
  142. $user_value = str_replace('<textarea', '', $user_value); 
  143. $user_value = str_replace('</textarea', '', $user_value); 
  144. $user_value = str_replace('</textarea', '', $user_value); 
  145.  
  146. $ninja_forms_processing->update_field_value( $field_id, $user_value ); 
.