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

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