/htdocs/wp-content/plugins/wordpress-seo/admin/views/tool-file-editor.php

https://gitlab.com/VTTE/sitios-vtte · PHP · 239 lines · 193 code · 24 blank · 22 comment · 31 complexity · d876486a49aef7d7604ca0c7cb1dd6e6 MD5 · raw file

  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. if ( ! defined( 'WPSEO_VERSION' ) ) {
  8. header( 'Status: 403 Forbidden' );
  9. header( 'HTTP/1.1 403 Forbidden' );
  10. exit();
  11. }
  12. $yform = Yoast_Form::get_instance();
  13. $robots_file = get_home_path() . 'robots.txt';
  14. $ht_access_file = get_home_path() . '.htaccess';
  15. if ( isset( $_POST['create_robots'] ) ) {
  16. if ( ! current_user_can( 'edit_files' ) ) {
  17. $die_msg = sprintf(
  18. /* translators: %s expands to robots.txt. */
  19. __( 'You cannot create a %s file.', 'wordpress-seo' ),
  20. 'robots.txt'
  21. );
  22. die( esc_html( $die_msg ) );
  23. }
  24. check_admin_referer( 'wpseo_create_robots' );
  25. ob_start();
  26. error_reporting( 0 );
  27. do_robots();
  28. $robots_content = ob_get_clean();
  29. $f = fopen( $robots_file, 'x' );
  30. fwrite( $f, $robots_content );
  31. }
  32. if ( isset( $_POST['submitrobots'] ) ) {
  33. if ( ! current_user_can( 'edit_files' ) ) {
  34. $die_msg = sprintf(
  35. /* translators: %s expands to robots.txt. */
  36. __( 'You cannot edit the %s file.', 'wordpress-seo' ),
  37. 'robots.txt'
  38. );
  39. die( esc_html( $die_msg ) );
  40. }
  41. check_admin_referer( 'wpseo-robotstxt' );
  42. if ( isset( $_POST['robotsnew'] ) && file_exists( $robots_file ) ) {
  43. $robotsnew = sanitize_textarea_field( wp_unslash( $_POST['robotsnew'] ) );
  44. if ( is_writable( $robots_file ) ) {
  45. $f = fopen( $robots_file, 'w+' );
  46. fwrite( $f, $robotsnew );
  47. fclose( $f );
  48. $msg = sprintf(
  49. /* translators: %s expands to robots.txt. */
  50. __( 'Updated %s', 'wordpress-seo' ),
  51. 'robots.txt'
  52. );
  53. }
  54. }
  55. }
  56. if ( isset( $_POST['submithtaccess'] ) ) {
  57. if ( ! current_user_can( 'edit_files' ) ) {
  58. $die_msg = sprintf(
  59. /* translators: %s expands to ".htaccess". */
  60. __( 'You cannot edit the %s file.', 'wordpress-seo' ),
  61. '.htaccess'
  62. );
  63. die( esc_html( $die_msg ) );
  64. }
  65. check_admin_referer( 'wpseo-htaccess' );
  66. if ( isset( $_POST['htaccessnew'] ) && file_exists( $ht_access_file ) ) {
  67. // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Writing to .htaccess file and escaping for HTML will break functionality.
  68. $ht_access_new = wp_unslash( $_POST['htaccessnew'] );
  69. if ( is_writable( $ht_access_file ) ) {
  70. $f = fopen( $ht_access_file, 'w+' );
  71. fwrite( $f, $ht_access_new );
  72. fclose( $f );
  73. }
  74. }
  75. }
  76. if ( is_multisite() ) {
  77. $action_url = network_admin_url( 'admin.php?page=wpseo_files' );
  78. $yform->admin_header( false, 'wpseo_ms' );
  79. }
  80. else {
  81. $action_url = admin_url( 'admin.php?page=wpseo_tools&tool=file-editor' );
  82. }
  83. if ( isset( $msg ) && ! empty( $msg ) ) {
  84. echo '<div id="message" class="notice notice-success"><p>', esc_html( $msg ), '</p></div>';
  85. }
  86. // N.B.: "robots.txt" is a fixed file name and should not be translatable.
  87. echo '<h2>robots.txt</h2>';
  88. if ( ! file_exists( $robots_file ) ) {
  89. if ( is_writable( get_home_path() ) ) {
  90. echo '<form action="', esc_url( $action_url ), '" method="post" id="robotstxtcreateform">';
  91. wp_nonce_field( 'wpseo_create_robots', '_wpnonce', true, true );
  92. echo '<p>';
  93. printf(
  94. /* translators: %s expands to robots.txt. */
  95. esc_html__( 'You don\'t have a %s file, create one here:', 'wordpress-seo' ),
  96. 'robots.txt'
  97. );
  98. echo '</p>';
  99. printf(
  100. '<input type="submit" class="button" name="create_robots" value="%s">',
  101. sprintf(
  102. /* translators: %s expands to robots.txt. */
  103. esc_attr__( 'Create %s file', 'wordpress-seo' ),
  104. 'robots.txt'
  105. )
  106. );
  107. echo '</form>';
  108. }
  109. else {
  110. echo '<p>';
  111. printf(
  112. /* translators: %s expands to robots.txt. */
  113. esc_html__( 'If you had a %s file and it was editable, you could edit it from here.', 'wordpress-seo' ),
  114. 'robots.txt'
  115. );
  116. echo '</p>';
  117. }
  118. }
  119. else {
  120. $f = fopen( $robots_file, 'r' );
  121. $content = '';
  122. if ( filesize( $robots_file ) > 0 ) {
  123. $content = fread( $f, filesize( $robots_file ) );
  124. }
  125. if ( ! is_writable( $robots_file ) ) {
  126. echo '<p><em>';
  127. printf(
  128. /* translators: %s expands to robots.txt. */
  129. esc_html__( 'If your %s were writable, you could edit it from here.', 'wordpress-seo' ),
  130. 'robots.txt'
  131. );
  132. echo '</em></p>';
  133. echo '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">', esc_textarea( $content ), '</textarea><br/>';
  134. }
  135. else {
  136. echo '<form action="', esc_url( $action_url ), '" method="post" id="robotstxtform">';
  137. wp_nonce_field( 'wpseo-robotstxt', '_wpnonce', true, true );
  138. echo '<label for="robotsnew" class="yoast-inline-label">';
  139. printf(
  140. /* translators: %s expands to robots.txt. */
  141. esc_html__( 'Edit the content of your %s:', 'wordpress-seo' ),
  142. 'robots.txt'
  143. );
  144. echo '</label>';
  145. echo '<textarea class="large-text code" rows="15" name="robotsnew" id="robotsnew">', esc_textarea( $content ), '</textarea><br/>';
  146. printf(
  147. '<div class="submit"><input class="button" type="submit" name="submitrobots" value="%s" /></div>',
  148. sprintf(
  149. /* translators: %s expands to robots.txt. */
  150. esc_attr__( 'Save changes to %s', 'wordpress-seo' ),
  151. 'robots.txt'
  152. )
  153. );
  154. echo '</form>';
  155. }
  156. }
  157. if ( ! WPSEO_Utils::is_nginx() ) {
  158. echo '<h2>';
  159. printf(
  160. /* translators: %s expands to ".htaccess". */
  161. esc_html__( '%s file', 'wordpress-seo' ),
  162. '.htaccess'
  163. );
  164. echo '</h2>';
  165. if ( file_exists( $ht_access_file ) ) {
  166. $f = fopen( $ht_access_file, 'r' );
  167. $contentht = '';
  168. if ( filesize( $ht_access_file ) > 0 ) {
  169. $contentht = fread( $f, filesize( $ht_access_file ) );
  170. }
  171. if ( ! is_writable( $ht_access_file ) ) {
  172. echo '<p><em>';
  173. printf(
  174. /* translators: %s expands to ".htaccess". */
  175. esc_html__( 'If your %s were writable, you could edit it from here.', 'wordpress-seo' ),
  176. '.htaccess'
  177. );
  178. echo '</em></p>';
  179. echo '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">', esc_textarea( $contentht ), '</textarea><br/>';
  180. }
  181. else {
  182. echo '<form action="', esc_url( $action_url ), '" method="post" id="htaccessform">';
  183. wp_nonce_field( 'wpseo-htaccess', '_wpnonce', true, true );
  184. echo '<label for="htaccessnew" class="yoast-inline-label">';
  185. printf(
  186. /* translators: %s expands to ".htaccess". */
  187. esc_html__( 'Edit the content of your %s:', 'wordpress-seo' ),
  188. '.htaccess'
  189. );
  190. echo '</label>';
  191. echo '<textarea class="large-text code" rows="15" name="htaccessnew" id="htaccessnew">', esc_textarea( $contentht ), '</textarea><br/>';
  192. printf(
  193. '<div class="submit"><input class="button" type="submit" name="submithtaccess" value="%s" /></div>',
  194. sprintf(
  195. /* translators: %s expands to ".htaccess". */
  196. esc_attr__( 'Save changes to %s', 'wordpress-seo' ),
  197. '.htaccess'
  198. )
  199. );
  200. echo '</form>';
  201. }
  202. }
  203. else {
  204. echo '<p>';
  205. printf(
  206. /* translators: %s expands to ".htaccess". */
  207. esc_html__( 'If you had a %s file and it was editable, you could edit it from here.', 'wordpress-seo' ),
  208. '.htaccess'
  209. );
  210. echo '</p>';
  211. }
  212. }
  213. if ( is_multisite() ) {
  214. $yform->admin_footer( false );
  215. }