PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/iamgraeme/royalmile
PHP | 137 lines | 111 code | 23 blank | 3 comment | 28 complexity | 55c1507027e72091483814115f309540 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. $action_url = network_admin_url( 'admin.php?page=wpseo_files' ); // auto-falls back on admin_url for non-multisite
  59. if ( ! file_exists( $robots_file ) ) {
  60. if ( is_writable( get_home_path() ) ) {
  61. $content = '<form action="' . esc_url( $action_url ) . '" method="post" id="robotstxtcreateform">';
  62. $content .= wp_nonce_field( 'wpseo_create_robots', '_wpnonce', true, false );
  63. $content .= '<p>' . __( 'You don\'t have a robots.txt file, create one here:', 'wordpress-seo' ) . '</p>';
  64. $content .= '<input type="submit" class="button" name="create_robots" value="' . __( 'Create robots.txt file', 'wordpress-seo' ) . '">';
  65. $content .= '</form>';
  66. }
  67. else {
  68. $content = '<p>' . __( 'If you had a robots.txt file and it was editable, you could edit it from here.', 'wordpress-seo' );
  69. }
  70. }
  71. else {
  72. $f = fopen( $robots_file, 'r' );
  73. $content = '';
  74. if ( filesize( $robots_file ) > 0 ) {
  75. $content = fread( $f, filesize( $robots_file ) );
  76. }
  77. $robots_txt_content = esc_textarea( $content );
  78. if ( ! is_writable( $robots_file ) ) {
  79. $content = '<p><em>' . __( 'If your robots.txt were writable, you could edit it from here.', 'wordpress-seo' ) . '</em></p>';
  80. $content .= '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">' . $robots_txt_content . '</textarea><br/>';
  81. } else {
  82. $content = '<form action="' . esc_url( $action_url ) . '" method="post" id="robotstxtform">';
  83. $content .= wp_nonce_field( 'wpseo-robotstxt', '_wpnonce', true, false );
  84. $content .= '<p>' . __( 'Edit the content of your robots.txt:', 'wordpress-seo' ) . '</p>';
  85. $content .= '<textarea class="large-text code" rows="15" name="robotsnew">' . $robots_txt_content . '</textarea><br/>';
  86. $content .= '<div class="submit"><input class="button" type="submit" name="submitrobots" value="' . __( 'Save changes to Robots.txt', 'wordpress-seo' ) . '" /></div>';
  87. $content .= '</form>';
  88. }
  89. }
  90. $wpseo_admin_pages->postbox( 'robotstxt', __( 'Robots.txt', 'wordpress-seo' ), $content );
  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. $content = '<p><em>' . __( 'If your .htaccess were writable, you could edit it from here.', 'wordpress-seo' ) . '</em></p>';
  100. $content .= '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">' . $contentht . '</textarea><br/>';
  101. } else {
  102. $content = '<form action="' . esc_url( $action_url ) . '" method="post" id="htaccessform">';
  103. $content .= wp_nonce_field( 'wpseo-htaccess', '_wpnonce', true, false );
  104. $content .= '<p>' . __( 'Edit the content of your .htaccess:', 'wordpress-seo' ) . '</p>';
  105. $content .= '<textarea class="large-text code" rows="15" name="htaccessnew">' . $contentht . '</textarea><br/>';
  106. $content .= '<div class="submit"><input class="button" type="submit" name="submithtaccess" value="' . __( 'Save changes to .htaccess', 'wordpress-seo' ) . '" /></div>';
  107. $content .= '</form>';
  108. }
  109. $wpseo_admin_pages->postbox( 'htaccess', __( '.htaccess file', 'wordpress-seo' ), $content );
  110. } elseif ( ( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) === false ) && ! file_exists( $ht_access_file ) ) {
  111. $content = '<p>' . __( 'If you had a .htaccess file and it was editable, you could edit it from here.', 'wordpress-seo' );
  112. $wpseo_admin_pages->postbox( 'htaccess', __( '.htaccess file', 'wordpress-seo' ), $content );
  113. }
  114. $wpseo_admin_pages->admin_footer( false );