class-ryte-service.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\OnPage
  6. */
  7. /**
  8. * Represents the service to be used by the WPSEO_Endpoint_Ryte endpoint.
  9. */
  10. class WPSEO_Ryte_Service {
  11. /**
  12. * @var WPSEO_OnPage_Option
  13. */
  14. protected $option;
  15. /**
  16. * Constructs the WPSEO_Ryte_Service class.
  17. *
  18. * @param WPSEO_OnPage_Option $option The option to retrieve data from.
  19. */
  20. public function __construct( WPSEO_OnPage_Option $option ) {
  21. $this->option = $option;
  22. }
  23. /**
  24. * Fetches statistics via REST request.
  25. *
  26. * @return WP_REST_Response The response object.
  27. */
  28. public function get_statistics() {
  29. $result = false;
  30. if ( $this->option->is_enabled() ) {
  31. $result = $this->get_score( $this->option->get_status(), $this->option->should_be_fetched() );
  32. }
  33. return new WP_REST_Response( array( 'ryte' => $result ) );
  34. }
  35. /**
  36. * Returns an the results of the Ryte option based on the passed status.
  37. *
  38. * @param string $status The option's status.
  39. * @param bool $fetch Whether or not the data should be fetched.
  40. *
  41. * @return array The results, contains a score and label.
  42. */
  43. private function get_score( $status, $fetch = false ) {
  44. if ( $status === WPSEO_OnPage_Option::IS_INDEXABLE ) {
  45. return array(
  46. 'score' => 'good',
  47. 'label' => __( 'Your homepage can be indexed by search engines.', 'wordpress-seo' ),
  48. 'can_fetch' => $fetch,
  49. );
  50. }
  51. if ( $status === WPSEO_OnPage_Option::IS_NOT_INDEXABLE ) {
  52. return array(
  53. 'score' => 'bad',
  54. 'label' => sprintf(
  55. /* translators: %1$s: opens a link to a related knowledge base article. %2$s: closes the link. */
  56. __( '%1$sYour homepage cannot be indexed by search engines%2$s. This is very bad for SEO and should be fixed.', 'wordpress-seo' ),
  57. '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/onpageindexerror' ) . '" target="_blank">',
  58. '</a>'
  59. ),
  60. 'can_fetch' => $fetch,
  61. );
  62. }
  63. if ( $status === WPSEO_OnPage_Option::CANNOT_FETCH ) {
  64. return array(
  65. 'score' => 'na',
  66. 'label' => sprintf(
  67. /* translators: %1$s: opens a link to a related knowledge base article, %2$s: expands to Yoast SEO, %3$s: closes the link, %4$s: expands to Ryte. */
  68. __( '%1$s%2$s has not been able to fetch your site\'s indexability status%3$s from %4$s', 'wordpress-seo' ),
  69. '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/onpagerequestfailed' ) . '" target="_blank">',
  70. 'Yoast SEO',
  71. '</a>',
  72. 'Ryte'
  73. ),
  74. 'can_fetch' => $fetch,
  75. );
  76. }
  77. if ( $status === WPSEO_OnPage_Option::NOT_FETCHED ) {
  78. return array(
  79. 'score' => 'na',
  80. 'label' => esc_html( sprintf(
  81. /* translators: %1$s: expands to Yoast SEO, %2$s: expands to Ryte. */
  82. __( '%1$s has not fetched your site\'s indexability status yet from %2$s', 'wordpress-seo' ),
  83. 'Yoast SEO',
  84. 'Ryte'
  85. ) ),
  86. 'can_fetch' => $fetch,
  87. );
  88. }
  89. return array();
  90. }
  91. }