PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/contact-form-7/modules/text.php

https://gitlab.com/oxidigitaluser/liguelista
PHP | 307 lines | 235 code | 61 blank | 11 comment | 61 complexity | 49ff76d05a551e8f09eff45dab89ce3c MD5 | raw file
  1. <?php
  2. /**
  3. ** A base module for the following types of tags:
  4. ** [text] and [text*] # Single-line text
  5. ** [email] and [email*] # Email address
  6. ** [url] and [url*] # URL
  7. ** [tel] and [tel*] # Telephone number
  8. **/
  9. /* Shortcode handler */
  10. add_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );
  11. function wpcf7_add_shortcode_text() {
  12. wpcf7_add_shortcode(
  13. array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
  14. 'wpcf7_text_shortcode_handler', true );
  15. }
  16. function wpcf7_text_shortcode_handler( $tag ) {
  17. $tag = new WPCF7_Shortcode( $tag );
  18. if ( empty( $tag->name ) )
  19. return '';
  20. $validation_error = wpcf7_get_validation_error( $tag->name );
  21. $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' );
  22. if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) )
  23. $class .= ' wpcf7-validates-as-' . $tag->basetype;
  24. if ( $validation_error )
  25. $class .= ' wpcf7-not-valid';
  26. $atts = array();
  27. $atts['size'] = $tag->get_size_option( '40' );
  28. $atts['maxlength'] = $tag->get_maxlength_option();
  29. $atts['minlength'] = $tag->get_minlength_option();
  30. if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) {
  31. unset( $atts['maxlength'], $atts['minlength'] );
  32. }
  33. $atts['class'] = $tag->get_class_option( $class );
  34. $atts['id'] = $tag->get_id_option();
  35. $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
  36. if ( $tag->has_option( 'readonly' ) )
  37. $atts['readonly'] = 'readonly';
  38. if ( $tag->is_required() )
  39. $atts['aria-required'] = 'true';
  40. $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
  41. $value = (string) reset( $tag->values );
  42. if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
  43. $atts['placeholder'] = $value;
  44. $value = '';
  45. }
  46. $value = $tag->get_default_option( $value );
  47. $value = wpcf7_get_hangover( $tag->name, $value );
  48. $atts['value'] = $value;
  49. if ( wpcf7_support_html5() ) {
  50. $atts['type'] = $tag->basetype;
  51. } else {
  52. $atts['type'] = 'text';
  53. }
  54. $atts['name'] = $tag->name;
  55. $atts = wpcf7_format_atts( $atts );
  56. $html = sprintf(
  57. '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
  58. sanitize_html_class( $tag->name ), $atts, $validation_error );
  59. return $html;
  60. }
  61. /* Validation filter */
  62. add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 );
  63. add_filter( 'wpcf7_validate_text*', 'wpcf7_text_validation_filter', 10, 2 );
  64. add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
  65. add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 );
  66. add_filter( 'wpcf7_validate_url', 'wpcf7_text_validation_filter', 10, 2 );
  67. add_filter( 'wpcf7_validate_url*', 'wpcf7_text_validation_filter', 10, 2 );
  68. add_filter( 'wpcf7_validate_tel', 'wpcf7_text_validation_filter', 10, 2 );
  69. add_filter( 'wpcf7_validate_tel*', 'wpcf7_text_validation_filter', 10, 2 );
  70. function wpcf7_text_validation_filter( $result, $tag ) {
  71. $tag = new WPCF7_Shortcode( $tag );
  72. $name = $tag->name;
  73. $value = isset( $_POST[$name] )
  74. ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) )
  75. : '';
  76. if ( 'text' == $tag->basetype ) {
  77. if ( $tag->is_required() && '' == $value ) {
  78. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
  79. }
  80. }
  81. if ( 'email' == $tag->basetype ) {
  82. if ( $tag->is_required() && '' == $value ) {
  83. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
  84. } elseif ( '' != $value && ! wpcf7_is_email( $value ) ) {
  85. $result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) );
  86. }
  87. }
  88. if ( 'url' == $tag->basetype ) {
  89. if ( $tag->is_required() && '' == $value ) {
  90. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
  91. } elseif ( '' != $value && ! wpcf7_is_url( $value ) ) {
  92. $result->invalidate( $tag, wpcf7_get_message( 'invalid_url' ) );
  93. }
  94. }
  95. if ( 'tel' == $tag->basetype ) {
  96. if ( $tag->is_required() && '' == $value ) {
  97. $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
  98. } elseif ( '' != $value && ! wpcf7_is_tel( $value ) ) {
  99. $result->invalidate( $tag, wpcf7_get_message( 'invalid_tel' ) );
  100. }
  101. }
  102. if ( ! empty( $value ) ) {
  103. $maxlength = $tag->get_maxlength_option();
  104. $minlength = $tag->get_minlength_option();
  105. if ( $maxlength && $minlength && $maxlength < $minlength ) {
  106. $maxlength = $minlength = null;
  107. }
  108. $code_units = wpcf7_count_code_units( $value );
  109. if ( false !== $code_units ) {
  110. if ( $maxlength && $maxlength < $code_units ) {
  111. $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
  112. } elseif ( $minlength && $code_units < $minlength ) {
  113. $result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
  114. }
  115. }
  116. }
  117. return $result;
  118. }
  119. /* Messages */
  120. add_filter( 'wpcf7_messages', 'wpcf7_text_messages' );
  121. function wpcf7_text_messages( $messages ) {
  122. return array_merge( $messages, array(
  123. 'invalid_email' => array(
  124. 'description' => __( "Email address that the sender entered is invalid", 'contact-form-7' ),
  125. 'default' => __( 'Email address seems invalid.', 'contact-form-7' )
  126. ),
  127. 'invalid_url' => array(
  128. 'description' => __( "URL that the sender entered is invalid", 'contact-form-7' ),
  129. 'default' => __( 'URL seems invalid.', 'contact-form-7' )
  130. ),
  131. 'invalid_tel' => array(
  132. 'description' => __( "Telephone number that the sender entered is invalid", 'contact-form-7' ),
  133. 'default' => __( 'Telephone number seems invalid.', 'contact-form-7' )
  134. ) ) );
  135. }
  136. /* Tag generator */
  137. if ( is_admin() ) {
  138. add_action( 'admin_init', 'wpcf7_add_tag_generator_text', 15 );
  139. }
  140. function wpcf7_add_tag_generator_text() {
  141. $tag_generator = WPCF7_TagGenerator::get_instance();
  142. $tag_generator->add( 'text', __( 'text', 'contact-form-7' ),
  143. 'wpcf7_tag_generator_text' );
  144. $tag_generator->add( 'email', __( 'email', 'contact-form-7' ),
  145. 'wpcf7_tag_generator_text' );
  146. $tag_generator->add( 'url', __( 'URL', 'contact-form-7' ),
  147. 'wpcf7_tag_generator_text' );
  148. $tag_generator->add( 'tel', __( 'tel', 'contact-form-7' ),
  149. 'wpcf7_tag_generator_text' );
  150. }
  151. function wpcf7_tag_generator_text( $contact_form, $args = '' ) {
  152. $args = wp_parse_args( $args, array() );
  153. $type = $args['id'];
  154. if ( ! in_array( $type, array( 'email', 'url', 'tel' ) ) ) {
  155. $type = 'text';
  156. }
  157. if ( 'text' == $type ) {
  158. $description = __( "Generate a form-tag for a single-line plain text input field. For more details, see %s.", 'contact-form-7' );
  159. } elseif ( 'email' == $type ) {
  160. $description = __( "Generate a form-tag for a single-line email address input field. For more details, see %s.", 'contact-form-7' );
  161. } elseif ( 'url' == $type ) {
  162. $description = __( "Generate a form-tag for a single-line URL input field. For more details, see %s.", 'contact-form-7' );
  163. } elseif ( 'tel' == $type ) {
  164. $description = __( "Generate a form-tag for a single-line telephone number input field. For more details, see %s.", 'contact-form-7' );
  165. }
  166. $desc_link = wpcf7_link( __( 'http://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text Fields', 'contact-form-7' ) );
  167. ?>
  168. <div class="control-box">
  169. <fieldset>
  170. <legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
  171. <table class="form-table">
  172. <tbody>
  173. <tr>
  174. <th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
  175. <td>
  176. <fieldset>
  177. <legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
  178. <label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
  179. </fieldset>
  180. </td>
  181. </tr>
  182. <tr>
  183. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
  184. <td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
  185. </tr>
  186. <tr>
  187. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
  188. <td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
  189. <label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
  190. </tr>
  191. <?php if ( in_array( $type, array( 'text', 'email', 'url' ) ) ) : ?>
  192. <tr>
  193. <th scope="row"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></th>
  194. <td>
  195. <fieldset>
  196. <legend class="screen-reader-text"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></legend>
  197. <?php if ( 'text' == $type ) : ?>
  198. <label>
  199. <input type="checkbox" name="akismet:author" class="option" />
  200. <?php echo esc_html( __( "This field requires author's name", 'contact-form-7' ) ); ?>
  201. </label>
  202. <?php elseif ( 'email' == $type ) : ?>
  203. <label>
  204. <input type="checkbox" name="akismet:author_email" class="option" />
  205. <?php echo esc_html( __( "This field requires author's email address", 'contact-form-7' ) ); ?>
  206. </label>
  207. <?php elseif ( 'url' == $type ) : ?>
  208. <label>
  209. <input type="checkbox" name="akismet:author_url" class="option" />
  210. <?php echo esc_html( __( "This field requires author's URL", 'contact-form-7' ) ); ?>
  211. </label>
  212. <?php endif; ?>
  213. </fieldset>
  214. </td>
  215. </tr>
  216. <?php endif; ?>
  217. <tr>
  218. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
  219. <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
  220. </tr>
  221. <tr>
  222. <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
  223. <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
  224. </tr>
  225. </tbody>
  226. </table>
  227. </fieldset>
  228. </div>
  229. <div class="insert-box">
  230. <input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
  231. <div class="submitbox">
  232. <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
  233. </div>
  234. <br class="clear" />
  235. <p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
  236. </div>
  237. <?php
  238. }