PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/hop23typhu/list-theme
PHP | 134 lines | 110 code | 21 blank | 3 comment | 28 complexity | 4139bb16c247f1b806367c47b4fee905 MD5 | raw file
  1. <?php
  2. /**
  3. * @package WPSEO\Admin
  4. */
  5. if ( ! defined( 'WPSEO_VERSION' ) ) {
  6. header( 'Status: 403 Forbidden' );
  7. header( 'HTTP/1.1 403 Forbidden' );
  8. exit();
  9. }
  10. $robots_file = get_home_path() . 'robots.txt';
  11. $ht_access_file = get_home_path() . '.htaccess';
  12. if ( isset( $_POST['create_robots'] ) ) {
  13. if ( ! current_user_can( 'manage_options' ) ) {
  14. die( __( 'You cannot create a robots.txt file.', 'wordpress-seo' ) );
  15. }
  16. check_admin_referer( 'wpseo_create_robots' );
  17. ob_start();
  18. error_reporting( 0 );
  19. do_robots();
  20. $robots_content = ob_get_clean();
  21. $f = fopen( $robots_file, 'x' );
  22. fwrite( $f, $robots_content );
  23. }
  24. if ( isset( $_POST['submitrobots'] ) ) {
  25. if ( ! current_user_can( 'manage_options' ) ) {
  26. die( __( 'You cannot edit the robots.txt file.', 'wordpress-seo' ) );
  27. }
  28. check_admin_referer( 'wpseo-robotstxt' );
  29. if ( file_exists( $robots_file ) ) {
  30. $robotsnew = stripslashes( $_POST['robotsnew'] );
  31. if ( is_writable( $robots_file ) ) {
  32. $f = fopen( $robots_file, 'w+' );
  33. fwrite( $f, $robotsnew );
  34. fclose( $f );
  35. $msg = __( 'Updated Robots.txt', 'wordpress-seo' );
  36. }
  37. }
  38. }
  39. if ( isset( $_POST['submithtaccess'] ) ) {
  40. if ( ! current_user_can( 'manage_options' ) ) {
  41. die( __( 'You cannot edit the .htaccess file.', 'wordpress-seo' ) );
  42. }
  43. check_admin_referer( 'wpseo-htaccess' );
  44. if ( file_exists( $ht_access_file ) ) {
  45. $ht_access_new = stripslashes( $_POST['htaccessnew'] );
  46. if ( is_writeable( $ht_access_file ) ) {
  47. $f = fopen( $ht_access_file, 'w+' );
  48. fwrite( $f, $ht_access_new );
  49. fclose( $f );
  50. }
  51. }
  52. }
  53. if ( isset( $msg ) && ! empty( $msg ) ) {
  54. echo '<div id="message" style="width:94%;" class="updated fade"><p>', esc_html( $msg ), '</p></div>';
  55. }
  56. $action_url = network_admin_url( 'admin.php?page=wpseo_tools&tool=file-editor' ); // auto-falls back on admin_url for non-multisite
  57. echo '<h2>', __( 'Robots.txt', 'wordpress-seo' ), '</h2>';
  58. if ( ! file_exists( $robots_file ) ) {
  59. if ( is_writable( get_home_path() ) ) {
  60. echo '<form action="', esc_url( $action_url ), '" method="post" id="robotstxtcreateform">';
  61. wp_nonce_field( 'wpseo_create_robots', '_wpnonce', true, true );
  62. echo '<p>', __( 'You don\'t have a robots.txt file, create one here:', 'wordpress-seo' ), '</p>';
  63. echo '<input type="submit" class="button" name="create_robots" value="', __( 'Create robots.txt file', 'wordpress-seo' ), '">';
  64. echo '</form>';
  65. }
  66. else {
  67. echo '<p>', __( 'If you had a robots.txt file and it was editable, you could edit it from here.', 'wordpress-seo' ), '</p>';
  68. }
  69. }
  70. else {
  71. $f = fopen( $robots_file, 'r' );
  72. $content = '';
  73. if ( filesize( $robots_file ) > 0 ) {
  74. $content = fread( $f, filesize( $robots_file ) );
  75. }
  76. $robots_txt_content = esc_textarea( $content );
  77. if ( ! is_writable( $robots_file ) ) {
  78. echo '<p><em>', __( 'If your robots.txt were writable, you could edit it from here.', 'wordpress-seo' ), '</em></p>';
  79. echo '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">', $robots_txt_content, '</textarea><br/>';
  80. }
  81. else {
  82. echo '<form action="', esc_url( $action_url ), '" method="post" id="robotstxtform">';
  83. wp_nonce_field( 'wpseo-robotstxt', '_wpnonce', true, true );
  84. echo '<p>', __( 'Edit the content of your robots.txt:', 'wordpress-seo' ), '</p>';
  85. echo '<textarea class="large-text code" rows="15" name="robotsnew">', $robots_txt_content, '</textarea><br/>';
  86. echo '<div class="submit"><input class="button" type="submit" name="submitrobots" value="', __( 'Save changes to Robots.txt', 'wordpress-seo' ), '" /></div>';
  87. echo '</form>';
  88. }
  89. }
  90. echo '<h2>', __( '.htaccess file', 'wordpress-seo' ), '</h2>';
  91. if ( ( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) === false ) && file_exists( $ht_access_file ) ) {
  92. $f = fopen( $ht_access_file, 'r' );
  93. $contentht = '';
  94. if ( filesize( $ht_access_file ) > 0 ) {
  95. $contentht = fread( $f, filesize( $ht_access_file ) );
  96. }
  97. $contentht = esc_textarea( $contentht );
  98. if ( ! is_writable( $ht_access_file ) ) {
  99. echo '<p><em>', __( 'If your .htaccess were writable, you could edit it from here.', 'wordpress-seo' ), '</em></p>';
  100. echo '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">', $contentht, '</textarea><br/>';
  101. }
  102. else {
  103. echo '<form action="', esc_url( $action_url ), '" method="post" id="htaccessform">';
  104. wp_nonce_field( 'wpseo-htaccess', '_wpnonce', true, true );
  105. echo '<p>', __( 'Edit the content of your .htaccess:', 'wordpress-seo' ), '</p>';
  106. echo '<textarea class="large-text code" rows="15" name="htaccessnew">', $contentht, '</textarea><br/>';
  107. echo '<div class="submit"><input class="button" type="submit" name="submithtaccess" value="', __( 'Save changes to .htaccess', 'wordpress-seo' ), '" /></div>';
  108. echo '</form>';
  109. }
  110. }
  111. elseif ( ( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) === false ) && ! file_exists( $ht_access_file ) ) {
  112. echo '<p>', __( 'If you had a .htaccess file and it was editable, you could edit it from here.', 'wordpress-seo' ), '</p>';
  113. }