/html/blog/wp-content/plugins/wordpress-seo/admin/pages/files.php

https://github.com/jimmytidey/jimmytidey.co.uk · PHP · 136 lines · 110 code · 23 blank · 3 comment · 28 complexity · b837716c7ebe1abbbf1e7143ed3dc9e8 MD5 · raw file

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