editor.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. class WPCF7_Editor {
  3. private $contact_form;
  4. private $panels = array();
  5. public function __construct( WPCF7_ContactForm $contact_form ) {
  6. $this->contact_form = $contact_form;
  7. }
  8. public function add_panel( $id, $title, $callback ) {
  9. if ( wpcf7_is_name( $id ) ) {
  10. $this->panels[$id] = array(
  11. 'title' => $title,
  12. 'callback' => $callback,
  13. );
  14. }
  15. }
  16. public function display() {
  17. if ( empty( $this->panels ) ) {
  18. return;
  19. }
  20. echo '<ul id="contact-form-editor-tabs">';
  21. foreach ( $this->panels as $id => $panel ) {
  22. echo sprintf( '<li id="%1$s-tab"><a href="#%1$s">%2$s</a></li>',
  23. esc_attr( $id ), esc_html( $panel['title'] ) );
  24. }
  25. echo '</ul>';
  26. foreach ( $this->panels as $id => $panel ) {
  27. echo sprintf( '<div class="contact-form-editor-panel" id="%1$s">',
  28. esc_attr( $id ) );
  29. if ( is_callable( $panel['callback'] ) ) {
  30. $this->notice( $id, $panel );
  31. call_user_func( $panel['callback'], $this->contact_form );
  32. }
  33. echo '</div>';
  34. }
  35. }
  36. public function notice( $id, $panel ) {
  37. echo '<div class="config-error"></div>';
  38. }
  39. }
  40. function wpcf7_editor_panel_form( $post ) {
  41. $desc_link = wpcf7_link(
  42. __( 'https://contactform7.com/editing-form-template/', 'contact-form-7' ),
  43. __( 'Editing Form Template', 'contact-form-7' ) );
  44. $description = __( "You can edit the form template here. For details, see %s.", 'contact-form-7' );
  45. $description = sprintf( esc_html( $description ), $desc_link );
  46. ?>
  47. <h2><?php echo esc_html( __( 'Form', 'contact-form-7' ) ); ?></h2>
  48. <fieldset>
  49. <legend><?php echo $description; ?></legend>
  50. <?php
  51. $tag_generator = WPCF7_TagGenerator::get_instance();
  52. $tag_generator->print_buttons();
  53. ?>
  54. <textarea id="wpcf7-form" name="wpcf7-form" cols="100" rows="24" class="large-text code" data-config-field="form.body"><?php echo esc_textarea( $post->prop( 'form' ) ); ?></textarea>
  55. </fieldset>
  56. <?php
  57. }
  58. function wpcf7_editor_panel_mail( $post ) {
  59. wpcf7_editor_box_mail( $post );
  60. echo '<br class="clear" />';
  61. wpcf7_editor_box_mail( $post, array(
  62. 'id' => 'wpcf7-mail-2',
  63. 'name' => 'mail_2',
  64. 'title' => __( 'Mail (2)', 'contact-form-7' ),
  65. 'use' => __( 'Use Mail (2)', 'contact-form-7' ),
  66. ) );
  67. }
  68. function wpcf7_editor_box_mail( $post, $args = '' ) {
  69. $args = wp_parse_args( $args, array(
  70. 'id' => 'wpcf7-mail',
  71. 'name' => 'mail',
  72. 'title' => __( 'Mail', 'contact-form-7' ),
  73. 'use' => null,
  74. ) );
  75. $id = esc_attr( $args['id'] );
  76. $mail = wp_parse_args( $post->prop( $args['name'] ), array(
  77. 'active' => false,
  78. 'recipient' => '',
  79. 'sender' => '',
  80. 'subject' => '',
  81. 'body' => '',
  82. 'additional_headers' => '',
  83. 'attachments' => '',
  84. 'use_html' => false,
  85. 'exclude_blank' => false,
  86. ) );
  87. ?>
  88. <div class="contact-form-editor-box-mail" id="<?php echo $id; ?>">
  89. <h2><?php echo esc_html( $args['title'] ); ?></h2>
  90. <?php
  91. if ( ! empty( $args['use'] ) ) :
  92. ?>
  93. <label for="<?php echo $id; ?>-active"><input type="checkbox" id="<?php echo $id; ?>-active" name="<?php echo $id; ?>[active]" class="toggle-form-table" value="1"<?php echo ( $mail['active'] ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( $args['use'] ); ?></label>
  94. <p class="description"><?php echo esc_html( __( "Mail (2) is an additional mail template often used as an autoresponder.", 'contact-form-7' ) ); ?></p>
  95. <?php
  96. endif;
  97. ?>
  98. <fieldset>
  99. <legend>
  100. <?php
  101. $desc_link = wpcf7_link(
  102. __( 'https://contactform7.com/setting-up-mail/', 'contact-form-7' ),
  103. __( 'Setting Up Mail', 'contact-form-7' ) );
  104. $description = __( "You can edit the mail template here. For details, see %s.", 'contact-form-7' );
  105. $description = sprintf( esc_html( $description ), $desc_link );
  106. echo $description;
  107. echo '<br />';
  108. echo esc_html( __( "In the following fields, you can use these mail-tags:",
  109. 'contact-form-7' ) );
  110. echo '<br />';
  111. $post->suggest_mail_tags( $args['name'] );
  112. ?>
  113. </legend>
  114. <table class="form-table">
  115. <tbody>
  116. <tr>
  117. <th scope="row">
  118. <label for="<?php echo $id; ?>-recipient"><?php echo esc_html( __( 'To', 'contact-form-7' ) ); ?></label>
  119. </th>
  120. <td>
  121. <input type="text" id="<?php echo $id; ?>-recipient" name="<?php echo $id; ?>[recipient]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['recipient'] ); ?>" data-config-field="<?php echo sprintf( '%s.recipient', esc_attr( $args['name'] ) ); ?>" />
  122. </td>
  123. </tr>
  124. <tr>
  125. <th scope="row">
  126. <label for="<?php echo $id; ?>-sender"><?php echo esc_html( __( 'From', 'contact-form-7' ) ); ?></label>
  127. </th>
  128. <td>
  129. <input type="text" id="<?php echo $id; ?>-sender" name="<?php echo $id; ?>[sender]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['sender'] ); ?>" data-config-field="<?php echo sprintf( '%s.sender', esc_attr( $args['name'] ) ); ?>" />
  130. </td>
  131. </tr>
  132. <tr>
  133. <th scope="row">
  134. <label for="<?php echo $id; ?>-subject"><?php echo esc_html( __( 'Subject', 'contact-form-7' ) ); ?></label>
  135. </th>
  136. <td>
  137. <input type="text" id="<?php echo $id; ?>-subject" name="<?php echo $id; ?>[subject]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['subject'] ); ?>" data-config-field="<?php echo sprintf( '%s.subject', esc_attr( $args['name'] ) ); ?>" />
  138. </td>
  139. </tr>
  140. <tr>
  141. <th scope="row">
  142. <label for="<?php echo $id; ?>-additional-headers"><?php echo esc_html( __( 'Additional Headers', 'contact-form-7' ) ); ?></label>
  143. </th>
  144. <td>
  145. <textarea id="<?php echo $id; ?>-additional-headers" name="<?php echo $id; ?>[additional_headers]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.additional_headers', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['additional_headers'] ); ?></textarea>
  146. </td>
  147. </tr>
  148. <tr>
  149. <th scope="row">
  150. <label for="<?php echo $id; ?>-body"><?php echo esc_html( __( 'Message Body', 'contact-form-7' ) ); ?></label>
  151. </th>
  152. <td>
  153. <textarea id="<?php echo $id; ?>-body" name="<?php echo $id; ?>[body]" cols="100" rows="18" class="large-text code" data-config-field="<?php echo sprintf( '%s.body', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['body'] ); ?></textarea>
  154. <p><label for="<?php echo $id; ?>-exclude-blank"><input type="checkbox" id="<?php echo $id; ?>-exclude-blank" name="<?php echo $id; ?>[exclude_blank]" value="1"<?php echo ( ! empty( $mail['exclude_blank'] ) ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( __( 'Exclude lines with blank mail-tags from output', 'contact-form-7' ) ); ?></label></p>
  155. <p><label for="<?php echo $id; ?>-use-html"><input type="checkbox" id="<?php echo $id; ?>-use-html" name="<?php echo $id; ?>[use_html]" value="1"<?php echo ( $mail['use_html'] ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( __( 'Use HTML content type', 'contact-form-7' ) ); ?></label></p>
  156. </td>
  157. </tr>
  158. <tr>
  159. <th scope="row">
  160. <label for="<?php echo $id; ?>-attachments"><?php echo esc_html( __( 'File Attachments', 'contact-form-7' ) ); ?></label>
  161. </th>
  162. <td>
  163. <textarea id="<?php echo $id; ?>-attachments" name="<?php echo $id; ?>[attachments]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.attachments', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['attachments'] ); ?></textarea>
  164. </td>
  165. </tr>
  166. </tbody>
  167. </table>
  168. </fieldset>
  169. </div>
  170. <?php
  171. }
  172. function wpcf7_editor_panel_messages( $post ) {
  173. $desc_link = wpcf7_link(
  174. __( 'https://contactform7.com/editing-messages/', 'contact-form-7' ),
  175. __( 'Editing Messages', 'contact-form-7' ) );
  176. $description = __( "You can edit messages used in various situations here. For details, see %s.", 'contact-form-7' );
  177. $description = sprintf( esc_html( $description ), $desc_link );
  178. $messages = wpcf7_messages();
  179. if ( isset( $messages['captcha_not_match'] )
  180. and ! wpcf7_use_really_simple_captcha() ) {
  181. unset( $messages['captcha_not_match'] );
  182. }
  183. ?>
  184. <h2><?php echo esc_html( __( 'Messages', 'contact-form-7' ) ); ?></h2>
  185. <fieldset>
  186. <legend><?php echo $description; ?></legend>
  187. <?php
  188. foreach ( $messages as $key => $arr ) {
  189. $field_id = sprintf( 'wpcf7-message-%s', strtr( $key, '_', '-' ) );
  190. $field_name = sprintf( 'wpcf7-messages[%s]', $key );
  191. ?>
  192. <p class="description">
  193. <label for="<?php echo $field_id; ?>"><?php echo esc_html( $arr['description'] ); ?><br />
  194. <input type="text" id="<?php echo $field_id; ?>" name="<?php echo $field_name; ?>" class="large-text" size="70" value="<?php echo esc_attr( $post->message( $key, false ) ); ?>" data-config-field="<?php echo sprintf( 'messages.%s', esc_attr( $key ) ); ?>" />
  195. </label>
  196. </p>
  197. <?php
  198. }
  199. ?>
  200. </fieldset>
  201. <?php
  202. }
  203. function wpcf7_editor_panel_additional_settings( $post ) {
  204. $desc_link = wpcf7_link(
  205. __( 'https://contactform7.com/additional-settings/', 'contact-form-7' ),
  206. __( 'Additional Settings', 'contact-form-7' ) );
  207. $description = __( "You can add customization code snippets here. For details, see %s.", 'contact-form-7' );
  208. $description = sprintf( esc_html( $description ), $desc_link );
  209. ?>
  210. <h2><?php echo esc_html( __( 'Additional Settings', 'contact-form-7' ) ); ?></h2>
  211. <fieldset>
  212. <legend><?php echo $description; ?></legend>
  213. <textarea id="wpcf7-additional-settings" name="wpcf7-additional-settings" cols="100" rows="8" class="large-text" data-config-field="additional_settings.body"><?php echo esc_textarea( $post->prop( 'additional_settings' ) ); ?></textarea>
  214. </fieldset>
  215. <?php
  216. }