PageRenderTime 35ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/ngochuynh1991/cuacuon
PHP | 186 lines | 146 code | 29 blank | 11 comment | 36 complexity | ae573b423a2195a05c07da3dfe524c5f 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. if ( filter_input( INPUT_GET, 'intro' ) ) {
  11. require WPSEO_PATH . 'admin/views/about.php';
  12. return;
  13. }
  14. $options = get_option( 'wpseo' );
  15. if ( isset( $_GET['allow_tracking'] ) && check_admin_referer( 'wpseo_activate_tracking', 'nonce' ) ) {
  16. $options['yoast_tracking'] = ( $_GET['allow_tracking'] == 'yes' );
  17. update_option( 'wpseo', $options );
  18. if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
  19. wp_safe_redirect( $_SERVER['HTTP_REFERER'], 307 );
  20. exit;
  21. }
  22. }
  23. // Fix metadescription if so requested.
  24. if ( isset( $_GET['fixmetadesc'] ) && check_admin_referer( 'wpseo-fix-metadesc', 'nonce' ) && $options['theme_description_found'] !== '' ) {
  25. $path = false;
  26. if ( file_exists( get_stylesheet_directory() . '/header.php' ) ) {
  27. // Theme or child theme.
  28. $path = get_stylesheet_directory();
  29. }
  30. elseif ( file_exists( get_template_directory() . '/header.php' ) ) {
  31. // Parent theme in case of a child theme.
  32. $path = get_template_directory();
  33. }
  34. if ( is_string( $path ) && $path !== '' ) {
  35. $fcontent = file_get_contents( $path . '/header.php' );
  36. $msg = '';
  37. $backup_file = date( 'Ymd-H.i.s-' ) . 'header.php.wpseobak';
  38. if ( ! file_exists( $path . '/' . $backup_file ) ) {
  39. $backupfile = fopen( $path . '/' . $backup_file, 'w+' );
  40. if ( $backupfile ) {
  41. fwrite( $backupfile, $fcontent );
  42. fclose( $backupfile );
  43. $msg = __( 'Backed up the original file header.php to <strong><em>' . esc_html( $backup_file ) . '</em></strong>, ', 'wordpress-seo' );
  44. $count = 0;
  45. $fcontent = str_replace( $options['theme_description_found'], '', $fcontent, $count );
  46. if ( $count > 0 ) {
  47. $header_file = fopen( $path . '/header.php', 'w+' );
  48. if ( $header_file ) {
  49. if ( fwrite( $header_file, $fcontent ) !== false ) {
  50. $msg .= __( 'Removed hardcoded meta description.', 'wordpress-seo' );
  51. $options['theme_has_description'] = false;
  52. $options['theme_description_found'] = '';
  53. update_option( 'wpseo', $options );
  54. }
  55. else {
  56. $msg .= '<span class="error">' . __( 'Failed to remove hardcoded meta description.', 'wordpress-seo' ) . '</span>';
  57. }
  58. fclose( $header_file );
  59. }
  60. }
  61. else {
  62. wpseo_description_test();
  63. $msg .= '<span class="warning">' . __( 'Earlier found meta description was not found in file. Renewed the description test data.', 'wordpress-seo' ) . '</span>';
  64. }
  65. add_settings_error( 'yoast_wpseo_dashboard_options', 'error', $msg, 'updated' );
  66. }
  67. }
  68. }
  69. // Clean up the referrer url for later use.
  70. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  71. $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'nonce', 'fixmetadesc' ), $_SERVER['REQUEST_URI'] );
  72. }
  73. }
  74. if ( ( ! isset( $options['theme_has_description'] ) || ( ( isset( $options['theme_has_description'] ) && $options['theme_has_description'] === true ) || $options['theme_description_found'] !== '' ) ) || ( isset( $_GET['checkmetadesc'] ) && check_admin_referer( 'wpseo-check-metadesc', 'nonce' ) ) ) {
  75. wpseo_description_test();
  76. // Renew the options after the test.
  77. $options = get_option( 'wpseo' );
  78. }
  79. if ( isset( $_GET['checkmetadesc'] ) ) {
  80. // Clean up the referrer url for later use.
  81. if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  82. $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'nonce', 'checkmetadesc' ), $_SERVER['REQUEST_URI'] );
  83. }
  84. }
  85. $yform = Yoast_Form::get_instance();
  86. $yform->admin_header( true, 'wpseo' );
  87. do_action( 'wpseo_all_admin_notices' );
  88. if ( is_array( $options['blocking_files'] ) && count( $options['blocking_files'] ) > 0 ) {
  89. echo '<p id="blocking_files" class="wrong">';
  90. echo '<a href="javascript:wpseoKillBlockingFiles(\'', esc_js( wp_create_nonce( 'wpseo-blocking-files' ) ), '\')" class="button fixit">', __( 'Fix it.', 'wordpress-seo' ), '</a>';
  91. echo __( 'The following file(s) is/are blocking your XML sitemaps from working properly:', 'wordpress-seo' ), '<br />';
  92. foreach ( $options['blocking_files'] as $file ) {
  93. echo esc_html( $file ), '<br/>';
  94. }
  95. unset( $file );
  96. /* translators: %1$s expands to Yoast SEO */
  97. echo '
  98. ', sprintf( __( 'Either delete them (this can be done with the "Fix it" button) or disable %1$s XML sitemaps.', 'wordpress-seo' ), 'Yoast SEO' ), '
  99. </p>';
  100. }
  101. if ( $options['theme_description_found'] !== '' ) {
  102. echo '<p id="metadesc_found notice" class="wrong settings_error">';
  103. echo '<a href="', esc_url( add_query_arg( array( 'nonce' => wp_create_nonce( 'wpseo-fix-metadesc' ) ), admin_url( 'admin.php?page=wpseo_dashboard&fixmetadesc' ) ) ), '" class="button fixit">', __( 'Fix it.', 'wordpress-seo' ), '</a>';
  104. echo ' <a href="', esc_url( add_query_arg( array( 'nonce' => wp_create_nonce( 'wpseo-check-metadesc' ) ), admin_url( 'admin.php?page=wpseo_dashboard&checkmetadesc' ) ) ), '" class="button checkit">', __( 'Re-check theme.', 'wordpress-seo' ), '</a>';
  105. /* translators: %1$s expands to Yoast SEO */
  106. echo sprintf( __( 'Your theme contains a meta description, which blocks %1$s from working properly, please delete the following line, or press fix it:', 'wordpress-seo' ), 'Yoast SEO' ) . '<br />';
  107. echo '<code>', esc_html( $options['theme_description_found'] ), '</code>';
  108. echo '</p>';
  109. }
  110. if ( strpos( get_option( 'permalink_structure' ), '%postname%' ) === false && $options['ignore_permalink'] === false ) {
  111. echo '<p id="wrong_permalink" class="wrong">';
  112. echo '<a href="', esc_url( admin_url( 'options-permalink.php' ) ), '" class="button fixit">', __( 'Fix it.', 'wordpress-seo' ), '</a>';
  113. echo '<a href="javascript:wpseoSetIgnore(\'permalink\',\'wrong_permalink\',\'', esc_js( wp_create_nonce( 'wpseo-ignore' ) ), '\');" class="button fixit">', __( 'Ignore.', 'wordpress-seo' ), '</a>';
  114. echo __( 'You do not have your postname in the URL of your posts and pages, it is highly recommended that you do. Consider setting your permalink structure to <strong>/%postname%/</strong>.', 'wordpress-seo' ), '</p>';
  115. }
  116. if ( get_option( 'page_comments' ) && $options['ignore_page_comments'] === false ) {
  117. echo '<p id="wrong_page_comments" class="wrong">';
  118. echo '<a href="javascript:setWPOption(\'page_comments\',\'0\',\'wrong_page_comments\',\'', esc_js( wp_create_nonce( 'wpseo-setoption' ) ), '\');" class="button fixit">', __( 'Fix it.', 'wordpress-seo' ), '</a>';
  119. echo '<a href="javascript:wpseoSetIgnore(\'page_comments\',\'wrong_page_comments\',\'', esc_js( wp_create_nonce( 'wpseo-ignore' ) ), '\');" class="button fixit">', __( 'Ignore.', 'wordpress-seo' ), '</a>';
  120. echo __( 'Paging comments is enabled, this is not needed in 999 out of 1000 cases, so the suggestion is to disable it, to do that, simply uncheck the box before "Break comments into pages..."', 'wordpress-seo' ), '</p>';
  121. }
  122. $tabs = array(
  123. 'general' => array(
  124. 'label' => __( 'General', 'wordpress-seo' ),
  125. 'screencast_video_url' => 'https://yoa.st/screencast-general',
  126. ),
  127. 'knowledge-graph' => array(
  128. 'label' => ( 'company' === $options['company_or_person'] ) ? __( 'Company Info', 'wordpress-seo' ) : __( 'Your Info', 'wordpress-seo' ),
  129. 'screencast_video_url' => 'https://yoa.st/screencast-knowledge-graph',
  130. ),
  131. 'webmaster-tools' => array(
  132. 'label' => __( 'Webmaster Tools', 'wordpress-seo' ),
  133. 'screencast_video_url' => 'https://yoa.st/screencast-general-search-console',
  134. ),
  135. 'security' => array(
  136. 'label' => __( 'Security', 'wordpress-seo' ),
  137. 'screencast_video_url' => 'https://yoa.st/screencast-security',
  138. ),
  139. );
  140. ?>
  141. <h2 class="nav-tab-wrapper" id="wpseo-tabs">
  142. <?php foreach ( $tabs as $identifier => $tab ) : ?>
  143. <a class="nav-tab" id="<?php echo $identifier; ?>-tab" href="#top#<?php echo $identifier; ?>"><?php echo $tab['label']; ?></a>
  144. <?php endforeach; ?>
  145. </h2>
  146. <?php
  147. foreach ( $tabs as $identifier => $tab ) {
  148. printf( '<div id="%s" class="wpseotab">', $identifier );
  149. if ( ! empty( $tab['screencast_video_url'] ) ) {
  150. $tab_video_url = $tab['screencast_video_url'];
  151. include WPSEO_PATH . 'admin/views/partial-settings-tab-video.php';
  152. }
  153. require_once WPSEO_PATH . 'admin/views/tabs/dashboard/' . $identifier . '.php';
  154. echo '</div>';
  155. }
  156. do_action( 'wpseo_dashboard' );
  157. $yform->admin_footer();