WPSEO_GSC_Marker

Class WPSEO_GSC_Marker.

Defined (1)

The class is defined in the following location(s).

/admin/google_search_console/class-gsc-marker.php  
  1. class WPSEO_GSC_Marker { 
  2.  
  3. /** 
  4. * @var WPSEO_GSC_Issues 
  5. */ 
  6. private $crawl_issues; 
  7.  
  8. /** 
  9. * @var string 
  10. */ 
  11. private $url = ''; 
  12.  
  13. /** 
  14. * @var string 
  15. */ 
  16. private $platform; 
  17.  
  18. /** 
  19. * @var string 
  20. */ 
  21. private $category; 
  22.  
  23. /** 
  24. * @var string 
  25. */ 
  26. private $result; 
  27.  
  28. /** 
  29. * Setting up the needed API libs and return the result 
  30. * If param URL is given, the request is performed by a bulk action 
  31. * @param string $url Optional URL. 
  32. */ 
  33. public function __construct( $url = '' ) { 
  34. $this->url = $url; 
  35. $this->result = $this->get_result(); 
  36.  
  37. /** 
  38. * Getting the response for the AJAX request 
  39. * @return string 
  40. */ 
  41. public function get_response() { 
  42. return $this->result; 
  43.  
  44. /** 
  45. * Setting the result, this method will check if current 
  46. * @return string 
  47. */ 
  48. private function get_result() { 
  49. if ( $this->can_be_marked_as_fixed() ) { 
  50. $service = new WPSEO_GSC_Service( WPSEO_GSC_Settings::get_profile() ); 
  51.  
  52. if ( $this->set_crawl_issues() && $this->send_mark_as_fixed( $service ) && $this->delete_crawl_issue() ) { 
  53. $this->update_issue_count( $service ); 
  54.  
  55. return 'true'; 
  56.  
  57. return 'false'; 
  58.  
  59. /** 
  60. * Check if request is valid by verifying the posted nonce and return the URL if this one is set 
  61. * @return bool|string 
  62. */ 
  63. private function can_be_marked_as_fixed() { 
  64. if ( $this->url !== '' ) { 
  65. return $this->url; 
  66.  
  67. return false; 
  68.  
  69. /** 
  70. * Storing the data belonging to the current issue, this data is needed in the 'mark as fixed' flow 
  71. * @return bool 
  72. */ 
  73. private function set_crawl_issues() { 
  74. $this->platform = filter_input( INPUT_POST, 'platform' ); 
  75. $this->category = filter_input( INPUT_POST, 'category' ); 
  76. if ( $this->platform && $this->category ) { 
  77. $this->crawl_issues = new WPSEO_GSC_Issues( $this->platform, $this->category ); 
  78.  
  79. return true; 
  80.  
  81. return false; 
  82.  
  83. /** 
  84. * Sending a request to the Google Search Console API to let them know we marked an issue as fixed. 
  85. * @param WPSEO_GSC_Service $service Service object instance. 
  86. * @return bool 
  87. */ 
  88. private function send_mark_as_fixed( WPSEO_GSC_Service $service ) { 
  89. return $service->mark_as_fixed( $this->url, $this->platform, $this->category ); 
  90.  
  91. /** 
  92. * Delete the crawl issue from the database 
  93. * @return bool 
  94. */ 
  95. private function delete_crawl_issue() { 
  96. return $this->crawl_issues->delete_issue( $this->url ); 
  97.  
  98. /** 
  99. * Getting the counts for current platform - category combination and update the score of it. 
  100. * @param WPSEO_GSC_Service $service Service object instance. 
  101. */ 
  102. private function update_issue_count( WPSEO_GSC_Service $service ) { 
  103. $counts = new WPSEO_GSC_Count( $service ); 
  104.  
  105. // Get the issues. 
  106. $total_issues = $counts->get_issue_count( $this->platform, $this->category ); 
  107.  
  108. // Lower the current count with 1. 
  109. $total_issues = ( $total_issues - 1 ); 
  110.  
  111. // And update the count. 
  112. $counts->update_issue_count( $this->platform, $this->category, $total_issues );