WPCF7_MailTaggedText

The Contact Form 7 WPCF7 MailTaggedText class.

Defined (1)

The class is defined in the following location(s).

/includes/mail.php  
  1. class WPCF7_MailTaggedText { 
  2.  
  3. private $html = false; 
  4. private $callback = null; 
  5. private $content = ''; 
  6. private $replaced_tags = array(); 
  7.  
  8. public function __construct( $content, $args = '' ) { 
  9. $args = wp_parse_args( $args, array( 
  10. 'html' => false,  
  11. 'callback' => null,  
  12. ) ); 
  13.  
  14. $this->html = (bool) $args['html']; 
  15.  
  16. if ( null !== $args['callback'] && is_callable( $args['callback'] ) ) { 
  17. $this->callback = $args['callback']; 
  18. } elseif ( $this->html ) { 
  19. $this->callback = array( $this, 'replace_tags_callback_html' ); 
  20. } else { 
  21. $this->callback = array( $this, 'replace_tags_callback' ); 
  22.  
  23. $this->content = $content; 
  24.  
  25. public function get_replaced_tags() { 
  26. return $this->replaced_tags; 
  27.  
  28. public function replace_tags() { 
  29. $regex = '/(\[?)\[[\t ]*' 
  30. . '([a-zA-Z_][0-9a-zA-Z:._-]*)' // [2] = name 
  31. . '((?:[\t ]+"[^"]*"|[\t ]+\'[^\']*\')*)' // [3] = values 
  32. . '[\t ]*\](\]?)/'; 
  33.  
  34. return preg_replace_callback( $regex, $this->callback, $this->content ); 
  35.  
  36. private function replace_tags_callback_html( $matches ) { 
  37. return $this->replace_tags_callback( $matches, true ); 
  38.  
  39. private function replace_tags_callback( $matches, $html = false ) { 
  40. // allow [[foo]] syntax for escaping a tag 
  41. if ( $matches[1] == '[' && $matches[4] == ']' ) { 
  42. return substr( $matches[0], 1, -1 ); 
  43.  
  44. $tag = $matches[0]; 
  45. $tagname = $matches[2]; 
  46. $values = $matches[3]; 
  47.  
  48. if ( ! empty( $values ) ) { 
  49. preg_match_all( '/"[^"]*"|\'[^\']*\'/', $values, $matches ); 
  50. $values = wpcf7_strip_quote_deep( $matches[0] ); 
  51.  
  52. $do_not_heat = false; 
  53.  
  54. if ( preg_match( '/^_raw_(.+)$/', $tagname, $matches ) ) { 
  55. $tagname = trim( $matches[1] ); 
  56. $do_not_heat = true; 
  57.  
  58. $format = ''; 
  59.  
  60. if ( preg_match( '/^_format_(.+)$/', $tagname, $matches ) ) { 
  61. $tagname = trim( $matches[1] ); 
  62. $format = $values[0]; 
  63.  
  64. $submission = WPCF7_Submission::get_instance(); 
  65. $submitted = $submission ? $submission->get_posted_data( $tagname ) : null; 
  66.  
  67. if ( null !== $submitted ) { 
  68.  
  69. if ( $do_not_heat ) { 
  70. $submitted = isset( $_POST[$tagname] ) ? $_POST[$tagname] : ''; 
  71.  
  72. $replaced = $submitted; 
  73.  
  74. if ( ! empty( $format ) ) { 
  75. $replaced = $this->format( $replaced, $format ); 
  76.  
  77. $replaced = wpcf7_flat_join( $replaced ); 
  78.  
  79. if ( $html ) { 
  80. $replaced = esc_html( $replaced ); 
  81. $replaced = wptexturize( $replaced ); 
  82.  
  83. $replaced = apply_filters( 'wpcf7_mail_tag_replaced',  
  84. $replaced, $submitted, $html ); 
  85.  
  86. $replaced = wp_unslash( trim( $replaced ) ); 
  87.  
  88. $this->replaced_tags[$tag] = $replaced; 
  89. return $replaced; 
  90.  
  91. $special = apply_filters( 'wpcf7_special_mail_tags', '', $tagname, $html ); 
  92.  
  93. if ( ! empty( $special ) ) { 
  94. $this->replaced_tags[$tag] = $special; 
  95. return $special; 
  96.  
  97. return $tag; 
  98.  
  99. public function format( $original, $format ) { 
  100. $original = (array) $original; 
  101.  
  102. foreach ( $original as $key => $value ) { 
  103. if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $value ) ) { 
  104. $original[$key] = mysql2date( $format, $value ); 
  105.  
  106. return $original;