WPSEO_Recalculate

Abstract class to force methods in recalculate classes.

Defined (1)

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

/admin/recalculate/class-recalculate.php  
  1. abstract class WPSEO_Recalculate { 
  2.  
  3. /** 
  4. * @var array The options stored in the database 
  5. */ 
  6. protected $options; 
  7.  
  8. /** 
  9. * @var int 
  10. */ 
  11. protected $items_per_page = 20; 
  12.  
  13. /** 
  14. * Saves the array with scores to the database. 
  15. * @param array $scores Array with the score for each item. 
  16. */ 
  17. abstract public function save_scores( array $scores ); 
  18.  
  19. /** 
  20. * Gets the items and parses it to an response 
  21. * @param integer $paged The current page number. 
  22. * @return string 
  23. */ 
  24. abstract protected function get_items( $paged ); 
  25.  
  26. /** 
  27. * Maps the items to an array for the response 
  28. * @param mixed $item Object with data to parse. 
  29. * @return array 
  30. */ 
  31. abstract protected function item_to_response( $item ); 
  32.  
  33.  
  34. /** 
  35. * Gets the items to recalculate 
  36. * @param int $paged The current page number. 
  37. * @return array Items that can be recalculated. 
  38. */ 
  39. public function get_items_to_recalculate( $paged ) { 
  40. $return = array(); 
  41.  
  42. $paged = abs( $paged ); 
  43. $this->options = WPSEO_Options::get_all(); 
  44.  
  45. $items = $this->get_items( $paged ); 
  46.  
  47. $return['items'] = $this->parse_items( $items ); 
  48. $return['total_items'] = count( $items ); 
  49.  
  50. if ( $return['total_items'] >= $this->items_per_page ) { 
  51. $return['next_page'] = ( $paged + 1 ); 
  52.  
  53. return $return; 
  54.  
  55. /** 
  56. * Parse the posts|terms with the value we need 
  57. * @param array $items The items to parse. 
  58. * @return array 
  59. */ 
  60. protected function parse_items( array $items ) { 
  61. $return = array(); 
  62. foreach ( $items as $item ) { 
  63. $response = $this->item_to_response( $item ); 
  64. if ( ! empty( $response ) ) { 
  65. $return[] = $response; 
  66.  
  67. return $return; 
  68.  
  69. /** 
  70. * Get default from the options for given field 
  71. * @param string $field The field for which to get the default options. 
  72. * @param string $suffix The post type. 
  73. * @return bool|string 
  74. */ 
  75. protected function default_from_options( $field, $suffix ) { 
  76. $target_option_field = $field . '-' . $suffix; 
  77. if ( ! empty( $this->options[ $target_option_field ] ) ) { 
  78. return $this->options[ $target_option_field ]; 
  79.  
  80. return false;